his_api_controller.go 438KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291
  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. //beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. //beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. //func (c *HisApiController) CheckHisPatient() {
  91. // record_date := c.GetString("record_date")
  92. // patient_id, _ := c.GetInt64("patient_id")
  93. //
  94. // timeLayout := "2006-01-02"
  95. // loc, _ := time.LoadLocation("Local")
  96. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. // if err != nil {
  98. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. // return
  100. // }
  101. // recordDateTime := theTime.Unix()
  102. // adminInfo := c.GetAdminUserInfo()
  103. // patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. // if len(patients) > 1 {
  105. // ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. // if len(ps) > 0 {
  107. // c.ServeSuccessJSON(map[string]interface{}{
  108. // "status": 1,
  109. // "msg": "关联",
  110. // "ps": ps,
  111. // })
  112. // } else {
  113. // c.ServeSuccessJSON(map[string]interface{}{
  114. // "status": 0,
  115. // "msg": "无需关联",
  116. // })
  117. // }
  118. // } else {
  119. // c.ServeSuccessJSON(map[string]interface{}{
  120. // "status": 0,
  121. // "msg": "无需关联",
  122. // })
  123. // return
  124. // }
  125. //}
  126. //func (c *HisApiController) AssociationHisPrescription() {
  127. // record_date, _ := c.GetInt64("record_date")
  128. // his_patient_id, _ := c.GetInt64("his_patient_id")
  129. // patient_id, _ := c.GetInt64("patient_id")
  130. // p_ids := c.GetString("p_ids")
  131. // p_ids_arr := strings.Split(p_ids, ",")
  132. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  133. // if his_patient_id == 0 || his_patient.ID == 0 {
  134. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. // return
  136. // }
  137. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  138. // if err == nil {
  139. // c.ServeSuccessJSON(map[string]interface{}{
  140. // "msg": "关联处方成功",
  141. // })
  142. // return
  143. // } else {
  144. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  145. // return
  146. // }
  147. //}
  148. //func (c *HisApiController) AssociationHisPrescription() {
  149. // record_date, _ := c.GetInt64("record_date")
  150. // his_patient_id, _ := c.GetInt64("his_patient_id")
  151. // patient_id, _ := c.GetInt64("patient_id")
  152. // p_ids := c.GetString("p_ids")
  153. // p_ids_arr := strings.Split(p_ids, ",")
  154. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  155. // if his_patient_id == 0 || his_patient.ID == 0 {
  156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. // return
  158. // }
  159. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  160. // if err == nil {
  161. // c.ServeSuccessJSON(map[string]interface{}{
  162. // "msg": "关联处方成功",
  163. // })
  164. // return
  165. // } else {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  167. // return
  168. // }
  169. //}
  170. func (c *HisApiController) GetFaPiaoNumber() {
  171. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  172. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  173. fmt.Println(count)
  174. var zero string
  175. number := count + 1
  176. if number >= 1000 {
  177. zero = "0000" + strconv.FormatInt(number, 10)
  178. } else if number >= 10000 {
  179. zero = "000" + strconv.FormatInt(number, 10)
  180. } else if number >= 100000 {
  181. zero = "00" + strconv.FormatInt(number, 10)
  182. } else if number >= 1000000 {
  183. zero = "0" + strconv.FormatInt(number, 10)
  184. } else {
  185. zero = strconv.FormatInt(number, 10)
  186. }
  187. c.ServeSuccessJSON(map[string]interface{}{
  188. "fapiao_number": zero,
  189. })
  190. return
  191. }
  192. func (c *HisApiController) ChangeOrderDesc() {
  193. id, _ := c.GetInt64("id")
  194. desc := c.GetString("desc")
  195. change_type := c.GetString("change_type")
  196. order, _ := service.GetHisOrderByID(id)
  197. if order.ID == 0 {
  198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  199. return
  200. }
  201. switch change_type {
  202. case "oth_desc":
  203. order.OthDesc = desc
  204. break
  205. case "cash_pay":
  206. order.CashPay = desc
  207. break
  208. case "jifen_pay":
  209. order.JifenPay = desc
  210. break
  211. case "band_card_pay":
  212. order.BandCardPay = desc
  213. break
  214. case "ali_pay":
  215. order.AliPay = desc
  216. break
  217. case "wechat_pay":
  218. order.WechatPay = desc
  219. break
  220. case "fa_piao_number":
  221. order.FaPiaoNumber = desc
  222. break
  223. case "fa_piao_code":
  224. order.FaPiaoCode = desc
  225. break
  226. }
  227. err := service.SaveHisOrder(&order)
  228. if err == nil {
  229. c.ServeSuccessJSON(map[string]interface{}{
  230. "msg": "修改成功",
  231. })
  232. return
  233. } else {
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  235. return
  236. }
  237. }
  238. func (c *HisApiController) GetMonthHisPatient() {
  239. record_date := c.GetString("record_date")
  240. //order_status, _ := c.GetInt64("type")
  241. timeLayout := "2006-01-02"
  242. loc, _ := time.LoadLocation("Local")
  243. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  244. if err != nil {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. recordDateTime := theTime.Unix()
  249. adminInfo := c.GetAdminUserInfo()
  250. var tempPatients []service.NewTempPatients
  251. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  252. // 获取当前时间
  253. now := time.Now()
  254. // 获取本月的第一天
  255. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  256. // 获取下个月的第一天
  257. nextMonth := firstDay.AddDate(0, 1, 0)
  258. // 获取本月的最后一天
  259. lastDay := nextMonth.Add(-time.Nanosecond)
  260. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  261. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  262. var patients []service.NewTempPatients
  263. var patients_two []service.NewTempPatients
  264. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  265. for _, item := range tempPatients {
  266. //过滤掉没挂号的和没开处方的
  267. if len(item.HisPrescription) > 0 {
  268. patients = append(patients, item)
  269. patients_two = append(patients_two, item)
  270. }
  271. ////过滤掉没挂号的
  272. //if len(item.HisPatient) > 0 {
  273. //}
  274. }
  275. } else {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. // patients_two = append(patients_two, item)
  284. //}
  285. }
  286. }
  287. c.ServeSuccessJSON(map[string]interface{}{
  288. "list": patients,
  289. "list_two": patients_two,
  290. "chargePatients": chargePatients,
  291. })
  292. }
  293. func (c *HisApiController) GetBatchSettleAccounts() {
  294. order_ids := c.GetString("order_ids")
  295. admin_user_id, _ := c.GetInt64("admin_user_id")
  296. adminUser := c.GetAdminUserInfo()
  297. orders := strings.Split(order_ids, ",")
  298. var newOrders []models.Orders
  299. for _, item := range orders {
  300. order, _ := service.GetHisOrderByIDTenOne(item)
  301. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  302. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  303. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  304. orderInfos = append(orderInfos, orderInfos_two...)
  305. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  306. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  307. var diagnosis_ids []string
  308. if his.ID > 0 {
  309. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  310. } else {
  311. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  312. }
  313. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  314. var dia_config []*models.HisXtDiagnoseConfig
  315. var name string
  316. for _, item := range diagnosis_ids {
  317. id, _ := strconv.ParseInt(item, 10, 64)
  318. diagnosisConfig, _ := service.FindDiagnoseById(id)
  319. dia_config = append(dia_config, diagnosisConfig)
  320. if len(name) == 0 {
  321. name = diagnosisConfig.ClassName
  322. } else {
  323. name = name + "," + diagnosisConfig.ClassName
  324. }
  325. }
  326. var bedCostTotal float64 = 0 //床位总费
  327. var bedCostSelfTotal float64 = 0 //床位自费
  328. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  329. var bedSelfTotal float64 = 0 //床位部分项目自费
  330. var bedInscpTotal float64 = 0 //床位部分项目自费
  331. var operationCostTotal float64 = 0 //手术费
  332. var operationCostSelfTotal float64 = 0 //手术费
  333. var operationCostPartSelfTotal float64 = 0 //手术费
  334. var operationSelfTotal float64 = 0 //床位部分项目自费
  335. var operationInscpTotal float64 = 0 //床位部分项目自费
  336. var otherCostTotal float64 = 0 //其他费用
  337. var otherCostSelfTotal float64 = 0 //其他费用
  338. var otherCostPartSelfTotal float64 = 0 //其他费用
  339. var otherSelfTotal float64 = 0 //床位部分项目自费
  340. var otherInscpTotal float64 = 0 //床位部分项目自费
  341. var materialCostTotal float64 = 0 //材料费
  342. var materialCostSelfTotal float64 = 0 //材料费
  343. var materialCostPartSelfTotal float64 = 0 //材料费
  344. var materialSelfTotal float64 = 0 //床位部分项目自费
  345. var materialInscpTotal float64 = 0 //床位部分项目自费
  346. var westernMedicineCostTotal float64 = 0 //西药费
  347. var westernMedicineCostSelfTotal float64 = 0 //西药费
  348. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  349. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  350. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  351. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  352. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  353. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  354. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  355. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  356. var checkCostTotal float64 = 0 //检查费
  357. var checkCostSelfTotal float64 = 0 //检查费
  358. var checkCostPartSelfTotal float64 = 0 //检查费
  359. var checkSelfTotal float64 = 0 //床位部分项目自费
  360. var checkInscpTotal float64 = 0 //床位部分项目自费
  361. var laboratoryCostTotal float64 = 0 //化验费
  362. var laboratoryCostSelfTotal float64 = 0 //化验费
  363. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  364. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  365. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  366. var treatCostTotal float64 = 0 //治疗费用
  367. var treatCostSelfTotal float64 = 0 //治疗费用
  368. var treatCostPartSelfTotal float64 = 0 //治疗费用
  369. var treatSelfTotal float64 = 0 //床位部分项目自费
  370. var treatInscpTotal float64 = 0 //床位部分项目自费
  371. decimal.DivisionPrecision = 2
  372. for _, item := range orderInfos {
  373. if item.MedChrgitmType == "01" { //床位费
  374. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  375. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  376. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  377. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  378. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  379. }
  380. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  381. if item.MedChrgitmType == "03" { //检查费
  382. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  383. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  384. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  385. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  386. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  387. }
  388. } else {
  389. if item.MedChrgitmType == "03" { //检查费
  390. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  391. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  392. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  393. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  394. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  395. }
  396. }
  397. if item.MedChrgitmType == "04" { //化验费
  398. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  399. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  400. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  401. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  402. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  403. }
  404. if item.MedChrgitmType == "05" { //治疗费
  405. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  406. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  407. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  408. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  409. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  410. }
  411. if item.MedChrgitmType == "06" { //手术费
  412. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  413. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  414. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  415. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  416. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  417. }
  418. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  419. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. if item.MedChrgitmType == "09" { //西药费
  426. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  427. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  428. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  429. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  430. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  431. }
  432. if item.MedChrgitmType == "11" { //中成费
  433. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  434. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  435. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  436. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  437. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  438. }
  439. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  440. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  441. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  442. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  443. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  444. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  445. }
  446. }
  447. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  448. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  449. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  450. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  451. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  452. var doctor_name string
  453. if roles.ID == 0 {
  454. doctor_name = "管理员"
  455. } else {
  456. doctor_name = roles.UserName
  457. }
  458. yiliao_leibie := ""
  459. switch order.MedType {
  460. case "11":
  461. yiliao_leibie = "普通门诊"
  462. break
  463. case "12":
  464. yiliao_leibie = "门诊挂号"
  465. break
  466. case "13":
  467. yiliao_leibie = "急诊"
  468. break
  469. case "14":
  470. yiliao_leibie = "门诊特殊病"
  471. break
  472. case "15":
  473. yiliao_leibie = "门诊统筹"
  474. break
  475. case "16":
  476. yiliao_leibie = "门诊慢性病"
  477. break
  478. case "21":
  479. yiliao_leibie = "普通住院"
  480. break
  481. }
  482. var newOrder models.Orders
  483. newOrder.Diagnosis = name
  484. newOrder.OrderInfos = orderInfos
  485. newOrder.Number = order.MdtrtId
  486. newOrder.Date = order.SettleAccountsDate
  487. newOrder.ChargeAdmin = charge_admin
  488. newOrder.PrintorAdmin = printor_admin
  489. newOrder.Order = order
  490. newOrder.BedCostTotal = bedCostTotal
  491. newOrder.BedCostSelfTotal = bedCostSelfTotal
  492. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  493. newOrder.BedSelfTotal = bedSelfTotal
  494. newOrder.BedInscpTotal = bedInscpTotal
  495. newOrder.OperationCostTotal = operationCostTotal
  496. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  497. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  498. newOrder.OperationSelfTotal = operationSelfTotal
  499. newOrder.OperationInscpTotal = operationInscpTotal
  500. newOrder.OtherCostTotal = otherCostTotal
  501. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  502. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  503. newOrder.OtherSelfTotal = otherSelfTotal
  504. newOrder.OtherInscpTotal = otherInscpTotal
  505. newOrder.MaterialCostTotal = materialCostTotal
  506. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  507. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  508. newOrder.MaterialSelfTotal = materialSelfTotal
  509. newOrder.MaterialInscpTotal = materialInscpTotal
  510. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  511. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  512. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  513. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  514. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  515. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  516. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  517. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  518. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  519. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  520. newOrder.CheckCostTotal = checkCostTotal
  521. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  522. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  523. newOrder.CheckSelfTotal = checkSelfTotal
  524. newOrder.CheckInscpTotal = checkInscpTotal
  525. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  526. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  527. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  528. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  529. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  530. newOrder.TreatCostTotal = treatCostTotal
  531. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  532. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  533. newOrder.TreatSelfTotal = treatSelfTotal
  534. newOrder.TreatInscpTotal = treatInscpTotal
  535. newOrder.DoctorInfo = doctor_info
  536. newOrder.DoctorName = doctor_name
  537. newOrder.HealthCardNo = order.PsnNo
  538. newOrder.YiliaoLeibie = yiliao_leibie
  539. newOrder.Patient = patient
  540. newOrder.OrgName = miConfig.OrgName
  541. newOrder.OrgCode = miConfig.Code
  542. newOrder.OrderNumber = order.Number
  543. newOrder.HisPatient = his
  544. newOrder.DiaConfig = dia_config
  545. newOrders = append(newOrders, newOrder)
  546. }
  547. c.ServeSuccessJSON(map[string]interface{}{
  548. "orders": newOrders,
  549. })
  550. }
  551. func (c *HisApiController) GetTestOrder() {
  552. order_id, _ := c.GetInt64("order_id")
  553. admin_user_id, _ := c.GetInt64("admin_user_id")
  554. adminUser := c.GetAdminUserInfo()
  555. order, _ := service.GetHisOrderByID(order_id)
  556. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  557. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  558. orderInfos = append(orderInfos, orderInfos_two...)
  559. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  560. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  561. var dia_config []*models.HisXtDiagnoseConfig
  562. var name string
  563. var bedCostTotal float64 = 0 //床位总费
  564. var bedCostSelfTotal float64 = 0 //床位自费
  565. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  566. var bedSelfTotal float64 = 0 //床位部分项目自费
  567. var bedInscpTotal float64 = 0 //床位部分项目自费
  568. var operationCostTotal float64 = 0 //手术费
  569. var operationCostSelfTotal float64 = 0 //手术费
  570. var operationCostPartSelfTotal float64 = 0 //手术费
  571. var operationSelfTotal float64 = 0 //床位部分项目自费
  572. var operationInscpTotal float64 = 0 //床位部分项目自费
  573. var otherCostTotal float64 = 0 //其他费用
  574. var otherCostSelfTotal float64 = 0 //其他费用
  575. var otherCostPartSelfTotal float64 = 0 //其他费用
  576. var otherSelfTotal float64 = 0 //床位部分项目自费
  577. var otherInscpTotal float64 = 0 //床位部分项目自费
  578. var materialCostTotal float64 = 0 //材料费
  579. var materialCostSelfTotal float64 = 0 //材料费
  580. var materialCostPartSelfTotal float64 = 0 //材料费
  581. var materialSelfTotal float64 = 0 //床位部分项目自费
  582. var materialInscpTotal float64 = 0 //床位部分项目自费
  583. var westernMedicineCostTotal float64 = 0 //西药费
  584. var westernMedicineCostSelfTotal float64 = 0 //西药费
  585. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  586. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  587. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  588. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  589. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  590. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  591. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  592. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  593. var checkCostTotal float64 = 0 //检查费
  594. var checkCostSelfTotal float64 = 0 //检查费
  595. var checkCostPartSelfTotal float64 = 0 //检查费
  596. var checkSelfTotal float64 = 0 //床位部分项目自费
  597. var checkInscpTotal float64 = 0 //床位部分项目自费
  598. var laboratoryCostTotal float64 = 0 //化验费
  599. var laboratoryCostSelfTotal float64 = 0 //化验费
  600. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  601. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  602. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  603. var treatCostTotal float64 = 0 //治疗费用
  604. var treatCostSelfTotal float64 = 0 //治疗费用
  605. var treatCostPartSelfTotal float64 = 0 //治疗费用
  606. var treatSelfTotal float64 = 0 //床位部分项目自费
  607. var treatInscpTotal float64 = 0 //床位部分项目自费
  608. decimal.DivisionPrecision = 2
  609. for _, item := range orderInfos {
  610. if item.MedChrgitmType == "01" { //床位费
  611. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  612. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  613. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  614. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  615. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  616. }
  617. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  618. if item.MedChrgitmType == "03" { //检查费
  619. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  620. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  621. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  622. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  623. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  624. }
  625. } else {
  626. if item.MedChrgitmType == "03" { //检查费
  627. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  628. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  629. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  630. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  631. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  632. }
  633. }
  634. if item.MedChrgitmType == "04" { //化验费
  635. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  636. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  637. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  638. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  639. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  640. }
  641. if item.MedChrgitmType == "05" { //治疗费
  642. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  643. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  644. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  645. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  646. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  647. }
  648. if item.MedChrgitmType == "06" { //手术费
  649. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  650. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  651. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  652. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  653. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  654. }
  655. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  656. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  657. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  658. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  659. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  660. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  661. }
  662. if item.MedChrgitmType == "09" { //西药费
  663. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  664. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  665. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  666. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  667. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  668. }
  669. if item.MedChrgitmType == "11" { //中成费
  670. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  671. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  672. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  673. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  674. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  675. }
  676. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  677. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  678. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  679. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  680. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  681. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  682. }
  683. }
  684. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  685. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  686. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  687. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  688. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  689. var doctor_name string
  690. if roles.ID == 0 {
  691. doctor_name = "管理员"
  692. } else {
  693. doctor_name = roles.UserName
  694. }
  695. yiliao_leibie := ""
  696. switch order.MedType {
  697. case "11":
  698. yiliao_leibie = "普通门诊"
  699. break
  700. case "12":
  701. yiliao_leibie = "门诊挂号"
  702. break
  703. case "13":
  704. yiliao_leibie = "急诊"
  705. break
  706. case "14":
  707. yiliao_leibie = "门诊特殊病"
  708. break
  709. case "15":
  710. yiliao_leibie = "门诊统筹"
  711. break
  712. case "16":
  713. yiliao_leibie = "门诊慢性病"
  714. break
  715. case "21":
  716. yiliao_leibie = "普通住院"
  717. break
  718. }
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "diagnosis": name,
  721. "order_infos": orderInfos,
  722. "number": order.MdtrtId,
  723. "date": order.SettleAccountsDate,
  724. "charge_admin": charge_admin,
  725. "printor_admin": printor_admin,
  726. "info": order,
  727. "order": order,
  728. "bedCostTotal": bedCostTotal,
  729. "bedCostSelfTotal": bedCostSelfTotal,
  730. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  731. "bedSelfTotal": bedSelfTotal,
  732. "bedInscpTotal": bedInscpTotal,
  733. "operationCostTotal": operationCostTotal,
  734. "operationCostSelfTotal": operationCostSelfTotal,
  735. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  736. "operationSelfTotal": operationSelfTotal,
  737. "operationInscpTotal": operationInscpTotal,
  738. "otherCostTotal": otherCostTotal,
  739. "otherCostSelfTotal": otherCostSelfTotal,
  740. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  741. "otherSelfTotal": otherSelfTotal,
  742. "otherInscpTotal": otherInscpTotal,
  743. "materialCostTotal": materialCostTotal,
  744. "materialCostSelfTotal": materialCostSelfTotal,
  745. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  746. "materialSelfTotal": materialSelfTotal,
  747. "materialInscpTotal": materialInscpTotal,
  748. "westernMedicineCostTotal": westernMedicineCostTotal,
  749. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  750. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  751. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  752. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  753. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  754. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  755. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  756. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  757. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  758. "checkCostTotal": checkCostTotal,
  759. "checkCostSelfTotal": checkCostSelfTotal,
  760. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  761. "checkSelfTotal": checkSelfTotal,
  762. "checkInscpTotal": checkInscpTotal,
  763. "laboratoryCostTotal": laboratoryCostTotal,
  764. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  765. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  766. "laboratorySelfTotal": laboratorySelfTotal,
  767. "laboratoryInscpTotal": laboratoryInscpTotal,
  768. "treatCostTotal": treatCostTotal,
  769. "treatCostSelfTotal": treatCostSelfTotal,
  770. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  771. "treatSelfTotal": treatSelfTotal,
  772. "treatInscpTotal": treatInscpTotal,
  773. "doctor_info": doctor_info,
  774. "doctor_name": doctor_name,
  775. "health_card_no": order.PsnNo,
  776. "yiliao_leibie": yiliao_leibie,
  777. "patient": patient,
  778. "org_name": miConfig.OrgName,
  779. "org_code": miConfig.Code,
  780. "order_number": order.Number,
  781. "his_hospital": his_hospital,
  782. "dia_config": dia_config,
  783. })
  784. }
  785. func (c *PublicApiController) GetBaiLinExportData() {
  786. data := service.GetBaiLinOrderData()
  787. fmt.Println(len(data))
  788. var new_data []*models.NewCustomHisOrder
  789. for _, item := range data {
  790. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  791. new_data = append(new_data, item)
  792. }
  793. }
  794. fmt.Println(len(new_data))
  795. c.ServeSuccessJSON(map[string]interface{}{
  796. "list": new_data,
  797. })
  798. }
  799. func (c *HisApiController) GetHisUnChargePatientList() {
  800. record_date := c.GetString("record_date")
  801. sch_type, _ := c.GetInt64("sch_type")
  802. timeLayout := "2006-01-02"
  803. loc, _ := time.LoadLocation("Local")
  804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  805. if err != nil {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. recordDateTime := theTime.Unix()
  810. adminInfo := c.GetAdminUserInfo()
  811. var tempPatients []*service.NewTempPatients
  812. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  813. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  814. var patients []*service.NewTempPatients
  815. var patients_two []*service.NewTempPatients
  816. for _, item := range tempPatients {
  817. //过滤掉没挂号的和没开处方的
  818. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  819. patients = append(patients, item)
  820. }
  821. //过滤掉没挂号的
  822. if len(item.HisPatient) > 0 {
  823. patients_two = append(patients_two, item)
  824. }
  825. }
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": patients,
  828. "list_two": patients_two,
  829. })
  830. }
  831. func (c *HisApiController) GetPrivateExpensesOrder() {
  832. //id, _ := c.GetInt64("id")
  833. //record_time := c.GetString("record_time")
  834. order_id, _ := c.GetInt64("order_id")
  835. admin_user_id, _ := c.GetInt64("admin_user_id")
  836. //timeLayout := "2006-01-02"
  837. //loc, _ := time.LoadLocation("Local")
  838. //
  839. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  840. //if err != nil {
  841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  842. // return
  843. //}
  844. //recordDateTime := theTime.Unix()
  845. adminUser := c.GetAdminUserInfo()
  846. order, _ := service.GetHisOrderByID(order_id)
  847. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  848. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  849. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  850. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  851. //var config []*models.HisXtDiagnoseConfig
  852. var name string
  853. if order.PType == 1 {
  854. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  855. for _, item := range diagnosis_ids {
  856. id, _ := strconv.ParseInt(item, 10, 64)
  857. diagnosisConfig, _ := service.FindDiagnoseById(id)
  858. if len(name) == 0 {
  859. name = diagnosisConfig.ClassName
  860. } else {
  861. name = name + "," + diagnosisConfig.ClassName
  862. }
  863. }
  864. } else {
  865. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  866. for _, item := range diagnosis_ids {
  867. id, _ := strconv.ParseInt(item, 10, 64)
  868. diagnosisConfig, _ := service.FindDiagnoseById(id)
  869. if len(name) == 0 {
  870. name = diagnosisConfig.ClassName
  871. } else {
  872. name = name + "," + diagnosisConfig.ClassName
  873. }
  874. }
  875. }
  876. var bedCostTotal float64 = 0 //床位总费
  877. //var bedCostSelfTotal float64 = 0 //床位自费
  878. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  879. var operationCostTotal float64 = 0 //手术费
  880. //var operationCostSelfTotal float64 = 0 //手术费
  881. var operationCostPartSelfTotal float64 = 0 //手术费
  882. var otherCostTotal float64 = 0 //其他费用
  883. //var otherCostSelfTotal float64 = 0 //其他费用
  884. var otherCostPartSelfTotal float64 = 0 //其他费用
  885. var materialCostTotal float64 = 0 //材料费
  886. //var materialCostSelfTotal float64 = 0 //材料费
  887. var materialCostPartSelfTotal float64 = 0 //材料费
  888. var westernMedicineCostTotal float64 = 0 //西药费
  889. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  890. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  891. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  892. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  893. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  894. var checkCostTotal float64 = 0 //检查费
  895. //var checkCostSelfTotal float64 = 0 //检查费
  896. var checkCostPartSelfTotal float64 = 0 //检查费
  897. var laboratoryCostTotal float64 = 0 //化验费
  898. //var laboratoryCostSelfTotal float64 = 0 //化验费
  899. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  900. var treatCostTotal float64 = 0 //治疗费用
  901. //var treatCostSelfTotal float64 = 0 //治疗费用
  902. var treatCostPartSelfTotal float64 = 0 //治疗费用
  903. var zhenChaCostTotal float64 = 0 //其他费用
  904. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  905. decimal.DivisionPrecision = 2
  906. for _, item := range orderInfos {
  907. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  908. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  909. item.MedChrgitmType = "09"
  910. }
  911. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  912. if item.HisPrescriptionProject.Type == 2 {
  913. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  914. fmt.Println("CostClassify")
  915. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  916. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  917. case 0:
  918. item.MedChrgitmType = "0"
  919. break
  920. case 1:
  921. item.MedChrgitmType = "14"
  922. break
  923. case 2:
  924. item.MedChrgitmType = "05"
  925. break
  926. case 3:
  927. item.MedChrgitmType = "03"
  928. break
  929. case 4:
  930. item.MedChrgitmType = "03"
  931. break
  932. case 5:
  933. item.MedChrgitmType = "08"
  934. break
  935. case 6:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 7:
  939. item.MedChrgitmType = "14"
  940. break
  941. case 8:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 9:
  945. item.MedChrgitmType = "14"
  946. break
  947. case 10:
  948. item.MedChrgitmType = "14"
  949. break
  950. case 11:
  951. item.MedChrgitmType = "06"
  952. break
  953. case 12:
  954. item.MedChrgitmType = "12"
  955. break
  956. case 13:
  957. item.MedChrgitmType = "01"
  958. break
  959. case 14:
  960. item.MedChrgitmType = "04"
  961. break
  962. case 15:
  963. item.MedChrgitmType = "14"
  964. break
  965. }
  966. } else {
  967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  968. case 1:
  969. item.MedChrgitmType = "14"
  970. break
  971. case 2:
  972. item.MedChrgitmType = "05"
  973. break
  974. case 3:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 4:
  978. item.MedChrgitmType = "14"
  979. break
  980. case 5:
  981. item.MedChrgitmType = "08"
  982. break
  983. case 6:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 7:
  987. item.MedChrgitmType = "14"
  988. break
  989. case 8:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 9:
  993. item.MedChrgitmType = "14"
  994. break
  995. default:
  996. item.MedChrgitmType = "14"
  997. break
  998. }
  999. }
  1000. } else if item.HisPrescriptionProject.Type == 3 {
  1001. item.MedChrgitmType = "08"
  1002. }
  1003. }
  1004. }
  1005. order.PsnCashPay = order.MedfeeSumamt
  1006. for _, item := range orderInfos {
  1007. if item.MedChrgitmType == "01" { //床位费
  1008. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1009. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1010. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1011. }
  1012. if item.MedChrgitmType == "02" { //诊察费
  1013. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1014. //zhenChaCostSelfTotal = zhenChaCostTotal
  1015. }
  1016. if item.MedChrgitmType == "03" { //检查费
  1017. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1018. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1019. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1020. }
  1021. if item.MedChrgitmType == "02" { //检查费
  1022. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1024. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1025. }
  1026. if item.MedChrgitmType == "04" { //化验费
  1027. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1028. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1029. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1030. }
  1031. if item.MedChrgitmType == "05" { //治疗费
  1032. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "06" { //手术费
  1037. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1042. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "09" { //西药费
  1047. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "11" { //中成费
  1052. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1057. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. }
  1062. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1063. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1064. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1065. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1066. c.ServeSuccessJSON(map[string]interface{}{
  1067. "patient": patient,
  1068. "order_infos": orderInfos,
  1069. "diagnosis": name,
  1070. "bedCostTotal": bedCostTotal,
  1071. "bedCostSelfTotal": bedCostTotal,
  1072. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1073. "operationCostTotal": operationCostTotal,
  1074. "operationCostSelfTotal": operationCostTotal,
  1075. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1076. "otherCostTotal": otherCostTotal,
  1077. "otherCostSelfTotal": otherCostTotal,
  1078. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1079. "materialCostTotal": materialCostTotal,
  1080. "materialCostSelfTotal": materialCostTotal,
  1081. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1082. "westernMedicineCostTotal": westernMedicineCostTotal,
  1083. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1084. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1085. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1086. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1087. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1088. "checkCostTotal": checkCostTotal,
  1089. "checkCostSelfTotal": checkCostTotal,
  1090. "zhenChaCostTotal": zhenChaCostTotal,
  1091. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1092. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1093. "laboratoryCostTotal": laboratoryCostTotal,
  1094. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1095. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1096. "treatCostTotal": treatCostTotal,
  1097. "treatCostSelfTotal": treatCostTotal,
  1098. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1099. "charge_admin": charge_admin,
  1100. "printor_admin": printor_admin,
  1101. "org_name": org.OrgName,
  1102. "org_code": miConfig.Code,
  1103. "name": patient.Name,
  1104. "number": order.MdtrtId,
  1105. "date": order.SettleAccountsDate,
  1106. "info": order,
  1107. "his_hospital": his_hospital,
  1108. "his": his,
  1109. })
  1110. }
  1111. func (c *HisApiController) RefudDetail() {
  1112. order_id, _ := c.GetInt64("order_id")
  1113. order, _ := service.GetHisOrderByID(order_id)
  1114. adminUser := c.GetAdminUserInfo()
  1115. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1116. c.ServeSuccessJSON(map[string]interface{}{
  1117. "msg": "撤销成功",
  1118. })
  1119. }
  1120. func (c *HisApiController) Sscard() {
  1121. //r := CardInit()
  1122. //if r == 0 {
  1123. // GetBaseInfo()
  1124. //}
  1125. //c.ServeSuccessJSON(map[string]interface{}{
  1126. // "list": "11",
  1127. //})
  1128. }
  1129. func GetBaseInfo() error {
  1130. //handle := syscall.MustLoadDLL("SSCard.dll")
  1131. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1132. //
  1133. //str := make([]byte, 256)
  1134. //str1 := make([]byte, 256)
  1135. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1136. //if ferr != nil {
  1137. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1138. // return ferr
  1139. //}
  1140. //
  1141. //fmt.Println(string(str))
  1142. //
  1143. //fmt.Println(r)
  1144. return nil
  1145. }
  1146. func CardInit() int {
  1147. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1148. //add := DllTestDef.MustFindProc("Init")
  1149. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1150. //if err != nil {
  1151. // fmt.Println("SSCard的运算结果为:", ret)
  1152. //}
  1153. //result := int(ret)
  1154. return 0
  1155. }
  1156. func IntPtr(n int) uintptr {
  1157. return uintptr(n)
  1158. }
  1159. func StrPtr(s string) uintptr {
  1160. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1161. }
  1162. func (c *HisApiController) GetHisPatientList() {
  1163. //types, _ := c.GetInt64("type", 0)
  1164. record_date := c.GetString("record_date")
  1165. sch_type, _ := c.GetInt64("sch_type")
  1166. timeLayout := "2006-01-02"
  1167. loc, _ := time.LoadLocation("Local")
  1168. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1169. if err != nil {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. recordDateTime := theTime.Unix()
  1174. adminInfo := c.GetAdminUserInfo()
  1175. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1176. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1177. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1178. //获取当前用户的信息
  1179. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1180. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1181. //获取所有科室信息
  1182. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1183. c.ServeSuccessJSON(map[string]interface{}{
  1184. "list": patients,
  1185. "list_two": patients_two,
  1186. "info": adminUserInfo,
  1187. "doctors": doctors,
  1188. "department": department,
  1189. })
  1190. }
  1191. type CustomTemplate struct {
  1192. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1194. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1195. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1196. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1197. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1198. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1199. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1200. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1201. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1202. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1203. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1204. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1205. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1206. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1207. }
  1208. func (c *HisApiController) GetHisPatientInfo() {
  1209. patient_id, _ := c.GetInt64("patient_id")
  1210. his_patient_id, _ := c.GetInt64("his_patient_id")
  1211. record_date := c.GetString("record_date")
  1212. number := c.GetString("number")
  1213. //start_time := c.GetString("start_time")
  1214. //end_time := c.GetString("end_time")
  1215. p_type, _ := c.GetInt64("p_type")
  1216. timeLayout := "2006-01-02"
  1217. loc, _ := time.LoadLocation("Local")
  1218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1219. if err != nil {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1221. return
  1222. }
  1223. recordDateTime := theTime.Unix()
  1224. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1225. //if err != nil {
  1226. //
  1227. //}
  1228. //startRecordDateTime := startTime.Unix()
  1229. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1230. //if err != nil {
  1231. //
  1232. //}
  1233. //endRecordDateTime := endTime.Unix()
  1234. admin := c.GetAdminUserInfo()
  1235. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1236. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1237. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1238. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1239. var prescriptions []*models.HisPrescription
  1240. var last_prescriptions []*models.HisPrescription
  1241. var sch_prescriptions []CustomTemplate
  1242. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1243. if p_type == 1 { //住院
  1244. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1245. for _, item := range prescriptions {
  1246. for _, subItem := range item.HisDoctorAdviceInfo {
  1247. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1248. if info.RetailPrice > 0 {
  1249. subItem.Drug.MinPrice = info.RetailPrice
  1250. }
  1251. }
  1252. }
  1253. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1254. } else { //门诊
  1255. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1256. for _, item := range prescriptions {
  1257. for _, subItem := range item.HisDoctorAdviceInfo {
  1258. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1259. if info.RetailPrice > 0 {
  1260. subItem.Drug.MinPrice = info.RetailPrice
  1261. }
  1262. }
  1263. }
  1264. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1265. }
  1266. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1267. if sch.ID > 0 {
  1268. var week string
  1269. t := time.Now()
  1270. switch t.Weekday().String() {
  1271. case "Monday":
  1272. week = "周一"
  1273. break
  1274. case "Tuesday":
  1275. week = "周二"
  1276. break
  1277. case "Wednesday":
  1278. week = "周三"
  1279. break
  1280. case "Thursday":
  1281. week = "周四"
  1282. break
  1283. case "Friday":
  1284. week = "周五"
  1285. break
  1286. case "Saturday":
  1287. week = "周六"
  1288. break
  1289. case "Sunday":
  1290. week = "周日"
  1291. break
  1292. }
  1293. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1294. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1295. //根据推送频率组装新的数组
  1296. for _, item := range temp_sch_prescriptions {
  1297. var cus CustomTemplate
  1298. cus.ID = item.ID
  1299. cus.UserOrgId = item.UserOrgId
  1300. cus.PatientId = item.PatientId
  1301. cus.MedType = item.MedType
  1302. cus.RecordDate = item.RecordDate
  1303. cus.Type = item.Type
  1304. cus.PType = item.PType
  1305. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1306. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1307. if subItem.FrequencyType == 1 { //每次必推
  1308. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1309. }
  1310. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1311. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1312. }
  1313. if subItem.FrequencyType == 2 { //按照天数频率
  1314. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1315. now := p.Unix()
  1316. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1317. dayStr2 := "-" + dayStr
  1318. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1319. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1320. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1321. if len(advices) == 0 {
  1322. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1323. }
  1324. }
  1325. }
  1326. }
  1327. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1328. if subItem.Type == 2 {
  1329. if subItem.XtHisProject.MedicalStatus != 1 {
  1330. if subItem.FrequencyType == 1 {
  1331. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1332. }
  1333. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1334. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1335. }
  1336. if subItem.FrequencyType == 2 {
  1337. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1338. now := p.Unix()
  1339. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1340. dayStr2 := "-" + dayStr
  1341. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1342. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1343. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1344. if len(projects) == 0 {
  1345. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1346. }
  1347. }
  1348. }
  1349. } else if subItem.Type == 3 {
  1350. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1351. if subItem.FrequencyType == 1 {
  1352. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1353. }
  1354. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1355. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1356. }
  1357. if subItem.FrequencyType == 2 {
  1358. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1359. now := p.Unix()
  1360. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1361. dayStr2 := "-" + dayStr
  1362. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1363. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1364. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1365. if len(projects) == 0 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. sch_prescriptions = append(sch_prescriptions, cus)
  1373. }
  1374. for _, item := range sch_prescriptions {
  1375. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1376. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1377. }
  1378. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1379. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1380. }
  1381. }
  1382. }
  1383. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1384. if config.ID > 0 && config.IsOpen == 1 {
  1385. for _, item := range sch_prescriptions {
  1386. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1387. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1388. if info.RetailPrice > 0 {
  1389. subItem.Drug.MinPrice = info.RetailPrice
  1390. }
  1391. }
  1392. }
  1393. }
  1394. if config.ID > 0 && config.IsOpen == 1 {
  1395. for _, item := range sch_prescriptions {
  1396. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1397. if subItem.Type == 3 {
  1398. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1399. if info.Price > 0 {
  1400. subItem.GoodInfo.PackingPrice = info.Price
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1407. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1408. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1409. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1410. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1411. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1412. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1413. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1414. //获取所有科室信息
  1415. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "his_info": his_patient_info,
  1418. "xt_info": xt_patient_info,
  1419. "prescription": prescriptions,
  1420. "case_history": case_history,
  1421. "info": patientPrescriptionInfo,
  1422. //"month_prescriptions": monthPrescriptions,
  1423. "order": order,
  1424. "doctors": doctors,
  1425. "department": department,
  1426. "sch_prescriptions": sch_prescriptions,
  1427. "last_prescriptions": last_prescriptions,
  1428. "schedule": sch,
  1429. "count": count,
  1430. "drugStockConfig": drugStockConfig,
  1431. "last_info": lastPatientPrescriptionInfo,
  1432. })
  1433. return
  1434. }
  1435. func (c *HisApiController) GetHisPrescriptionConfig() {
  1436. adminInfo := c.GetAdminUserInfo()
  1437. //获取医嘱模版
  1438. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1439. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1440. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1441. //获取所有基础药
  1442. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1443. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1444. if config.ID > 0 && config.IsOpen == 1 {
  1445. for _, item := range drugs {
  1446. var index = 0
  1447. for _, subItem := range item.OtherDrugWarehouseInfo {
  1448. if index == 0 {
  1449. index = index + 1
  1450. if subItem.RetailPrice > 0 {
  1451. item.MinPrice = subItem.RetailPrice
  1452. }
  1453. }
  1454. }
  1455. }
  1456. }
  1457. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1458. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1459. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1460. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1463. //获取诊断信息
  1464. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1465. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1466. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1467. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1468. //获取是否开启保存耗材出库的开关
  1469. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1470. c.ServeSuccessJSON(map[string]interface{}{
  1471. "drugs": drugs,
  1472. "advices_template": advices,
  1473. "drugways": drugways,
  1474. "efs": efs,
  1475. "doctors": doctors,
  1476. "department": department,
  1477. "sick": sick,
  1478. "additions": additions,
  1479. "diagnose": diagnose,
  1480. "manufacturers": manufacturers,
  1481. "goodOutOpen": goodOutOpen,
  1482. "patientDiagnose": patientDiagnose,
  1483. })
  1484. }
  1485. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1486. //获取所有基础药
  1487. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1488. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1489. if config.ID > 0 && config.IsOpen == 1 {
  1490. for _, item := range drugs {
  1491. var index = 0
  1492. for _, subItem := range item.OtherDrugWarehouseInfo {
  1493. if index == 0 {
  1494. index = index + 1
  1495. if subItem.RetailPrice > 0 {
  1496. item.MinPrice = subItem.RetailPrice
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1503. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1504. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1505. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1506. //获取所有科室信息
  1507. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1508. //获取诊断信息
  1509. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1510. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1511. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1512. //获取是否开启保存耗材出库的开关
  1513. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1514. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1515. c.ServeSuccessJSON(map[string]interface{}{
  1516. "drugs": drugs,
  1517. "advices_template": advices,
  1518. "drugways": drugways,
  1519. "efs": efs,
  1520. "doctors": doctors,
  1521. "department": department,
  1522. "sick": sick,
  1523. "additions": additions,
  1524. "diagnose": diagnose,
  1525. "manufacturers": manufacturers,
  1526. "goodOutOpen": goodOutOpen,
  1527. "patientDiagnose": patientDiagnose,
  1528. })
  1529. }
  1530. }
  1531. func (c *HisApiController) CreateHisPrescription() {
  1532. record_date := c.GetString("record_date")
  1533. patient_id, _ := c.GetInt64("patient_id")
  1534. reg_type, _ := c.GetInt64("reg_type")
  1535. diagnose := c.GetString("diagnose")
  1536. sick_type, _ := c.GetInt64("sick_type")
  1537. sick_history := c.GetString("sick_history")
  1538. doctor_id, _ := c.GetInt64("doctor", 0)
  1539. department, _ := c.GetInt64("department", 0)
  1540. his_patient_id, _ := c.GetInt64("his_patient_id")
  1541. p_type, _ := c.GetInt64("p_type")
  1542. patient_diagnose := c.GetString("patient_diagnose")
  1543. dataBody := make(map[string]interface{}, 0)
  1544. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1545. if err != nil {
  1546. utils.ErrorLog(err.Error())
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1548. return
  1549. }
  1550. timeLayout := "2006-01-02"
  1551. loc, _ := time.LoadLocation("Local")
  1552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1553. if err != nil {
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1555. return
  1556. }
  1557. adminInfo := c.GetAdminUserInfo()
  1558. recordDateTime := theTime.Unix()
  1559. //查询默认出库仓库库存
  1560. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1561. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1562. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1563. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1564. if len(lists) == 1 {
  1565. his_patient_id = lists[0].ID
  1566. }
  1567. }
  1568. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1569. //保存处方出库
  1570. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1571. //自动出库
  1572. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1573. //耗材保存处方出库
  1574. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1575. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1576. //已发药和已收费限制逻辑
  1577. isMidicine := false
  1578. isCharge := false
  1579. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1580. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1581. if len(prescriptions) > 0 {
  1582. for _, item := range prescriptions {
  1583. items := item.(map[string]interface{})
  1584. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1585. utils.ErrorLog("id")
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. id := int64(items["id"].(float64))
  1590. if id > 0 {
  1591. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1592. if err != nil {
  1593. if new_prescription.OrderStatus == 4 {
  1594. isCharge = true
  1595. }
  1596. }
  1597. }
  1598. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1599. advices := items["advices"].([]interface{})
  1600. if len(advices) > 0 {
  1601. for _, advice := range advices {
  1602. var adviceId int64
  1603. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1604. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1605. }
  1606. if adviceId > 0 {
  1607. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1608. if err == nil {
  1609. if his_advice_info.IsMedicine == 1 {
  1610. isMidicine = true
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. if isMidicine == true {
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1622. return
  1623. }
  1624. if isCharge == true {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1626. return
  1627. }
  1628. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1629. //药品发药出库
  1630. if pharmacyConfig.IsOpen == 1 {
  1631. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1632. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1633. if len(prescriptions) > 0 {
  1634. for _, item := range prescriptions {
  1635. items := item.(map[string]interface{})
  1636. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1637. advices := items["advices"].([]interface{})
  1638. if len(advices) > 0 {
  1639. for _, advice := range advices {
  1640. var drug_id int64
  1641. var prescribing_number float64
  1642. var prescribingNumberUnit string
  1643. var adviceId int64
  1644. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1645. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1646. }
  1647. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1648. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1649. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1650. }
  1651. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1652. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1653. }
  1654. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1655. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1656. }
  1657. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1658. if drug.ID == 0 {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1660. return
  1661. }
  1662. //查询药品的所有库存
  1663. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1664. var total_count int64
  1665. for _, it := range list {
  1666. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1667. }
  1668. totals := strconv.FormatInt(total_count, 10)
  1669. //查询该药品是否存在开药记录
  1670. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1671. //新增处方
  1672. if advicelist.ID == 0 {
  1673. all_count, _ := strconv.ParseFloat(totals, 64)
  1674. if prescribingNumberUnit == drug.MinUnit {
  1675. if drug.IsUse != 1 {
  1676. if drug.IsProject == 0 || drug.IsProject == 2 {
  1677. if all_count == 0 {
  1678. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1679. return
  1680. }
  1681. if prescribing_number > all_count {
  1682. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1683. return
  1684. }
  1685. }
  1686. }
  1687. }
  1688. if prescribingNumberUnit == drug.MaxUnit {
  1689. num := prescribing_number * float64(drug.MinNumber)
  1690. if drug.IsUse != 1 {
  1691. if drug.IsProject == 0 || drug.IsProject == 2 {
  1692. if all_count == 0 {
  1693. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1694. return
  1695. }
  1696. if num > all_count {
  1697. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1698. return
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1705. if drugOutConfig.IsOpen != 1 {
  1706. //修改处方
  1707. for _, advice := range advices {
  1708. var drug_id int64
  1709. var prescribing_number float64
  1710. var prescribingNumberUnit string
  1711. var prescribingNumber string
  1712. var adviceId int64
  1713. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1714. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1715. }
  1716. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1717. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1718. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1719. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1720. }
  1721. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1722. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1723. }
  1724. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1725. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1726. }
  1727. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1728. if drug.ID == 0 {
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1730. return
  1731. }
  1732. //查询药品的所有库存
  1733. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1734. var total_count int64
  1735. for _, it := range list {
  1736. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1737. }
  1738. totals := strconv.FormatInt(total_count, 10)
  1739. //查询该药品是否存在开药记录
  1740. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1741. //新增处方
  1742. if advicelist.ID == 0 {
  1743. all_count, _ := strconv.ParseFloat(totals, 64)
  1744. if prescribingNumberUnit == drug.MinUnit {
  1745. if drug.IsUse != 1 {
  1746. if drug.IsProject == 0 || drug.IsProject == 2 {
  1747. if all_count == 0 {
  1748. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1749. return
  1750. }
  1751. if prescribing_number > all_count {
  1752. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1753. return
  1754. }
  1755. }
  1756. }
  1757. } else {
  1758. if prescribingNumberUnit == drug.MaxUnit {
  1759. num := prescribing_number * float64(drug.MinNumber)
  1760. if drug.IsUse != 1 {
  1761. if drug.IsProject == 0 || drug.IsProject == 2 {
  1762. if all_count == 0 {
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. if num > all_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. //修改处方
  1776. if advicelist.ID > 0 {
  1777. var device_number int64
  1778. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1779. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1780. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1781. device_number = prescribingNumberInt * drug.MinNumber
  1782. }
  1783. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1784. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1785. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1786. device_number = prescribingNumberInt
  1787. }
  1788. var number_count int64
  1789. if prescribingNumberUnit == drug.MaxUnit {
  1790. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1791. number_count = prescribingNumberInt * drug.MinNumber
  1792. }
  1793. if prescribingNumberUnit == drug.MinUnit {
  1794. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1795. number_count = prescribingNumberInt
  1796. }
  1797. //如果修改的数量大于之前修改的数量
  1798. if (number_count - device_number) > 0 {
  1799. //如果修改的差数量 大于库存数量
  1800. if drug.IsUse != 1 {
  1801. if (number_count - device_number) > total_count {
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1803. return
  1804. }
  1805. }
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. //已发药和已收费限制逻辑
  1818. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1819. //校验库存总量
  1820. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1821. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1822. if len(prescriptions) > 0 {
  1823. for _, item := range prescriptions {
  1824. items := item.(map[string]interface{})
  1825. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1826. advices := items["advices"].([]interface{})
  1827. if len(advices) > 0 {
  1828. for _, advice := range advices {
  1829. var drug_id int64
  1830. var prescribing_number float64
  1831. var prescribingNumberUnit string
  1832. var adviceId int64
  1833. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1834. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1835. }
  1836. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1837. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1838. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1839. }
  1840. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1841. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1842. }
  1843. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1844. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1845. }
  1846. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1847. if drug.ID == 0 {
  1848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1849. return
  1850. }
  1851. //查询药品的所有库存
  1852. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1853. var total_count int64
  1854. for _, it := range list {
  1855. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1856. }
  1857. totals := strconv.FormatInt(total_count, 10)
  1858. //查询该药品是否存在开药记录
  1859. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1860. //查询最新批次库存
  1861. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1862. var batch_number_count int64
  1863. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1864. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1865. //新增处方
  1866. if advicelist.ID == 0 {
  1867. all_count, _ := strconv.ParseFloat(totals, 64)
  1868. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1869. if prescribingNumberUnit == drug.MinUnit {
  1870. if drug.IsUse != 1 {
  1871. if drug.IsProject == 0 || drug.IsProject == 2 {
  1872. if all_count == 0 {
  1873. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1874. return
  1875. }
  1876. if prescribing_number > all_count {
  1877. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1878. return
  1879. }
  1880. }
  1881. if adminInfo.CurrentOrgId == 10215 {
  1882. if prescribing_number > batch_number_all_count {
  1883. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1884. return
  1885. }
  1886. }
  1887. }
  1888. }
  1889. if prescribingNumberUnit == drug.MaxUnit {
  1890. num := prescribing_number * float64(drug.MinNumber)
  1891. if drug.IsUse != 1 {
  1892. if drug.IsProject == 0 || drug.IsProject == 2 {
  1893. if all_count == 0 {
  1894. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1895. return
  1896. }
  1897. if num > all_count {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1899. return
  1900. }
  1901. }
  1902. if adminInfo.CurrentOrgId == 10215 {
  1903. if num > batch_number_all_count {
  1904. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1905. return
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }
  1911. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1912. if drugOutConfig.IsOpen != 1 {
  1913. //修改处方
  1914. for _, advice := range advices {
  1915. var drug_id int64
  1916. var prescribing_number float64
  1917. var prescribingNumberUnit string
  1918. var prescribingNumber string
  1919. var adviceId int64
  1920. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1921. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1922. }
  1923. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1924. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1925. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1926. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1927. }
  1928. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1929. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1930. }
  1931. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1932. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1933. }
  1934. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1935. if drug.ID == 0 {
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1937. return
  1938. }
  1939. //查询药品的所有库存
  1940. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1941. var total_count int64
  1942. for _, it := range list {
  1943. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1944. }
  1945. totals := strconv.FormatInt(total_count, 10)
  1946. //查询该药品是否存在开药记录
  1947. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1948. //新增处方
  1949. if advicelist.ID == 0 {
  1950. //查询最新批次库存
  1951. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1952. var batch_number_count int64
  1953. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1954. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1955. all_count, _ := strconv.ParseFloat(totals, 64)
  1956. if prescribingNumberUnit == drug.MinUnit {
  1957. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1958. if drug.IsUse != 1 {
  1959. if drug.IsProject == 0 || drug.IsProject == 2 {
  1960. if all_count == 0 {
  1961. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1962. return
  1963. }
  1964. if prescribing_number > all_count {
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1966. return
  1967. }
  1968. }
  1969. if adminInfo.CurrentOrgId == 10215 {
  1970. if prescribing_number > batch_number_all_count {
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1972. return
  1973. }
  1974. }
  1975. }
  1976. } else {
  1977. if prescribingNumberUnit == drug.MaxUnit {
  1978. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1979. num := prescribing_number * float64(drug.MinNumber)
  1980. if drug.IsUse != 1 {
  1981. if drug.IsProject == 0 || drug.IsProject == 2 {
  1982. if all_count == 0 {
  1983. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1984. return
  1985. }
  1986. if num > all_count {
  1987. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1988. return
  1989. }
  1990. }
  1991. if adminInfo.CurrentOrgId == 10215 {
  1992. if prescribing_number > batch_number_all_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1994. return
  1995. }
  1996. }
  1997. }
  1998. }
  1999. }
  2000. }
  2001. //修改处方
  2002. if advicelist.ID > 0 {
  2003. //查询最新批次库存
  2004. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2005. var batch_number_count int64
  2006. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2007. var device_number int64
  2008. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2009. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2010. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2011. device_number = prescribingNumberInt * drug.MinNumber
  2012. }
  2013. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2014. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2015. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2016. device_number = prescribingNumberInt
  2017. }
  2018. var number_count int64
  2019. if prescribingNumberUnit == drug.MaxUnit {
  2020. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2021. number_count = prescribingNumberInt * drug.MinNumber
  2022. }
  2023. if prescribingNumberUnit == drug.MinUnit {
  2024. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2025. number_count = prescribingNumberInt
  2026. }
  2027. //如果修改的数量大于之前修改的数量
  2028. if (number_count - device_number) > 0 {
  2029. //如果修改的差数量 大于库存数量
  2030. if drug.IsUse != 1 {
  2031. if drug.IsProject == 0 || drug.IsProject == 2 {
  2032. if total_count == 0 {
  2033. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2034. return
  2035. }
  2036. if (number_count - device_number) > total_count {
  2037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2038. return
  2039. }
  2040. if (number_count - device_number) > batch_number_count {
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2042. return
  2043. }
  2044. }
  2045. if adminInfo.CurrentOrgId == 10215 {
  2046. // 查询该药品最后一次出库记录
  2047. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2048. var out_count int64
  2049. var in_count int64
  2050. var stock_max_number int64
  2051. var stock_min_number int64
  2052. for _, it := range outInfo {
  2053. if it.CountUnit == drug.MaxUnit {
  2054. it.Count = it.Count * drug.MinNumber
  2055. }
  2056. out_count += it.Count
  2057. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2058. stock_max_number = warehouseInfoList.StockMaxNumber
  2059. stock_min_number = warehouseInfoList.StockMinNumber
  2060. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2061. }
  2062. if out_count > 0 {
  2063. if (number_count - device_number) > in_count {
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2065. return
  2066. }
  2067. }
  2068. // 未出库
  2069. if out_count == 0 {
  2070. var sum_in_count int64
  2071. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2072. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2073. //如果修改的数量大于有库存的第一个批次
  2074. if number_count > sum_in_count {
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2083. if pharmacyConfig.IsOpen != 1 {
  2084. if device_number != number_count {
  2085. // 查询该药品最后一次出库记录
  2086. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2087. //回退库存
  2088. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2089. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2090. }
  2091. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2092. var stock_max_number int64
  2093. var stock_min_number int64
  2094. if number_count >= drug.MinNumber {
  2095. stock_max_number = device_number / drug.MinNumber
  2096. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2097. stock_min_number = device_number % drug.MinNumber
  2098. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2099. } else {
  2100. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2101. }
  2102. }
  2103. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2104. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2105. }
  2106. //删除记录
  2107. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2108. //查询默认仓库剩余多少库存
  2109. var sum_count int64
  2110. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2111. for _, its := range stockInfo {
  2112. if its.MaxUnit == drug.MaxUnit {
  2113. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2114. }
  2115. sum_count += its.StockMaxNumber + its.StockMinNumber
  2116. }
  2117. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. //保存处方开药
  2124. if drugOutConfig.IsOpen == 1 {
  2125. //修改处方
  2126. for _, advice := range advices {
  2127. var drug_id int64
  2128. var prescribing_number float64
  2129. var prescribingNumberUnit string
  2130. var prescribingNumber string
  2131. var adviceId int64
  2132. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2133. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2134. }
  2135. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2136. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2137. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2138. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2139. }
  2140. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2141. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2142. }
  2143. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2144. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2145. }
  2146. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2147. if drug.ID == 0 {
  2148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2149. return
  2150. }
  2151. //查询药品的所有库存
  2152. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2153. var total_count int64
  2154. for _, it := range list {
  2155. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2156. }
  2157. totals := strconv.FormatInt(total_count, 10)
  2158. //查询该药品是否存在开药记录
  2159. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2160. //新增处方
  2161. if advicelist.ID == 0 {
  2162. //查询最新批次库存
  2163. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2164. var batch_number_count int64
  2165. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2166. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2167. all_count, _ := strconv.ParseFloat(totals, 64)
  2168. if prescribingNumberUnit == drug.MinUnit {
  2169. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2170. if drug.IsUse != 1 {
  2171. if drug.IsProject == 0 || drug.IsProject == 2 {
  2172. if all_count == 0 {
  2173. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2174. return
  2175. }
  2176. if prescribing_number > all_count {
  2177. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2178. return
  2179. }
  2180. }
  2181. if adminInfo.CurrentOrgId == 10215 {
  2182. if prescribing_number > batch_number_all_count {
  2183. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2184. return
  2185. }
  2186. }
  2187. }
  2188. } else {
  2189. if prescribingNumberUnit == drug.MaxUnit {
  2190. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2191. num := prescribing_number * float64(drug.MinNumber)
  2192. if drug.IsUse != 1 {
  2193. if drug.IsProject == 0 || drug.IsProject == 2 {
  2194. if all_count == 0 {
  2195. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2196. return
  2197. }
  2198. if num > all_count {
  2199. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2200. return
  2201. }
  2202. }
  2203. if adminInfo.CurrentOrgId == 10215 {
  2204. if prescribing_number > batch_number_all_count {
  2205. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2206. return
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. //修改处方
  2214. if advicelist.ID > 0 {
  2215. //查询最新批次库存
  2216. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2217. var batch_number_count int64
  2218. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2219. var device_number int64
  2220. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2221. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2222. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2223. device_number = prescribingNumberInt * drug.MinNumber
  2224. }
  2225. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2226. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2227. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2228. device_number = prescribingNumberInt
  2229. }
  2230. var number_count int64
  2231. if prescribingNumberUnit == drug.MaxUnit {
  2232. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2233. number_count = prescribingNumberInt * drug.MinNumber
  2234. }
  2235. if prescribingNumberUnit == drug.MinUnit {
  2236. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2237. number_count = prescribingNumberInt
  2238. }
  2239. //如果修改的数量大于之前修改的数量
  2240. if (number_count - device_number) > 0 {
  2241. //如果修改的差数量 大于库存数量
  2242. if drug.IsUse != 1 {
  2243. if drug.IsProject == 0 || drug.IsProject == 2 {
  2244. if total_count == 0 {
  2245. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2246. return
  2247. }
  2248. if (number_count - device_number) > total_count {
  2249. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2250. return
  2251. }
  2252. }
  2253. if adminInfo.CurrentOrgId == 10215 {
  2254. if (number_count - device_number) > batch_number_count {
  2255. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2256. return
  2257. }
  2258. }
  2259. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2260. //查询历史出库数据总批次
  2261. // 查询该药品最后一次出库记录
  2262. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2263. var out_count int64
  2264. var in_count int64
  2265. var stock_max_number int64
  2266. var stock_min_number int64
  2267. for _, it := range outInfo {
  2268. if it.CountUnit == drug.MaxUnit {
  2269. it.Count = it.Count * drug.MinNumber
  2270. }
  2271. out_count += it.Count
  2272. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2273. stock_max_number = warehouseInfoList.StockMaxNumber
  2274. stock_min_number = warehouseInfoList.StockMinNumber
  2275. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2276. }
  2277. if out_count > 0 {
  2278. if (number_count - device_number) > in_count {
  2279. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2280. return
  2281. }
  2282. }
  2283. // 未出库
  2284. if out_count == 0 {
  2285. var sum_in_count int64
  2286. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2287. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2288. if sum_in_count == 0 {
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2290. return
  2291. }
  2292. //如果修改的数量大于有库存的第一个批次
  2293. if number_count > sum_in_count {
  2294. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2295. return
  2296. }
  2297. }
  2298. }
  2299. }
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. //校验耗材库存
  2312. if goodOutConfig.IsOpen == 1 {
  2313. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2314. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2315. if len(prescriptions) > 0 {
  2316. for _, item := range prescriptions {
  2317. items := item.(map[string]interface{})
  2318. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2319. projects := items["project"].([]interface{})
  2320. if len(projects) > 0 {
  2321. for _, project := range projects {
  2322. var project_id int64
  2323. var project_type int64
  2324. var totals float64
  2325. var project_name string
  2326. var parsetotal int64
  2327. var id int64
  2328. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2329. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2330. }
  2331. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2332. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2333. }
  2334. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2335. total, _ := project.(map[string]interface{})["total"].(string)
  2336. totals, _ = strconv.ParseFloat(total, 64)
  2337. }
  2338. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2339. project_name = project.(map[string]interface{})["project_name"].(string)
  2340. }
  2341. if project_type == 3 {
  2342. //查找该耗材的出库记录
  2343. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2344. if len(goodWarehouseInfo) == 0 {
  2345. //查询耗材库存
  2346. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2347. var stock_count int64
  2348. for _, it := range list {
  2349. stock_count += it.StockCount
  2350. }
  2351. stock_counts := strconv.FormatInt(stock_count, 10)
  2352. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2353. if stock_total_count == 0 {
  2354. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2355. return
  2356. }
  2357. if totals > stock_total_count {
  2358. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2359. return
  2360. }
  2361. }
  2362. if len(goodWarehouseInfo) > 0 {
  2363. //查询该患者耗材的历史数据
  2364. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2365. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2366. //数量发生改变
  2367. if parsetotal != count {
  2368. //如果现在的数量大于历史数量,就要看库存是否足够
  2369. if parsetotal > count {
  2370. //查询耗材所有库存
  2371. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2372. var stock_count int64
  2373. for _, it := range list {
  2374. stock_count += it.StockCount
  2375. }
  2376. //库存不足
  2377. if stock_count == 0 {
  2378. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2379. return
  2380. }
  2381. if (parsetotal - count) > stock_count {
  2382. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2383. return
  2384. }
  2385. }
  2386. }
  2387. }
  2388. }
  2389. }
  2390. }
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. //不使用耗材保存处方出库
  2397. if goodOutConfig.IsOpen != 1 {
  2398. if stockConfig.IsOpen == 1 {
  2399. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2400. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2401. if len(prescriptions) > 0 {
  2402. for _, item := range prescriptions {
  2403. items := item.(map[string]interface{})
  2404. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2405. projects := items["project"].([]interface{})
  2406. if len(projects) > 0 {
  2407. for _, project := range projects {
  2408. var project_id int64
  2409. var project_type int64
  2410. var totals float64
  2411. var project_name string
  2412. var parsetotal int64
  2413. var id int64
  2414. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2415. id = int64(project.(map[string]interface{})["id"].(float64))
  2416. }
  2417. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2418. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2419. }
  2420. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2421. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2422. }
  2423. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2424. total, _ := project.(map[string]interface{})["total"].(string)
  2425. totals, _ = strconv.ParseFloat(total, 64)
  2426. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2427. }
  2428. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2429. project_name = project.(map[string]interface{})["project_name"].(string)
  2430. }
  2431. if project_type == 3 {
  2432. //查找该耗材的出库记录
  2433. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2434. //没有出库记录
  2435. if len(goodWarehouseInfo) == 0 {
  2436. //查询耗材库存
  2437. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2438. var stock_count int64
  2439. for _, it := range list {
  2440. stock_count += it.StockCount
  2441. }
  2442. stock_counts := strconv.FormatInt(stock_count, 10)
  2443. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2444. if stock_total_count == 0 {
  2445. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2446. return
  2447. }
  2448. if totals > stock_total_count {
  2449. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2450. return
  2451. }
  2452. //查找今日该患者已经出库的所有耗材
  2453. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2454. for _, item := range goodList {
  2455. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2456. var flush_count int64
  2457. for _, it := range goodListSix {
  2458. flush_count += it.StockCount
  2459. }
  2460. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2461. creater := adminInfo.AdminUser.Id
  2462. if errs != nil {
  2463. goodErrcode := models.XtGoodErrcode{
  2464. UserOrgId: item.OrgId,
  2465. Errcode: "手动出库更新剩余出库失败",
  2466. GoodId: item.GoodId,
  2467. Status: 1,
  2468. Ctime: time.Now().Unix(),
  2469. Mtime: 0,
  2470. Count: 0,
  2471. StockCount: 0,
  2472. Creater: creater,
  2473. BatchNumberId: 0,
  2474. WarehouseOutId: 0,
  2475. }
  2476. service.CreateGoodErrcode(goodErrcode)
  2477. }
  2478. }
  2479. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2480. }
  2481. //有出库记录
  2482. if len(goodWarehouseInfo) > 0 {
  2483. //查询该患者耗材的历史数据
  2484. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2485. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2486. //数量发生改变
  2487. if parsetotal != count {
  2488. //查找今日该患者已经出库的所有耗材
  2489. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2490. for _, item := range goodList {
  2491. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2492. var flush_count int64
  2493. for _, it := range goodListSix {
  2494. flush_count += it.StockCount
  2495. }
  2496. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2497. //减少出库数量
  2498. creater := adminInfo.AdminUser.Id
  2499. if errs != nil {
  2500. goodErrcode := models.XtGoodErrcode{
  2501. UserOrgId: item.OrgId,
  2502. Errcode: "手动出库更新剩余出库失败",
  2503. GoodId: item.GoodId,
  2504. Status: 1,
  2505. Ctime: time.Now().Unix(),
  2506. Mtime: 0,
  2507. Count: 0,
  2508. StockCount: 0,
  2509. Creater: creater,
  2510. BatchNumberId: 0,
  2511. WarehouseOutId: 0,
  2512. }
  2513. service.CreateGoodErrcode(goodErrcode)
  2514. }
  2515. //查询默认仓库
  2516. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2517. var total_count int64
  2518. for _, it := range stockList {
  2519. total_count += it.StockCount
  2520. }
  2521. //基础库插入数据
  2522. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2523. }
  2524. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2537. var hpInfo models.HisPrescriptionInfo
  2538. if info.ID == 0 {
  2539. var randNum int
  2540. randNum = rand.Intn(10000) + 1000
  2541. timestamp := time.Now().Unix()
  2542. tempTime := time.Unix(timestamp, 0)
  2543. timeFormat := tempTime.Format("20060102150405")
  2544. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2545. hpInfo = models.HisPrescriptionInfo{
  2546. HisPatientId: his_patient_id,
  2547. UserOrgId: adminInfo.CurrentOrgId,
  2548. RecordDate: theTime.Unix(),
  2549. PatientId: patient_id,
  2550. Status: 1,
  2551. Ctime: time.Now().Unix(),
  2552. Mtime: time.Now().Unix(),
  2553. Creator: adminInfo.AdminUser.Id,
  2554. Modifier: adminInfo.AdminUser.Id,
  2555. Diagnosis: diagnose,
  2556. SickHistory: sick_history,
  2557. Departments: department,
  2558. RegisterType: reg_type,
  2559. PrescriptionNumber: p_number,
  2560. PrescriptionStatus: 1,
  2561. Doctor: role.UserName,
  2562. DoctorId: doctor_id,
  2563. SickType: sick_type,
  2564. PType: p_type,
  2565. PatientDiagnosis: patient_diagnose,
  2566. }
  2567. service.SavePatientPrescriptionInfo(hpInfo)
  2568. //创建步骤表
  2569. finish := models.XtDialysisFinish{
  2570. IsFinish: 1,
  2571. UserOrgId: adminInfo.CurrentOrgId,
  2572. Status: 1,
  2573. Ctime: time.Now().Unix(),
  2574. Mtime: 0,
  2575. Module: 4,
  2576. RecordDate: theTime.Unix(),
  2577. Sourse: 1,
  2578. PatientId: patient_id,
  2579. }
  2580. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2581. if dialysisFinish.ID == 0 {
  2582. service.CreateDialysisFinish(finish)
  2583. }
  2584. redis := service.RedisClient()
  2585. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2586. redis.Set(key, "", time.Second)
  2587. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2588. redis.Set(keyOne, "", time.Second)
  2589. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2590. redis.Set(keySeven, "", time.Second)
  2591. defer redis.Close()
  2592. } else {
  2593. hpInfo = models.HisPrescriptionInfo{
  2594. ID: info.ID,
  2595. UserOrgId: adminInfo.CurrentOrgId,
  2596. RecordDate: info.RecordDate,
  2597. PatientId: info.PatientId,
  2598. Status: 1,
  2599. Ctime: info.Ctime,
  2600. Mtime: time.Now().Unix(),
  2601. Creator: info.Creator,
  2602. Modifier: adminInfo.AdminUser.Id,
  2603. Diagnosis: diagnose,
  2604. SickHistory: sick_history,
  2605. Departments: department,
  2606. RegisterType: reg_type,
  2607. PrescriptionNumber: info.PrescriptionNumber,
  2608. Doctor: role.UserName,
  2609. PrescriptionStatus: info.PrescriptionStatus,
  2610. DoctorId: doctor_id,
  2611. SickType: sick_type,
  2612. PType: info.PType,
  2613. HisPatientId: info.HisPatientId,
  2614. PatientDiagnosis: patient_diagnose,
  2615. }
  2616. service.SavePatientPrescriptionInfo(hpInfo)
  2617. //创建步骤表
  2618. finish := models.XtDialysisFinish{
  2619. IsFinish: 1,
  2620. UserOrgId: adminInfo.CurrentOrgId,
  2621. Status: 1,
  2622. Ctime: time.Now().Unix(),
  2623. Mtime: 0,
  2624. Module: 4,
  2625. RecordDate: info.RecordDate,
  2626. Sourse: 1,
  2627. PatientId: info.PatientId,
  2628. }
  2629. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2630. if dialysisFinish.ID == 0 {
  2631. service.CreateDialysisFinish(finish)
  2632. }
  2633. redis := service.RedisClient()
  2634. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2635. redis.Set(key, "", time.Second)
  2636. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2637. redis.Set(keyOne, "", time.Second)
  2638. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2639. redis.Set(keySeven, "", time.Second)
  2640. defer redis.Close()
  2641. }
  2642. //定义切片
  2643. var adviceList []models.HisDoctorAdviceInfo
  2644. var projectList []models.HisPrescriptionProject
  2645. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2646. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2647. var tempPrescription *models.HisPrescription
  2648. if len(prescriptions) > 0 {
  2649. for _, item := range prescriptions {
  2650. items := item.(map[string]interface{})
  2651. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2652. utils.ErrorLog("id")
  2653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2654. return
  2655. }
  2656. id := int64(items["id"].(float64))
  2657. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2658. tempPrescription = &new_prescription
  2659. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2660. utils.ErrorLog("type")
  2661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2662. return
  2663. }
  2664. types := int64(items["type"].(float64))
  2665. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2666. utils.ErrorLog("med_type")
  2667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2668. return
  2669. }
  2670. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2671. if med_type == "0" {
  2672. med_type = "14"
  2673. }
  2674. //if order_status == 0 {
  2675. // order_status = 1
  2676. //}
  2677. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2678. utils.ErrorLog("pre_time")
  2679. }
  2680. preTime, _ := items["pre_time"].(string)
  2681. timeLayout := "2006-01-02"
  2682. loc, _ := time.LoadLocation("Local")
  2683. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2684. if err != nil {
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. pTime := theTime2.Unix()
  2689. ctime := time.Now().Unix()
  2690. if tempPrescription.ID == 0 {
  2691. prescription := &models.HisPrescription{
  2692. ID: 0,
  2693. PatientId: patient_id,
  2694. UserOrgId: adminInfo.CurrentOrgId,
  2695. RecordDate: recordDateTime,
  2696. Ctime: ctime,
  2697. Mtime: ctime,
  2698. Type: types,
  2699. Modifier: adminInfo.AdminUser.Id,
  2700. Creator: adminInfo.AdminUser.Id,
  2701. Status: 1,
  2702. Doctor: role.UserName,
  2703. HisPatientId: his_patient_id,
  2704. OrderStatus: 1,
  2705. BatchNumber: "",
  2706. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2707. PreTime: pTime,
  2708. PType: p_type,
  2709. MedType: med_type,
  2710. }
  2711. tempPrescription = prescription
  2712. service.SaveHisPrescription(tempPrescription)
  2713. redis := service.RedisClient()
  2714. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(key, "", time.Second)
  2716. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyOne, "", time.Second)
  2718. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keySeven, "", time.Second)
  2720. defer redis.Close()
  2721. } else {
  2722. tempPrescription.ID = id
  2723. tempPrescription.Type = types
  2724. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2725. tempPrescription.Mtime = time.Now().Unix()
  2726. tempPrescription.Doctor = role.UserName
  2727. //tempPrescription.OrderStatus = order_status
  2728. tempPrescription.PreTime = pTime
  2729. tempPrescription.MedType = med_type
  2730. service.SaveHisPrescription(tempPrescription)
  2731. redis := service.RedisClient()
  2732. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2733. redis.Set(key, "", time.Second)
  2734. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2735. redis.Set(keyOne, "", time.Second)
  2736. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2737. redis.Set(keySeven, "", time.Second)
  2738. defer redis.Close()
  2739. }
  2740. //service.SaveHisPrescription(prescription)
  2741. //更改患者挂号状态
  2742. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2743. fmt.Println("更改失败", err2)
  2744. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2745. advices := items["advices"].([]interface{})
  2746. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2747. groupNo := int64(0)
  2748. ctime := time.Now().Unix()
  2749. mtime := ctime
  2750. if len(advices) > 0 {
  2751. for _, advice := range advices {
  2752. var s models.HisDoctorAdviceInfo
  2753. s.PrescriptionId = tempPrescription.ID
  2754. s.AdviceType = 2
  2755. s.AdviceDoctor = doctor_id
  2756. s.StopState = 2
  2757. s.ExecutionState = 2
  2758. s.AdviceDate = recordDateTime
  2759. s.Status = 1
  2760. s.UserOrgId = adminInfo.CurrentOrgId
  2761. s.RecordDate = recordDateTime
  2762. s.StartTime = tempPrescription.PreTime
  2763. s.Groupno = groupNo
  2764. s.CreatedTime = ctime
  2765. s.UpdatedTime = mtime
  2766. s.PatientId = patient_id
  2767. s.HisPatientId = his_patient_id
  2768. s.StartTime = pTime
  2769. s.IsSettle = 2
  2770. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2771. if errcode > 0 {
  2772. c.ServeFailJSONWithSGJErrorCode(errcode)
  2773. return
  2774. }
  2775. s.StartTime = pTime
  2776. var total_count int64 //处方总库存
  2777. //查询改药品信息
  2778. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2779. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2780. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2781. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2782. total_count += prescribingNumberSeven * medical.MinNumber
  2783. }
  2784. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2785. total_count += prescribingNumberSeven
  2786. }
  2787. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2788. total_count += prescribingNumberSeven
  2789. }
  2790. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2791. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2792. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2793. if s.Price != lastWarehouse.RetailPrice {
  2794. s.Price = lastWarehouse.RetailPrice
  2795. }
  2796. if s.Price == 0 {
  2797. s.Price = lastWarehouse.RetailPrice
  2798. }
  2799. }
  2800. service.CreateHisDoctorAdvice(&s)
  2801. //记录日志
  2802. byterequest, _ := json.Marshal(s)
  2803. adviceLog := models.XtDoctorAdviceLog{
  2804. UserOrgId: s.UserOrgId,
  2805. PatientId: s.PatientId,
  2806. AdminUserId: adminInfo.AdminUser.Id,
  2807. Module: 1,
  2808. ErrLog: string(byterequest),
  2809. Status: 1,
  2810. Ctime: time.Now().Unix(),
  2811. Mtime: 0,
  2812. Source: "电脑端新建his医嘱",
  2813. RecordDate: s.AdviceDate,
  2814. }
  2815. service.CreateDoctorAdviceLog(adviceLog)
  2816. //存储切片中
  2817. adviceList = append(adviceList, s)
  2818. redis := service.RedisClient()
  2819. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2820. redis.Set(key, "", time.Second)
  2821. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2822. redis.Set(keyOne, "", time.Second)
  2823. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2824. redis.Set(keySeven, "", time.Second)
  2825. var randNum int
  2826. randNum = rand.Intn(10000) + 1000
  2827. timestamp := time.Now().Unix()
  2828. tempTime := time.Unix(timestamp, 0)
  2829. timeFormat := tempTime.Format("20060102150405")
  2830. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2831. service.CreateHisDoctorAdvice(&s)
  2832. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2833. redis.Set(keySix, "", time.Second)
  2834. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2835. redis.Set(keyFive, "", time.Second)
  2836. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2837. redis.Set(keyEight, "", time.Second)
  2838. defer redis.Close()
  2839. }
  2840. }
  2841. }
  2842. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2843. projects := items["project"].([]interface{})
  2844. if len(projects) > 0 {
  2845. for _, project := range projects {
  2846. var p models.HisPrescriptionProject
  2847. p.PrescriptionId = tempPrescription.ID
  2848. p.Ctime = time.Now().Unix()
  2849. p.Mtime = time.Now().Unix()
  2850. p.PatientId = patient_id
  2851. p.RecordDate = recordDateTime
  2852. p.Doctor = doctor_id
  2853. p.UserOrgId = adminInfo.CurrentOrgId
  2854. p.HisPatientId = his_patient_id
  2855. p.Status = 1
  2856. p.StartTime = pTime
  2857. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2858. if errcode > 0 {
  2859. c.ServeFailJSONWithSGJErrorCode(errcode)
  2860. return
  2861. }
  2862. if p.ID == 0 {
  2863. p.IsOut = 2
  2864. }
  2865. if p.ID > 0 {
  2866. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2867. p.IsOut = projectDetail.IsOut
  2868. }
  2869. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2870. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2871. if p.Type == 3 {
  2872. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2873. if p.Price != lastWarehouse.PackingPrice {
  2874. p.Price = lastWarehouse.PackingPrice
  2875. }
  2876. if p.Unit == "" {
  2877. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2878. p.Unit = goodInfoOne.PackingUnit
  2879. }
  2880. }
  2881. }
  2882. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2883. //
  2884. // if p.Type == 3 {
  2885. // //查询该耗材是否停用
  2886. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2887. // //表示该耗材已经停用,不能保存
  2888. // if goodInfoSeven.ID == 0 {
  2889. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2890. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2891. // return
  2892. // }
  2893. // }
  2894. //
  2895. //}
  2896. service.CreateHisProjectTwo(&p)
  2897. //记录日志
  2898. byterequest, _ := json.Marshal(p)
  2899. adviceLog := models.XtDoctorAdviceLog{
  2900. UserOrgId: p.UserOrgId,
  2901. PatientId: p.PatientId,
  2902. AdminUserId: adminInfo.AdminUser.Id,
  2903. Module: 1,
  2904. ErrLog: string(byterequest),
  2905. Status: 1,
  2906. Ctime: time.Now().Unix(),
  2907. Mtime: 0,
  2908. Source: "电脑端新建his项目",
  2909. RecordDate: p.RecordDate,
  2910. }
  2911. service.CreateDoctorAdviceLog(adviceLog)
  2912. projectList = append(projectList, p)
  2913. var randNum int
  2914. randNum = rand.Intn(10000) + 1000
  2915. timestamp := time.Now().Unix()
  2916. tempTime := time.Unix(timestamp, 0)
  2917. timeFormat := tempTime.Format("20060102150405")
  2918. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2919. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2920. //新增或者编辑项目,修改对应的标签数据
  2921. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2922. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2923. var label models.HisLabelPrintInfo
  2924. project, _ := service.GetProjectDetail(p.ProjectId)
  2925. if project.CostClassify == 3 { //类别为检验检查
  2926. if p.TeamId > 0 { //检验检查组套
  2927. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2928. if tempLabel.ID == 0 {
  2929. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2930. label.Number = tempPrescription.PrescriptionNumber
  2931. label.ProjectId = project.ID
  2932. label.Status = 1
  2933. label.IsPrint = 2
  2934. label.DoctorId = info.DoctorId
  2935. label.UserOrgId = p.UserOrgId
  2936. label.PatientId = patient_id
  2937. label.RecordDate = recordDateTime
  2938. label.Ctime = time.Now().Unix()
  2939. label.Mtime = time.Now().Unix()
  2940. label.ItemId = p.TeamId
  2941. label.FeedetlSn = p.FeedetlSn
  2942. label.PProjectId = p.ID
  2943. label.ProjectName = team.ProjectTeam
  2944. label.PatientName = patient.Name
  2945. service.CreateHisLabelRecord(&label)
  2946. }
  2947. } else { //单条检验检查项目
  2948. label.Number = tempPrescription.PrescriptionNumber
  2949. label.ProjectId = project.ID
  2950. label.Status = 1
  2951. label.DoctorId = info.DoctorId
  2952. label.UserOrgId = p.UserOrgId
  2953. label.PatientId = patient_id
  2954. label.RecordDate = recordDateTime
  2955. label.IsPrint = 2
  2956. label.Ctime = time.Now().Unix()
  2957. label.Mtime = time.Now().Unix()
  2958. label.FeedetlSn = p.FeedetlSn
  2959. label.PProjectId = p.ID
  2960. label.ItemId = p.TeamId
  2961. label.ProjectName = project.ProjectName
  2962. label.PatientName = patient.Name
  2963. service.CreateHisLabelRecord(&label)
  2964. }
  2965. }
  2966. }
  2967. }
  2968. service.SaveHisProjectTwo(&p)
  2969. }
  2970. }
  2971. }
  2972. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2973. // addition := items["addition"].([]interface{})
  2974. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2975. // ctime := time.Now().Unix()
  2976. // mtime := ctime
  2977. // if len(addition) > 0 {
  2978. // for _, item := range addition {
  2979. // var s models.HisAdditionalCharge
  2980. // s.PrescriptionId = tempPrescription.ID
  2981. // s.Status = 1
  2982. // s.UserOrgId = adminInfo.CurrentOrgId
  2983. // s.RecordDate = recordDateTime
  2984. // s.CreatedTime = ctime
  2985. // s.UpdatedTime = mtime
  2986. // s.PatientId = patient_id
  2987. // s.HisPatientId = his_patient_id
  2988. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2989. // if errcode > 0 {
  2990. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2991. // return
  2992. // }
  2993. // service.CreateAdditionalCharge(&s)
  2994. // var randNum int
  2995. // randNum = rand.Intn(10000) + 1000
  2996. // timestamp := time.Now().Unix()
  2997. // tempTime := time.Unix(timestamp, 0)
  2998. // timeFormat := tempTime.Format("20060102150405")
  2999. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3000. // service.CreateAdditionalCharge(&s)
  3001. //
  3002. // }
  3003. // }
  3004. //}
  3005. }
  3006. }
  3007. //查询今日该患者开的药品处方
  3008. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3009. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3010. //药品出库
  3011. if drugOutConfig.IsOpen == 1 {
  3012. for _, item := range hisdoctorlist {
  3013. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3014. // 查询该药品最后一次出库记录
  3015. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3016. if len(druginfo) > 0 {
  3017. //回退库存
  3018. for _, it := range druginfo {
  3019. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3020. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3021. }
  3022. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3023. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3024. }
  3025. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3026. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3027. }
  3028. }
  3029. }
  3030. //删除记录
  3031. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3032. //查询最后一次数据
  3033. if drugOutConfig.IsOpen == 1 {
  3034. //出库
  3035. if drug.IsUse == 2 {
  3036. creater := adminInfo.AdminUser.Id
  3037. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3038. }
  3039. //更新字典里面的库存
  3040. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3041. var sum_count int64
  3042. for _, its := range stockInfo {
  3043. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3044. if its.MaxUnit == baseDrug.MaxUnit {
  3045. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3046. }
  3047. sum_count += its.StockMaxNumber + its.StockMinNumber
  3048. }
  3049. //更新基础库存
  3050. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3051. //剩余库存
  3052. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3053. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3054. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3055. }
  3056. }
  3057. }
  3058. //耗材保存处方出库
  3059. if goodOutConfig.IsOpen == 1 {
  3060. //查询今日耗材出库数量
  3061. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3062. for _, item := range hisgoodlist {
  3063. //查询历史出库数据
  3064. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3065. var out_count_five int64
  3066. for _, item := range flowGood {
  3067. out_count_five += item.Count
  3068. }
  3069. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3070. if out_count_five != parseIntCount {
  3071. //查询耗材最后一次出库记录
  3072. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3073. //查询默认出库仓库库存
  3074. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3075. if len(wareOut) > 0 {
  3076. for _, it := range wareOut {
  3077. //回退库存
  3078. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3079. //删除出库记录
  3080. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3081. }
  3082. }
  3083. timeStr := time.Now().Format("2006-01-02")
  3084. timeArr := strings.Split(timeStr, "-")
  3085. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3086. total = total + 1
  3087. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3088. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3089. number = number + total
  3090. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3091. operation_time := time.Now().Unix()
  3092. creater := c.GetAdminUserInfo().AdminUser.Id
  3093. recordDateStr := time.Now().Format("2006-01-02")
  3094. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3095. nowtime := recordDate.Unix()
  3096. warehouseOut := models.WarehouseOut{
  3097. WarehouseOutOrderNumber: warehousing_out_order,
  3098. OperationTime: operation_time,
  3099. OrgId: adminInfo.CurrentOrgId,
  3100. Creater: creater,
  3101. Ctime: time.Now().Unix(),
  3102. Status: 1,
  3103. WarehouseOutTime: nowtime,
  3104. Type: 1,
  3105. StorehouseId: storeConfig.StorehouseOutInfo,
  3106. IsCheck: 1,
  3107. IsSys: 1,
  3108. }
  3109. //查询是否生成出库单
  3110. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3111. if out.ID == 0 {
  3112. service.AddSigleWarehouseOut(&warehouseOut)
  3113. }
  3114. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3115. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3116. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3117. dialyPrepareOne := models.DialysisBeforePrepare{
  3118. GoodTypeId: goodObj.GoodTypeId,
  3119. GoodId: item.ProjectId,
  3120. PatientId: item.PatientId,
  3121. RecordDate: item.RecordDate,
  3122. UserOrgId: adminInfo.CurrentOrgId,
  3123. Count: parseIntCount,
  3124. Ctime: time.Now().Unix(),
  3125. Creater: creater,
  3126. Status: 1,
  3127. StorehouseId: houseConfig.StorehouseOutInfo,
  3128. ProjectId: item.ID,
  3129. }
  3130. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3131. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3132. //查询历史出库数据
  3133. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3134. var out_count int64
  3135. for _, item := range flowGood {
  3136. out_count += item.Count
  3137. }
  3138. //如果历史数和当前数据不想等才进行退库出库
  3139. if out_count != parseIntCount {
  3140. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3141. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3142. detail := models.AutomaticReduceDetail{
  3143. WarehouseOutId: 0,
  3144. WarehouseOutOrderNumber: "",
  3145. PatientId: item.PatientId,
  3146. Ctime: time.Now().Unix(),
  3147. Mtime: 0,
  3148. Status: 1,
  3149. RecordTime: item.RecordDate,
  3150. OrgId: item.UserOrgId,
  3151. GoodId: item.ProjectId,
  3152. GoodTypeId: 0,
  3153. Count: parseIntCount,
  3154. Type: 0,
  3155. ProjectId: item.ID,
  3156. StorehouseId: 0,
  3157. }
  3158. service.CreateAutoDetail(detail)
  3159. //查询剩余库存
  3160. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3161. var sum_count int64
  3162. for _, item := range goodList {
  3163. sum_count += item.StockCount
  3164. }
  3165. //更新剩余库存
  3166. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3167. //耗材
  3168. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3169. }
  3170. }
  3171. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3172. //查询历史出库数据
  3173. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3174. var out_count int64
  3175. for _, item := range flowGood {
  3176. out_count += item.Count
  3177. }
  3178. //如果历史数和当前数据不想等才进行退库出库
  3179. if out_count != parseIntCount {
  3180. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3181. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3182. detail := models.AutomaticReduceDetail{
  3183. WarehouseOutId: 0,
  3184. WarehouseOutOrderNumber: "",
  3185. PatientId: item.PatientId,
  3186. Ctime: time.Now().Unix(),
  3187. Mtime: 0,
  3188. Status: 1,
  3189. RecordTime: item.RecordDate,
  3190. OrgId: item.UserOrgId,
  3191. GoodId: item.ProjectId,
  3192. GoodTypeId: 0,
  3193. Count: parseIntCount,
  3194. Type: 0,
  3195. ProjectId: item.ID,
  3196. StorehouseId: 0,
  3197. }
  3198. service.CreateAutoDetail(detail)
  3199. //查询剩余库存
  3200. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3201. var sum_count int64
  3202. for _, item := range goodList {
  3203. sum_count += item.StockCount
  3204. }
  3205. //更新剩余库存
  3206. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3207. //耗材
  3208. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3209. }
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. //redisClient := service.RedisClient()
  3216. //defer redisClient.Close()
  3217. //
  3218. //list := models.HisList{
  3219. // Patient_id: patient_id,
  3220. // Advice_id:0,
  3221. // Record_date: 0,
  3222. // Advice: adviceList,
  3223. // Project: nil,
  3224. //}
  3225. //hisLis = append(hisLis, list)
  3226. //
  3227. //advice_json, _ := json.Marshal(&hisLis)
  3228. //redisClient.RPush("111", advice_json).Result()
  3229. //result, _ := redisClient.RPop("111").Result()
  3230. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3231. //
  3232. //var dat []map[string]interface{}
  3233. //json.Unmarshal([]byte(result), &dat)
  3234. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3235. //
  3236. //for k,v:=range dat{
  3237. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3238. //}
  3239. //project_json, _ := json.Marshal(&projectList)
  3240. //redisClient.LPush("222", project_json).Result()
  3241. if err == nil {
  3242. c.ServeSuccessJSON(map[string]interface{}{
  3243. "msg": "保存成功",
  3244. })
  3245. return
  3246. } else {
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3248. return
  3249. }
  3250. }
  3251. func (c *HisApiController) EditHisPrescription() {
  3252. record_date := c.GetString("record_date")
  3253. patient_id, _ := c.GetInt64("patient_id")
  3254. reg_type, _ := c.GetInt64("reg_type")
  3255. //diagnose, _ := c.GetInt64("diagnose", 0)
  3256. diagnose := c.GetString("diagnose")
  3257. sick_type, _ := c.GetInt64("sick_type")
  3258. sick_history := c.GetString("sick_history")
  3259. doctor_id, _ := c.GetInt64("doctor", 0)
  3260. department, _ := c.GetInt64("department", 0)
  3261. his_patient_id, _ := c.GetInt64("his_patient_id")
  3262. p_type, _ := c.GetInt64("p_type")
  3263. dataBody := make(map[string]interface{}, 0)
  3264. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3265. if err != nil {
  3266. utils.ErrorLog(err.Error())
  3267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3268. return
  3269. }
  3270. timeLayout := "2006-01-02"
  3271. loc, _ := time.LoadLocation("Local")
  3272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3273. if err != nil {
  3274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3275. return
  3276. }
  3277. adminInfo := c.GetAdminUserInfo()
  3278. recordDateTime := theTime.Unix()
  3279. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3280. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3281. var hpInfo models.HisPrescriptionInfo
  3282. if info.ID == 0 {
  3283. var randNum int
  3284. randNum = rand.Intn(10000) + 1000
  3285. timestamp := time.Now().Unix()
  3286. tempTime := time.Unix(timestamp, 0)
  3287. timeFormat := tempTime.Format("20060102150405")
  3288. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3289. hpInfo = models.HisPrescriptionInfo{
  3290. UserOrgId: adminInfo.CurrentOrgId,
  3291. RecordDate: theTime.Unix(),
  3292. PatientId: patient_id,
  3293. Status: 1,
  3294. Ctime: time.Now().Unix(),
  3295. Mtime: time.Now().Unix(),
  3296. Creator: adminInfo.AdminUser.Id,
  3297. Modifier: adminInfo.AdminUser.Id,
  3298. Diagnosis: diagnose,
  3299. SickHistory: sick_history,
  3300. Departments: department,
  3301. RegisterType: reg_type,
  3302. PrescriptionNumber: p_number,
  3303. PrescriptionStatus: 1,
  3304. Doctor: role.UserName,
  3305. DoctorId: doctor_id,
  3306. SickType: sick_type,
  3307. PType: p_type,
  3308. }
  3309. service.SavePatientPrescriptionInfo(hpInfo)
  3310. } else {
  3311. hpInfo = models.HisPrescriptionInfo{
  3312. ID: info.ID,
  3313. UserOrgId: adminInfo.CurrentOrgId,
  3314. RecordDate: info.RecordDate,
  3315. PatientId: info.PatientId,
  3316. Status: 1,
  3317. Ctime: info.Ctime,
  3318. Mtime: time.Now().Unix(),
  3319. Creator: info.Creator,
  3320. Modifier: adminInfo.AdminUser.Id,
  3321. Diagnosis: diagnose,
  3322. SickHistory: sick_history,
  3323. Departments: department,
  3324. RegisterType: reg_type,
  3325. PrescriptionNumber: info.PrescriptionNumber,
  3326. Doctor: role.UserName,
  3327. PrescriptionStatus: info.PrescriptionStatus,
  3328. DoctorId: doctor_id,
  3329. SickType: sick_type,
  3330. PType: info.PType,
  3331. }
  3332. service.SavePatientPrescriptionInfo(hpInfo)
  3333. }
  3334. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3335. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3336. if len(prescriptions) > 0 {
  3337. for _, item := range prescriptions {
  3338. items := item.(map[string]interface{})
  3339. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3340. utils.ErrorLog("id")
  3341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. id := int64(items["id"].(float64))
  3345. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3346. utils.ErrorLog("type")
  3347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. types := int64(items["type"].(float64))
  3351. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3352. utils.ErrorLog("med_type")
  3353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3357. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3358. ctime := time.Now().Unix()
  3359. prescription := &models.HisPrescription{
  3360. ID: id,
  3361. PatientId: patient_id,
  3362. UserOrgId: adminInfo.CurrentOrgId,
  3363. RecordDate: recordDateTime,
  3364. Ctime: ctime,
  3365. Mtime: ctime,
  3366. Type: types,
  3367. Modifier: adminInfo.AdminUser.Id,
  3368. Creator: adminInfo.AdminUser.Id,
  3369. Status: 1,
  3370. Doctor: role.UserName,
  3371. HisPatientId: his_patient_id,
  3372. OrderStatus: 1,
  3373. BatchNumber: "",
  3374. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3375. PType: hpInfo.PType,
  3376. MedType: med_type,
  3377. }
  3378. if historyPrescription.ID > 0 {
  3379. prescription.PreTime = historyPrescription.PreTime
  3380. }
  3381. service.SaveHisPrescription(prescription)
  3382. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3383. advices := items["advices"].([]interface{})
  3384. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3385. groupNo := int64(0)
  3386. ctime := time.Now().Unix()
  3387. mtime := ctime
  3388. if len(advices) > 0 {
  3389. for _, advice := range advices {
  3390. var s models.HisDoctorAdviceInfo
  3391. s.PrescriptionId = prescription.ID
  3392. s.AdviceType = 2
  3393. s.AdviceDoctor = adminInfo.AdminUser.Id
  3394. s.StopState = 2
  3395. s.ExecutionState = 2
  3396. s.AdviceDate = recordDateTime
  3397. s.Status = 1
  3398. s.UserOrgId = adminInfo.CurrentOrgId
  3399. s.RecordDate = recordDateTime
  3400. s.StartTime = prescription.PreTime
  3401. s.Groupno = groupNo
  3402. s.CreatedTime = ctime
  3403. s.UpdatedTime = mtime
  3404. s.PatientId = patient_id
  3405. s.HisPatientId = his_patient_id
  3406. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3407. if errcode > 0 {
  3408. c.ServeFailJSONWithSGJErrorCode(errcode)
  3409. return
  3410. }
  3411. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3412. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3413. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3414. if s.Price == 0 {
  3415. s.Price = lastWarehouse.RetailPrice
  3416. }
  3417. }
  3418. service.CreateHisDoctorAdvice(&s)
  3419. //记录日志
  3420. byterequest, _ := json.Marshal(s)
  3421. adviceLog := models.XtDoctorAdviceLog{
  3422. UserOrgId: s.UserOrgId,
  3423. PatientId: s.PatientId,
  3424. AdminUserId: adminInfo.AdminUser.Id,
  3425. Module: 1,
  3426. ErrLog: string(byterequest),
  3427. Status: 1,
  3428. Ctime: time.Now().Unix(),
  3429. Mtime: 0,
  3430. Source: "电脑端his医嘱修改",
  3431. RecordDate: s.AdviceDate,
  3432. }
  3433. service.CreateDoctorAdviceLog(adviceLog)
  3434. redis := service.RedisClient()
  3435. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3436. redis.Set(key, "", time.Second)
  3437. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3438. fmt.Println("keyOne", keyOne)
  3439. redis.Set(keyOne, "", time.Second)
  3440. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3441. redis.Set(keySeven, "", time.Second)
  3442. redis.Close()
  3443. }
  3444. }
  3445. }
  3446. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3447. projects := items["project"].([]interface{})
  3448. if len(projects) > 0 {
  3449. for _, project := range projects {
  3450. var p models.HisPrescriptionProject
  3451. p.PrescriptionId = prescription.ID
  3452. p.Ctime = time.Now().Unix()
  3453. p.Mtime = time.Now().Unix()
  3454. p.PatientId = patient_id
  3455. p.RecordDate = recordDateTime
  3456. p.UserOrgId = adminInfo.CurrentOrgId
  3457. p.HisPatientId = his_patient_id
  3458. p.Status = 1
  3459. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3460. if errcode > 0 {
  3461. c.ServeFailJSONWithSGJErrorCode(errcode)
  3462. return
  3463. }
  3464. service.CreateHisProjectTwo(&p)
  3465. //记录日志
  3466. byterequest, _ := json.Marshal(p)
  3467. adviceLog := models.XtDoctorAdviceLog{
  3468. UserOrgId: p.UserOrgId,
  3469. PatientId: p.PatientId,
  3470. AdminUserId: adminInfo.AdminUser.Id,
  3471. Module: 1,
  3472. ErrLog: string(byterequest),
  3473. Status: 1,
  3474. Ctime: time.Now().Unix(),
  3475. Mtime: 0,
  3476. Source: "电脑端his项目修改",
  3477. RecordDate: p.RecordDate,
  3478. }
  3479. service.CreateDoctorAdviceLog(adviceLog)
  3480. }
  3481. }
  3482. }
  3483. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3484. addition := items["addition"].([]interface{})
  3485. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3486. ctime := time.Now().Unix()
  3487. mtime := ctime
  3488. if len(addition) > 0 {
  3489. for _, item := range addition {
  3490. var s models.HisAdditionalCharge
  3491. s.PrescriptionId = prescription.ID
  3492. s.Status = 1
  3493. s.UserOrgId = adminInfo.CurrentOrgId
  3494. s.RecordDate = recordDateTime
  3495. s.CreatedTime = ctime
  3496. s.UpdatedTime = mtime
  3497. s.PatientId = patient_id
  3498. s.HisPatientId = his_patient_id
  3499. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3500. if errcode > 0 {
  3501. c.ServeFailJSONWithSGJErrorCode(errcode)
  3502. return
  3503. }
  3504. service.CreateAdditionalCharge(&s)
  3505. }
  3506. }
  3507. }
  3508. }
  3509. }
  3510. }
  3511. if err == nil {
  3512. c.ServeSuccessJSON(map[string]interface{}{
  3513. "msg": "保存成功",
  3514. })
  3515. return
  3516. } else {
  3517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3518. return
  3519. }
  3520. }
  3521. func (c *HisApiController) DeletePrescription() {
  3522. prescription_id, _ := c.GetInt64("id")
  3523. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3524. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3525. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3526. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3527. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3528. //耗材保存处方出库
  3529. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3530. //已收费和已发药限制逻辑
  3531. isCharge := false
  3532. isMedicine := false
  3533. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3534. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3535. for _, item := range new_prescriptions {
  3536. if item.IsMedicine == 1 {
  3537. isMedicine = true
  3538. }
  3539. }
  3540. for _, item := range new_prescriptions {
  3541. if item.OrderStatus == 4 {
  3542. isCharge = true
  3543. }
  3544. }
  3545. if p_err != nil {
  3546. if new_prescription.ID > 0 {
  3547. if new_prescription.OrderStatus == 2 {
  3548. isCharge = true
  3549. }
  3550. }
  3551. }
  3552. for _, item := range advices {
  3553. if item.IsMedicine == 1 {
  3554. isMedicine = true
  3555. }
  3556. }
  3557. if isCharge {
  3558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3559. return
  3560. }
  3561. if isMedicine {
  3562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3563. return
  3564. }
  3565. //已收费和已发药限制逻辑
  3566. if len(projects) > 0 {
  3567. for _, item := range projects {
  3568. service.DeletePrintInfo(item.ID) //删除打印信息
  3569. if goodOutConfig.IsOpen != 1 {
  3570. if stockConfig.IsOpen == 1 {
  3571. if item.Type == 3 && item.IsOut == 1 {
  3572. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3573. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3574. good.Total = good.Total + f_count
  3575. service.UpdateGoodInfo(&good)
  3576. operation_time := time.Now().Unix()
  3577. creater := c.GetAdminUserInfo().AdminUser.Id
  3578. //创建退库单
  3579. timeStr := time.Now().Format("2006-01-02")
  3580. timeArr := strings.Split(timeStr, "-")
  3581. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3582. total = total + 1
  3583. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3584. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3585. cancelStock := models.CancelStock{
  3586. OrderNumber: orderNumber,
  3587. OperaTime: operation_time,
  3588. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3589. Creater: creater,
  3590. Ctime: time.Now().Unix(),
  3591. Status: 1,
  3592. ReturnTime: item.RecordDate,
  3593. Type: 1,
  3594. StorehouseId: houseConfig.StorehouseOutInfo,
  3595. IsCheck: 1,
  3596. }
  3597. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3598. if msgerrkonde == gorm.ErrRecordNotFound {
  3599. service.AddSigleCancelStock(&cancelStock)
  3600. }
  3601. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3602. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3603. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3604. //查询该耗材是否出库
  3605. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3606. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3607. deaerler, _ := service.GetDealerById(info.Dealer)
  3608. var total_count int64
  3609. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3610. total_count += count
  3611. if info.ID > 0 {
  3612. if info.Count >= total_count {
  3613. //回退库存
  3614. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3615. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3616. var flush_count int64
  3617. for _, it := range goodList {
  3618. flush_count += it.StockCount
  3619. }
  3620. cancelStockInfo := models.CancelStockInfo{
  3621. GoodId: item.ProjectId,
  3622. CancelStockId: cancel.ID,
  3623. GoodTypeId: good.GoodTypeId,
  3624. Count: prescribingNumber,
  3625. Price: info.Price,
  3626. Total: 0,
  3627. ProductDate: info.ProductDate,
  3628. ExpiryDate: info.ExpiryDate,
  3629. Ctime: time.Now().Unix(),
  3630. Status: 1,
  3631. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3632. OrderNumber: cancel.OrderNumber,
  3633. Type: 0,
  3634. Dealer: deaerler.DealerName,
  3635. Manufacturer: manufacturer.ManufacturerName,
  3636. Number: info.Number,
  3637. RegisterAccount: "",
  3638. Remark: "",
  3639. WarehouseInfoId: info.WarehouseInfotId,
  3640. PatientId: info.PatientId,
  3641. RecordDate: info.SysRecordTime,
  3642. StorehouseId: houseConfig.StorehouseOutInfo,
  3643. IsCheck: 1,
  3644. }
  3645. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3646. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3647. flow := models.VmStockFlow{
  3648. WarehousingId: info.WarehouseInfotId,
  3649. GoodId: item.ProjectId,
  3650. Number: info.Number,
  3651. LicenseNumber: info.LicenseNumber,
  3652. Count: prescribingNumber,
  3653. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3654. PatientId: item.PatientId,
  3655. SystemTime: info.SysRecordTime,
  3656. ConsumableType: 7,
  3657. IsSys: 0,
  3658. WarehousingOrder: "",
  3659. WarehouseOutId: info.WarehouseOutId,
  3660. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3661. IsEdit: 0,
  3662. CancelStockId: cancel.ID,
  3663. CancelOrderNumber: cancel.OrderNumber,
  3664. Manufacturer: manufacturer.ID,
  3665. Dealer: 0,
  3666. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3667. UpdateCreator: 0,
  3668. Status: 1,
  3669. Ctime: time.Now().Unix(),
  3670. Mtime: 0,
  3671. Price: info.Price,
  3672. WarehousingDetailId: info.WarehouseInfotId,
  3673. WarehouseOutDetailId: info.ID,
  3674. CancelOutDetailId: cancelInfo.ID,
  3675. ProductDate: info.ProductDate,
  3676. ExpireDate: info.ExpiryDate,
  3677. StorehouseId: houseConfig.StorehouseOutInfo,
  3678. OverCount: flush_count,
  3679. }
  3680. service.CreateStockFlowOne(flow)
  3681. //退库数量增加
  3682. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3683. //出库数量减少
  3684. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3685. }
  3686. if info.Count < total_count {
  3687. //回退库存
  3688. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3689. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3690. var flush_count int64
  3691. for _, it := range goodList {
  3692. flush_count += it.StockCount
  3693. }
  3694. cancelStockInfo := models.CancelStockInfo{
  3695. GoodId: item.ProjectId,
  3696. CancelStockId: cancel.ID,
  3697. GoodTypeId: good.GoodTypeId,
  3698. Count: info.Count,
  3699. Price: info.Price,
  3700. Total: 0,
  3701. ProductDate: info.ProductDate,
  3702. ExpiryDate: info.ExpiryDate,
  3703. Ctime: time.Now().Unix(),
  3704. Status: 1,
  3705. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3706. OrderNumber: cancel.OrderNumber,
  3707. Type: 0,
  3708. Dealer: deaerler.DealerName,
  3709. Manufacturer: manufacturer.ManufacturerName,
  3710. Number: info.Number,
  3711. RegisterAccount: "",
  3712. Remark: "",
  3713. WarehouseInfoId: info.WarehouseInfotId,
  3714. PatientId: info.PatientId,
  3715. RecordDate: info.SysRecordTime,
  3716. StorehouseId: houseConfig.StorehouseOutInfo,
  3717. IsCheck: 1,
  3718. }
  3719. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3720. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3721. flow := models.VmStockFlow{
  3722. WarehousingId: info.WarehouseInfotId,
  3723. GoodId: item.ProjectId,
  3724. Number: info.Number,
  3725. LicenseNumber: info.LicenseNumber,
  3726. Count: info.Count,
  3727. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3728. PatientId: item.PatientId,
  3729. SystemTime: info.SysRecordTime,
  3730. ConsumableType: 7,
  3731. IsSys: 0,
  3732. WarehousingOrder: "",
  3733. WarehouseOutId: info.WarehouseOutId,
  3734. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3735. IsEdit: 0,
  3736. CancelStockId: cancel.ID,
  3737. CancelOrderNumber: cancel.OrderNumber,
  3738. Manufacturer: manufacturer.ID,
  3739. Dealer: 0,
  3740. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3741. UpdateCreator: 0,
  3742. Status: 1,
  3743. Ctime: time.Now().Unix(),
  3744. Mtime: 0,
  3745. Price: info.Price,
  3746. WarehousingDetailId: info.WarehouseInfotId,
  3747. WarehouseOutDetailId: info.ID,
  3748. CancelOutDetailId: cancelInfo.ID,
  3749. ProductDate: info.ProductDate,
  3750. ExpireDate: info.ExpiryDate,
  3751. StorehouseId: houseConfig.StorehouseOutInfo,
  3752. OverCount: flush_count,
  3753. }
  3754. service.CreateStockFlowOne(flow)
  3755. //退库数量增加
  3756. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3757. //出库数量减少
  3758. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3759. }
  3760. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3761. var flush_count int64
  3762. for _, it := range goodList {
  3763. flush_count += it.StockCount
  3764. }
  3765. //查询已出库数量
  3766. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3767. if prescribingNumber < dialysisInfo.Count {
  3768. //改变数量
  3769. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3770. }
  3771. if prescribingNumber >= dialysisInfo.Count {
  3772. //删除出库表
  3773. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3774. }
  3775. //更新库存
  3776. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3777. //更新基础库库存
  3778. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3779. }
  3780. }
  3781. }
  3782. }
  3783. //保存耗材出库
  3784. if goodOutConfig.IsOpen == 1 {
  3785. if item.Type == 3 {
  3786. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3787. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3788. good.Total = good.Total + f_count
  3789. service.UpdateGoodInfo(&good)
  3790. operation_time := time.Now().Unix()
  3791. creater := c.GetAdminUserInfo().AdminUser.Id
  3792. //创建退库单
  3793. timeStr := time.Now().Format("2006-01-02")
  3794. timeArr := strings.Split(timeStr, "-")
  3795. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3796. total = total + 1
  3797. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3798. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3799. cancelStock := models.CancelStock{
  3800. OrderNumber: orderNumber,
  3801. OperaTime: operation_time,
  3802. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3803. Creater: creater,
  3804. Ctime: time.Now().Unix(),
  3805. Status: 1,
  3806. ReturnTime: item.RecordDate,
  3807. Type: 1,
  3808. StorehouseId: houseConfig.StorehouseOutInfo,
  3809. IsCheck: 1,
  3810. }
  3811. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3812. if msgerrkonde == gorm.ErrRecordNotFound {
  3813. service.AddSigleCancelStock(&cancelStock)
  3814. }
  3815. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3816. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3817. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3818. //查询该耗材是否出库
  3819. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3820. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3821. deaerler, _ := service.GetDealerById(info.Dealer)
  3822. var total_count int64
  3823. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3824. total_count += count
  3825. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3826. var flush_count int64
  3827. for _, it := range goodList {
  3828. flush_count += it.StockCount
  3829. }
  3830. fmt.Println("历史出库数据", info.Count)
  3831. fmt.Println("出库数量", total_count)
  3832. if info.ID > 0 {
  3833. cancelStockInfo := models.CancelStockInfo{
  3834. GoodId: item.ProjectId,
  3835. CancelStockId: cancel.ID,
  3836. GoodTypeId: good.GoodTypeId,
  3837. Count: prescribingNumber,
  3838. Price: info.Price,
  3839. Total: 0,
  3840. ProductDate: info.ProductDate,
  3841. ExpiryDate: info.ExpiryDate,
  3842. Ctime: time.Now().Unix(),
  3843. Status: 1,
  3844. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3845. OrderNumber: cancel.OrderNumber,
  3846. Type: 0,
  3847. Dealer: deaerler.DealerName,
  3848. Manufacturer: manufacturer.ManufacturerName,
  3849. Number: info.Number,
  3850. RegisterAccount: "",
  3851. Remark: "",
  3852. WarehouseInfoId: info.WarehouseInfotId,
  3853. PatientId: info.PatientId,
  3854. RecordDate: info.SysRecordTime,
  3855. StorehouseId: houseConfig.StorehouseOutInfo,
  3856. IsCheck: 1,
  3857. }
  3858. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3859. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3860. //查询出库数量
  3861. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3862. //出库数据 大于 退库数量
  3863. if len(list) > 0 {
  3864. for _, it := range list {
  3865. //回退库存
  3866. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3867. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3868. var flush_count_one int64
  3869. for _, it := range goodList {
  3870. flush_count_one += it.StockCount
  3871. }
  3872. //查询该批次是否有退库数据
  3873. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3874. creater := c.GetAdminUserInfo().AdminUser.Id
  3875. flow := models.VmStockFlow{
  3876. WarehousingId: it.WarehouseInfotId,
  3877. GoodId: it.GoodId,
  3878. Number: it.Number,
  3879. LicenseNumber: it.LicenseNumber,
  3880. Count: it.Count,
  3881. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3882. PatientId: it.PatientId,
  3883. SystemTime: it.SysRecordTime,
  3884. ConsumableType: 7,
  3885. IsSys: 0,
  3886. WarehousingOrder: "",
  3887. WarehouseOutId: it.WarehouseOutId,
  3888. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3889. IsEdit: 0,
  3890. CancelStockId: cancel.ID,
  3891. CancelOrderNumber: cancel.OrderNumber,
  3892. Manufacturer: manufacturer.ID,
  3893. Dealer: 0,
  3894. Creator: creater,
  3895. UpdateCreator: 0,
  3896. Status: 1,
  3897. Ctime: time.Now().Unix(),
  3898. Mtime: 0,
  3899. Price: it.Price,
  3900. WarehousingDetailId: it.WarehouseInfotId,
  3901. WarehouseOutDetailId: it.ID,
  3902. CancelOutDetailId: cancelInfo.ID,
  3903. ProductDate: it.ProductDate,
  3904. ExpireDate: it.ExpiryDate,
  3905. StorehouseId: houseConfig.StorehouseOutInfo,
  3906. OverCount: flush_count_one,
  3907. }
  3908. service.CreateStockFlowOne(flow)
  3909. //if flow.ID > 0 {
  3910. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3911. //}
  3912. }
  3913. }
  3914. //flow := models.VmStockFlow{
  3915. // WarehousingId: info.WarehouseInfotId,
  3916. // GoodId: item.ProjectId,
  3917. // Number: info.Number,
  3918. // LicenseNumber: info.LicenseNumber,
  3919. // Count: prescribingNumber,
  3920. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3921. // PatientId: item.PatientId,
  3922. // SystemTime: info.SysRecordTime,
  3923. // ConsumableType: 7,
  3924. // IsSys: 0,
  3925. // WarehousingOrder: "",
  3926. // WarehouseOutId: info.WarehouseOutId,
  3927. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3928. // IsEdit: 0,
  3929. // CancelStockId: cancel.ID,
  3930. // CancelOrderNumber: cancel.OrderNumber,
  3931. // Manufacturer: manufacturer.ID,
  3932. // Dealer: 0,
  3933. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3934. // UpdateCreator: 0,
  3935. // Status: 1,
  3936. // Ctime: time.Now().Unix(),
  3937. // Mtime: 0,
  3938. // Price: info.Price,
  3939. // WarehousingDetailId: info.WarehouseInfotId,
  3940. // WarehouseOutDetailId: info.ID,
  3941. // CancelOutDetailId: cancelInfo.ID,
  3942. // ProductDate: info.ProductDate,
  3943. // ExpireDate: info.ExpiryDate,
  3944. // StorehouseId: houseConfig.StorehouseOutInfo,
  3945. // OverCount: flush_count,
  3946. //}
  3947. //service.CreateStockFlowOne(flow)
  3948. //退库数量增加
  3949. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3950. //出库数量减少
  3951. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3952. //查询已出库数量
  3953. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3954. if prescribingNumber < dialysisInfo.Count {
  3955. //改变数量
  3956. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3957. }
  3958. if prescribingNumber >= dialysisInfo.Count {
  3959. //删除出库表
  3960. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3961. }
  3962. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3963. var flush_count_one int64
  3964. for _, it := range goodList {
  3965. flush_count_one += it.StockCount
  3966. }
  3967. //更新库存
  3968. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3969. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3970. //更新基础库库存
  3971. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3972. }
  3973. }
  3974. }
  3975. }
  3976. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3977. fmt.Println(err)
  3978. }
  3979. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3980. fmt.Println(err)
  3981. if len(advices) > 0 {
  3982. for _, item := range advices {
  3983. redis := service.RedisClient()
  3984. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3985. redis.Set(keyFive, "", time.Second)
  3986. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3987. redis.Set(keyOne, "", time.Second)
  3988. redis.Close()
  3989. }
  3990. }
  3991. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3992. if len(advices) > 0 {
  3993. for _, item := range advices {
  3994. creater := c.GetAdminUserInfo().AdminUser.Id
  3995. service.DrugAutoAddCancelInfo(item, creater)
  3996. }
  3997. }
  3998. } else {
  3999. if drugOutConfig.IsOpen == 1 {
  4000. if len(advices) > 0 {
  4001. for _, item := range advices {
  4002. creater := c.GetAdminUserInfo().AdminUser.Id
  4003. service.DrugAutoAddCancelInfo(item, creater)
  4004. }
  4005. }
  4006. } else {
  4007. if len(advices) > 0 {
  4008. for _, item := range advices {
  4009. creater := c.GetAdminUserInfo().AdminUser.Id
  4010. service.DrugAutoAddCancelInfo(item, creater)
  4011. }
  4012. }
  4013. }
  4014. }
  4015. c.ServeSuccessJSON(map[string]interface{}{
  4016. "msg": "删除成功",
  4017. })
  4018. return
  4019. }
  4020. func (c *HisApiController) DeleteDoctorAdvice() {
  4021. id, _ := c.GetInt64("id")
  4022. advice, _ := service.GetHisDoctorAdvicesById(id)
  4023. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4024. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4025. //已收费和已发药的限制逻辑
  4026. isCharge := false
  4027. isMedicine := false
  4028. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4029. //获取今天该患者所有处方,判断是否发药或者收费
  4030. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4031. for _, item := range new_prescriptions {
  4032. if item.IsMedicine == 1 {
  4033. isMedicine = true
  4034. }
  4035. }
  4036. for _, item := range new_prescriptions {
  4037. if item.OrderStatus == 4 {
  4038. isCharge = true
  4039. }
  4040. }
  4041. if isMedicine {
  4042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4043. return
  4044. }
  4045. if isCharge {
  4046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4047. return
  4048. }
  4049. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4050. for _, item := range advices {
  4051. if item.IsMedicine == 1 {
  4052. isMedicine = true
  4053. }
  4054. }
  4055. if isMedicine {
  4056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4057. return
  4058. }
  4059. if new_prescription.ID > 0 {
  4060. if new_prescription.OrderStatus == 2 {
  4061. isCharge = true
  4062. }
  4063. }
  4064. if isCharge {
  4065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4066. return
  4067. }
  4068. //已收费和已发药的限制逻辑
  4069. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4070. redis := service.RedisClient()
  4071. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4072. redis.Set(keyFive, "", time.Second)
  4073. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4074. redis.Set(keyOne, "", time.Second)
  4075. defer redis.Close()
  4076. if err == nil {
  4077. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4078. //查询是否在处方中出库
  4079. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4080. if openConfig.IsOpen != 1 {
  4081. //判断该医嘱是否执行了
  4082. if advice.ExecutionState == 1 {
  4083. creater := c.GetAdminUserInfo().AdminUser.Id
  4084. service.DrugAutoAddCancelInfo(&advice, creater)
  4085. }
  4086. }
  4087. //开启保存处方扣减功能
  4088. if openConfig.IsOpen == 1 {
  4089. creater := c.GetAdminUserInfo().AdminUser.Id
  4090. service.DrugAutoAddCancelInfo(&advice, creater)
  4091. }
  4092. } else {
  4093. if drugOutConfig.IsOpen == 1 {
  4094. //查询是否在处方中出库
  4095. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4096. if openConfig.IsOpen != 1 {
  4097. //判断该医嘱是否执行了
  4098. if advice.ExecutionState == 1 {
  4099. creater := c.GetAdminUserInfo().AdminUser.Id
  4100. service.DrugAutoAddCancelInfo(&advice, creater)
  4101. }
  4102. }
  4103. //开启保存处方扣减功能
  4104. if openConfig.IsOpen == 1 {
  4105. creater := c.GetAdminUserInfo().AdminUser.Id
  4106. service.DrugAutoAddCancelInfo(&advice, creater)
  4107. }
  4108. } else {
  4109. //判断该医嘱是否执行了
  4110. if advice.ExecutionState == 1 {
  4111. creater := c.GetAdminUserInfo().AdminUser.Id
  4112. service.DrugAutoAddCancelInfo(&advice, creater)
  4113. }
  4114. }
  4115. }
  4116. c.ServeSuccessJSON(map[string]interface{}{
  4117. "msg": "删除成功",
  4118. })
  4119. return
  4120. } else {
  4121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4122. return
  4123. }
  4124. }
  4125. func (c *HisApiController) DeleteProject() {
  4126. id, _ := c.GetInt64("id")
  4127. adminInfo := c.GetAdminUserInfo()
  4128. project, _ := service.GetHisProjectByID(id)
  4129. // var consumable models.DialysisBeforePrepare
  4130. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4131. //耗材保存处方出库
  4132. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4133. isCharge := false
  4134. isMedicine := false
  4135. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4136. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4137. for _, item := range new_prescriptions {
  4138. if item.IsMedicine == 1 {
  4139. isMedicine = true
  4140. }
  4141. }
  4142. for _, item := range new_prescriptions {
  4143. if item.OrderStatus == 4 {
  4144. isCharge = true
  4145. }
  4146. }
  4147. if isMedicine {
  4148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4149. return
  4150. }
  4151. if isCharge {
  4152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4153. return
  4154. }
  4155. if new_prescription.ID > 0 {
  4156. if new_prescription.OrderStatus == 2 {
  4157. isCharge = true
  4158. }
  4159. }
  4160. if isCharge {
  4161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4162. return
  4163. }
  4164. service.DeletePrintInfo(id)
  4165. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4166. label.Status = 0
  4167. service.CreateHisLabelRecord(&label)
  4168. fmt.Println(goodOutConfig.IsOpen)
  4169. if goodOutConfig.IsOpen != 1 {
  4170. if stockConfig.IsOpen == 1 {
  4171. if project.Type == 2 {
  4172. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4173. fmt.Println(err)
  4174. }
  4175. if project.Type == 3 && project.IsOut == 1 {
  4176. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4177. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4178. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4179. operation_time := time.Now().Unix()
  4180. creater := adminInfo.AdminUser.Id
  4181. //创建退库单
  4182. timeStr := time.Now().Format("2006-01-02")
  4183. timeArr := strings.Split(timeStr, "-")
  4184. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4185. total = total + 1
  4186. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4187. cancelStock := models.CancelStock{
  4188. OrderNumber: orderNumber,
  4189. OperaTime: operation_time,
  4190. OrgId: adminInfo.CurrentOrgId,
  4191. Creater: creater,
  4192. Ctime: time.Now().Unix(),
  4193. Status: 1,
  4194. ReturnTime: project.RecordDate,
  4195. Type: 1,
  4196. StorehouseId: houseConfig.StorehouseOutInfo,
  4197. IsCheck: 1,
  4198. }
  4199. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4200. if msgerrkonde == gorm.ErrRecordNotFound {
  4201. service.AddSigleCancelStock(&cancelStock)
  4202. }
  4203. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4204. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4205. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4206. //查询是否有出库
  4207. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4208. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4209. deaerler, _ := service.GetDealerById(info.Dealer)
  4210. if info.ID > 0 {
  4211. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4212. if info.Count >= prescribingNumber {
  4213. cancelStockInfo := models.CancelStockInfo{
  4214. GoodId: project.ProjectId,
  4215. CancelStockId: cancel.ID,
  4216. GoodTypeId: good.GoodTypeId,
  4217. Count: prescribingNumber,
  4218. Price: info.Price,
  4219. Total: 0,
  4220. ProductDate: info.ProductDate,
  4221. ExpiryDate: info.ExpiryDate,
  4222. Ctime: time.Now().Unix(),
  4223. Status: 1,
  4224. OrgId: adminInfo.CurrentOrgId,
  4225. OrderNumber: cancel.OrderNumber,
  4226. Type: 0,
  4227. Dealer: deaerler.DealerName,
  4228. Manufacturer: manufacturer.ManufacturerName,
  4229. Number: info.Number,
  4230. RegisterAccount: "",
  4231. Remark: "",
  4232. WarehouseInfoId: info.WarehouseInfotId,
  4233. PatientId: info.PatientId,
  4234. RecordDate: info.SysRecordTime,
  4235. StorehouseId: houseConfig.StorehouseOutInfo,
  4236. IsCheck: 1,
  4237. }
  4238. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4239. //回退库存
  4240. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4241. //退库数量增加
  4242. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4243. //出库数量减少
  4244. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4245. }
  4246. if info.Count < prescribingNumber {
  4247. cancelStockInfo := models.CancelStockInfo{
  4248. GoodId: project.ProjectId,
  4249. CancelStockId: cancel.ID,
  4250. GoodTypeId: good.GoodTypeId,
  4251. Count: info.Count,
  4252. Price: info.Price,
  4253. Total: 0,
  4254. ProductDate: info.ProductDate,
  4255. ExpiryDate: info.ExpiryDate,
  4256. Ctime: time.Now().Unix(),
  4257. Status: 1,
  4258. OrgId: adminInfo.CurrentOrgId,
  4259. OrderNumber: cancel.OrderNumber,
  4260. Type: 0,
  4261. Dealer: deaerler.DealerName,
  4262. Manufacturer: manufacturer.ManufacturerName,
  4263. Number: info.Number,
  4264. RegisterAccount: "",
  4265. Remark: "",
  4266. WarehouseInfoId: info.WarehouseInfotId,
  4267. PatientId: info.PatientId,
  4268. RecordDate: info.SysRecordTime,
  4269. StorehouseId: houseConfig.StorehouseOutInfo,
  4270. IsCheck: 1,
  4271. }
  4272. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4273. //回退库存
  4274. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4275. //退库数量增加
  4276. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4277. //出库数量减少
  4278. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4279. }
  4280. //查询剩余库存
  4281. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4282. var over_count int64
  4283. for _, it := range goodList {
  4284. over_count += it.StockCount
  4285. }
  4286. //出库数据 大于 退库数量
  4287. if info.Count >= prescribingNumber {
  4288. flow := models.VmStockFlow{
  4289. WarehousingId: info.WarehouseInfotId,
  4290. GoodId: project.ProjectId,
  4291. Number: info.Number,
  4292. LicenseNumber: info.LicenseNumber,
  4293. Count: prescribingNumber,
  4294. UserOrgId: adminInfo.CurrentOrgId,
  4295. PatientId: project.PatientId,
  4296. SystemTime: info.SysRecordTime,
  4297. ConsumableType: 7,
  4298. IsSys: 0,
  4299. WarehousingOrder: "",
  4300. WarehouseOutId: info.WarehouseOutId,
  4301. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4302. IsEdit: 0,
  4303. CancelStockId: cancel.ID,
  4304. CancelOrderNumber: cancel.OrderNumber,
  4305. Manufacturer: manufacturer.ID,
  4306. Dealer: 0,
  4307. Creator: adminInfo.AdminUser.Id,
  4308. UpdateCreator: 0,
  4309. Status: 1,
  4310. Ctime: time.Now().Unix(),
  4311. Mtime: 0,
  4312. Price: info.Price,
  4313. WarehousingDetailId: info.WarehouseInfotId,
  4314. WarehouseOutDetailId: info.ID,
  4315. CancelOutDetailId: cancelInfo.ID,
  4316. ProductDate: info.ProductDate,
  4317. ExpireDate: info.ExpiryDate,
  4318. StorehouseId: houseConfig.StorehouseOutInfo,
  4319. OverCount: over_count,
  4320. }
  4321. service.CreateStockFlowOne(flow)
  4322. }
  4323. //出库数据小于退库数据
  4324. if info.Count < prescribingNumber {
  4325. flow := models.VmStockFlow{
  4326. WarehousingId: info.WarehouseInfotId,
  4327. GoodId: project.ProjectId,
  4328. Number: info.Number,
  4329. LicenseNumber: info.LicenseNumber,
  4330. Count: info.Count,
  4331. UserOrgId: adminInfo.CurrentOrgId,
  4332. PatientId: project.PatientId,
  4333. SystemTime: info.SysRecordTime,
  4334. ConsumableType: 7,
  4335. IsSys: 0,
  4336. WarehousingOrder: "",
  4337. WarehouseOutId: info.WarehouseOutId,
  4338. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4339. IsEdit: 0,
  4340. CancelStockId: cancel.ID,
  4341. CancelOrderNumber: cancel.OrderNumber,
  4342. Manufacturer: manufacturer.ID,
  4343. Dealer: 0,
  4344. Creator: adminInfo.AdminUser.Id,
  4345. UpdateCreator: 0,
  4346. Status: 1,
  4347. Ctime: time.Now().Unix(),
  4348. Mtime: 0,
  4349. Price: info.Price,
  4350. WarehousingDetailId: info.WarehouseInfotId,
  4351. WarehouseOutDetailId: info.ID,
  4352. CancelOutDetailId: cancelInfo.ID,
  4353. ProductDate: info.ProductDate,
  4354. ExpireDate: info.ExpiryDate,
  4355. StorehouseId: houseConfig.StorehouseOutInfo,
  4356. OverCount: over_count,
  4357. }
  4358. service.CreateStockFlowOne(flow)
  4359. }
  4360. //查询已出库数量
  4361. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4362. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4363. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4364. if prescribingNumber < dialysisInfo.Count {
  4365. //改变数量
  4366. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4367. }
  4368. if prescribingNumber >= dialysisInfo.Count {
  4369. //删除出库表
  4370. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4371. }
  4372. //更新剩余库存
  4373. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4374. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4375. var total_count_one int64
  4376. for _, it := range stockList {
  4377. total_count_one += it.StockCount
  4378. }
  4379. //基础库插入数据
  4380. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4381. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4382. var flush_count int64
  4383. for _, it := range goodListOne {
  4384. flush_count += it.StockCount
  4385. }
  4386. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4387. if errs != nil {
  4388. goodErrcode := models.XtGoodErrcode{
  4389. UserOrgId: project.UserOrgId,
  4390. Errcode: "手动出库更新剩余出库失败",
  4391. GoodId: project.ProjectId,
  4392. Status: 1,
  4393. Ctime: time.Now().Unix(),
  4394. Mtime: 0,
  4395. Count: 0,
  4396. StockCount: 0,
  4397. Creater: creater,
  4398. BatchNumberId: 0,
  4399. WarehouseOutId: 0,
  4400. }
  4401. service.CreateGoodErrcode(goodErrcode)
  4402. }
  4403. }
  4404. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4405. fmt.Println(err)
  4406. } else {
  4407. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4408. fmt.Println(err)
  4409. }
  4410. } else {
  4411. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4412. fmt.Println(err)
  4413. }
  4414. }
  4415. //保存处方出库
  4416. if goodOutConfig.IsOpen == 1 {
  4417. if project.Type == 3 {
  4418. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4419. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4420. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4421. operation_time := time.Now().Unix()
  4422. creater := adminInfo.AdminUser.Id
  4423. //创建退库单
  4424. timeStr := time.Now().Format("2006-01-02")
  4425. timeArr := strings.Split(timeStr, "-")
  4426. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4427. total = total + 1
  4428. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4429. cancelStock := models.CancelStock{
  4430. OrderNumber: orderNumber,
  4431. OperaTime: operation_time,
  4432. OrgId: adminInfo.CurrentOrgId,
  4433. Creater: creater,
  4434. Ctime: time.Now().Unix(),
  4435. Status: 1,
  4436. ReturnTime: project.RecordDate,
  4437. Type: 1,
  4438. StorehouseId: houseConfig.StorehouseOutInfo,
  4439. IsCheck: 1,
  4440. }
  4441. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4442. if msgerrkonde == gorm.ErrRecordNotFound {
  4443. service.AddSigleCancelStock(&cancelStock)
  4444. }
  4445. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4446. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4447. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4448. //获取出库数据
  4449. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4450. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4451. deaerler, _ := service.GetDealerById(info.Dealer)
  4452. if info.ID > 0 {
  4453. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4454. if info.Count >= prescribingNumber {
  4455. cancelStockInfo := models.CancelStockInfo{
  4456. GoodId: project.ProjectId,
  4457. CancelStockId: cancel.ID,
  4458. GoodTypeId: good.GoodTypeId,
  4459. Count: prescribingNumber,
  4460. Price: info.Price,
  4461. Total: 0,
  4462. ProductDate: info.ProductDate,
  4463. ExpiryDate: info.ExpiryDate,
  4464. Ctime: time.Now().Unix(),
  4465. Status: 1,
  4466. OrgId: adminInfo.CurrentOrgId,
  4467. OrderNumber: cancel.OrderNumber,
  4468. Type: 0,
  4469. Dealer: deaerler.DealerName,
  4470. Manufacturer: manufacturer.ManufacturerName,
  4471. Number: info.Number,
  4472. RegisterAccount: "",
  4473. Remark: "",
  4474. WarehouseInfoId: info.WarehouseInfotId,
  4475. PatientId: info.PatientId,
  4476. RecordDate: info.SysRecordTime,
  4477. StorehouseId: houseConfig.StorehouseOutInfo,
  4478. IsCheck: 1,
  4479. }
  4480. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4481. //退库数量增加
  4482. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4483. //出库数量减少
  4484. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4485. }
  4486. if info.Count < prescribingNumber {
  4487. cancelStockInfo := models.CancelStockInfo{
  4488. GoodId: project.ProjectId,
  4489. CancelStockId: cancel.ID,
  4490. GoodTypeId: good.GoodTypeId,
  4491. Count: prescribingNumber,
  4492. Price: info.Price,
  4493. Total: 0,
  4494. ProductDate: info.ProductDate,
  4495. ExpiryDate: info.ExpiryDate,
  4496. Ctime: time.Now().Unix(),
  4497. Status: 1,
  4498. OrgId: adminInfo.CurrentOrgId,
  4499. OrderNumber: cancel.OrderNumber,
  4500. Type: 0,
  4501. Dealer: deaerler.DealerName,
  4502. Manufacturer: manufacturer.ManufacturerName,
  4503. Number: info.Number,
  4504. RegisterAccount: "",
  4505. Remark: "",
  4506. WarehouseInfoId: info.WarehouseInfotId,
  4507. PatientId: info.PatientId,
  4508. RecordDate: info.SysRecordTime,
  4509. StorehouseId: houseConfig.StorehouseOutInfo,
  4510. IsCheck: 1,
  4511. }
  4512. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4513. //回退库存
  4514. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4515. }
  4516. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4517. var over_count int64
  4518. for _, it := range goodList {
  4519. over_count += it.StockCount
  4520. }
  4521. //查询出库数量
  4522. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4523. //出库数据 大于 退库数量
  4524. if len(list) > 0 {
  4525. for _, it := range list {
  4526. //回退库存
  4527. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4528. //退库数量增加
  4529. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4530. //出库数量减少
  4531. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4532. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4533. var over_count_one int64
  4534. for _, it := range goodList {
  4535. over_count_one += it.StockCount
  4536. }
  4537. //查询该批次是否有退库数据
  4538. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4539. flow := models.VmStockFlow{
  4540. WarehousingId: it.WarehouseInfotId,
  4541. GoodId: it.GoodId,
  4542. Number: it.Number,
  4543. LicenseNumber: it.LicenseNumber,
  4544. Count: it.Count,
  4545. UserOrgId: adminInfo.CurrentOrgId,
  4546. PatientId: it.PatientId,
  4547. SystemTime: it.SysRecordTime,
  4548. ConsumableType: 7,
  4549. IsSys: 0,
  4550. WarehousingOrder: "",
  4551. WarehouseOutId: it.WarehouseOutId,
  4552. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4553. IsEdit: 0,
  4554. CancelStockId: cancel.ID,
  4555. CancelOrderNumber: cancel.OrderNumber,
  4556. Manufacturer: manufacturer.ID,
  4557. Dealer: 0,
  4558. Creator: adminInfo.AdminUser.Id,
  4559. UpdateCreator: 0,
  4560. Status: 1,
  4561. Ctime: time.Now().Unix(),
  4562. Mtime: 0,
  4563. Price: it.Price,
  4564. WarehousingDetailId: it.WarehouseInfotId,
  4565. WarehouseOutDetailId: it.ID,
  4566. CancelOutDetailId: cancelInfo.ID,
  4567. ProductDate: it.ProductDate,
  4568. ExpireDate: it.ExpiryDate,
  4569. StorehouseId: houseConfig.StorehouseOutInfo,
  4570. OverCount: over_count_one,
  4571. }
  4572. service.CreateStockFlowOne(flow)
  4573. }
  4574. }
  4575. //查询已出库数量
  4576. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4577. if prescribingNumber < dialysisInfo.Count {
  4578. //改变数量
  4579. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4580. }
  4581. if prescribingNumber >= dialysisInfo.Count {
  4582. //删除出库表
  4583. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4584. }
  4585. //更新剩余库存
  4586. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4587. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4588. var total_count_one int64
  4589. for _, it := range stockList {
  4590. total_count_one += it.StockCount
  4591. }
  4592. //基础库插入数据
  4593. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4594. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4595. var flush_count int64
  4596. for _, it := range goodListOne {
  4597. flush_count += it.StockCount
  4598. }
  4599. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4600. if errs != nil {
  4601. goodErrcode := models.XtGoodErrcode{
  4602. UserOrgId: project.UserOrgId,
  4603. Errcode: "手动出库更新剩余出库失败",
  4604. GoodId: project.ProjectId,
  4605. Status: 1,
  4606. Ctime: time.Now().Unix(),
  4607. Mtime: 0,
  4608. Count: 0,
  4609. StockCount: 0,
  4610. Creater: creater,
  4611. BatchNumberId: 0,
  4612. WarehouseOutId: 0,
  4613. }
  4614. service.CreateGoodErrcode(goodErrcode)
  4615. }
  4616. }
  4617. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4618. fmt.Println(err)
  4619. } else {
  4620. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4621. fmt.Println(err)
  4622. }
  4623. }
  4624. c.ServeSuccessJSON(map[string]interface{}{
  4625. "msg": "删除成功",
  4626. })
  4627. return
  4628. }
  4629. func (c *HisApiController) CreateHisAdditionalCharge() {
  4630. his_patient_id, _ := c.GetInt64("his_patient_id")
  4631. patient_id, _ := c.GetInt64("patient_id")
  4632. record_date := c.GetString("record_date")
  4633. timeLayout := "2006-01-02"
  4634. loc, _ := time.LoadLocation("Local")
  4635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4636. if err != nil {
  4637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4638. return
  4639. }
  4640. adminInfo := c.GetAdminUserInfo()
  4641. recordDateTime := theTime.Unix()
  4642. dataBody := make(map[string]interface{}, 0)
  4643. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4644. if err != nil {
  4645. utils.ErrorLog(err.Error())
  4646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4647. return
  4648. }
  4649. var additions []*models.HisAdditionalCharge
  4650. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4651. additions, _ := dataBody["addition"].([]interface{})
  4652. if len(additions) > 0 {
  4653. for _, item := range additions {
  4654. items := item.(map[string]interface{})
  4655. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4656. utils.ErrorLog("item_id")
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4658. return
  4659. }
  4660. item_id := int64(items["item_id"].(float64))
  4661. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4662. utils.ErrorLog("item_name")
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. item_name := items["item_name"].(string)
  4667. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4668. utils.ErrorLog("price")
  4669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4670. return
  4671. }
  4672. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4673. ctime := time.Now().Unix()
  4674. additional := &models.HisAdditionalCharge{
  4675. PatientId: patient_id,
  4676. HisPatientId: his_patient_id,
  4677. UserOrgId: adminInfo.CurrentOrgId,
  4678. RecordDate: recordDateTime,
  4679. CreatedTime: ctime,
  4680. UpdatedTime: ctime,
  4681. Modifier: adminInfo.AdminUser.Id,
  4682. Creator: adminInfo.AdminUser.Id,
  4683. Price: price,
  4684. ItemName: item_name,
  4685. ItemId: item_id,
  4686. Status: 1,
  4687. }
  4688. additions = append(additions, additional)
  4689. }
  4690. }
  4691. }
  4692. for _, item := range additions {
  4693. service.CreateAddtionalCharge(item)
  4694. }
  4695. c.ServeSuccessJSON(map[string]interface{}{
  4696. "msg": "创建成功",
  4697. })
  4698. }
  4699. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4700. blood_fat := c.GetString("blood_fat")
  4701. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4702. blood_sugar := c.GetString("blood_sugar")
  4703. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4704. chief_conplaint := c.GetString("chief_conplaint")
  4705. dbp := c.GetString("dbp")
  4706. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4707. delivery_way, _ := c.GetInt64("delivery_way")
  4708. diagnostic := c.GetString("diagnostic")
  4709. family_history := c.GetString("family_history")
  4710. height := c.GetString("height")
  4711. history_of_present_illness := c.GetString("history_of_present_illness")
  4712. is_infect, _ := c.GetInt64("is_infect")
  4713. past_history := c.GetString("past_history")
  4714. patient_id, _ := c.GetInt64("patient_id")
  4715. his_patient_id, _ := c.GetInt64("his_patient_id")
  4716. personal_history := c.GetString("personal_history")
  4717. pulse := c.GetString("pulse")
  4718. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4719. sbp := c.GetString("sbp")
  4720. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4721. heightfloat, _ := strconv.ParseFloat(height, 64)
  4722. sicktype := c.GetString("sick_type")
  4723. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4724. symptom := c.GetString("symptom")
  4725. sick_date := c.GetString("sick_date")
  4726. temperatures := c.GetString("temperature")
  4727. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4728. record_date := c.GetString("record_date")
  4729. breathing := c.GetString("breathing")
  4730. doctor_advice := c.GetString("doctor_advice")
  4731. remark := c.GetString("remark")
  4732. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4733. sick, _ := c.GetInt64("sick")
  4734. diagnose, _ := c.GetInt64("diagnose")
  4735. //id, _ := c.GetInt64("id")
  4736. timeLayout := "2006-01-02"
  4737. loc, _ := time.LoadLocation("Local")
  4738. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4739. allergic_history := c.GetString("allergic_history")
  4740. if err != nil {
  4741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4742. return
  4743. }
  4744. recordDateTime := theTime.Unix()
  4745. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4746. if err != nil {
  4747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4748. return
  4749. }
  4750. sickTimes := sickTime.Unix()
  4751. ctime := time.Now().Unix()
  4752. primary_disease := c.GetString("primary_disease")
  4753. confirm_failure_date := c.GetString("confirm_failure_date")
  4754. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4755. drug_allergy_history := c.GetString("drug_allergy_history")
  4756. physical_examination := c.GetString("physical_examination")
  4757. special_inspection := c.GetString("special_inspection")
  4758. lab_apparatus := c.GetString("lab_apparatus")
  4759. caseHistory := models.HisPatientCaseHistory{
  4760. HisPatientId: his_patient_id,
  4761. PatientId: patient_id,
  4762. Temperature: temperature,
  4763. BloodSugar: bloodsugarfloat,
  4764. Pulse: pulsefloat,
  4765. Sbp: sbpfloat,
  4766. Dbp: dbpfloat,
  4767. Height: heightfloat,
  4768. BloodFat: bloodfatfloat,
  4769. SickType: sick_type,
  4770. Symptom: symptom,
  4771. SickDate: sickTimes,
  4772. IsInfect: is_infect,
  4773. HistoryOfPresentIllness: history_of_present_illness,
  4774. PastHistory: past_history,
  4775. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4776. ChiefConplaint: chief_conplaint,
  4777. PersonalHistory: personal_history,
  4778. FamilyHistory: family_history,
  4779. Diagnostic: diagnostic,
  4780. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4781. Status: 1,
  4782. Ctime: ctime,
  4783. Mtime: ctime,
  4784. RecordDate: recordDateTime,
  4785. DeliveryWay: delivery_way,
  4786. Breathing: breathingfloat,
  4787. DoctorAdvice: doctor_advice,
  4788. Remark: remark,
  4789. Sick: sick,
  4790. Diagnose: diagnose,
  4791. AllergicHistory: allergic_history,
  4792. PrimaryDisease: primary_disease,
  4793. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4794. DrugAllergyHistory: drug_allergy_history,
  4795. PhysicalExamination: physical_examination,
  4796. SpecialInspection: special_inspection,
  4797. LabApparatus: lab_apparatus,
  4798. }
  4799. //查询该患者是否有病历
  4800. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4801. if errcodes == gorm.ErrRecordNotFound {
  4802. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4803. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4804. if err != nil {
  4805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4806. return
  4807. }
  4808. c.ServeSuccessJSON(map[string]interface{}{
  4809. "caseHistory": caseHistory,
  4810. "historyInfo": historyInfo,
  4811. })
  4812. return
  4813. } else if errcodes == nil {
  4814. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4815. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4816. if err != nil {
  4817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4818. return
  4819. }
  4820. c.ServeSuccessJSON(map[string]interface{}{
  4821. "caseHistory": caseHistory,
  4822. "historyInfo": historyInfo,
  4823. })
  4824. }
  4825. //查询该患者是否有病历
  4826. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4827. //if errcode == gorm.ErrRecordNotFound {
  4828. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4829. // if err != nil {
  4830. // c.ServeSuccessJSON(map[string]interface{}{
  4831. // "msg": "保存成功",
  4832. // })
  4833. // }
  4834. //} else if errcode == nil {
  4835. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4836. // return
  4837. //}
  4838. }
  4839. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4840. patient_id, _ := c.GetInt64("patient_id", 0)
  4841. adminUser := c.GetAdminUserInfo()
  4842. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4843. c.ServeSuccessJSON(map[string]interface{}{
  4844. "list": caseHistorys,
  4845. })
  4846. }
  4847. func (c *HisApiController) GetHisPatientCaseHistory() {
  4848. record_date, _ := c.GetInt64("record_date", 0)
  4849. patient_id, _ := c.GetInt64("patient_id", 0)
  4850. admin := c.GetAdminUserInfo()
  4851. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4852. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4853. c.ServeSuccessJSON(map[string]interface{}{
  4854. "info": info,
  4855. "case_history": case_history,
  4856. })
  4857. }
  4858. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4859. template_name := c.GetString("template_name")
  4860. template_remark := c.GetString("template_remark")
  4861. doctor := c.GetAdminUserInfo().AdminUser.Id
  4862. diagnostic := c.GetString("diagnostic")
  4863. chief_conplaint := c.GetString("chief_conplain")
  4864. history_of_present_illness := c.GetString("history_of_present_illness")
  4865. past_history := c.GetString("past_history")
  4866. personal_history := c.GetString("personal_history")
  4867. family_history := c.GetString("family_history")
  4868. user_name := c.GetString("user_name")
  4869. doctor_advice := c.GetString("doctor_advice")
  4870. remark := c.GetString("remark")
  4871. //record_date := c.GetString("record_date")
  4872. //fmt.Println("record_date--------",record_date)
  4873. //timeLayout := "2006-01-02"
  4874. //loc, _ := time.LoadLocation("Local")
  4875. //
  4876. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4877. //if err != nil {
  4878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4879. // return
  4880. //}
  4881. //recordDateTime := theTime.Unix()
  4882. ctime := time.Now().Unix()
  4883. template := models.HisCaseHistoryTemplate{
  4884. HistoryOfPresentIllness: history_of_present_illness,
  4885. PastHistory: past_history,
  4886. ChiefConplaint: chief_conplaint,
  4887. PersonalHistory: personal_history,
  4888. FamilyHistory: family_history,
  4889. Diagnostic: diagnostic,
  4890. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4891. Status: 1,
  4892. Ctime: ctime,
  4893. Mtime: ctime,
  4894. RecordDate: time.Now().Unix(),
  4895. TemplateName: template_name,
  4896. TemplateRemark: template_remark,
  4897. Creator: doctor,
  4898. Modifier: doctor,
  4899. UserName: user_name,
  4900. DoctorAdvice: doctor_advice,
  4901. Remark: remark,
  4902. }
  4903. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4904. if err == nil {
  4905. c.ServeSuccessJSON(map[string]interface{}{
  4906. "msg": "保存成功",
  4907. })
  4908. } else {
  4909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4910. return
  4911. }
  4912. }
  4913. func (c *HisApiController) GetCaseHistoryTemplate() {
  4914. timeLayout := "2006-01-02"
  4915. loc, _ := time.LoadLocation("Local")
  4916. keyword := c.GetString("keyword")
  4917. start_time := c.GetString("start_time")
  4918. end_time := c.GetString("end_time")
  4919. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4920. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4921. admin := c.GetAdminUserInfo()
  4922. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4923. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4924. c.ServeSuccessJSON(map[string]interface{}{
  4925. "template": template,
  4926. //"history": history,
  4927. })
  4928. }
  4929. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4930. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4931. utils.ErrorLog("drug_name")
  4932. return enums.ErrorCodeParamWrong
  4933. }
  4934. adviceName, _ := json["drug_name"].(string)
  4935. if len(adviceName) == 0 {
  4936. utils.ErrorLog("len(advice_name) == 0")
  4937. return enums.ErrorCodeParamWrong
  4938. }
  4939. advice.AdviceName = adviceName
  4940. adviceDesc, _ := json["advice_desc"].(string)
  4941. advice.AdviceDesc = adviceDesc
  4942. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4943. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4944. advice.DrugSpec = drugSpec
  4945. }
  4946. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4947. remark, _ := json["remark"].(string)
  4948. advice.Remark = remark
  4949. }
  4950. if json["id"] == nil {
  4951. advice.DrugId = 0
  4952. } else {
  4953. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4954. drug_id := int64(json["id"].(float64))
  4955. advice.DrugId = drug_id
  4956. }
  4957. }
  4958. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4959. advice_id := int64(json["advice_id"].(float64))
  4960. advice.ID = advice_id
  4961. if advice.ID > 0 {
  4962. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4963. if err == nil {
  4964. if hisAdvice.ID > 0 {
  4965. advice.ExecutionTime = hisAdvice.ExecutionTime
  4966. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4967. advice.ExecutionState = hisAdvice.ExecutionState
  4968. advice.CheckTime = hisAdvice.CheckTime
  4969. advice.Checker = hisAdvice.Checker
  4970. advice.CheckState = hisAdvice.CheckState
  4971. advice.StartTime = hisAdvice.StartTime
  4972. advice.FeedetlSn = hisAdvice.FeedetlSn
  4973. }
  4974. }
  4975. }
  4976. }
  4977. //
  4978. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4979. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4980. // advice.ExecutionTime = execution_time
  4981. //}
  4982. //
  4983. //
  4984. //
  4985. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4986. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4987. // advice.ExecutionStaff = execution_staff
  4988. //}
  4989. //
  4990. //
  4991. //
  4992. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4993. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4994. // advice.ExecutionState = execution_state
  4995. //}
  4996. //
  4997. //
  4998. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4999. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5000. // advice.CheckTime = check_time
  5001. //}
  5002. //
  5003. //
  5004. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5005. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5006. // advice.CheckState = check_state
  5007. //}
  5008. //
  5009. //
  5010. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5011. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5012. // advice.Checker = checker
  5013. //}
  5014. //
  5015. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5016. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5017. // advice.StartTime = start_time
  5018. //}
  5019. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5020. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5021. advice.IsSelfDrug = is_self_drug
  5022. }
  5023. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5024. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5025. drug_way_count, _ := json["drug_way_count"].(string)
  5026. advice.DrugWayCount = drug_way_count
  5027. }
  5028. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5029. drugSpecUnit, _ := json["min_unit"].(string)
  5030. advice.DrugSpecUnit = drugSpecUnit
  5031. }
  5032. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5033. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5034. advice.SingleDose = singleDose
  5035. }
  5036. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5037. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5038. advice.SingleDoseUnit = singleDoseUnit
  5039. }
  5040. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5041. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5042. advice.PrescribingNumber = prescribingNumber
  5043. }
  5044. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5045. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5046. advice.PrescribingNumberUnit = prescribingNumberUnit
  5047. }
  5048. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5049. deliveryWay, _ := json["delivery_way"].(string)
  5050. advice.DeliveryWay = deliveryWay
  5051. }
  5052. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5053. executionFrequency, _ := json["execution_frequency"].(string)
  5054. advice.ExecutionFrequency = executionFrequency
  5055. }
  5056. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5057. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5058. advice.Price = price
  5059. }
  5060. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5061. med_list_codg, _ := json["medical_insurance_number"].(string)
  5062. advice.MedListCodg = med_list_codg
  5063. }
  5064. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5065. day := int64(json["day"].(float64))
  5066. advice.Day = day
  5067. }
  5068. return 0
  5069. }
  5070. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5071. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5072. id := int64(json["id"].(float64))
  5073. project.ID = id
  5074. historyProject, _ := service.GetHisProjectByID(id)
  5075. project.FeedetlSn = historyProject.FeedetlSn
  5076. }
  5077. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5078. project_id := int64(json["project_id"].(float64))
  5079. project.ProjectId = project_id
  5080. }
  5081. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5082. // price := int64(json["price"].(float64))
  5083. // formatInt_price := strconv.FormatInt(price, 10)
  5084. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5085. // project.Price = float_price
  5086. // }
  5087. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5088. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5089. project.Price = price
  5090. }
  5091. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5092. total, _ := json["total"].(string)
  5093. project.Count = total
  5094. }
  5095. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5096. medical_code, _ := json["medical_code"].(string)
  5097. project.MedListCodg = medical_code
  5098. }
  5099. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5100. single_dose, _ := json["single_dose"].(string)
  5101. project.SingleDose = single_dose
  5102. }
  5103. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5104. delivery_way, _ := json["delivery_way"].(string)
  5105. project.DeliveryWay = delivery_way
  5106. }
  5107. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5108. execution_frequency, _ := json["execution_frequency"].(string)
  5109. project.ExecutionFrequency = execution_frequency
  5110. }
  5111. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5112. remark, _ := json["remark"].(string)
  5113. project.Remark = remark
  5114. }
  5115. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5116. day, _ := json["number_days"].(string)
  5117. project.Day = day
  5118. }
  5119. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5120. unit, _ := json["unit"].(string)
  5121. project.Unit = unit
  5122. }
  5123. return 0
  5124. }
  5125. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5126. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5127. id := int64(json["id"].(float64))
  5128. historyAddtions, _ := service.GetHisAdditionByID(id)
  5129. additionalCharge.ID = id
  5130. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5131. }
  5132. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5133. item_id := int64(json["item_id"].(float64))
  5134. additionalCharge.ItemId = item_id
  5135. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5136. if config.ID > 0 {
  5137. if len(config.Code) > 0 {
  5138. additionalCharge.MedListCodg = config.Code
  5139. }
  5140. }
  5141. }
  5142. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5143. // price := int64(json["price"].(float64))
  5144. // formatInt_price := strconv.FormatInt(price, 10)
  5145. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5146. // additionalCharge.Price = float_price
  5147. // }
  5148. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5149. // price := int64(json["price"].(float64))
  5150. // formatInt_price := strconv.FormatInt(price, 10)
  5151. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5152. // additionalCharge.Price = float_price
  5153. //}
  5154. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5155. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5156. additionalCharge.Price = price
  5157. }
  5158. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5159. count, _ := json["count"].(string)
  5160. counts, _ := strconv.ParseInt(count, 10, 64)
  5161. additionalCharge.Count = counts
  5162. }
  5163. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5164. item_name, _ := json["item_name"].(string)
  5165. additionalCharge.ItemName = item_name
  5166. }
  5167. return 0
  5168. }
  5169. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5170. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5171. utils.ErrorLog("drug_name")
  5172. return enums.ErrorCodeParamWrong
  5173. }
  5174. adviceName, _ := json["drug_name"].(string)
  5175. if len(adviceName) == 0 {
  5176. utils.ErrorLog("len(advice_name) == 0")
  5177. return enums.ErrorCodeParamWrong
  5178. }
  5179. advice.AdviceName = adviceName
  5180. adviceDesc, _ := json["advice_desc"].(string)
  5181. advice.AdviceDesc = adviceDesc
  5182. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5183. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5184. advice.DrugSpec = drugSpec
  5185. }
  5186. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5187. remark, _ := json["remark"].(string)
  5188. advice.Remark = remark
  5189. }
  5190. if json["id"] == nil {
  5191. advice.DrugId = 0
  5192. } else {
  5193. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5194. drug_id := int64(json["id"].(float64))
  5195. advice.DrugId = drug_id
  5196. }
  5197. }
  5198. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5199. groupno := int64(json["groupno"].(float64))
  5200. advice.Groupno = groupno
  5201. }
  5202. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5203. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5204. advice.IsSelfDrug = is_self_drug
  5205. }
  5206. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5207. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5208. drug_way_count, _ := json["drug_way_count"].(string)
  5209. advice.DrugWayCount = drug_way_count
  5210. }
  5211. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5212. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5213. advice.HospApprFlag = hosp_appr_flag
  5214. }
  5215. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5216. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5217. advice.PrescribingNumber = prescribingNumber
  5218. }
  5219. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5220. // frequency_type := int64(json["frequency_type"].(float64))
  5221. // advice.FrequencyType = frequency_type
  5222. //}
  5223. //
  5224. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5225. // day_count := int64(json["day_count"].(float64))
  5226. // advice.DayCount = day_count
  5227. //}
  5228. //
  5229. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5230. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5231. // week_day, _ := json["week_day"].(string)
  5232. // advice.WeekDay = week_day
  5233. //}
  5234. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5235. drugSpecUnit, _ := json["min_unit"].(string)
  5236. advice.DrugSpecUnit = drugSpecUnit
  5237. }
  5238. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5239. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5240. advice.SingleDose = singleDose
  5241. }
  5242. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5243. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5244. advice.SingleDoseUnit = singleDoseUnit
  5245. }
  5246. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5247. deliveryWay, _ := json["delivery_way"].(string)
  5248. advice.DeliveryWay = deliveryWay
  5249. }
  5250. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5251. executionFrequency, _ := json["execution_frequency"].(string)
  5252. advice.ExecutionFrequency = executionFrequency
  5253. }
  5254. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5255. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5256. advice.Price = price
  5257. }
  5258. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5259. med_list_codg, _ := json["medical_insurance_number"].(string)
  5260. advice.MedListCodg = med_list_codg
  5261. }
  5262. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5263. day := int64(json["day"].(float64))
  5264. advice.Day = day
  5265. }
  5266. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5267. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5268. advice.PrescribingNumberUnit = prescribingNumberUnit
  5269. }
  5270. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5271. advice_id := int64(json["advice_id"].(float64))
  5272. advice.ID = advice_id
  5273. if advice.ID > 0 {
  5274. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5275. if err == nil {
  5276. if hisAdvice.ID > 0 {
  5277. advice.ExecutionTime = hisAdvice.ExecutionTime
  5278. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5279. advice.ExecutionState = hisAdvice.ExecutionState
  5280. advice.CheckTime = hisAdvice.CheckTime
  5281. advice.Checker = hisAdvice.Checker
  5282. advice.CheckState = hisAdvice.CheckState
  5283. advice.StartTime = hisAdvice.StartTime
  5284. advice.HospApprFlag = hisAdvice.HospApprFlag
  5285. advice.IsMedicine = hisAdvice.IsMedicine
  5286. if hisAdvice.UserOrgId == 10028 {
  5287. 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 {
  5288. advice.ExecutionTime = 0
  5289. advice.ExecutionStaff = 0
  5290. advice.ExecutionState = 2
  5291. advice.CheckTime = 0
  5292. advice.Checker = 0
  5293. advice.CheckState = 2
  5294. }
  5295. } else {
  5296. 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 {
  5297. advice.ExecutionTime = 0
  5298. advice.ExecutionStaff = 0
  5299. advice.ExecutionState = 2
  5300. advice.CheckTime = 0
  5301. advice.Checker = 0
  5302. advice.CheckState = 2
  5303. }
  5304. }
  5305. //advice.Groupno = hisAdvice.Groupno
  5306. }
  5307. }
  5308. }
  5309. }
  5310. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5311. //
  5312. //if drugStockConfig.IsOpen == 1 {
  5313. //
  5314. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5315. // if advice.ID == 0 { //医嘱不存在
  5316. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5317. // drug.Total = drug.Total - advice.PrescribingNumber
  5318. // service.UpdateBaseDrugLib(&drug)
  5319. //
  5320. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5321. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5322. // drug.Total = drug.Total - num
  5323. // service.UpdateBaseDrugLib(&drug)
  5324. // }
  5325. //
  5326. // } else if advice.ID > 0 { //医嘱存在
  5327. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5328. // var num float64
  5329. //
  5330. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5331. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5332. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5333. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5334. // drug.Total = drug.Total + num
  5335. // service.UpdateBaseDrugLib(&drug)
  5336. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5337. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5338. // drug.Total = drug.Total - num
  5339. // service.UpdateBaseDrugLib(&drug)
  5340. // }
  5341. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5342. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5343. // if num2 > advice.PrescribingNumber {
  5344. // num = num2 - advice.PrescribingNumber
  5345. // drug.Total = drug.Total + num
  5346. // service.UpdateBaseDrugLib(&drug)
  5347. // } else if num2 < advice.PrescribingNumber {
  5348. // num = advice.PrescribingNumber - num2
  5349. // drug.Total = drug.Total - num
  5350. // service.UpdateBaseDrugLib(&drug)
  5351. // }
  5352. //
  5353. // }
  5354. //
  5355. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5356. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5357. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5358. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5359. // if num1 > num2 {
  5360. // num = num1 - num2
  5361. // drug.Total = drug.Total + num
  5362. // service.UpdateBaseDrugLib(&drug)
  5363. // } else if num1 < num2 {
  5364. // num = num2 - num1
  5365. // drug.Total = drug.Total - num
  5366. // service.UpdateBaseDrugLib(&drug)
  5367. // }
  5368. //
  5369. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5370. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5371. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5372. // if hisAdvice.PrescribingNumber > num2 {
  5373. // num = hisAdvice.PrescribingNumber - num2
  5374. // drug.Total = drug.Total + num
  5375. // service.UpdateBaseDrugLib(&drug)
  5376. // } else if num2 < advice.PrescribingNumber {
  5377. // num = num2 - hisAdvice.PrescribingNumber
  5378. // drug.Total = drug.Total - num
  5379. // service.UpdateBaseDrugLib(&drug)
  5380. // }
  5381. //
  5382. // }
  5383. // }
  5384. // }
  5385. //}
  5386. //
  5387. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5388. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5389. // advice.ExecutionTime = execution_time
  5390. //}
  5391. //
  5392. //
  5393. //
  5394. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5395. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5396. // advice.ExecutionStaff = execution_staff
  5397. //}
  5398. //
  5399. //
  5400. //
  5401. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5402. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5403. // advice.ExecutionState = execution_state
  5404. //}
  5405. //
  5406. //
  5407. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5408. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5409. // advice.CheckTime = check_time
  5410. //}
  5411. //
  5412. //
  5413. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5414. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5415. // advice.CheckState = check_state
  5416. //}
  5417. //
  5418. //
  5419. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5420. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5421. // advice.Checker = checker
  5422. //}
  5423. //
  5424. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5425. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5426. // advice.StartTime = start_time
  5427. //}
  5428. return 0
  5429. }
  5430. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5431. project.ExecutionStaff = 0
  5432. project.ExecutionState = 2
  5433. project.ExecutionTime = 0
  5434. project.Checker = 0
  5435. project.CheckState = 2
  5436. project.CheckTime = 0
  5437. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5438. id := int64(json["id"].(float64))
  5439. project.ID = id
  5440. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5441. project.ExecutionStaff = temp_project.ExecutionStaff
  5442. project.ExecutionState = temp_project.ExecutionState
  5443. project.ExecutionTime = temp_project.ExecutionTime
  5444. project.Checker = temp_project.Checker
  5445. project.CheckState = temp_project.CheckState
  5446. project.CheckTime = temp_project.CheckTime
  5447. project.TeamId = temp_project.TeamId
  5448. }
  5449. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5450. types := int64(json["type"].(float64))
  5451. project.Type = types
  5452. }
  5453. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5454. project_id := int64(json["project_id"].(float64))
  5455. project.ProjectId = project_id
  5456. }
  5457. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5458. team_id := int64(json["team_id"].(float64))
  5459. project.TeamId = team_id
  5460. }
  5461. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5462. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5463. project.Price = price
  5464. }
  5465. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5466. total, _ := json["total"].(string)
  5467. //totals, _ := strconv.ParseInt(total, 10, 64)
  5468. project.Count = total
  5469. }
  5470. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5471. medical_code, _ := json["medical_code"].(string)
  5472. project.MedListCodg = medical_code
  5473. }
  5474. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5475. single_dose, _ := json["single_dose"].(string)
  5476. project.SingleDose = single_dose
  5477. }
  5478. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5479. delivery_way, _ := json["delivery_way"].(string)
  5480. project.DeliveryWay = delivery_way
  5481. }
  5482. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5483. execution_frequency, _ := json["execution_frequency"].(string)
  5484. project.ExecutionFrequency = execution_frequency
  5485. }
  5486. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5487. remark, _ := json["remark"].(string)
  5488. project.Remark = remark
  5489. }
  5490. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5491. day, _ := json["number_days"].(string)
  5492. project.Day = day
  5493. }
  5494. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5495. unit, _ := json["unit"].(string)
  5496. project.Unit = unit
  5497. }
  5498. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5499. // frequency_type := int64(json["frequency_type"].(float64))
  5500. // project.FrequencyType = frequency_type
  5501. //}
  5502. //
  5503. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5504. // day_count := int64(json["day_count"].(float64))
  5505. // project.DayCount = day_count
  5506. //}
  5507. //
  5508. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5509. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5510. // week_day, _ := json["week_day"].(string)
  5511. // project.WeekDay = week_day
  5512. //}
  5513. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5514. //
  5515. //if project.ID == 0 {
  5516. // if stockConfig.IsOpen == 1 {
  5517. // if project.Type == 3 {
  5518. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5519. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5520. // good.Total = good.Total - f_count
  5521. // service.UpdateGoodInfo(&good)
  5522. // }
  5523. // }
  5524. //
  5525. //} else {
  5526. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5527. //
  5528. // if stockConfig.IsOpen == 1 {
  5529. // if project.Type == 3 {
  5530. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5531. // if project.Count < temp_project.Count {
  5532. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5533. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5534. //
  5535. // other_count := f_count_two - f_count_one
  5536. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5537. // good.Total = good.Total + other_count_two
  5538. // service.UpdateGoodInfo(&good)
  5539. // } else if project.Count > temp_project.Count {
  5540. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5541. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5542. //
  5543. // other_count := f_count_one - f_count_two
  5544. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5545. // good.Total = good.Total - other_count_two
  5546. // service.UpdateGoodInfo(&good)
  5547. // }
  5548. //
  5549. // }
  5550. // }
  5551. //
  5552. //}
  5553. return 0
  5554. }
  5555. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5556. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5557. id := int64(json["id"].(float64))
  5558. additionalCharge.ID = id
  5559. }
  5560. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5561. item_id := int64(json["item_id"].(float64))
  5562. additionalCharge.ItemId = item_id
  5563. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5564. if config.ID > 0 {
  5565. if len(config.Code) > 0 {
  5566. additionalCharge.MedListCodg = config.Code
  5567. }
  5568. }
  5569. }
  5570. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5571. // price := int64(json["price"].(float64))
  5572. // formatInt_price := strconv.FormatInt(price, 10)
  5573. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5574. // additionalCharge.Price = float_price
  5575. // }
  5576. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5577. // price := int64(json["price"].(float64))
  5578. // formatInt_price := strconv.FormatInt(price, 10)
  5579. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5580. // additionalCharge.Price = float_price
  5581. //}
  5582. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5583. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5584. additionalCharge.Price = price
  5585. }
  5586. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5587. count, _ := json["count"].(string)
  5588. counts, _ := strconv.ParseInt(count, 10, 64)
  5589. additionalCharge.Count = counts
  5590. }
  5591. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5592. item_name, _ := json["item_name"].(string)
  5593. additionalCharge.ItemName = item_name
  5594. }
  5595. return 0
  5596. }
  5597. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5598. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5599. utils.ErrorLog("drug_name")
  5600. return enums.ErrorCodeParamWrong
  5601. }
  5602. adviceName, _ := json["drug_name"].(string)
  5603. if len(adviceName) == 0 {
  5604. utils.ErrorLog("len(advice_name) == 0")
  5605. return enums.ErrorCodeParamWrong
  5606. }
  5607. advice.AdviceName = adviceName
  5608. adviceDesc, _ := json["advice_desc"].(string)
  5609. advice.AdviceDesc = adviceDesc
  5610. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5611. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5612. advice.DrugSpec = drugSpec
  5613. }
  5614. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5615. remark, _ := json["remark"].(string)
  5616. advice.Remark = remark
  5617. }
  5618. if json["id"] == nil {
  5619. advice.DrugId = 0
  5620. } else {
  5621. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5622. drug_id := int64(json["id"].(float64))
  5623. advice.DrugId = drug_id
  5624. }
  5625. }
  5626. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5627. groupno := int64(json["groupno"].(float64))
  5628. advice.Groupno = groupno
  5629. }
  5630. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5631. drugSpecUnit, _ := json["min_unit"].(string)
  5632. advice.DrugSpecUnit = drugSpecUnit
  5633. }
  5634. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5635. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5636. advice.SingleDose = singleDose
  5637. }
  5638. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5639. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5640. advice.SingleDoseUnit = singleDoseUnit
  5641. }
  5642. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5643. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5644. advice.PrescribingNumber = prescribingNumber
  5645. }
  5646. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5647. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5648. advice.PrescribingNumberUnit = prescribingNumberUnit
  5649. }
  5650. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5651. deliveryWay, _ := json["delivery_way"].(string)
  5652. advice.DeliveryWay = deliveryWay
  5653. }
  5654. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5655. executionFrequency, _ := json["execution_frequency"].(string)
  5656. advice.ExecutionFrequency = executionFrequency
  5657. }
  5658. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5659. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5660. advice.Price = price
  5661. }
  5662. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5663. med_list_codg, _ := json["medical_insurance_number"].(string)
  5664. advice.MedListCodg = med_list_codg
  5665. }
  5666. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5667. day := int64(json["day"].(float64))
  5668. advice.Day = day
  5669. }
  5670. advice.FrequencyType = 1
  5671. return 0
  5672. }
  5673. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5674. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5675. types := int64(json["type"].(float64))
  5676. project.Type = types
  5677. }
  5678. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5679. project_id := int64(json["project_id"].(float64))
  5680. project.ProjectId = project_id
  5681. }
  5682. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5683. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5684. project.Price = price
  5685. }
  5686. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5687. total, _ := json["total"].(string)
  5688. //totals, _ := strconv.ParseInt(total, 10, 64)
  5689. project.Count = total
  5690. }
  5691. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5692. medical_code, _ := json["medical_code"].(string)
  5693. project.MedListCodg = medical_code
  5694. }
  5695. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5696. single_dose, _ := json["single_dose"].(string)
  5697. project.SingleDose = single_dose
  5698. }
  5699. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5700. delivery_way, _ := json["delivery_way"].(string)
  5701. project.DeliveryWay = delivery_way
  5702. }
  5703. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5704. execution_frequency, _ := json["execution_frequency"].(string)
  5705. project.ExecutionFrequency = execution_frequency
  5706. }
  5707. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5708. remark, _ := json["remark"].(string)
  5709. project.Remark = remark
  5710. }
  5711. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5712. day, _ := json["number_days"].(string)
  5713. project.Day = day
  5714. }
  5715. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5716. unit, _ := json["unit"].(string)
  5717. project.Unit = unit
  5718. }
  5719. project.FrequencyType = 1
  5720. return 0
  5721. }
  5722. func (c *HisApiController) GetHisOrderList() {
  5723. page, _ := c.GetInt64("page", -1)
  5724. limit, _ := c.GetInt64("limit", -1)
  5725. start_time := c.GetString("start_time")
  5726. end_time := c.GetString("end_time")
  5727. types, _ := c.GetInt64("type", 0)
  5728. keywords := c.GetString("keywords")
  5729. p_type, _ := c.GetInt64("p_type", 0)
  5730. sort_type, _ := c.GetInt64("sort_type", 0)
  5731. charge_type, _ := c.GetInt64("charge_type", 0)
  5732. sch_type, _ := c.GetInt64("sch_type", 0)
  5733. zone_type, _ := c.GetInt64("zone_type", 0)
  5734. med_type, _ := c.GetInt64("med_type", 0)
  5735. timeLayout := "2006-01-02"
  5736. loc, _ := time.LoadLocation("Local")
  5737. var startTime int64
  5738. if len(start_time) > 0 {
  5739. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5740. if err != nil {
  5741. //fmt.Println(err)
  5742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5743. return
  5744. }
  5745. startTime = theTime.Unix()
  5746. }
  5747. var endTime int64
  5748. if len(end_time) > 0 {
  5749. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5750. if err != nil {
  5751. utils.ErrorLog(err.Error())
  5752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5753. return
  5754. }
  5755. endTime = theTime.Unix()
  5756. }
  5757. adminUser := c.GetAdminUserInfo()
  5758. org_id := adminUser.CurrentOrgId
  5759. 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)
  5760. for _, item := range order {
  5761. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5762. item.DoctorName = info.Doctor
  5763. item.DepartmentName = info.XtHisDepartment.Name
  5764. }
  5765. if err == nil {
  5766. c.ServeSuccessJSON(map[string]interface{}{
  5767. "order": order,
  5768. "total": total,
  5769. })
  5770. } else {
  5771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5772. return
  5773. }
  5774. }
  5775. func (c *HisApiController) GetHisOrder() {
  5776. patient_id, _ := c.GetInt64("patient_id", 0)
  5777. number := c.GetString("number")
  5778. adminInfo := c.GetAdminUserInfo()
  5779. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5780. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5781. if err == nil {
  5782. c.ServeSuccessJSON(map[string]interface{}{
  5783. "order": order,
  5784. "prescription": prescriptions,
  5785. })
  5786. } else {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5788. return
  5789. }
  5790. }
  5791. func (c *HisApiController) GetHisPrescriptionList() {
  5792. record_date := c.GetString("record_date")
  5793. keywords := c.GetString("keywords")
  5794. page, _ := c.GetInt64("page")
  5795. limit, _ := c.GetInt64("limit")
  5796. sch_type, _ := c.GetInt64("sch_type")
  5797. timeLayout := "2006-01-02"
  5798. loc, _ := time.LoadLocation("Local")
  5799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5800. if err != nil {
  5801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5802. return
  5803. }
  5804. recordDateTime := theTime.Unix()
  5805. adminInfo := c.GetAdminUserInfo()
  5806. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5807. //adminInfo := c.GetAdminUserInfo()
  5808. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5809. //fmt.Println(prescriptionOrder)
  5810. if err == nil {
  5811. c.ServeSuccessJSON(map[string]interface{}{
  5812. "order": prescriptionOrder,
  5813. "total": total,
  5814. })
  5815. } else {
  5816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5817. return
  5818. }
  5819. }
  5820. func (c *HisApiController) GetHisPrescriptionInfo() {
  5821. id, _ := c.GetInt64("id")
  5822. adminInfo := c.GetAdminUserInfo()
  5823. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5824. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5825. if err == nil {
  5826. c.ServeSuccessJSON(map[string]interface{}{
  5827. "order": prescriptionOrder,
  5828. "prescription": prescription,
  5829. })
  5830. } else {
  5831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5832. return
  5833. }
  5834. }
  5835. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5836. adminUser := c.GetAdminUserInfo()
  5837. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5838. c.ServeSuccessJSON(map[string]interface{}{
  5839. "config": config,
  5840. })
  5841. }
  5842. type ResultTwo struct {
  5843. ErrMsg interface{} `json:"err_msg"`
  5844. InfRefmsgid string `json:"inf_refmsgid"`
  5845. Infcode int64 `json:"infcode"`
  5846. Output struct {
  5847. Baseinfo struct {
  5848. Age float64 `json:"age"`
  5849. Brdy string `json:"brdy"`
  5850. Certno string `json:"certno"`
  5851. Gend string `json:"gend"`
  5852. Naty string `json:"naty"`
  5853. PsnCertType string `json:"psn_cert_type"`
  5854. PsnName string `json:"psn_name"`
  5855. PsnNo string `json:"psn_no"`
  5856. } `json:"baseinfo"`
  5857. Idetinfo []interface{} `json:"idetinfo"`
  5858. Iinfo []struct {
  5859. Balc float64 `json:"balc"`
  5860. CvlservFlag string `json:"cvlserv_flag"`
  5861. EmpName string `json:"emp_name"`
  5862. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5863. Insutype string `json:"insutype"`
  5864. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5865. PausInsuDate interface{} `json:"paus_insu_date"`
  5866. PsnInsuDate string `json:"psn_insu_date"`
  5867. PsnInsuStas string `json:"psn_insu_stas"`
  5868. PsnType string `json:"psn_type"`
  5869. } `json:"insuinfo"`
  5870. } `json:"output"`
  5871. RefmsgTime string `json:"refmsg_time"`
  5872. RespondTime string `json:"respond_time"`
  5873. Signtype interface{} `json:"signtype"`
  5874. WarnInfo interface{} `json:"warn_info"`
  5875. }
  5876. type ResultThree struct {
  5877. Cainfo interface{} `json:"cainfo"`
  5878. ErrMsg interface{} `json:"err_msg"`
  5879. InfRefmsgid string `json:"inf_refmsgid"`
  5880. Infcode int64 `json:"infcode"`
  5881. Output struct {
  5882. Data struct {
  5883. IptOtpNo string `json:"ipt_otp_no"`
  5884. MdtrtID string `json:"mdtrt_id"`
  5885. PsnNo string `json:"psn_no"`
  5886. } `json:"data"`
  5887. } `json:"output"`
  5888. RefmsgTime string `json:"refmsg_time"`
  5889. RespondTime string `json:"respond_time"`
  5890. Signtype interface{} `json:"signtype"`
  5891. WarnMsg interface{} `json:"warn_msg"`
  5892. }
  5893. type ResultFour struct {
  5894. Cainfo string `json:"cainfo"`
  5895. ErrMsg string `json:"err_msg"`
  5896. InfRefmsgid string `json:"inf_refmsgid"`
  5897. Infcode int64 `json:"infcode"`
  5898. Output struct {
  5899. Result []struct {
  5900. BasMednFlag string `json:"bas_medn_flag"`
  5901. ChldMedcFlag string `json:"chld_medc_flag"`
  5902. ChrgitmLv string `json:"chrgitm_lv"`
  5903. Cnt float64 `json:"cnt"`
  5904. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5905. DrtReimFlag string `json:"drt_reim_flag"`
  5906. FeedetlSn string `json:"feedetl_sn"`
  5907. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5908. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5909. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5910. ListSpItemFlag string `json:"list_sp_item_flag"`
  5911. LmtUsedFlag string `json:"lmt_used_flag"`
  5912. MedChrgitmType string `json:"med_chrgitm_type"`
  5913. Memo string `json:"memo"`
  5914. OverlmtAmt float64 `json:"overlmt_amt"`
  5915. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5916. Pric float64 `json:"pric"`
  5917. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5918. SelfpayProp float64 `json:"selfpay_prop"`
  5919. } `json:"result"`
  5920. } `json:"output"`
  5921. RefmsgTime string `json:"refmsg_time"`
  5922. RespondTime string `json:"respond_time"`
  5923. Signtype string `json:"signtype"`
  5924. WarnMsg string `json:"warn_msg"`
  5925. }
  5926. type ResultFive struct {
  5927. Insutype string `json:"insutype"`
  5928. }
  5929. type ResultSix struct {
  5930. Cainfo interface{} `json:"cainfo"`
  5931. ErrMsg interface{} `json:"err_msg"`
  5932. InfRefmsgid string `json:"inf_refmsgid"`
  5933. Infcode int64 `json:"infcode"`
  5934. Output struct {
  5935. } `json:"output"`
  5936. RefmsgTime string `json:"refmsg_time"`
  5937. RespondTime string `json:"respond_time"`
  5938. Signtype interface{} `json:"signtype"`
  5939. WarnMsg interface{} `json:"warn_msg"`
  5940. }
  5941. type ResultSeven struct {
  5942. Cainfo string `json:"cainfo"`
  5943. ErrMsg string `json:"err_msg"`
  5944. InfRefmsgid string `json:"inf_refmsgid"`
  5945. Infcode int64 `json:"infcode"`
  5946. Output struct {
  5947. Setldetail []interface{} `json:"setldetail"`
  5948. Setlinfo struct {
  5949. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5950. AcctPay float64 `json:"acct_pay"`
  5951. ActPayDedc float64 `json:"act_pay_dedc"`
  5952. Age float64 `json:"age"`
  5953. Balc float64 `json:"balc"`
  5954. Brdy string `json:"brdy"`
  5955. Certno string `json:"certno"`
  5956. ClrOptins string `json:"clr_optins"`
  5957. ClrType string `json:"clr_type"`
  5958. ClrWay string `json:"clr_way"`
  5959. CvlservFlag string `json:"cvlserv_flag"`
  5960. CvlservPay float64 `json:"cvlserv_pay"`
  5961. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5962. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5963. Gend string `json:"gend"`
  5964. HifesPay float64 `json:"hifes_pay"`
  5965. HifmiPay float64 `json:"hifmi_pay"`
  5966. HifobPay float64 `json:"hifob_pay"`
  5967. HifpPay float64 `json:"hifp_pay"`
  5968. HospPartAmt float64 `json:"hosp_part_amt"`
  5969. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5970. Insutype string `json:"insutype"`
  5971. MafPay float64 `json:"maf_pay"`
  5972. MdtrtCertType string `json:"mdtrt_cert_type"`
  5973. MdtrtID string `json:"mdtrt_id"`
  5974. MedType string `json:"med_type"`
  5975. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5976. MedinsSetlID string `json:"medins_setl_id"`
  5977. Naty string `json:"naty"`
  5978. OthPay float64 `json:"oth_pay"`
  5979. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5980. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5981. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5982. PsnCashPay float64 `json:"psn_cash_pay"`
  5983. PsnCertType string `json:"psn_cert_type"`
  5984. PsnName string `json:"psn_name"`
  5985. PsnNo string `json:"psn_no"`
  5986. PsnPartAmt float64 `json:"psn_part_amt"`
  5987. PsnType string `json:"psn_type"`
  5988. SetlID string `json:"setl_id"`
  5989. SetlTime string `json:"setl_time"`
  5990. } `json:"setlinfo"`
  5991. } `json:"output"`
  5992. RefmsgTime string `json:"refmsg_time"`
  5993. RespondTime string `json:"respond_time"`
  5994. Signtype interface{} `json:"signtype"`
  5995. WarnMsg interface{} `json:"warn_msg"`
  5996. }
  5997. type ResultEight struct {
  5998. Cainfo string `json:"cainfo"`
  5999. ErrMsg string `json:"err_msg"`
  6000. InfRefmsgid string `json:"inf_refmsgid"`
  6001. Infcode int64 `json:"infcode"`
  6002. Output struct {
  6003. Stmtinfo struct {
  6004. SetlOptins string `json:"setl_optins"`
  6005. StmtRslt string `json:"stmt_rslt"`
  6006. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6007. } `json:"stmtinfo"`
  6008. } `json:"output"`
  6009. RefmsgTime string `json:"refmsg_time"`
  6010. RespondTime string `json:"respond_time"`
  6011. Signtype interface{} `json:"signtype"`
  6012. WarnMsg interface{} `json:"warn_msg"`
  6013. }
  6014. type ResultNine struct {
  6015. Cainfo string `json:"cainfo"`
  6016. ErrMsg string `json:"err_msg"`
  6017. InfRefmsgid string `json:"inf_refmsgid"`
  6018. Infcode int64 `json:"infcode"`
  6019. Output struct {
  6020. FileQuryNo string `json:"file_qury_no"`
  6021. } `json:"output"`
  6022. RefmsgTime string `json:"refmsg_time"`
  6023. RespondTime string `json:"respond_time"`
  6024. Signtype interface{} `json:"signtype"`
  6025. WarnMsg interface{} `json:"warn_msg"`
  6026. }
  6027. type ResultTen struct {
  6028. Cainfo string `json:"cainfo"`
  6029. ErrMsg string `json:"err_msg"`
  6030. InfRefmsgid string `json:"inf_refmsgid"`
  6031. Infcode int64 `json:"infcode"`
  6032. Output struct {
  6033. DldEndtime string `json:"dld_endtime"`
  6034. FileQuryNo string `json:"file_qury_no"`
  6035. Filename string `json:"filename"`
  6036. } `json:"output"`
  6037. RefmsgTime string `json:"refmsg_time"`
  6038. RespondTime string `json:"respond_time"`
  6039. Signtype interface{} `json:"signtype"`
  6040. WarnMsg interface{} `json:"warn_msg"`
  6041. }
  6042. type ResultEleven struct {
  6043. Cainfo string `json:"cainfo"`
  6044. ErrMsg string `json:"err_msg"`
  6045. InfRefmsgid string `json:"inf_refmsgid"`
  6046. Infcode int64 `json:"infcode"`
  6047. Output struct {
  6048. Setlinfo struct {
  6049. FixmedinsName string `json:"fixmedins_name"`
  6050. FixmedinsCode string `json:"fixmedins_code"`
  6051. PsnNo string `json:"psn_no"`
  6052. PsnName string `json:"psn_name"`
  6053. HifobPay float64 `json:"hifob_pay"`
  6054. Gend string `json:"gend"`
  6055. Brdy string `json:"brdy"`
  6056. PsnCertType string `json:"psn_cert_type"`
  6057. PsnType string `json:"psn_type"`
  6058. EmpName string `json:"emp_name"`
  6059. Certno string `json:"certno"`
  6060. Insutype string `json:"insutype"`
  6061. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6062. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6063. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6064. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6065. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6066. ActPayDedc float64 `json:"act_pay_dedc"`
  6067. HifpPay float64 `json:"hifp_pay"`
  6068. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6069. CvlservPay float64 `json:"cvlserv_pay"`
  6070. HifesPay float64 `json:"hifes_pay"`
  6071. HifmiPay float64 `json:"hifmi_pay"`
  6072. MafPay float64 `json:"maf_pay"`
  6073. OthPay float64 `json:"oth_pay"`
  6074. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6075. PsnPay float64 `json:"psn_pay"`
  6076. AcctPay float64 `json:"acct_pay"`
  6077. CashPayamt float64 `json:"cash_payamt"`
  6078. Balc float64 `json:"balc"`
  6079. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6080. MedinsSetlId string `json:"medins_setl_id"`
  6081. RefdSetlFlag string `json:"refd_setl_flag"`
  6082. SetlTime string `json:"setl_time"`
  6083. MedType string `json:"med_type"`
  6084. } `json:"setlinfo"`
  6085. } `json:"output"`
  6086. RefmsgTime string `json:"refmsg_time"`
  6087. RespondTime string `json:"respond_time"`
  6088. Signtype interface{} `json:"signtype"`
  6089. WarnMsg interface{} `json:"warn_msg"`
  6090. }
  6091. type Custom struct {
  6092. DetItemFeeSumamt string
  6093. Cut string
  6094. FeedetlSn string
  6095. Price string
  6096. MedListCodg string
  6097. Type int64
  6098. AdviceId int64
  6099. ProjectId int64
  6100. ItemId int64
  6101. }
  6102. // 获取个人信息----挂号-----上传就诊信息
  6103. func (c *HisApiController) GetRegisterInfo() {
  6104. id, _ := c.GetInt64("id")
  6105. record_time := c.GetString("record_time")
  6106. settlementValue, _ := c.GetInt64("settlement_value")
  6107. medical_insurance_card := c.GetString("medical_insurance_card")
  6108. name := c.GetString("name")
  6109. id_card_type, _ := c.GetInt64("id_card_type")
  6110. certificates, _ := c.GetInt64("certificates")
  6111. medical_care, _ := c.GetInt64("medical_care")
  6112. birthday := c.GetString("birthday")
  6113. age, _ := c.GetInt64("age")
  6114. id_card := c.GetString("id_card")
  6115. register_type, _ := c.GetInt64("register")
  6116. doctor, _ := c.GetInt64("doctor")
  6117. department, _ := c.GetInt64("department")
  6118. gender, _ := c.GetInt64("sex")
  6119. phone := c.GetString("phone")
  6120. registration_fee, _ := c.GetFloat("registration_fee")
  6121. medical_expenses, _ := c.GetFloat("medical_expenses")
  6122. social_type, _ := c.GetInt64("social_type")
  6123. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6124. diagnosis_ids := c.GetString("diagnosis")
  6125. sick_type, _ := c.GetInt64("sick_type")
  6126. reg_type := c.GetString("p_type")
  6127. timeLayout := "2006-01-02"
  6128. loc, _ := time.LoadLocation("Local")
  6129. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6130. birthUnix := birthdays.Unix()
  6131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6132. if err != nil {
  6133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6134. return
  6135. }
  6136. recordDateTime := theTime.Unix()
  6137. adminInfo := c.GetAdminUserInfo()
  6138. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6139. if tempPatient.ID == 0 {
  6140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6141. return
  6142. }
  6143. var patient service.Patients
  6144. if id == 0 {
  6145. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6146. } else {
  6147. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6148. }
  6149. if patient.ID == 0 {
  6150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6151. return
  6152. }
  6153. if len(patient.IdCardNo) == 0 {
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6155. return
  6156. }
  6157. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6158. if len(his) >= 1 {
  6159. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6160. if len(his) >= 1 && order.ID == 0 {
  6161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6162. return
  6163. }
  6164. }
  6165. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6166. fmt.Println(timeStr)
  6167. timeArr := strings.Split(timeStr, " ")
  6168. fmt.Println(timeArr)
  6169. timeArrTwo := strings.Split(timeArr[0], "-")
  6170. timeArrThree := strings.Split(timeArr[1], ":")
  6171. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6172. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6173. if len(lists) == 0 {
  6174. var hisPatient models.XtHisPatient
  6175. hisPatient = models.XtHisPatient{
  6176. Name: name,
  6177. Age: age,
  6178. Gender: gender,
  6179. Birthday: birthUnix,
  6180. Phone: phone,
  6181. MedicalTreatmentType: medical_care,
  6182. IdType: certificates,
  6183. IdCardNo: id_card,
  6184. BalanceAccountsType: settlementValue,
  6185. SocialType: social_type,
  6186. MedicalInsuranceNumber: medical_insurance_card,
  6187. RegisterType: register_type,
  6188. RegisterCost: registration_fee,
  6189. TreatmentCost: medical_expenses,
  6190. AdminUserId: adminInfo.AdminUser.Id,
  6191. UserOrgId: adminInfo.CurrentOrgId,
  6192. Status: 1,
  6193. RecordDate: recordDateTime,
  6194. IsReturn: 1,
  6195. PatientId: patient.ID,
  6196. Ctime: time.Now().Unix(),
  6197. Mtime: time.Now().Unix(),
  6198. Number: str,
  6199. IdCardType: id_card_type,
  6200. Departments: department,
  6201. Doctor: doctor,
  6202. PType: reg_type,
  6203. Diagnosis: diagnosis_ids,
  6204. SickType: sick_type,
  6205. }
  6206. service.CreateHisPatient(&hisPatient)
  6207. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6208. c.ServeSuccessJSON(map[string]interface{}{
  6209. "his_info": hisPatient,
  6210. })
  6211. } else {
  6212. //chrgBchno := rand.Intn(1000000) + 10000
  6213. var hisPatient models.XtHisPatient
  6214. hisPatient = models.XtHisPatient{
  6215. Name: name,
  6216. Age: age,
  6217. Gender: gender,
  6218. Birthday: birthUnix,
  6219. Phone: phone,
  6220. MedicalTreatmentType: medical_care,
  6221. IdType: certificates,
  6222. IdCardNo: id_card,
  6223. BalanceAccountsType: settlementValue,
  6224. SocialType: social_type,
  6225. MedicalInsuranceNumber: medical_insurance_card,
  6226. RegisterType: register_type,
  6227. RegisterCost: registration_fee,
  6228. TreatmentCost: medical_expenses,
  6229. AdminUserId: adminInfo.AdminUser.Id,
  6230. UserOrgId: adminInfo.CurrentOrgId,
  6231. Status: 1,
  6232. RecordDate: recordDateTime,
  6233. IsReturn: 1,
  6234. PatientId: patient.ID,
  6235. Ctime: time.Now().Unix(),
  6236. Mtime: time.Now().Unix(),
  6237. Number: str,
  6238. IdCardType: id_card_type,
  6239. Departments: department,
  6240. Doctor: doctor,
  6241. PType: reg_type,
  6242. Diagnosis: diagnosis_ids,
  6243. SickType: sick_type,
  6244. }
  6245. service.CreateHisPatient(&hisPatient)
  6246. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6247. c.ServeSuccessJSON(map[string]interface{}{
  6248. "his_info": hisPatient,
  6249. })
  6250. }
  6251. }
  6252. // 上传明细----结算
  6253. func (c *HisApiController) GetUploadInfo() {
  6254. id, _ := c.GetInt64("id")
  6255. record_time := c.GetString("record_time")
  6256. his_patient_id, _ := c.GetInt64("his_patient_id")
  6257. oth_desc := c.GetString("oth_desc")
  6258. pay_way, _ := c.GetInt64("pay_way")
  6259. pay_ways := c.GetString("pay_ways")
  6260. pay_price, _ := c.GetFloat("pay_price")
  6261. pay_card_no := c.GetString("pay_card_no")
  6262. discount_price, _ := c.GetFloat("discount_price")
  6263. preferential_price, _ := c.GetFloat("preferential_price")
  6264. reality_price, _ := c.GetFloat("reality_price")
  6265. found_price, _ := c.GetFloat("found_price")
  6266. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6267. private_price, _ := c.GetFloat("private_price")
  6268. timeLayout := "2006-01-02"
  6269. loc, _ := time.LoadLocation("Local")
  6270. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6271. fapiao_code := c.GetString("fapiao_code")
  6272. fapiao_number := c.GetString("fapiao_number")
  6273. diagnosis_id := c.GetString("diagnosis")
  6274. sick_type, _ := c.GetInt64("sick_type")
  6275. reg_type, _ := c.GetInt64("p_type")
  6276. order_id, _ := c.GetInt64("order_id")
  6277. cash_pay := c.GetString("cash_pay")
  6278. wechat_pay := c.GetString("wechat_pay")
  6279. ali_pay := c.GetString("ali_pay")
  6280. jifen_pay := c.GetString("jifen_pay")
  6281. band_card_pay := c.GetString("band_card_pay")
  6282. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6283. tmp_decimal := c.GetString("tmp_decimal")
  6284. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6285. var decimal float64 //本次使用的押金
  6286. var errmsg error
  6287. tx := service.XTWriteDB().Begin() //开了事务
  6288. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6289. defer func() {
  6290. if errmsg != nil {
  6291. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6292. tx.Rollback()
  6293. } else {
  6294. tx.Commit()
  6295. }
  6296. }()
  6297. fmt.Println("dec_way", dec_way)
  6298. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6299. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6300. return
  6301. }
  6302. if len(tmp_decimal) > 0 {
  6303. if tmp_decimal[0] == 45 {
  6304. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6305. return
  6306. }
  6307. }
  6308. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6309. fmt.Println(errs)
  6310. decimal = tt
  6311. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6312. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6314. if err != nil {
  6315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6316. return
  6317. }
  6318. recordDateTime := theTime.Unix()
  6319. adminUser := c.GetAdminUserInfo()
  6320. var prescriptions []*models.HisPrescription
  6321. var prescriptionsOne []*models.HisPrescription
  6322. var start_time int64
  6323. var end_time int64
  6324. ids_str := c.GetString("ids")
  6325. ids_arr := strings.Split(ids_str, ",")
  6326. if tempOrder.ID == 0 {
  6327. if settle_accounts_type == 1 { //日结
  6328. fmt.Println(reg_type)
  6329. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6330. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6331. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6332. } else {
  6333. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6334. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6335. }
  6336. } else { //月结
  6337. start_time_str := c.GetString("start_time")
  6338. end_time_str := c.GetString("end_time")
  6339. timeLayout := "2006-01-02"
  6340. loc, _ := time.LoadLocation("Local")
  6341. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6342. if err != nil {
  6343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6344. return
  6345. }
  6346. recordStartTime := theStartTime.Unix()
  6347. start_time = recordStartTime
  6348. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6349. if err != nil {
  6350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6351. return
  6352. }
  6353. recordEndTime := theEndTime.Unix()
  6354. end_time = recordEndTime
  6355. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6356. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6357. }
  6358. var goods []*models.DialysisBeforePrepareGoods
  6359. var newGoods []*models.NewDialysisBeforePrepareGoods
  6360. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6361. var infos []*models.HisDoctorAdviceInfo
  6362. var infoList []*models.HisDoctorAdviceInfo
  6363. var hisAdvice []*models.HisDoctorAdviceInfo
  6364. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6365. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6366. //判断库存不足
  6367. //结算出库开关
  6368. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6369. if settConfig.IsOpen == 1 {
  6370. //判断库存的地方
  6371. for _, info := range prescriptions {
  6372. if info.Type == 1 {
  6373. infos = append(infos, info.HisDoctorAdviceInfo...)
  6374. }
  6375. if info.Type == 2 {
  6376. for _, sumItem := range info.HisPrescriptionProject {
  6377. if sumItem.Type == 3 {
  6378. var good models.DialysisBeforePrepareGoods
  6379. var newGood models.NewDialysisBeforePrepareGoods
  6380. good.GoodId = sumItem.GoodInfo.ID
  6381. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6382. count, _ := strconv.Atoi(sumItem.Count)
  6383. good.Count = int64(count)
  6384. good.StorehouseId = houseConfig.StorehouseOutInfo
  6385. good.ProjectId = sumItem.ID
  6386. goods = append(goods, &good)
  6387. newGood.GoodId = sumItem.GoodInfo.ID
  6388. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6389. count2, _ := strconv.Atoi(sumItem.Count)
  6390. newGood.Count = int64(count2)
  6391. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6392. newGood.ProjectId = sumItem.ID
  6393. newGoods = append(newGoods, &newGood)
  6394. }
  6395. }
  6396. }
  6397. }
  6398. for _, info := range prescriptionsOne {
  6399. if info.Type == 1 {
  6400. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6401. }
  6402. if info.Type == 2 {
  6403. for _, sumItem := range info.HisPrescriptionProject {
  6404. if sumItem.Type == 3 {
  6405. var newGood models.NewDialysisBeforePrepareGoods
  6406. newGood.GoodId = sumItem.GoodInfo.ID
  6407. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6408. count2, _ := strconv.Atoi(sumItem.Count)
  6409. newGood.Count = int64(count2)
  6410. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6411. newGood.ProjectId = sumItem.ID
  6412. newGoodOne = append(newGoodOne, &newGood)
  6413. }
  6414. }
  6415. }
  6416. }
  6417. //判断
  6418. for _, itemOne := range infos {
  6419. for _, itemTwo := range hisAdvice {
  6420. if itemOne.DrugId == itemTwo.DrugId {
  6421. itemTwo.Child = append(itemTwo.Child, itemOne)
  6422. }
  6423. }
  6424. }
  6425. for _, itemTwo := range hisAdvice {
  6426. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6427. var sum_out_count int64
  6428. for _, itemThree := range itemTwo.Child {
  6429. var prescribing_number int64
  6430. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6431. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6432. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6433. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6434. }
  6435. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6436. prescribing_number = parseIntPrescribingNumber
  6437. }
  6438. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6439. prescribing_number = parseIntPrescribingNumber
  6440. }
  6441. sum_out_count += prescribing_number
  6442. }
  6443. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6444. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6445. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6446. if sum_out_count > drugStockOut.FlushCount {
  6447. c.ServeSuccessJSON(map[string]interface{}{
  6448. "msg": "2",
  6449. "drug": medical,
  6450. })
  6451. return
  6452. }
  6453. }
  6454. fmt.Println("newGoods99999988882os", newGoods)
  6455. for _, itemOne := range newGoods {
  6456. for _, item := range newGoodOne {
  6457. if itemOne.GoodId == item.GoodId {
  6458. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6459. }
  6460. }
  6461. }
  6462. for _, item := range newGoodOne {
  6463. var sum_out_count_one int64
  6464. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6465. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6466. sum_out_count_one += itemOne.Count
  6467. }
  6468. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6469. fmt.Println("sum_out_count_one", sum_out_count_one)
  6470. fmt.Println("list.FlushCount", list.FlushCount)
  6471. if sum_out_count_one > list.FlushCount {
  6472. c.ServeSuccessJSON(map[string]interface{}{
  6473. "msg": "3",
  6474. "good": good,
  6475. })
  6476. return
  6477. }
  6478. }
  6479. }
  6480. timestamp := time.Now().Unix()
  6481. tempTime := time.Unix(timestamp, 0)
  6482. timeFormat := tempTime.Format("20060102150405")
  6483. chrgBchno := rand.Intn(100000) + 10000
  6484. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6485. strconv.FormatInt(his.PatientId, 10)
  6486. var ids []int64
  6487. for _, item := range prescriptions {
  6488. ids = append(ids, item.ID)
  6489. }
  6490. var total float64
  6491. for _, item := range prescriptions {
  6492. fmt.Println(item)
  6493. if item.Type == 1 { //药品
  6494. for _, subItem := range item.HisDoctorAdviceInfo {
  6495. total = total + (subItem.Price * subItem.PrescribingNumber)
  6496. }
  6497. }
  6498. if item.Type == 2 { //项目
  6499. for _, subItem := range item.HisPrescriptionProject {
  6500. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6501. total = total + (subItem.Price * cnt)
  6502. }
  6503. }
  6504. for _, subItem := range item.HisAdditionalCharge {
  6505. total = total + (subItem.Price * float64(subItem.Count))
  6506. }
  6507. }
  6508. if reg_type == 1111 || reg_type == 1112 {
  6509. reg_type = 11
  6510. }
  6511. tm := time.Unix(time.Now().Unix(), 0)
  6512. allTotal := fmt.Sprintf("%.4f", total)
  6513. totals, _ := strconv.ParseFloat(allTotal, 64)
  6514. order := &models.HisOrder{
  6515. UserOrgId: adminUser.CurrentOrgId,
  6516. HisPatientId: his.ID,
  6517. PatientId: id,
  6518. SettleAccountsDate: recordDateTime,
  6519. Ctime: time.Now().Unix(),
  6520. Mtime: time.Now().Unix(),
  6521. Status: 1,
  6522. OrderStatus: 2,
  6523. MdtrtId: his.Number,
  6524. Number: chrg_bchno,
  6525. MedfeeSumamt: totals,
  6526. PayWay: pay_way,
  6527. PayWays: pay_ways,
  6528. PayPrice: pay_price,
  6529. MedType: strconv.Itoa(int(reg_type)),
  6530. PayCardNo: pay_card_no,
  6531. DiscountPrice: discount_price,
  6532. PreferentialPrice: preferential_price,
  6533. RealityPrice: reality_price,
  6534. FoundPrice: found_price,
  6535. MedicalInsurancePrice: medical_insurance_price,
  6536. PrivatePrice: private_price,
  6537. SettleEndTime: end_time,
  6538. SettleStartTime: start_time,
  6539. PsnPartAmt: totals,
  6540. PsnCashPay: totals,
  6541. SettleType: settle_accounts_type,
  6542. FaPiaoCode: fapiao_code,
  6543. FaPiaoNumber: fapiao_number,
  6544. Diagnosis: diagnosis_id,
  6545. PType: 2,
  6546. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6547. Decimal: decimal,
  6548. OthDesc: oth_desc,
  6549. CashPay: cash_pay,
  6550. WechatPay: wechat_pay,
  6551. AliPay: ali_pay,
  6552. JifenPay: jifen_pay,
  6553. BandCardPay: band_card_pay,
  6554. }
  6555. err = service.CreateOrderTX(order, tx)
  6556. if err != nil {
  6557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6558. return
  6559. }
  6560. var customs []*Custom
  6561. for _, item := range prescriptions {
  6562. if item.Type == 1 { //药品a
  6563. for _, subItem := range item.HisDoctorAdviceInfo {
  6564. cus := &Custom{
  6565. AdviceId: subItem.ID,
  6566. ProjectId: 0,
  6567. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6568. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6569. FeedetlSn: subItem.FeedetlSn,
  6570. Price: fmt.Sprintf("%.4f", subItem.Price),
  6571. MedListCodg: subItem.MedListCodg,
  6572. Type: 1,
  6573. }
  6574. customs = append(customs, cus)
  6575. }
  6576. }
  6577. if item.Type == 2 { //项目
  6578. for _, subItem := range item.HisPrescriptionProject {
  6579. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6580. cus := &Custom{
  6581. AdviceId: 0,
  6582. ProjectId: subItem.ID,
  6583. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6584. Cut: fmt.Sprintf("%.4f", cnt),
  6585. FeedetlSn: subItem.FeedetlSn,
  6586. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6587. MedListCodg: subItem.MedListCodg,
  6588. Type: 2,
  6589. }
  6590. customs = append(customs, cus)
  6591. }
  6592. }
  6593. for _, item := range item.HisAdditionalCharge {
  6594. cus := &Custom{
  6595. ItemId: item.ID,
  6596. AdviceId: 0,
  6597. ProjectId: 0,
  6598. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6599. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6600. FeedetlSn: item.FeedetlSn,
  6601. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6602. MedListCodg: item.XtHisAddtionConfig.Code,
  6603. Type: 3,
  6604. }
  6605. customs = append(customs, cus)
  6606. }
  6607. }
  6608. for _, item := range customs {
  6609. var advice_id int64 = 0
  6610. var project_id int64 = 0
  6611. var item_id int64 = 0
  6612. var types int64 = 0
  6613. if item.Type == 1 {
  6614. advice_id = item.AdviceId
  6615. project_id = 0
  6616. item_id = 0
  6617. } else if item.Type == 2 {
  6618. advice_id = 0
  6619. item_id = 0
  6620. project_id = item.ProjectId
  6621. } else if item.Type == 3 {
  6622. advice_id = 0
  6623. item_id = item.ItemId
  6624. project_id = 0
  6625. }
  6626. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6627. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6628. pric, _ := strconv.ParseFloat(item.Price, 32)
  6629. info := &models.HisOrderInfo{
  6630. OrderNumber: order.Number,
  6631. UploadDate: time.Now().Unix(),
  6632. AdviceId: advice_id,
  6633. DetItemFeeSumamt: detItemFeeSumamt,
  6634. Cnt: cut,
  6635. Pric: pric,
  6636. PatientId: id,
  6637. Status: 1,
  6638. Mtime: time.Now().Unix(),
  6639. Ctime: time.Now().Unix(),
  6640. UserOrgId: adminUser.CurrentOrgId,
  6641. HisPatientId: his.ID,
  6642. OrderId: order.ID,
  6643. ProjectId: project_id,
  6644. Type: types,
  6645. ItemId: item_id,
  6646. }
  6647. service.CreateOrderInfoTX(info, tx)
  6648. }
  6649. his.Diagnosis = diagnosis_id
  6650. his.SickType = sick_type
  6651. his.RegisterType = reg_type
  6652. his.MedicalTreatmentType = reg_type
  6653. service.UpdataHisPateintTX(&his, tx)
  6654. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6655. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6656. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6657. //判断是否使用了押金
  6658. if dec_way == "true" {
  6659. tmpstring := strconv.FormatInt(order.ID, 10)
  6660. //扣押金
  6661. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6662. order.Decimal = decimal
  6663. service.UpDateOrderTwo(order, tx)
  6664. if errmsg != nil {
  6665. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6666. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6667. return
  6668. }
  6669. }
  6670. if err == nil {
  6671. for _, info := range prescriptions {
  6672. if info.Type == 1 {
  6673. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6674. }
  6675. if info.Type == 2 {
  6676. for _, sumItem := range info.HisPrescriptionProject {
  6677. if sumItem.Type == 3 {
  6678. var good models.DialysisBeforePrepareGoods
  6679. var newGood models.NewDialysisBeforePrepareGoods
  6680. var oldGood models.OldDialysisBeforePrepareGoods
  6681. good.GoodId = sumItem.GoodInfo.ID
  6682. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6683. count, _ := strconv.Atoi(sumItem.Count)
  6684. good.Count = int64(count)
  6685. good.StorehouseId = houseConfig.StorehouseOutInfo
  6686. good.ProjectId = sumItem.ID
  6687. good.PatientId = sumItem.PatientId
  6688. goods = append(goods, &good)
  6689. newGood.GoodId = sumItem.GoodInfo.ID
  6690. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6691. count2, _ := strconv.Atoi(sumItem.Count)
  6692. newGood.Count = int64(count2)
  6693. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6694. newGood.ProjectId = sumItem.ID
  6695. newGood.PatientId = sumItem.HisPatientId
  6696. newGoods = append(newGoods, &newGood)
  6697. oldGood.GoodId = sumItem.GoodInfo.ID
  6698. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6699. count3, _ := strconv.Atoi(sumItem.Count)
  6700. oldGood.Count = int64(count3)
  6701. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6702. oldGood.ProjectId = sumItem.ID
  6703. oldGood.RecordDate = sumItem.RecordDate
  6704. oldGood.PatientId = sumItem.HisPatientId
  6705. oldGoods = append(oldGoods, &oldGood)
  6706. }
  6707. }
  6708. }
  6709. }
  6710. if settConfig.IsOpen == 1 {
  6711. for _, item := range infoList {
  6712. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6713. if medical.IsUse == 2 {
  6714. //药品出库
  6715. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6716. //查询默认仓库
  6717. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6718. //查询默认仓库剩余多少库存
  6719. var sum_count int64
  6720. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6721. for _, its := range stockInfo {
  6722. if its.MaxUnit == medical.MaxUnit {
  6723. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6724. }
  6725. sum_count += its.StockMaxNumber + its.StockMinNumber
  6726. }
  6727. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6728. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6729. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6730. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6731. }
  6732. }
  6733. orgId := c.GetAdminUserInfo().CurrentOrgId
  6734. if len(oldGoods) > 0 {
  6735. timeStr := time.Now().Format("2006-01-02")
  6736. timeArr := strings.Split(timeStr, "-")
  6737. total, _ := service.FindAllWarehouseOut(orgId)
  6738. total = total + 1
  6739. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6740. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6741. number = number + total
  6742. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6743. operation_time := time.Now().Unix()
  6744. creater := c.GetAdminUserInfo().AdminUser.Id
  6745. //查询默认出库仓库库存
  6746. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6747. recordDateStr := time.Now().Format("2006-01-02")
  6748. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6749. nowtime := recordDate.Unix()
  6750. warehouseOut := models.WarehouseOut{
  6751. WarehouseOutOrderNumber: warehousing_out_order,
  6752. OperationTime: operation_time,
  6753. OrgId: orgId,
  6754. Creater: creater,
  6755. Ctime: time.Now().Unix(),
  6756. Status: 1,
  6757. WarehouseOutTime: nowtime,
  6758. Type: 1,
  6759. StorehouseId: storeConfig.StorehouseOutInfo,
  6760. IsCheck: 1,
  6761. OrderId: order.ID,
  6762. IsSys: 5,
  6763. }
  6764. //查询是否生成出库单
  6765. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6766. if out.ID == 0 {
  6767. service.AddSigleWarehouseOut(&warehouseOut)
  6768. }
  6769. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6770. for _, item := range oldGoods {
  6771. dialyPrepareOne := models.DialysisBeforePrepare{
  6772. GoodTypeId: item.GoodTypeId,
  6773. GoodId: item.GoodId,
  6774. PatientId: his.PatientId,
  6775. RecordDate: item.RecordDate,
  6776. UserOrgId: adminUser.CurrentOrgId,
  6777. Count: item.Count,
  6778. Ctime: time.Now().Unix(),
  6779. Creater: adminUser.AdminUser.Id,
  6780. CommdityCode: item.CommdityCode,
  6781. Status: 1,
  6782. StorehouseId: houseConfig.StorehouseOutInfo,
  6783. }
  6784. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6785. //非零用
  6786. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6787. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6788. //查询剩余库存
  6789. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6790. var sum_count int64
  6791. for _, item := range goodList {
  6792. sum_count += item.StockCount
  6793. }
  6794. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6795. //耗材
  6796. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6797. }
  6798. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6799. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6800. //查询剩余库存
  6801. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6802. var sum_count int64
  6803. for _, item := range goodList {
  6804. sum_count += item.StockCount
  6805. }
  6806. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6807. //耗材
  6808. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6809. }
  6810. }
  6811. }
  6812. }
  6813. c.ServeSuccessJSON(map[string]interface{}{
  6814. "msg": "结算成功",
  6815. })
  6816. }
  6817. }
  6818. }
  6819. // 退款
  6820. func (c *HisApiController) Refund() {
  6821. order_id, _ := c.GetInt64("order_id")
  6822. order, _ := service.GetHisOrderByID(order_id)
  6823. adminUser := c.GetAdminUserInfo()
  6824. orgid := c.GetAdminUserInfo().CurrentOrgId
  6825. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6826. if err != nil {
  6827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6828. return
  6829. }
  6830. tmp := strconv.FormatInt(order.ID, 10)
  6831. //当押金不为零时产生退费记录
  6832. if order.Decimal != 0 {
  6833. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6834. if err != nil {
  6835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6836. return
  6837. }
  6838. }
  6839. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6840. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6841. var goods []*models.DialysisBeforePrepareGoods
  6842. var newGoods []*models.NewDialysisBeforePrepareGoods
  6843. var infos []*models.HisDoctorAdviceInfo
  6844. for _, info := range orders {
  6845. if info.AdviceId > 0 && info.ProjectId == 0 {
  6846. infos = append(infos, &info.HisDoctorAdviceInfo)
  6847. }
  6848. if info.ProjectId > 0 && info.AdviceId == 0 {
  6849. if info.HisPrescriptionProject.Type == 3 {
  6850. var good models.DialysisBeforePrepareGoods
  6851. var newGood models.NewDialysisBeforePrepareGoods
  6852. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6853. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6854. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6855. good.Count = int64(count)
  6856. good.StorehouseId = houseConfig.StorehouseOutInfo
  6857. good.ProjectId = info.HisPrescriptionProject.ID
  6858. good.PatientId = info.PatientId
  6859. good.OrderId = order_id
  6860. goods = append(goods, &good)
  6861. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6862. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6863. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6864. newGood.Count = int64(count2)
  6865. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6866. newGood.ProjectId = info.HisPrescriptionProject.ID
  6867. newGood.RecordDate = order.SettleAccountsDate
  6868. newGood.UserOrgId = order.UserOrgId
  6869. newGood.PatientId = info.PatientId
  6870. newGood.OrderId = order_id
  6871. newGoods = append(newGoods, &newGood)
  6872. }
  6873. }
  6874. }
  6875. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6876. if settConfig.IsOpen == 1 {
  6877. for _, item := range infos {
  6878. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6879. }
  6880. for _, item := range newGoods {
  6881. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6882. }
  6883. }
  6884. c.ServeSuccessJSON(map[string]interface{}{
  6885. "msg": "退费成功",
  6886. })
  6887. }
  6888. func (c *HisApiController) RefundNumber() {
  6889. his_patient_id, _ := c.GetInt64("id")
  6890. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6891. info.Status = 0
  6892. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6893. if count > 0 {
  6894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6895. return
  6896. }
  6897. err := service.SaveHisPatient(info)
  6898. if err == nil {
  6899. c.ServeSuccessJSON(map[string]interface{}{
  6900. "msg": "退号成功",
  6901. })
  6902. } else {
  6903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6904. return
  6905. }
  6906. }
  6907. func (this *HisApiController) AdditionalCharge() {
  6908. dataBody := make(map[string]interface{}, 0)
  6909. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6910. fmt.Println(err)
  6911. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6912. patient_id := int64(dataBody["patient_id"].(float64))
  6913. medicineData, _ := dataBody["medicineData"].([]interface{})
  6914. adminUserInfo := this.GetAdminUserInfo()
  6915. orgId := adminUserInfo.CurrentOrgId
  6916. admin_user_id := adminUserInfo.AdminUser.Id
  6917. timeStr := time.Now().Format("2006-01-02")
  6918. timeLayout := "2006-01-02 15:04:05"
  6919. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6920. timenow := timeStringToTime.Unix()
  6921. var additionalCharges []*models.HisAdditionalCharge
  6922. for _, item := range medicineData {
  6923. var randNum int
  6924. randNum = rand.Intn(10000) + 1000
  6925. timestamp := time.Now().Unix()
  6926. tempTime := time.Unix(timestamp, 0)
  6927. timeFormat := tempTime.Format("20060102150405")
  6928. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6929. items := item.(map[string]interface{})
  6930. money := items["price"].(string)
  6931. item_id_str := items["item_id"].(string)
  6932. name := items["name"].(string)
  6933. id_str := items["id"].(string)
  6934. moneys, _ := strconv.ParseInt(money, 10, 64)
  6935. monStr := strconv.FormatInt(moneys, 10)
  6936. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6937. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6938. id, _ := strconv.ParseInt(id_str, 10, 64)
  6939. additionalCharge := &models.HisAdditionalCharge{
  6940. ID: id,
  6941. HisPatientId: his_patient_id,
  6942. UserOrgId: orgId,
  6943. PatientId: patient_id,
  6944. RecordDate: timenow,
  6945. Price: monneyStr,
  6946. Status: 1,
  6947. ItemName: name,
  6948. ItemId: item_id,
  6949. AdminUserId: admin_user_id,
  6950. CreatedTime: time.Now().Unix(),
  6951. OrderStatus: 0,
  6952. PrescriptionNumber: "",
  6953. BatchNumber: "",
  6954. FeedetlSn: p_number,
  6955. }
  6956. service.CreateAdditionalCharge(additionalCharge)
  6957. additionalCharges = append(additionalCharges, additionalCharge)
  6958. }
  6959. this.ServeSuccessJSON(map[string]interface{}{
  6960. "msg": "添加成功",
  6961. "additional_charges": additionalCharges,
  6962. })
  6963. }
  6964. func (this *HisApiController) DeleteAddition() {
  6965. id, _ := this.GetInt64("id")
  6966. //TODO 需要判断是否已经结算
  6967. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6968. if err == nil {
  6969. this.ServeSuccessJSON(map[string]interface{}{
  6970. "msg": "删除成功",
  6971. })
  6972. return
  6973. } else {
  6974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6975. return
  6976. }
  6977. }
  6978. func (this *HisApiController) GetAdminUsers() {
  6979. adminUser := this.GetAdminUserInfo()
  6980. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6981. this.ServeSuccessJSON(map[string]interface{}{
  6982. "doctors": doctors,
  6983. })
  6984. }
  6985. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6986. change_type, _ := this.GetInt64("type", 0)
  6987. record_date := this.GetString("record_time")
  6988. patient_id, _ := this.GetInt64("patient_id", 0)
  6989. p_type, _ := this.GetInt64("p_type", 0)
  6990. timeLayout := "2006-01-02"
  6991. loc, _ := time.LoadLocation("Local")
  6992. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6993. record_time := theAdviceRecordTime.Unix()
  6994. adminUserInfo := this.GetAdminUserInfo()
  6995. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6996. if err == nil {
  6997. if len(prescriptions) == 0 {
  6998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6999. return
  7000. } else {
  7001. this.ServeSuccessJSON(map[string]interface{}{
  7002. "prescriptions": prescriptions,
  7003. })
  7004. return
  7005. }
  7006. } else {
  7007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7008. return
  7009. }
  7010. }
  7011. func (this *HisApiController) GetCallHisPrescription() {
  7012. patient_id, _ := this.GetInt64("patient_id", 0)
  7013. timeLayout := "2006-01-02"
  7014. loc, _ := time.LoadLocation("Local")
  7015. start_time := this.GetString("start_time")
  7016. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7017. end_time := this.GetString("end_time")
  7018. p_type, _ := this.GetInt64("p_type")
  7019. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7020. adminUserInfo := this.GetAdminUserInfo()
  7021. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7022. if err == nil {
  7023. this.ServeSuccessJSON(map[string]interface{}{
  7024. "prescriptions": prescriptions,
  7025. })
  7026. return
  7027. } else {
  7028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7029. return
  7030. }
  7031. }
  7032. func (this *HisApiController) GetHisDayPrescription() {
  7033. timeLayout := "2006-01-02"
  7034. loc, _ := time.LoadLocation("Local")
  7035. start_time := this.GetString("start_time")
  7036. patient_id, _ := this.GetInt64("patient_id", 0)
  7037. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7038. end_time := this.GetString("end_time")
  7039. p_type, _ := this.GetInt64("p_type")
  7040. order_status, _ := this.GetInt64("type")
  7041. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7042. adminUserInfo := this.GetAdminUserInfo()
  7043. var dayHisPrescription []*models.HisPrescription
  7044. var err error
  7045. if order_status == 1 || order_status == 0 {
  7046. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7047. } else if order_status == 2 {
  7048. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7049. }
  7050. var settle_total float64
  7051. for _, item := range dayHisPrescription {
  7052. if len(item.HisPrescriptionProject) > 0 {
  7053. for _, subItem := range item.HisPrescriptionProject {
  7054. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7055. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7056. settle_total = settle_total + total
  7057. }
  7058. }
  7059. if len(item.HisDoctorAdviceInfo) > 0 {
  7060. for _, subItem := range item.HisDoctorAdviceInfo {
  7061. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7062. settle_total = settle_total + total
  7063. }
  7064. }
  7065. }
  7066. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7067. if err == nil {
  7068. this.ServeSuccessJSON(map[string]interface{}{
  7069. "day_prescription": dayHisPrescription,
  7070. "settle_total": settle_total,
  7071. })
  7072. return
  7073. } else {
  7074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7075. return
  7076. }
  7077. }
  7078. func (c *HisApiController) GetHisChargePatientList() {
  7079. record_date := c.GetString("record_date")
  7080. order_status, _ := c.GetInt64("type")
  7081. sch_type, _ := c.GetInt64("sch_type")
  7082. timeLayout := "2006-01-02"
  7083. loc, _ := time.LoadLocation("Local")
  7084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7085. if err != nil {
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7087. return
  7088. }
  7089. recordDateTime := theTime.Unix()
  7090. adminInfo := c.GetAdminUserInfo()
  7091. var tempPatients []*service.NewTempPatients
  7092. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7093. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7094. if order_status != 2 {
  7095. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7096. } else {
  7097. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7098. }
  7099. } else {
  7100. if order_status != 2 {
  7101. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7102. } else {
  7103. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7104. }
  7105. }
  7106. var patients []*service.NewTempPatients
  7107. var patients_two []*service.NewTempPatients
  7108. for _, item := range tempPatients {
  7109. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7110. //过滤掉没挂号的和没开处方的
  7111. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7112. patients = append(patients, item)
  7113. }
  7114. //过滤掉没挂号的
  7115. if len(item.HisPatient) > 0 {
  7116. patients_two = append(patients_two, item)
  7117. }
  7118. } else {
  7119. if len(item.HisPrescription) > 0 {
  7120. patients = append(patients, item)
  7121. }
  7122. }
  7123. }
  7124. c.ServeSuccessJSON(map[string]interface{}{
  7125. "list": patients,
  7126. "list_two": patients_two,
  7127. })
  7128. }
  7129. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7130. record_date := c.GetString("record_date")
  7131. timeLayout := "2006-01-02"
  7132. loc, _ := time.LoadLocation("Local")
  7133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7134. if err != nil {
  7135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7136. return
  7137. }
  7138. recordDateTime := theTime.Unix()
  7139. adminUser := c.GetAdminUserInfo()
  7140. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7141. var patients []*service.Patients
  7142. for _, item := range tempPatients {
  7143. if item.HisPatient.ID == 0 {
  7144. patients = append(patients, item)
  7145. }
  7146. }
  7147. c.ServeSuccessJSON(map[string]interface{}{
  7148. "list": patients,
  7149. //"list_two": patients_two,
  7150. })
  7151. }
  7152. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7153. newArr = make([]*service.Patients, 0)
  7154. for i := 0; i < len(patient); i++ {
  7155. repeat := false
  7156. for j := i + 1; j < len(patient); j++ {
  7157. if patient[i].ID == patient[j].ID {
  7158. repeat = true
  7159. break
  7160. }
  7161. }
  7162. if !repeat {
  7163. newArr = append(newArr, patient[i])
  7164. }
  7165. }
  7166. return
  7167. }
  7168. func (c *HisApiController) GetHisChargePatientInfo() {
  7169. patient_id, _ := c.GetInt64("patient_id")
  7170. his_patient_id, _ := c.GetInt64("his_patient_id")
  7171. record_date := c.GetString("record_date")
  7172. //start_time := c.GetString("start_time")
  7173. //end_time := c.GetString("end_time")
  7174. order_status, _ := c.GetInt64("type", 0)
  7175. p_type, _ := c.GetInt64("p_type", 0)
  7176. order_id, _ := c.GetInt64("order_id", 0)
  7177. timeLayout := "2006-01-02"
  7178. loc, _ := time.LoadLocation("Local")
  7179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7180. if err != nil {
  7181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7182. return
  7183. }
  7184. recordDateTime := theTime.Unix()
  7185. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7186. //if err != nil {
  7187. //
  7188. //}
  7189. //startRecordDateTime := startTime.Unix()
  7190. //
  7191. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7192. //if err != nil {
  7193. //
  7194. //}
  7195. //endRecordDateTime := endTime.Unix()
  7196. admin := c.GetAdminUserInfo()
  7197. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7198. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7199. var prescriptions []*models.HisPrescription
  7200. //var unChargeMonthPrescriptions []*models.HisPrescription
  7201. order, _ := service.GetHisOrderByID(order_id)
  7202. if order_status == 1 || order_status == 0 {
  7203. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7204. } else if order_status == 2 {
  7205. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7206. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7207. }
  7208. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7209. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7210. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7211. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7212. //获取所有科室信息
  7213. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7214. c.ServeSuccessJSON(map[string]interface{}{
  7215. "his_info": his_patient_info,
  7216. "xt_info": xt_patient_info,
  7217. "prescription": prescriptions,
  7218. "case_history": case_history,
  7219. "info": patientPrescriptionInfo,
  7220. "last_info": lastPatientPrescriptionInfo,
  7221. "order": order,
  7222. "doctors": doctors,
  7223. "department": department,
  7224. })
  7225. return
  7226. }
  7227. func (c *HisApiController) GetAllOrderDetail() {
  7228. order_id, _ := c.GetInt64("id", 0)
  7229. order, _ := service.GetHisOrderByID(order_id)
  7230. if order.ID == 0 {
  7231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7232. return
  7233. }
  7234. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7235. org_id := c.GetAdminUserInfo().CurrentOrgId
  7236. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7237. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7238. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7239. c.ServeSuccessJSON(map[string]interface{}{
  7240. "order": order,
  7241. "order_info": order_info,
  7242. "patient": patient,
  7243. "admin_info": adminInfo,
  7244. "hospital_record": record,
  7245. })
  7246. return
  7247. }
  7248. func (c *HisApiController) GetAllOrderDetailCollect() {
  7249. order_id, _ := c.GetInt64("id", 0)
  7250. order, _ := service.GetHisOrderByID(order_id)
  7251. if order.ID == 0 {
  7252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7253. return
  7254. }
  7255. org_id := c.GetAdminUserInfo().CurrentOrgId
  7256. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7257. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7258. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7259. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7260. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7261. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7262. var bedCostTotal float64 = 0 //床位总费
  7263. //var bedCostSelfTotal float64 = 0 //床位自费
  7264. var operationCostTotal float64 = 0 //手术费
  7265. //var operationCostSelfTotal float64 = 0 //手术费
  7266. var otherCostTotal float64 = 0 //其他费用
  7267. //var otherCostSelfTotal float64 = 0 //其他费用
  7268. var materialCostTotal float64 = 0 //材料费
  7269. //var materialCostSelfTotal float64 = 0 //材料费
  7270. var westernMedicineCostTotal float64 = 0 //西药费
  7271. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7272. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7273. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7274. var checkCostTotal float64 = 0 //检查费
  7275. //var checkCostSelfTotal float64 = 0 //检查费
  7276. var laboratoryCostTotal float64 = 0 //化验费
  7277. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7278. var treatCostTotal float64 = 0 //治疗费用
  7279. //var treatCostSelfTotal float64 = 0 //治疗费用
  7280. var zhenChaCostTotal float64 = 0 //其他费用
  7281. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7282. decimal.DivisionPrecision = 2
  7283. var BalanceAccountsType int64
  7284. if his.ID > 0 {
  7285. BalanceAccountsType = his.BalanceAccountsType
  7286. } else {
  7287. BalanceAccountsType = record.BalanceAccountsType
  7288. }
  7289. if BalanceAccountsType != 2 {
  7290. for _, item := range order_info {
  7291. if org_id == 10215 {
  7292. if item.MedChrgitmType == "01" { //床位费
  7293. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7294. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7295. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7296. }
  7297. if item.MedChrgitmType == "02" { //诊察费
  7298. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7299. //zhenChaCostSelfTotal = zhenChaCostTotal
  7300. }
  7301. if item.MedChrgitmType == "03" { //检查费
  7302. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7303. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7304. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7305. }
  7306. //if item.MedChrgitmType == "02" { //检查费
  7307. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7308. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7309. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7310. //}
  7311. if item.MedChrgitmType == "04" { //化验费
  7312. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7313. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7314. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7315. }
  7316. if item.MedChrgitmType == "05" { //治疗费
  7317. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7318. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7319. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7320. }
  7321. if item.MedChrgitmType == "06" { //手术费
  7322. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7323. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7324. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7325. }
  7326. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7327. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7328. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7329. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7330. }
  7331. if item.MedChrgitmType == "09" { //西药费
  7332. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7333. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7334. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7335. }
  7336. if item.MedChrgitmType == "11" { //中成费
  7337. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7338. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7339. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7340. }
  7341. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7342. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7343. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7344. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7345. }
  7346. } else if org_id == 10188 || org_id == 10217 {
  7347. if item.MedChrgitmType == "01" { //床位费
  7348. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7349. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7350. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7351. }
  7352. if item.MedChrgitmType == "02" { //诊察费
  7353. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7354. //zhenChaCostSelfTotal = zhenChaCostTotal
  7355. }
  7356. if item.MedChrgitmType == "03" { //检查费
  7357. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7358. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7359. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7360. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7361. }
  7362. //if item.MedChrgitmType == "02" { //检查费
  7363. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7364. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7365. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7366. //}
  7367. if item.MedChrgitmType == "04" { //化验费
  7368. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7369. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7370. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7371. }
  7372. if item.MedChrgitmType == "05" { //治疗费
  7373. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7374. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7375. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7376. }
  7377. if item.MedChrgitmType == "06" { //手术费
  7378. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7379. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7380. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7381. }
  7382. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7383. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7384. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7385. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7386. }
  7387. if item.MedChrgitmType == "09" { //西药费
  7388. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7389. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7390. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7391. }
  7392. if item.MedChrgitmType == "11" { //中成费
  7393. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7394. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7395. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7396. }
  7397. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7398. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7399. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7400. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7401. }
  7402. } else {
  7403. if item.MedChrgitmType == "01" { //床位费
  7404. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7405. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7406. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7407. }
  7408. //if item.MedChrgitmType == "02" { //诊察费
  7409. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7411. //}
  7412. if item.MedChrgitmType == "03" { //检查费
  7413. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7414. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7415. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7416. }
  7417. //if item.MedChrgitmType == "02" { //检查费
  7418. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7419. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7420. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7421. //}
  7422. if item.MedChrgitmType == "04" { //化验费
  7423. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7424. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7425. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7426. }
  7427. if item.MedChrgitmType == "05" { //治疗费
  7428. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7429. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7430. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7431. }
  7432. if item.MedChrgitmType == "06" { //手术费
  7433. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7434. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7435. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7436. }
  7437. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7438. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7439. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7440. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7441. }
  7442. if item.MedChrgitmType == "09" { //西药费
  7443. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7444. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7445. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7446. }
  7447. if item.MedChrgitmType == "11" { //中成费
  7448. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7449. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7450. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7451. }
  7452. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7453. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7454. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7455. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7456. }
  7457. }
  7458. }
  7459. c.ServeSuccessJSON(map[string]interface{}{
  7460. "order": order,
  7461. "order_info": order_info,
  7462. "patient": patient,
  7463. "admin_info": adminInfo,
  7464. "his_hospital": record,
  7465. "bedCostTotal": bedCostTotal,
  7466. "operationCostTotal": operationCostTotal,
  7467. "otherCostTotal": otherCostTotal,
  7468. "materialCostTotal": materialCostTotal,
  7469. "westernMedicineCostTotal": westernMedicineCostTotal,
  7470. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7471. "checkCostTotal": checkCostTotal,
  7472. "zhenChaCostTotal": zhenChaCostTotal,
  7473. "laboratoryCostTotal": laboratoryCostTotal,
  7474. "treatCostTotal": treatCostTotal,
  7475. })
  7476. } else {
  7477. for _, item := range order_info {
  7478. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7479. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7480. item.MedChrgitmType = "09"
  7481. }
  7482. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7483. if item.HisPrescriptionProject.Type == 2 {
  7484. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7485. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7486. case 0:
  7487. item.MedChrgitmType = "0"
  7488. break
  7489. case 1:
  7490. item.MedChrgitmType = "14"
  7491. break
  7492. case 2:
  7493. item.MedChrgitmType = "05"
  7494. break
  7495. case 3:
  7496. item.MedChrgitmType = "03"
  7497. break
  7498. case 4:
  7499. item.MedChrgitmType = "03"
  7500. break
  7501. case 5:
  7502. item.MedChrgitmType = "08"
  7503. break
  7504. case 6:
  7505. item.MedChrgitmType = "14"
  7506. break
  7507. case 7:
  7508. item.MedChrgitmType = "14"
  7509. break
  7510. case 8:
  7511. item.MedChrgitmType = "03"
  7512. break
  7513. case 9:
  7514. item.MedChrgitmType = "14"
  7515. break
  7516. case 10:
  7517. item.MedChrgitmType = "14"
  7518. break
  7519. case 11:
  7520. item.MedChrgitmType = "06"
  7521. break
  7522. case 12:
  7523. item.MedChrgitmType = "12"
  7524. break
  7525. case 13:
  7526. item.MedChrgitmType = "01"
  7527. break
  7528. case 14:
  7529. item.MedChrgitmType = "04"
  7530. break
  7531. case 15:
  7532. item.MedChrgitmType = "14"
  7533. break
  7534. }
  7535. } else {
  7536. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7537. case 1:
  7538. item.MedChrgitmType = "14"
  7539. break
  7540. case 2:
  7541. item.MedChrgitmType = "05"
  7542. break
  7543. case 3:
  7544. item.MedChrgitmType = "04"
  7545. break
  7546. case 4:
  7547. item.MedChrgitmType = "14"
  7548. break
  7549. case 5:
  7550. item.MedChrgitmType = "08"
  7551. break
  7552. case 6:
  7553. item.MedChrgitmType = "14"
  7554. break
  7555. case 7:
  7556. item.MedChrgitmType = "14"
  7557. break
  7558. case 8:
  7559. item.MedChrgitmType = "03"
  7560. break
  7561. case 9:
  7562. item.MedChrgitmType = "14"
  7563. break
  7564. }
  7565. }
  7566. } else if item.HisPrescriptionProject.Type == 3 {
  7567. item.MedChrgitmType = "08"
  7568. }
  7569. }
  7570. }
  7571. for _, item := range order_info {
  7572. if org_id == 10215 {
  7573. if item.MedChrgitmType == "01" { //床位费
  7574. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7575. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7576. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7577. }
  7578. if item.MedChrgitmType == "02" { //诊察费
  7579. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7580. //zhenChaCostSelfTotal = zhenChaCostTotal
  7581. }
  7582. if item.MedChrgitmType == "03" { //检查费
  7583. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7584. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7585. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7586. }
  7587. //if item.MedChrgitmType == "02" { //检查费
  7588. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7589. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7590. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7591. //}
  7592. if item.MedChrgitmType == "04" { //化验费
  7593. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7594. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7595. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7596. }
  7597. if item.MedChrgitmType == "05" { //治疗费
  7598. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7599. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7600. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7601. }
  7602. if item.MedChrgitmType == "06" { //手术费
  7603. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7604. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7605. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7606. }
  7607. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7608. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7609. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7610. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7611. }
  7612. if item.MedChrgitmType == "09" { //西药费
  7613. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7614. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7615. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7616. }
  7617. if item.MedChrgitmType == "11" { //中成费
  7618. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7619. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7620. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7621. }
  7622. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7623. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7624. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7625. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7626. }
  7627. } else {
  7628. if item.MedChrgitmType == "01" { //床位费
  7629. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7630. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7631. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7632. }
  7633. //if item.MedChrgitmType == "02" { //诊察费
  7634. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7635. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7636. //}
  7637. if item.MedChrgitmType == "03" { //检查费
  7638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7639. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7640. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7641. }
  7642. //if item.MedChrgitmType == "02" { //检查费
  7643. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7644. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7645. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7646. //}
  7647. if item.MedChrgitmType == "04" { //化验费
  7648. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7649. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7650. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7651. }
  7652. if item.MedChrgitmType == "05" { //治疗费
  7653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7654. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7655. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7656. }
  7657. if item.MedChrgitmType == "06" { //手术费
  7658. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7659. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7660. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7661. }
  7662. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7663. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7664. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7665. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7666. }
  7667. if item.MedChrgitmType == "09" { //西药费
  7668. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7669. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7670. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7671. }
  7672. if item.MedChrgitmType == "11" { //中成费
  7673. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7674. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7675. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7676. }
  7677. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7678. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7679. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7680. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7681. }
  7682. }
  7683. }
  7684. c.ServeSuccessJSON(map[string]interface{}{
  7685. "order": order,
  7686. "order_info": order_info,
  7687. "patient": patient,
  7688. "admin_info": adminInfo,
  7689. "his_hospital": record,
  7690. "bedCostTotal": bedCostTotal,
  7691. "operationCostTotal": operationCostTotal,
  7692. "otherCostTotal": otherCostTotal,
  7693. "materialCostTotal": materialCostTotal,
  7694. "westernMedicineCostTotal": westernMedicineCostTotal,
  7695. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7696. "checkCostTotal": checkCostTotal,
  7697. "zhenChaCostTotal": zhenChaCostTotal,
  7698. "laboratoryCostTotal": laboratoryCostTotal,
  7699. "treatCostTotal": treatCostTotal,
  7700. })
  7701. }
  7702. }
  7703. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7704. page, _ := c.GetInt64("page")
  7705. limit, _ := c.GetInt64("limit")
  7706. keywords := c.GetString("keywords")
  7707. start_time := c.GetString("start_time")
  7708. end_time := c.GetString("end_time")
  7709. //clr_type := c.GetString("clr_type")
  7710. insutype := c.GetString("insutype")
  7711. timeLayout := "2006-01-02"
  7712. loc, _ := time.LoadLocation("Local")
  7713. var theStartTIme int64
  7714. if len(start_time) > 0 {
  7715. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7716. theStartTIme = theTime.Unix()
  7717. }
  7718. var theEndtTIme int64
  7719. if len(end_time) > 0 {
  7720. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7721. theEndtTIme = theTime.Unix()
  7722. }
  7723. if page <= 0 {
  7724. page = 1
  7725. }
  7726. if limit <= 0 {
  7727. limit = 10
  7728. }
  7729. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7730. c.ServeSuccessJSON(map[string]interface{}{
  7731. "total": total,
  7732. "list": list,
  7733. })
  7734. return
  7735. }
  7736. func (c *HisApiController) GetPutOnRecordList() {
  7737. page, _ := c.GetInt64("page")
  7738. limit, _ := c.GetInt64("limit")
  7739. keywords := c.GetString("keywords")
  7740. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7741. if page <= 0 {
  7742. page = 1
  7743. }
  7744. if limit <= 0 {
  7745. limit = 10
  7746. }
  7747. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7748. c.ServeSuccessJSON(map[string]interface{}{
  7749. "total": total,
  7750. "list": list,
  7751. })
  7752. return
  7753. }
  7754. func (c *HisApiController) GetCompareData() {
  7755. start_time := c.GetString("start_time")
  7756. end_time := c.GetString("end_time")
  7757. insutype := c.GetString("insutype")
  7758. clr_type := c.GetString("clr_type")
  7759. timeLayout := "2006-01-02"
  7760. loc, _ := time.LoadLocation("Local")
  7761. var theStartTIme int64
  7762. if len(start_time) > 0 {
  7763. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7764. if err != nil {
  7765. theStartTIme = 0
  7766. }
  7767. theStartTIme = theTime.Unix()
  7768. }
  7769. var theEndtTIme int64
  7770. if len(end_time) > 0 {
  7771. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7772. if err != nil {
  7773. theEndtTIme = 0
  7774. }
  7775. theEndtTIme = theTime.Unix()
  7776. }
  7777. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7778. fmt.Println(err)
  7779. if err == nil {
  7780. c.ServeSuccessJSON(map[string]interface{}{
  7781. "list": formData,
  7782. })
  7783. } else {
  7784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7785. return
  7786. }
  7787. }
  7788. func (c *HisApiController) GetFaPiaoData() {
  7789. order_id, _ := c.GetInt64("order_id")
  7790. patient_id, _ := c.GetInt64("patient_id")
  7791. //number := c.GetString("number")
  7792. adminUser := c.GetAdminUserInfo()
  7793. order, _ := service.GetHisOrderByID(order_id)
  7794. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7795. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7796. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7797. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7798. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7799. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7800. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7801. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7802. var bedCostTotal float64 = 0 //床位总费
  7803. var bedCostSelfTotal float64 = 0 //床位自费
  7804. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7805. var operationCostTotal float64 = 0 //手术费
  7806. var operationCostSelfTotal float64 = 0 //手术费
  7807. var operationCostPartSelfTotal float64 = 0 //手术费
  7808. var otherCostTotal float64 = 0 //其他费用
  7809. var otherCostSelfTotal float64 = 0 //其他费用
  7810. var otherCostPartSelfTotal float64 = 0 //其他费用
  7811. var materialCostTotal float64 = 0 //材料费
  7812. var materialCostSelfTotal float64 = 0 //材料费
  7813. var materialCostPartSelfTotal float64 = 0 //材料费
  7814. var westernMedicineCostTotal float64 = 0 //西药费
  7815. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7816. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7817. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7818. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7819. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7820. var checkCostTotal float64 = 0 //检查费
  7821. var checkCostSelfTotal float64 = 0 //检查费
  7822. var checkCostPartSelfTotal float64 = 0 //检查费
  7823. var hiliCostTotal float64 = 0 //护理费
  7824. var hiliCostSelfTotal float64 = 0 //护理费
  7825. var hiliCostPartSelfTotal float64 = 0 //护理费
  7826. var laboratoryCostTotal float64 = 0 //化验费
  7827. var laboratoryCostSelfTotal float64 = 0 //化验费
  7828. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7829. var treatCostTotal float64 = 0 //治疗费用
  7830. var treatCostSelfTotal float64 = 0 //治疗费用
  7831. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7832. var zhenChaCostTotal float64 = 0 //其他费用
  7833. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7834. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7835. decimal.DivisionPrecision = 2
  7836. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7837. var balanceAccountsType int64
  7838. if his.ID > 0 {
  7839. balanceAccountsType = his.BalanceAccountsType
  7840. } else {
  7841. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7842. }
  7843. if balanceAccountsType == 2 {
  7844. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7845. for _, item := range orderInfos_two {
  7846. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7847. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7848. item.MedChrgitmType = "09"
  7849. }
  7850. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7851. if item.HisPrescriptionProject.Type == 2 {
  7852. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7853. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7854. case 0:
  7855. item.MedChrgitmType = "0"
  7856. break
  7857. case 1:
  7858. item.MedChrgitmType = "14"
  7859. break
  7860. case 2:
  7861. item.MedChrgitmType = "05"
  7862. break
  7863. case 3:
  7864. item.MedChrgitmType = "03"
  7865. break
  7866. case 4:
  7867. item.MedChrgitmType = "03"
  7868. break
  7869. case 5:
  7870. item.MedChrgitmType = "08"
  7871. break
  7872. case 6:
  7873. item.MedChrgitmType = "14"
  7874. break
  7875. case 7:
  7876. item.MedChrgitmType = "14"
  7877. break
  7878. case 8:
  7879. item.MedChrgitmType = "03"
  7880. break
  7881. case 9:
  7882. item.MedChrgitmType = "14"
  7883. break
  7884. case 10:
  7885. item.MedChrgitmType = "14"
  7886. break
  7887. case 11:
  7888. item.MedChrgitmType = "06"
  7889. break
  7890. case 12:
  7891. item.MedChrgitmType = "12"
  7892. break
  7893. case 13:
  7894. item.MedChrgitmType = "01"
  7895. break
  7896. case 14:
  7897. item.MedChrgitmType = "04"
  7898. break
  7899. case 15:
  7900. item.MedChrgitmType = "02"
  7901. break
  7902. }
  7903. } else {
  7904. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7905. case 1:
  7906. item.MedChrgitmType = "14"
  7907. break
  7908. case 2:
  7909. item.MedChrgitmType = "05"
  7910. break
  7911. case 3:
  7912. item.MedChrgitmType = "03"
  7913. break
  7914. case 4:
  7915. item.MedChrgitmType = "03"
  7916. break
  7917. case 5:
  7918. item.MedChrgitmType = "08"
  7919. break
  7920. case 6:
  7921. item.MedChrgitmType = "14"
  7922. break
  7923. case 7:
  7924. item.MedChrgitmType = "14"
  7925. break
  7926. case 8:
  7927. item.MedChrgitmType = "03"
  7928. break
  7929. case 9:
  7930. item.MedChrgitmType = "14"
  7931. break
  7932. }
  7933. }
  7934. } else if item.HisPrescriptionProject.Type == 3 {
  7935. item.MedChrgitmType = "08"
  7936. }
  7937. }
  7938. }
  7939. for _, item := range orderInfos_two {
  7940. fmt.Println(item.MedChrgitmType)
  7941. if item.MedChrgitmType == "07" { //床位费
  7942. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7943. hiliCostSelfTotal = hiliCostTotal
  7944. }
  7945. if item.MedChrgitmType == "01" { //床位费
  7946. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7947. bedCostSelfTotal = bedCostTotal
  7948. }
  7949. if item.MedChrgitmType == "02" { //诊察费
  7950. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7951. zhenChaCostSelfTotal = zhenChaCostTotal
  7952. }
  7953. if item.MedChrgitmType == "03" { //检查费
  7954. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7955. checkCostSelfTotal = checkCostTotal
  7956. }
  7957. if item.MedChrgitmType == "04" { //化验费
  7958. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7959. laboratoryCostSelfTotal = laboratoryCostTotal
  7960. }
  7961. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7962. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7963. treatCostSelfTotal = treatCostTotal
  7964. }
  7965. if item.MedChrgitmType == "06" { //手术费
  7966. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7967. operationCostSelfTotal = treatCostTotal
  7968. }
  7969. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7970. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7971. materialCostSelfTotal = materialCostTotal
  7972. }
  7973. if item.MedChrgitmType == "09" { //西药费
  7974. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7975. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7976. }
  7977. if item.MedChrgitmType == "11" { //中成费
  7978. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7979. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7980. }
  7981. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7982. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7983. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7984. otherCostSelfTotal = otherCostTotal
  7985. }
  7986. } else {
  7987. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7988. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7989. otherCostSelfTotal = otherCostTotal
  7990. }
  7991. }
  7992. }
  7993. } else {
  7994. for _, item := range orderInfos {
  7995. if item.MedChrgitmType == "01" { //床位费
  7996. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7997. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7998. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7999. }
  8000. if item.MedChrgitmType == "02" { //诊察费
  8001. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8002. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8003. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8004. }
  8005. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8006. if item.MedChrgitmType == "03" { //检查费
  8007. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8008. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8009. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8010. }
  8011. } else {
  8012. if item.MedChrgitmType == "03" { //检查费
  8013. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8014. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8015. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8016. }
  8017. }
  8018. if item.MedChrgitmType == "04" { //化验费
  8019. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8020. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8021. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8022. }
  8023. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8024. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8025. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8026. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8027. }
  8028. if item.MedChrgitmType == "06" { //手术费
  8029. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8030. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8031. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8032. }
  8033. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8034. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8035. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8036. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8037. }
  8038. if item.MedChrgitmType == "07" { //西药费
  8039. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8040. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8041. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8042. }
  8043. if item.MedChrgitmType == "09" { //西药费
  8044. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8045. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8046. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8047. }
  8048. if item.MedChrgitmType == "11" { //中成费
  8049. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8050. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8051. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8052. }
  8053. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8054. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8055. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8056. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8057. }
  8058. }
  8059. }
  8060. timeLayout := "2006-01-02"
  8061. loc, _ := time.LoadLocation("Local")
  8062. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8063. if err != nil {
  8064. }
  8065. startRecordDateTime := startTime.Unix()
  8066. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8067. if err != nil {
  8068. }
  8069. endRecordDateTime := endTime.Unix()
  8070. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8071. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8072. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8073. c.ServeSuccessJSON(map[string]interface{}{
  8074. "order_number": order.Number, //业务流水号
  8075. "id_card_no": his.IdCardNo, //社会保障号
  8076. "patient": patient,
  8077. "department_name": department.Name, //科室
  8078. "number": his.Number, //门诊号
  8079. "date": order.SettleAccountsDate, //结算日期
  8080. "name": order.PsnName, //姓名
  8081. "gender": patient.Gender, //性别
  8082. "psn_cash_money": order.PsnCashPay, //个人支付
  8083. "pay_way": "门诊", //结算方式
  8084. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8085. "admin_user_name": admin.UserName, //收款员
  8086. "order": order,
  8087. "order_info": orderInfos_two,
  8088. "his": his,
  8089. "bedCostTotal": bedCostTotal,
  8090. "bedCostSelfTotal": bedCostSelfTotal,
  8091. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8092. "operationCostTotal": operationCostTotal,
  8093. "operationCostSelfTotal": operationCostSelfTotal,
  8094. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8095. "otherCostTotal": otherCostTotal,
  8096. "otherCostSelfTotal": otherCostSelfTotal,
  8097. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8098. "materialCostTotal": materialCostTotal,
  8099. "materialCostSelfTotal": materialCostSelfTotal,
  8100. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8101. "westernMedicineCostTotal": westernMedicineCostTotal,
  8102. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8103. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8104. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8105. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8106. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8107. "checkCostTotal": checkCostTotal,
  8108. "checkCostSelfTotal": checkCostSelfTotal,
  8109. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8110. "laboratoryCostTotal": laboratoryCostTotal,
  8111. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8112. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8113. "treatCostTotal": treatCostTotal,
  8114. "treatCostSelfTotal": treatCostSelfTotal,
  8115. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8116. "zhenChaCostTotal": zhenChaCostTotal,
  8117. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8118. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8119. "his_hospital_record": his_hospital_record,
  8120. "pre_pay_money": pre_pay_money,
  8121. "refund_sum": sum,
  8122. "doctor_info": doctor_info,
  8123. "hiliCostTotal": hiliCostTotal,
  8124. "hiliCostSelfTotal": hiliCostSelfTotal,
  8125. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8126. })
  8127. }
  8128. //func (c *HisApiController) GetFaPiaoDatas() {
  8129. // order_ids := c.GetString("order_ids")
  8130. // patient_id, _ := c.GetInt64("patient_id")
  8131. // adminUser := c.GetAdminUserInfo()
  8132. //
  8133. // orders := strings.Split(order_ids, ",")
  8134. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8135. //
  8136. // for _, item := range orders {
  8137. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8138. // order, _ := service.GetHisOrderByID(order_id)
  8139. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8140. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8141. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8142. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8143. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8144. //
  8145. // }
  8146. //
  8147. // var bedCostTotal float64 = 0 //床位总费
  8148. // var bedCostSelfTotal float64 = 0 //床位自费
  8149. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8150. //
  8151. // var operationCostTotal float64 = 0 //手术费
  8152. // var operationCostSelfTotal float64 = 0 //手术费
  8153. // var operationCostPartSelfTotal float64 = 0 //手术费
  8154. //
  8155. // var otherCostTotal float64 = 0 //其他费用
  8156. // var otherCostSelfTotal float64 = 0 //其他费用
  8157. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8158. //
  8159. // var materialCostTotal float64 = 0 //材料费
  8160. // var materialCostSelfTotal float64 = 0 //材料费
  8161. // var materialCostPartSelfTotal float64 = 0 //材料费
  8162. //
  8163. // var westernMedicineCostTotal float64 = 0 //西药费
  8164. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8165. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8166. //
  8167. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8168. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8169. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8170. //
  8171. // var checkCostTotal float64 = 0 //检查费
  8172. // var checkCostSelfTotal float64 = 0 //检查费
  8173. // var checkCostPartSelfTotal float64 = 0 //检查费
  8174. //
  8175. // var laboratoryCostTotal float64 = 0 //化验费
  8176. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8177. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8178. //
  8179. // var treatCostTotal float64 = 0 //治疗费用
  8180. // var treatCostSelfTotal float64 = 0 //治疗费用
  8181. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8182. //
  8183. // var zhenChaCostTotal float64 = 0 //其他费用
  8184. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8185. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8186. //
  8187. // decimal.DivisionPrecision = 2
  8188. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8189. //
  8190. // var balanceAccountsType int64
  8191. // if his.ID > 0 {
  8192. // balanceAccountsType = his.BalanceAccountsType
  8193. // } else {
  8194. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8195. // }
  8196. // if balanceAccountsType == 2 {
  8197. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8198. // for _, item := range orderInfos_two {
  8199. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8200. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8201. // item.MedChrgitmType = "09"
  8202. // }
  8203. //
  8204. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8205. // if item.HisPrescriptionProject.Type == 2 {
  8206. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8207. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8208. // case 0:
  8209. // item.MedChrgitmType = "0"
  8210. // break
  8211. // case 1:
  8212. // item.MedChrgitmType = "14"
  8213. // break
  8214. // case 2:
  8215. // item.MedChrgitmType = "05"
  8216. //
  8217. // break
  8218. // case 3:
  8219. // item.MedChrgitmType = "03"
  8220. //
  8221. // break
  8222. // case 4:
  8223. // item.MedChrgitmType = "03"
  8224. //
  8225. // break
  8226. // case 5:
  8227. // item.MedChrgitmType = "08"
  8228. //
  8229. // break
  8230. // case 6:
  8231. // item.MedChrgitmType = "14"
  8232. //
  8233. // break
  8234. // case 7:
  8235. // item.MedChrgitmType = "14"
  8236. //
  8237. // break
  8238. // case 8:
  8239. // item.MedChrgitmType = "03"
  8240. // break
  8241. // case 9:
  8242. // item.MedChrgitmType = "14"
  8243. // break
  8244. // case 10:
  8245. // item.MedChrgitmType = "14"
  8246. // break
  8247. // case 11:
  8248. // item.MedChrgitmType = "06"
  8249. // break
  8250. // case 12:
  8251. // item.MedChrgitmType = "12"
  8252. // break
  8253. // case 13:
  8254. // item.MedChrgitmType = "01"
  8255. // break
  8256. // case 14:
  8257. // item.MedChrgitmType = "04"
  8258. // break
  8259. // case 15:
  8260. // item.MedChrgitmType = "02"
  8261. // break
  8262. //
  8263. // }
  8264. //
  8265. // } else {
  8266. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8267. //
  8268. // case 1:
  8269. // item.MedChrgitmType = "14"
  8270. // break
  8271. // case 2:
  8272. // item.MedChrgitmType = "05"
  8273. //
  8274. // break
  8275. // case 3:
  8276. // item.MedChrgitmType = "03"
  8277. //
  8278. // break
  8279. // case 4:
  8280. // item.MedChrgitmType = "03"
  8281. //
  8282. // break
  8283. // case 5:
  8284. // item.MedChrgitmType = "08"
  8285. //
  8286. // break
  8287. // case 6:
  8288. // item.MedChrgitmType = "14"
  8289. //
  8290. // break
  8291. // case 7:
  8292. // item.MedChrgitmType = "14"
  8293. //
  8294. // break
  8295. // case 8:
  8296. // item.MedChrgitmType = "03"
  8297. // break
  8298. // case 9:
  8299. // item.MedChrgitmType = "14"
  8300. // break
  8301. //
  8302. // }
  8303. //
  8304. // }
  8305. //
  8306. // } else if item.HisPrescriptionProject.Type == 3 {
  8307. // item.MedChrgitmType = "08"
  8308. // }
  8309. // }
  8310. // }
  8311. //
  8312. // for _, item := range orderInfos_two {
  8313. // fmt.Println(item.MedChrgitmType)
  8314. // if item.MedChrgitmType == "01" { //床位费
  8315. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8316. // bedCostSelfTotal = bedCostTotal
  8317. // }
  8318. //
  8319. // if item.MedChrgitmType == "02" { //诊察费
  8320. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8321. // zhenChaCostSelfTotal = zhenChaCostTotal
  8322. // }
  8323. //
  8324. // if item.MedChrgitmType == "03" { //检查费
  8325. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8326. // checkCostSelfTotal = checkCostTotal
  8327. // }
  8328. //
  8329. // if item.MedChrgitmType == "04" { //化验费
  8330. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8331. // laboratoryCostSelfTotal = laboratoryCostTotal
  8332. // }
  8333. //
  8334. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8335. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8336. // treatCostSelfTotal = treatCostTotal
  8337. // }
  8338. //
  8339. // if item.MedChrgitmType == "06" { //手术费
  8340. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8341. // operationCostSelfTotal = treatCostTotal
  8342. // }
  8343. //
  8344. // if item.MedChrgitmType == "08" { //材料费
  8345. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8346. // materialCostSelfTotal = materialCostTotal
  8347. // }
  8348. //
  8349. // if item.MedChrgitmType == "09" { //西药费
  8350. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8351. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8352. // }
  8353. //
  8354. // if item.MedChrgitmType == "11" { //中成费
  8355. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8356. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8357. // }
  8358. //
  8359. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8360. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8361. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8362. // otherCostSelfTotal = otherCostTotal
  8363. // }
  8364. // } else {
  8365. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8366. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8367. // otherCostSelfTotal = otherCostTotal
  8368. // }
  8369. //
  8370. // }
  8371. //
  8372. // }
  8373. //
  8374. // } else {
  8375. // for _, item := range orderInfos {
  8376. // if item.MedChrgitmType == "01" { //床位费
  8377. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8378. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8379. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8380. // }
  8381. //
  8382. // if item.MedChrgitmType == "02" { //诊察费
  8383. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8384. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8385. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8386. // }
  8387. //
  8388. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8389. // if item.MedChrgitmType == "03" { //检查费
  8390. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8391. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8392. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8393. //
  8394. // }
  8395. // } else {
  8396. // if item.MedChrgitmType == "03" { //检查费
  8397. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8398. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8399. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8400. // }
  8401. //
  8402. // }
  8403. //
  8404. // if item.MedChrgitmType == "04" { //化验费
  8405. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8406. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8407. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8408. //
  8409. // }
  8410. //
  8411. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8412. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8413. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8414. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8415. //
  8416. // }
  8417. //
  8418. // if item.MedChrgitmType == "06" { //手术费
  8419. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8420. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8421. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8422. // }
  8423. //
  8424. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8425. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8426. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8427. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8428. // }
  8429. //
  8430. // if item.MedChrgitmType == "09" { //西药费
  8431. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8432. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8433. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8434. // }
  8435. //
  8436. // if item.MedChrgitmType == "11" { //中成费
  8437. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8438. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8439. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8440. // }
  8441. //
  8442. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8443. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8444. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8445. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8446. // }
  8447. //
  8448. // }
  8449. // }
  8450. // timeLayout := "2006-01-02"
  8451. // loc, _ := time.LoadLocation("Local")
  8452. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8453. // if err != nil {
  8454. // }
  8455. // startRecordDateTime := startTime.Unix()
  8456. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8457. // if err != nil {
  8458. // }
  8459. // endRecordDateTime := endTime.Unix()
  8460. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8461. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8462. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8463. //
  8464. // c.ServeSuccessJSON(map[string]interface{}{
  8465. // "order_number": order.Number, //业务流水号
  8466. // "id_card_no": his.IdCardNo, //社会保障号
  8467. // "department_name": department.Name, //科室
  8468. // "number": his.Number, //门诊号
  8469. // "date": order.SettleAccountsDate, //结算日期
  8470. // "name": order.PsnName, //姓名
  8471. // "gender": patient.Gender, //性别
  8472. // "psn_cash_money": order.PsnCashPay, //个人支付
  8473. // "pay_way": "门诊", //结算方式
  8474. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8475. // "admin_user_name": admin.UserName, //收款员
  8476. // "order": order,
  8477. // "order_info": orderInfos_two,
  8478. // "his": his,
  8479. // "bedCostTotal": bedCostTotal,
  8480. // "bedCostSelfTotal": bedCostSelfTotal,
  8481. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8482. // "operationCostTotal": operationCostTotal,
  8483. // "operationCostSelfTotal": operationCostSelfTotal,
  8484. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8485. // "otherCostTotal": otherCostTotal,
  8486. // "otherCostSelfTotal": otherCostSelfTotal,
  8487. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8488. // "materialCostTotal": materialCostTotal,
  8489. // "materialCostSelfTotal": materialCostSelfTotal,
  8490. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8491. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8492. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8493. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8494. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8495. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8496. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8497. // "checkCostTotal": checkCostTotal,
  8498. // "checkCostSelfTotal": checkCostSelfTotal,
  8499. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8500. // "laboratoryCostTotal": laboratoryCostTotal,
  8501. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8502. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8503. // "treatCostTotal": treatCostTotal,
  8504. // "treatCostSelfTotal": treatCostSelfTotal,
  8505. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8506. // "zhenChaCostTotal": zhenChaCostTotal,
  8507. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8508. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8509. // "his_hospital_record": his_hospital_record,
  8510. // "pre_pay_money": pre_pay_money,
  8511. // "refund_sum": sum,
  8512. // })
  8513. //
  8514. //}
  8515. func (this *HisApiController) GetIncomeStatisticsData() {
  8516. start_time := this.GetString("start_time")
  8517. end_time := this.GetString("end_time")
  8518. key_words := this.GetString("key_words")
  8519. limit, _ := this.GetInt64("limit")
  8520. page, _ := this.GetInt64("page")
  8521. if page <= 0 {
  8522. page = 1
  8523. }
  8524. if limit <= 0 {
  8525. limit = 10
  8526. }
  8527. statistics_type, _ := this.GetInt64("statistics_type")
  8528. admin := this.GetAdminUserInfo()
  8529. timeLayout := "2006-01-02"
  8530. loc, _ := time.LoadLocation("Local")
  8531. var theStartTIme int64
  8532. if len(start_time) > 0 {
  8533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8534. if err != nil {
  8535. theStartTIme = 0
  8536. }
  8537. theStartTIme = theTime.Unix()
  8538. }
  8539. var theEndtTIme int64
  8540. if len(end_time) > 0 {
  8541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8542. if err != nil {
  8543. theEndtTIme = 0
  8544. }
  8545. theEndtTIme = theTime.Unix()
  8546. }
  8547. if statistics_type == 1 {
  8548. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8549. this.ServeSuccessJSON(map[string]interface{}{
  8550. "list": list,
  8551. "total": total,
  8552. })
  8553. } else {
  8554. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8555. this.ServeSuccessJSON(map[string]interface{}{
  8556. "list": list,
  8557. "total": total,
  8558. })
  8559. }
  8560. }
  8561. func (c *HisApiController) PostProjectInformation() {
  8562. adminUser := c.GetAdminUserInfo()
  8563. orgId := adminUser.CurrentOrgId
  8564. dataBody := make(map[string]interface{}, 0)
  8565. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8566. if err != nil {
  8567. utils.ErrorLog(err.Error())
  8568. return
  8569. }
  8570. utils.ErrorLog("%v", dataBody)
  8571. var projectList []*models.HisProject
  8572. var total_goods []interface{}
  8573. tempProjects := dataBody["projects"].([]interface{})
  8574. total_goods = tempProjects
  8575. for index, projectMap := range tempProjects {
  8576. projectM := projectMap.(map[string]interface{})
  8577. var project models.HisProject
  8578. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8579. utils.ErrorLog("project_name")
  8580. return
  8581. }
  8582. project_name, _ := projectM["project_name"].(string)
  8583. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8584. err_log := models.ExportErrLog{
  8585. LogType: 6,
  8586. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8587. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8588. Status: 1,
  8589. CreateTime: time.Now().Unix(),
  8590. UpdateTime: time.Now().Unix(),
  8591. ExportTime: time.Now().Unix(),
  8592. }
  8593. service.CreateExportErrLog(&err_log)
  8594. continue
  8595. }
  8596. project.ProjectName = project_name
  8597. prices := projectM["price"].(string)
  8598. price, _ := strconv.ParseFloat(prices, 64)
  8599. if price <= 0 { //名字为空则生成一条导入错误日志
  8600. err_log := models.ExportErrLog{
  8601. LogType: 6,
  8602. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8603. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8604. Status: 1,
  8605. CreateTime: time.Now().Unix(),
  8606. UpdateTime: time.Now().Unix(),
  8607. ExportTime: time.Now().Unix(),
  8608. }
  8609. service.CreateExportErrLog(&err_log)
  8610. continue
  8611. }
  8612. project.Price = price
  8613. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8614. utils.ErrorLog("unit_id")
  8615. return
  8616. }
  8617. unit := projectM["unit"].(string)
  8618. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8619. err_log := models.ExportErrLog{
  8620. LogType: 6,
  8621. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8622. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8623. Status: 1,
  8624. CreateTime: time.Now().Unix(),
  8625. UpdateTime: time.Now().Unix(),
  8626. ExportTime: time.Now().Unix(),
  8627. }
  8628. service.CreateExportErrLog(&err_log)
  8629. continue
  8630. }
  8631. project.Unit = unit
  8632. cost_classify := projectM["cost_classify"].(string)
  8633. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8634. err_log := models.ExportErrLog{
  8635. LogType: 6,
  8636. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8637. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8638. Status: 1,
  8639. CreateTime: time.Now().Unix(),
  8640. UpdateTime: time.Now().Unix(),
  8641. ExportTime: time.Now().Unix(),
  8642. }
  8643. service.CreateExportErrLog(&err_log)
  8644. continue
  8645. }
  8646. var costClassify = "费用类别"
  8647. var cost_classify_id int64
  8648. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8649. if len(cost_classify) != 0 {
  8650. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8651. if errcode == gorm.ErrRecordNotFound {
  8652. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8653. dataconfig := models.DictDataconfig{
  8654. ParentId: costClassifyConfig.ID,
  8655. Module: "system",
  8656. OrgId: orgId,
  8657. Name: cost_classify,
  8658. FieldName: "",
  8659. Value: costConfig.Value + 1,
  8660. CreatedTime: "",
  8661. UpdatedTime: "",
  8662. CreateUserId: adminUser.AdminUser.Id,
  8663. Status: 1,
  8664. Remark: "",
  8665. DeleteIdSystem: 0,
  8666. Title: "",
  8667. Content: "",
  8668. Order: 0,
  8669. Code: "",
  8670. }
  8671. service.CreatedDicConfig(&dataconfig)
  8672. }
  8673. }
  8674. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8675. for _, it := range costClassList {
  8676. if cost_classify == it.Name {
  8677. cost_classify_id = int64(it.Value)
  8678. }
  8679. }
  8680. project.CostClassify = cost_classify_id
  8681. executive_section := projectM["executive_section"].(string)
  8682. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8683. err_log := models.ExportErrLog{
  8684. LogType: 6,
  8685. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8686. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8687. Status: 1,
  8688. CreateTime: time.Now().Unix(),
  8689. UpdateTime: time.Now().Unix(),
  8690. ExportTime: time.Now().Unix(),
  8691. }
  8692. service.CreateExportErrLog(&err_log)
  8693. continue
  8694. }
  8695. if len(executive_section) != 0 {
  8696. //查找科室是否有内容
  8697. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8698. if errcodedepart == gorm.ErrRecordNotFound {
  8699. department := models.XtHisDepartment{
  8700. Name: executive_section,
  8701. Status: 1,
  8702. UserOrgId: adminUser.CurrentOrgId,
  8703. CreatedTime: time.Now().Unix(),
  8704. }
  8705. service.CreateDePartment(&department)
  8706. }
  8707. }
  8708. var executive_section_id int64
  8709. departMentList, _ := service.GetAllDepartMent(orgId)
  8710. for _, it := range departMentList {
  8711. if executive_section == it.Name {
  8712. executive_section_id = it.ID
  8713. }
  8714. }
  8715. project.ExecutiveSection = executive_section_id
  8716. medical_coverage := projectM["medical_coverage"].(string)
  8717. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8718. err_log := models.ExportErrLog{
  8719. LogType: 6,
  8720. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8721. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8722. Status: 1,
  8723. CreateTime: time.Now().Unix(),
  8724. UpdateTime: time.Now().Unix(),
  8725. ExportTime: time.Now().Unix(),
  8726. }
  8727. service.CreateExportErrLog(&err_log)
  8728. continue
  8729. }
  8730. var medicalCoverage = "医保等级"
  8731. var medical_coverage_id int64
  8732. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8733. if len(medical_coverage) != 0 {
  8734. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8735. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8736. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8737. dataconfig := models.DictDataconfig{
  8738. ParentId: medicalCoverageConfig.ID,
  8739. Module: "system",
  8740. OrgId: orgId,
  8741. Name: medical_coverage,
  8742. FieldName: "",
  8743. Value: medicalCoverageConfig.Value + 1,
  8744. CreatedTime: "",
  8745. UpdatedTime: "",
  8746. CreateUserId: adminUser.AdminUser.Id,
  8747. Status: 1,
  8748. Remark: "",
  8749. DeleteIdSystem: 0,
  8750. Title: "",
  8751. Content: "",
  8752. Order: 0,
  8753. Code: "",
  8754. }
  8755. service.CreatedDicConfig(&dataconfig)
  8756. }
  8757. }
  8758. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8759. for _, it := range medicalCoverageList {
  8760. if medical_coverage == it.Name {
  8761. medical_coverage_id = int64(it.Value)
  8762. }
  8763. }
  8764. project.MedicalCoverage = medical_coverage_id
  8765. pinyin := projectM["pinyin"].(string)
  8766. project.Pinyin = pinyin
  8767. wubi := projectM["wubi"].(string)
  8768. project.Wubi = wubi
  8769. statistical_classification := projectM["statistical_classification"].(string)
  8770. var statisticalClassification = "统计分类"
  8771. var statistical_classification_id int64
  8772. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8773. if len(statistical_classification) != 0 {
  8774. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8775. if classificationerrcodes == gorm.ErrRecordNotFound {
  8776. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8777. dataconfig := models.DictDataconfig{
  8778. ParentId: classiFication.ID,
  8779. Module: "system",
  8780. OrgId: orgId,
  8781. Name: statistical_classification,
  8782. FieldName: "",
  8783. Value: classiFicationConfig.Value + 1,
  8784. CreatedTime: "",
  8785. UpdatedTime: "",
  8786. CreateUserId: adminUser.AdminUser.Id,
  8787. Status: 1,
  8788. Remark: "",
  8789. DeleteIdSystem: 0,
  8790. Title: "",
  8791. Content: "",
  8792. Order: 0,
  8793. Code: "",
  8794. }
  8795. service.CreatedDicConfig(&dataconfig)
  8796. }
  8797. }
  8798. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8799. for _, it := range classiFicationList {
  8800. if statistical_classification == it.Name {
  8801. statistical_classification_id = int64(it.Value)
  8802. }
  8803. }
  8804. project.StatisticalClassification = statistical_classification_id
  8805. disease_directory := int64(projectM["disease_directory"].(float64))
  8806. project.DiseaseDirectory = disease_directory
  8807. is_record := int64(projectM["is_record"].(float64))
  8808. project.IsRecord = is_record
  8809. medical_code := projectM["medical_code"].(string)
  8810. project.MedicalCode = medical_code
  8811. tube_color := projectM["tube_color"].(string)
  8812. var tubeColor = "试管颜色"
  8813. var tube_color_id int64
  8814. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8815. if len(tube_color) != 0 {
  8816. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8817. if errcodetube == gorm.ErrRecordNotFound {
  8818. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8819. dataconfig := models.DictDataconfig{
  8820. ParentId: tubeColorConfig.ID,
  8821. Module: "system",
  8822. OrgId: orgId,
  8823. Name: tube_color,
  8824. FieldName: "",
  8825. Value: tubeConfig.Value + 1,
  8826. CreatedTime: "",
  8827. UpdatedTime: "",
  8828. CreateUserId: adminUser.AdminUser.Id,
  8829. Status: 1,
  8830. Remark: "",
  8831. DeleteIdSystem: 0,
  8832. Title: "",
  8833. Content: "",
  8834. Order: 0,
  8835. Code: "",
  8836. }
  8837. service.CreatedDicConfig(&dataconfig)
  8838. }
  8839. }
  8840. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8841. for _, it := range tubeColorList {
  8842. if tube_color == it.Name {
  8843. tube_color_id = int64(it.Value)
  8844. }
  8845. }
  8846. project.TubeColor = tube_color_id
  8847. single_dose := projectM["single_dose"].(string)
  8848. project.SingleDose = single_dose
  8849. execution_frequency := projectM["execution_frequency"].(string)
  8850. project.ExecutionFrequency = execution_frequency
  8851. delivery_way := projectM["delivery_way"].(string)
  8852. project.DeliveryWay = delivery_way
  8853. number_days := projectM["number_days"].(string)
  8854. project.NumberDays = number_days
  8855. total := projectM["total"].(string)
  8856. project.Total = total
  8857. medical_status := int64(projectM["medical_status"].(float64))
  8858. project.MedicalStatus = medical_status
  8859. category := int64(projectM["category"].(float64))
  8860. project.Category = category
  8861. specail_project := int64(projectM["specail_project"].(float64))
  8862. project.SpecailProject = specail_project
  8863. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8864. project.SocialSecurityDirectoryCode = social_security_directory_code
  8865. remark := projectM["remark"].(string)
  8866. project.Remark = remark
  8867. record_date := projectM["record_date"].(string)
  8868. timeLayout := "2006-01-02"
  8869. loc, _ := time.LoadLocation("Local")
  8870. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8871. project.RecordDate = theTime.Unix()
  8872. projectList = append(projectList, &project)
  8873. }
  8874. export_time := time.Now().Unix()
  8875. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8876. if len(projectList) > 0 {
  8877. for _, item := range projectList {
  8878. project := models.HisProject{
  8879. ProjectName: item.ProjectName,
  8880. Price: item.Price,
  8881. Unit: item.Unit,
  8882. CostClassify: item.CostClassify,
  8883. ExecutiveSection: item.ExecutiveSection,
  8884. MedicalCoverage: item.MedicalCoverage,
  8885. UserOrgId: orgId,
  8886. Status: 1,
  8887. CreatedTime: time.Now().Unix(),
  8888. Pinyin: item.Pinyin,
  8889. Wubi: item.Wubi,
  8890. StatisticalClassification: item.StatisticalClassification,
  8891. DiseaseDirectory: item.DiseaseDirectory,
  8892. IsRecord: item.IsRecord,
  8893. MedicalCode: item.MedicalCode,
  8894. TubeColor: item.TubeColor,
  8895. SingleDose: item.SingleDose,
  8896. DeliveryWay: item.DeliveryWay,
  8897. NumberDays: item.NumberDays,
  8898. Total: item.Total,
  8899. Category: item.Category,
  8900. MedicalStatus: item.MedicalStatus,
  8901. SpecailProject: item.SpecailProject,
  8902. RecordDate: item.RecordDate,
  8903. Remark: item.Remark,
  8904. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8905. ExecutionFrequency: item.ExecutionFrequency,
  8906. }
  8907. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8908. if errcodeproject == gorm.ErrRecordNotFound {
  8909. service.CreateProjectInfomation(&project)
  8910. } else if errcodeproject == nil {
  8911. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8912. }
  8913. log := models.ExportLog{
  8914. LogType: 6,
  8915. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8916. TotalNum: int64(len(total_goods)),
  8917. FailNum: int64(len(errLogs)),
  8918. SuccessNum: int64(len(projectList)),
  8919. CreateTime: time.Now().Unix(),
  8920. UpdateTime: time.Now().Unix(),
  8921. ExportTime: export_time,
  8922. Status: 1,
  8923. }
  8924. service.CreateExportLog(&log)
  8925. c.ServeSuccessJSON(map[string]interface{}{
  8926. "msg": "导入成功",
  8927. "total_num": len(total_goods),
  8928. "success_num": len(projectList),
  8929. "fail_num": int64(len(errLogs)),
  8930. })
  8931. }
  8932. } else {
  8933. log := models.ExportLog{
  8934. LogType: 6,
  8935. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8936. TotalNum: int64(len(total_goods)),
  8937. FailNum: int64(len(errLogs)),
  8938. SuccessNum: int64(len(projectList)),
  8939. CreateTime: time.Now().Unix(),
  8940. UpdateTime: time.Now().Unix(),
  8941. ExportTime: export_time,
  8942. Status: 1,
  8943. }
  8944. service.CreateExportLog(&log)
  8945. c.ServeSuccessJSON(map[string]interface{}{
  8946. "msg": "导入成功",
  8947. "total_num": len(total_goods),
  8948. "success_num": len(projectList),
  8949. "fail_num": int64(len(errLogs)),
  8950. })
  8951. }
  8952. }
  8953. //func (this *HisApiController) EditProjectInformation(){
  8954. //
  8955. // id, _ := this.GetInt64("id")
  8956. // project_team := this.GetString("project_team")
  8957. // price := this.GetString("price")
  8958. // price_float, _ := strconv.ParseFloat(price, 64)
  8959. // pinyin := this.GetString("pinyin")
  8960. // wubi := this.GetString("wubi")
  8961. // tube_color, _ := this.GetInt64("tube_color")
  8962. // team_type, _ := this.GetInt64("team_type")
  8963. // remark := this.GetString("remark")
  8964. // ids := this.GetString("ids")
  8965. // item_id := this.GetString("item_id")
  8966. // projectTeam := models.XtHisProjectTeam{
  8967. // ProjectTeam: project_team,
  8968. // Price: price_float,
  8969. // Pinyin: pinyin,
  8970. // Wubi: wubi,
  8971. // TubeColor: tube_color,
  8972. // TeamType: team_type,
  8973. // Remark: remark,
  8974. // ProjectId: ids,
  8975. // ItemId: item_id,
  8976. // }
  8977. //
  8978. //
  8979. // dataBody := make(map[string]interface{}, 0)
  8980. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8981. // if err != nil {
  8982. // utils.ErrorLog(err.Error())
  8983. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8984. // return
  8985. // }
  8986. //
  8987. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8988. //
  8989. //
  8990. // if err != nil {
  8991. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8992. // return
  8993. // }
  8994. //
  8995. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8996. // infos, _ := dataBody["info"].([]interface{})
  8997. // if len(infos) > 0 {
  8998. // var ids []string
  8999. //
  9000. // for _, item := range infos {
  9001. // items := item.(map[string]interface{})
  9002. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9003. // utils.ErrorLog("id")
  9004. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9005. // return
  9006. // }
  9007. // id := int64(items["id"].(float64))
  9008. //
  9009. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9010. // utils.ErrorLog("type")
  9011. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9012. // return
  9013. // }
  9014. // types := int64(items["type"].(float64))
  9015. //
  9016. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9017. // utils.ErrorLog("number")
  9018. // }
  9019. //
  9020. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9021. //
  9022. // projectList := models.XtHisProjectList{
  9023. // Number: number,
  9024. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9025. // ProjectId: id,
  9026. // Status: 1,
  9027. // CreatedTime: time.Now().Unix(),
  9028. // UpdatedTime: time.Now().Unix(),
  9029. // TeamId: projectTeam.ID,
  9030. // Type: types,
  9031. // }
  9032. // list := projectList
  9033. //
  9034. // service.CreateProjectList(&list)
  9035. //
  9036. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9037. //
  9038. // }
  9039. // ids_str := strings.Join(ids, ",")
  9040. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9041. // service.SaveProjectTeam(&projectTeam)
  9042. // this.ServeSuccessJSON(map[string]interface{}{
  9043. // "projectTeam": projectTeam,
  9044. // })
  9045. // }
  9046. // }
  9047. //}
  9048. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9049. name := c.GetString("name")
  9050. mode_id, _ := c.GetInt64("mode", 0)
  9051. types, _ := c.GetInt64("type", 0)
  9052. patient_id, _ := c.GetInt64("patient_id", 0)
  9053. types = 1
  9054. adminInfo := c.GetAdminUserInfo()
  9055. template := &models.HisPrescriptionTemplate{
  9056. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9057. PatientId: patient_id,
  9058. Type: types,
  9059. Status: 1,
  9060. Ctime: time.Now().Unix(),
  9061. Mtime: time.Now().Unix(),
  9062. Name: name,
  9063. Mode: mode_id,
  9064. }
  9065. dataBody := make(map[string]interface{}, 0)
  9066. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9067. if err != nil {
  9068. utils.ErrorLog(err.Error())
  9069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9070. return
  9071. }
  9072. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9073. //如果已经存在记录则删除处方
  9074. if template_one.ID > 0 {
  9075. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9076. for _, item := range ps {
  9077. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9078. }
  9079. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9080. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9081. if len(prescriptions) > 0 {
  9082. for _, item := range prescriptions {
  9083. items := item.(map[string]interface{})
  9084. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9085. utils.ErrorLog("type")
  9086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9087. return
  9088. }
  9089. types := int64(items["type"].(float64))
  9090. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9091. utils.ErrorLog("med_type")
  9092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9093. return
  9094. }
  9095. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9096. ctime := time.Now().Unix()
  9097. prescription := &models.HisPrescriptionInfoTemplate{
  9098. PatientId: patient_id,
  9099. UserOrgId: adminInfo.CurrentOrgId,
  9100. Ctime: ctime,
  9101. Mtime: ctime,
  9102. Type: types,
  9103. Modifier: adminInfo.AdminUser.Id,
  9104. Creator: adminInfo.AdminUser.Id,
  9105. Status: 1,
  9106. PTemplateId: template_one.ID,
  9107. MedType: med_type,
  9108. }
  9109. service.CreateHisPrescriptionInfoTemplate(prescription)
  9110. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9111. advices := items["advices"].([]interface{})
  9112. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9113. ctime := time.Now().Unix()
  9114. mtime := ctime
  9115. if len(advices) > 0 {
  9116. for _, advice := range advices {
  9117. var s models.HisPrescriptionAdviceTemplate
  9118. s.PrescriptionId = prescription.ID
  9119. s.AdviceType = 2
  9120. s.StopState = 2
  9121. s.ExecutionState = 2
  9122. s.Status = 1
  9123. s.UserOrgId = adminInfo.CurrentOrgId
  9124. s.CreatedTime = ctime
  9125. s.UpdatedTime = mtime
  9126. s.PatientId = patient_id
  9127. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9128. if errcode > 0 {
  9129. c.ServeFailJSONWithSGJErrorCode(errcode)
  9130. return
  9131. }
  9132. service.CreateHisPrescriptionAdviceTemplate(&s)
  9133. }
  9134. }
  9135. }
  9136. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9137. projects := items["project"].([]interface{})
  9138. if len(projects) > 0 {
  9139. for _, project := range projects {
  9140. var p models.HisPrescriptionProjectTemplate
  9141. p.PrescriptionId = prescription.ID
  9142. p.Ctime = time.Now().Unix()
  9143. p.Mtime = time.Now().Unix()
  9144. p.PatientId = patient_id
  9145. p.UserOrgId = adminInfo.CurrentOrgId
  9146. p.Status = 1
  9147. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9148. if errcode > 0 {
  9149. c.ServeFailJSONWithSGJErrorCode(errcode)
  9150. return
  9151. }
  9152. service.CreateHisPrescriptionProjectTemplate(&p)
  9153. }
  9154. }
  9155. }
  9156. }
  9157. c.ServeSuccessJSON(map[string]interface{}{
  9158. "msg": "创建成功",
  9159. })
  9160. }
  9161. }
  9162. } else {
  9163. err = service.CreateHisPrescriptionTemplate(template)
  9164. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9165. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9166. if len(prescriptions) > 0 {
  9167. for _, item := range prescriptions {
  9168. items := item.(map[string]interface{})
  9169. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9170. utils.ErrorLog("type")
  9171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9172. return
  9173. }
  9174. types := int64(items["type"].(float64))
  9175. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9176. utils.ErrorLog("med_type")
  9177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9178. return
  9179. }
  9180. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9181. ctime := time.Now().Unix()
  9182. prescription := &models.HisPrescriptionInfoTemplate{
  9183. PatientId: patient_id,
  9184. UserOrgId: adminInfo.CurrentOrgId,
  9185. Ctime: ctime,
  9186. Mtime: ctime,
  9187. Type: types,
  9188. Modifier: adminInfo.AdminUser.Id,
  9189. Creator: adminInfo.AdminUser.Id,
  9190. Status: 1,
  9191. PTemplateId: template.ID,
  9192. MedType: med_type,
  9193. }
  9194. service.CreateHisPrescriptionInfoTemplate(prescription)
  9195. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9196. advices := items["advices"].([]interface{})
  9197. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9198. ctime := time.Now().Unix()
  9199. mtime := ctime
  9200. if len(advices) > 0 {
  9201. for _, advice := range advices {
  9202. var s models.HisPrescriptionAdviceTemplate
  9203. s.PrescriptionId = prescription.ID
  9204. s.AdviceType = 2
  9205. s.StopState = 2
  9206. s.ExecutionState = 2
  9207. s.Status = 1
  9208. s.UserOrgId = adminInfo.CurrentOrgId
  9209. s.CreatedTime = ctime
  9210. s.UpdatedTime = mtime
  9211. s.PatientId = patient_id
  9212. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9213. if errcode > 0 {
  9214. c.ServeFailJSONWithSGJErrorCode(errcode)
  9215. return
  9216. }
  9217. service.CreateHisPrescriptionAdviceTemplate(&s)
  9218. }
  9219. }
  9220. }
  9221. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9222. projects := items["project"].([]interface{})
  9223. if len(projects) > 0 {
  9224. for _, project := range projects {
  9225. var p models.HisPrescriptionProjectTemplate
  9226. p.PrescriptionId = prescription.ID
  9227. p.Ctime = time.Now().Unix()
  9228. p.Mtime = time.Now().Unix()
  9229. p.PatientId = patient_id
  9230. p.UserOrgId = adminInfo.CurrentOrgId
  9231. p.Status = 1
  9232. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9233. if errcode > 0 {
  9234. c.ServeFailJSONWithSGJErrorCode(errcode)
  9235. return
  9236. }
  9237. service.CreateHisPrescriptionProjectTemplate(&p)
  9238. }
  9239. }
  9240. }
  9241. }
  9242. c.ServeSuccessJSON(map[string]interface{}{
  9243. "msg": "创建成功",
  9244. })
  9245. }
  9246. }
  9247. }
  9248. }
  9249. func (c *HisApiController) PreSettle() {
  9250. id, _ := c.GetInt64("id")
  9251. record_time := c.GetString("record_time")
  9252. his_patient_id, _ := c.GetInt64("his_patient_id")
  9253. timeLayout := "2006-01-02"
  9254. loc, _ := time.LoadLocation("Local")
  9255. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9256. diagnosis_id := c.GetString("diagnosis")
  9257. sick_type, _ := c.GetInt64("sick_type")
  9258. reg_type, _ := c.GetInt64("p_type")
  9259. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9261. if err != nil {
  9262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9263. return
  9264. }
  9265. recordDateTime := theTime.Unix()
  9266. adminUser := c.GetAdminUserInfo()
  9267. var prescriptions []*models.HisPrescription
  9268. var start_time int64
  9269. var end_time int64
  9270. ids_str := c.GetString("ids")
  9271. ids_arr := strings.Split(ids_str, ",")
  9272. fmt.Println(reg_type)
  9273. if settle_accounts_type == 1 { //日结
  9274. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9275. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9276. } else {
  9277. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9278. }
  9279. fmt.Println(prescriptions)
  9280. } else { //月结
  9281. start_time_str := c.GetString("start_time")
  9282. end_time_str := c.GetString("end_time")
  9283. timeLayout := "2006-01-02"
  9284. loc, _ := time.LoadLocation("Local")
  9285. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9286. if err != nil {
  9287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9288. return
  9289. }
  9290. recordStartTime := theStartTime.Unix()
  9291. start_time = recordStartTime
  9292. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9293. if err != nil {
  9294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9295. return
  9296. }
  9297. recordEndTime := theEndTime.Unix()
  9298. end_time = recordEndTime
  9299. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9300. }
  9301. if reg_type == 1111 || reg_type == 1112 {
  9302. reg_type = 11
  9303. }
  9304. timestamp := time.Now().Unix()
  9305. tempTime := time.Unix(timestamp, 0)
  9306. timeFormat := tempTime.Format("20060102150405")
  9307. chrgBchno := rand.Intn(100000) + 10000
  9308. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9309. strconv.FormatInt(his.PatientId, 10)
  9310. var ids []int64
  9311. for _, item := range prescriptions {
  9312. ids = append(ids, item.ID)
  9313. }
  9314. fmt.Println(ids)
  9315. var total float64
  9316. for _, item := range prescriptions {
  9317. fmt.Println(item)
  9318. if item.Type == 1 { //药品
  9319. for _, subItem := range item.HisDoctorAdviceInfo {
  9320. total = total + (subItem.Price * subItem.PrescribingNumber)
  9321. }
  9322. }
  9323. if item.Type == 2 { //项目
  9324. for _, subItem := range item.HisPrescriptionProject {
  9325. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9326. total = total + (subItem.Price * cnt)
  9327. }
  9328. }
  9329. for _, subItem := range item.HisAdditionalCharge {
  9330. total = total + (subItem.Price * float64(subItem.Count))
  9331. }
  9332. }
  9333. allTotal := fmt.Sprintf("%.2f", total)
  9334. totals, _ := strconv.ParseFloat(allTotal, 64)
  9335. order := &models.HisOrder{
  9336. UserOrgId: adminUser.CurrentOrgId,
  9337. HisPatientId: his.ID,
  9338. PatientId: id,
  9339. SettleAccountsDate: recordDateTime,
  9340. Ctime: time.Now().Unix(),
  9341. Mtime: time.Now().Unix(),
  9342. Status: 1,
  9343. OrderStatus: 1,
  9344. MdtrtId: his.Number,
  9345. Number: chrg_bchno,
  9346. MedfeeSumamt: totals,
  9347. SettleEndTime: end_time,
  9348. SettleStartTime: start_time,
  9349. SettleType: settle_accounts_type,
  9350. PsnPartAmt: totals,
  9351. PsnCashPay: totals,
  9352. PType: 2,
  9353. IsPre: 1,
  9354. MedType: strconv.Itoa(int(reg_type)),
  9355. Diagnosis: diagnosis_id,
  9356. }
  9357. err = service.CreateOrder(order)
  9358. if err != nil {
  9359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9360. return
  9361. }
  9362. var customs []*Custom
  9363. for _, item := range prescriptions {
  9364. fmt.Println(item.Type)
  9365. if item.Type == 1 { //药品
  9366. for _, subItem := range item.HisDoctorAdviceInfo {
  9367. cus := &Custom{
  9368. AdviceId: subItem.ID,
  9369. ProjectId: 0,
  9370. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9371. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9372. FeedetlSn: subItem.FeedetlSn,
  9373. Price: fmt.Sprintf("%.2f", subItem.Price),
  9374. MedListCodg: subItem.MedListCodg,
  9375. Type: 1,
  9376. }
  9377. customs = append(customs, cus)
  9378. }
  9379. }
  9380. if item.Type == 2 { //项目
  9381. for _, subItem := range item.HisPrescriptionProject {
  9382. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9383. cus := &Custom{
  9384. AdviceId: 0,
  9385. ProjectId: subItem.ID,
  9386. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9387. Cut: fmt.Sprintf("%.2f", cnt),
  9388. FeedetlSn: subItem.FeedetlSn,
  9389. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9390. MedListCodg: subItem.MedListCodg,
  9391. Type: 2,
  9392. }
  9393. customs = append(customs, cus)
  9394. }
  9395. }
  9396. for _, item := range item.HisAdditionalCharge {
  9397. cus := &Custom{
  9398. ItemId: item.ID,
  9399. AdviceId: 0,
  9400. ProjectId: 0,
  9401. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9402. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9403. FeedetlSn: item.FeedetlSn,
  9404. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9405. MedListCodg: item.XtHisAddtionConfig.Code,
  9406. Type: 3,
  9407. }
  9408. customs = append(customs, cus)
  9409. }
  9410. }
  9411. fmt.Println(customs)
  9412. for _, item := range customs {
  9413. var advice_id int64 = 0
  9414. var project_id int64 = 0
  9415. var item_id int64 = 0
  9416. var types int64 = 0
  9417. if item.Type == 1 {
  9418. advice_id = item.AdviceId
  9419. project_id = 0
  9420. item_id = 0
  9421. } else if item.Type == 2 {
  9422. advice_id = 0
  9423. item_id = 0
  9424. project_id = item.ProjectId
  9425. } else if item.Type == 3 {
  9426. advice_id = 0
  9427. item_id = item.ItemId
  9428. project_id = 0
  9429. }
  9430. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9431. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9432. pric, _ := strconv.ParseFloat(item.Price, 32)
  9433. info := &models.HisOrderInfo{
  9434. OrderNumber: order.Number,
  9435. UploadDate: time.Now().Unix(),
  9436. AdviceId: advice_id,
  9437. DetItemFeeSumamt: detItemFeeSumamt,
  9438. Cnt: cut,
  9439. Pric: pric,
  9440. PatientId: id,
  9441. Status: 1,
  9442. Mtime: time.Now().Unix(),
  9443. Ctime: time.Now().Unix(),
  9444. UserOrgId: adminUser.CurrentOrgId,
  9445. HisPatientId: his.ID,
  9446. OrderId: order.ID,
  9447. ProjectId: project_id,
  9448. Type: types,
  9449. ItemId: item_id,
  9450. }
  9451. service.CreateOrderInfo(info)
  9452. }
  9453. his.SickType = sick_type
  9454. service.UpdataHisPateint(&his)
  9455. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9456. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9457. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9458. if err == nil {
  9459. c.ServeSuccessJSON(map[string]interface{}{
  9460. "msg": "结算成功",
  9461. })
  9462. }
  9463. }
  9464. type CustomOrderInfo struct {
  9465. Name string
  9466. Spec string
  9467. Unit string
  9468. Count float64
  9469. Price float64
  9470. Total float64
  9471. }
  9472. func (c *HisApiController) GetPrivateExpensesInfo() {
  9473. order_id, _ := c.GetInt64("id", 0)
  9474. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9475. order, _ := service.GetHisOrderByID(order_id)
  9476. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9477. if order.ID == 0 {
  9478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9479. return
  9480. }
  9481. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9482. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9483. org_id := c.GetAdminUserInfo().CurrentOrgId
  9484. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9485. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9486. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9487. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9488. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9489. //var orderInfos_four []*models.HisOrderInfoTwo
  9490. //for _, item := range orderInfos_three {
  9491. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9492. // item.HisPrescriptionProject.IsCheckTeam = 1
  9493. // orderInfos_four = append(orderInfos_four, item)
  9494. //
  9495. // }
  9496. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9497. // item.HisPrescriptionProject.IsCheckTeam = 2
  9498. // orderInfos_two = append(orderInfos_two, item)
  9499. // }
  9500. //}
  9501. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9502. //var cus_slice []CustomOrderInfo
  9503. //for _, item := range new_order_info {
  9504. // var cus CustomOrderInfo
  9505. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9506. // cus.Unit = ""
  9507. // cus.Spec = ""
  9508. // var total float64
  9509. // for _, subItem := range orderInfos_four {
  9510. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9511. // total = total + subItem.DetItemFeeSumamt
  9512. // fmt.Println(subItem.DetItemFeeSumamt)
  9513. // }
  9514. // }
  9515. // cus.Count = 1
  9516. // cus.Total = total
  9517. // cus_slice = append(cus_slice, cus)
  9518. //}
  9519. orderInfos = append(orderInfos, orderInfos_two...)
  9520. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9521. //orderInfos = append(orderInfos, orderInfos_three...)
  9522. //}/**/
  9523. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9524. c.ServeSuccessJSON(map[string]interface{}{
  9525. "order": order,
  9526. "order_info": orderInfos,
  9527. "patient": patient,
  9528. "admin_info": adminInfo,
  9529. "his": his,
  9530. "current_admin": role,
  9531. "org_config": miConfig,
  9532. //"new_order_info": cus_slice,
  9533. })
  9534. }
  9535. func (this *HisApiController) ChangeMedType() {
  9536. med_type := this.GetString("med_type")
  9537. old_med_type := this.GetString("old_med_type")
  9538. ids := this.GetString("ids")
  9539. settle_type, _ := this.GetInt64("settle_type")
  9540. start_time := this.GetString("start_time")
  9541. end_time := this.GetString("end_time")
  9542. ids_arr := strings.Split(ids, ",")
  9543. if settle_type == 1 { //日结
  9544. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9545. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9546. prescription.MedType = med_type
  9547. err := service.SaveHisPrescription(&prescription)
  9548. if err == nil {
  9549. this.ServeSuccessJSON(map[string]interface{}{
  9550. "msg": "修改成功",
  9551. })
  9552. } else {
  9553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9554. return
  9555. }
  9556. } else if settle_type == 2 {
  9557. timeLayout := "2006-01-02"
  9558. loc, _ := time.LoadLocation("Local")
  9559. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9560. if err != nil {
  9561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9562. return
  9563. }
  9564. recordStartTime := theStartTime.Unix()
  9565. start_time_timestamp := recordStartTime
  9566. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9567. if err != nil {
  9568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9569. return
  9570. }
  9571. recordEndTime := theEndTime.Unix()
  9572. end_time_timestamp := recordEndTime
  9573. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9574. if updateErr == nil {
  9575. this.ServeSuccessJSON(map[string]interface{}{
  9576. "msg": "修改成功",
  9577. })
  9578. } else {
  9579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9580. return
  9581. }
  9582. }
  9583. }
  9584. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9585. patient_id, _ := c.GetInt64("patient_id")
  9586. his_patient_id, _ := c.GetInt64("his_patient_id")
  9587. record_date := c.GetString("record_date")
  9588. start_time := c.GetString("start_time")
  9589. end_time := c.GetString("end_time")
  9590. order_status, _ := c.GetInt64("type", 0)
  9591. p_type, _ := c.GetInt64("p_type", 0)
  9592. order_id, _ := c.GetInt64("order_id", 0)
  9593. timeLayout := "2006-01-02"
  9594. loc, _ := time.LoadLocation("Local")
  9595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9596. if err != nil {
  9597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9598. return
  9599. }
  9600. recordDateTime := theTime.Unix()
  9601. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9602. if err != nil {
  9603. }
  9604. startRecordDateTime := startTime.Unix()
  9605. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9606. if err != nil {
  9607. }
  9608. endRecordDateTime := endTime.Unix()
  9609. admin := c.GetAdminUserInfo()
  9610. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9611. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9612. order, _ := service.GetHisOrderByID(order_id)
  9613. var monthPrescriptions []*models.HisPrescription
  9614. if order_status == 1 || order_status == 0 {
  9615. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9616. } else if order_status == 2 {
  9617. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9618. }
  9619. var settle_total float64
  9620. for _, item := range monthPrescriptions {
  9621. if len(item.HisPrescriptionProject) > 0 {
  9622. for _, subItem := range item.HisPrescriptionProject {
  9623. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9624. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9625. settle_total = settle_total + total
  9626. }
  9627. }
  9628. if len(item.HisDoctorAdviceInfo) > 0 {
  9629. for _, subItem := range item.HisDoctorAdviceInfo {
  9630. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9631. settle_total = settle_total + total
  9632. }
  9633. }
  9634. }
  9635. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9636. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9637. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9638. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9639. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9640. //获取所有科室信息
  9641. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9642. c.ServeSuccessJSON(map[string]interface{}{
  9643. "his_info": his_patient_info,
  9644. "xt_info": xt_patient_info,
  9645. "case_history": case_history,
  9646. "info": patientPrescriptionInfo,
  9647. "last_info": lastPatientPrescriptionInfo,
  9648. "month_prescriptions": monthPrescriptions,
  9649. "order": order,
  9650. "doctors": doctors,
  9651. "department": department,
  9652. "settle_total": settle_total,
  9653. })
  9654. return
  9655. }
  9656. func (c *HisApiController) GetHisMonthPatientInfo() {
  9657. patient_id, _ := c.GetInt64("patient_id")
  9658. his_patient_id, _ := c.GetInt64("his_patient_id")
  9659. record_date := c.GetString("record_date")
  9660. number := c.GetString("number")
  9661. start_time := c.GetString("start_time")
  9662. end_time := c.GetString("end_time")
  9663. p_type, _ := c.GetInt64("p_type")
  9664. timeLayout := "2006-01-02"
  9665. loc, _ := time.LoadLocation("Local")
  9666. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9667. if err != nil {
  9668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9669. return
  9670. }
  9671. recordDateTime := theTime.Unix()
  9672. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9673. if err != nil {
  9674. }
  9675. startRecordDateTime := startTime.Unix()
  9676. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9677. if err != nil {
  9678. }
  9679. endRecordDateTime := endTime.Unix()
  9680. admin := c.GetAdminUserInfo()
  9681. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9682. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9683. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9684. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9685. var settle_total float64
  9686. for _, item := range monthPrescriptions {
  9687. if len(item.HisPrescriptionProject) > 0 {
  9688. for _, subItem := range item.HisPrescriptionProject {
  9689. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9690. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9691. settle_total = settle_total + total
  9692. }
  9693. }
  9694. if len(item.HisDoctorAdviceInfo) > 0 {
  9695. for _, subItem := range item.HisDoctorAdviceInfo {
  9696. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9697. settle_total = settle_total + total
  9698. }
  9699. }
  9700. }
  9701. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9708. //获取所有科室信息
  9709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9710. c.ServeSuccessJSON(map[string]interface{}{
  9711. "his_info": his_patient_info,
  9712. "xt_info": xt_patient_info,
  9713. "case_history": case_history,
  9714. "info": patientPrescriptionInfo,
  9715. "month_prescriptions": monthPrescriptions,
  9716. "order": order,
  9717. "doctors": doctors,
  9718. "department": department,
  9719. "count": count,
  9720. "drugStockConfig": drugStockConfig,
  9721. "last_info": lastPatientPrescriptionInfo,
  9722. "settle_total": settle_total,
  9723. })
  9724. return
  9725. }
  9726. func (c *HisApiController) GetAllOrder() {
  9727. org_id := c.GetAdminUserInfo().CurrentOrgId
  9728. orders, _ := service.GetNewHisOrderList(org_id)
  9729. c.ServeSuccessJSON(map[string]interface{}{
  9730. "order": orders,
  9731. })
  9732. return
  9733. }
  9734. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9735. newArr = make([]*models.HisOrderInfoTwo, 0)
  9736. for i := 0; i < len(arr); i++ {
  9737. repeat := false
  9738. for j := i + 1; j < len(arr); j++ {
  9739. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9740. repeat = true
  9741. break
  9742. }
  9743. }
  9744. if !repeat {
  9745. newArr = append(newArr, arr[i])
  9746. }
  9747. }
  9748. return
  9749. }
  9750. // 修改处方退库操作 参数传修改之前的处方数据
  9751. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9752. if advice.ExecutionState == 1 {
  9753. //查询该病人该药品是否有库存记录
  9754. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9755. if errcode == gorm.ErrRecordNotFound {
  9756. } else {
  9757. //退库
  9758. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9759. if advice.PrescribingNumberUnit == drug.MinUnit {
  9760. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9761. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9762. //退库
  9763. warehouseInfo := models.DrugWarehouseInfo{
  9764. StockMinNumber: prescribingNumber,
  9765. }
  9766. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9767. operation_time := time.Now().Unix()
  9768. creater := advice.AdviceDoctor
  9769. ctime := time.Now().Unix()
  9770. timeStr := time.Now().Format("2006-01-02")
  9771. timeArr := strings.Split(timeStr, "-")
  9772. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9773. total = total + 1
  9774. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9775. cancelStock := models.DrugCancelStock{
  9776. OrderNumber: orderNumber,
  9777. OperaTime: operation_time,
  9778. OrgId: advice.UserOrgId,
  9779. Creater: creater,
  9780. Ctime: ctime,
  9781. Status: 1,
  9782. ReturnTime: advice.AdviceDate,
  9783. Dealer: info.Dealer,
  9784. Manufacturer: info.Manufacturer,
  9785. Type: 1,
  9786. }
  9787. service.AddSigleDrugCancelStock(&cancelStock)
  9788. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9789. dealer, _ := service.GetDealerById(info.Dealer)
  9790. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9791. cancelStockInfo := models.DrugCancelStockInfo{
  9792. OrderNumber: cancelInfo.OrderNumber,
  9793. CancelStockId: cancelInfo.ID,
  9794. DrugId: info.DrugId,
  9795. Count: info.Count,
  9796. Status: 1,
  9797. Ctime: ctime,
  9798. OrgId: advice.UserOrgId,
  9799. Type: 1,
  9800. Manufacturer: manufactureName.ManufacturerName,
  9801. Dealer: dealer.DealerName,
  9802. Total: 0,
  9803. RetailPrice: info.RetailPrice,
  9804. RetailTotalPrice: info.RetailTotalPrice,
  9805. Price: info.Price,
  9806. RegisterAccount: "",
  9807. Remark: info.Remark,
  9808. BatchNumber: info.BatchNumber,
  9809. MaxUnit: info.CountUnit,
  9810. ProductDate: info.ProductDate,
  9811. ExpiryDate: info.ExpiryDate,
  9812. BatchNumberId: info.WarehouseInfoId,
  9813. }
  9814. flow := models.DrugFlow{
  9815. WarehousingId: 0,
  9816. DrugId: info.DrugId,
  9817. Number: "",
  9818. BatchNumber: info.BatchNumber,
  9819. Count: info.Count,
  9820. UserOrgId: advice.UserOrgId,
  9821. PatientId: 0,
  9822. SystemTime: ctime,
  9823. ConsumableType: 4,
  9824. IsSys: 0,
  9825. WarehousingOrder: "",
  9826. WarehouseOutId: 0,
  9827. WarehouseOutOrderNumber: "",
  9828. IsEdit: 0,
  9829. CancelStockId: cancelStock.ID,
  9830. CancelOrderNumber: cancelStock.OrderNumber,
  9831. Manufacturer: info.Manufacturer,
  9832. Dealer: info.Dealer,
  9833. Creator: advice.UserOrgId,
  9834. UpdateCreator: 0,
  9835. Status: 1,
  9836. Ctime: time.Now().Unix(),
  9837. Mtime: 0,
  9838. Price: info.Price,
  9839. WarehousingDetailId: 0,
  9840. WarehouseOutDetailId: 0,
  9841. CancelOutDetailId: 0,
  9842. ExpireDate: info.ExpiryDate,
  9843. ProductDate: info.ProductDate,
  9844. MaxUnit: info.CountUnit,
  9845. MinUnit: "",
  9846. }
  9847. service.CreatedCancelStock(cancelStockInfo)
  9848. service.CreateDrugFlowOne(flow)
  9849. } else {
  9850. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9851. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9852. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9853. warehouseInfo := models.DrugWarehouseInfo{
  9854. StockMinNumber: prescribingNumber,
  9855. }
  9856. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9857. }
  9858. operation_time := time.Now().Unix()
  9859. creater := advice.AdviceDoctor
  9860. ctime := time.Now().Unix()
  9861. timeStr := time.Now().Format("2006-01-02")
  9862. timeArr := strings.Split(timeStr, "-")
  9863. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9864. total = total + 1
  9865. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9866. cancelStock := models.DrugCancelStock{
  9867. OrderNumber: orderNumber,
  9868. OperaTime: operation_time,
  9869. OrgId: advice.UserOrgId,
  9870. Creater: creater,
  9871. Ctime: ctime,
  9872. Status: 1,
  9873. ReturnTime: advice.AdviceDate,
  9874. Dealer: info.Dealer,
  9875. Manufacturer: info.Manufacturer,
  9876. Type: 1,
  9877. }
  9878. service.AddSigleDrugCancelStock(&cancelStock)
  9879. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9880. dealer, _ := service.GetDealerById(info.Dealer)
  9881. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9882. cancelStockInfo := models.DrugCancelStockInfo{
  9883. OrderNumber: cancelInfo.OrderNumber,
  9884. CancelStockId: cancelInfo.ID,
  9885. DrugId: info.DrugId,
  9886. Count: info.Count,
  9887. Status: 1,
  9888. Ctime: ctime,
  9889. OrgId: advice.UserOrgId,
  9890. Type: 1,
  9891. Manufacturer: manufactureName.ManufacturerName,
  9892. Dealer: dealer.DealerName,
  9893. Total: 0,
  9894. RetailPrice: info.RetailPrice,
  9895. RetailTotalPrice: info.RetailTotalPrice,
  9896. Price: info.Price,
  9897. RegisterAccount: "",
  9898. Remark: info.Remark,
  9899. BatchNumber: info.BatchNumber,
  9900. MaxUnit: info.CountUnit,
  9901. ProductDate: info.ProductDate,
  9902. ExpiryDate: info.ExpiryDate,
  9903. BatchNumberId: info.WarehouseInfoId,
  9904. }
  9905. flow := models.DrugFlow{
  9906. WarehousingId: 0,
  9907. DrugId: info.DrugId,
  9908. Number: "",
  9909. BatchNumber: info.BatchNumber,
  9910. Count: info.Count,
  9911. UserOrgId: advice.UserOrgId,
  9912. PatientId: 0,
  9913. SystemTime: ctime,
  9914. ConsumableType: 4,
  9915. IsSys: 0,
  9916. WarehousingOrder: "",
  9917. WarehouseOutId: 0,
  9918. WarehouseOutOrderNumber: "",
  9919. IsEdit: 0,
  9920. CancelStockId: cancelStock.ID,
  9921. CancelOrderNumber: cancelStock.OrderNumber,
  9922. Manufacturer: info.Manufacturer,
  9923. Dealer: info.Dealer,
  9924. Creator: advice.AdviceDoctor,
  9925. UpdateCreator: 0,
  9926. Status: 1,
  9927. Ctime: time.Now().Unix(),
  9928. Mtime: 0,
  9929. Price: info.Price,
  9930. WarehousingDetailId: 0,
  9931. WarehouseOutDetailId: 0,
  9932. CancelOutDetailId: 0,
  9933. ExpireDate: info.ExpiryDate,
  9934. ProductDate: info.ProductDate,
  9935. MaxUnit: info.CountUnit,
  9936. MinUnit: "",
  9937. }
  9938. service.CreatedCancelStock(cancelStockInfo)
  9939. service.CreateDrugFlowOne(flow)
  9940. }
  9941. }
  9942. }
  9943. return err
  9944. }
  9945. func (this *HisApiController) DeleteNCDS() {
  9946. id, _ := this.GetInt64("id", 0)
  9947. if id > 0 {
  9948. service.DeletePsnNCDSRecordById(id)
  9949. this.ServeSuccessJSON(map[string]interface{}{
  9950. "msg": "删除成功",
  9951. })
  9952. } else {
  9953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9954. return
  9955. }
  9956. }
  9957. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9958. id, _ := c.GetInt64("id")
  9959. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9960. c.ServeSuccessJSON(map[string]interface{}{
  9961. "advice": advice,
  9962. })
  9963. return
  9964. }
  9965. func (c *HisApiController) GetHisMonthChargePatientList() {
  9966. record_date := c.GetString("record_date")
  9967. start_time := c.GetString("start_time")
  9968. end_time := c.GetString("end_time")
  9969. timeLayout := "2006-01-02"
  9970. loc, _ := time.LoadLocation("Local")
  9971. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9972. if err != nil {
  9973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9974. return
  9975. }
  9976. if err != nil {
  9977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9978. return
  9979. }
  9980. recordDateTime := theTime.Unix()
  9981. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9982. if err != nil {
  9983. }
  9984. startRecordDateTime := startTime.Unix()
  9985. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9986. if err != nil {
  9987. }
  9988. endRecordDateTime := endTime.Unix()
  9989. adminInfo := c.GetAdminUserInfo()
  9990. var tempMonthChargePatients []*service.MonthChargePatients
  9991. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9992. for _, item := range tempPatients {
  9993. //过滤没有处方的
  9994. if len(item.HisPrescription) == 0 {
  9995. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9996. }
  9997. }
  9998. c.ServeSuccessJSON(map[string]interface{}{
  9999. "list": tempMonthChargePatients,
  10000. })
  10001. }