his_api_controller.go 433KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120
  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. //新增处方
  1760. if advicelist.ID == 0 {
  1761. all_count, _ := strconv.ParseFloat(totals, 64)
  1762. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1763. if prescribingNumberUnit == drug.MinUnit {
  1764. if drug.IsUse != 1 {
  1765. if all_count == 0 {
  1766. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1767. return
  1768. }
  1769. if prescribing_number > all_count {
  1770. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1771. return
  1772. }
  1773. if adminInfo.CurrentOrgId == 10215 {
  1774. if prescribing_number > batch_number_all_count {
  1775. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1776. return
  1777. }
  1778. }
  1779. }
  1780. }
  1781. if prescribingNumberUnit == drug.MaxUnit {
  1782. num := prescribing_number * float64(drug.MinNumber)
  1783. if drug.IsUse != 1 {
  1784. if all_count == 0 {
  1785. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1786. return
  1787. }
  1788. if num > all_count {
  1789. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1790. return
  1791. }
  1792. if adminInfo.CurrentOrgId == 10215 {
  1793. if num > batch_number_all_count {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1795. return
  1796. }
  1797. }
  1798. }
  1799. }
  1800. }
  1801. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1802. if drugOutConfig.IsOpen != 1 {
  1803. //修改处方
  1804. for _, advice := range advices {
  1805. var drug_id int64
  1806. var prescribing_number float64
  1807. var prescribingNumberUnit string
  1808. var prescribingNumber string
  1809. var adviceId int64
  1810. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1811. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1812. }
  1813. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1814. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1815. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1816. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1817. }
  1818. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1819. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1820. }
  1821. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1822. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1823. }
  1824. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1825. if drug.ID == 0 {
  1826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1827. return
  1828. }
  1829. //查询药品的所有库存
  1830. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1831. var total_count int64
  1832. for _, it := range list {
  1833. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1834. }
  1835. totals := strconv.FormatInt(total_count, 10)
  1836. //查询该药品是否存在开药记录
  1837. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1838. //新增处方
  1839. if advicelist.ID == 0 {
  1840. //查询最新批次库存
  1841. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1842. var batch_number_count int64
  1843. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1844. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1845. all_count, _ := strconv.ParseFloat(totals, 64)
  1846. if prescribingNumberUnit == drug.MinUnit {
  1847. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1848. if drug.IsUse != 1 {
  1849. if all_count == 0 {
  1850. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1851. return
  1852. }
  1853. if prescribing_number > all_count {
  1854. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1855. return
  1856. }
  1857. if adminInfo.CurrentOrgId == 10215 {
  1858. if prescribing_number > batch_number_all_count {
  1859. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1860. return
  1861. }
  1862. }
  1863. }
  1864. } else {
  1865. if prescribingNumberUnit == drug.MaxUnit {
  1866. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1867. num := prescribing_number * float64(drug.MinNumber)
  1868. if drug.IsUse != 1 {
  1869. if all_count == 0 {
  1870. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1871. return
  1872. }
  1873. if num > all_count {
  1874. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1875. return
  1876. }
  1877. if adminInfo.CurrentOrgId == 10215 {
  1878. if prescribing_number > batch_number_all_count {
  1879. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1880. return
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. //修改处方
  1888. if advicelist.ID > 0 {
  1889. //查询最新批次库存
  1890. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1891. var batch_number_count int64
  1892. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1893. var device_number int64
  1894. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1895. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1896. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1897. device_number = prescribingNumberInt * drug.MinNumber
  1898. }
  1899. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1900. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1901. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1902. device_number = prescribingNumberInt
  1903. }
  1904. var number_count int64
  1905. if prescribingNumberUnit == drug.MaxUnit {
  1906. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1907. number_count = prescribingNumberInt * drug.MinNumber
  1908. }
  1909. if prescribingNumberUnit == drug.MinUnit {
  1910. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1911. number_count = prescribingNumberInt
  1912. }
  1913. //如果修改的数量大于之前修改的数量
  1914. if (number_count - device_number) > 0 {
  1915. //如果修改的差数量 大于库存数量
  1916. if drug.IsUse != 1 {
  1917. if total_count == 0 {
  1918. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1919. return
  1920. }
  1921. if (number_count - device_number) > total_count {
  1922. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1923. return
  1924. }
  1925. if (number_count - device_number) > batch_number_count {
  1926. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1927. return
  1928. }
  1929. if adminInfo.CurrentOrgId == 10215 {
  1930. // 查询该药品最后一次出库记录
  1931. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1932. var out_count int64
  1933. var in_count int64
  1934. var stock_max_number int64
  1935. var stock_min_number int64
  1936. for _, it := range outInfo {
  1937. if it.CountUnit == drug.MaxUnit {
  1938. it.Count = it.Count * drug.MinNumber
  1939. }
  1940. out_count += it.Count
  1941. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1942. stock_max_number = warehouseInfoList.StockMaxNumber
  1943. stock_min_number = warehouseInfoList.StockMinNumber
  1944. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1945. }
  1946. if out_count > 0 {
  1947. if (number_count - device_number) > in_count {
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1949. return
  1950. }
  1951. }
  1952. // 未出库
  1953. if out_count == 0 {
  1954. var sum_in_count int64
  1955. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1956. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1957. fmt.Println("sum_in_count", sum_in_count)
  1958. //如果修改的数量大于有库存的第一个批次
  1959. if number_count > sum_in_count {
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1961. return
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1968. if pharmacyConfig.IsOpen != 1 {
  1969. if device_number != number_count {
  1970. // 查询该药品最后一次出库记录
  1971. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1972. //回退库存
  1973. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1974. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1975. }
  1976. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1977. var stock_max_number int64
  1978. var stock_min_number int64
  1979. if number_count >= drug.MinNumber {
  1980. stock_max_number = device_number / drug.MinNumber
  1981. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1982. stock_min_number = device_number % drug.MinNumber
  1983. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1984. } else {
  1985. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1986. }
  1987. }
  1988. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1989. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1990. }
  1991. //删除记录
  1992. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1993. //查询默认仓库剩余多少库存
  1994. var sum_count int64
  1995. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1996. for _, its := range stockInfo {
  1997. if its.MaxUnit == drug.MaxUnit {
  1998. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1999. }
  2000. sum_count += its.StockMaxNumber + its.StockMinNumber
  2001. }
  2002. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. //保存处方开药
  2009. if drugOutConfig.IsOpen == 1 {
  2010. //修改处方
  2011. for _, advice := range advices {
  2012. var drug_id int64
  2013. var prescribing_number float64
  2014. var prescribingNumberUnit string
  2015. var prescribingNumber string
  2016. var adviceId int64
  2017. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2018. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2019. }
  2020. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2021. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2022. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2023. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2024. }
  2025. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2026. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2027. }
  2028. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2029. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2030. }
  2031. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2032. if drug.ID == 0 {
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. //查询最新批次库存
  2048. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2049. var batch_number_count int64
  2050. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2051. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2052. all_count, _ := strconv.ParseFloat(totals, 64)
  2053. if prescribingNumberUnit == drug.MinUnit {
  2054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2055. if drug.IsUse != 1 {
  2056. if all_count == 0 {
  2057. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2058. return
  2059. }
  2060. if prescribing_number > all_count {
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. if adminInfo.CurrentOrgId == 10215 {
  2065. if prescribing_number > batch_number_all_count {
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2067. return
  2068. }
  2069. }
  2070. }
  2071. } else {
  2072. if prescribingNumberUnit == drug.MaxUnit {
  2073. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2074. num := prescribing_number * float64(drug.MinNumber)
  2075. if drug.IsUse != 1 {
  2076. if all_count == 0 {
  2077. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2078. return
  2079. }
  2080. if num > all_count {
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2082. return
  2083. }
  2084. if adminInfo.CurrentOrgId == 10215 {
  2085. if prescribing_number > batch_number_all_count {
  2086. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2087. return
  2088. }
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. //修改处方
  2095. if advicelist.ID > 0 {
  2096. //查询最新批次库存
  2097. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2098. var batch_number_count int64
  2099. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2100. var device_number int64
  2101. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2102. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2104. device_number = prescribingNumberInt * drug.MinNumber
  2105. }
  2106. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2108. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2109. device_number = prescribingNumberInt
  2110. }
  2111. var number_count int64
  2112. if prescribingNumberUnit == drug.MaxUnit {
  2113. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2114. number_count = prescribingNumberInt * drug.MinNumber
  2115. }
  2116. if prescribingNumberUnit == drug.MinUnit {
  2117. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2118. number_count = prescribingNumberInt
  2119. }
  2120. //如果修改的数量大于之前修改的数量
  2121. if (number_count - device_number) > 0 {
  2122. //如果修改的差数量 大于库存数量
  2123. if drug.IsUse != 1 {
  2124. if total_count == 0 {
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if (number_count - device_number) > total_count {
  2129. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2130. return
  2131. }
  2132. if adminInfo.CurrentOrgId == 10215 {
  2133. if (number_count - device_number) > batch_number_count {
  2134. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2135. return
  2136. }
  2137. }
  2138. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2139. //查询历史出库数据总批次
  2140. // 查询该药品最后一次出库记录
  2141. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2142. var out_count int64
  2143. var in_count int64
  2144. var stock_max_number int64
  2145. var stock_min_number int64
  2146. for _, it := range outInfo {
  2147. if it.CountUnit == drug.MaxUnit {
  2148. it.Count = it.Count * drug.MinNumber
  2149. }
  2150. out_count += it.Count
  2151. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2152. stock_max_number = warehouseInfoList.StockMaxNumber
  2153. stock_min_number = warehouseInfoList.StockMinNumber
  2154. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2155. }
  2156. if out_count > 0 {
  2157. if (number_count - device_number) > in_count {
  2158. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2159. return
  2160. }
  2161. }
  2162. // 未出库
  2163. if out_count == 0 {
  2164. var sum_in_count int64
  2165. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2166. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2167. if sum_in_count == 0 {
  2168. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2169. return
  2170. }
  2171. //如果修改的数量大于有库存的第一个批次
  2172. if number_count > sum_in_count {
  2173. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2174. return
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. //校验耗材库存
  2191. if goodOutConfig.IsOpen == 1 {
  2192. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2193. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2194. if len(prescriptions) > 0 {
  2195. for _, item := range prescriptions {
  2196. items := item.(map[string]interface{})
  2197. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2198. projects := items["project"].([]interface{})
  2199. if len(projects) > 0 {
  2200. for _, project := range projects {
  2201. var project_id int64
  2202. var project_type int64
  2203. var totals float64
  2204. var project_name string
  2205. var parsetotal int64
  2206. var id int64
  2207. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2208. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2209. }
  2210. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2211. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2212. }
  2213. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2214. total, _ := project.(map[string]interface{})["total"].(string)
  2215. totals, _ = strconv.ParseFloat(total, 64)
  2216. }
  2217. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2218. project_name = project.(map[string]interface{})["project_name"].(string)
  2219. }
  2220. if project_type == 3 {
  2221. //查找该耗材的出库记录
  2222. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2223. if len(goodWarehouseInfo) == 0 {
  2224. //查询耗材库存
  2225. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2226. var stock_count int64
  2227. for _, it := range list {
  2228. stock_count += it.StockCount
  2229. }
  2230. stock_counts := strconv.FormatInt(stock_count, 10)
  2231. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2232. if stock_total_count == 0 {
  2233. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2234. return
  2235. }
  2236. if totals > stock_total_count {
  2237. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2238. return
  2239. }
  2240. }
  2241. if len(goodWarehouseInfo) > 0 {
  2242. //查询该患者耗材的历史数据
  2243. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2244. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2245. //数量发生改变
  2246. if parsetotal != count {
  2247. //如果现在的数量大于历史数量,就要看库存是否足够
  2248. if parsetotal > count {
  2249. //查询耗材所有库存
  2250. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2251. var stock_count int64
  2252. for _, it := range list {
  2253. stock_count += it.StockCount
  2254. }
  2255. //库存不足
  2256. if stock_count == 0 {
  2257. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2258. return
  2259. }
  2260. if (parsetotal - count) > stock_count {
  2261. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2262. return
  2263. }
  2264. }
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. }
  2275. //不使用耗材保存处方出库
  2276. if goodOutConfig.IsOpen != 1 {
  2277. if stockConfig.IsOpen == 1 {
  2278. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2279. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2280. if len(prescriptions) > 0 {
  2281. for _, item := range prescriptions {
  2282. items := item.(map[string]interface{})
  2283. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2284. projects := items["project"].([]interface{})
  2285. if len(projects) > 0 {
  2286. for _, project := range projects {
  2287. var project_id int64
  2288. var project_type int64
  2289. var totals float64
  2290. var project_name string
  2291. var parsetotal int64
  2292. var id int64
  2293. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2294. id = int64(project.(map[string]interface{})["id"].(float64))
  2295. }
  2296. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2297. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2298. }
  2299. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2300. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2301. }
  2302. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2303. total, _ := project.(map[string]interface{})["total"].(string)
  2304. totals, _ = strconv.ParseFloat(total, 64)
  2305. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2306. }
  2307. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2308. project_name = project.(map[string]interface{})["project_name"].(string)
  2309. }
  2310. if project_type == 3 {
  2311. //查找该耗材的出库记录
  2312. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2313. //没有出库记录
  2314. if len(goodWarehouseInfo) == 0 {
  2315. //查询耗材库存
  2316. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2317. var stock_count int64
  2318. for _, it := range list {
  2319. stock_count += it.StockCount
  2320. }
  2321. stock_counts := strconv.FormatInt(stock_count, 10)
  2322. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2323. if stock_total_count == 0 {
  2324. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2325. return
  2326. }
  2327. if totals > stock_total_count {
  2328. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2329. return
  2330. }
  2331. //查找今日该患者已经出库的所有耗材
  2332. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2333. for _, item := range goodList {
  2334. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2335. var flush_count int64
  2336. for _, it := range goodListSix {
  2337. flush_count += it.StockCount
  2338. }
  2339. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2340. creater := adminInfo.AdminUser.Id
  2341. if errs != nil {
  2342. goodErrcode := models.XtGoodErrcode{
  2343. UserOrgId: item.OrgId,
  2344. Errcode: "手动出库更新剩余出库失败",
  2345. GoodId: item.GoodId,
  2346. Status: 1,
  2347. Ctime: time.Now().Unix(),
  2348. Mtime: 0,
  2349. Count: 0,
  2350. StockCount: 0,
  2351. Creater: creater,
  2352. BatchNumberId: 0,
  2353. WarehouseOutId: 0,
  2354. }
  2355. service.CreateGoodErrcode(goodErrcode)
  2356. }
  2357. }
  2358. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2359. }
  2360. //有出库记录
  2361. if len(goodWarehouseInfo) > 0 {
  2362. //查询该患者耗材的历史数据
  2363. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2364. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2365. //数量发生改变
  2366. if parsetotal != count {
  2367. //查找今日该患者已经出库的所有耗材
  2368. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2369. for _, item := range goodList {
  2370. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2371. var flush_count int64
  2372. for _, it := range goodListSix {
  2373. flush_count += it.StockCount
  2374. }
  2375. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2376. //减少出库数量
  2377. creater := adminInfo.AdminUser.Id
  2378. if errs != nil {
  2379. goodErrcode := models.XtGoodErrcode{
  2380. UserOrgId: item.OrgId,
  2381. Errcode: "手动出库更新剩余出库失败",
  2382. GoodId: item.GoodId,
  2383. Status: 1,
  2384. Ctime: time.Now().Unix(),
  2385. Mtime: 0,
  2386. Count: 0,
  2387. StockCount: 0,
  2388. Creater: creater,
  2389. BatchNumberId: 0,
  2390. WarehouseOutId: 0,
  2391. }
  2392. service.CreateGoodErrcode(goodErrcode)
  2393. }
  2394. //查询默认仓库
  2395. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2396. var total_count int64
  2397. for _, it := range stockList {
  2398. total_count += it.StockCount
  2399. }
  2400. //基础库插入数据
  2401. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2402. }
  2403. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2416. var hpInfo models.HisPrescriptionInfo
  2417. if info.ID == 0 {
  2418. var randNum int
  2419. randNum = rand.Intn(10000) + 1000
  2420. timestamp := time.Now().Unix()
  2421. tempTime := time.Unix(timestamp, 0)
  2422. timeFormat := tempTime.Format("20060102150405")
  2423. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2424. hpInfo = models.HisPrescriptionInfo{
  2425. HisPatientId: his_patient_id,
  2426. UserOrgId: adminInfo.CurrentOrgId,
  2427. RecordDate: theTime.Unix(),
  2428. PatientId: patient_id,
  2429. Status: 1,
  2430. Ctime: time.Now().Unix(),
  2431. Mtime: time.Now().Unix(),
  2432. Creator: adminInfo.AdminUser.Id,
  2433. Modifier: adminInfo.AdminUser.Id,
  2434. Diagnosis: diagnose,
  2435. SickHistory: sick_history,
  2436. Departments: department,
  2437. RegisterType: reg_type,
  2438. PrescriptionNumber: p_number,
  2439. PrescriptionStatus: 1,
  2440. Doctor: role.UserName,
  2441. DoctorId: doctor_id,
  2442. SickType: sick_type,
  2443. PType: p_type,
  2444. PatientDiagnosis: patient_diagnose,
  2445. }
  2446. service.SavePatientPrescriptionInfo(hpInfo)
  2447. //创建步骤表
  2448. finish := models.XtDialysisFinish{
  2449. IsFinish: 1,
  2450. UserOrgId: adminInfo.CurrentOrgId,
  2451. Status: 1,
  2452. Ctime: time.Now().Unix(),
  2453. Mtime: 0,
  2454. Module: 4,
  2455. RecordDate: theTime.Unix(),
  2456. Sourse: 1,
  2457. PatientId: patient_id,
  2458. }
  2459. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2460. if dialysisFinish.ID == 0 {
  2461. service.CreateDialysisFinish(finish)
  2462. }
  2463. redis := service.RedisClient()
  2464. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2465. redis.Set(key, "", time.Second)
  2466. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2467. redis.Set(keyOne, "", time.Second)
  2468. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2469. redis.Set(keySeven, "", time.Second)
  2470. defer redis.Close()
  2471. } else {
  2472. hpInfo = models.HisPrescriptionInfo{
  2473. ID: info.ID,
  2474. UserOrgId: adminInfo.CurrentOrgId,
  2475. RecordDate: info.RecordDate,
  2476. PatientId: info.PatientId,
  2477. Status: 1,
  2478. Ctime: info.Ctime,
  2479. Mtime: time.Now().Unix(),
  2480. Creator: info.Creator,
  2481. Modifier: adminInfo.AdminUser.Id,
  2482. Diagnosis: diagnose,
  2483. SickHistory: sick_history,
  2484. Departments: department,
  2485. RegisterType: reg_type,
  2486. PrescriptionNumber: info.PrescriptionNumber,
  2487. Doctor: role.UserName,
  2488. PrescriptionStatus: info.PrescriptionStatus,
  2489. DoctorId: doctor_id,
  2490. SickType: sick_type,
  2491. PType: info.PType,
  2492. HisPatientId: info.HisPatientId,
  2493. PatientDiagnosis: patient_diagnose,
  2494. }
  2495. service.SavePatientPrescriptionInfo(hpInfo)
  2496. //创建步骤表
  2497. finish := models.XtDialysisFinish{
  2498. IsFinish: 1,
  2499. UserOrgId: adminInfo.CurrentOrgId,
  2500. Status: 1,
  2501. Ctime: time.Now().Unix(),
  2502. Mtime: 0,
  2503. Module: 4,
  2504. RecordDate: info.RecordDate,
  2505. Sourse: 1,
  2506. PatientId: info.PatientId,
  2507. }
  2508. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2509. if dialysisFinish.ID == 0 {
  2510. service.CreateDialysisFinish(finish)
  2511. }
  2512. redis := service.RedisClient()
  2513. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2514. redis.Set(key, "", time.Second)
  2515. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2516. redis.Set(keyOne, "", time.Second)
  2517. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2518. redis.Set(keySeven, "", time.Second)
  2519. defer redis.Close()
  2520. }
  2521. //定义切片
  2522. var adviceList []models.HisDoctorAdviceInfo
  2523. var projectList []models.HisPrescriptionProject
  2524. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2525. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2526. var tempPrescription *models.HisPrescription
  2527. if len(prescriptions) > 0 {
  2528. for _, item := range prescriptions {
  2529. items := item.(map[string]interface{})
  2530. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2531. utils.ErrorLog("id")
  2532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2533. return
  2534. }
  2535. id := int64(items["id"].(float64))
  2536. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2537. tempPrescription = &new_prescription
  2538. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2539. utils.ErrorLog("type")
  2540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2541. return
  2542. }
  2543. types := int64(items["type"].(float64))
  2544. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2545. utils.ErrorLog("med_type")
  2546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2547. return
  2548. }
  2549. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2550. if med_type == "0" {
  2551. med_type = "14"
  2552. }
  2553. //if order_status == 0 {
  2554. // order_status = 1
  2555. //}
  2556. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2557. utils.ErrorLog("pre_time")
  2558. }
  2559. preTime, _ := items["pre_time"].(string)
  2560. timeLayout := "2006-01-02"
  2561. loc, _ := time.LoadLocation("Local")
  2562. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2563. if err != nil {
  2564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2565. return
  2566. }
  2567. pTime := theTime2.Unix()
  2568. ctime := time.Now().Unix()
  2569. if tempPrescription.ID == 0 {
  2570. prescription := &models.HisPrescription{
  2571. ID: 0,
  2572. PatientId: patient_id,
  2573. UserOrgId: adminInfo.CurrentOrgId,
  2574. RecordDate: recordDateTime,
  2575. Ctime: ctime,
  2576. Mtime: ctime,
  2577. Type: types,
  2578. Modifier: adminInfo.AdminUser.Id,
  2579. Creator: adminInfo.AdminUser.Id,
  2580. Status: 1,
  2581. Doctor: role.UserName,
  2582. HisPatientId: his_patient_id,
  2583. OrderStatus: 1,
  2584. BatchNumber: "",
  2585. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2586. PreTime: pTime,
  2587. PType: p_type,
  2588. MedType: med_type,
  2589. }
  2590. tempPrescription = prescription
  2591. service.SaveHisPrescription(tempPrescription)
  2592. redis := service.RedisClient()
  2593. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2594. redis.Set(key, "", time.Second)
  2595. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2596. redis.Set(keyOne, "", time.Second)
  2597. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2598. redis.Set(keySeven, "", time.Second)
  2599. defer redis.Close()
  2600. } else {
  2601. tempPrescription.ID = id
  2602. tempPrescription.Type = types
  2603. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2604. tempPrescription.Mtime = time.Now().Unix()
  2605. tempPrescription.Doctor = role.UserName
  2606. //tempPrescription.OrderStatus = order_status
  2607. tempPrescription.PreTime = pTime
  2608. tempPrescription.MedType = med_type
  2609. service.SaveHisPrescription(tempPrescription)
  2610. redis := service.RedisClient()
  2611. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2612. redis.Set(key, "", time.Second)
  2613. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2614. redis.Set(keyOne, "", time.Second)
  2615. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2616. redis.Set(keySeven, "", time.Second)
  2617. defer redis.Close()
  2618. }
  2619. //service.SaveHisPrescription(prescription)
  2620. //更改患者挂号状态
  2621. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2622. fmt.Println("更改失败", err2)
  2623. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2624. advices := items["advices"].([]interface{})
  2625. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2626. groupNo := int64(0)
  2627. ctime := time.Now().Unix()
  2628. mtime := ctime
  2629. if len(advices) > 0 {
  2630. for _, advice := range advices {
  2631. var s models.HisDoctorAdviceInfo
  2632. s.PrescriptionId = tempPrescription.ID
  2633. s.AdviceType = 2
  2634. s.AdviceDoctor = doctor_id
  2635. s.StopState = 2
  2636. s.ExecutionState = 2
  2637. s.AdviceDate = recordDateTime
  2638. s.Status = 1
  2639. s.UserOrgId = adminInfo.CurrentOrgId
  2640. s.RecordDate = recordDateTime
  2641. s.StartTime = tempPrescription.PreTime
  2642. s.Groupno = groupNo
  2643. s.CreatedTime = ctime
  2644. s.UpdatedTime = mtime
  2645. s.PatientId = patient_id
  2646. s.HisPatientId = his_patient_id
  2647. s.StartTime = pTime
  2648. s.IsSettle = 2
  2649. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2650. if errcode > 0 {
  2651. c.ServeFailJSONWithSGJErrorCode(errcode)
  2652. return
  2653. }
  2654. s.StartTime = pTime
  2655. var total_count int64 //处方总库存
  2656. //查询改药品信息
  2657. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2658. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2659. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2660. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2661. total_count += prescribingNumberSeven * medical.MinNumber
  2662. }
  2663. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2664. total_count += prescribingNumberSeven
  2665. }
  2666. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2667. total_count += prescribingNumberSeven
  2668. }
  2669. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2670. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2671. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2672. if s.Price != lastWarehouse.RetailPrice {
  2673. s.Price = lastWarehouse.RetailPrice
  2674. }
  2675. if s.Price == 0 {
  2676. s.Price = lastWarehouse.RetailPrice
  2677. }
  2678. }
  2679. service.CreateHisDoctorAdvice(&s)
  2680. //记录日志
  2681. byterequest, _ := json.Marshal(s)
  2682. adviceLog := models.XtDoctorAdviceLog{
  2683. UserOrgId: s.UserOrgId,
  2684. PatientId: s.PatientId,
  2685. AdminUserId: adminInfo.AdminUser.Id,
  2686. Module: 1,
  2687. ErrLog: string(byterequest),
  2688. Status: 1,
  2689. Ctime: time.Now().Unix(),
  2690. Mtime: 0,
  2691. Source: "电脑端新建his医嘱",
  2692. RecordDate: s.AdviceDate,
  2693. }
  2694. service.CreateDoctorAdviceLog(adviceLog)
  2695. //存储切片中
  2696. adviceList = append(adviceList, s)
  2697. redis := service.RedisClient()
  2698. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2699. redis.Set(key, "", time.Second)
  2700. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2701. redis.Set(keyOne, "", time.Second)
  2702. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2703. redis.Set(keySeven, "", time.Second)
  2704. var randNum int
  2705. randNum = rand.Intn(10000) + 1000
  2706. timestamp := time.Now().Unix()
  2707. tempTime := time.Unix(timestamp, 0)
  2708. timeFormat := tempTime.Format("20060102150405")
  2709. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2710. service.CreateHisDoctorAdvice(&s)
  2711. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2712. redis.Set(keySix, "", time.Second)
  2713. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2714. redis.Set(keyFive, "", time.Second)
  2715. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2716. redis.Set(keyEight, "", time.Second)
  2717. defer redis.Close()
  2718. }
  2719. }
  2720. }
  2721. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2722. projects := items["project"].([]interface{})
  2723. if len(projects) > 0 {
  2724. for _, project := range projects {
  2725. var p models.HisPrescriptionProject
  2726. p.PrescriptionId = tempPrescription.ID
  2727. p.Ctime = time.Now().Unix()
  2728. p.Mtime = time.Now().Unix()
  2729. p.PatientId = patient_id
  2730. p.RecordDate = recordDateTime
  2731. p.Doctor = doctor_id
  2732. p.UserOrgId = adminInfo.CurrentOrgId
  2733. p.HisPatientId = his_patient_id
  2734. p.Status = 1
  2735. p.StartTime = pTime
  2736. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2737. if errcode > 0 {
  2738. c.ServeFailJSONWithSGJErrorCode(errcode)
  2739. return
  2740. }
  2741. if p.ID == 0 {
  2742. p.IsOut = 2
  2743. }
  2744. if p.ID > 0 {
  2745. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2746. p.IsOut = projectDetail.IsOut
  2747. }
  2748. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2749. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2750. if p.Type == 3 {
  2751. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2752. if p.Price != lastWarehouse.PackingPrice {
  2753. p.Price = lastWarehouse.PackingPrice
  2754. }
  2755. if p.Unit == "" {
  2756. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2757. p.Unit = goodInfoOne.PackingUnit
  2758. }
  2759. }
  2760. }
  2761. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2762. //
  2763. // if p.Type == 3 {
  2764. // //查询该耗材是否停用
  2765. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2766. // //表示该耗材已经停用,不能保存
  2767. // if goodInfoSeven.ID == 0 {
  2768. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2769. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2770. // return
  2771. // }
  2772. // }
  2773. //
  2774. //}
  2775. service.CreateHisProjectTwo(&p)
  2776. //记录日志
  2777. byterequest, _ := json.Marshal(p)
  2778. adviceLog := models.XtDoctorAdviceLog{
  2779. UserOrgId: p.UserOrgId,
  2780. PatientId: p.PatientId,
  2781. AdminUserId: adminInfo.AdminUser.Id,
  2782. Module: 1,
  2783. ErrLog: string(byterequest),
  2784. Status: 1,
  2785. Ctime: time.Now().Unix(),
  2786. Mtime: 0,
  2787. Source: "电脑端新建his项目",
  2788. RecordDate: p.RecordDate,
  2789. }
  2790. service.CreateDoctorAdviceLog(adviceLog)
  2791. projectList = append(projectList, p)
  2792. var randNum int
  2793. randNum = rand.Intn(10000) + 1000
  2794. timestamp := time.Now().Unix()
  2795. tempTime := time.Unix(timestamp, 0)
  2796. timeFormat := tempTime.Format("20060102150405")
  2797. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2798. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2799. //新增或者编辑项目,修改对应的标签数据
  2800. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2801. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2802. var label models.HisLabelPrintInfo
  2803. project, _ := service.GetProjectDetail(p.ProjectId)
  2804. if project.CostClassify == 3 { //类别为检验检查
  2805. if p.TeamId > 0 { //检验检查组套
  2806. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2807. if tempLabel.ID == 0 {
  2808. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2809. label.Number = tempPrescription.PrescriptionNumber
  2810. label.ProjectId = project.ID
  2811. label.Status = 1
  2812. label.IsPrint = 2
  2813. label.DoctorId = info.DoctorId
  2814. label.UserOrgId = p.UserOrgId
  2815. label.PatientId = patient_id
  2816. label.RecordDate = recordDateTime
  2817. label.Ctime = time.Now().Unix()
  2818. label.Mtime = time.Now().Unix()
  2819. label.ItemId = p.TeamId
  2820. label.FeedetlSn = p.FeedetlSn
  2821. label.PProjectId = p.ID
  2822. label.ProjectName = team.ProjectTeam
  2823. label.PatientName = patient.Name
  2824. service.CreateHisLabelRecord(&label)
  2825. }
  2826. } else { //单条检验检查项目
  2827. label.Number = tempPrescription.PrescriptionNumber
  2828. label.ProjectId = project.ID
  2829. label.Status = 1
  2830. label.DoctorId = info.DoctorId
  2831. label.UserOrgId = p.UserOrgId
  2832. label.PatientId = patient_id
  2833. label.RecordDate = recordDateTime
  2834. label.IsPrint = 2
  2835. label.Ctime = time.Now().Unix()
  2836. label.Mtime = time.Now().Unix()
  2837. label.FeedetlSn = p.FeedetlSn
  2838. label.PProjectId = p.ID
  2839. label.ItemId = p.TeamId
  2840. label.ProjectName = project.ProjectName
  2841. label.PatientName = patient.Name
  2842. service.CreateHisLabelRecord(&label)
  2843. }
  2844. }
  2845. }
  2846. }
  2847. service.SaveHisProjectTwo(&p)
  2848. }
  2849. }
  2850. }
  2851. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2852. // addition := items["addition"].([]interface{})
  2853. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2854. // ctime := time.Now().Unix()
  2855. // mtime := ctime
  2856. // if len(addition) > 0 {
  2857. // for _, item := range addition {
  2858. // var s models.HisAdditionalCharge
  2859. // s.PrescriptionId = tempPrescription.ID
  2860. // s.Status = 1
  2861. // s.UserOrgId = adminInfo.CurrentOrgId
  2862. // s.RecordDate = recordDateTime
  2863. // s.CreatedTime = ctime
  2864. // s.UpdatedTime = mtime
  2865. // s.PatientId = patient_id
  2866. // s.HisPatientId = his_patient_id
  2867. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2868. // if errcode > 0 {
  2869. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2870. // return
  2871. // }
  2872. // service.CreateAdditionalCharge(&s)
  2873. // var randNum int
  2874. // randNum = rand.Intn(10000) + 1000
  2875. // timestamp := time.Now().Unix()
  2876. // tempTime := time.Unix(timestamp, 0)
  2877. // timeFormat := tempTime.Format("20060102150405")
  2878. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2879. // service.CreateAdditionalCharge(&s)
  2880. //
  2881. // }
  2882. // }
  2883. //}
  2884. }
  2885. }
  2886. //查询今日该患者开的药品处方
  2887. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2888. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2889. //药品出库
  2890. if drugOutConfig.IsOpen == 1 {
  2891. for _, item := range hisdoctorlist {
  2892. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2893. // 查询该药品最后一次出库记录
  2894. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2895. if len(druginfo) > 0 {
  2896. //回退库存
  2897. for _, it := range druginfo {
  2898. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2899. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2900. }
  2901. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2902. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2903. }
  2904. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2905. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2906. }
  2907. }
  2908. }
  2909. //删除记录
  2910. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2911. //查询最后一次数据
  2912. if drugOutConfig.IsOpen == 1 {
  2913. //出库
  2914. if drug.IsUse == 2 {
  2915. creater := adminInfo.AdminUser.Id
  2916. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2917. }
  2918. //更新字典里面的库存
  2919. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2920. var sum_count int64
  2921. for _, its := range stockInfo {
  2922. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2923. if its.MaxUnit == baseDrug.MaxUnit {
  2924. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2925. }
  2926. sum_count += its.StockMaxNumber + its.StockMinNumber
  2927. }
  2928. //更新基础库存
  2929. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2930. //剩余库存
  2931. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2932. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2933. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2934. }
  2935. }
  2936. }
  2937. //耗材保存处方出库
  2938. if goodOutConfig.IsOpen == 1 {
  2939. //查询今日耗材出库数量
  2940. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2941. for _, item := range hisgoodlist {
  2942. //查询历史出库数据
  2943. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2944. var out_count_five int64
  2945. for _, item := range flowGood {
  2946. out_count_five += item.Count
  2947. }
  2948. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2949. if out_count_five != parseIntCount {
  2950. //查询耗材最后一次出库记录
  2951. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2952. //查询默认出库仓库库存
  2953. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2954. if len(wareOut) > 0 {
  2955. for _, it := range wareOut {
  2956. //回退库存
  2957. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2958. //删除出库记录
  2959. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2960. }
  2961. }
  2962. timeStr := time.Now().Format("2006-01-02")
  2963. timeArr := strings.Split(timeStr, "-")
  2964. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2965. total = total + 1
  2966. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2967. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2968. number = number + total
  2969. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2970. operation_time := time.Now().Unix()
  2971. creater := c.GetAdminUserInfo().AdminUser.Id
  2972. recordDateStr := time.Now().Format("2006-01-02")
  2973. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2974. nowtime := recordDate.Unix()
  2975. warehouseOut := models.WarehouseOut{
  2976. WarehouseOutOrderNumber: warehousing_out_order,
  2977. OperationTime: operation_time,
  2978. OrgId: adminInfo.CurrentOrgId,
  2979. Creater: creater,
  2980. Ctime: time.Now().Unix(),
  2981. Status: 1,
  2982. WarehouseOutTime: nowtime,
  2983. Type: 1,
  2984. StorehouseId: storeConfig.StorehouseOutInfo,
  2985. IsCheck: 1,
  2986. IsSys: 1,
  2987. }
  2988. //查询是否生成出库单
  2989. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2990. if out.ID == 0 {
  2991. service.AddSigleWarehouseOut(&warehouseOut)
  2992. }
  2993. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2994. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2995. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2996. dialyPrepareOne := models.DialysisBeforePrepare{
  2997. GoodTypeId: goodObj.GoodTypeId,
  2998. GoodId: item.ProjectId,
  2999. PatientId: item.PatientId,
  3000. RecordDate: item.RecordDate,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Count: parseIntCount,
  3003. Ctime: time.Now().Unix(),
  3004. Creater: creater,
  3005. Status: 1,
  3006. StorehouseId: houseConfig.StorehouseOutInfo,
  3007. ProjectId: item.ID,
  3008. }
  3009. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3010. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3011. //查询历史出库数据
  3012. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3013. var out_count int64
  3014. for _, item := range flowGood {
  3015. out_count += item.Count
  3016. }
  3017. //如果历史数和当前数据不想等才进行退库出库
  3018. if out_count != parseIntCount {
  3019. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3020. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3021. detail := models.AutomaticReduceDetail{
  3022. WarehouseOutId: 0,
  3023. WarehouseOutOrderNumber: "",
  3024. PatientId: item.PatientId,
  3025. Ctime: time.Now().Unix(),
  3026. Mtime: 0,
  3027. Status: 1,
  3028. RecordTime: item.RecordDate,
  3029. OrgId: item.UserOrgId,
  3030. GoodId: item.ProjectId,
  3031. GoodTypeId: 0,
  3032. Count: parseIntCount,
  3033. Type: 0,
  3034. ProjectId: item.ID,
  3035. StorehouseId: 0,
  3036. }
  3037. service.CreateAutoDetail(detail)
  3038. //查询剩余库存
  3039. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3040. var sum_count int64
  3041. for _, item := range goodList {
  3042. sum_count += item.StockCount
  3043. }
  3044. //更新剩余库存
  3045. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3046. //耗材
  3047. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3048. }
  3049. }
  3050. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3051. //查询历史出库数据
  3052. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3053. var out_count int64
  3054. for _, item := range flowGood {
  3055. out_count += item.Count
  3056. }
  3057. //如果历史数和当前数据不想等才进行退库出库
  3058. if out_count != parseIntCount {
  3059. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3060. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3061. detail := models.AutomaticReduceDetail{
  3062. WarehouseOutId: 0,
  3063. WarehouseOutOrderNumber: "",
  3064. PatientId: item.PatientId,
  3065. Ctime: time.Now().Unix(),
  3066. Mtime: 0,
  3067. Status: 1,
  3068. RecordTime: item.RecordDate,
  3069. OrgId: item.UserOrgId,
  3070. GoodId: item.ProjectId,
  3071. GoodTypeId: 0,
  3072. Count: parseIntCount,
  3073. Type: 0,
  3074. ProjectId: item.ID,
  3075. StorehouseId: 0,
  3076. }
  3077. service.CreateAutoDetail(detail)
  3078. //查询剩余库存
  3079. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3080. var sum_count int64
  3081. for _, item := range goodList {
  3082. sum_count += item.StockCount
  3083. }
  3084. //更新剩余库存
  3085. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3086. //耗材
  3087. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3088. }
  3089. }
  3090. }
  3091. }
  3092. }
  3093. }
  3094. //redisClient := service.RedisClient()
  3095. //defer redisClient.Close()
  3096. //
  3097. //list := models.HisList{
  3098. // Patient_id: patient_id,
  3099. // Advice_id:0,
  3100. // Record_date: 0,
  3101. // Advice: adviceList,
  3102. // Project: nil,
  3103. //}
  3104. //hisLis = append(hisLis, list)
  3105. //
  3106. //advice_json, _ := json.Marshal(&hisLis)
  3107. //redisClient.RPush("111", advice_json).Result()
  3108. //result, _ := redisClient.RPop("111").Result()
  3109. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3110. //
  3111. //var dat []map[string]interface{}
  3112. //json.Unmarshal([]byte(result), &dat)
  3113. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3114. //
  3115. //for k,v:=range dat{
  3116. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3117. //}
  3118. //project_json, _ := json.Marshal(&projectList)
  3119. //redisClient.LPush("222", project_json).Result()
  3120. if err == nil {
  3121. c.ServeSuccessJSON(map[string]interface{}{
  3122. "msg": "保存成功",
  3123. })
  3124. return
  3125. } else {
  3126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3127. return
  3128. }
  3129. }
  3130. func (c *HisApiController) EditHisPrescription() {
  3131. record_date := c.GetString("record_date")
  3132. patient_id, _ := c.GetInt64("patient_id")
  3133. reg_type, _ := c.GetInt64("reg_type")
  3134. //diagnose, _ := c.GetInt64("diagnose", 0)
  3135. diagnose := c.GetString("diagnose")
  3136. sick_type, _ := c.GetInt64("sick_type")
  3137. sick_history := c.GetString("sick_history")
  3138. doctor_id, _ := c.GetInt64("doctor", 0)
  3139. department, _ := c.GetInt64("department", 0)
  3140. his_patient_id, _ := c.GetInt64("his_patient_id")
  3141. p_type, _ := c.GetInt64("p_type")
  3142. dataBody := make(map[string]interface{}, 0)
  3143. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3144. if err != nil {
  3145. utils.ErrorLog(err.Error())
  3146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3147. return
  3148. }
  3149. timeLayout := "2006-01-02"
  3150. loc, _ := time.LoadLocation("Local")
  3151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3152. if err != nil {
  3153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3154. return
  3155. }
  3156. adminInfo := c.GetAdminUserInfo()
  3157. recordDateTime := theTime.Unix()
  3158. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3159. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3160. var hpInfo models.HisPrescriptionInfo
  3161. if info.ID == 0 {
  3162. var randNum int
  3163. randNum = rand.Intn(10000) + 1000
  3164. timestamp := time.Now().Unix()
  3165. tempTime := time.Unix(timestamp, 0)
  3166. timeFormat := tempTime.Format("20060102150405")
  3167. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3168. hpInfo = models.HisPrescriptionInfo{
  3169. UserOrgId: adminInfo.CurrentOrgId,
  3170. RecordDate: theTime.Unix(),
  3171. PatientId: patient_id,
  3172. Status: 1,
  3173. Ctime: time.Now().Unix(),
  3174. Mtime: time.Now().Unix(),
  3175. Creator: adminInfo.AdminUser.Id,
  3176. Modifier: adminInfo.AdminUser.Id,
  3177. Diagnosis: diagnose,
  3178. SickHistory: sick_history,
  3179. Departments: department,
  3180. RegisterType: reg_type,
  3181. PrescriptionNumber: p_number,
  3182. PrescriptionStatus: 1,
  3183. Doctor: role.UserName,
  3184. DoctorId: doctor_id,
  3185. SickType: sick_type,
  3186. PType: p_type,
  3187. }
  3188. service.SavePatientPrescriptionInfo(hpInfo)
  3189. } else {
  3190. hpInfo = models.HisPrescriptionInfo{
  3191. ID: info.ID,
  3192. UserOrgId: adminInfo.CurrentOrgId,
  3193. RecordDate: info.RecordDate,
  3194. PatientId: info.PatientId,
  3195. Status: 1,
  3196. Ctime: info.Ctime,
  3197. Mtime: time.Now().Unix(),
  3198. Creator: info.Creator,
  3199. Modifier: adminInfo.AdminUser.Id,
  3200. Diagnosis: diagnose,
  3201. SickHistory: sick_history,
  3202. Departments: department,
  3203. RegisterType: reg_type,
  3204. PrescriptionNumber: info.PrescriptionNumber,
  3205. Doctor: role.UserName,
  3206. PrescriptionStatus: info.PrescriptionStatus,
  3207. DoctorId: doctor_id,
  3208. SickType: sick_type,
  3209. PType: info.PType,
  3210. }
  3211. service.SavePatientPrescriptionInfo(hpInfo)
  3212. }
  3213. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3214. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3215. if len(prescriptions) > 0 {
  3216. for _, item := range prescriptions {
  3217. items := item.(map[string]interface{})
  3218. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3219. utils.ErrorLog("id")
  3220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3221. return
  3222. }
  3223. id := int64(items["id"].(float64))
  3224. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3225. utils.ErrorLog("type")
  3226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3227. return
  3228. }
  3229. types := int64(items["type"].(float64))
  3230. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3231. utils.ErrorLog("med_type")
  3232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3233. return
  3234. }
  3235. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3236. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3237. ctime := time.Now().Unix()
  3238. prescription := &models.HisPrescription{
  3239. ID: id,
  3240. PatientId: patient_id,
  3241. UserOrgId: adminInfo.CurrentOrgId,
  3242. RecordDate: recordDateTime,
  3243. Ctime: ctime,
  3244. Mtime: ctime,
  3245. Type: types,
  3246. Modifier: adminInfo.AdminUser.Id,
  3247. Creator: adminInfo.AdminUser.Id,
  3248. Status: 1,
  3249. Doctor: role.UserName,
  3250. HisPatientId: his_patient_id,
  3251. OrderStatus: 1,
  3252. BatchNumber: "",
  3253. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3254. PType: hpInfo.PType,
  3255. MedType: med_type,
  3256. }
  3257. if historyPrescription.ID > 0 {
  3258. prescription.PreTime = historyPrescription.PreTime
  3259. }
  3260. service.SaveHisPrescription(prescription)
  3261. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3262. advices := items["advices"].([]interface{})
  3263. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3264. groupNo := int64(0)
  3265. ctime := time.Now().Unix()
  3266. mtime := ctime
  3267. if len(advices) > 0 {
  3268. for _, advice := range advices {
  3269. var s models.HisDoctorAdviceInfo
  3270. s.PrescriptionId = prescription.ID
  3271. s.AdviceType = 2
  3272. s.AdviceDoctor = adminInfo.AdminUser.Id
  3273. s.StopState = 2
  3274. s.ExecutionState = 2
  3275. s.AdviceDate = recordDateTime
  3276. s.Status = 1
  3277. s.UserOrgId = adminInfo.CurrentOrgId
  3278. s.RecordDate = recordDateTime
  3279. s.StartTime = prescription.PreTime
  3280. s.Groupno = groupNo
  3281. s.CreatedTime = ctime
  3282. s.UpdatedTime = mtime
  3283. s.PatientId = patient_id
  3284. s.HisPatientId = his_patient_id
  3285. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3286. if errcode > 0 {
  3287. c.ServeFailJSONWithSGJErrorCode(errcode)
  3288. return
  3289. }
  3290. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3291. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3292. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3293. if s.Price == 0 {
  3294. s.Price = lastWarehouse.RetailPrice
  3295. }
  3296. }
  3297. service.CreateHisDoctorAdvice(&s)
  3298. //记录日志
  3299. byterequest, _ := json.Marshal(s)
  3300. adviceLog := models.XtDoctorAdviceLog{
  3301. UserOrgId: s.UserOrgId,
  3302. PatientId: s.PatientId,
  3303. AdminUserId: adminInfo.AdminUser.Id,
  3304. Module: 1,
  3305. ErrLog: string(byterequest),
  3306. Status: 1,
  3307. Ctime: time.Now().Unix(),
  3308. Mtime: 0,
  3309. Source: "电脑端his医嘱修改",
  3310. RecordDate: s.AdviceDate,
  3311. }
  3312. service.CreateDoctorAdviceLog(adviceLog)
  3313. redis := service.RedisClient()
  3314. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3315. redis.Set(key, "", time.Second)
  3316. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3317. fmt.Println("keyOne", keyOne)
  3318. redis.Set(keyOne, "", time.Second)
  3319. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3320. redis.Set(keySeven, "", time.Second)
  3321. redis.Close()
  3322. }
  3323. }
  3324. }
  3325. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3326. projects := items["project"].([]interface{})
  3327. if len(projects) > 0 {
  3328. for _, project := range projects {
  3329. var p models.HisPrescriptionProject
  3330. p.PrescriptionId = prescription.ID
  3331. p.Ctime = time.Now().Unix()
  3332. p.Mtime = time.Now().Unix()
  3333. p.PatientId = patient_id
  3334. p.RecordDate = recordDateTime
  3335. p.UserOrgId = adminInfo.CurrentOrgId
  3336. p.HisPatientId = his_patient_id
  3337. p.Status = 1
  3338. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3339. if errcode > 0 {
  3340. c.ServeFailJSONWithSGJErrorCode(errcode)
  3341. return
  3342. }
  3343. service.CreateHisProjectTwo(&p)
  3344. //记录日志
  3345. byterequest, _ := json.Marshal(p)
  3346. adviceLog := models.XtDoctorAdviceLog{
  3347. UserOrgId: p.UserOrgId,
  3348. PatientId: p.PatientId,
  3349. AdminUserId: adminInfo.AdminUser.Id,
  3350. Module: 1,
  3351. ErrLog: string(byterequest),
  3352. Status: 1,
  3353. Ctime: time.Now().Unix(),
  3354. Mtime: 0,
  3355. Source: "电脑端his项目修改",
  3356. RecordDate: p.RecordDate,
  3357. }
  3358. service.CreateDoctorAdviceLog(adviceLog)
  3359. }
  3360. }
  3361. }
  3362. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3363. addition := items["addition"].([]interface{})
  3364. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3365. ctime := time.Now().Unix()
  3366. mtime := ctime
  3367. if len(addition) > 0 {
  3368. for _, item := range addition {
  3369. var s models.HisAdditionalCharge
  3370. s.PrescriptionId = prescription.ID
  3371. s.Status = 1
  3372. s.UserOrgId = adminInfo.CurrentOrgId
  3373. s.RecordDate = recordDateTime
  3374. s.CreatedTime = ctime
  3375. s.UpdatedTime = mtime
  3376. s.PatientId = patient_id
  3377. s.HisPatientId = his_patient_id
  3378. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3379. if errcode > 0 {
  3380. c.ServeFailJSONWithSGJErrorCode(errcode)
  3381. return
  3382. }
  3383. service.CreateAdditionalCharge(&s)
  3384. }
  3385. }
  3386. }
  3387. }
  3388. }
  3389. }
  3390. if err == nil {
  3391. c.ServeSuccessJSON(map[string]interface{}{
  3392. "msg": "保存成功",
  3393. })
  3394. return
  3395. } else {
  3396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3397. return
  3398. }
  3399. }
  3400. func (c *HisApiController) DeletePrescription() {
  3401. prescription_id, _ := c.GetInt64("id")
  3402. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3403. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3404. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3405. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3406. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3407. //耗材保存处方出库
  3408. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3409. //已收费和已发药限制逻辑
  3410. isCharge := false
  3411. isMedicine := false
  3412. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3413. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3414. for _, item := range new_prescriptions {
  3415. if item.IsMedicine == 1 {
  3416. isMedicine = true
  3417. }
  3418. }
  3419. for _, item := range new_prescriptions {
  3420. if item.OrderStatus == 4 {
  3421. isCharge = true
  3422. }
  3423. }
  3424. if p_err != nil {
  3425. if new_prescription.ID > 0 {
  3426. if new_prescription.OrderStatus == 2 {
  3427. isCharge = true
  3428. }
  3429. }
  3430. }
  3431. for _, item := range advices {
  3432. if item.IsMedicine == 1 {
  3433. isMedicine = true
  3434. }
  3435. }
  3436. if isCharge {
  3437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3438. return
  3439. }
  3440. if isMedicine {
  3441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3442. return
  3443. }
  3444. //已收费和已发药限制逻辑
  3445. if len(projects) > 0 {
  3446. for _, item := range projects {
  3447. service.DeletePrintInfo(item.ID) //删除打印信息
  3448. if goodOutConfig.IsOpen != 1 {
  3449. if stockConfig.IsOpen == 1 {
  3450. if item.Type == 3 && item.IsOut == 1 {
  3451. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3452. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3453. good.Total = good.Total + f_count
  3454. service.UpdateGoodInfo(&good)
  3455. operation_time := time.Now().Unix()
  3456. creater := c.GetAdminUserInfo().AdminUser.Id
  3457. //创建退库单
  3458. timeStr := time.Now().Format("2006-01-02")
  3459. timeArr := strings.Split(timeStr, "-")
  3460. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3461. total = total + 1
  3462. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3463. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3464. cancelStock := models.CancelStock{
  3465. OrderNumber: orderNumber,
  3466. OperaTime: operation_time,
  3467. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3468. Creater: creater,
  3469. Ctime: time.Now().Unix(),
  3470. Status: 1,
  3471. ReturnTime: item.RecordDate,
  3472. Type: 1,
  3473. StorehouseId: houseConfig.StorehouseOutInfo,
  3474. IsCheck: 1,
  3475. }
  3476. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3477. if msgerrkonde == gorm.ErrRecordNotFound {
  3478. service.AddSigleCancelStock(&cancelStock)
  3479. }
  3480. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3481. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3482. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3483. //查询该耗材是否出库
  3484. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3485. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3486. deaerler, _ := service.GetDealerById(info.Dealer)
  3487. var total_count int64
  3488. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3489. total_count += count
  3490. if info.ID > 0 {
  3491. if info.Count >= total_count {
  3492. //回退库存
  3493. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3494. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3495. var flush_count int64
  3496. for _, it := range goodList {
  3497. flush_count += it.StockCount
  3498. }
  3499. cancelStockInfo := models.CancelStockInfo{
  3500. GoodId: item.ProjectId,
  3501. CancelStockId: cancel.ID,
  3502. GoodTypeId: good.GoodTypeId,
  3503. Count: prescribingNumber,
  3504. Price: info.Price,
  3505. Total: 0,
  3506. ProductDate: info.ProductDate,
  3507. ExpiryDate: info.ExpiryDate,
  3508. Ctime: time.Now().Unix(),
  3509. Status: 1,
  3510. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3511. OrderNumber: cancel.OrderNumber,
  3512. Type: 0,
  3513. Dealer: deaerler.DealerName,
  3514. Manufacturer: manufacturer.ManufacturerName,
  3515. Number: info.Number,
  3516. RegisterAccount: "",
  3517. Remark: "",
  3518. WarehouseInfoId: info.WarehouseInfotId,
  3519. PatientId: info.PatientId,
  3520. RecordDate: info.SysRecordTime,
  3521. StorehouseId: houseConfig.StorehouseOutInfo,
  3522. IsCheck: 1,
  3523. }
  3524. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3525. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3526. flow := models.VmStockFlow{
  3527. WarehousingId: info.WarehouseInfotId,
  3528. GoodId: item.ProjectId,
  3529. Number: info.Number,
  3530. LicenseNumber: info.LicenseNumber,
  3531. Count: prescribingNumber,
  3532. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3533. PatientId: item.PatientId,
  3534. SystemTime: info.SysRecordTime,
  3535. ConsumableType: 7,
  3536. IsSys: 0,
  3537. WarehousingOrder: "",
  3538. WarehouseOutId: info.WarehouseOutId,
  3539. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3540. IsEdit: 0,
  3541. CancelStockId: cancel.ID,
  3542. CancelOrderNumber: cancel.OrderNumber,
  3543. Manufacturer: manufacturer.ID,
  3544. Dealer: 0,
  3545. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3546. UpdateCreator: 0,
  3547. Status: 1,
  3548. Ctime: time.Now().Unix(),
  3549. Mtime: 0,
  3550. Price: info.Price,
  3551. WarehousingDetailId: info.WarehouseInfotId,
  3552. WarehouseOutDetailId: info.ID,
  3553. CancelOutDetailId: cancelInfo.ID,
  3554. ProductDate: info.ProductDate,
  3555. ExpireDate: info.ExpiryDate,
  3556. StorehouseId: houseConfig.StorehouseOutInfo,
  3557. OverCount: flush_count,
  3558. }
  3559. service.CreateStockFlowOne(flow)
  3560. //退库数量增加
  3561. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3562. //出库数量减少
  3563. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3564. }
  3565. if info.Count < total_count {
  3566. //回退库存
  3567. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3568. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3569. var flush_count int64
  3570. for _, it := range goodList {
  3571. flush_count += it.StockCount
  3572. }
  3573. cancelStockInfo := models.CancelStockInfo{
  3574. GoodId: item.ProjectId,
  3575. CancelStockId: cancel.ID,
  3576. GoodTypeId: good.GoodTypeId,
  3577. Count: info.Count,
  3578. Price: info.Price,
  3579. Total: 0,
  3580. ProductDate: info.ProductDate,
  3581. ExpiryDate: info.ExpiryDate,
  3582. Ctime: time.Now().Unix(),
  3583. Status: 1,
  3584. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3585. OrderNumber: cancel.OrderNumber,
  3586. Type: 0,
  3587. Dealer: deaerler.DealerName,
  3588. Manufacturer: manufacturer.ManufacturerName,
  3589. Number: info.Number,
  3590. RegisterAccount: "",
  3591. Remark: "",
  3592. WarehouseInfoId: info.WarehouseInfotId,
  3593. PatientId: info.PatientId,
  3594. RecordDate: info.SysRecordTime,
  3595. StorehouseId: houseConfig.StorehouseOutInfo,
  3596. IsCheck: 1,
  3597. }
  3598. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3599. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3600. flow := models.VmStockFlow{
  3601. WarehousingId: info.WarehouseInfotId,
  3602. GoodId: item.ProjectId,
  3603. Number: info.Number,
  3604. LicenseNumber: info.LicenseNumber,
  3605. Count: info.Count,
  3606. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3607. PatientId: item.PatientId,
  3608. SystemTime: info.SysRecordTime,
  3609. ConsumableType: 7,
  3610. IsSys: 0,
  3611. WarehousingOrder: "",
  3612. WarehouseOutId: info.WarehouseOutId,
  3613. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3614. IsEdit: 0,
  3615. CancelStockId: cancel.ID,
  3616. CancelOrderNumber: cancel.OrderNumber,
  3617. Manufacturer: manufacturer.ID,
  3618. Dealer: 0,
  3619. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3620. UpdateCreator: 0,
  3621. Status: 1,
  3622. Ctime: time.Now().Unix(),
  3623. Mtime: 0,
  3624. Price: info.Price,
  3625. WarehousingDetailId: info.WarehouseInfotId,
  3626. WarehouseOutDetailId: info.ID,
  3627. CancelOutDetailId: cancelInfo.ID,
  3628. ProductDate: info.ProductDate,
  3629. ExpireDate: info.ExpiryDate,
  3630. StorehouseId: houseConfig.StorehouseOutInfo,
  3631. OverCount: flush_count,
  3632. }
  3633. service.CreateStockFlowOne(flow)
  3634. //退库数量增加
  3635. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3636. //出库数量减少
  3637. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3638. }
  3639. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3640. var flush_count int64
  3641. for _, it := range goodList {
  3642. flush_count += it.StockCount
  3643. }
  3644. //查询已出库数量
  3645. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3646. if prescribingNumber < dialysisInfo.Count {
  3647. //改变数量
  3648. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3649. }
  3650. if prescribingNumber >= dialysisInfo.Count {
  3651. //删除出库表
  3652. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3653. }
  3654. //更新库存
  3655. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3656. //更新基础库库存
  3657. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3658. }
  3659. }
  3660. }
  3661. }
  3662. //保存耗材出库
  3663. if goodOutConfig.IsOpen == 1 {
  3664. if item.Type == 3 {
  3665. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3666. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3667. good.Total = good.Total + f_count
  3668. service.UpdateGoodInfo(&good)
  3669. operation_time := time.Now().Unix()
  3670. creater := c.GetAdminUserInfo().AdminUser.Id
  3671. //创建退库单
  3672. timeStr := time.Now().Format("2006-01-02")
  3673. timeArr := strings.Split(timeStr, "-")
  3674. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3675. total = total + 1
  3676. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3677. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3678. cancelStock := models.CancelStock{
  3679. OrderNumber: orderNumber,
  3680. OperaTime: operation_time,
  3681. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3682. Creater: creater,
  3683. Ctime: time.Now().Unix(),
  3684. Status: 1,
  3685. ReturnTime: item.RecordDate,
  3686. Type: 1,
  3687. StorehouseId: houseConfig.StorehouseOutInfo,
  3688. IsCheck: 1,
  3689. }
  3690. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3691. if msgerrkonde == gorm.ErrRecordNotFound {
  3692. service.AddSigleCancelStock(&cancelStock)
  3693. }
  3694. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3695. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3696. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3697. //查询该耗材是否出库
  3698. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3699. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3700. deaerler, _ := service.GetDealerById(info.Dealer)
  3701. var total_count int64
  3702. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3703. total_count += count
  3704. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3705. var flush_count int64
  3706. for _, it := range goodList {
  3707. flush_count += it.StockCount
  3708. }
  3709. fmt.Println("历史出库数据", info.Count)
  3710. fmt.Println("出库数量", total_count)
  3711. if info.ID > 0 {
  3712. cancelStockInfo := models.CancelStockInfo{
  3713. GoodId: item.ProjectId,
  3714. CancelStockId: cancel.ID,
  3715. GoodTypeId: good.GoodTypeId,
  3716. Count: prescribingNumber,
  3717. Price: info.Price,
  3718. Total: 0,
  3719. ProductDate: info.ProductDate,
  3720. ExpiryDate: info.ExpiryDate,
  3721. Ctime: time.Now().Unix(),
  3722. Status: 1,
  3723. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3724. OrderNumber: cancel.OrderNumber,
  3725. Type: 0,
  3726. Dealer: deaerler.DealerName,
  3727. Manufacturer: manufacturer.ManufacturerName,
  3728. Number: info.Number,
  3729. RegisterAccount: "",
  3730. Remark: "",
  3731. WarehouseInfoId: info.WarehouseInfotId,
  3732. PatientId: info.PatientId,
  3733. RecordDate: info.SysRecordTime,
  3734. StorehouseId: houseConfig.StorehouseOutInfo,
  3735. IsCheck: 1,
  3736. }
  3737. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3738. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3739. //查询出库数量
  3740. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3741. //出库数据 大于 退库数量
  3742. if len(list) > 0 {
  3743. for _, it := range list {
  3744. //回退库存
  3745. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3746. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3747. var flush_count_one int64
  3748. for _, it := range goodList {
  3749. flush_count_one += it.StockCount
  3750. }
  3751. //查询该批次是否有退库数据
  3752. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3753. creater := c.GetAdminUserInfo().AdminUser.Id
  3754. flow := models.VmStockFlow{
  3755. WarehousingId: it.WarehouseInfotId,
  3756. GoodId: it.GoodId,
  3757. Number: it.Number,
  3758. LicenseNumber: it.LicenseNumber,
  3759. Count: it.Count,
  3760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3761. PatientId: it.PatientId,
  3762. SystemTime: it.SysRecordTime,
  3763. ConsumableType: 7,
  3764. IsSys: 0,
  3765. WarehousingOrder: "",
  3766. WarehouseOutId: it.WarehouseOutId,
  3767. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3768. IsEdit: 0,
  3769. CancelStockId: cancel.ID,
  3770. CancelOrderNumber: cancel.OrderNumber,
  3771. Manufacturer: manufacturer.ID,
  3772. Dealer: 0,
  3773. Creator: creater,
  3774. UpdateCreator: 0,
  3775. Status: 1,
  3776. Ctime: time.Now().Unix(),
  3777. Mtime: 0,
  3778. Price: it.Price,
  3779. WarehousingDetailId: it.WarehouseInfotId,
  3780. WarehouseOutDetailId: it.ID,
  3781. CancelOutDetailId: cancelInfo.ID,
  3782. ProductDate: it.ProductDate,
  3783. ExpireDate: it.ExpiryDate,
  3784. StorehouseId: houseConfig.StorehouseOutInfo,
  3785. OverCount: flush_count_one,
  3786. }
  3787. service.CreateStockFlowOne(flow)
  3788. //if flow.ID > 0 {
  3789. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3790. //}
  3791. }
  3792. }
  3793. //flow := models.VmStockFlow{
  3794. // WarehousingId: info.WarehouseInfotId,
  3795. // GoodId: item.ProjectId,
  3796. // Number: info.Number,
  3797. // LicenseNumber: info.LicenseNumber,
  3798. // Count: prescribingNumber,
  3799. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3800. // PatientId: item.PatientId,
  3801. // SystemTime: info.SysRecordTime,
  3802. // ConsumableType: 7,
  3803. // IsSys: 0,
  3804. // WarehousingOrder: "",
  3805. // WarehouseOutId: info.WarehouseOutId,
  3806. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3807. // IsEdit: 0,
  3808. // CancelStockId: cancel.ID,
  3809. // CancelOrderNumber: cancel.OrderNumber,
  3810. // Manufacturer: manufacturer.ID,
  3811. // Dealer: 0,
  3812. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3813. // UpdateCreator: 0,
  3814. // Status: 1,
  3815. // Ctime: time.Now().Unix(),
  3816. // Mtime: 0,
  3817. // Price: info.Price,
  3818. // WarehousingDetailId: info.WarehouseInfotId,
  3819. // WarehouseOutDetailId: info.ID,
  3820. // CancelOutDetailId: cancelInfo.ID,
  3821. // ProductDate: info.ProductDate,
  3822. // ExpireDate: info.ExpiryDate,
  3823. // StorehouseId: houseConfig.StorehouseOutInfo,
  3824. // OverCount: flush_count,
  3825. //}
  3826. //service.CreateStockFlowOne(flow)
  3827. //退库数量增加
  3828. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3829. //出库数量减少
  3830. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3831. //查询已出库数量
  3832. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3833. if prescribingNumber < dialysisInfo.Count {
  3834. //改变数量
  3835. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3836. }
  3837. if prescribingNumber >= dialysisInfo.Count {
  3838. //删除出库表
  3839. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3840. }
  3841. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3842. var flush_count_one int64
  3843. for _, it := range goodList {
  3844. flush_count_one += it.StockCount
  3845. }
  3846. //更新库存
  3847. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3848. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3849. //更新基础库库存
  3850. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3851. }
  3852. }
  3853. }
  3854. }
  3855. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3856. fmt.Println(err)
  3857. }
  3858. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3859. fmt.Println(err)
  3860. if len(advices) > 0 {
  3861. for _, item := range advices {
  3862. redis := service.RedisClient()
  3863. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3864. redis.Set(keyFive, "", time.Second)
  3865. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3866. redis.Set(keyOne, "", time.Second)
  3867. redis.Close()
  3868. }
  3869. }
  3870. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3871. if len(advices) > 0 {
  3872. for _, item := range advices {
  3873. creater := c.GetAdminUserInfo().AdminUser.Id
  3874. service.DrugAutoAddCancelInfo(item, creater)
  3875. }
  3876. }
  3877. } else {
  3878. if drugOutConfig.IsOpen == 1 {
  3879. if len(advices) > 0 {
  3880. for _, item := range advices {
  3881. creater := c.GetAdminUserInfo().AdminUser.Id
  3882. service.DrugAutoAddCancelInfo(item, creater)
  3883. }
  3884. }
  3885. } else {
  3886. if len(advices) > 0 {
  3887. for _, item := range advices {
  3888. creater := c.GetAdminUserInfo().AdminUser.Id
  3889. service.DrugAutoAddCancelInfo(item, creater)
  3890. }
  3891. }
  3892. }
  3893. }
  3894. c.ServeSuccessJSON(map[string]interface{}{
  3895. "msg": "删除成功",
  3896. })
  3897. return
  3898. }
  3899. func (c *HisApiController) DeleteDoctorAdvice() {
  3900. id, _ := c.GetInt64("id")
  3901. advice, _ := service.GetHisDoctorAdvicesById(id)
  3902. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3903. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3904. //已收费和已发药的限制逻辑
  3905. isCharge := false
  3906. isMedicine := false
  3907. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3908. //获取今天该患者所有处方,判断是否发药或者收费
  3909. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3910. for _, item := range new_prescriptions {
  3911. if item.IsMedicine == 1 {
  3912. isMedicine = true
  3913. }
  3914. }
  3915. for _, item := range new_prescriptions {
  3916. if item.OrderStatus == 4 {
  3917. isCharge = true
  3918. }
  3919. }
  3920. if isMedicine {
  3921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3922. return
  3923. }
  3924. if isCharge {
  3925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3926. return
  3927. }
  3928. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3929. for _, item := range advices {
  3930. if item.IsMedicine == 1 {
  3931. isMedicine = true
  3932. }
  3933. }
  3934. if isMedicine {
  3935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3936. return
  3937. }
  3938. if new_prescription.ID > 0 {
  3939. if new_prescription.OrderStatus == 2 {
  3940. isCharge = true
  3941. }
  3942. }
  3943. if isCharge {
  3944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3945. return
  3946. }
  3947. //已收费和已发药的限制逻辑
  3948. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3949. redis := service.RedisClient()
  3950. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3951. redis.Set(keyFive, "", time.Second)
  3952. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3953. redis.Set(keyOne, "", time.Second)
  3954. defer redis.Close()
  3955. if err == nil {
  3956. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3957. //查询是否在处方中出库
  3958. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3959. if openConfig.IsOpen != 1 {
  3960. //判断该医嘱是否执行了
  3961. if advice.ExecutionState == 1 {
  3962. creater := c.GetAdminUserInfo().AdminUser.Id
  3963. service.DrugAutoAddCancelInfo(&advice, creater)
  3964. }
  3965. }
  3966. //开启保存处方扣减功能
  3967. if openConfig.IsOpen == 1 {
  3968. creater := c.GetAdminUserInfo().AdminUser.Id
  3969. service.DrugAutoAddCancelInfo(&advice, creater)
  3970. }
  3971. } else {
  3972. if drugOutConfig.IsOpen == 1 {
  3973. //查询是否在处方中出库
  3974. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3975. if openConfig.IsOpen != 1 {
  3976. //判断该医嘱是否执行了
  3977. if advice.ExecutionState == 1 {
  3978. creater := c.GetAdminUserInfo().AdminUser.Id
  3979. service.DrugAutoAddCancelInfo(&advice, creater)
  3980. }
  3981. }
  3982. //开启保存处方扣减功能
  3983. if openConfig.IsOpen == 1 {
  3984. creater := c.GetAdminUserInfo().AdminUser.Id
  3985. service.DrugAutoAddCancelInfo(&advice, creater)
  3986. }
  3987. } else {
  3988. //判断该医嘱是否执行了
  3989. if advice.ExecutionState == 1 {
  3990. creater := c.GetAdminUserInfo().AdminUser.Id
  3991. service.DrugAutoAddCancelInfo(&advice, creater)
  3992. }
  3993. }
  3994. }
  3995. c.ServeSuccessJSON(map[string]interface{}{
  3996. "msg": "删除成功",
  3997. })
  3998. return
  3999. } else {
  4000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4001. return
  4002. }
  4003. }
  4004. func (c *HisApiController) DeleteProject() {
  4005. id, _ := c.GetInt64("id")
  4006. adminInfo := c.GetAdminUserInfo()
  4007. project, _ := service.GetHisProjectByID(id)
  4008. // var consumable models.DialysisBeforePrepare
  4009. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4010. //耗材保存处方出库
  4011. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4012. isCharge := false
  4013. isMedicine := false
  4014. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4015. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4016. for _, item := range new_prescriptions {
  4017. if item.IsMedicine == 1 {
  4018. isMedicine = true
  4019. }
  4020. }
  4021. for _, item := range new_prescriptions {
  4022. if item.OrderStatus == 4 {
  4023. isCharge = true
  4024. }
  4025. }
  4026. if isMedicine {
  4027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4028. return
  4029. }
  4030. if isCharge {
  4031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4032. return
  4033. }
  4034. if new_prescription.ID > 0 {
  4035. if new_prescription.OrderStatus == 2 {
  4036. isCharge = true
  4037. }
  4038. }
  4039. if isCharge {
  4040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4041. return
  4042. }
  4043. service.DeletePrintInfo(id)
  4044. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4045. label.Status = 0
  4046. service.CreateHisLabelRecord(&label)
  4047. fmt.Println(goodOutConfig.IsOpen)
  4048. if goodOutConfig.IsOpen != 1 {
  4049. if stockConfig.IsOpen == 1 {
  4050. if project.Type == 2 {
  4051. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4052. fmt.Println(err)
  4053. }
  4054. if project.Type == 3 && project.IsOut == 1 {
  4055. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4056. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4057. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4058. operation_time := time.Now().Unix()
  4059. creater := adminInfo.AdminUser.Id
  4060. //创建退库单
  4061. timeStr := time.Now().Format("2006-01-02")
  4062. timeArr := strings.Split(timeStr, "-")
  4063. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4064. total = total + 1
  4065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4066. cancelStock := models.CancelStock{
  4067. OrderNumber: orderNumber,
  4068. OperaTime: operation_time,
  4069. OrgId: adminInfo.CurrentOrgId,
  4070. Creater: creater,
  4071. Ctime: time.Now().Unix(),
  4072. Status: 1,
  4073. ReturnTime: project.RecordDate,
  4074. Type: 1,
  4075. StorehouseId: houseConfig.StorehouseOutInfo,
  4076. IsCheck: 1,
  4077. }
  4078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4079. if msgerrkonde == gorm.ErrRecordNotFound {
  4080. service.AddSigleCancelStock(&cancelStock)
  4081. }
  4082. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4083. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4084. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4085. //查询是否有出库
  4086. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4087. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4088. deaerler, _ := service.GetDealerById(info.Dealer)
  4089. if info.ID > 0 {
  4090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4091. if info.Count >= prescribingNumber {
  4092. cancelStockInfo := models.CancelStockInfo{
  4093. GoodId: project.ProjectId,
  4094. CancelStockId: cancel.ID,
  4095. GoodTypeId: good.GoodTypeId,
  4096. Count: prescribingNumber,
  4097. Price: info.Price,
  4098. Total: 0,
  4099. ProductDate: info.ProductDate,
  4100. ExpiryDate: info.ExpiryDate,
  4101. Ctime: time.Now().Unix(),
  4102. Status: 1,
  4103. OrgId: adminInfo.CurrentOrgId,
  4104. OrderNumber: cancel.OrderNumber,
  4105. Type: 0,
  4106. Dealer: deaerler.DealerName,
  4107. Manufacturer: manufacturer.ManufacturerName,
  4108. Number: info.Number,
  4109. RegisterAccount: "",
  4110. Remark: "",
  4111. WarehouseInfoId: info.WarehouseInfotId,
  4112. PatientId: info.PatientId,
  4113. RecordDate: info.SysRecordTime,
  4114. StorehouseId: houseConfig.StorehouseOutInfo,
  4115. IsCheck: 1,
  4116. }
  4117. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4118. //回退库存
  4119. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4120. //退库数量增加
  4121. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4122. //出库数量减少
  4123. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4124. }
  4125. if info.Count < prescribingNumber {
  4126. cancelStockInfo := models.CancelStockInfo{
  4127. GoodId: project.ProjectId,
  4128. CancelStockId: cancel.ID,
  4129. GoodTypeId: good.GoodTypeId,
  4130. Count: info.Count,
  4131. Price: info.Price,
  4132. Total: 0,
  4133. ProductDate: info.ProductDate,
  4134. ExpiryDate: info.ExpiryDate,
  4135. Ctime: time.Now().Unix(),
  4136. Status: 1,
  4137. OrgId: adminInfo.CurrentOrgId,
  4138. OrderNumber: cancel.OrderNumber,
  4139. Type: 0,
  4140. Dealer: deaerler.DealerName,
  4141. Manufacturer: manufacturer.ManufacturerName,
  4142. Number: info.Number,
  4143. RegisterAccount: "",
  4144. Remark: "",
  4145. WarehouseInfoId: info.WarehouseInfotId,
  4146. PatientId: info.PatientId,
  4147. RecordDate: info.SysRecordTime,
  4148. StorehouseId: houseConfig.StorehouseOutInfo,
  4149. IsCheck: 1,
  4150. }
  4151. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4152. //回退库存
  4153. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4154. //退库数量增加
  4155. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4156. //出库数量减少
  4157. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4158. }
  4159. //查询剩余库存
  4160. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4161. var over_count int64
  4162. for _, it := range goodList {
  4163. over_count += it.StockCount
  4164. }
  4165. //出库数据 大于 退库数量
  4166. if info.Count >= prescribingNumber {
  4167. flow := models.VmStockFlow{
  4168. WarehousingId: info.WarehouseInfotId,
  4169. GoodId: project.ProjectId,
  4170. Number: info.Number,
  4171. LicenseNumber: info.LicenseNumber,
  4172. Count: prescribingNumber,
  4173. UserOrgId: adminInfo.CurrentOrgId,
  4174. PatientId: project.PatientId,
  4175. SystemTime: info.SysRecordTime,
  4176. ConsumableType: 7,
  4177. IsSys: 0,
  4178. WarehousingOrder: "",
  4179. WarehouseOutId: info.WarehouseOutId,
  4180. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4181. IsEdit: 0,
  4182. CancelStockId: cancel.ID,
  4183. CancelOrderNumber: cancel.OrderNumber,
  4184. Manufacturer: manufacturer.ID,
  4185. Dealer: 0,
  4186. Creator: adminInfo.AdminUser.Id,
  4187. UpdateCreator: 0,
  4188. Status: 1,
  4189. Ctime: time.Now().Unix(),
  4190. Mtime: 0,
  4191. Price: info.Price,
  4192. WarehousingDetailId: info.WarehouseInfotId,
  4193. WarehouseOutDetailId: info.ID,
  4194. CancelOutDetailId: cancelInfo.ID,
  4195. ProductDate: info.ProductDate,
  4196. ExpireDate: info.ExpiryDate,
  4197. StorehouseId: houseConfig.StorehouseOutInfo,
  4198. OverCount: over_count,
  4199. }
  4200. service.CreateStockFlowOne(flow)
  4201. }
  4202. //出库数据小于退库数据
  4203. if info.Count < prescribingNumber {
  4204. flow := models.VmStockFlow{
  4205. WarehousingId: info.WarehouseInfotId,
  4206. GoodId: project.ProjectId,
  4207. Number: info.Number,
  4208. LicenseNumber: info.LicenseNumber,
  4209. Count: info.Count,
  4210. UserOrgId: adminInfo.CurrentOrgId,
  4211. PatientId: project.PatientId,
  4212. SystemTime: info.SysRecordTime,
  4213. ConsumableType: 7,
  4214. IsSys: 0,
  4215. WarehousingOrder: "",
  4216. WarehouseOutId: info.WarehouseOutId,
  4217. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4218. IsEdit: 0,
  4219. CancelStockId: cancel.ID,
  4220. CancelOrderNumber: cancel.OrderNumber,
  4221. Manufacturer: manufacturer.ID,
  4222. Dealer: 0,
  4223. Creator: adminInfo.AdminUser.Id,
  4224. UpdateCreator: 0,
  4225. Status: 1,
  4226. Ctime: time.Now().Unix(),
  4227. Mtime: 0,
  4228. Price: info.Price,
  4229. WarehousingDetailId: info.WarehouseInfotId,
  4230. WarehouseOutDetailId: info.ID,
  4231. CancelOutDetailId: cancelInfo.ID,
  4232. ProductDate: info.ProductDate,
  4233. ExpireDate: info.ExpiryDate,
  4234. StorehouseId: houseConfig.StorehouseOutInfo,
  4235. OverCount: over_count,
  4236. }
  4237. service.CreateStockFlowOne(flow)
  4238. }
  4239. //查询已出库数量
  4240. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4241. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4242. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4243. if prescribingNumber < dialysisInfo.Count {
  4244. //改变数量
  4245. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4246. }
  4247. if prescribingNumber >= dialysisInfo.Count {
  4248. //删除出库表
  4249. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4250. }
  4251. //更新剩余库存
  4252. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4253. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4254. var total_count_one int64
  4255. for _, it := range stockList {
  4256. total_count_one += it.StockCount
  4257. }
  4258. //基础库插入数据
  4259. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4260. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4261. var flush_count int64
  4262. for _, it := range goodListOne {
  4263. flush_count += it.StockCount
  4264. }
  4265. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4266. if errs != nil {
  4267. goodErrcode := models.XtGoodErrcode{
  4268. UserOrgId: project.UserOrgId,
  4269. Errcode: "手动出库更新剩余出库失败",
  4270. GoodId: project.ProjectId,
  4271. Status: 1,
  4272. Ctime: time.Now().Unix(),
  4273. Mtime: 0,
  4274. Count: 0,
  4275. StockCount: 0,
  4276. Creater: creater,
  4277. BatchNumberId: 0,
  4278. WarehouseOutId: 0,
  4279. }
  4280. service.CreateGoodErrcode(goodErrcode)
  4281. }
  4282. }
  4283. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4284. fmt.Println(err)
  4285. } else {
  4286. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4287. fmt.Println(err)
  4288. }
  4289. } else {
  4290. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4291. fmt.Println(err)
  4292. }
  4293. }
  4294. //保存处方出库
  4295. if goodOutConfig.IsOpen == 1 {
  4296. if project.Type == 3 {
  4297. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4298. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4299. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4300. operation_time := time.Now().Unix()
  4301. creater := adminInfo.AdminUser.Id
  4302. //创建退库单
  4303. timeStr := time.Now().Format("2006-01-02")
  4304. timeArr := strings.Split(timeStr, "-")
  4305. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4306. total = total + 1
  4307. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4308. cancelStock := models.CancelStock{
  4309. OrderNumber: orderNumber,
  4310. OperaTime: operation_time,
  4311. OrgId: adminInfo.CurrentOrgId,
  4312. Creater: creater,
  4313. Ctime: time.Now().Unix(),
  4314. Status: 1,
  4315. ReturnTime: project.RecordDate,
  4316. Type: 1,
  4317. StorehouseId: houseConfig.StorehouseOutInfo,
  4318. IsCheck: 1,
  4319. }
  4320. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4321. if msgerrkonde == gorm.ErrRecordNotFound {
  4322. service.AddSigleCancelStock(&cancelStock)
  4323. }
  4324. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4325. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4326. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4327. //获取出库数据
  4328. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4329. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4330. deaerler, _ := service.GetDealerById(info.Dealer)
  4331. if info.ID > 0 {
  4332. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4333. if info.Count >= prescribingNumber {
  4334. cancelStockInfo := models.CancelStockInfo{
  4335. GoodId: project.ProjectId,
  4336. CancelStockId: cancel.ID,
  4337. GoodTypeId: good.GoodTypeId,
  4338. Count: prescribingNumber,
  4339. Price: info.Price,
  4340. Total: 0,
  4341. ProductDate: info.ProductDate,
  4342. ExpiryDate: info.ExpiryDate,
  4343. Ctime: time.Now().Unix(),
  4344. Status: 1,
  4345. OrgId: adminInfo.CurrentOrgId,
  4346. OrderNumber: cancel.OrderNumber,
  4347. Type: 0,
  4348. Dealer: deaerler.DealerName,
  4349. Manufacturer: manufacturer.ManufacturerName,
  4350. Number: info.Number,
  4351. RegisterAccount: "",
  4352. Remark: "",
  4353. WarehouseInfoId: info.WarehouseInfotId,
  4354. PatientId: info.PatientId,
  4355. RecordDate: info.SysRecordTime,
  4356. StorehouseId: houseConfig.StorehouseOutInfo,
  4357. IsCheck: 1,
  4358. }
  4359. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4360. //退库数量增加
  4361. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4362. //出库数量减少
  4363. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4364. }
  4365. if info.Count < prescribingNumber {
  4366. cancelStockInfo := models.CancelStockInfo{
  4367. GoodId: project.ProjectId,
  4368. CancelStockId: cancel.ID,
  4369. GoodTypeId: good.GoodTypeId,
  4370. Count: prescribingNumber,
  4371. Price: info.Price,
  4372. Total: 0,
  4373. ProductDate: info.ProductDate,
  4374. ExpiryDate: info.ExpiryDate,
  4375. Ctime: time.Now().Unix(),
  4376. Status: 1,
  4377. OrgId: adminInfo.CurrentOrgId,
  4378. OrderNumber: cancel.OrderNumber,
  4379. Type: 0,
  4380. Dealer: deaerler.DealerName,
  4381. Manufacturer: manufacturer.ManufacturerName,
  4382. Number: info.Number,
  4383. RegisterAccount: "",
  4384. Remark: "",
  4385. WarehouseInfoId: info.WarehouseInfotId,
  4386. PatientId: info.PatientId,
  4387. RecordDate: info.SysRecordTime,
  4388. StorehouseId: houseConfig.StorehouseOutInfo,
  4389. IsCheck: 1,
  4390. }
  4391. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4392. //回退库存
  4393. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4394. }
  4395. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4396. var over_count int64
  4397. for _, it := range goodList {
  4398. over_count += it.StockCount
  4399. }
  4400. //查询出库数量
  4401. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4402. //出库数据 大于 退库数量
  4403. if len(list) > 0 {
  4404. for _, it := range list {
  4405. //回退库存
  4406. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4407. //退库数量增加
  4408. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4409. //出库数量减少
  4410. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4411. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4412. var over_count_one int64
  4413. for _, it := range goodList {
  4414. over_count_one += it.StockCount
  4415. }
  4416. //查询该批次是否有退库数据
  4417. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4418. flow := models.VmStockFlow{
  4419. WarehousingId: it.WarehouseInfotId,
  4420. GoodId: it.GoodId,
  4421. Number: it.Number,
  4422. LicenseNumber: it.LicenseNumber,
  4423. Count: it.Count,
  4424. UserOrgId: adminInfo.CurrentOrgId,
  4425. PatientId: it.PatientId,
  4426. SystemTime: it.SysRecordTime,
  4427. ConsumableType: 7,
  4428. IsSys: 0,
  4429. WarehousingOrder: "",
  4430. WarehouseOutId: it.WarehouseOutId,
  4431. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4432. IsEdit: 0,
  4433. CancelStockId: cancel.ID,
  4434. CancelOrderNumber: cancel.OrderNumber,
  4435. Manufacturer: manufacturer.ID,
  4436. Dealer: 0,
  4437. Creator: adminInfo.AdminUser.Id,
  4438. UpdateCreator: 0,
  4439. Status: 1,
  4440. Ctime: time.Now().Unix(),
  4441. Mtime: 0,
  4442. Price: it.Price,
  4443. WarehousingDetailId: it.WarehouseInfotId,
  4444. WarehouseOutDetailId: it.ID,
  4445. CancelOutDetailId: cancelInfo.ID,
  4446. ProductDate: it.ProductDate,
  4447. ExpireDate: it.ExpiryDate,
  4448. StorehouseId: houseConfig.StorehouseOutInfo,
  4449. OverCount: over_count_one,
  4450. }
  4451. service.CreateStockFlowOne(flow)
  4452. }
  4453. }
  4454. //查询已出库数量
  4455. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4456. if prescribingNumber < dialysisInfo.Count {
  4457. //改变数量
  4458. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4459. }
  4460. if prescribingNumber >= dialysisInfo.Count {
  4461. //删除出库表
  4462. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4463. }
  4464. //更新剩余库存
  4465. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4466. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4467. var total_count_one int64
  4468. for _, it := range stockList {
  4469. total_count_one += it.StockCount
  4470. }
  4471. //基础库插入数据
  4472. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4473. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4474. var flush_count int64
  4475. for _, it := range goodListOne {
  4476. flush_count += it.StockCount
  4477. }
  4478. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4479. if errs != nil {
  4480. goodErrcode := models.XtGoodErrcode{
  4481. UserOrgId: project.UserOrgId,
  4482. Errcode: "手动出库更新剩余出库失败",
  4483. GoodId: project.ProjectId,
  4484. Status: 1,
  4485. Ctime: time.Now().Unix(),
  4486. Mtime: 0,
  4487. Count: 0,
  4488. StockCount: 0,
  4489. Creater: creater,
  4490. BatchNumberId: 0,
  4491. WarehouseOutId: 0,
  4492. }
  4493. service.CreateGoodErrcode(goodErrcode)
  4494. }
  4495. }
  4496. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4497. fmt.Println(err)
  4498. } else {
  4499. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4500. fmt.Println(err)
  4501. }
  4502. }
  4503. c.ServeSuccessJSON(map[string]interface{}{
  4504. "msg": "删除成功",
  4505. })
  4506. return
  4507. }
  4508. func (c *HisApiController) CreateHisAdditionalCharge() {
  4509. his_patient_id, _ := c.GetInt64("his_patient_id")
  4510. patient_id, _ := c.GetInt64("patient_id")
  4511. record_date := c.GetString("record_date")
  4512. timeLayout := "2006-01-02"
  4513. loc, _ := time.LoadLocation("Local")
  4514. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4515. if err != nil {
  4516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4517. return
  4518. }
  4519. adminInfo := c.GetAdminUserInfo()
  4520. recordDateTime := theTime.Unix()
  4521. dataBody := make(map[string]interface{}, 0)
  4522. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4523. if err != nil {
  4524. utils.ErrorLog(err.Error())
  4525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4526. return
  4527. }
  4528. var additions []*models.HisAdditionalCharge
  4529. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4530. additions, _ := dataBody["addition"].([]interface{})
  4531. if len(additions) > 0 {
  4532. for _, item := range additions {
  4533. items := item.(map[string]interface{})
  4534. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4535. utils.ErrorLog("item_id")
  4536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4537. return
  4538. }
  4539. item_id := int64(items["item_id"].(float64))
  4540. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4541. utils.ErrorLog("item_name")
  4542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4543. return
  4544. }
  4545. item_name := items["item_name"].(string)
  4546. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4547. utils.ErrorLog("price")
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4549. return
  4550. }
  4551. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4552. ctime := time.Now().Unix()
  4553. additional := &models.HisAdditionalCharge{
  4554. PatientId: patient_id,
  4555. HisPatientId: his_patient_id,
  4556. UserOrgId: adminInfo.CurrentOrgId,
  4557. RecordDate: recordDateTime,
  4558. CreatedTime: ctime,
  4559. UpdatedTime: ctime,
  4560. Modifier: adminInfo.AdminUser.Id,
  4561. Creator: adminInfo.AdminUser.Id,
  4562. Price: price,
  4563. ItemName: item_name,
  4564. ItemId: item_id,
  4565. Status: 1,
  4566. }
  4567. additions = append(additions, additional)
  4568. }
  4569. }
  4570. }
  4571. for _, item := range additions {
  4572. service.CreateAddtionalCharge(item)
  4573. }
  4574. c.ServeSuccessJSON(map[string]interface{}{
  4575. "msg": "创建成功",
  4576. })
  4577. }
  4578. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4579. blood_fat := c.GetString("blood_fat")
  4580. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4581. blood_sugar := c.GetString("blood_sugar")
  4582. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4583. chief_conplaint := c.GetString("chief_conplaint")
  4584. dbp := c.GetString("dbp")
  4585. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4586. delivery_way, _ := c.GetInt64("delivery_way")
  4587. diagnostic := c.GetString("diagnostic")
  4588. family_history := c.GetString("family_history")
  4589. height := c.GetString("height")
  4590. history_of_present_illness := c.GetString("history_of_present_illness")
  4591. is_infect, _ := c.GetInt64("is_infect")
  4592. past_history := c.GetString("past_history")
  4593. patient_id, _ := c.GetInt64("patient_id")
  4594. his_patient_id, _ := c.GetInt64("his_patient_id")
  4595. personal_history := c.GetString("personal_history")
  4596. pulse := c.GetString("pulse")
  4597. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4598. sbp := c.GetString("sbp")
  4599. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4600. heightfloat, _ := strconv.ParseFloat(height, 64)
  4601. sicktype := c.GetString("sick_type")
  4602. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4603. symptom := c.GetString("symptom")
  4604. sick_date := c.GetString("sick_date")
  4605. temperatures := c.GetString("temperature")
  4606. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4607. record_date := c.GetString("record_date")
  4608. breathing := c.GetString("breathing")
  4609. doctor_advice := c.GetString("doctor_advice")
  4610. remark := c.GetString("remark")
  4611. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4612. sick, _ := c.GetInt64("sick")
  4613. diagnose, _ := c.GetInt64("diagnose")
  4614. //id, _ := c.GetInt64("id")
  4615. timeLayout := "2006-01-02"
  4616. loc, _ := time.LoadLocation("Local")
  4617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4618. allergic_history := c.GetString("allergic_history")
  4619. if err != nil {
  4620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4621. return
  4622. }
  4623. recordDateTime := theTime.Unix()
  4624. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4625. if err != nil {
  4626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4627. return
  4628. }
  4629. sickTimes := sickTime.Unix()
  4630. ctime := time.Now().Unix()
  4631. primary_disease := c.GetString("primary_disease")
  4632. confirm_failure_date := c.GetString("confirm_failure_date")
  4633. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4634. drug_allergy_history := c.GetString("drug_allergy_history")
  4635. physical_examination := c.GetString("physical_examination")
  4636. special_inspection := c.GetString("special_inspection")
  4637. lab_apparatus := c.GetString("lab_apparatus")
  4638. caseHistory := models.HisPatientCaseHistory{
  4639. HisPatientId: his_patient_id,
  4640. PatientId: patient_id,
  4641. Temperature: temperature,
  4642. BloodSugar: bloodsugarfloat,
  4643. Pulse: pulsefloat,
  4644. Sbp: sbpfloat,
  4645. Dbp: dbpfloat,
  4646. Height: heightfloat,
  4647. BloodFat: bloodfatfloat,
  4648. SickType: sick_type,
  4649. Symptom: symptom,
  4650. SickDate: sickTimes,
  4651. IsInfect: is_infect,
  4652. HistoryOfPresentIllness: history_of_present_illness,
  4653. PastHistory: past_history,
  4654. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4655. ChiefConplaint: chief_conplaint,
  4656. PersonalHistory: personal_history,
  4657. FamilyHistory: family_history,
  4658. Diagnostic: diagnostic,
  4659. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4660. Status: 1,
  4661. Ctime: ctime,
  4662. Mtime: ctime,
  4663. RecordDate: recordDateTime,
  4664. DeliveryWay: delivery_way,
  4665. Breathing: breathingfloat,
  4666. DoctorAdvice: doctor_advice,
  4667. Remark: remark,
  4668. Sick: sick,
  4669. Diagnose: diagnose,
  4670. AllergicHistory: allergic_history,
  4671. PrimaryDisease: primary_disease,
  4672. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4673. DrugAllergyHistory: drug_allergy_history,
  4674. PhysicalExamination: physical_examination,
  4675. SpecialInspection: special_inspection,
  4676. LabApparatus: lab_apparatus,
  4677. }
  4678. //查询该患者是否有病历
  4679. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4680. if errcodes == gorm.ErrRecordNotFound {
  4681. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4682. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4683. if err != nil {
  4684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4685. return
  4686. }
  4687. c.ServeSuccessJSON(map[string]interface{}{
  4688. "caseHistory": caseHistory,
  4689. "historyInfo": historyInfo,
  4690. })
  4691. return
  4692. } else if errcodes == nil {
  4693. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4694. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4695. if err != nil {
  4696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4697. return
  4698. }
  4699. c.ServeSuccessJSON(map[string]interface{}{
  4700. "caseHistory": caseHistory,
  4701. "historyInfo": historyInfo,
  4702. })
  4703. }
  4704. //查询该患者是否有病历
  4705. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4706. //if errcode == gorm.ErrRecordNotFound {
  4707. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4708. // if err != nil {
  4709. // c.ServeSuccessJSON(map[string]interface{}{
  4710. // "msg": "保存成功",
  4711. // })
  4712. // }
  4713. //} else if errcode == nil {
  4714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4715. // return
  4716. //}
  4717. }
  4718. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4719. patient_id, _ := c.GetInt64("patient_id", 0)
  4720. adminUser := c.GetAdminUserInfo()
  4721. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4722. c.ServeSuccessJSON(map[string]interface{}{
  4723. "list": caseHistorys,
  4724. })
  4725. }
  4726. func (c *HisApiController) GetHisPatientCaseHistory() {
  4727. record_date, _ := c.GetInt64("record_date", 0)
  4728. patient_id, _ := c.GetInt64("patient_id", 0)
  4729. admin := c.GetAdminUserInfo()
  4730. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4731. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4732. c.ServeSuccessJSON(map[string]interface{}{
  4733. "info": info,
  4734. "case_history": case_history,
  4735. })
  4736. }
  4737. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4738. template_name := c.GetString("template_name")
  4739. template_remark := c.GetString("template_remark")
  4740. doctor := c.GetAdminUserInfo().AdminUser.Id
  4741. diagnostic := c.GetString("diagnostic")
  4742. chief_conplaint := c.GetString("chief_conplain")
  4743. history_of_present_illness := c.GetString("history_of_present_illness")
  4744. past_history := c.GetString("past_history")
  4745. personal_history := c.GetString("personal_history")
  4746. family_history := c.GetString("family_history")
  4747. user_name := c.GetString("user_name")
  4748. doctor_advice := c.GetString("doctor_advice")
  4749. remark := c.GetString("remark")
  4750. //record_date := c.GetString("record_date")
  4751. //fmt.Println("record_date--------",record_date)
  4752. //timeLayout := "2006-01-02"
  4753. //loc, _ := time.LoadLocation("Local")
  4754. //
  4755. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4756. //if err != nil {
  4757. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4758. // return
  4759. //}
  4760. //recordDateTime := theTime.Unix()
  4761. ctime := time.Now().Unix()
  4762. template := models.HisCaseHistoryTemplate{
  4763. HistoryOfPresentIllness: history_of_present_illness,
  4764. PastHistory: past_history,
  4765. ChiefConplaint: chief_conplaint,
  4766. PersonalHistory: personal_history,
  4767. FamilyHistory: family_history,
  4768. Diagnostic: diagnostic,
  4769. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4770. Status: 1,
  4771. Ctime: ctime,
  4772. Mtime: ctime,
  4773. RecordDate: time.Now().Unix(),
  4774. TemplateName: template_name,
  4775. TemplateRemark: template_remark,
  4776. Creator: doctor,
  4777. Modifier: doctor,
  4778. UserName: user_name,
  4779. DoctorAdvice: doctor_advice,
  4780. Remark: remark,
  4781. }
  4782. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4783. if err == nil {
  4784. c.ServeSuccessJSON(map[string]interface{}{
  4785. "msg": "保存成功",
  4786. })
  4787. } else {
  4788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4789. return
  4790. }
  4791. }
  4792. func (c *HisApiController) GetCaseHistoryTemplate() {
  4793. timeLayout := "2006-01-02"
  4794. loc, _ := time.LoadLocation("Local")
  4795. keyword := c.GetString("keyword")
  4796. start_time := c.GetString("start_time")
  4797. end_time := c.GetString("end_time")
  4798. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4799. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4800. admin := c.GetAdminUserInfo()
  4801. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4802. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4803. c.ServeSuccessJSON(map[string]interface{}{
  4804. "template": template,
  4805. //"history": history,
  4806. })
  4807. }
  4808. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4809. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4810. utils.ErrorLog("drug_name")
  4811. return enums.ErrorCodeParamWrong
  4812. }
  4813. adviceName, _ := json["drug_name"].(string)
  4814. if len(adviceName) == 0 {
  4815. utils.ErrorLog("len(advice_name) == 0")
  4816. return enums.ErrorCodeParamWrong
  4817. }
  4818. advice.AdviceName = adviceName
  4819. adviceDesc, _ := json["advice_desc"].(string)
  4820. advice.AdviceDesc = adviceDesc
  4821. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4822. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4823. advice.DrugSpec = drugSpec
  4824. }
  4825. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4826. remark, _ := json["remark"].(string)
  4827. advice.Remark = remark
  4828. }
  4829. if json["id"] == nil {
  4830. advice.DrugId = 0
  4831. } else {
  4832. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4833. drug_id := int64(json["id"].(float64))
  4834. advice.DrugId = drug_id
  4835. }
  4836. }
  4837. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4838. advice_id := int64(json["advice_id"].(float64))
  4839. advice.ID = advice_id
  4840. if advice.ID > 0 {
  4841. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4842. if err == nil {
  4843. if hisAdvice.ID > 0 {
  4844. advice.ExecutionTime = hisAdvice.ExecutionTime
  4845. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4846. advice.ExecutionState = hisAdvice.ExecutionState
  4847. advice.CheckTime = hisAdvice.CheckTime
  4848. advice.Checker = hisAdvice.Checker
  4849. advice.CheckState = hisAdvice.CheckState
  4850. advice.StartTime = hisAdvice.StartTime
  4851. advice.FeedetlSn = hisAdvice.FeedetlSn
  4852. }
  4853. }
  4854. }
  4855. }
  4856. //
  4857. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4858. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4859. // advice.ExecutionTime = execution_time
  4860. //}
  4861. //
  4862. //
  4863. //
  4864. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4865. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4866. // advice.ExecutionStaff = execution_staff
  4867. //}
  4868. //
  4869. //
  4870. //
  4871. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4872. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4873. // advice.ExecutionState = execution_state
  4874. //}
  4875. //
  4876. //
  4877. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4878. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4879. // advice.CheckTime = check_time
  4880. //}
  4881. //
  4882. //
  4883. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4884. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4885. // advice.CheckState = check_state
  4886. //}
  4887. //
  4888. //
  4889. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4890. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4891. // advice.Checker = checker
  4892. //}
  4893. //
  4894. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4895. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4896. // advice.StartTime = start_time
  4897. //}
  4898. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4899. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4900. advice.IsSelfDrug = is_self_drug
  4901. }
  4902. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4903. drugSpecUnit, _ := json["min_unit"].(string)
  4904. advice.DrugSpecUnit = drugSpecUnit
  4905. }
  4906. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4907. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4908. advice.SingleDose = singleDose
  4909. }
  4910. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4911. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4912. advice.SingleDoseUnit = singleDoseUnit
  4913. }
  4914. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4915. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4916. advice.PrescribingNumber = prescribingNumber
  4917. }
  4918. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4919. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4920. advice.PrescribingNumberUnit = prescribingNumberUnit
  4921. }
  4922. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4923. deliveryWay, _ := json["delivery_way"].(string)
  4924. advice.DeliveryWay = deliveryWay
  4925. }
  4926. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4927. executionFrequency, _ := json["execution_frequency"].(string)
  4928. advice.ExecutionFrequency = executionFrequency
  4929. }
  4930. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4931. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4932. advice.Price = price
  4933. }
  4934. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4935. med_list_codg, _ := json["medical_insurance_number"].(string)
  4936. advice.MedListCodg = med_list_codg
  4937. }
  4938. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4939. day := int64(json["day"].(float64))
  4940. advice.Day = day
  4941. }
  4942. return 0
  4943. }
  4944. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4945. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4946. id := int64(json["id"].(float64))
  4947. project.ID = id
  4948. historyProject, _ := service.GetHisProjectByID(id)
  4949. project.FeedetlSn = historyProject.FeedetlSn
  4950. }
  4951. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4952. project_id := int64(json["project_id"].(float64))
  4953. project.ProjectId = project_id
  4954. }
  4955. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4956. // price := int64(json["price"].(float64))
  4957. // formatInt_price := strconv.FormatInt(price, 10)
  4958. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4959. // project.Price = float_price
  4960. // }
  4961. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4962. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4963. project.Price = price
  4964. }
  4965. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4966. total, _ := json["total"].(string)
  4967. project.Count = total
  4968. }
  4969. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4970. medical_code, _ := json["medical_code"].(string)
  4971. project.MedListCodg = medical_code
  4972. }
  4973. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4974. single_dose, _ := json["single_dose"].(string)
  4975. project.SingleDose = single_dose
  4976. }
  4977. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4978. delivery_way, _ := json["delivery_way"].(string)
  4979. project.DeliveryWay = delivery_way
  4980. }
  4981. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4982. execution_frequency, _ := json["execution_frequency"].(string)
  4983. project.ExecutionFrequency = execution_frequency
  4984. }
  4985. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4986. remark, _ := json["remark"].(string)
  4987. project.Remark = remark
  4988. }
  4989. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4990. day, _ := json["number_days"].(string)
  4991. project.Day = day
  4992. }
  4993. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4994. unit, _ := json["unit"].(string)
  4995. project.Unit = unit
  4996. }
  4997. return 0
  4998. }
  4999. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5000. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5001. id := int64(json["id"].(float64))
  5002. historyAddtions, _ := service.GetHisAdditionByID(id)
  5003. additionalCharge.ID = id
  5004. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5005. }
  5006. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5007. item_id := int64(json["item_id"].(float64))
  5008. additionalCharge.ItemId = item_id
  5009. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5010. if config.ID > 0 {
  5011. if len(config.Code) > 0 {
  5012. additionalCharge.MedListCodg = config.Code
  5013. }
  5014. }
  5015. }
  5016. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5017. // price := int64(json["price"].(float64))
  5018. // formatInt_price := strconv.FormatInt(price, 10)
  5019. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5020. // additionalCharge.Price = float_price
  5021. // }
  5022. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5023. // price := int64(json["price"].(float64))
  5024. // formatInt_price := strconv.FormatInt(price, 10)
  5025. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5026. // additionalCharge.Price = float_price
  5027. //}
  5028. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5029. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5030. additionalCharge.Price = price
  5031. }
  5032. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5033. count, _ := json["count"].(string)
  5034. counts, _ := strconv.ParseInt(count, 10, 64)
  5035. additionalCharge.Count = counts
  5036. }
  5037. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5038. item_name, _ := json["item_name"].(string)
  5039. additionalCharge.ItemName = item_name
  5040. }
  5041. return 0
  5042. }
  5043. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5044. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5045. utils.ErrorLog("drug_name")
  5046. return enums.ErrorCodeParamWrong
  5047. }
  5048. adviceName, _ := json["drug_name"].(string)
  5049. if len(adviceName) == 0 {
  5050. utils.ErrorLog("len(advice_name) == 0")
  5051. return enums.ErrorCodeParamWrong
  5052. }
  5053. advice.AdviceName = adviceName
  5054. adviceDesc, _ := json["advice_desc"].(string)
  5055. advice.AdviceDesc = adviceDesc
  5056. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5057. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5058. advice.DrugSpec = drugSpec
  5059. }
  5060. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5061. remark, _ := json["remark"].(string)
  5062. advice.Remark = remark
  5063. }
  5064. if json["id"] == nil {
  5065. advice.DrugId = 0
  5066. } else {
  5067. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5068. drug_id := int64(json["id"].(float64))
  5069. advice.DrugId = drug_id
  5070. }
  5071. }
  5072. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5073. groupno := int64(json["groupno"].(float64))
  5074. advice.Groupno = groupno
  5075. }
  5076. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5077. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5078. advice.IsSelfDrug = is_self_drug
  5079. }
  5080. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5081. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5082. advice.HospApprFlag = hosp_appr_flag
  5083. }
  5084. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5085. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5086. advice.PrescribingNumber = prescribingNumber
  5087. }
  5088. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5089. // frequency_type := int64(json["frequency_type"].(float64))
  5090. // advice.FrequencyType = frequency_type
  5091. //}
  5092. //
  5093. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5094. // day_count := int64(json["day_count"].(float64))
  5095. // advice.DayCount = day_count
  5096. //}
  5097. //
  5098. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5099. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5100. // week_day, _ := json["week_day"].(string)
  5101. // advice.WeekDay = week_day
  5102. //}
  5103. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5104. drugSpecUnit, _ := json["min_unit"].(string)
  5105. advice.DrugSpecUnit = drugSpecUnit
  5106. }
  5107. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5108. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5109. advice.SingleDose = singleDose
  5110. }
  5111. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5112. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5113. advice.SingleDoseUnit = singleDoseUnit
  5114. }
  5115. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5116. deliveryWay, _ := json["delivery_way"].(string)
  5117. advice.DeliveryWay = deliveryWay
  5118. }
  5119. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5120. executionFrequency, _ := json["execution_frequency"].(string)
  5121. advice.ExecutionFrequency = executionFrequency
  5122. }
  5123. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5124. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5125. advice.Price = price
  5126. }
  5127. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5128. med_list_codg, _ := json["medical_insurance_number"].(string)
  5129. advice.MedListCodg = med_list_codg
  5130. }
  5131. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5132. day := int64(json["day"].(float64))
  5133. advice.Day = day
  5134. }
  5135. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5136. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5137. advice.PrescribingNumberUnit = prescribingNumberUnit
  5138. }
  5139. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5140. advice_id := int64(json["advice_id"].(float64))
  5141. advice.ID = advice_id
  5142. if advice.ID > 0 {
  5143. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5144. if err == nil {
  5145. if hisAdvice.ID > 0 {
  5146. advice.ExecutionTime = hisAdvice.ExecutionTime
  5147. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5148. advice.ExecutionState = hisAdvice.ExecutionState
  5149. advice.CheckTime = hisAdvice.CheckTime
  5150. advice.Checker = hisAdvice.Checker
  5151. advice.CheckState = hisAdvice.CheckState
  5152. advice.StartTime = hisAdvice.StartTime
  5153. advice.HospApprFlag = hisAdvice.HospApprFlag
  5154. advice.IsMedicine = hisAdvice.IsMedicine
  5155. if hisAdvice.UserOrgId == 10028 {
  5156. 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 {
  5157. advice.ExecutionTime = 0
  5158. advice.ExecutionStaff = 0
  5159. advice.ExecutionState = 2
  5160. advice.CheckTime = 0
  5161. advice.Checker = 0
  5162. advice.CheckState = 2
  5163. }
  5164. } else {
  5165. 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 {
  5166. advice.ExecutionTime = 0
  5167. advice.ExecutionStaff = 0
  5168. advice.ExecutionState = 2
  5169. advice.CheckTime = 0
  5170. advice.Checker = 0
  5171. advice.CheckState = 2
  5172. }
  5173. }
  5174. //advice.Groupno = hisAdvice.Groupno
  5175. }
  5176. }
  5177. }
  5178. }
  5179. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5180. //
  5181. //if drugStockConfig.IsOpen == 1 {
  5182. //
  5183. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5184. // if advice.ID == 0 { //医嘱不存在
  5185. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5186. // drug.Total = drug.Total - advice.PrescribingNumber
  5187. // service.UpdateBaseDrugLib(&drug)
  5188. //
  5189. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5190. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5191. // drug.Total = drug.Total - num
  5192. // service.UpdateBaseDrugLib(&drug)
  5193. // }
  5194. //
  5195. // } else if advice.ID > 0 { //医嘱存在
  5196. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5197. // var num float64
  5198. //
  5199. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5200. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5201. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5202. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5203. // drug.Total = drug.Total + num
  5204. // service.UpdateBaseDrugLib(&drug)
  5205. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5206. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5207. // drug.Total = drug.Total - num
  5208. // service.UpdateBaseDrugLib(&drug)
  5209. // }
  5210. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5211. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5212. // if num2 > advice.PrescribingNumber {
  5213. // num = num2 - advice.PrescribingNumber
  5214. // drug.Total = drug.Total + num
  5215. // service.UpdateBaseDrugLib(&drug)
  5216. // } else if num2 < advice.PrescribingNumber {
  5217. // num = advice.PrescribingNumber - num2
  5218. // drug.Total = drug.Total - num
  5219. // service.UpdateBaseDrugLib(&drug)
  5220. // }
  5221. //
  5222. // }
  5223. //
  5224. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5225. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5226. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5227. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5228. // if num1 > num2 {
  5229. // num = num1 - num2
  5230. // drug.Total = drug.Total + num
  5231. // service.UpdateBaseDrugLib(&drug)
  5232. // } else if num1 < num2 {
  5233. // num = num2 - num1
  5234. // drug.Total = drug.Total - num
  5235. // service.UpdateBaseDrugLib(&drug)
  5236. // }
  5237. //
  5238. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5239. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5240. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5241. // if hisAdvice.PrescribingNumber > num2 {
  5242. // num = hisAdvice.PrescribingNumber - num2
  5243. // drug.Total = drug.Total + num
  5244. // service.UpdateBaseDrugLib(&drug)
  5245. // } else if num2 < advice.PrescribingNumber {
  5246. // num = num2 - hisAdvice.PrescribingNumber
  5247. // drug.Total = drug.Total - num
  5248. // service.UpdateBaseDrugLib(&drug)
  5249. // }
  5250. //
  5251. // }
  5252. // }
  5253. // }
  5254. //}
  5255. //
  5256. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5257. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5258. // advice.ExecutionTime = execution_time
  5259. //}
  5260. //
  5261. //
  5262. //
  5263. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5264. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5265. // advice.ExecutionStaff = execution_staff
  5266. //}
  5267. //
  5268. //
  5269. //
  5270. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5271. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5272. // advice.ExecutionState = execution_state
  5273. //}
  5274. //
  5275. //
  5276. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5277. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5278. // advice.CheckTime = check_time
  5279. //}
  5280. //
  5281. //
  5282. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5283. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5284. // advice.CheckState = check_state
  5285. //}
  5286. //
  5287. //
  5288. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5289. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5290. // advice.Checker = checker
  5291. //}
  5292. //
  5293. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5294. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5295. // advice.StartTime = start_time
  5296. //}
  5297. return 0
  5298. }
  5299. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5300. project.ExecutionStaff = 0
  5301. project.ExecutionState = 2
  5302. project.ExecutionTime = 0
  5303. project.Checker = 0
  5304. project.CheckState = 2
  5305. project.CheckTime = 0
  5306. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5307. id := int64(json["id"].(float64))
  5308. project.ID = id
  5309. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5310. project.ExecutionStaff = temp_project.ExecutionStaff
  5311. project.ExecutionState = temp_project.ExecutionState
  5312. project.ExecutionTime = temp_project.ExecutionTime
  5313. project.Checker = temp_project.Checker
  5314. project.CheckState = temp_project.CheckState
  5315. project.CheckTime = temp_project.CheckTime
  5316. project.TeamId = temp_project.TeamId
  5317. }
  5318. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5319. types := int64(json["type"].(float64))
  5320. project.Type = types
  5321. }
  5322. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5323. project_id := int64(json["project_id"].(float64))
  5324. project.ProjectId = project_id
  5325. }
  5326. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5327. team_id := int64(json["team_id"].(float64))
  5328. project.TeamId = team_id
  5329. }
  5330. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5331. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5332. project.Price = price
  5333. }
  5334. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5335. total, _ := json["total"].(string)
  5336. //totals, _ := strconv.ParseInt(total, 10, 64)
  5337. project.Count = total
  5338. }
  5339. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5340. medical_code, _ := json["medical_code"].(string)
  5341. project.MedListCodg = medical_code
  5342. }
  5343. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5344. single_dose, _ := json["single_dose"].(string)
  5345. project.SingleDose = single_dose
  5346. }
  5347. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5348. delivery_way, _ := json["delivery_way"].(string)
  5349. project.DeliveryWay = delivery_way
  5350. }
  5351. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5352. execution_frequency, _ := json["execution_frequency"].(string)
  5353. project.ExecutionFrequency = execution_frequency
  5354. }
  5355. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5356. remark, _ := json["remark"].(string)
  5357. project.Remark = remark
  5358. }
  5359. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5360. day, _ := json["number_days"].(string)
  5361. project.Day = day
  5362. }
  5363. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5364. unit, _ := json["unit"].(string)
  5365. project.Unit = unit
  5366. }
  5367. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5368. // frequency_type := int64(json["frequency_type"].(float64))
  5369. // project.FrequencyType = frequency_type
  5370. //}
  5371. //
  5372. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5373. // day_count := int64(json["day_count"].(float64))
  5374. // project.DayCount = day_count
  5375. //}
  5376. //
  5377. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5378. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5379. // week_day, _ := json["week_day"].(string)
  5380. // project.WeekDay = week_day
  5381. //}
  5382. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5383. //
  5384. //if project.ID == 0 {
  5385. // if stockConfig.IsOpen == 1 {
  5386. // if project.Type == 3 {
  5387. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5388. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5389. // good.Total = good.Total - f_count
  5390. // service.UpdateGoodInfo(&good)
  5391. // }
  5392. // }
  5393. //
  5394. //} else {
  5395. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5396. //
  5397. // if stockConfig.IsOpen == 1 {
  5398. // if project.Type == 3 {
  5399. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5400. // if project.Count < temp_project.Count {
  5401. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5402. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5403. //
  5404. // other_count := f_count_two - f_count_one
  5405. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5406. // good.Total = good.Total + other_count_two
  5407. // service.UpdateGoodInfo(&good)
  5408. // } else if project.Count > temp_project.Count {
  5409. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5410. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5411. //
  5412. // other_count := f_count_one - f_count_two
  5413. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5414. // good.Total = good.Total - other_count_two
  5415. // service.UpdateGoodInfo(&good)
  5416. // }
  5417. //
  5418. // }
  5419. // }
  5420. //
  5421. //}
  5422. return 0
  5423. }
  5424. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5425. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5426. id := int64(json["id"].(float64))
  5427. additionalCharge.ID = id
  5428. }
  5429. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5430. item_id := int64(json["item_id"].(float64))
  5431. additionalCharge.ItemId = item_id
  5432. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5433. if config.ID > 0 {
  5434. if len(config.Code) > 0 {
  5435. additionalCharge.MedListCodg = config.Code
  5436. }
  5437. }
  5438. }
  5439. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5440. // price := int64(json["price"].(float64))
  5441. // formatInt_price := strconv.FormatInt(price, 10)
  5442. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5443. // additionalCharge.Price = float_price
  5444. // }
  5445. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5446. // price := int64(json["price"].(float64))
  5447. // formatInt_price := strconv.FormatInt(price, 10)
  5448. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5449. // additionalCharge.Price = float_price
  5450. //}
  5451. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5452. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5453. additionalCharge.Price = price
  5454. }
  5455. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5456. count, _ := json["count"].(string)
  5457. counts, _ := strconv.ParseInt(count, 10, 64)
  5458. additionalCharge.Count = counts
  5459. }
  5460. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5461. item_name, _ := json["item_name"].(string)
  5462. additionalCharge.ItemName = item_name
  5463. }
  5464. return 0
  5465. }
  5466. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5467. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5468. utils.ErrorLog("drug_name")
  5469. return enums.ErrorCodeParamWrong
  5470. }
  5471. adviceName, _ := json["drug_name"].(string)
  5472. if len(adviceName) == 0 {
  5473. utils.ErrorLog("len(advice_name) == 0")
  5474. return enums.ErrorCodeParamWrong
  5475. }
  5476. advice.AdviceName = adviceName
  5477. adviceDesc, _ := json["advice_desc"].(string)
  5478. advice.AdviceDesc = adviceDesc
  5479. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5480. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5481. advice.DrugSpec = drugSpec
  5482. }
  5483. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5484. remark, _ := json["remark"].(string)
  5485. advice.Remark = remark
  5486. }
  5487. if json["id"] == nil {
  5488. advice.DrugId = 0
  5489. } else {
  5490. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5491. drug_id := int64(json["id"].(float64))
  5492. advice.DrugId = drug_id
  5493. }
  5494. }
  5495. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5496. groupno := int64(json["groupno"].(float64))
  5497. advice.Groupno = groupno
  5498. }
  5499. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5500. drugSpecUnit, _ := json["min_unit"].(string)
  5501. advice.DrugSpecUnit = drugSpecUnit
  5502. }
  5503. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5504. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5505. advice.SingleDose = singleDose
  5506. }
  5507. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5508. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5509. advice.SingleDoseUnit = singleDoseUnit
  5510. }
  5511. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5512. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5513. advice.PrescribingNumber = prescribingNumber
  5514. }
  5515. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5516. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5517. advice.PrescribingNumberUnit = prescribingNumberUnit
  5518. }
  5519. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5520. deliveryWay, _ := json["delivery_way"].(string)
  5521. advice.DeliveryWay = deliveryWay
  5522. }
  5523. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5524. executionFrequency, _ := json["execution_frequency"].(string)
  5525. advice.ExecutionFrequency = executionFrequency
  5526. }
  5527. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5528. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5529. advice.Price = price
  5530. }
  5531. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5532. med_list_codg, _ := json["medical_insurance_number"].(string)
  5533. advice.MedListCodg = med_list_codg
  5534. }
  5535. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5536. day := int64(json["day"].(float64))
  5537. advice.Day = day
  5538. }
  5539. advice.FrequencyType = 1
  5540. return 0
  5541. }
  5542. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5543. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5544. types := int64(json["type"].(float64))
  5545. project.Type = types
  5546. }
  5547. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5548. project_id := int64(json["project_id"].(float64))
  5549. project.ProjectId = project_id
  5550. }
  5551. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5552. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5553. project.Price = price
  5554. }
  5555. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5556. total, _ := json["total"].(string)
  5557. //totals, _ := strconv.ParseInt(total, 10, 64)
  5558. project.Count = total
  5559. }
  5560. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5561. medical_code, _ := json["medical_code"].(string)
  5562. project.MedListCodg = medical_code
  5563. }
  5564. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5565. single_dose, _ := json["single_dose"].(string)
  5566. project.SingleDose = single_dose
  5567. }
  5568. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5569. delivery_way, _ := json["delivery_way"].(string)
  5570. project.DeliveryWay = delivery_way
  5571. }
  5572. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5573. execution_frequency, _ := json["execution_frequency"].(string)
  5574. project.ExecutionFrequency = execution_frequency
  5575. }
  5576. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5577. remark, _ := json["remark"].(string)
  5578. project.Remark = remark
  5579. }
  5580. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5581. day, _ := json["number_days"].(string)
  5582. project.Day = day
  5583. }
  5584. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5585. unit, _ := json["unit"].(string)
  5586. project.Unit = unit
  5587. }
  5588. project.FrequencyType = 1
  5589. return 0
  5590. }
  5591. func (c *HisApiController) GetHisOrderList() {
  5592. page, _ := c.GetInt64("page", -1)
  5593. limit, _ := c.GetInt64("limit", -1)
  5594. start_time := c.GetString("start_time")
  5595. end_time := c.GetString("end_time")
  5596. types, _ := c.GetInt64("type", 0)
  5597. keywords := c.GetString("keywords")
  5598. p_type, _ := c.GetInt64("p_type", 0)
  5599. sort_type, _ := c.GetInt64("sort_type", 0)
  5600. charge_type, _ := c.GetInt64("charge_type", 0)
  5601. sch_type, _ := c.GetInt64("sch_type", 0)
  5602. zone_type, _ := c.GetInt64("zone_type", 0)
  5603. med_type, _ := c.GetInt64("med_type", 0)
  5604. timeLayout := "2006-01-02"
  5605. loc, _ := time.LoadLocation("Local")
  5606. var startTime int64
  5607. if len(start_time) > 0 {
  5608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5609. if err != nil {
  5610. //fmt.Println(err)
  5611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5612. return
  5613. }
  5614. startTime = theTime.Unix()
  5615. }
  5616. var endTime int64
  5617. if len(end_time) > 0 {
  5618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5619. if err != nil {
  5620. utils.ErrorLog(err.Error())
  5621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5622. return
  5623. }
  5624. endTime = theTime.Unix()
  5625. }
  5626. adminUser := c.GetAdminUserInfo()
  5627. org_id := adminUser.CurrentOrgId
  5628. 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)
  5629. for _, item := range order {
  5630. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5631. item.DoctorName = info.Doctor
  5632. item.DepartmentName = info.XtHisDepartment.Name
  5633. }
  5634. if err == nil {
  5635. c.ServeSuccessJSON(map[string]interface{}{
  5636. "order": order,
  5637. "total": total,
  5638. })
  5639. } else {
  5640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5641. return
  5642. }
  5643. }
  5644. func (c *HisApiController) GetHisOrder() {
  5645. patient_id, _ := c.GetInt64("patient_id", 0)
  5646. number := c.GetString("number")
  5647. adminInfo := c.GetAdminUserInfo()
  5648. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5649. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5650. if err == nil {
  5651. c.ServeSuccessJSON(map[string]interface{}{
  5652. "order": order,
  5653. "prescription": prescriptions,
  5654. })
  5655. } else {
  5656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5657. return
  5658. }
  5659. }
  5660. func (c *HisApiController) GetHisPrescriptionList() {
  5661. record_date := c.GetString("record_date")
  5662. keywords := c.GetString("keywords")
  5663. page, _ := c.GetInt64("page")
  5664. limit, _ := c.GetInt64("limit")
  5665. sch_type, _ := c.GetInt64("sch_type")
  5666. timeLayout := "2006-01-02"
  5667. loc, _ := time.LoadLocation("Local")
  5668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5669. if err != nil {
  5670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5671. return
  5672. }
  5673. recordDateTime := theTime.Unix()
  5674. adminInfo := c.GetAdminUserInfo()
  5675. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5676. //adminInfo := c.GetAdminUserInfo()
  5677. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5678. //fmt.Println(prescriptionOrder)
  5679. if err == nil {
  5680. c.ServeSuccessJSON(map[string]interface{}{
  5681. "order": prescriptionOrder,
  5682. "total": total,
  5683. })
  5684. } else {
  5685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5686. return
  5687. }
  5688. }
  5689. func (c *HisApiController) GetHisPrescriptionInfo() {
  5690. id, _ := c.GetInt64("id")
  5691. adminInfo := c.GetAdminUserInfo()
  5692. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5693. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5694. if err == nil {
  5695. c.ServeSuccessJSON(map[string]interface{}{
  5696. "order": prescriptionOrder,
  5697. "prescription": prescription,
  5698. })
  5699. } else {
  5700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5701. return
  5702. }
  5703. }
  5704. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5705. adminUser := c.GetAdminUserInfo()
  5706. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5707. c.ServeSuccessJSON(map[string]interface{}{
  5708. "config": config,
  5709. })
  5710. }
  5711. type ResultTwo struct {
  5712. ErrMsg interface{} `json:"err_msg"`
  5713. InfRefmsgid string `json:"inf_refmsgid"`
  5714. Infcode int64 `json:"infcode"`
  5715. Output struct {
  5716. Baseinfo struct {
  5717. Age float64 `json:"age"`
  5718. Brdy string `json:"brdy"`
  5719. Certno string `json:"certno"`
  5720. Gend string `json:"gend"`
  5721. Naty string `json:"naty"`
  5722. PsnCertType string `json:"psn_cert_type"`
  5723. PsnName string `json:"psn_name"`
  5724. PsnNo string `json:"psn_no"`
  5725. } `json:"baseinfo"`
  5726. Idetinfo []interface{} `json:"idetinfo"`
  5727. Iinfo []struct {
  5728. Balc float64 `json:"balc"`
  5729. CvlservFlag string `json:"cvlserv_flag"`
  5730. EmpName string `json:"emp_name"`
  5731. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5732. Insutype string `json:"insutype"`
  5733. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5734. PausInsuDate interface{} `json:"paus_insu_date"`
  5735. PsnInsuDate string `json:"psn_insu_date"`
  5736. PsnInsuStas string `json:"psn_insu_stas"`
  5737. PsnType string `json:"psn_type"`
  5738. } `json:"insuinfo"`
  5739. } `json:"output"`
  5740. RefmsgTime string `json:"refmsg_time"`
  5741. RespondTime string `json:"respond_time"`
  5742. Signtype interface{} `json:"signtype"`
  5743. WarnInfo interface{} `json:"warn_info"`
  5744. }
  5745. type ResultThree struct {
  5746. Cainfo interface{} `json:"cainfo"`
  5747. ErrMsg interface{} `json:"err_msg"`
  5748. InfRefmsgid string `json:"inf_refmsgid"`
  5749. Infcode int64 `json:"infcode"`
  5750. Output struct {
  5751. Data struct {
  5752. IptOtpNo string `json:"ipt_otp_no"`
  5753. MdtrtID string `json:"mdtrt_id"`
  5754. PsnNo string `json:"psn_no"`
  5755. } `json:"data"`
  5756. } `json:"output"`
  5757. RefmsgTime string `json:"refmsg_time"`
  5758. RespondTime string `json:"respond_time"`
  5759. Signtype interface{} `json:"signtype"`
  5760. WarnMsg interface{} `json:"warn_msg"`
  5761. }
  5762. type ResultFour struct {
  5763. Cainfo string `json:"cainfo"`
  5764. ErrMsg string `json:"err_msg"`
  5765. InfRefmsgid string `json:"inf_refmsgid"`
  5766. Infcode int64 `json:"infcode"`
  5767. Output struct {
  5768. Result []struct {
  5769. BasMednFlag string `json:"bas_medn_flag"`
  5770. ChldMedcFlag string `json:"chld_medc_flag"`
  5771. ChrgitmLv string `json:"chrgitm_lv"`
  5772. Cnt float64 `json:"cnt"`
  5773. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5774. DrtReimFlag string `json:"drt_reim_flag"`
  5775. FeedetlSn string `json:"feedetl_sn"`
  5776. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5777. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5778. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5779. ListSpItemFlag string `json:"list_sp_item_flag"`
  5780. LmtUsedFlag string `json:"lmt_used_flag"`
  5781. MedChrgitmType string `json:"med_chrgitm_type"`
  5782. Memo string `json:"memo"`
  5783. OverlmtAmt float64 `json:"overlmt_amt"`
  5784. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5785. Pric float64 `json:"pric"`
  5786. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5787. SelfpayProp float64 `json:"selfpay_prop"`
  5788. } `json:"result"`
  5789. } `json:"output"`
  5790. RefmsgTime string `json:"refmsg_time"`
  5791. RespondTime string `json:"respond_time"`
  5792. Signtype string `json:"signtype"`
  5793. WarnMsg string `json:"warn_msg"`
  5794. }
  5795. type ResultFive struct {
  5796. Insutype string `json:"insutype"`
  5797. }
  5798. type ResultSix struct {
  5799. Cainfo interface{} `json:"cainfo"`
  5800. ErrMsg interface{} `json:"err_msg"`
  5801. InfRefmsgid string `json:"inf_refmsgid"`
  5802. Infcode int64 `json:"infcode"`
  5803. Output struct {
  5804. } `json:"output"`
  5805. RefmsgTime string `json:"refmsg_time"`
  5806. RespondTime string `json:"respond_time"`
  5807. Signtype interface{} `json:"signtype"`
  5808. WarnMsg interface{} `json:"warn_msg"`
  5809. }
  5810. type ResultSeven struct {
  5811. Cainfo string `json:"cainfo"`
  5812. ErrMsg string `json:"err_msg"`
  5813. InfRefmsgid string `json:"inf_refmsgid"`
  5814. Infcode int64 `json:"infcode"`
  5815. Output struct {
  5816. Setldetail []interface{} `json:"setldetail"`
  5817. Setlinfo struct {
  5818. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5819. AcctPay float64 `json:"acct_pay"`
  5820. ActPayDedc float64 `json:"act_pay_dedc"`
  5821. Age float64 `json:"age"`
  5822. Balc float64 `json:"balc"`
  5823. Brdy string `json:"brdy"`
  5824. Certno string `json:"certno"`
  5825. ClrOptins string `json:"clr_optins"`
  5826. ClrType string `json:"clr_type"`
  5827. ClrWay string `json:"clr_way"`
  5828. CvlservFlag string `json:"cvlserv_flag"`
  5829. CvlservPay float64 `json:"cvlserv_pay"`
  5830. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5831. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5832. Gend string `json:"gend"`
  5833. HifesPay float64 `json:"hifes_pay"`
  5834. HifmiPay float64 `json:"hifmi_pay"`
  5835. HifobPay float64 `json:"hifob_pay"`
  5836. HifpPay float64 `json:"hifp_pay"`
  5837. HospPartAmt float64 `json:"hosp_part_amt"`
  5838. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5839. Insutype string `json:"insutype"`
  5840. MafPay float64 `json:"maf_pay"`
  5841. MdtrtCertType string `json:"mdtrt_cert_type"`
  5842. MdtrtID string `json:"mdtrt_id"`
  5843. MedType string `json:"med_type"`
  5844. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5845. MedinsSetlID string `json:"medins_setl_id"`
  5846. Naty string `json:"naty"`
  5847. OthPay float64 `json:"oth_pay"`
  5848. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5849. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5850. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5851. PsnCashPay float64 `json:"psn_cash_pay"`
  5852. PsnCertType string `json:"psn_cert_type"`
  5853. PsnName string `json:"psn_name"`
  5854. PsnNo string `json:"psn_no"`
  5855. PsnPartAmt float64 `json:"psn_part_amt"`
  5856. PsnType string `json:"psn_type"`
  5857. SetlID string `json:"setl_id"`
  5858. SetlTime string `json:"setl_time"`
  5859. } `json:"setlinfo"`
  5860. } `json:"output"`
  5861. RefmsgTime string `json:"refmsg_time"`
  5862. RespondTime string `json:"respond_time"`
  5863. Signtype interface{} `json:"signtype"`
  5864. WarnMsg interface{} `json:"warn_msg"`
  5865. }
  5866. type ResultEight struct {
  5867. Cainfo string `json:"cainfo"`
  5868. ErrMsg string `json:"err_msg"`
  5869. InfRefmsgid string `json:"inf_refmsgid"`
  5870. Infcode int64 `json:"infcode"`
  5871. Output struct {
  5872. Stmtinfo struct {
  5873. SetlOptins string `json:"setl_optins"`
  5874. StmtRslt string `json:"stmt_rslt"`
  5875. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5876. } `json:"stmtinfo"`
  5877. } `json:"output"`
  5878. RefmsgTime string `json:"refmsg_time"`
  5879. RespondTime string `json:"respond_time"`
  5880. Signtype interface{} `json:"signtype"`
  5881. WarnMsg interface{} `json:"warn_msg"`
  5882. }
  5883. type ResultNine struct {
  5884. Cainfo string `json:"cainfo"`
  5885. ErrMsg string `json:"err_msg"`
  5886. InfRefmsgid string `json:"inf_refmsgid"`
  5887. Infcode int64 `json:"infcode"`
  5888. Output struct {
  5889. FileQuryNo string `json:"file_qury_no"`
  5890. } `json:"output"`
  5891. RefmsgTime string `json:"refmsg_time"`
  5892. RespondTime string `json:"respond_time"`
  5893. Signtype interface{} `json:"signtype"`
  5894. WarnMsg interface{} `json:"warn_msg"`
  5895. }
  5896. type ResultTen struct {
  5897. Cainfo string `json:"cainfo"`
  5898. ErrMsg string `json:"err_msg"`
  5899. InfRefmsgid string `json:"inf_refmsgid"`
  5900. Infcode int64 `json:"infcode"`
  5901. Output struct {
  5902. DldEndtime string `json:"dld_endtime"`
  5903. FileQuryNo string `json:"file_qury_no"`
  5904. Filename string `json:"filename"`
  5905. } `json:"output"`
  5906. RefmsgTime string `json:"refmsg_time"`
  5907. RespondTime string `json:"respond_time"`
  5908. Signtype interface{} `json:"signtype"`
  5909. WarnMsg interface{} `json:"warn_msg"`
  5910. }
  5911. type ResultEleven struct {
  5912. Cainfo string `json:"cainfo"`
  5913. ErrMsg string `json:"err_msg"`
  5914. InfRefmsgid string `json:"inf_refmsgid"`
  5915. Infcode int64 `json:"infcode"`
  5916. Output struct {
  5917. Setlinfo struct {
  5918. FixmedinsName string `json:"fixmedins_name"`
  5919. FixmedinsCode string `json:"fixmedins_code"`
  5920. PsnNo string `json:"psn_no"`
  5921. PsnName string `json:"psn_name"`
  5922. HifobPay float64 `json:"hifob_pay"`
  5923. Gend string `json:"gend"`
  5924. Brdy string `json:"brdy"`
  5925. PsnCertType string `json:"psn_cert_type"`
  5926. PsnType string `json:"psn_type"`
  5927. EmpName string `json:"emp_name"`
  5928. Certno string `json:"certno"`
  5929. Insutype string `json:"insutype"`
  5930. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5931. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5932. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5933. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5934. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5935. ActPayDedc float64 `json:"act_pay_dedc"`
  5936. HifpPay float64 `json:"hifp_pay"`
  5937. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5938. CvlservPay float64 `json:"cvlserv_pay"`
  5939. HifesPay float64 `json:"hifes_pay"`
  5940. HifmiPay float64 `json:"hifmi_pay"`
  5941. MafPay float64 `json:"maf_pay"`
  5942. OthPay float64 `json:"oth_pay"`
  5943. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5944. PsnPay float64 `json:"psn_pay"`
  5945. AcctPay float64 `json:"acct_pay"`
  5946. CashPayamt float64 `json:"cash_payamt"`
  5947. Balc float64 `json:"balc"`
  5948. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5949. MedinsSetlId string `json:"medins_setl_id"`
  5950. RefdSetlFlag string `json:"refd_setl_flag"`
  5951. SetlTime string `json:"setl_time"`
  5952. MedType string `json:"med_type"`
  5953. } `json:"setlinfo"`
  5954. } `json:"output"`
  5955. RefmsgTime string `json:"refmsg_time"`
  5956. RespondTime string `json:"respond_time"`
  5957. Signtype interface{} `json:"signtype"`
  5958. WarnMsg interface{} `json:"warn_msg"`
  5959. }
  5960. type Custom struct {
  5961. DetItemFeeSumamt string
  5962. Cut string
  5963. FeedetlSn string
  5964. Price string
  5965. MedListCodg string
  5966. Type int64
  5967. AdviceId int64
  5968. ProjectId int64
  5969. ItemId int64
  5970. }
  5971. // 获取个人信息----挂号-----上传就诊信息
  5972. func (c *HisApiController) GetRegisterInfo() {
  5973. id, _ := c.GetInt64("id")
  5974. record_time := c.GetString("record_time")
  5975. settlementValue, _ := c.GetInt64("settlement_value")
  5976. medical_insurance_card := c.GetString("medical_insurance_card")
  5977. name := c.GetString("name")
  5978. id_card_type, _ := c.GetInt64("id_card_type")
  5979. certificates, _ := c.GetInt64("certificates")
  5980. medical_care, _ := c.GetInt64("medical_care")
  5981. birthday := c.GetString("birthday")
  5982. age, _ := c.GetInt64("age")
  5983. id_card := c.GetString("id_card")
  5984. register_type, _ := c.GetInt64("register")
  5985. doctor, _ := c.GetInt64("doctor")
  5986. department, _ := c.GetInt64("department")
  5987. gender, _ := c.GetInt64("sex")
  5988. phone := c.GetString("phone")
  5989. registration_fee, _ := c.GetFloat("registration_fee")
  5990. medical_expenses, _ := c.GetFloat("medical_expenses")
  5991. social_type, _ := c.GetInt64("social_type")
  5992. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5993. diagnosis_ids := c.GetString("diagnosis")
  5994. sick_type, _ := c.GetInt64("sick_type")
  5995. reg_type := c.GetString("p_type")
  5996. timeLayout := "2006-01-02"
  5997. loc, _ := time.LoadLocation("Local")
  5998. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5999. birthUnix := birthdays.Unix()
  6000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6001. if err != nil {
  6002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6003. return
  6004. }
  6005. recordDateTime := theTime.Unix()
  6006. adminInfo := c.GetAdminUserInfo()
  6007. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6008. if tempPatient.ID == 0 {
  6009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6010. return
  6011. }
  6012. var patient service.Patients
  6013. if id == 0 {
  6014. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6015. } else {
  6016. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6017. }
  6018. if patient.ID == 0 {
  6019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6020. return
  6021. }
  6022. if len(patient.IdCardNo) == 0 {
  6023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6024. return
  6025. }
  6026. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6027. if len(his) >= 1 {
  6028. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6029. if len(his) >= 1 && order.ID == 0 {
  6030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6031. return
  6032. }
  6033. }
  6034. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6035. fmt.Println(timeStr)
  6036. timeArr := strings.Split(timeStr, " ")
  6037. fmt.Println(timeArr)
  6038. timeArrTwo := strings.Split(timeArr[0], "-")
  6039. timeArrThree := strings.Split(timeArr[1], ":")
  6040. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6041. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6042. if len(lists) == 0 {
  6043. var hisPatient models.XtHisPatient
  6044. hisPatient = models.XtHisPatient{
  6045. Name: name,
  6046. Age: age,
  6047. Gender: gender,
  6048. Birthday: birthUnix,
  6049. Phone: phone,
  6050. MedicalTreatmentType: medical_care,
  6051. IdType: certificates,
  6052. IdCardNo: id_card,
  6053. BalanceAccountsType: settlementValue,
  6054. SocialType: social_type,
  6055. MedicalInsuranceNumber: medical_insurance_card,
  6056. RegisterType: register_type,
  6057. RegisterCost: registration_fee,
  6058. TreatmentCost: medical_expenses,
  6059. AdminUserId: adminInfo.AdminUser.Id,
  6060. UserOrgId: adminInfo.CurrentOrgId,
  6061. Status: 1,
  6062. RecordDate: recordDateTime,
  6063. IsReturn: 1,
  6064. PatientId: patient.ID,
  6065. Ctime: time.Now().Unix(),
  6066. Mtime: time.Now().Unix(),
  6067. Number: str,
  6068. IdCardType: id_card_type,
  6069. Departments: department,
  6070. Doctor: doctor,
  6071. PType: reg_type,
  6072. Diagnosis: diagnosis_ids,
  6073. SickType: sick_type,
  6074. }
  6075. service.CreateHisPatient(&hisPatient)
  6076. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6077. c.ServeSuccessJSON(map[string]interface{}{
  6078. "his_info": hisPatient,
  6079. })
  6080. } else {
  6081. //chrgBchno := rand.Intn(1000000) + 10000
  6082. var hisPatient models.XtHisPatient
  6083. hisPatient = models.XtHisPatient{
  6084. Name: name,
  6085. Age: age,
  6086. Gender: gender,
  6087. Birthday: birthUnix,
  6088. Phone: phone,
  6089. MedicalTreatmentType: medical_care,
  6090. IdType: certificates,
  6091. IdCardNo: id_card,
  6092. BalanceAccountsType: settlementValue,
  6093. SocialType: social_type,
  6094. MedicalInsuranceNumber: medical_insurance_card,
  6095. RegisterType: register_type,
  6096. RegisterCost: registration_fee,
  6097. TreatmentCost: medical_expenses,
  6098. AdminUserId: adminInfo.AdminUser.Id,
  6099. UserOrgId: adminInfo.CurrentOrgId,
  6100. Status: 1,
  6101. RecordDate: recordDateTime,
  6102. IsReturn: 1,
  6103. PatientId: patient.ID,
  6104. Ctime: time.Now().Unix(),
  6105. Mtime: time.Now().Unix(),
  6106. Number: str,
  6107. IdCardType: id_card_type,
  6108. Departments: department,
  6109. Doctor: doctor,
  6110. PType: reg_type,
  6111. Diagnosis: diagnosis_ids,
  6112. SickType: sick_type,
  6113. }
  6114. service.CreateHisPatient(&hisPatient)
  6115. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6116. c.ServeSuccessJSON(map[string]interface{}{
  6117. "his_info": hisPatient,
  6118. })
  6119. }
  6120. }
  6121. // 上传明细----结算
  6122. func (c *HisApiController) GetUploadInfo() {
  6123. id, _ := c.GetInt64("id")
  6124. record_time := c.GetString("record_time")
  6125. his_patient_id, _ := c.GetInt64("his_patient_id")
  6126. oth_desc := c.GetString("oth_desc")
  6127. pay_way, _ := c.GetInt64("pay_way")
  6128. pay_ways := c.GetString("pay_ways")
  6129. pay_price, _ := c.GetFloat("pay_price")
  6130. pay_card_no := c.GetString("pay_card_no")
  6131. discount_price, _ := c.GetFloat("discount_price")
  6132. preferential_price, _ := c.GetFloat("preferential_price")
  6133. reality_price, _ := c.GetFloat("reality_price")
  6134. found_price, _ := c.GetFloat("found_price")
  6135. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6136. private_price, _ := c.GetFloat("private_price")
  6137. timeLayout := "2006-01-02"
  6138. loc, _ := time.LoadLocation("Local")
  6139. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6140. fapiao_code := c.GetString("fapiao_code")
  6141. fapiao_number := c.GetString("fapiao_number")
  6142. diagnosis_id := c.GetString("diagnosis")
  6143. sick_type, _ := c.GetInt64("sick_type")
  6144. reg_type, _ := c.GetInt64("p_type")
  6145. order_id, _ := c.GetInt64("order_id")
  6146. cash_pay := c.GetString("cash_pay")
  6147. wechat_pay := c.GetString("wechat_pay")
  6148. ali_pay := c.GetString("ali_pay")
  6149. jifen_pay := c.GetString("jifen_pay")
  6150. band_card_pay := c.GetString("band_card_pay")
  6151. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6152. tmp_decimal := c.GetString("tmp_decimal")
  6153. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6154. var decimal float64 //本次使用的押金
  6155. var errmsg error
  6156. tx := service.XTWriteDB().Begin() //开了事务
  6157. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6158. defer func() {
  6159. if errmsg != nil {
  6160. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6161. tx.Rollback()
  6162. } else {
  6163. tx.Commit()
  6164. }
  6165. }()
  6166. fmt.Println("dec_way", dec_way)
  6167. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6168. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6169. return
  6170. }
  6171. if len(tmp_decimal) > 0 {
  6172. if tmp_decimal[0] == 45 {
  6173. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6174. return
  6175. }
  6176. }
  6177. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6178. fmt.Println(errs)
  6179. decimal = tt
  6180. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6181. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6183. if err != nil {
  6184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6185. return
  6186. }
  6187. recordDateTime := theTime.Unix()
  6188. adminUser := c.GetAdminUserInfo()
  6189. var prescriptions []*models.HisPrescription
  6190. var prescriptionsOne []*models.HisPrescription
  6191. var start_time int64
  6192. var end_time int64
  6193. ids_str := c.GetString("ids")
  6194. ids_arr := strings.Split(ids_str, ",")
  6195. if tempOrder.ID == 0 {
  6196. if settle_accounts_type == 1 { //日结
  6197. fmt.Println(reg_type)
  6198. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6199. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6200. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6201. } else {
  6202. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6203. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6204. }
  6205. } else { //月结
  6206. start_time_str := c.GetString("start_time")
  6207. end_time_str := c.GetString("end_time")
  6208. timeLayout := "2006-01-02"
  6209. loc, _ := time.LoadLocation("Local")
  6210. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6211. if err != nil {
  6212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6213. return
  6214. }
  6215. recordStartTime := theStartTime.Unix()
  6216. start_time = recordStartTime
  6217. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6218. if err != nil {
  6219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6220. return
  6221. }
  6222. recordEndTime := theEndTime.Unix()
  6223. end_time = recordEndTime
  6224. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6225. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6226. }
  6227. var goods []*models.DialysisBeforePrepareGoods
  6228. var newGoods []*models.NewDialysisBeforePrepareGoods
  6229. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6230. var infos []*models.HisDoctorAdviceInfo
  6231. var infoList []*models.HisDoctorAdviceInfo
  6232. var hisAdvice []*models.HisDoctorAdviceInfo
  6233. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6234. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6235. //判断库存不足
  6236. //结算出库开关
  6237. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6238. if settConfig.IsOpen == 1 {
  6239. //判断库存的地方
  6240. for _, info := range prescriptions {
  6241. if info.Type == 1 {
  6242. infos = append(infos, info.HisDoctorAdviceInfo...)
  6243. }
  6244. if info.Type == 2 {
  6245. for _, sumItem := range info.HisPrescriptionProject {
  6246. if sumItem.Type == 3 {
  6247. var good models.DialysisBeforePrepareGoods
  6248. var newGood models.NewDialysisBeforePrepareGoods
  6249. good.GoodId = sumItem.GoodInfo.ID
  6250. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6251. count, _ := strconv.Atoi(sumItem.Count)
  6252. good.Count = int64(count)
  6253. good.StorehouseId = houseConfig.StorehouseOutInfo
  6254. good.ProjectId = sumItem.ID
  6255. goods = append(goods, &good)
  6256. newGood.GoodId = sumItem.GoodInfo.ID
  6257. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6258. count2, _ := strconv.Atoi(sumItem.Count)
  6259. newGood.Count = int64(count2)
  6260. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6261. newGood.ProjectId = sumItem.ID
  6262. newGoods = append(newGoods, &newGood)
  6263. }
  6264. }
  6265. }
  6266. }
  6267. for _, info := range prescriptionsOne {
  6268. if info.Type == 1 {
  6269. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6270. }
  6271. if info.Type == 2 {
  6272. for _, sumItem := range info.HisPrescriptionProject {
  6273. if sumItem.Type == 3 {
  6274. var newGood models.NewDialysisBeforePrepareGoods
  6275. newGood.GoodId = sumItem.GoodInfo.ID
  6276. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6277. count2, _ := strconv.Atoi(sumItem.Count)
  6278. newGood.Count = int64(count2)
  6279. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6280. newGood.ProjectId = sumItem.ID
  6281. newGoodOne = append(newGoodOne, &newGood)
  6282. }
  6283. }
  6284. }
  6285. }
  6286. //判断
  6287. for _, itemOne := range infos {
  6288. for _, itemTwo := range hisAdvice {
  6289. if itemOne.DrugId == itemTwo.DrugId {
  6290. itemTwo.Child = append(itemTwo.Child, itemOne)
  6291. }
  6292. }
  6293. }
  6294. for _, itemTwo := range hisAdvice {
  6295. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6296. var sum_out_count int64
  6297. for _, itemThree := range itemTwo.Child {
  6298. var prescribing_number int64
  6299. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6300. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6301. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6302. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6303. }
  6304. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6305. prescribing_number = parseIntPrescribingNumber
  6306. }
  6307. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6308. prescribing_number = parseIntPrescribingNumber
  6309. }
  6310. sum_out_count += prescribing_number
  6311. }
  6312. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6313. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6314. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6315. if sum_out_count > drugStockOut.FlushCount {
  6316. c.ServeSuccessJSON(map[string]interface{}{
  6317. "msg": "2",
  6318. "drug": medical,
  6319. })
  6320. return
  6321. }
  6322. }
  6323. fmt.Println("newGoods99999988882os", newGoods)
  6324. for _, itemOne := range newGoods {
  6325. for _, item := range newGoodOne {
  6326. if itemOne.GoodId == item.GoodId {
  6327. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6328. }
  6329. }
  6330. }
  6331. for _, item := range newGoodOne {
  6332. var sum_out_count_one int64
  6333. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6334. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6335. sum_out_count_one += itemOne.Count
  6336. }
  6337. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6338. fmt.Println("sum_out_count_one", sum_out_count_one)
  6339. fmt.Println("list.FlushCount", list.FlushCount)
  6340. if sum_out_count_one > list.FlushCount {
  6341. c.ServeSuccessJSON(map[string]interface{}{
  6342. "msg": "3",
  6343. "good": good,
  6344. })
  6345. return
  6346. }
  6347. }
  6348. }
  6349. timestamp := time.Now().Unix()
  6350. tempTime := time.Unix(timestamp, 0)
  6351. timeFormat := tempTime.Format("20060102150405")
  6352. chrgBchno := rand.Intn(100000) + 10000
  6353. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6354. strconv.FormatInt(his.PatientId, 10)
  6355. var ids []int64
  6356. for _, item := range prescriptions {
  6357. ids = append(ids, item.ID)
  6358. }
  6359. var total float64
  6360. for _, item := range prescriptions {
  6361. fmt.Println(item)
  6362. if item.Type == 1 { //药品
  6363. for _, subItem := range item.HisDoctorAdviceInfo {
  6364. total = total + (subItem.Price * subItem.PrescribingNumber)
  6365. }
  6366. }
  6367. if item.Type == 2 { //项目
  6368. for _, subItem := range item.HisPrescriptionProject {
  6369. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6370. total = total + (subItem.Price * cnt)
  6371. }
  6372. }
  6373. for _, subItem := range item.HisAdditionalCharge {
  6374. total = total + (subItem.Price * float64(subItem.Count))
  6375. }
  6376. }
  6377. if reg_type == 1111 || reg_type == 1112 {
  6378. reg_type = 11
  6379. }
  6380. tm := time.Unix(time.Now().Unix(), 0)
  6381. allTotal := fmt.Sprintf("%.4f", total)
  6382. totals, _ := strconv.ParseFloat(allTotal, 64)
  6383. order := &models.HisOrder{
  6384. UserOrgId: adminUser.CurrentOrgId,
  6385. HisPatientId: his.ID,
  6386. PatientId: id,
  6387. SettleAccountsDate: recordDateTime,
  6388. Ctime: time.Now().Unix(),
  6389. Mtime: time.Now().Unix(),
  6390. Status: 1,
  6391. OrderStatus: 2,
  6392. MdtrtId: his.Number,
  6393. Number: chrg_bchno,
  6394. MedfeeSumamt: totals,
  6395. PayWay: pay_way,
  6396. PayWays: pay_ways,
  6397. PayPrice: pay_price,
  6398. MedType: strconv.Itoa(int(reg_type)),
  6399. PayCardNo: pay_card_no,
  6400. DiscountPrice: discount_price,
  6401. PreferentialPrice: preferential_price,
  6402. RealityPrice: reality_price,
  6403. FoundPrice: found_price,
  6404. MedicalInsurancePrice: medical_insurance_price,
  6405. PrivatePrice: private_price,
  6406. SettleEndTime: end_time,
  6407. SettleStartTime: start_time,
  6408. PsnPartAmt: totals,
  6409. PsnCashPay: totals,
  6410. SettleType: settle_accounts_type,
  6411. FaPiaoCode: fapiao_code,
  6412. FaPiaoNumber: fapiao_number,
  6413. Diagnosis: diagnosis_id,
  6414. PType: 2,
  6415. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6416. Decimal: decimal,
  6417. OthDesc: oth_desc,
  6418. CashPay: cash_pay,
  6419. WechatPay: wechat_pay,
  6420. AliPay: ali_pay,
  6421. JifenPay: jifen_pay,
  6422. BandCardPay: band_card_pay,
  6423. }
  6424. err = service.CreateOrderTX(order, tx)
  6425. if err != nil {
  6426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6427. return
  6428. }
  6429. var customs []*Custom
  6430. for _, item := range prescriptions {
  6431. if item.Type == 1 { //药品a
  6432. for _, subItem := range item.HisDoctorAdviceInfo {
  6433. cus := &Custom{
  6434. AdviceId: subItem.ID,
  6435. ProjectId: 0,
  6436. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6437. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6438. FeedetlSn: subItem.FeedetlSn,
  6439. Price: fmt.Sprintf("%.4f", subItem.Price),
  6440. MedListCodg: subItem.MedListCodg,
  6441. Type: 1,
  6442. }
  6443. customs = append(customs, cus)
  6444. }
  6445. }
  6446. if item.Type == 2 { //项目
  6447. for _, subItem := range item.HisPrescriptionProject {
  6448. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6449. cus := &Custom{
  6450. AdviceId: 0,
  6451. ProjectId: subItem.ID,
  6452. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6453. Cut: fmt.Sprintf("%.4f", cnt),
  6454. FeedetlSn: subItem.FeedetlSn,
  6455. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6456. MedListCodg: subItem.MedListCodg,
  6457. Type: 2,
  6458. }
  6459. customs = append(customs, cus)
  6460. }
  6461. }
  6462. for _, item := range item.HisAdditionalCharge {
  6463. cus := &Custom{
  6464. ItemId: item.ID,
  6465. AdviceId: 0,
  6466. ProjectId: 0,
  6467. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6468. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6469. FeedetlSn: item.FeedetlSn,
  6470. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6471. MedListCodg: item.XtHisAddtionConfig.Code,
  6472. Type: 3,
  6473. }
  6474. customs = append(customs, cus)
  6475. }
  6476. }
  6477. for _, item := range customs {
  6478. var advice_id int64 = 0
  6479. var project_id int64 = 0
  6480. var item_id int64 = 0
  6481. var types int64 = 0
  6482. if item.Type == 1 {
  6483. advice_id = item.AdviceId
  6484. project_id = 0
  6485. item_id = 0
  6486. } else if item.Type == 2 {
  6487. advice_id = 0
  6488. item_id = 0
  6489. project_id = item.ProjectId
  6490. } else if item.Type == 3 {
  6491. advice_id = 0
  6492. item_id = item.ItemId
  6493. project_id = 0
  6494. }
  6495. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6496. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6497. pric, _ := strconv.ParseFloat(item.Price, 32)
  6498. info := &models.HisOrderInfo{
  6499. OrderNumber: order.Number,
  6500. UploadDate: time.Now().Unix(),
  6501. AdviceId: advice_id,
  6502. DetItemFeeSumamt: detItemFeeSumamt,
  6503. Cnt: cut,
  6504. Pric: pric,
  6505. PatientId: id,
  6506. Status: 1,
  6507. Mtime: time.Now().Unix(),
  6508. Ctime: time.Now().Unix(),
  6509. UserOrgId: adminUser.CurrentOrgId,
  6510. HisPatientId: his.ID,
  6511. OrderId: order.ID,
  6512. ProjectId: project_id,
  6513. Type: types,
  6514. ItemId: item_id,
  6515. }
  6516. service.CreateOrderInfoTX(info, tx)
  6517. }
  6518. his.Diagnosis = diagnosis_id
  6519. his.SickType = sick_type
  6520. his.RegisterType = reg_type
  6521. his.MedicalTreatmentType = reg_type
  6522. service.UpdataHisPateintTX(&his, tx)
  6523. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6524. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6525. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6526. //判断是否使用了押金
  6527. if dec_way == "true" {
  6528. tmpstring := strconv.FormatInt(order.ID, 10)
  6529. //扣押金
  6530. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6531. order.Decimal = decimal
  6532. service.UpDateOrderTwo(order, tx)
  6533. if errmsg != nil {
  6534. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6535. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6536. return
  6537. }
  6538. }
  6539. if err == nil {
  6540. for _, info := range prescriptions {
  6541. if info.Type == 1 {
  6542. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6543. }
  6544. if info.Type == 2 {
  6545. for _, sumItem := range info.HisPrescriptionProject {
  6546. if sumItem.Type == 3 {
  6547. var good models.DialysisBeforePrepareGoods
  6548. var newGood models.NewDialysisBeforePrepareGoods
  6549. var oldGood models.OldDialysisBeforePrepareGoods
  6550. good.GoodId = sumItem.GoodInfo.ID
  6551. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6552. count, _ := strconv.Atoi(sumItem.Count)
  6553. good.Count = int64(count)
  6554. good.StorehouseId = houseConfig.StorehouseOutInfo
  6555. good.ProjectId = sumItem.ID
  6556. good.PatientId = sumItem.PatientId
  6557. goods = append(goods, &good)
  6558. newGood.GoodId = sumItem.GoodInfo.ID
  6559. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6560. count2, _ := strconv.Atoi(sumItem.Count)
  6561. newGood.Count = int64(count2)
  6562. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6563. newGood.ProjectId = sumItem.ID
  6564. newGood.PatientId = sumItem.HisPatientId
  6565. newGoods = append(newGoods, &newGood)
  6566. oldGood.GoodId = sumItem.GoodInfo.ID
  6567. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6568. count3, _ := strconv.Atoi(sumItem.Count)
  6569. oldGood.Count = int64(count3)
  6570. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6571. oldGood.ProjectId = sumItem.ID
  6572. oldGood.RecordDate = sumItem.RecordDate
  6573. oldGood.PatientId = sumItem.HisPatientId
  6574. oldGoods = append(oldGoods, &oldGood)
  6575. }
  6576. }
  6577. }
  6578. }
  6579. if settConfig.IsOpen == 1 {
  6580. for _, item := range infoList {
  6581. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6582. if medical.IsUse == 2 {
  6583. //药品出库
  6584. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6585. //查询默认仓库
  6586. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6587. //查询默认仓库剩余多少库存
  6588. var sum_count int64
  6589. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6590. for _, its := range stockInfo {
  6591. if its.MaxUnit == medical.MaxUnit {
  6592. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6593. }
  6594. sum_count += its.StockMaxNumber + its.StockMinNumber
  6595. }
  6596. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6597. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6598. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6599. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6600. }
  6601. }
  6602. orgId := c.GetAdminUserInfo().CurrentOrgId
  6603. if len(oldGoods) > 0 {
  6604. timeStr := time.Now().Format("2006-01-02")
  6605. timeArr := strings.Split(timeStr, "-")
  6606. total, _ := service.FindAllWarehouseOut(orgId)
  6607. total = total + 1
  6608. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6609. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6610. number = number + total
  6611. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6612. operation_time := time.Now().Unix()
  6613. creater := c.GetAdminUserInfo().AdminUser.Id
  6614. //查询默认出库仓库库存
  6615. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6616. recordDateStr := time.Now().Format("2006-01-02")
  6617. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6618. nowtime := recordDate.Unix()
  6619. warehouseOut := models.WarehouseOut{
  6620. WarehouseOutOrderNumber: warehousing_out_order,
  6621. OperationTime: operation_time,
  6622. OrgId: orgId,
  6623. Creater: creater,
  6624. Ctime: time.Now().Unix(),
  6625. Status: 1,
  6626. WarehouseOutTime: nowtime,
  6627. Type: 1,
  6628. StorehouseId: storeConfig.StorehouseOutInfo,
  6629. IsCheck: 1,
  6630. OrderId: order.ID,
  6631. IsSys: 5,
  6632. }
  6633. //查询是否生成出库单
  6634. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6635. if out.ID == 0 {
  6636. service.AddSigleWarehouseOut(&warehouseOut)
  6637. }
  6638. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6639. for _, item := range oldGoods {
  6640. dialyPrepareOne := models.DialysisBeforePrepare{
  6641. GoodTypeId: item.GoodTypeId,
  6642. GoodId: item.GoodId,
  6643. PatientId: his.PatientId,
  6644. RecordDate: item.RecordDate,
  6645. UserOrgId: adminUser.CurrentOrgId,
  6646. Count: item.Count,
  6647. Ctime: time.Now().Unix(),
  6648. Creater: adminUser.AdminUser.Id,
  6649. CommdityCode: item.CommdityCode,
  6650. Status: 1,
  6651. StorehouseId: houseConfig.StorehouseOutInfo,
  6652. }
  6653. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6654. //非零用
  6655. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6656. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6657. //查询剩余库存
  6658. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6659. var sum_count int64
  6660. for _, item := range goodList {
  6661. sum_count += item.StockCount
  6662. }
  6663. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6664. //耗材
  6665. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6666. }
  6667. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6668. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6669. //查询剩余库存
  6670. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6671. var sum_count int64
  6672. for _, item := range goodList {
  6673. sum_count += item.StockCount
  6674. }
  6675. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6676. //耗材
  6677. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6678. }
  6679. }
  6680. }
  6681. }
  6682. c.ServeSuccessJSON(map[string]interface{}{
  6683. "msg": "结算成功",
  6684. })
  6685. }
  6686. }
  6687. }
  6688. // 退款
  6689. func (c *HisApiController) Refund() {
  6690. order_id, _ := c.GetInt64("order_id")
  6691. order, _ := service.GetHisOrderByID(order_id)
  6692. adminUser := c.GetAdminUserInfo()
  6693. orgid := c.GetAdminUserInfo().CurrentOrgId
  6694. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6695. if err != nil {
  6696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6697. return
  6698. }
  6699. tmp := strconv.FormatInt(order.ID, 10)
  6700. //当押金不为零时产生退费记录
  6701. if order.Decimal != 0 {
  6702. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6703. if err != nil {
  6704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6705. return
  6706. }
  6707. }
  6708. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6709. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6710. var goods []*models.DialysisBeforePrepareGoods
  6711. var newGoods []*models.NewDialysisBeforePrepareGoods
  6712. var infos []*models.HisDoctorAdviceInfo
  6713. for _, info := range orders {
  6714. if info.AdviceId > 0 && info.ProjectId == 0 {
  6715. infos = append(infos, &info.HisDoctorAdviceInfo)
  6716. }
  6717. if info.ProjectId > 0 && info.AdviceId == 0 {
  6718. if info.HisPrescriptionProject.Type == 3 {
  6719. var good models.DialysisBeforePrepareGoods
  6720. var newGood models.NewDialysisBeforePrepareGoods
  6721. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6722. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6723. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6724. good.Count = int64(count)
  6725. good.StorehouseId = houseConfig.StorehouseOutInfo
  6726. good.ProjectId = info.HisPrescriptionProject.ID
  6727. good.PatientId = info.PatientId
  6728. good.OrderId = order_id
  6729. goods = append(goods, &good)
  6730. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6731. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6732. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6733. newGood.Count = int64(count2)
  6734. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6735. newGood.ProjectId = info.HisPrescriptionProject.ID
  6736. newGood.RecordDate = order.SettleAccountsDate
  6737. newGood.UserOrgId = order.UserOrgId
  6738. newGood.PatientId = info.PatientId
  6739. newGood.OrderId = order_id
  6740. newGoods = append(newGoods, &newGood)
  6741. }
  6742. }
  6743. }
  6744. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6745. if settConfig.IsOpen == 1 {
  6746. for _, item := range infos {
  6747. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6748. }
  6749. for _, item := range newGoods {
  6750. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6751. }
  6752. }
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "msg": "退费成功",
  6755. })
  6756. }
  6757. func (c *HisApiController) RefundNumber() {
  6758. his_patient_id, _ := c.GetInt64("id")
  6759. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6760. info.Status = 0
  6761. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6762. if count > 0 {
  6763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6764. return
  6765. }
  6766. err := service.SaveHisPatient(info)
  6767. if err == nil {
  6768. c.ServeSuccessJSON(map[string]interface{}{
  6769. "msg": "退号成功",
  6770. })
  6771. } else {
  6772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6773. return
  6774. }
  6775. }
  6776. func (this *HisApiController) AdditionalCharge() {
  6777. dataBody := make(map[string]interface{}, 0)
  6778. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6779. fmt.Println(err)
  6780. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6781. patient_id := int64(dataBody["patient_id"].(float64))
  6782. medicineData, _ := dataBody["medicineData"].([]interface{})
  6783. adminUserInfo := this.GetAdminUserInfo()
  6784. orgId := adminUserInfo.CurrentOrgId
  6785. admin_user_id := adminUserInfo.AdminUser.Id
  6786. timeStr := time.Now().Format("2006-01-02")
  6787. timeLayout := "2006-01-02 15:04:05"
  6788. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6789. timenow := timeStringToTime.Unix()
  6790. var additionalCharges []*models.HisAdditionalCharge
  6791. for _, item := range medicineData {
  6792. var randNum int
  6793. randNum = rand.Intn(10000) + 1000
  6794. timestamp := time.Now().Unix()
  6795. tempTime := time.Unix(timestamp, 0)
  6796. timeFormat := tempTime.Format("20060102150405")
  6797. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6798. items := item.(map[string]interface{})
  6799. money := items["price"].(string)
  6800. item_id_str := items["item_id"].(string)
  6801. name := items["name"].(string)
  6802. id_str := items["id"].(string)
  6803. moneys, _ := strconv.ParseInt(money, 10, 64)
  6804. monStr := strconv.FormatInt(moneys, 10)
  6805. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6806. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6807. id, _ := strconv.ParseInt(id_str, 10, 64)
  6808. additionalCharge := &models.HisAdditionalCharge{
  6809. ID: id,
  6810. HisPatientId: his_patient_id,
  6811. UserOrgId: orgId,
  6812. PatientId: patient_id,
  6813. RecordDate: timenow,
  6814. Price: monneyStr,
  6815. Status: 1,
  6816. ItemName: name,
  6817. ItemId: item_id,
  6818. AdminUserId: admin_user_id,
  6819. CreatedTime: time.Now().Unix(),
  6820. OrderStatus: 0,
  6821. PrescriptionNumber: "",
  6822. BatchNumber: "",
  6823. FeedetlSn: p_number,
  6824. }
  6825. service.CreateAdditionalCharge(additionalCharge)
  6826. additionalCharges = append(additionalCharges, additionalCharge)
  6827. }
  6828. this.ServeSuccessJSON(map[string]interface{}{
  6829. "msg": "添加成功",
  6830. "additional_charges": additionalCharges,
  6831. })
  6832. }
  6833. func (this *HisApiController) DeleteAddition() {
  6834. id, _ := this.GetInt64("id")
  6835. //TODO 需要判断是否已经结算
  6836. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6837. if err == nil {
  6838. this.ServeSuccessJSON(map[string]interface{}{
  6839. "msg": "删除成功",
  6840. })
  6841. return
  6842. } else {
  6843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6844. return
  6845. }
  6846. }
  6847. func (this *HisApiController) GetAdminUsers() {
  6848. adminUser := this.GetAdminUserInfo()
  6849. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6850. this.ServeSuccessJSON(map[string]interface{}{
  6851. "doctors": doctors,
  6852. })
  6853. }
  6854. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6855. change_type, _ := this.GetInt64("type", 0)
  6856. record_date := this.GetString("record_time")
  6857. patient_id, _ := this.GetInt64("patient_id", 0)
  6858. p_type, _ := this.GetInt64("p_type", 0)
  6859. timeLayout := "2006-01-02"
  6860. loc, _ := time.LoadLocation("Local")
  6861. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6862. record_time := theAdviceRecordTime.Unix()
  6863. adminUserInfo := this.GetAdminUserInfo()
  6864. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6865. if err == nil {
  6866. if len(prescriptions) == 0 {
  6867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6868. return
  6869. } else {
  6870. this.ServeSuccessJSON(map[string]interface{}{
  6871. "prescriptions": prescriptions,
  6872. })
  6873. return
  6874. }
  6875. } else {
  6876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6877. return
  6878. }
  6879. }
  6880. func (this *HisApiController) GetCallHisPrescription() {
  6881. patient_id, _ := this.GetInt64("patient_id", 0)
  6882. timeLayout := "2006-01-02"
  6883. loc, _ := time.LoadLocation("Local")
  6884. start_time := this.GetString("start_time")
  6885. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6886. end_time := this.GetString("end_time")
  6887. p_type, _ := this.GetInt64("p_type")
  6888. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6889. adminUserInfo := this.GetAdminUserInfo()
  6890. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6891. if err == nil {
  6892. this.ServeSuccessJSON(map[string]interface{}{
  6893. "prescriptions": prescriptions,
  6894. })
  6895. return
  6896. } else {
  6897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6898. return
  6899. }
  6900. }
  6901. func (this *HisApiController) GetHisDayPrescription() {
  6902. timeLayout := "2006-01-02"
  6903. loc, _ := time.LoadLocation("Local")
  6904. start_time := this.GetString("start_time")
  6905. patient_id, _ := this.GetInt64("patient_id", 0)
  6906. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6907. end_time := this.GetString("end_time")
  6908. p_type, _ := this.GetInt64("p_type")
  6909. order_status, _ := this.GetInt64("type")
  6910. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6911. adminUserInfo := this.GetAdminUserInfo()
  6912. var dayHisPrescription []*models.HisPrescription
  6913. var err error
  6914. if order_status == 1 || order_status == 0 {
  6915. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6916. } else if order_status == 2 {
  6917. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6918. }
  6919. var settle_total float64
  6920. for _, item := range dayHisPrescription {
  6921. if len(item.HisPrescriptionProject) > 0 {
  6922. for _, subItem := range item.HisPrescriptionProject {
  6923. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6924. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6925. settle_total = settle_total + total
  6926. }
  6927. }
  6928. if len(item.HisDoctorAdviceInfo) > 0 {
  6929. for _, subItem := range item.HisDoctorAdviceInfo {
  6930. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6931. settle_total = settle_total + total
  6932. }
  6933. }
  6934. }
  6935. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6936. if err == nil {
  6937. this.ServeSuccessJSON(map[string]interface{}{
  6938. "day_prescription": dayHisPrescription,
  6939. "settle_total": settle_total,
  6940. })
  6941. return
  6942. } else {
  6943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6944. return
  6945. }
  6946. }
  6947. func (c *HisApiController) GetHisChargePatientList() {
  6948. record_date := c.GetString("record_date")
  6949. order_status, _ := c.GetInt64("type")
  6950. sch_type, _ := c.GetInt64("sch_type")
  6951. timeLayout := "2006-01-02"
  6952. loc, _ := time.LoadLocation("Local")
  6953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6954. if err != nil {
  6955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6956. return
  6957. }
  6958. recordDateTime := theTime.Unix()
  6959. adminInfo := c.GetAdminUserInfo()
  6960. var tempPatients []*service.NewTempPatients
  6961. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6962. if order_status != 2 {
  6963. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6964. } else {
  6965. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6966. }
  6967. var patients []*service.NewTempPatients
  6968. var patients_two []*service.NewTempPatients
  6969. for _, item := range tempPatients {
  6970. //过滤掉没挂号的和没开处方的
  6971. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6972. patients = append(patients, item)
  6973. }
  6974. //过滤掉没挂号的
  6975. if len(item.HisPatient) > 0 {
  6976. patients_two = append(patients_two, item)
  6977. }
  6978. }
  6979. c.ServeSuccessJSON(map[string]interface{}{
  6980. "list": patients,
  6981. "list_two": patients_two,
  6982. })
  6983. }
  6984. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6985. record_date := c.GetString("record_date")
  6986. timeLayout := "2006-01-02"
  6987. loc, _ := time.LoadLocation("Local")
  6988. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6989. if err != nil {
  6990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6991. return
  6992. }
  6993. recordDateTime := theTime.Unix()
  6994. adminUser := c.GetAdminUserInfo()
  6995. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6996. var patients []*service.Patients
  6997. for _, item := range tempPatients {
  6998. if item.HisPatient.ID == 0 {
  6999. patients = append(patients, item)
  7000. }
  7001. }
  7002. c.ServeSuccessJSON(map[string]interface{}{
  7003. "list": patients,
  7004. //"list_two": patients_two,
  7005. })
  7006. }
  7007. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7008. newArr = make([]*service.Patients, 0)
  7009. for i := 0; i < len(patient); i++ {
  7010. repeat := false
  7011. for j := i + 1; j < len(patient); j++ {
  7012. if patient[i].ID == patient[j].ID {
  7013. repeat = true
  7014. break
  7015. }
  7016. }
  7017. if !repeat {
  7018. newArr = append(newArr, patient[i])
  7019. }
  7020. }
  7021. return
  7022. }
  7023. func (c *HisApiController) GetHisChargePatientInfo() {
  7024. patient_id, _ := c.GetInt64("patient_id")
  7025. his_patient_id, _ := c.GetInt64("his_patient_id")
  7026. record_date := c.GetString("record_date")
  7027. //start_time := c.GetString("start_time")
  7028. //end_time := c.GetString("end_time")
  7029. order_status, _ := c.GetInt64("type", 0)
  7030. p_type, _ := c.GetInt64("p_type", 0)
  7031. order_id, _ := c.GetInt64("order_id", 0)
  7032. timeLayout := "2006-01-02"
  7033. loc, _ := time.LoadLocation("Local")
  7034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7035. if err != nil {
  7036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7037. return
  7038. }
  7039. recordDateTime := theTime.Unix()
  7040. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7041. //if err != nil {
  7042. //
  7043. //}
  7044. //startRecordDateTime := startTime.Unix()
  7045. //
  7046. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7047. //if err != nil {
  7048. //
  7049. //}
  7050. //endRecordDateTime := endTime.Unix()
  7051. admin := c.GetAdminUserInfo()
  7052. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7053. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7054. var prescriptions []*models.HisPrescription
  7055. //var unChargeMonthPrescriptions []*models.HisPrescription
  7056. order, _ := service.GetHisOrderByID(order_id)
  7057. if order_status == 1 || order_status == 0 {
  7058. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7059. } else if order_status == 2 {
  7060. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7061. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7062. }
  7063. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7064. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7065. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7066. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7067. //获取所有科室信息
  7068. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7069. c.ServeSuccessJSON(map[string]interface{}{
  7070. "his_info": his_patient_info,
  7071. "xt_info": xt_patient_info,
  7072. "prescription": prescriptions,
  7073. "case_history": case_history,
  7074. "info": patientPrescriptionInfo,
  7075. "last_info": lastPatientPrescriptionInfo,
  7076. "order": order,
  7077. "doctors": doctors,
  7078. "department": department,
  7079. })
  7080. return
  7081. }
  7082. func (c *HisApiController) GetAllOrderDetail() {
  7083. order_id, _ := c.GetInt64("id", 0)
  7084. order, _ := service.GetHisOrderByID(order_id)
  7085. if order.ID == 0 {
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7087. return
  7088. }
  7089. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7090. org_id := c.GetAdminUserInfo().CurrentOrgId
  7091. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7092. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7093. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7094. c.ServeSuccessJSON(map[string]interface{}{
  7095. "order": order,
  7096. "order_info": order_info,
  7097. "patient": patient,
  7098. "admin_info": adminInfo,
  7099. "hospital_record": record,
  7100. })
  7101. return
  7102. }
  7103. func (c *HisApiController) GetAllOrderDetailCollect() {
  7104. order_id, _ := c.GetInt64("id", 0)
  7105. order, _ := service.GetHisOrderByID(order_id)
  7106. if order.ID == 0 {
  7107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7108. return
  7109. }
  7110. org_id := c.GetAdminUserInfo().CurrentOrgId
  7111. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7112. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7113. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7114. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7115. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7116. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7117. var bedCostTotal float64 = 0 //床位总费
  7118. //var bedCostSelfTotal float64 = 0 //床位自费
  7119. var operationCostTotal float64 = 0 //手术费
  7120. //var operationCostSelfTotal float64 = 0 //手术费
  7121. var otherCostTotal float64 = 0 //其他费用
  7122. //var otherCostSelfTotal float64 = 0 //其他费用
  7123. var materialCostTotal float64 = 0 //材料费
  7124. //var materialCostSelfTotal float64 = 0 //材料费
  7125. var westernMedicineCostTotal float64 = 0 //西药费
  7126. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7127. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7128. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7129. var checkCostTotal float64 = 0 //检查费
  7130. //var checkCostSelfTotal float64 = 0 //检查费
  7131. var laboratoryCostTotal float64 = 0 //化验费
  7132. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7133. var treatCostTotal float64 = 0 //治疗费用
  7134. //var treatCostSelfTotal float64 = 0 //治疗费用
  7135. var zhenChaCostTotal float64 = 0 //其他费用
  7136. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7137. decimal.DivisionPrecision = 2
  7138. var BalanceAccountsType int64
  7139. if his.ID > 0 {
  7140. BalanceAccountsType = his.BalanceAccountsType
  7141. } else {
  7142. BalanceAccountsType = record.BalanceAccountsType
  7143. }
  7144. if BalanceAccountsType != 2 {
  7145. for _, item := range order_info {
  7146. if org_id == 10215 {
  7147. if item.MedChrgitmType == "01" { //床位费
  7148. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7149. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7150. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7151. }
  7152. if item.MedChrgitmType == "02" { //诊察费
  7153. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7154. //zhenChaCostSelfTotal = zhenChaCostTotal
  7155. }
  7156. if item.MedChrgitmType == "03" { //检查费
  7157. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7158. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7159. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7160. }
  7161. //if item.MedChrgitmType == "02" { //检查费
  7162. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7163. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7164. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7165. //}
  7166. if item.MedChrgitmType == "04" { //化验费
  7167. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7168. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7169. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7170. }
  7171. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7172. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7173. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7174. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7175. }
  7176. if item.MedChrgitmType == "06" { //手术费
  7177. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7178. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7179. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7180. }
  7181. if item.MedChrgitmType == "08" { //材料费
  7182. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7183. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7184. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7185. }
  7186. if item.MedChrgitmType == "09" { //西药费
  7187. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7188. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7189. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7190. }
  7191. if item.MedChrgitmType == "11" { //中成费
  7192. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7193. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7194. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7195. }
  7196. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7197. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7198. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7199. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7200. }
  7201. } else if org_id == 10188 || org_id == 10217 {
  7202. if item.MedChrgitmType == "01" { //床位费
  7203. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7204. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7205. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7206. }
  7207. if item.MedChrgitmType == "02" { //诊察费
  7208. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7209. //zhenChaCostSelfTotal = zhenChaCostTotal
  7210. }
  7211. if item.MedChrgitmType == "03" { //检查费
  7212. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7213. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7214. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7215. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7216. }
  7217. //if item.MedChrgitmType == "02" { //检查费
  7218. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7219. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7220. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7221. //}
  7222. if item.MedChrgitmType == "04" { //化验费
  7223. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7224. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7225. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7226. }
  7227. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7228. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7229. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7230. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7231. }
  7232. if item.MedChrgitmType == "06" { //手术费
  7233. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7234. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7235. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7236. }
  7237. if item.MedChrgitmType == "08" { //材料费
  7238. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7239. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7240. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7241. }
  7242. if item.MedChrgitmType == "09" { //西药费
  7243. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7244. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7245. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7246. }
  7247. if item.MedChrgitmType == "11" { //中成费
  7248. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7249. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7250. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7251. }
  7252. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7253. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7254. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7255. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7256. }
  7257. } else {
  7258. if item.MedChrgitmType == "01" { //床位费
  7259. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7260. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7261. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7262. }
  7263. //if item.MedChrgitmType == "02" { //诊察费
  7264. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7265. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7266. //}
  7267. if item.MedChrgitmType == "03" { //检查费
  7268. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7269. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7270. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7271. }
  7272. //if item.MedChrgitmType == "02" { //检查费
  7273. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7274. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7275. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7276. //}
  7277. if item.MedChrgitmType == "04" { //化验费
  7278. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7279. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7280. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7281. }
  7282. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7283. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7284. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7285. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7286. }
  7287. if item.MedChrgitmType == "06" { //手术费
  7288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7289. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7290. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7291. }
  7292. if item.MedChrgitmType == "08" { //材料费
  7293. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7294. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7295. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7296. }
  7297. if item.MedChrgitmType == "09" { //西药费
  7298. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7299. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7300. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7301. }
  7302. if item.MedChrgitmType == "11" { //中成费
  7303. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7304. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7305. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7306. }
  7307. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7308. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7309. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7310. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7311. }
  7312. }
  7313. }
  7314. c.ServeSuccessJSON(map[string]interface{}{
  7315. "order": order,
  7316. "order_info": order_info,
  7317. "patient": patient,
  7318. "admin_info": adminInfo,
  7319. "his_hospital": record,
  7320. "bedCostTotal": bedCostTotal,
  7321. "operationCostTotal": operationCostTotal,
  7322. "otherCostTotal": otherCostTotal,
  7323. "materialCostTotal": materialCostTotal,
  7324. "westernMedicineCostTotal": westernMedicineCostTotal,
  7325. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7326. "checkCostTotal": checkCostTotal,
  7327. "zhenChaCostTotal": zhenChaCostTotal,
  7328. "laboratoryCostTotal": laboratoryCostTotal,
  7329. "treatCostTotal": treatCostTotal,
  7330. })
  7331. } else {
  7332. for _, item := range order_info {
  7333. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7334. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7335. item.MedChrgitmType = "09"
  7336. }
  7337. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7338. if item.HisPrescriptionProject.Type == 2 {
  7339. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7340. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7341. case 0:
  7342. item.MedChrgitmType = "0"
  7343. break
  7344. case 1:
  7345. item.MedChrgitmType = "14"
  7346. break
  7347. case 2:
  7348. item.MedChrgitmType = "05"
  7349. break
  7350. case 3:
  7351. item.MedChrgitmType = "03"
  7352. break
  7353. case 4:
  7354. item.MedChrgitmType = "03"
  7355. break
  7356. case 5:
  7357. item.MedChrgitmType = "08"
  7358. break
  7359. case 6:
  7360. item.MedChrgitmType = "14"
  7361. break
  7362. case 7:
  7363. item.MedChrgitmType = "14"
  7364. break
  7365. case 8:
  7366. item.MedChrgitmType = "03"
  7367. break
  7368. case 9:
  7369. item.MedChrgitmType = "14"
  7370. break
  7371. case 10:
  7372. item.MedChrgitmType = "14"
  7373. break
  7374. case 11:
  7375. item.MedChrgitmType = "06"
  7376. break
  7377. case 12:
  7378. item.MedChrgitmType = "12"
  7379. break
  7380. case 13:
  7381. item.MedChrgitmType = "01"
  7382. break
  7383. case 14:
  7384. item.MedChrgitmType = "04"
  7385. break
  7386. case 15:
  7387. item.MedChrgitmType = "14"
  7388. break
  7389. }
  7390. } else {
  7391. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7392. case 1:
  7393. item.MedChrgitmType = "14"
  7394. break
  7395. case 2:
  7396. item.MedChrgitmType = "05"
  7397. break
  7398. case 3:
  7399. item.MedChrgitmType = "04"
  7400. break
  7401. case 4:
  7402. item.MedChrgitmType = "14"
  7403. break
  7404. case 5:
  7405. item.MedChrgitmType = "08"
  7406. break
  7407. case 6:
  7408. item.MedChrgitmType = "14"
  7409. break
  7410. case 7:
  7411. item.MedChrgitmType = "14"
  7412. break
  7413. case 8:
  7414. item.MedChrgitmType = "03"
  7415. break
  7416. case 9:
  7417. item.MedChrgitmType = "14"
  7418. break
  7419. }
  7420. }
  7421. } else if item.HisPrescriptionProject.Type == 3 {
  7422. item.MedChrgitmType = "08"
  7423. }
  7424. }
  7425. }
  7426. for _, item := range order_info {
  7427. if org_id == 10215 {
  7428. if item.MedChrgitmType == "01" { //床位费
  7429. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7431. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7432. }
  7433. if item.MedChrgitmType == "02" { //诊察费
  7434. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7435. //zhenChaCostSelfTotal = zhenChaCostTotal
  7436. }
  7437. if item.MedChrgitmType == "03" { //检查费
  7438. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7439. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7440. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7441. }
  7442. //if item.MedChrgitmType == "02" { //检查费
  7443. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7444. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7445. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7446. //}
  7447. if item.MedChrgitmType == "04" { //化验费
  7448. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7449. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7450. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7451. }
  7452. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7453. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7454. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7455. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7456. }
  7457. if item.MedChrgitmType == "06" { //手术费
  7458. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7459. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7460. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7461. }
  7462. if item.MedChrgitmType == "08" { //材料费
  7463. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7464. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7465. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7466. }
  7467. if item.MedChrgitmType == "09" { //西药费
  7468. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7469. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7470. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7471. }
  7472. if item.MedChrgitmType == "11" { //中成费
  7473. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7474. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7475. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7476. }
  7477. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7478. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7479. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7480. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7481. }
  7482. } else {
  7483. if item.MedChrgitmType == "01" { //床位费
  7484. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7485. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7486. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7487. }
  7488. //if item.MedChrgitmType == "02" { //诊察费
  7489. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7490. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7491. //}
  7492. if item.MedChrgitmType == "03" { //检查费
  7493. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7494. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7495. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7496. }
  7497. //if item.MedChrgitmType == "02" { //检查费
  7498. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7499. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7500. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7501. //}
  7502. if item.MedChrgitmType == "04" { //化验费
  7503. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7504. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7505. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7506. }
  7507. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7508. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7509. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7510. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7511. }
  7512. if item.MedChrgitmType == "06" { //手术费
  7513. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7514. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7515. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7516. }
  7517. if item.MedChrgitmType == "08" { //材料费
  7518. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7519. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7520. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7521. }
  7522. if item.MedChrgitmType == "09" { //西药费
  7523. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7524. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7525. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7526. }
  7527. if item.MedChrgitmType == "11" { //中成费
  7528. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7529. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7530. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7531. }
  7532. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7533. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7534. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7535. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7536. }
  7537. }
  7538. }
  7539. c.ServeSuccessJSON(map[string]interface{}{
  7540. "order": order,
  7541. "order_info": order_info,
  7542. "patient": patient,
  7543. "admin_info": adminInfo,
  7544. "his_hospital": record,
  7545. "bedCostTotal": bedCostTotal,
  7546. "operationCostTotal": operationCostTotal,
  7547. "otherCostTotal": otherCostTotal,
  7548. "materialCostTotal": materialCostTotal,
  7549. "westernMedicineCostTotal": westernMedicineCostTotal,
  7550. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7551. "checkCostTotal": checkCostTotal,
  7552. "zhenChaCostTotal": zhenChaCostTotal,
  7553. "laboratoryCostTotal": laboratoryCostTotal,
  7554. "treatCostTotal": treatCostTotal,
  7555. })
  7556. }
  7557. }
  7558. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7559. page, _ := c.GetInt64("page")
  7560. limit, _ := c.GetInt64("limit")
  7561. keywords := c.GetString("keywords")
  7562. start_time := c.GetString("start_time")
  7563. end_time := c.GetString("end_time")
  7564. //clr_type := c.GetString("clr_type")
  7565. insutype := c.GetString("insutype")
  7566. timeLayout := "2006-01-02"
  7567. loc, _ := time.LoadLocation("Local")
  7568. var theStartTIme int64
  7569. if len(start_time) > 0 {
  7570. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7571. theStartTIme = theTime.Unix()
  7572. }
  7573. var theEndtTIme int64
  7574. if len(end_time) > 0 {
  7575. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7576. theEndtTIme = theTime.Unix()
  7577. }
  7578. if page <= 0 {
  7579. page = 1
  7580. }
  7581. if limit <= 0 {
  7582. limit = 10
  7583. }
  7584. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7585. c.ServeSuccessJSON(map[string]interface{}{
  7586. "total": total,
  7587. "list": list,
  7588. })
  7589. return
  7590. }
  7591. func (c *HisApiController) GetPutOnRecordList() {
  7592. page, _ := c.GetInt64("page")
  7593. limit, _ := c.GetInt64("limit")
  7594. keywords := c.GetString("keywords")
  7595. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7596. if page <= 0 {
  7597. page = 1
  7598. }
  7599. if limit <= 0 {
  7600. limit = 10
  7601. }
  7602. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7603. c.ServeSuccessJSON(map[string]interface{}{
  7604. "total": total,
  7605. "list": list,
  7606. })
  7607. return
  7608. }
  7609. func (c *HisApiController) GetCompareData() {
  7610. start_time := c.GetString("start_time")
  7611. end_time := c.GetString("end_time")
  7612. insutype := c.GetString("insutype")
  7613. clr_type := c.GetString("clr_type")
  7614. timeLayout := "2006-01-02"
  7615. loc, _ := time.LoadLocation("Local")
  7616. var theStartTIme int64
  7617. if len(start_time) > 0 {
  7618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7619. if err != nil {
  7620. theStartTIme = 0
  7621. }
  7622. theStartTIme = theTime.Unix()
  7623. }
  7624. var theEndtTIme int64
  7625. if len(end_time) > 0 {
  7626. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7627. if err != nil {
  7628. theEndtTIme = 0
  7629. }
  7630. theEndtTIme = theTime.Unix()
  7631. }
  7632. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7633. fmt.Println(err)
  7634. if err == nil {
  7635. c.ServeSuccessJSON(map[string]interface{}{
  7636. "list": formData,
  7637. })
  7638. } else {
  7639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7640. return
  7641. }
  7642. }
  7643. func (c *HisApiController) GetFaPiaoData() {
  7644. order_id, _ := c.GetInt64("order_id")
  7645. patient_id, _ := c.GetInt64("patient_id")
  7646. //number := c.GetString("number")
  7647. adminUser := c.GetAdminUserInfo()
  7648. order, _ := service.GetHisOrderByID(order_id)
  7649. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7650. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7651. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7652. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7653. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7654. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7655. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7656. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7657. var bedCostTotal float64 = 0 //床位总费
  7658. var bedCostSelfTotal float64 = 0 //床位自费
  7659. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7660. var operationCostTotal float64 = 0 //手术费
  7661. var operationCostSelfTotal float64 = 0 //手术费
  7662. var operationCostPartSelfTotal float64 = 0 //手术费
  7663. var otherCostTotal float64 = 0 //其他费用
  7664. var otherCostSelfTotal float64 = 0 //其他费用
  7665. var otherCostPartSelfTotal float64 = 0 //其他费用
  7666. var materialCostTotal float64 = 0 //材料费
  7667. var materialCostSelfTotal float64 = 0 //材料费
  7668. var materialCostPartSelfTotal float64 = 0 //材料费
  7669. var westernMedicineCostTotal float64 = 0 //西药费
  7670. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7671. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7672. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7673. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7674. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7675. var checkCostTotal float64 = 0 //检查费
  7676. var checkCostSelfTotal float64 = 0 //检查费
  7677. var checkCostPartSelfTotal float64 = 0 //检查费
  7678. var hiliCostTotal float64 = 0 //护理费
  7679. var hiliCostSelfTotal float64 = 0 //护理费
  7680. var hiliCostPartSelfTotal float64 = 0 //护理费
  7681. var laboratoryCostTotal float64 = 0 //化验费
  7682. var laboratoryCostSelfTotal float64 = 0 //化验费
  7683. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7684. var treatCostTotal float64 = 0 //治疗费用
  7685. var treatCostSelfTotal float64 = 0 //治疗费用
  7686. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7687. var zhenChaCostTotal float64 = 0 //其他费用
  7688. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7689. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7690. decimal.DivisionPrecision = 2
  7691. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7692. var balanceAccountsType int64
  7693. if his.ID > 0 {
  7694. balanceAccountsType = his.BalanceAccountsType
  7695. } else {
  7696. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7697. }
  7698. if balanceAccountsType == 2 {
  7699. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7700. for _, item := range orderInfos_two {
  7701. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7702. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7703. item.MedChrgitmType = "09"
  7704. }
  7705. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7706. if item.HisPrescriptionProject.Type == 2 {
  7707. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7708. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7709. case 0:
  7710. item.MedChrgitmType = "0"
  7711. break
  7712. case 1:
  7713. item.MedChrgitmType = "14"
  7714. break
  7715. case 2:
  7716. item.MedChrgitmType = "05"
  7717. break
  7718. case 3:
  7719. item.MedChrgitmType = "03"
  7720. break
  7721. case 4:
  7722. item.MedChrgitmType = "03"
  7723. break
  7724. case 5:
  7725. item.MedChrgitmType = "08"
  7726. break
  7727. case 6:
  7728. item.MedChrgitmType = "14"
  7729. break
  7730. case 7:
  7731. item.MedChrgitmType = "14"
  7732. break
  7733. case 8:
  7734. item.MedChrgitmType = "03"
  7735. break
  7736. case 9:
  7737. item.MedChrgitmType = "14"
  7738. break
  7739. case 10:
  7740. item.MedChrgitmType = "14"
  7741. break
  7742. case 11:
  7743. item.MedChrgitmType = "06"
  7744. break
  7745. case 12:
  7746. item.MedChrgitmType = "12"
  7747. break
  7748. case 13:
  7749. item.MedChrgitmType = "01"
  7750. break
  7751. case 14:
  7752. item.MedChrgitmType = "04"
  7753. break
  7754. case 15:
  7755. item.MedChrgitmType = "02"
  7756. break
  7757. }
  7758. } else {
  7759. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7760. case 1:
  7761. item.MedChrgitmType = "14"
  7762. break
  7763. case 2:
  7764. item.MedChrgitmType = "05"
  7765. break
  7766. case 3:
  7767. item.MedChrgitmType = "03"
  7768. break
  7769. case 4:
  7770. item.MedChrgitmType = "03"
  7771. break
  7772. case 5:
  7773. item.MedChrgitmType = "08"
  7774. break
  7775. case 6:
  7776. item.MedChrgitmType = "14"
  7777. break
  7778. case 7:
  7779. item.MedChrgitmType = "14"
  7780. break
  7781. case 8:
  7782. item.MedChrgitmType = "03"
  7783. break
  7784. case 9:
  7785. item.MedChrgitmType = "14"
  7786. break
  7787. }
  7788. }
  7789. } else if item.HisPrescriptionProject.Type == 3 {
  7790. item.MedChrgitmType = "08"
  7791. }
  7792. }
  7793. }
  7794. for _, item := range orderInfos_two {
  7795. fmt.Println(item.MedChrgitmType)
  7796. if item.MedChrgitmType == "07" { //床位费
  7797. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7798. hiliCostSelfTotal = hiliCostTotal
  7799. }
  7800. if item.MedChrgitmType == "01" { //床位费
  7801. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7802. bedCostSelfTotal = bedCostTotal
  7803. }
  7804. if item.MedChrgitmType == "02" { //诊察费
  7805. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7806. zhenChaCostSelfTotal = zhenChaCostTotal
  7807. }
  7808. if item.MedChrgitmType == "03" { //检查费
  7809. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7810. checkCostSelfTotal = checkCostTotal
  7811. }
  7812. if item.MedChrgitmType == "04" { //化验费
  7813. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7814. laboratoryCostSelfTotal = laboratoryCostTotal
  7815. }
  7816. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7817. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7818. treatCostSelfTotal = treatCostTotal
  7819. }
  7820. if item.MedChrgitmType == "06" { //手术费
  7821. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7822. operationCostSelfTotal = treatCostTotal
  7823. }
  7824. if item.MedChrgitmType == "08" { //材料费
  7825. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7826. materialCostSelfTotal = materialCostTotal
  7827. }
  7828. if item.MedChrgitmType == "09" { //西药费
  7829. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7830. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7831. }
  7832. if item.MedChrgitmType == "11" { //中成费
  7833. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7834. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7835. }
  7836. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7837. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7838. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7839. otherCostSelfTotal = otherCostTotal
  7840. }
  7841. } else {
  7842. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7843. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7844. otherCostSelfTotal = otherCostTotal
  7845. }
  7846. }
  7847. }
  7848. } else {
  7849. for _, item := range orderInfos {
  7850. if item.MedChrgitmType == "01" { //床位费
  7851. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7852. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7853. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7854. }
  7855. if item.MedChrgitmType == "02" { //诊察费
  7856. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7857. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7858. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7859. }
  7860. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7861. if item.MedChrgitmType == "03" { //检查费
  7862. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7863. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7864. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7865. }
  7866. } else {
  7867. if item.MedChrgitmType == "03" { //检查费
  7868. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7869. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7870. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7871. }
  7872. }
  7873. if item.MedChrgitmType == "04" { //化验费
  7874. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7875. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7876. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7877. }
  7878. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7879. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7880. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7881. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7882. }
  7883. if item.MedChrgitmType == "06" { //手术费
  7884. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7885. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7886. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7887. }
  7888. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7889. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7890. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7891. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7892. }
  7893. if item.MedChrgitmType == "07" { //西药费
  7894. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7895. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7896. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7897. }
  7898. if item.MedChrgitmType == "09" { //西药费
  7899. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7900. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7901. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7902. }
  7903. if item.MedChrgitmType == "11" { //中成费
  7904. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7905. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7906. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7907. }
  7908. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7909. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7910. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7911. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7912. }
  7913. }
  7914. }
  7915. timeLayout := "2006-01-02"
  7916. loc, _ := time.LoadLocation("Local")
  7917. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7918. if err != nil {
  7919. }
  7920. startRecordDateTime := startTime.Unix()
  7921. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7922. if err != nil {
  7923. }
  7924. endRecordDateTime := endTime.Unix()
  7925. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7926. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7927. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7928. c.ServeSuccessJSON(map[string]interface{}{
  7929. "order_number": order.Number, //业务流水号
  7930. "id_card_no": his.IdCardNo, //社会保障号
  7931. "patient": patient,
  7932. "department_name": department.Name, //科室
  7933. "number": his.Number, //门诊号
  7934. "date": order.SettleAccountsDate, //结算日期
  7935. "name": order.PsnName, //姓名
  7936. "gender": patient.Gender, //性别
  7937. "psn_cash_money": order.PsnCashPay, //个人支付
  7938. "pay_way": "门诊", //结算方式
  7939. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7940. "admin_user_name": admin.UserName, //收款员
  7941. "order": order,
  7942. "order_info": orderInfos_two,
  7943. "his": his,
  7944. "bedCostTotal": bedCostTotal,
  7945. "bedCostSelfTotal": bedCostSelfTotal,
  7946. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7947. "operationCostTotal": operationCostTotal,
  7948. "operationCostSelfTotal": operationCostSelfTotal,
  7949. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7950. "otherCostTotal": otherCostTotal,
  7951. "otherCostSelfTotal": otherCostSelfTotal,
  7952. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7953. "materialCostTotal": materialCostTotal,
  7954. "materialCostSelfTotal": materialCostSelfTotal,
  7955. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7956. "westernMedicineCostTotal": westernMedicineCostTotal,
  7957. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7958. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7959. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7960. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7961. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7962. "checkCostTotal": checkCostTotal,
  7963. "checkCostSelfTotal": checkCostSelfTotal,
  7964. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7965. "laboratoryCostTotal": laboratoryCostTotal,
  7966. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7967. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7968. "treatCostTotal": treatCostTotal,
  7969. "treatCostSelfTotal": treatCostSelfTotal,
  7970. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7971. "zhenChaCostTotal": zhenChaCostTotal,
  7972. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7973. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7974. "his_hospital_record": his_hospital_record,
  7975. "pre_pay_money": pre_pay_money,
  7976. "refund_sum": sum,
  7977. "doctor_info": doctor_info,
  7978. "hiliCostTotal": hiliCostTotal,
  7979. "hiliCostSelfTotal": hiliCostSelfTotal,
  7980. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7981. })
  7982. }
  7983. //func (c *HisApiController) GetFaPiaoDatas() {
  7984. // order_ids := c.GetString("order_ids")
  7985. // patient_id, _ := c.GetInt64("patient_id")
  7986. // adminUser := c.GetAdminUserInfo()
  7987. //
  7988. // orders := strings.Split(order_ids, ",")
  7989. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7990. //
  7991. // for _, item := range orders {
  7992. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7993. // order, _ := service.GetHisOrderByID(order_id)
  7994. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7995. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7996. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7997. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7998. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7999. //
  8000. // }
  8001. //
  8002. // var bedCostTotal float64 = 0 //床位总费
  8003. // var bedCostSelfTotal float64 = 0 //床位自费
  8004. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8005. //
  8006. // var operationCostTotal float64 = 0 //手术费
  8007. // var operationCostSelfTotal float64 = 0 //手术费
  8008. // var operationCostPartSelfTotal float64 = 0 //手术费
  8009. //
  8010. // var otherCostTotal float64 = 0 //其他费用
  8011. // var otherCostSelfTotal float64 = 0 //其他费用
  8012. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8013. //
  8014. // var materialCostTotal float64 = 0 //材料费
  8015. // var materialCostSelfTotal float64 = 0 //材料费
  8016. // var materialCostPartSelfTotal float64 = 0 //材料费
  8017. //
  8018. // var westernMedicineCostTotal float64 = 0 //西药费
  8019. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8020. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8021. //
  8022. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8023. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8024. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8025. //
  8026. // var checkCostTotal float64 = 0 //检查费
  8027. // var checkCostSelfTotal float64 = 0 //检查费
  8028. // var checkCostPartSelfTotal float64 = 0 //检查费
  8029. //
  8030. // var laboratoryCostTotal float64 = 0 //化验费
  8031. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8032. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8033. //
  8034. // var treatCostTotal float64 = 0 //治疗费用
  8035. // var treatCostSelfTotal float64 = 0 //治疗费用
  8036. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8037. //
  8038. // var zhenChaCostTotal float64 = 0 //其他费用
  8039. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8040. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8041. //
  8042. // decimal.DivisionPrecision = 2
  8043. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8044. //
  8045. // var balanceAccountsType int64
  8046. // if his.ID > 0 {
  8047. // balanceAccountsType = his.BalanceAccountsType
  8048. // } else {
  8049. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8050. // }
  8051. // if balanceAccountsType == 2 {
  8052. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8053. // for _, item := range orderInfos_two {
  8054. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8055. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8056. // item.MedChrgitmType = "09"
  8057. // }
  8058. //
  8059. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8060. // if item.HisPrescriptionProject.Type == 2 {
  8061. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8062. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8063. // case 0:
  8064. // item.MedChrgitmType = "0"
  8065. // break
  8066. // case 1:
  8067. // item.MedChrgitmType = "14"
  8068. // break
  8069. // case 2:
  8070. // item.MedChrgitmType = "05"
  8071. //
  8072. // break
  8073. // case 3:
  8074. // item.MedChrgitmType = "03"
  8075. //
  8076. // break
  8077. // case 4:
  8078. // item.MedChrgitmType = "03"
  8079. //
  8080. // break
  8081. // case 5:
  8082. // item.MedChrgitmType = "08"
  8083. //
  8084. // break
  8085. // case 6:
  8086. // item.MedChrgitmType = "14"
  8087. //
  8088. // break
  8089. // case 7:
  8090. // item.MedChrgitmType = "14"
  8091. //
  8092. // break
  8093. // case 8:
  8094. // item.MedChrgitmType = "03"
  8095. // break
  8096. // case 9:
  8097. // item.MedChrgitmType = "14"
  8098. // break
  8099. // case 10:
  8100. // item.MedChrgitmType = "14"
  8101. // break
  8102. // case 11:
  8103. // item.MedChrgitmType = "06"
  8104. // break
  8105. // case 12:
  8106. // item.MedChrgitmType = "12"
  8107. // break
  8108. // case 13:
  8109. // item.MedChrgitmType = "01"
  8110. // break
  8111. // case 14:
  8112. // item.MedChrgitmType = "04"
  8113. // break
  8114. // case 15:
  8115. // item.MedChrgitmType = "02"
  8116. // break
  8117. //
  8118. // }
  8119. //
  8120. // } else {
  8121. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8122. //
  8123. // case 1:
  8124. // item.MedChrgitmType = "14"
  8125. // break
  8126. // case 2:
  8127. // item.MedChrgitmType = "05"
  8128. //
  8129. // break
  8130. // case 3:
  8131. // item.MedChrgitmType = "03"
  8132. //
  8133. // break
  8134. // case 4:
  8135. // item.MedChrgitmType = "03"
  8136. //
  8137. // break
  8138. // case 5:
  8139. // item.MedChrgitmType = "08"
  8140. //
  8141. // break
  8142. // case 6:
  8143. // item.MedChrgitmType = "14"
  8144. //
  8145. // break
  8146. // case 7:
  8147. // item.MedChrgitmType = "14"
  8148. //
  8149. // break
  8150. // case 8:
  8151. // item.MedChrgitmType = "03"
  8152. // break
  8153. // case 9:
  8154. // item.MedChrgitmType = "14"
  8155. // break
  8156. //
  8157. // }
  8158. //
  8159. // }
  8160. //
  8161. // } else if item.HisPrescriptionProject.Type == 3 {
  8162. // item.MedChrgitmType = "08"
  8163. // }
  8164. // }
  8165. // }
  8166. //
  8167. // for _, item := range orderInfos_two {
  8168. // fmt.Println(item.MedChrgitmType)
  8169. // if item.MedChrgitmType == "01" { //床位费
  8170. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8171. // bedCostSelfTotal = bedCostTotal
  8172. // }
  8173. //
  8174. // if item.MedChrgitmType == "02" { //诊察费
  8175. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8176. // zhenChaCostSelfTotal = zhenChaCostTotal
  8177. // }
  8178. //
  8179. // if item.MedChrgitmType == "03" { //检查费
  8180. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8181. // checkCostSelfTotal = checkCostTotal
  8182. // }
  8183. //
  8184. // if item.MedChrgitmType == "04" { //化验费
  8185. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8186. // laboratoryCostSelfTotal = laboratoryCostTotal
  8187. // }
  8188. //
  8189. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8190. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8191. // treatCostSelfTotal = treatCostTotal
  8192. // }
  8193. //
  8194. // if item.MedChrgitmType == "06" { //手术费
  8195. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8196. // operationCostSelfTotal = treatCostTotal
  8197. // }
  8198. //
  8199. // if item.MedChrgitmType == "08" { //材料费
  8200. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8201. // materialCostSelfTotal = materialCostTotal
  8202. // }
  8203. //
  8204. // if item.MedChrgitmType == "09" { //西药费
  8205. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8206. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8207. // }
  8208. //
  8209. // if item.MedChrgitmType == "11" { //中成费
  8210. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8211. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8212. // }
  8213. //
  8214. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8215. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8216. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8217. // otherCostSelfTotal = otherCostTotal
  8218. // }
  8219. // } else {
  8220. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8221. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8222. // otherCostSelfTotal = otherCostTotal
  8223. // }
  8224. //
  8225. // }
  8226. //
  8227. // }
  8228. //
  8229. // } else {
  8230. // for _, item := range orderInfos {
  8231. // if item.MedChrgitmType == "01" { //床位费
  8232. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8233. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8234. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8235. // }
  8236. //
  8237. // if item.MedChrgitmType == "02" { //诊察费
  8238. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8239. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8240. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8241. // }
  8242. //
  8243. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8244. // if item.MedChrgitmType == "03" { //检查费
  8245. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8246. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8247. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8248. //
  8249. // }
  8250. // } else {
  8251. // if item.MedChrgitmType == "03" { //检查费
  8252. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8253. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8254. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8255. // }
  8256. //
  8257. // }
  8258. //
  8259. // if item.MedChrgitmType == "04" { //化验费
  8260. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8261. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8262. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8263. //
  8264. // }
  8265. //
  8266. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8267. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8268. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8269. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8270. //
  8271. // }
  8272. //
  8273. // if item.MedChrgitmType == "06" { //手术费
  8274. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8275. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8276. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8277. // }
  8278. //
  8279. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8280. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8281. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8282. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8283. // }
  8284. //
  8285. // if item.MedChrgitmType == "09" { //西药费
  8286. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8287. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8288. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8289. // }
  8290. //
  8291. // if item.MedChrgitmType == "11" { //中成费
  8292. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8293. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8294. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8295. // }
  8296. //
  8297. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8298. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8299. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8300. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8301. // }
  8302. //
  8303. // }
  8304. // }
  8305. // timeLayout := "2006-01-02"
  8306. // loc, _ := time.LoadLocation("Local")
  8307. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8308. // if err != nil {
  8309. // }
  8310. // startRecordDateTime := startTime.Unix()
  8311. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8312. // if err != nil {
  8313. // }
  8314. // endRecordDateTime := endTime.Unix()
  8315. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8316. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8317. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8318. //
  8319. // c.ServeSuccessJSON(map[string]interface{}{
  8320. // "order_number": order.Number, //业务流水号
  8321. // "id_card_no": his.IdCardNo, //社会保障号
  8322. // "department_name": department.Name, //科室
  8323. // "number": his.Number, //门诊号
  8324. // "date": order.SettleAccountsDate, //结算日期
  8325. // "name": order.PsnName, //姓名
  8326. // "gender": patient.Gender, //性别
  8327. // "psn_cash_money": order.PsnCashPay, //个人支付
  8328. // "pay_way": "门诊", //结算方式
  8329. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8330. // "admin_user_name": admin.UserName, //收款员
  8331. // "order": order,
  8332. // "order_info": orderInfos_two,
  8333. // "his": his,
  8334. // "bedCostTotal": bedCostTotal,
  8335. // "bedCostSelfTotal": bedCostSelfTotal,
  8336. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8337. // "operationCostTotal": operationCostTotal,
  8338. // "operationCostSelfTotal": operationCostSelfTotal,
  8339. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8340. // "otherCostTotal": otherCostTotal,
  8341. // "otherCostSelfTotal": otherCostSelfTotal,
  8342. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8343. // "materialCostTotal": materialCostTotal,
  8344. // "materialCostSelfTotal": materialCostSelfTotal,
  8345. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8346. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8347. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8348. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8349. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8350. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8351. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8352. // "checkCostTotal": checkCostTotal,
  8353. // "checkCostSelfTotal": checkCostSelfTotal,
  8354. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8355. // "laboratoryCostTotal": laboratoryCostTotal,
  8356. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8357. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8358. // "treatCostTotal": treatCostTotal,
  8359. // "treatCostSelfTotal": treatCostSelfTotal,
  8360. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8361. // "zhenChaCostTotal": zhenChaCostTotal,
  8362. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8363. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8364. // "his_hospital_record": his_hospital_record,
  8365. // "pre_pay_money": pre_pay_money,
  8366. // "refund_sum": sum,
  8367. // })
  8368. //
  8369. //}
  8370. func (this *HisApiController) GetIncomeStatisticsData() {
  8371. start_time := this.GetString("start_time")
  8372. end_time := this.GetString("end_time")
  8373. key_words := this.GetString("key_words")
  8374. limit, _ := this.GetInt64("limit")
  8375. page, _ := this.GetInt64("page")
  8376. if page <= 0 {
  8377. page = 1
  8378. }
  8379. if limit <= 0 {
  8380. limit = 10
  8381. }
  8382. statistics_type, _ := this.GetInt64("statistics_type")
  8383. admin := this.GetAdminUserInfo()
  8384. timeLayout := "2006-01-02"
  8385. loc, _ := time.LoadLocation("Local")
  8386. var theStartTIme int64
  8387. if len(start_time) > 0 {
  8388. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8389. if err != nil {
  8390. theStartTIme = 0
  8391. }
  8392. theStartTIme = theTime.Unix()
  8393. }
  8394. var theEndtTIme int64
  8395. if len(end_time) > 0 {
  8396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8397. if err != nil {
  8398. theEndtTIme = 0
  8399. }
  8400. theEndtTIme = theTime.Unix()
  8401. }
  8402. if statistics_type == 1 {
  8403. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8404. this.ServeSuccessJSON(map[string]interface{}{
  8405. "list": list,
  8406. "total": total,
  8407. })
  8408. } else {
  8409. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8410. this.ServeSuccessJSON(map[string]interface{}{
  8411. "list": list,
  8412. "total": total,
  8413. })
  8414. }
  8415. }
  8416. func (c *HisApiController) PostProjectInformation() {
  8417. adminUser := c.GetAdminUserInfo()
  8418. orgId := adminUser.CurrentOrgId
  8419. dataBody := make(map[string]interface{}, 0)
  8420. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8421. if err != nil {
  8422. utils.ErrorLog(err.Error())
  8423. return
  8424. }
  8425. utils.ErrorLog("%v", dataBody)
  8426. var projectList []*models.HisProject
  8427. var total_goods []interface{}
  8428. tempProjects := dataBody["projects"].([]interface{})
  8429. total_goods = tempProjects
  8430. for index, projectMap := range tempProjects {
  8431. projectM := projectMap.(map[string]interface{})
  8432. var project models.HisProject
  8433. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8434. utils.ErrorLog("project_name")
  8435. return
  8436. }
  8437. project_name, _ := projectM["project_name"].(string)
  8438. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8439. err_log := models.ExportErrLog{
  8440. LogType: 6,
  8441. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8442. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8443. Status: 1,
  8444. CreateTime: time.Now().Unix(),
  8445. UpdateTime: time.Now().Unix(),
  8446. ExportTime: time.Now().Unix(),
  8447. }
  8448. service.CreateExportErrLog(&err_log)
  8449. continue
  8450. }
  8451. project.ProjectName = project_name
  8452. prices := projectM["price"].(string)
  8453. price, _ := strconv.ParseFloat(prices, 64)
  8454. if price <= 0 { //名字为空则生成一条导入错误日志
  8455. err_log := models.ExportErrLog{
  8456. LogType: 6,
  8457. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8458. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8459. Status: 1,
  8460. CreateTime: time.Now().Unix(),
  8461. UpdateTime: time.Now().Unix(),
  8462. ExportTime: time.Now().Unix(),
  8463. }
  8464. service.CreateExportErrLog(&err_log)
  8465. continue
  8466. }
  8467. project.Price = price
  8468. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8469. utils.ErrorLog("unit_id")
  8470. return
  8471. }
  8472. unit := projectM["unit"].(string)
  8473. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8474. err_log := models.ExportErrLog{
  8475. LogType: 6,
  8476. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8477. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8478. Status: 1,
  8479. CreateTime: time.Now().Unix(),
  8480. UpdateTime: time.Now().Unix(),
  8481. ExportTime: time.Now().Unix(),
  8482. }
  8483. service.CreateExportErrLog(&err_log)
  8484. continue
  8485. }
  8486. project.Unit = unit
  8487. cost_classify := projectM["cost_classify"].(string)
  8488. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8489. err_log := models.ExportErrLog{
  8490. LogType: 6,
  8491. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8492. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8493. Status: 1,
  8494. CreateTime: time.Now().Unix(),
  8495. UpdateTime: time.Now().Unix(),
  8496. ExportTime: time.Now().Unix(),
  8497. }
  8498. service.CreateExportErrLog(&err_log)
  8499. continue
  8500. }
  8501. var costClassify = "费用类别"
  8502. var cost_classify_id int64
  8503. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8504. if len(cost_classify) != 0 {
  8505. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8506. if errcode == gorm.ErrRecordNotFound {
  8507. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8508. dataconfig := models.DictDataconfig{
  8509. ParentId: costClassifyConfig.ID,
  8510. Module: "system",
  8511. OrgId: orgId,
  8512. Name: cost_classify,
  8513. FieldName: "",
  8514. Value: costConfig.Value + 1,
  8515. CreatedTime: "",
  8516. UpdatedTime: "",
  8517. CreateUserId: adminUser.AdminUser.Id,
  8518. Status: 1,
  8519. Remark: "",
  8520. DeleteIdSystem: 0,
  8521. Title: "",
  8522. Content: "",
  8523. Order: 0,
  8524. Code: "",
  8525. }
  8526. service.CreatedDicConfig(&dataconfig)
  8527. }
  8528. }
  8529. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8530. for _, it := range costClassList {
  8531. if cost_classify == it.Name {
  8532. cost_classify_id = int64(it.Value)
  8533. }
  8534. }
  8535. project.CostClassify = cost_classify_id
  8536. executive_section := projectM["executive_section"].(string)
  8537. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8538. err_log := models.ExportErrLog{
  8539. LogType: 6,
  8540. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8541. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8542. Status: 1,
  8543. CreateTime: time.Now().Unix(),
  8544. UpdateTime: time.Now().Unix(),
  8545. ExportTime: time.Now().Unix(),
  8546. }
  8547. service.CreateExportErrLog(&err_log)
  8548. continue
  8549. }
  8550. if len(executive_section) != 0 {
  8551. //查找科室是否有内容
  8552. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8553. if errcodedepart == gorm.ErrRecordNotFound {
  8554. department := models.XtHisDepartment{
  8555. Name: executive_section,
  8556. Status: 1,
  8557. UserOrgId: adminUser.CurrentOrgId,
  8558. CreatedTime: time.Now().Unix(),
  8559. }
  8560. service.CreateDePartment(&department)
  8561. }
  8562. }
  8563. var executive_section_id int64
  8564. departMentList, _ := service.GetAllDepartMent(orgId)
  8565. for _, it := range departMentList {
  8566. if executive_section == it.Name {
  8567. executive_section_id = it.ID
  8568. }
  8569. }
  8570. project.ExecutiveSection = executive_section_id
  8571. medical_coverage := projectM["medical_coverage"].(string)
  8572. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8573. err_log := models.ExportErrLog{
  8574. LogType: 6,
  8575. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8576. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8577. Status: 1,
  8578. CreateTime: time.Now().Unix(),
  8579. UpdateTime: time.Now().Unix(),
  8580. ExportTime: time.Now().Unix(),
  8581. }
  8582. service.CreateExportErrLog(&err_log)
  8583. continue
  8584. }
  8585. var medicalCoverage = "医保等级"
  8586. var medical_coverage_id int64
  8587. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8588. if len(medical_coverage) != 0 {
  8589. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8590. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8591. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8592. dataconfig := models.DictDataconfig{
  8593. ParentId: medicalCoverageConfig.ID,
  8594. Module: "system",
  8595. OrgId: orgId,
  8596. Name: medical_coverage,
  8597. FieldName: "",
  8598. Value: medicalCoverageConfig.Value + 1,
  8599. CreatedTime: "",
  8600. UpdatedTime: "",
  8601. CreateUserId: adminUser.AdminUser.Id,
  8602. Status: 1,
  8603. Remark: "",
  8604. DeleteIdSystem: 0,
  8605. Title: "",
  8606. Content: "",
  8607. Order: 0,
  8608. Code: "",
  8609. }
  8610. service.CreatedDicConfig(&dataconfig)
  8611. }
  8612. }
  8613. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8614. for _, it := range medicalCoverageList {
  8615. if medical_coverage == it.Name {
  8616. medical_coverage_id = int64(it.Value)
  8617. }
  8618. }
  8619. project.MedicalCoverage = medical_coverage_id
  8620. pinyin := projectM["pinyin"].(string)
  8621. project.Pinyin = pinyin
  8622. wubi := projectM["wubi"].(string)
  8623. project.Wubi = wubi
  8624. statistical_classification := projectM["statistical_classification"].(string)
  8625. var statisticalClassification = "统计分类"
  8626. var statistical_classification_id int64
  8627. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8628. if len(statistical_classification) != 0 {
  8629. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8630. if classificationerrcodes == gorm.ErrRecordNotFound {
  8631. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8632. dataconfig := models.DictDataconfig{
  8633. ParentId: classiFication.ID,
  8634. Module: "system",
  8635. OrgId: orgId,
  8636. Name: statistical_classification,
  8637. FieldName: "",
  8638. Value: classiFicationConfig.Value + 1,
  8639. CreatedTime: "",
  8640. UpdatedTime: "",
  8641. CreateUserId: adminUser.AdminUser.Id,
  8642. Status: 1,
  8643. Remark: "",
  8644. DeleteIdSystem: 0,
  8645. Title: "",
  8646. Content: "",
  8647. Order: 0,
  8648. Code: "",
  8649. }
  8650. service.CreatedDicConfig(&dataconfig)
  8651. }
  8652. }
  8653. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8654. for _, it := range classiFicationList {
  8655. if statistical_classification == it.Name {
  8656. statistical_classification_id = int64(it.Value)
  8657. }
  8658. }
  8659. project.StatisticalClassification = statistical_classification_id
  8660. disease_directory := int64(projectM["disease_directory"].(float64))
  8661. project.DiseaseDirectory = disease_directory
  8662. is_record := int64(projectM["is_record"].(float64))
  8663. project.IsRecord = is_record
  8664. medical_code := projectM["medical_code"].(string)
  8665. project.MedicalCode = medical_code
  8666. tube_color := projectM["tube_color"].(string)
  8667. var tubeColor = "试管颜色"
  8668. var tube_color_id int64
  8669. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8670. if len(tube_color) != 0 {
  8671. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8672. if errcodetube == gorm.ErrRecordNotFound {
  8673. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8674. dataconfig := models.DictDataconfig{
  8675. ParentId: tubeColorConfig.ID,
  8676. Module: "system",
  8677. OrgId: orgId,
  8678. Name: tube_color,
  8679. FieldName: "",
  8680. Value: tubeConfig.Value + 1,
  8681. CreatedTime: "",
  8682. UpdatedTime: "",
  8683. CreateUserId: adminUser.AdminUser.Id,
  8684. Status: 1,
  8685. Remark: "",
  8686. DeleteIdSystem: 0,
  8687. Title: "",
  8688. Content: "",
  8689. Order: 0,
  8690. Code: "",
  8691. }
  8692. service.CreatedDicConfig(&dataconfig)
  8693. }
  8694. }
  8695. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8696. for _, it := range tubeColorList {
  8697. if tube_color == it.Name {
  8698. tube_color_id = int64(it.Value)
  8699. }
  8700. }
  8701. project.TubeColor = tube_color_id
  8702. single_dose := projectM["single_dose"].(string)
  8703. project.SingleDose = single_dose
  8704. execution_frequency := projectM["execution_frequency"].(string)
  8705. project.ExecutionFrequency = execution_frequency
  8706. delivery_way := projectM["delivery_way"].(string)
  8707. project.DeliveryWay = delivery_way
  8708. number_days := projectM["number_days"].(string)
  8709. project.NumberDays = number_days
  8710. total := projectM["total"].(string)
  8711. project.Total = total
  8712. medical_status := int64(projectM["medical_status"].(float64))
  8713. project.MedicalStatus = medical_status
  8714. category := int64(projectM["category"].(float64))
  8715. project.Category = category
  8716. specail_project := int64(projectM["specail_project"].(float64))
  8717. project.SpecailProject = specail_project
  8718. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8719. project.SocialSecurityDirectoryCode = social_security_directory_code
  8720. remark := projectM["remark"].(string)
  8721. project.Remark = remark
  8722. record_date := projectM["record_date"].(string)
  8723. timeLayout := "2006-01-02"
  8724. loc, _ := time.LoadLocation("Local")
  8725. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8726. project.RecordDate = theTime.Unix()
  8727. projectList = append(projectList, &project)
  8728. }
  8729. export_time := time.Now().Unix()
  8730. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8731. if len(projectList) > 0 {
  8732. for _, item := range projectList {
  8733. project := models.HisProject{
  8734. ProjectName: item.ProjectName,
  8735. Price: item.Price,
  8736. Unit: item.Unit,
  8737. CostClassify: item.CostClassify,
  8738. ExecutiveSection: item.ExecutiveSection,
  8739. MedicalCoverage: item.MedicalCoverage,
  8740. UserOrgId: orgId,
  8741. Status: 1,
  8742. CreatedTime: time.Now().Unix(),
  8743. Pinyin: item.Pinyin,
  8744. Wubi: item.Wubi,
  8745. StatisticalClassification: item.StatisticalClassification,
  8746. DiseaseDirectory: item.DiseaseDirectory,
  8747. IsRecord: item.IsRecord,
  8748. MedicalCode: item.MedicalCode,
  8749. TubeColor: item.TubeColor,
  8750. SingleDose: item.SingleDose,
  8751. DeliveryWay: item.DeliveryWay,
  8752. NumberDays: item.NumberDays,
  8753. Total: item.Total,
  8754. Category: item.Category,
  8755. MedicalStatus: item.MedicalStatus,
  8756. SpecailProject: item.SpecailProject,
  8757. RecordDate: item.RecordDate,
  8758. Remark: item.Remark,
  8759. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8760. ExecutionFrequency: item.ExecutionFrequency,
  8761. }
  8762. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8763. if errcodeproject == gorm.ErrRecordNotFound {
  8764. service.CreateProjectInfomation(&project)
  8765. } else if errcodeproject == nil {
  8766. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8767. }
  8768. log := models.ExportLog{
  8769. LogType: 6,
  8770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8771. TotalNum: int64(len(total_goods)),
  8772. FailNum: int64(len(errLogs)),
  8773. SuccessNum: int64(len(projectList)),
  8774. CreateTime: time.Now().Unix(),
  8775. UpdateTime: time.Now().Unix(),
  8776. ExportTime: export_time,
  8777. Status: 1,
  8778. }
  8779. service.CreateExportLog(&log)
  8780. c.ServeSuccessJSON(map[string]interface{}{
  8781. "msg": "导入成功",
  8782. "total_num": len(total_goods),
  8783. "success_num": len(projectList),
  8784. "fail_num": int64(len(errLogs)),
  8785. })
  8786. }
  8787. } else {
  8788. log := models.ExportLog{
  8789. LogType: 6,
  8790. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8791. TotalNum: int64(len(total_goods)),
  8792. FailNum: int64(len(errLogs)),
  8793. SuccessNum: int64(len(projectList)),
  8794. CreateTime: time.Now().Unix(),
  8795. UpdateTime: time.Now().Unix(),
  8796. ExportTime: export_time,
  8797. Status: 1,
  8798. }
  8799. service.CreateExportLog(&log)
  8800. c.ServeSuccessJSON(map[string]interface{}{
  8801. "msg": "导入成功",
  8802. "total_num": len(total_goods),
  8803. "success_num": len(projectList),
  8804. "fail_num": int64(len(errLogs)),
  8805. })
  8806. }
  8807. }
  8808. //func (this *HisApiController) EditProjectInformation(){
  8809. //
  8810. // id, _ := this.GetInt64("id")
  8811. // project_team := this.GetString("project_team")
  8812. // price := this.GetString("price")
  8813. // price_float, _ := strconv.ParseFloat(price, 64)
  8814. // pinyin := this.GetString("pinyin")
  8815. // wubi := this.GetString("wubi")
  8816. // tube_color, _ := this.GetInt64("tube_color")
  8817. // team_type, _ := this.GetInt64("team_type")
  8818. // remark := this.GetString("remark")
  8819. // ids := this.GetString("ids")
  8820. // item_id := this.GetString("item_id")
  8821. // projectTeam := models.XtHisProjectTeam{
  8822. // ProjectTeam: project_team,
  8823. // Price: price_float,
  8824. // Pinyin: pinyin,
  8825. // Wubi: wubi,
  8826. // TubeColor: tube_color,
  8827. // TeamType: team_type,
  8828. // Remark: remark,
  8829. // ProjectId: ids,
  8830. // ItemId: item_id,
  8831. // }
  8832. //
  8833. //
  8834. // dataBody := make(map[string]interface{}, 0)
  8835. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8836. // if err != nil {
  8837. // utils.ErrorLog(err.Error())
  8838. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8839. // return
  8840. // }
  8841. //
  8842. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8843. //
  8844. //
  8845. // if err != nil {
  8846. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8847. // return
  8848. // }
  8849. //
  8850. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8851. // infos, _ := dataBody["info"].([]interface{})
  8852. // if len(infos) > 0 {
  8853. // var ids []string
  8854. //
  8855. // for _, item := range infos {
  8856. // items := item.(map[string]interface{})
  8857. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8858. // utils.ErrorLog("id")
  8859. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8860. // return
  8861. // }
  8862. // id := int64(items["id"].(float64))
  8863. //
  8864. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8865. // utils.ErrorLog("type")
  8866. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8867. // return
  8868. // }
  8869. // types := int64(items["type"].(float64))
  8870. //
  8871. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8872. // utils.ErrorLog("number")
  8873. // }
  8874. //
  8875. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8876. //
  8877. // projectList := models.XtHisProjectList{
  8878. // Number: number,
  8879. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8880. // ProjectId: id,
  8881. // Status: 1,
  8882. // CreatedTime: time.Now().Unix(),
  8883. // UpdatedTime: time.Now().Unix(),
  8884. // TeamId: projectTeam.ID,
  8885. // Type: types,
  8886. // }
  8887. // list := projectList
  8888. //
  8889. // service.CreateProjectList(&list)
  8890. //
  8891. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8892. //
  8893. // }
  8894. // ids_str := strings.Join(ids, ",")
  8895. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8896. // service.SaveProjectTeam(&projectTeam)
  8897. // this.ServeSuccessJSON(map[string]interface{}{
  8898. // "projectTeam": projectTeam,
  8899. // })
  8900. // }
  8901. // }
  8902. //}
  8903. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8904. name := c.GetString("name")
  8905. mode_id, _ := c.GetInt64("mode", 0)
  8906. types, _ := c.GetInt64("type", 0)
  8907. patient_id, _ := c.GetInt64("patient_id", 0)
  8908. types = 1
  8909. adminInfo := c.GetAdminUserInfo()
  8910. template := &models.HisPrescriptionTemplate{
  8911. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8912. PatientId: patient_id,
  8913. Type: types,
  8914. Status: 1,
  8915. Ctime: time.Now().Unix(),
  8916. Mtime: time.Now().Unix(),
  8917. Name: name,
  8918. Mode: mode_id,
  8919. }
  8920. dataBody := make(map[string]interface{}, 0)
  8921. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8922. if err != nil {
  8923. utils.ErrorLog(err.Error())
  8924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8925. return
  8926. }
  8927. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8928. //如果已经存在记录则删除处方
  8929. if template_one.ID > 0 {
  8930. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8931. for _, item := range ps {
  8932. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8933. }
  8934. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8935. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8936. if len(prescriptions) > 0 {
  8937. for _, item := range prescriptions {
  8938. items := item.(map[string]interface{})
  8939. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8940. utils.ErrorLog("type")
  8941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8942. return
  8943. }
  8944. types := int64(items["type"].(float64))
  8945. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8946. utils.ErrorLog("med_type")
  8947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8948. return
  8949. }
  8950. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8951. ctime := time.Now().Unix()
  8952. prescription := &models.HisPrescriptionInfoTemplate{
  8953. PatientId: patient_id,
  8954. UserOrgId: adminInfo.CurrentOrgId,
  8955. Ctime: ctime,
  8956. Mtime: ctime,
  8957. Type: types,
  8958. Modifier: adminInfo.AdminUser.Id,
  8959. Creator: adminInfo.AdminUser.Id,
  8960. Status: 1,
  8961. PTemplateId: template_one.ID,
  8962. MedType: med_type,
  8963. }
  8964. service.CreateHisPrescriptionInfoTemplate(prescription)
  8965. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8966. advices := items["advices"].([]interface{})
  8967. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8968. ctime := time.Now().Unix()
  8969. mtime := ctime
  8970. if len(advices) > 0 {
  8971. for _, advice := range advices {
  8972. var s models.HisPrescriptionAdviceTemplate
  8973. s.PrescriptionId = prescription.ID
  8974. s.AdviceType = 2
  8975. s.StopState = 2
  8976. s.ExecutionState = 2
  8977. s.Status = 1
  8978. s.UserOrgId = adminInfo.CurrentOrgId
  8979. s.CreatedTime = ctime
  8980. s.UpdatedTime = mtime
  8981. s.PatientId = patient_id
  8982. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8983. if errcode > 0 {
  8984. c.ServeFailJSONWithSGJErrorCode(errcode)
  8985. return
  8986. }
  8987. service.CreateHisPrescriptionAdviceTemplate(&s)
  8988. }
  8989. }
  8990. }
  8991. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8992. projects := items["project"].([]interface{})
  8993. if len(projects) > 0 {
  8994. for _, project := range projects {
  8995. var p models.HisPrescriptionProjectTemplate
  8996. p.PrescriptionId = prescription.ID
  8997. p.Ctime = time.Now().Unix()
  8998. p.Mtime = time.Now().Unix()
  8999. p.PatientId = patient_id
  9000. p.UserOrgId = adminInfo.CurrentOrgId
  9001. p.Status = 1
  9002. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9003. if errcode > 0 {
  9004. c.ServeFailJSONWithSGJErrorCode(errcode)
  9005. return
  9006. }
  9007. service.CreateHisPrescriptionProjectTemplate(&p)
  9008. }
  9009. }
  9010. }
  9011. }
  9012. c.ServeSuccessJSON(map[string]interface{}{
  9013. "msg": "创建成功",
  9014. })
  9015. }
  9016. }
  9017. } else {
  9018. err = service.CreateHisPrescriptionTemplate(template)
  9019. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9020. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9021. if len(prescriptions) > 0 {
  9022. for _, item := range prescriptions {
  9023. items := item.(map[string]interface{})
  9024. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9025. utils.ErrorLog("type")
  9026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9027. return
  9028. }
  9029. types := int64(items["type"].(float64))
  9030. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9031. utils.ErrorLog("med_type")
  9032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9033. return
  9034. }
  9035. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9036. ctime := time.Now().Unix()
  9037. prescription := &models.HisPrescriptionInfoTemplate{
  9038. PatientId: patient_id,
  9039. UserOrgId: adminInfo.CurrentOrgId,
  9040. Ctime: ctime,
  9041. Mtime: ctime,
  9042. Type: types,
  9043. Modifier: adminInfo.AdminUser.Id,
  9044. Creator: adminInfo.AdminUser.Id,
  9045. Status: 1,
  9046. PTemplateId: template.ID,
  9047. MedType: med_type,
  9048. }
  9049. service.CreateHisPrescriptionInfoTemplate(prescription)
  9050. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9051. advices := items["advices"].([]interface{})
  9052. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9053. ctime := time.Now().Unix()
  9054. mtime := ctime
  9055. if len(advices) > 0 {
  9056. for _, advice := range advices {
  9057. var s models.HisPrescriptionAdviceTemplate
  9058. s.PrescriptionId = prescription.ID
  9059. s.AdviceType = 2
  9060. s.StopState = 2
  9061. s.ExecutionState = 2
  9062. s.Status = 1
  9063. s.UserOrgId = adminInfo.CurrentOrgId
  9064. s.CreatedTime = ctime
  9065. s.UpdatedTime = mtime
  9066. s.PatientId = patient_id
  9067. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9068. if errcode > 0 {
  9069. c.ServeFailJSONWithSGJErrorCode(errcode)
  9070. return
  9071. }
  9072. service.CreateHisPrescriptionAdviceTemplate(&s)
  9073. }
  9074. }
  9075. }
  9076. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9077. projects := items["project"].([]interface{})
  9078. if len(projects) > 0 {
  9079. for _, project := range projects {
  9080. var p models.HisPrescriptionProjectTemplate
  9081. p.PrescriptionId = prescription.ID
  9082. p.Ctime = time.Now().Unix()
  9083. p.Mtime = time.Now().Unix()
  9084. p.PatientId = patient_id
  9085. p.UserOrgId = adminInfo.CurrentOrgId
  9086. p.Status = 1
  9087. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9088. if errcode > 0 {
  9089. c.ServeFailJSONWithSGJErrorCode(errcode)
  9090. return
  9091. }
  9092. service.CreateHisPrescriptionProjectTemplate(&p)
  9093. }
  9094. }
  9095. }
  9096. }
  9097. c.ServeSuccessJSON(map[string]interface{}{
  9098. "msg": "创建成功",
  9099. })
  9100. }
  9101. }
  9102. }
  9103. }
  9104. func (c *HisApiController) PreSettle() {
  9105. id, _ := c.GetInt64("id")
  9106. record_time := c.GetString("record_time")
  9107. his_patient_id, _ := c.GetInt64("his_patient_id")
  9108. timeLayout := "2006-01-02"
  9109. loc, _ := time.LoadLocation("Local")
  9110. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9111. diagnosis_id := c.GetString("diagnosis")
  9112. sick_type, _ := c.GetInt64("sick_type")
  9113. reg_type, _ := c.GetInt64("p_type")
  9114. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9115. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9116. if err != nil {
  9117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9118. return
  9119. }
  9120. recordDateTime := theTime.Unix()
  9121. adminUser := c.GetAdminUserInfo()
  9122. var prescriptions []*models.HisPrescription
  9123. var start_time int64
  9124. var end_time int64
  9125. ids_str := c.GetString("ids")
  9126. ids_arr := strings.Split(ids_str, ",")
  9127. fmt.Println(reg_type)
  9128. if settle_accounts_type == 1 { //日结
  9129. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9130. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9131. } else {
  9132. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9133. }
  9134. fmt.Println(prescriptions)
  9135. } else { //月结
  9136. start_time_str := c.GetString("start_time")
  9137. end_time_str := c.GetString("end_time")
  9138. timeLayout := "2006-01-02"
  9139. loc, _ := time.LoadLocation("Local")
  9140. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9141. if err != nil {
  9142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9143. return
  9144. }
  9145. recordStartTime := theStartTime.Unix()
  9146. start_time = recordStartTime
  9147. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9148. if err != nil {
  9149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9150. return
  9151. }
  9152. recordEndTime := theEndTime.Unix()
  9153. end_time = recordEndTime
  9154. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9155. }
  9156. if reg_type == 1111 || reg_type == 1112 {
  9157. reg_type = 11
  9158. }
  9159. timestamp := time.Now().Unix()
  9160. tempTime := time.Unix(timestamp, 0)
  9161. timeFormat := tempTime.Format("20060102150405")
  9162. chrgBchno := rand.Intn(100000) + 10000
  9163. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9164. strconv.FormatInt(his.PatientId, 10)
  9165. var ids []int64
  9166. for _, item := range prescriptions {
  9167. ids = append(ids, item.ID)
  9168. }
  9169. fmt.Println(ids)
  9170. var total float64
  9171. for _, item := range prescriptions {
  9172. fmt.Println(item)
  9173. if item.Type == 1 { //药品
  9174. for _, subItem := range item.HisDoctorAdviceInfo {
  9175. total = total + (subItem.Price * subItem.PrescribingNumber)
  9176. }
  9177. }
  9178. if item.Type == 2 { //项目
  9179. for _, subItem := range item.HisPrescriptionProject {
  9180. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9181. total = total + (subItem.Price * cnt)
  9182. }
  9183. }
  9184. for _, subItem := range item.HisAdditionalCharge {
  9185. total = total + (subItem.Price * float64(subItem.Count))
  9186. }
  9187. }
  9188. allTotal := fmt.Sprintf("%.2f", total)
  9189. totals, _ := strconv.ParseFloat(allTotal, 64)
  9190. order := &models.HisOrder{
  9191. UserOrgId: adminUser.CurrentOrgId,
  9192. HisPatientId: his.ID,
  9193. PatientId: id,
  9194. SettleAccountsDate: recordDateTime,
  9195. Ctime: time.Now().Unix(),
  9196. Mtime: time.Now().Unix(),
  9197. Status: 1,
  9198. OrderStatus: 1,
  9199. MdtrtId: his.Number,
  9200. Number: chrg_bchno,
  9201. MedfeeSumamt: totals,
  9202. SettleEndTime: end_time,
  9203. SettleStartTime: start_time,
  9204. SettleType: settle_accounts_type,
  9205. PsnPartAmt: totals,
  9206. PsnCashPay: totals,
  9207. PType: 2,
  9208. IsPre: 1,
  9209. MedType: strconv.Itoa(int(reg_type)),
  9210. Diagnosis: diagnosis_id,
  9211. }
  9212. err = service.CreateOrder(order)
  9213. if err != nil {
  9214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9215. return
  9216. }
  9217. var customs []*Custom
  9218. for _, item := range prescriptions {
  9219. fmt.Println(item.Type)
  9220. if item.Type == 1 { //药品
  9221. for _, subItem := range item.HisDoctorAdviceInfo {
  9222. cus := &Custom{
  9223. AdviceId: subItem.ID,
  9224. ProjectId: 0,
  9225. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9226. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9227. FeedetlSn: subItem.FeedetlSn,
  9228. Price: fmt.Sprintf("%.2f", subItem.Price),
  9229. MedListCodg: subItem.MedListCodg,
  9230. Type: 1,
  9231. }
  9232. customs = append(customs, cus)
  9233. }
  9234. }
  9235. if item.Type == 2 { //项目
  9236. for _, subItem := range item.HisPrescriptionProject {
  9237. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9238. cus := &Custom{
  9239. AdviceId: 0,
  9240. ProjectId: subItem.ID,
  9241. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9242. Cut: fmt.Sprintf("%.2f", cnt),
  9243. FeedetlSn: subItem.FeedetlSn,
  9244. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9245. MedListCodg: subItem.MedListCodg,
  9246. Type: 2,
  9247. }
  9248. customs = append(customs, cus)
  9249. }
  9250. }
  9251. for _, item := range item.HisAdditionalCharge {
  9252. cus := &Custom{
  9253. ItemId: item.ID,
  9254. AdviceId: 0,
  9255. ProjectId: 0,
  9256. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9257. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9258. FeedetlSn: item.FeedetlSn,
  9259. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9260. MedListCodg: item.XtHisAddtionConfig.Code,
  9261. Type: 3,
  9262. }
  9263. customs = append(customs, cus)
  9264. }
  9265. }
  9266. fmt.Println(customs)
  9267. for _, item := range customs {
  9268. var advice_id int64 = 0
  9269. var project_id int64 = 0
  9270. var item_id int64 = 0
  9271. var types int64 = 0
  9272. if item.Type == 1 {
  9273. advice_id = item.AdviceId
  9274. project_id = 0
  9275. item_id = 0
  9276. } else if item.Type == 2 {
  9277. advice_id = 0
  9278. item_id = 0
  9279. project_id = item.ProjectId
  9280. } else if item.Type == 3 {
  9281. advice_id = 0
  9282. item_id = item.ItemId
  9283. project_id = 0
  9284. }
  9285. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9286. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9287. pric, _ := strconv.ParseFloat(item.Price, 32)
  9288. info := &models.HisOrderInfo{
  9289. OrderNumber: order.Number,
  9290. UploadDate: time.Now().Unix(),
  9291. AdviceId: advice_id,
  9292. DetItemFeeSumamt: detItemFeeSumamt,
  9293. Cnt: cut,
  9294. Pric: pric,
  9295. PatientId: id,
  9296. Status: 1,
  9297. Mtime: time.Now().Unix(),
  9298. Ctime: time.Now().Unix(),
  9299. UserOrgId: adminUser.CurrentOrgId,
  9300. HisPatientId: his.ID,
  9301. OrderId: order.ID,
  9302. ProjectId: project_id,
  9303. Type: types,
  9304. ItemId: item_id,
  9305. }
  9306. service.CreateOrderInfo(info)
  9307. }
  9308. his.SickType = sick_type
  9309. service.UpdataHisPateint(&his)
  9310. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9311. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9312. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9313. if err == nil {
  9314. c.ServeSuccessJSON(map[string]interface{}{
  9315. "msg": "结算成功",
  9316. })
  9317. }
  9318. }
  9319. type CustomOrderInfo struct {
  9320. Name string
  9321. Spec string
  9322. Unit string
  9323. Count float64
  9324. Price float64
  9325. Total float64
  9326. }
  9327. func (c *HisApiController) GetPrivateExpensesInfo() {
  9328. order_id, _ := c.GetInt64("id", 0)
  9329. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9330. order, _ := service.GetHisOrderByID(order_id)
  9331. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9332. if order.ID == 0 {
  9333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9334. return
  9335. }
  9336. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9337. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9338. org_id := c.GetAdminUserInfo().CurrentOrgId
  9339. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9340. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9341. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9342. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9343. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9344. //var orderInfos_four []*models.HisOrderInfoTwo
  9345. //for _, item := range orderInfos_three {
  9346. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9347. // item.HisPrescriptionProject.IsCheckTeam = 1
  9348. // orderInfos_four = append(orderInfos_four, item)
  9349. //
  9350. // }
  9351. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9352. // item.HisPrescriptionProject.IsCheckTeam = 2
  9353. // orderInfos_two = append(orderInfos_two, item)
  9354. // }
  9355. //}
  9356. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9357. //var cus_slice []CustomOrderInfo
  9358. //for _, item := range new_order_info {
  9359. // var cus CustomOrderInfo
  9360. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9361. // cus.Unit = ""
  9362. // cus.Spec = ""
  9363. // var total float64
  9364. // for _, subItem := range orderInfos_four {
  9365. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9366. // total = total + subItem.DetItemFeeSumamt
  9367. // fmt.Println(subItem.DetItemFeeSumamt)
  9368. // }
  9369. // }
  9370. // cus.Count = 1
  9371. // cus.Total = total
  9372. // cus_slice = append(cus_slice, cus)
  9373. //}
  9374. orderInfos = append(orderInfos, orderInfos_two...)
  9375. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9376. //orderInfos = append(orderInfos, orderInfos_three...)
  9377. //}/**/
  9378. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9379. c.ServeSuccessJSON(map[string]interface{}{
  9380. "order": order,
  9381. "order_info": orderInfos,
  9382. "patient": patient,
  9383. "admin_info": adminInfo,
  9384. "his": his,
  9385. "current_admin": role,
  9386. "org_config": miConfig,
  9387. //"new_order_info": cus_slice,
  9388. })
  9389. }
  9390. func (this *HisApiController) ChangeMedType() {
  9391. med_type := this.GetString("med_type")
  9392. old_med_type := this.GetString("old_med_type")
  9393. ids := this.GetString("ids")
  9394. settle_type, _ := this.GetInt64("settle_type")
  9395. start_time := this.GetString("start_time")
  9396. end_time := this.GetString("end_time")
  9397. ids_arr := strings.Split(ids, ",")
  9398. if settle_type == 1 { //日结
  9399. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9400. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9401. prescription.MedType = med_type
  9402. err := service.SaveHisPrescription(&prescription)
  9403. if err == nil {
  9404. this.ServeSuccessJSON(map[string]interface{}{
  9405. "msg": "修改成功",
  9406. })
  9407. } else {
  9408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9409. return
  9410. }
  9411. } else if settle_type == 2 {
  9412. timeLayout := "2006-01-02"
  9413. loc, _ := time.LoadLocation("Local")
  9414. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9415. if err != nil {
  9416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9417. return
  9418. }
  9419. recordStartTime := theStartTime.Unix()
  9420. start_time_timestamp := recordStartTime
  9421. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9422. if err != nil {
  9423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9424. return
  9425. }
  9426. recordEndTime := theEndTime.Unix()
  9427. end_time_timestamp := recordEndTime
  9428. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9429. if updateErr == nil {
  9430. this.ServeSuccessJSON(map[string]interface{}{
  9431. "msg": "修改成功",
  9432. })
  9433. } else {
  9434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9435. return
  9436. }
  9437. }
  9438. }
  9439. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9440. patient_id, _ := c.GetInt64("patient_id")
  9441. his_patient_id, _ := c.GetInt64("his_patient_id")
  9442. record_date := c.GetString("record_date")
  9443. start_time := c.GetString("start_time")
  9444. end_time := c.GetString("end_time")
  9445. order_status, _ := c.GetInt64("type", 0)
  9446. p_type, _ := c.GetInt64("p_type", 0)
  9447. order_id, _ := c.GetInt64("order_id", 0)
  9448. timeLayout := "2006-01-02"
  9449. loc, _ := time.LoadLocation("Local")
  9450. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9451. if err != nil {
  9452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9453. return
  9454. }
  9455. recordDateTime := theTime.Unix()
  9456. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9457. if err != nil {
  9458. }
  9459. startRecordDateTime := startTime.Unix()
  9460. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9461. if err != nil {
  9462. }
  9463. endRecordDateTime := endTime.Unix()
  9464. admin := c.GetAdminUserInfo()
  9465. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9466. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9467. order, _ := service.GetHisOrderByID(order_id)
  9468. var monthPrescriptions []*models.HisPrescription
  9469. if order_status == 1 || order_status == 0 {
  9470. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9471. } else if order_status == 2 {
  9472. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9473. }
  9474. var settle_total float64
  9475. for _, item := range monthPrescriptions {
  9476. if len(item.HisPrescriptionProject) > 0 {
  9477. for _, subItem := range item.HisPrescriptionProject {
  9478. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9479. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9480. settle_total = settle_total + total
  9481. }
  9482. }
  9483. if len(item.HisDoctorAdviceInfo) > 0 {
  9484. for _, subItem := range item.HisDoctorAdviceInfo {
  9485. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9486. settle_total = settle_total + total
  9487. }
  9488. }
  9489. }
  9490. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9491. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9492. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9493. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9494. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9495. //获取所有科室信息
  9496. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9497. c.ServeSuccessJSON(map[string]interface{}{
  9498. "his_info": his_patient_info,
  9499. "xt_info": xt_patient_info,
  9500. "case_history": case_history,
  9501. "info": patientPrescriptionInfo,
  9502. "last_info": lastPatientPrescriptionInfo,
  9503. "month_prescriptions": monthPrescriptions,
  9504. "order": order,
  9505. "doctors": doctors,
  9506. "department": department,
  9507. "settle_total": settle_total,
  9508. })
  9509. return
  9510. }
  9511. func (c *HisApiController) GetHisMonthPatientInfo() {
  9512. patient_id, _ := c.GetInt64("patient_id")
  9513. his_patient_id, _ := c.GetInt64("his_patient_id")
  9514. record_date := c.GetString("record_date")
  9515. number := c.GetString("number")
  9516. start_time := c.GetString("start_time")
  9517. end_time := c.GetString("end_time")
  9518. p_type, _ := c.GetInt64("p_type")
  9519. timeLayout := "2006-01-02"
  9520. loc, _ := time.LoadLocation("Local")
  9521. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9522. if err != nil {
  9523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9524. return
  9525. }
  9526. recordDateTime := theTime.Unix()
  9527. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9528. if err != nil {
  9529. }
  9530. startRecordDateTime := startTime.Unix()
  9531. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9532. if err != nil {
  9533. }
  9534. endRecordDateTime := endTime.Unix()
  9535. admin := c.GetAdminUserInfo()
  9536. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9537. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9538. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9539. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9540. var settle_total float64
  9541. for _, item := range monthPrescriptions {
  9542. if len(item.HisPrescriptionProject) > 0 {
  9543. for _, subItem := range item.HisPrescriptionProject {
  9544. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9545. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9546. settle_total = settle_total + total
  9547. }
  9548. }
  9549. if len(item.HisDoctorAdviceInfo) > 0 {
  9550. for _, subItem := range item.HisDoctorAdviceInfo {
  9551. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9552. settle_total = settle_total + total
  9553. }
  9554. }
  9555. }
  9556. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9557. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9558. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9559. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9560. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9561. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9562. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9563. //获取所有科室信息
  9564. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9565. c.ServeSuccessJSON(map[string]interface{}{
  9566. "his_info": his_patient_info,
  9567. "xt_info": xt_patient_info,
  9568. "case_history": case_history,
  9569. "info": patientPrescriptionInfo,
  9570. "month_prescriptions": monthPrescriptions,
  9571. "order": order,
  9572. "doctors": doctors,
  9573. "department": department,
  9574. "count": count,
  9575. "drugStockConfig": drugStockConfig,
  9576. "last_info": lastPatientPrescriptionInfo,
  9577. "settle_total": settle_total,
  9578. })
  9579. return
  9580. }
  9581. func (c *HisApiController) GetAllOrder() {
  9582. org_id := c.GetAdminUserInfo().CurrentOrgId
  9583. orders, _ := service.GetNewHisOrderList(org_id)
  9584. c.ServeSuccessJSON(map[string]interface{}{
  9585. "order": orders,
  9586. })
  9587. return
  9588. }
  9589. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9590. newArr = make([]*models.HisOrderInfoTwo, 0)
  9591. for i := 0; i < len(arr); i++ {
  9592. repeat := false
  9593. for j := i + 1; j < len(arr); j++ {
  9594. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9595. repeat = true
  9596. break
  9597. }
  9598. }
  9599. if !repeat {
  9600. newArr = append(newArr, arr[i])
  9601. }
  9602. }
  9603. return
  9604. }
  9605. // 修改处方退库操作 参数传修改之前的处方数据
  9606. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9607. if advice.ExecutionState == 1 {
  9608. //查询该病人该药品是否有库存记录
  9609. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9610. if errcode == gorm.ErrRecordNotFound {
  9611. } else {
  9612. //退库
  9613. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9614. if advice.PrescribingNumberUnit == drug.MinUnit {
  9615. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9616. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9617. //退库
  9618. warehouseInfo := models.DrugWarehouseInfo{
  9619. StockMinNumber: prescribingNumber,
  9620. }
  9621. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9622. operation_time := time.Now().Unix()
  9623. creater := advice.AdviceDoctor
  9624. ctime := time.Now().Unix()
  9625. timeStr := time.Now().Format("2006-01-02")
  9626. timeArr := strings.Split(timeStr, "-")
  9627. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9628. total = total + 1
  9629. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9630. cancelStock := models.DrugCancelStock{
  9631. OrderNumber: orderNumber,
  9632. OperaTime: operation_time,
  9633. OrgId: advice.UserOrgId,
  9634. Creater: creater,
  9635. Ctime: ctime,
  9636. Status: 1,
  9637. ReturnTime: advice.AdviceDate,
  9638. Dealer: info.Dealer,
  9639. Manufacturer: info.Manufacturer,
  9640. Type: 1,
  9641. }
  9642. service.AddSigleDrugCancelStock(&cancelStock)
  9643. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9644. dealer, _ := service.GetDealerById(info.Dealer)
  9645. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9646. cancelStockInfo := models.DrugCancelStockInfo{
  9647. OrderNumber: cancelInfo.OrderNumber,
  9648. CancelStockId: cancelInfo.ID,
  9649. DrugId: info.DrugId,
  9650. Count: info.Count,
  9651. Status: 1,
  9652. Ctime: ctime,
  9653. OrgId: advice.UserOrgId,
  9654. Type: 1,
  9655. Manufacturer: manufactureName.ManufacturerName,
  9656. Dealer: dealer.DealerName,
  9657. Total: 0,
  9658. RetailPrice: info.RetailPrice,
  9659. RetailTotalPrice: info.RetailTotalPrice,
  9660. Price: info.Price,
  9661. RegisterAccount: "",
  9662. Remark: info.Remark,
  9663. BatchNumber: info.BatchNumber,
  9664. MaxUnit: info.CountUnit,
  9665. ProductDate: info.ProductDate,
  9666. ExpiryDate: info.ExpiryDate,
  9667. BatchNumberId: info.WarehouseInfoId,
  9668. }
  9669. flow := models.DrugFlow{
  9670. WarehousingId: 0,
  9671. DrugId: info.DrugId,
  9672. Number: "",
  9673. BatchNumber: info.BatchNumber,
  9674. Count: info.Count,
  9675. UserOrgId: advice.UserOrgId,
  9676. PatientId: 0,
  9677. SystemTime: ctime,
  9678. ConsumableType: 4,
  9679. IsSys: 0,
  9680. WarehousingOrder: "",
  9681. WarehouseOutId: 0,
  9682. WarehouseOutOrderNumber: "",
  9683. IsEdit: 0,
  9684. CancelStockId: cancelStock.ID,
  9685. CancelOrderNumber: cancelStock.OrderNumber,
  9686. Manufacturer: info.Manufacturer,
  9687. Dealer: info.Dealer,
  9688. Creator: advice.UserOrgId,
  9689. UpdateCreator: 0,
  9690. Status: 1,
  9691. Ctime: time.Now().Unix(),
  9692. Mtime: 0,
  9693. Price: info.Price,
  9694. WarehousingDetailId: 0,
  9695. WarehouseOutDetailId: 0,
  9696. CancelOutDetailId: 0,
  9697. ExpireDate: info.ExpiryDate,
  9698. ProductDate: info.ProductDate,
  9699. MaxUnit: info.CountUnit,
  9700. MinUnit: "",
  9701. }
  9702. service.CreatedCancelStock(cancelStockInfo)
  9703. service.CreateDrugFlowOne(flow)
  9704. } else {
  9705. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9706. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9707. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9708. warehouseInfo := models.DrugWarehouseInfo{
  9709. StockMinNumber: prescribingNumber,
  9710. }
  9711. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9712. }
  9713. operation_time := time.Now().Unix()
  9714. creater := advice.AdviceDoctor
  9715. ctime := time.Now().Unix()
  9716. timeStr := time.Now().Format("2006-01-02")
  9717. timeArr := strings.Split(timeStr, "-")
  9718. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9719. total = total + 1
  9720. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9721. cancelStock := models.DrugCancelStock{
  9722. OrderNumber: orderNumber,
  9723. OperaTime: operation_time,
  9724. OrgId: advice.UserOrgId,
  9725. Creater: creater,
  9726. Ctime: ctime,
  9727. Status: 1,
  9728. ReturnTime: advice.AdviceDate,
  9729. Dealer: info.Dealer,
  9730. Manufacturer: info.Manufacturer,
  9731. Type: 1,
  9732. }
  9733. service.AddSigleDrugCancelStock(&cancelStock)
  9734. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9735. dealer, _ := service.GetDealerById(info.Dealer)
  9736. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9737. cancelStockInfo := models.DrugCancelStockInfo{
  9738. OrderNumber: cancelInfo.OrderNumber,
  9739. CancelStockId: cancelInfo.ID,
  9740. DrugId: info.DrugId,
  9741. Count: info.Count,
  9742. Status: 1,
  9743. Ctime: ctime,
  9744. OrgId: advice.UserOrgId,
  9745. Type: 1,
  9746. Manufacturer: manufactureName.ManufacturerName,
  9747. Dealer: dealer.DealerName,
  9748. Total: 0,
  9749. RetailPrice: info.RetailPrice,
  9750. RetailTotalPrice: info.RetailTotalPrice,
  9751. Price: info.Price,
  9752. RegisterAccount: "",
  9753. Remark: info.Remark,
  9754. BatchNumber: info.BatchNumber,
  9755. MaxUnit: info.CountUnit,
  9756. ProductDate: info.ProductDate,
  9757. ExpiryDate: info.ExpiryDate,
  9758. BatchNumberId: info.WarehouseInfoId,
  9759. }
  9760. flow := models.DrugFlow{
  9761. WarehousingId: 0,
  9762. DrugId: info.DrugId,
  9763. Number: "",
  9764. BatchNumber: info.BatchNumber,
  9765. Count: info.Count,
  9766. UserOrgId: advice.UserOrgId,
  9767. PatientId: 0,
  9768. SystemTime: ctime,
  9769. ConsumableType: 4,
  9770. IsSys: 0,
  9771. WarehousingOrder: "",
  9772. WarehouseOutId: 0,
  9773. WarehouseOutOrderNumber: "",
  9774. IsEdit: 0,
  9775. CancelStockId: cancelStock.ID,
  9776. CancelOrderNumber: cancelStock.OrderNumber,
  9777. Manufacturer: info.Manufacturer,
  9778. Dealer: info.Dealer,
  9779. Creator: advice.AdviceDoctor,
  9780. UpdateCreator: 0,
  9781. Status: 1,
  9782. Ctime: time.Now().Unix(),
  9783. Mtime: 0,
  9784. Price: info.Price,
  9785. WarehousingDetailId: 0,
  9786. WarehouseOutDetailId: 0,
  9787. CancelOutDetailId: 0,
  9788. ExpireDate: info.ExpiryDate,
  9789. ProductDate: info.ProductDate,
  9790. MaxUnit: info.CountUnit,
  9791. MinUnit: "",
  9792. }
  9793. service.CreatedCancelStock(cancelStockInfo)
  9794. service.CreateDrugFlowOne(flow)
  9795. }
  9796. }
  9797. }
  9798. return err
  9799. }
  9800. func (this *HisApiController) DeleteNCDS() {
  9801. id, _ := this.GetInt64("id", 0)
  9802. if id > 0 {
  9803. service.DeletePsnNCDSRecordById(id)
  9804. this.ServeSuccessJSON(map[string]interface{}{
  9805. "msg": "删除成功",
  9806. })
  9807. } else {
  9808. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9809. return
  9810. }
  9811. }
  9812. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9813. id, _ := c.GetInt64("id")
  9814. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9815. c.ServeSuccessJSON(map[string]interface{}{
  9816. "advice": advice,
  9817. })
  9818. return
  9819. }
  9820. func (c *HisApiController) GetHisMonthChargePatientList() {
  9821. record_date := c.GetString("record_date")
  9822. start_time := c.GetString("start_time")
  9823. end_time := c.GetString("end_time")
  9824. timeLayout := "2006-01-02"
  9825. loc, _ := time.LoadLocation("Local")
  9826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9827. if err != nil {
  9828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9829. return
  9830. }
  9831. if err != nil {
  9832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9833. return
  9834. }
  9835. recordDateTime := theTime.Unix()
  9836. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9837. if err != nil {
  9838. }
  9839. startRecordDateTime := startTime.Unix()
  9840. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9841. if err != nil {
  9842. }
  9843. endRecordDateTime := endTime.Unix()
  9844. adminInfo := c.GetAdminUserInfo()
  9845. var tempMonthChargePatients []*service.MonthChargePatients
  9846. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9847. for _, item := range tempPatients {
  9848. //过滤没有处方的
  9849. if len(item.HisPrescription) == 0 {
  9850. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9851. }
  9852. }
  9853. c.ServeSuccessJSON(map[string]interface{}{
  9854. "list": tempMonthChargePatients,
  9855. })
  9856. }