1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177 |
- package controllers
-
- import (
- "encoding/json"
- "fmt"
- "math/rand"
- "reflect"
- "strconv"
- "strings"
- "syscall"
- "time"
- "unsafe"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "github.com/mozillazg/go-pinyin"
- "github.com/shopspring/decimal"
- )
-
- type HisApiController struct {
- BaseAuthAPIController
- }
-
- func HisManagerApiRegistRouters() {
-
- beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
- beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
- beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
- beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
- beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
- beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
- beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
- beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
- beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
- beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
- //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
- beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
- beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
- beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
- beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
- beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
- beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
- beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
- beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
- beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
- beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
- beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
- beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
- beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
- beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
-
- //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
- //新增附加费用
- //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
- //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
- beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
- beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
- beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
- beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
- beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
- beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
- beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
- beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
- beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
- beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
- beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
- beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
- beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
-
- beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
- beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
- beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
- beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
-
- beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
-
- beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
-
- beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
-
- beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
- beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
-
- beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
-
- beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
- beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
- beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
-
- beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
-
- beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
-
- beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
-
- beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
-
- beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
- beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
- beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
- beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
- beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
- beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
-
- }
-
- func (c *HisApiController) CheckHisPatient() {
- record_date := c.GetString("record_date")
- patient_id, _ := c.GetInt64("patient_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
- if len(patients) > 1 {
- ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
- if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "msg": "关联",
- "ps": ps,
- "his_patient_id": patients[len(patients)-1].ID,
- "patient_id": patients[len(patients)-1].PatientId,
- })
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "无需关联",
- })
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "无需关联",
- })
- return
- }
- }
- func (c *HisApiController) AssociationHisPrescription() {
- record_date := c.GetString("record_date")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- patient_id, _ := c.GetInt64("patient_id")
- p_ids := c.GetString("p_ids")
- p_ids_arr := strings.Split(p_ids, ",")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
- if his_patient_id == 0 || his_patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "关联处方成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- //func (c *HisApiController) AssociationHisPrescription() {
- // record_date, _ := c.GetInt64("record_date")
- // his_patient_id, _ := c.GetInt64("his_patient_id")
- // patient_id, _ := c.GetInt64("patient_id")
- // p_ids := c.GetString("p_ids")
- // p_ids_arr := strings.Split(p_ids, ",")
- // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
- // if his_patient_id == 0 || his_patient.ID == 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
- // if err == nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "关联处方成功",
- // })
- // return
- // } else {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- // return
- // }
- //}
-
- func (c *HisApiController) GetFaPiaoNumber() {
- max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
- count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
- fmt.Println(count)
- var zero string
- number := count + 1
-
- //if number >= 1000 {
- // zero = "0000" + strconv.FormatInt(number, 10)
- //} else if number >= 10000 {
- // zero = "000" + strconv.FormatInt(number, 10)
- //} else if number >= 100000 {
- // zero = "00" + strconv.FormatInt(number, 10)
- //} else if number >= 1000000 {
- // zero = "0" + strconv.FormatInt(number, 10)
- //} else {
- zero = "0" + strconv.FormatInt(number, 10)
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_number": zero,
- })
- return
- }
-
- func (c *HisApiController) ChangeOrderDesc() {
- id, _ := c.GetInt64("id")
- desc := c.GetString("desc")
- change_type := c.GetString("change_type")
- order, _ := service.GetHisOrderByID(id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- switch change_type {
- case "oth_desc":
- order.OthDesc = desc
- break
- case "cash_pay":
- order.CashPay = desc
-
- break
- case "jifen_pay":
- order.JifenPay = desc
-
- break
- case "band_card_pay":
- order.BandCardPay = desc
-
- break
- case "ali_pay":
- order.AliPay = desc
-
- break
- case "wechat_pay":
- order.WechatPay = desc
- break
- case "fa_piao_number":
- order.FaPiaoNumber = desc
- break
- case "fa_piao_code":
- order.FaPiaoCode = desc
- break
- }
- err := service.SaveHisOrder(&order)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *HisApiController) GetMonthHisPatient() {
- record_date := c.GetString("record_date")
- //order_status, _ := c.GetInt64("type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempPatients []service.NewTempPatients
- //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- // 获取当前时间
- now := time.Now()
- // 获取本月的第一天
- firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
- // 获取下个月的第一天
- nextMonth := firstDay.AddDate(0, 1, 0)
- // 获取本月的最后一天
- lastDay := nextMonth.Add(-time.Nanosecond)
- tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
-
- chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
-
- var patients []service.NewTempPatients
- var patients_two []service.NewTempPatients
-
- if c.GetAdminUserInfo().CurrentOrgId == 10206 {
-
- for _, item := range tempPatients {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- patients_two = append(patients_two, item)
-
- }
- ////过滤掉没挂号的
- //if len(item.HisPatient) > 0 {
- //}
- }
-
- } else {
-
- for _, item := range tempPatients {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
- ////过滤掉没挂号的
- //if len(item.HisPatient) > 0 {
- // patients_two = append(patients_two, item)
- //}
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- "chargePatients": chargePatients,
- })
-
- }
-
- func (c *HisApiController) GetBatchSettleAccounts() {
- order_ids := c.GetString("order_ids")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- adminUser := c.GetAdminUserInfo()
- orders := strings.Split(order_ids, ",")
- var newOrders []models.Orders
- for _, item := range orders {
- order, _ := service.GetHisOrderByIDTenOne(item)
- his, _ := service.GetHisPatientByNumber(order.MdtrtId)
- orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
- orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
- orderInfos = append(orderInfos, orderInfos_two...)
- his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
- //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
- var diagnosis_ids []string
- if his.ID > 0 {
- diagnosis_ids = strings.Split(his.Diagnosis, ",")
-
- } else {
- diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
-
- }
- patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
- var dia_config []*models.HisXtDiagnoseConfig
- var name string
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- dia_config = append(dia_config, diagnosisConfig)
- if len(name) == 0 {
- name = diagnosisConfig.ClassName
-
- } else {
- name = name + "," + diagnosisConfig.ClassName
- }
- }
-
- var bedCostTotal float64 = 0 //床位总费
- var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
- var bedSelfTotal float64 = 0 //床位部分项目自费
- var bedInscpTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
- var operationSelfTotal float64 = 0 //床位部分项目自费
- var operationInscpTotal float64 = 0 //床位部分项目自费
-
- var otherCostTotal float64 = 0 //其他费用
- var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
- var otherSelfTotal float64 = 0 //床位部分项目自费
- var otherInscpTotal float64 = 0 //床位部分项目自费
-
- var materialCostTotal float64 = 0 //材料费
- var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
- var materialSelfTotal float64 = 0 //床位部分项目自费
- var materialInscpTotal float64 = 0 //床位部分项目自费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
- var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
- var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
- var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
- var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
-
- var checkCostTotal float64 = 0 //检查费
- var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
- var checkSelfTotal float64 = 0 //床位部分项目自费
- var checkInscpTotal float64 = 0 //床位部分项目自费
-
- var laboratoryCostTotal float64 = 0 //化验费
- var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
- var laboratorySelfTotal float64 = 0 //床位部分项目自费
- var laboratoryInscpTotal float64 = 0 //床位部分项目自费
-
- var treatCostTotal float64 = 0 //治疗费用
- var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
- var treatSelfTotal float64 = 0 //床位部分项目自费
- var treatInscpTotal float64 = 0 //床位部分项目自费
-
- decimal.DivisionPrecision = 2
-
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
- } else {
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "05" { //治疗费
-
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
- }
-
- miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
-
- printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
-
- doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
-
- roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
-
- var doctor_name string
- if roles.ID == 0 {
- doctor_name = "管理员"
- } else {
- doctor_name = roles.UserName
- }
-
- yiliao_leibie := ""
-
- switch order.MedType {
- case "11":
- yiliao_leibie = "普通门诊"
- break
- case "12":
- yiliao_leibie = "门诊挂号"
- break
- case "13":
- yiliao_leibie = "急诊"
- break
- case "14":
- yiliao_leibie = "门诊特殊病"
- break
- case "15":
- yiliao_leibie = "门诊统筹"
- break
- case "16":
- yiliao_leibie = "门诊慢性病"
- break
- case "21":
- yiliao_leibie = "普通住院"
- break
- }
- var newOrder models.Orders
-
- newOrder.Diagnosis = name
- newOrder.OrderInfos = orderInfos
- newOrder.Number = order.MdtrtId
- newOrder.Date = order.SettleAccountsDate
- newOrder.ChargeAdmin = charge_admin
- newOrder.PrintorAdmin = printor_admin
- newOrder.Order = order
- newOrder.BedCostTotal = bedCostTotal
- newOrder.BedCostSelfTotal = bedCostSelfTotal
- newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
- newOrder.BedSelfTotal = bedSelfTotal
- newOrder.BedInscpTotal = bedInscpTotal
- newOrder.OperationCostTotal = operationCostTotal
- newOrder.OperationCostSelfTotal = operationCostSelfTotal
- newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
- newOrder.OperationSelfTotal = operationSelfTotal
- newOrder.OperationInscpTotal = operationInscpTotal
- newOrder.OtherCostTotal = otherCostTotal
- newOrder.OtherCostSelfTotal = otherCostSelfTotal
- newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
- newOrder.OtherSelfTotal = otherSelfTotal
- newOrder.OtherInscpTotal = otherInscpTotal
-
- newOrder.MaterialCostTotal = materialCostTotal
- newOrder.MaterialCostSelfTotal = materialCostSelfTotal
- newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
- newOrder.MaterialSelfTotal = materialSelfTotal
- newOrder.MaterialInscpTotal = materialInscpTotal
-
- newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
- newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
- newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
- newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
- newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
-
- newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
- newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
- newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
- newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
- newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
-
- newOrder.CheckCostTotal = checkCostTotal
- newOrder.CheckCostSelfTotal = checkCostSelfTotal
- newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
- newOrder.CheckSelfTotal = checkSelfTotal
- newOrder.CheckInscpTotal = checkInscpTotal
-
- newOrder.LaboratoryCostTotal = laboratoryCostTotal
- newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
- newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
- newOrder.LaboratorySelfTotal = laboratorySelfTotal
- newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
-
- newOrder.TreatCostTotal = treatCostTotal
- newOrder.TreatCostSelfTotal = treatCostSelfTotal
- newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
- newOrder.TreatSelfTotal = treatSelfTotal
- newOrder.TreatInscpTotal = treatInscpTotal
-
- newOrder.DoctorInfo = doctor_info
- newOrder.DoctorName = doctor_name
- newOrder.HealthCardNo = order.PsnNo
- newOrder.YiliaoLeibie = yiliao_leibie
- newOrder.Patient = patient
- newOrder.OrgName = miConfig.OrgName
- newOrder.OrgCode = miConfig.Code
- newOrder.OrderNumber = order.Number
- newOrder.HisPatient = his
- newOrder.DiaConfig = dia_config
-
- newOrders = append(newOrders, newOrder)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "orders": newOrders,
- })
- }
-
- func (c *HisApiController) GetTestOrder() {
- order_id, _ := c.GetInt64("order_id")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- adminUser := c.GetAdminUserInfo()
- order, _ := service.GetHisOrderByID(order_id)
- orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
- orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
- orderInfos = append(orderInfos, orderInfos_two...)
- his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
- patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
- var dia_config []*models.HisXtDiagnoseConfig
- var name string
-
- var bedCostTotal float64 = 0 //床位总费
- var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
- var bedSelfTotal float64 = 0 //床位部分项目自费
- var bedInscpTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
- var operationSelfTotal float64 = 0 //床位部分项目自费
- var operationInscpTotal float64 = 0 //床位部分项目自费
-
- var otherCostTotal float64 = 0 //其他费用
- var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
- var otherSelfTotal float64 = 0 //床位部分项目自费
- var otherInscpTotal float64 = 0 //床位部分项目自费
-
- var materialCostTotal float64 = 0 //材料费
- var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
- var materialSelfTotal float64 = 0 //床位部分项目自费
- var materialInscpTotal float64 = 0 //床位部分项目自费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
- var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
- var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
- var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
- var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
-
- var checkCostTotal float64 = 0 //检查费
- var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
- var checkSelfTotal float64 = 0 //床位部分项目自费
- var checkInscpTotal float64 = 0 //床位部分项目自费
-
- var laboratoryCostTotal float64 = 0 //化验费
- var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
- var laboratorySelfTotal float64 = 0 //床位部分项目自费
- var laboratoryInscpTotal float64 = 0 //床位部分项目自费
-
- var treatCostTotal float64 = 0 //治疗费用
- var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
- var treatSelfTotal float64 = 0 //床位部分项目自费
- var treatInscpTotal float64 = 0 //床位部分项目自费
-
- decimal.DivisionPrecision = 2
-
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
- } else {
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "05" { //治疗费
-
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
- otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
-
- }
- }
-
- miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
- printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
- doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
- roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
- var doctor_name string
- if roles.ID == 0 {
- doctor_name = "管理员"
- } else {
- doctor_name = roles.UserName
- }
- yiliao_leibie := ""
- switch order.MedType {
- case "11":
- yiliao_leibie = "普通门诊"
- break
- case "12":
- yiliao_leibie = "门诊挂号"
- break
- case "13":
- yiliao_leibie = "急诊"
- break
- case "14":
- yiliao_leibie = "门诊特殊病"
- break
- case "15":
- yiliao_leibie = "门诊统筹"
- break
- case "16":
- yiliao_leibie = "门诊慢性病"
- break
- case "21":
- yiliao_leibie = "普通住院"
- break
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "diagnosis": name,
- "order_infos": orderInfos,
- "number": order.MdtrtId,
- "date": order.SettleAccountsDate,
- "charge_admin": charge_admin,
- "printor_admin": printor_admin,
- "info": order,
- "order": order,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostSelfTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "bedSelfTotal": bedSelfTotal,
- "bedInscpTotal": bedInscpTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostSelfTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "operationSelfTotal": operationSelfTotal,
- "operationInscpTotal": operationInscpTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostSelfTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "otherSelfTotal": otherSelfTotal,
- "otherInscpTotal": otherInscpTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostSelfTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "materialSelfTotal": materialSelfTotal,
- "materialInscpTotal": materialInscpTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "westernMedicineSelfTotal": westernMedicineSelfTotal,
- "westernMedicineInscpTotal": westernMedicineInscpTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
- "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostSelfTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "checkSelfTotal": checkSelfTotal,
- "checkInscpTotal": checkInscpTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "laboratorySelfTotal": laboratorySelfTotal,
- "laboratoryInscpTotal": laboratoryInscpTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostSelfTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "treatSelfTotal": treatSelfTotal,
- "treatInscpTotal": treatInscpTotal,
- "doctor_info": doctor_info,
- "doctor_name": doctor_name,
- "health_card_no": order.PsnNo,
- "yiliao_leibie": yiliao_leibie,
- "patient": patient,
- "org_name": miConfig.OrgName,
- "org_code": miConfig.Code,
- "order_number": order.Number,
- "his_hospital": his_hospital,
- "dia_config": dia_config,
- })
-
- }
-
- type CustomFundPay struct {
- FundPayType string `json:"fund_pay_type"`
- FundPayamt float64 `json:"fund_payamt"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- }
-
- func (c *PublicApiController) GetBaiLinExportData() {
- data := service.GetBaiLinOrderData()
- fmt.Println(len(data))
- var new_data []*models.NewCustomHisOrder
- for _, item := range data {
- if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
- new_data = append(new_data, item)
- }
-
- }
- fmt.Println(len(new_data))
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": new_data,
- })
- }
-
- func (c *HisApiController) GetHisUnChargePatientList() {
- record_date := c.GetString("record_date")
- sch_type, _ := c.GetInt64("sch_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempPatients []*service.NewTempPatients
- //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- var patients []*service.NewTempPatients
- var patients_two []*service.NewTempPatients
-
- for _, item := range tempPatients {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
-
- //过滤掉没挂号的
- if len(item.HisPatient) > 0 {
- patients_two = append(patients_two, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- })
- }
-
- func (c *HisApiController) GetPrivateExpensesOrder() {
- //id, _ := c.GetInt64("id")
- //record_time := c.GetString("record_time")
- order_id, _ := c.GetInt64("order_id")
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //
- //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- //if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- order, _ := service.GetHisOrderByID(order_id)
-
- his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
- his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
-
- //var config []*models.HisXtDiagnoseConfig
-
- var name string
- if order.PType == 1 {
- diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- if len(name) == 0 {
- name = diagnosisConfig.ClassName
-
- } else {
- name = name + "," + diagnosisConfig.ClassName
- }
- }
- } else {
- diagnosis_ids := strings.Split(his.Diagnosis, ",")
-
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- if len(name) == 0 {
- name = diagnosisConfig.ClassName
-
- } else {
- name = name + "," + diagnosisConfig.ClassName
- }
- }
- }
-
- var bedCostTotal float64 = 0 //床位总费
- //var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- //var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- //var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- //var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- //var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- //var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
-
- var laboratoryCostTotal float64 = 0 //化验费
- //var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- //var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
-
- for _, item := range orderInfos {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- fmt.Println("CostClassify")
- fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "14"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "14"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
- break
- case 7:
- item.MedChrgitmType = "14"
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- default:
- item.MedChrgitmType = "14"
- break
- }
- }
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
- if order.IsMedicineInsurance != 1 {
- order.PsnCashPay = order.MedfeeSumamt
- }
-
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "02" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- }
-
- org, _ := service.GetOrgById(adminUser.CurrentOrgId)
- printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
- var dia_config []*models.HisXtDiagnoseConfig
- var diagnosis_ids []string
- if his.ID > 0 {
- diagnosis_ids = strings.Split(his.Diagnosis, ",")
-
- } else {
- diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
-
- }
-
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- dia_config = append(dia_config, diagnosisConfig)
- }
-
- var rf []CustomFundPay
- json.Unmarshal([]byte(order.SetlDetail), &rf)
- patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "order_infos": orderInfos,
- "diagnosis": name,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "zhenChaCostSelfTotal": zhenChaCostTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "charge_admin": charge_admin,
- "printor_admin": printor_admin,
- "org_name": org.OrgName,
- "org_code": miConfig.Code,
- "name": patient.Name,
- "number": order.MdtrtId,
- "date": order.SettleAccountsDate,
- "info": order,
- "new_order": order,
- "his_hospital": his_hospital,
- "his": his,
- "funds": rf,
- "dia_config": dia_config,
- })
-
- }
-
- func (c *HisApiController) RefudDetail() {
- order_id, _ := c.GetInt64("order_id")
- order, _ := service.GetHisOrderByID(order_id)
- adminUser := c.GetAdminUserInfo()
- service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "撤销成功",
- })
- }
-
- func (c *HisApiController) Sscard() {
- //r := CardInit()
- //if r == 0 {
- // GetBaseInfo()
- //}
- //c.ServeSuccessJSON(map[string]interface{}{
- // "list": "11",
- //})
-
- }
-
- func GetBaseInfo() error {
- //handle := syscall.MustLoadDLL("SSCard.dll")
- //ReadCardBas := handle.MustFindProc("ReadCardBas")
- //
- //str := make([]byte, 256)
- //str1 := make([]byte, 256)
- //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
- //if ferr != nil {
- // fmt.Println("ReadCardBas 报错", ferr.Error())
- // return ferr
- //}
- //
- //fmt.Println(string(str))
- //
- //fmt.Println(r)
- return nil
- }
-
- func CardInit() int {
- //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
- //add := DllTestDef.MustFindProc("Init")
- //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
- //if err != nil {
- // fmt.Println("SSCard的运算结果为:", ret)
- //}
- //result := int(ret)
- return 0
- }
-
- func IntPtr(n int) uintptr {
- return uintptr(n)
- }
-
- func StrPtr(s string) uintptr {
- return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
- }
-
- func (c *HisApiController) GetHisPatientList() {
- //types, _ := c.GetInt64("type", 0)
- record_date := c.GetString("record_date")
- sch_type, _ := c.GetInt64("sch_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
- patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
-
- //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
-
- //获取当前用户的信息
- adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- //var aa []service.PatientThree
-
- noElementsSlice := make([]service.PatientThree, 0)
- c.ServeSuccessJSON(map[string]interface{}{
-
- "list": patients,
- "list_two": patients_two,
- "list_three": noElementsSlice,
-
- "info": adminUserInfo,
- "doctors": doctors,
- "department": department,
- })
- }
-
- type CustomTemplate struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
- RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
- PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
- Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
- PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
- PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
- HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
- HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
- MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
- }
-
- func (c *HisApiController) GetHisPatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- number := c.GetString("number")
- //start_time := c.GetString("start_time")
- //end_time := c.GetString("end_time")
- p_type, _ := c.GetInt64("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- //if err != nil {
- //
- //}
- //startRecordDateTime := startTime.Unix()
- //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- //if err != nil {
- //
- //}
- //endRecordDateTime := endTime.Unix()
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
- //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
-
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
-
- var prescriptions []*models.HisPrescription
- var last_prescriptions []*models.HisPrescription
- var sch_prescriptions []CustomTemplate
- last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- if p_type == 1 { //住院
- prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
- for _, item := range prescriptions {
- for _, subItem := range item.HisDoctorAdviceInfo {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
- }
- }
- }
- last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
- } else { //门诊
- prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
- for _, item := range prescriptions {
- for _, subItem := range item.HisDoctorAdviceInfo {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
- }
- }
- }
- last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
- }
-
- sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
- if sch.ID > 0 {
- var week string
- t := time.Now()
- switch t.Weekday().String() {
- case "Monday":
- week = "周一"
- break
- case "Tuesday":
- week = "周二"
-
- break
- case "Wednesday":
- week = "周三"
-
- break
- case "Thursday":
- week = "周四"
-
- break
- case "Friday":
- week = "周五"
-
- break
- case "Saturday":
- week = "周六"
-
- break
- case "Sunday":
- week = "周日"
-
- break
-
- }
-
- mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
- temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
-
- //根据推送频率组装新的数组
- for _, item := range temp_sch_prescriptions {
- var cus CustomTemplate
- cus.ID = item.ID
- cus.UserOrgId = item.UserOrgId
- cus.PatientId = item.PatientId
- cus.MedType = item.MedType
- cus.RecordDate = item.RecordDate
- cus.Type = item.Type
- cus.PType = item.PType
- for _, subItem := range item.HisPrescriptionAdviceTemplate {
- if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
- if subItem.FrequencyType == 1 { //每次必推
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 { //按照天数频率
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
- if len(advices) == 0 {
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
- }
- }
- }
-
- for _, subItem := range item.HisPrescriptionProjectTemplate {
-
- if subItem.Type == 2 {
- if subItem.XtHisProject.MedicalStatus != 1 {
- if subItem.FrequencyType == 1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
- if len(projects) == 0 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
- }
-
- }
-
- } else if subItem.Type == 3 {
- if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
- if subItem.FrequencyType == 1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
- if len(projects) == 0 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
- }
- }
- }
- }
- sch_prescriptions = append(sch_prescriptions, cus)
- }
-
- for _, item := range sch_prescriptions {
- if len(item.HisPrescriptionProjectTemplate) == 0 {
- item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
- }
- if len(item.HisPrescriptionAdviceTemplate) == 0 {
- item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
- }
-
- }
- }
- _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range sch_prescriptions {
- for _, subItem := range item.HisPrescriptionAdviceTemplate {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
-
- if admin.CurrentOrgId != 10598 {
-
- service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
- service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
- }
-
- }
- }
- }
- }
-
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range sch_prescriptions {
- for _, subItem := range item.HisPrescriptionProjectTemplate {
- if subItem.Type == 3 {
- info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
- if info.Price > 0 {
- subItem.GoodInfo.PackingPrice = info.Price
-
- if admin.CurrentOrgId != 10598 {
-
- service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
- service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
- }
-
- }
- }
- }
- }
- }
-
- //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
- //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
-
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
-
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
-
- beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
-
- LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
-
- prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- //"month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "sch_prescriptions": sch_prescriptions,
- "last_prescriptions": last_prescriptions,
- "schedule": sch,
- "count": count,
- "drugStockConfig": drugStockConfig,
- "last_info": lastPatientPrescriptionInfo,
- "befor": beforThrity,
- "LastCaseHistory": LastCaseHistory,
- "prescriptionInfo": prescriptionInfo,
- })
- return
-
- }
-
- func (c *HisApiController) GetHisPrescriptionConfig() {
- adminInfo := c.GetAdminUserInfo()
- //获取医嘱模版
- advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
- //获取所有基础药
- drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
- _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range drugs {
- var index = 0
- for _, subItem := range item.OtherDrugWarehouseInfo {
- if index == 0 {
- index = index + 1
- if subItem.RetailPrice > 0 {
- item.MinPrice = subItem.RetailPrice
-
- }
- }
- }
- }
- }
-
- manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
- drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- //获取诊断信息
- sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
- diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
- additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
-
- patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
- //获取是否开启保存耗材出库的开关
- goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "advices_template": advices,
- "drugways": drugways,
- "efs": efs,
- "doctors": doctors,
- "department": department,
- "sick": sick,
- "additions": additions,
- "diagnose": diagnose,
- "manufacturers": manufacturers,
- "goodOutOpen": goodOutOpen,
- "patientDiagnose": patientDiagnose,
- })
- }
- if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
- //获取所有基础药
- drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
- _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range drugs {
- var index = 0
- for _, subItem := range item.OtherDrugWarehouseInfo {
- if index == 0 {
- index = index + 1
- if subItem.RetailPrice > 0 {
- item.MinPrice = subItem.RetailPrice
- }
- }
- }
- }
- }
-
- manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
- drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- //获取诊断信息
- sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
- diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
- additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
- //获取是否开启保存耗材出库的开关
- goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
- patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "advices_template": advices,
- "drugways": drugways,
- "efs": efs,
- "doctors": doctors,
- "department": department,
- "sick": sick,
- "additions": additions,
- "diagnose": diagnose,
- "manufacturers": manufacturers,
- "goodOutOpen": goodOutOpen,
- "patientDiagnose": patientDiagnose,
- })
- }
- }
-
- func (c *HisApiController) CreateHisPrescription() {
- record_date := c.GetString("record_date")
- patient_id, _ := c.GetInt64("patient_id")
- reg_type, _ := c.GetInt64("reg_type")
- diagnose := c.GetString("diagnose")
- sick_type, _ := c.GetInt64("sick_type")
- sick_history := c.GetString("sick_history")
- doctor_id, _ := c.GetInt64("doctor", 0)
- department, _ := c.GetInt64("department", 0)
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- p_type, _ := c.GetInt64("p_type")
- patient_diagnose := c.GetString("patient_diagnose")
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //edit, src := GetCompareData(dataBody)
- //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
- //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
- //fmt.Println(drugResult)
- //fmt.Println(goodResult)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetAdminUserInfo()
- recordDateTime := theTime.Unix()
-
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
- if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
- lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
- if len(lists) == 1 {
- his_patient_id = lists[0].ID
- }
- }
-
- patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
-
- //自动出库的开关开启
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- //自动出库
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- //已发药和已收费限制逻辑
- isMidicine := false
- isCharge := false
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if id > 0 {
- new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
- if err != nil {
- if new_prescription.OrderStatus == 4 {
- isCharge = true
- }
- }
- }
-
- }
- }
- }
- if isMidicine == true {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
- return
- }
- if isCharge == true {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
- return
- }
-
- // 开始主事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
-
- //药品发药出库
- if pharmacyConfig.IsOpen == 1 {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- if len(advices) > 0 {
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
-
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
-
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方盘点库存是否充足
- if advicelist.ID == 0 {
- all_count, _ := strconv.ParseFloat(totals, 64)
- if prescribingNumberUnit == drug.MinUnit {
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
-
- if prescribing_number > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
- }
-
- }
-
- }
- if prescribingNumberUnit == drug.MaxUnit {
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
- if num > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
- }
-
- }
- }
- }
-
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
- //不使用保存处方出库
- if drugOutConfig.IsOpen != 1 {
- //修改处方
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
- var prescribingNumber string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方
- if advicelist.ID == 0 {
-
- all_count, _ := strconv.ParseFloat(totals, 64)
- if prescribingNumberUnit == drug.MinUnit {
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
- if prescribing_number > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
- return
- }
- }
-
- }
- } else {
- if prescribingNumberUnit == drug.MaxUnit {
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if num > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- }
-
- }
- }
- }
- //修改处方
- if advicelist.ID > 0 {
-
- var device_number int64
-
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt * drug.MinNumber
- }
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt
- }
-
- var number_count int64
- if prescribingNumberUnit == drug.MaxUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt * drug.MinNumber
- }
- if prescribingNumberUnit == drug.MinUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt
- }
-
- //如果修改的数量大于之前修改的数量
- if (number_count - device_number) > 0 {
- //如果修改的差数量 大于库存数量
- if drug.IsUse != 1 {
- if (number_count - device_number) > total_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- //已发药和已收费限制逻辑
- //执行出库的逻辑
- if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
- //校验库存总量
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- if len(advices) > 0 {
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
-
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
-
- //新增处方
- if advicelist.ID == 0 {
- all_count, _ := strconv.ParseFloat(totals, 64)
-
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
-
- if prescribingNumberUnit == drug.MinUnit {
-
- if drug.IsUse != 1 {
-
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if prescribing_number > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if prescribing_number > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- if prescribingNumberUnit == drug.MaxUnit {
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if num > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if num > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
- }
- }
-
- //不是保存处方出库
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
- if drugOutConfig.IsOpen != 1 {
- //修改处方
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
- var prescribingNumber string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方
- if advicelist.ID == 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
-
- all_count, _ := strconv.ParseFloat(totals, 64)
-
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if prescribingNumberUnit == drug.MinUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if prescribing_number > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if prescribing_number > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- } else {
- if prescribingNumberUnit == drug.MaxUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if num > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if prescribing_number > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- }
- }
- //修改处方
- if advicelist.ID > 0 {
-
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
-
- var device_number int64
-
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt * drug.MinNumber
-
- }
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt
-
- //回退库存
- }
-
- var number_count int64
- if prescribingNumberUnit == drug.MaxUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt * drug.MinNumber
- //回退库存
- }
- if prescribingNumberUnit == drug.MinUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt
- //回退库存
- }
-
- //如果修改的数量大于之前修改的数量
- if (number_count - device_number) > 0 {
- //如果修改的差数量 大于库存数量
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if total_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if (number_count - device_number) > total_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
-
- if (number_count - device_number) > batch_number_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- // 查询该药品最后一次出库记录
- outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
-
- var out_count int64
- var in_count int64
- var stock_max_number int64
- var stock_min_number int64
- for _, it := range outInfo {
- if it.CountUnit == drug.MaxUnit {
- it.Count = it.Count * drug.MinNumber
- }
- out_count += it.Count
- warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
-
- stock_max_number = warehouseInfoList.StockMaxNumber
- stock_min_number = warehouseInfoList.StockMinNumber
- in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
-
- }
-
- if out_count > 0 {
- if (number_count - device_number) > in_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
- return
- }
- }
- // 未出库
- if out_count == 0 {
- var sum_in_count int64
- warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
- //如果修改的数量大于有库存的第一个批次
- if number_count > sum_in_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
- }
-
- }
-
- }
-
- //药品发药
- //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
- //不使用药品发药的功能
- //if pharmacyConfig.IsOpen != 1 {
- // if device_number != number_count {
- //
- // //查询该药品的出库记录
- // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
- // if len(outListExport) > 0 {
- // //
- // for _, item := range outListExport {
- // //回退库存
- // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
- // }
- // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- // var stock_max_number int64
- // var stock_min_number int64
- //
- // if number_count >= drug.MinNumber {
- //
- // stock_max_number = device_number / drug.MinNumber
- // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
- //
- // stock_min_number = device_number % drug.MinNumber
- // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
- //
- // } else {
- //
- // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
- //
- // }
- // }
- //
- // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
- // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
- // }
- // }
- // }
- //
- // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
- // var sum_count int64
- // orgId := c.GetAdminUserInfo().CurrentOrgId
- // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
- // for _, its := range stockInfo {
- // if its.MaxUnit == drug.MaxUnit {
- // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
- // }
- // sum_count += its.StockMaxNumber + its.StockMinNumber
- // }
- // //更新字典里面的库存
- // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
- //
- // //剩余库存
- // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
- //
- // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
- // //减少出库数量
- // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
- //
- // }
- //}
-
- }
- }
- }
-
- //保存处方开药
- if drugOutConfig.IsOpen == 1 {
- //修改处方
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
- var prescribingNumber string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方
- if advicelist.ID == 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
- all_count, _ := strconv.ParseFloat(totals, 64)
- if prescribingNumberUnit == drug.MinUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if prescribing_number > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if prescribing_number > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- } else {
- if prescribingNumberUnit == drug.MaxUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if all_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if num > all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if prescribing_number > batch_number_all_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- }
- }
- //修改处方
- if advicelist.ID > 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
-
- var device_number int64
-
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt * drug.MinNumber
- }
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt
- }
-
- var number_count int64
- if prescribingNumberUnit == drug.MaxUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt * drug.MinNumber
- }
- if prescribingNumberUnit == drug.MinUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt
- }
-
- //如果修改的数量大于之前修改的数量
- if (number_count - device_number) > 0 {
- //如果修改的差数量 大于库存数量
- if drug.IsUse != 1 {
- if drug.IsProject == 0 || drug.IsProject == 2 {
- if total_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if (number_count - device_number) > total_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 {
- if (number_count - device_number) > batch_number_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- //查询历史出库数据总批次
- // 查询该药品最后一次出库记录
- outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
- var out_count int64
- var in_count int64
- var stock_max_number int64
- var stock_min_number int64
- for _, it := range outInfo {
- if it.CountUnit == drug.MaxUnit {
- it.Count = it.Count * drug.MinNumber
- }
- out_count += it.Count
- warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
- stock_max_number = warehouseInfoList.StockMaxNumber
- stock_min_number = warehouseInfoList.StockMinNumber
- in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
-
- }
-
- if out_count > 0 {
- if (number_count - device_number) > in_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
- return
- }
- }
-
- // 未出库
- if out_count == 0 {
- var sum_in_count int64
- warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
- if sum_in_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- //如果修改的数量大于有库存的第一个批次
- if number_count > sum_in_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
- }
-
- }
- }
- }
- }
- }
-
- }
- }
- }
- }
- }
- }
- }
-
- //校验耗材库存
- if goodOutConfig.IsOpen == 1 {
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
-
- items := item.(map[string]interface{})
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
-
- for _, project := range projects {
- var project_id int64
- var project_type int64
- var totals float64
- var project_name string
- var parsetotal int64
- var id int64
- if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
- project_id = int64(project.(map[string]interface{})["project_id"].(float64))
- }
- if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
- project_type = int64(project.(map[string]interface{})["type"].(float64))
- }
- if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
- total, _ := project.(map[string]interface{})["total"].(string)
- totals, _ = strconv.ParseFloat(total, 64)
- }
-
- if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
- project_name = project.(map[string]interface{})["project_name"].(string)
-
- }
- if project_type == 3 {
-
- //查找该耗材的出库记录
- goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
-
- if len(goodWarehouseInfo) == 0 {
- //查询耗材库存
- list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
- stock_counts := strconv.FormatInt(stock_count, 10)
- stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
- if stock_total_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- if totals > stock_total_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- }
-
- if len(goodWarehouseInfo) > 0 {
- //查询该患者耗材的历史数据
- ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
- count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
- //数量发生改变
- if parsetotal != count {
- //如果现在的数量大于历史数量,就要看库存是否足够
- if parsetotal > count {
-
- //查询耗材所有库存
- list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
-
- //库存不足
- if stock_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- if (parsetotal - count) > stock_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- }
- }
- }
-
- }
-
- }
- }
- }
- }
- }
- }
- }
-
- //不使用耗材保存处方出库
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
-
- items := item.(map[string]interface{})
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
-
- for _, project := range projects {
-
- var project_id int64
- var project_type int64
- var totals float64
- var project_name string
- var parsetotal int64
- var id int64
-
- if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
- id = int64(project.(map[string]interface{})["id"].(float64))
- }
- if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
- project_id = int64(project.(map[string]interface{})["project_id"].(float64))
- }
- if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
- project_type = int64(project.(map[string]interface{})["type"].(float64))
- }
- if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
- total, _ := project.(map[string]interface{})["total"].(string)
- totals, _ = strconv.ParseFloat(total, 64)
- parsetotal, _ = strconv.ParseInt(total, 10, 64)
- }
-
- if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
- project_name = project.(map[string]interface{})["project_name"].(string)
-
- }
- if project_type == 3 {
-
- //查找该耗材的出库记录
- goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
-
- //没有出库记录
- if len(goodWarehouseInfo) == 0 {
- //查询耗材库存
- list, _ := service.GetGoodWarehouseInfoSeven(project_id)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
- stock_counts := strconv.FormatInt(stock_count, 10)
- stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
- if stock_total_count == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- if totals > stock_total_count {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- //查找今日该患者已经出库的所有耗材
- goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
-
- for _, item := range goodList {
-
- goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
- var flush_count int64
- for _, it := range goodListSix {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
- creater := adminInfo.AdminUser.Id
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
-
- service.DeleteAutoWarehouse(patient_id, recordDateTime)
-
- }
-
- //有出库记录
- if len(goodWarehouseInfo) > 0 {
- //查询该患者耗材的历史数据
- ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
-
- count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
-
- //数量发生改变
- if parsetotal != count {
- //查找今日该患者已经出库的所有耗材
- goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
-
- for _, item := range goodList {
-
- goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
- var flush_count int64
- for _, it := range goodListSix {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
-
- //减少出库数量
- creater := adminInfo.AdminUser.Id
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- //查询默认仓库
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
- }
-
- service.DeleteAutoWarehouse(patient_id, recordDateTime)
-
- }
-
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- var hpInfo models.HisPrescriptionInfo
- if info.ID == 0 {
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
-
- hpInfo = models.HisPrescriptionInfo{
- HisPatientId: his_patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: theTime.Unix(),
- PatientId: patient_id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: adminInfo.AdminUser.Id,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: p_number,
- PrescriptionStatus: 1,
- Doctor: role.UserName,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: p_type,
- PatientDiagnosis: patient_diagnose,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: theTime.Unix(),
- Sourse: 1,
- PatientId: patient_id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- } else {
- hpInfo = models.HisPrescriptionInfo{
- ID: info.ID,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: info.RecordDate,
- PatientId: info.PatientId,
- Status: 1,
- Ctime: info.Ctime,
- Mtime: time.Now().Unix(),
- Creator: info.Creator,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: info.PrescriptionNumber,
- Doctor: role.UserName,
- PrescriptionStatus: info.PrescriptionStatus,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: info.PType,
- HisPatientId: info.HisPatientId,
- PatientDiagnosis: patient_diagnose,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: info.RecordDate,
- Sourse: 1,
- PatientId: info.PatientId,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- }
-
- //定义切片
- var adviceList []models.HisDoctorAdviceInfo
- var projectList []models.HisPrescriptionProject
-
- if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- var tempPrescription *models.HisPrescription
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- // 开始外部循环的事务
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
- tempPrescription = &new_prescription
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- if med_type == "0" {
- med_type = "14"
- }
-
- //if order_status == 0 {
- // order_status = 1
- //}
-
- if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
- utils.ErrorLog("pre_time")
- }
- preTime, _ := items["pre_time"].(string)
- fmt.Println("preTime", preTime)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
- //result := strings.Split(preTime, " ")
- theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- pTime := theTime2.Unix()
-
- ctime := time.Now().Unix()
-
- if tempPrescription.ID == 0 {
- prescription := &models.HisPrescription{
- ID: 0,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- Doctor: role.UserName,
- HisPatientId: his_patient_id,
- OrderStatus: 1,
- BatchNumber: "",
- PrescriptionNumber: hpInfo.PrescriptionNumber,
- PreTime: pTime,
- PType: p_type,
- MedType: med_type,
- }
- tempPrescription = prescription
- service.SaveHisPrescriptionOne(tx, tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- } else {
- tempPrescription.ID = id
- tempPrescription.Type = types
- tempPrescription.Modifier = adminInfo.AdminUser.Id
- tempPrescription.Mtime = time.Now().Unix()
- tempPrescription.Doctor = role.UserName
- //tempPrescription.OrderStatus = order_status
- tempPrescription.PreTime = pTime
- tempPrescription.MedType = med_type
- service.SaveHisPrescriptionOne(tx, tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- }
- //service.SaveHisPrescription(prescription)
- //更改患者挂号状态
- _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
- fmt.Println("更改失败", err2)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- if len(advices) > 0 {
- for _, advice := range advices {
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- var s models.HisDoctorAdviceInfo
- s.PrescriptionId = tempPrescription.ID
- s.AdviceType = 2
- s.AdviceDoctor = doctor_id
- s.StopState = 2
- s.ExecutionState = 2
- s.AdviceDate = theTime3.Unix()
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.RecordDate = theTime3.Unix()
- s.StartTime = tempPrescription.PreTime
- s.Groupno = groupNo
-
- s.PatientId = patient_id
- s.HisPatientId = his_patient_id
- s.StartTime = pTime
- s.IsSettle = 2
- errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- s.StartTime = pTime
- var total_count int64 //处方总库存
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(s.DrugId)
- prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven * medical.MinNumber
- }
-
- if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- total_count += prescribingNumberSeven
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
- if s.Price != lastWarehouse.RetailPrice {
- s.Price = lastWarehouse.RetailPrice
- }
- if s.Price == 0 {
- if lastWarehouse.ID == 0 {
- lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
- s.Price = lastWarehouseTwo.RetailPrice
- }
-
- }
- }
-
- //查询保存处方出库开关是否打开
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
-
- if s.PatientId != 30038 {
- if drugOutConfig.IsOpen == 1 {
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
- // 查询该药品最后一次出库记录
- druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
-
- var is_user_total int64
- var no_user_total int64
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
-
- no_user_total += prescribingNumberSevenTy * drug.MinNumber
- }
-
- if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- no_user_total += prescribingNumberSevenTy
- }
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- no_user_total += prescribingNumberSevenTy
- }
- if len(druginfo) > 0 {
- for _, it := range druginfo {
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- it.Count = it.Count * drug.MinNumber
- is_user_total += it.Count
- }
-
- if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- is_user_total += it.Count
- }
-
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- is_user_total += it.Count
-
- }
- }
-
- }
-
- //fmt.Println("药品名称----------------------", drug.DrugName)
- //fmt.Println("药品名称----------------------", drug.IsUse)
- //fmt.Println("is_user_total-------------------------", is_user_total)
- //fmt.Println("no_user_total-------------------------", no_user_total)
-
- if is_user_total != no_user_total {
- //出库
- if drug.IsUse == 2 {
- creater := adminInfo.AdminUser.Id
- newadviceInfo := &models.HisDoctorAdviceInfo{
- ID: s.ID,
- UserOrgId: s.UserOrgId,
- PatientId: s.PatientId,
- HisPatientId: s.HisPatientId,
- AdviceType: s.AdviceType,
- AdviceDate: s.AdviceDate,
- StartTime: s.StartTime,
- AdviceName: s.AdviceName,
- AdviceDesc: s.AdviceDesc,
- ReminderDate: s.ReminderDate,
- SingleDose: s.SingleDose,
- SingleDoseUnit: s.SingleDoseUnit,
- PrescribingNumber: s.PrescribingNumber,
- PrescribingNumberUnit: s.PrescribingNumberUnit,
- DeliveryWay: s.DeliveryWay,
- ExecutionFrequency: s.ExecutionFrequency,
- AdviceDoctor: s.AdviceDoctor,
- Status: s.Status,
- CreatedTime: s.CreatedTime,
- UpdatedTime: s.UpdatedTime,
- AdviceAffirm: s.AdviceAffirm,
- Remark: s.Remark,
- StopTime: s.StopTime,
- StopReason: s.StopReason,
- StopDoctor: s.StopDoctor,
- StopState: s.StopState,
- ParentId: s.ParentId,
- ExecutionTime: s.ExecutionTime,
- ExecutionStaff: s.ExecutionStaff,
- ExecutionState: s.ExecutionState,
- Checker: s.Checker,
- RecordDate: s.RecordDate,
- DialysisOrderId: s.DialysisOrderId,
- CheckTime: s.CheckTime,
- CheckState: s.CheckState,
- DrugSpec: s.DrugSpec,
- DrugSpecUnit: s.DrugSpecUnit,
- Groupno: s.Groupno,
- RemindType: s.RemindType,
- FrequencyType: s.FrequencyType,
- DayCount: s.DayCount,
- WeekDay: s.WeekDay,
- TemplateId: s.TemplateId,
- Modifier: s.Modifier,
- DrugId: s.DrugId,
- Price: s.Price,
- PrescriptionId: s.PrescriptionId,
- MedListCodg: s.MedListCodg,
- FeedetlSn: s.FeedetlSn,
- Day: s.DayCount,
- ChildDoctorAdvice: nil,
- Drug: models.Drug{},
- Diagnosis: s.Diagnosis,
- Way: s.Way,
- HospApprFlag: s.HospApprFlag,
- LmtUsedFlag: s.LmtUsedFlag,
- HisOrderInfo: models.HisOrderInfo{},
- IsMedicine: s.IsMedicine,
- ExecutionFrequencyId: s.ExecutionFrequencyId,
- Child: nil,
- IsSettle: s.IsSettle,
- IsMobile: s.IsMobile,
- IsSelfDrug: s.IsSelfDrug,
- DrugWayCount: s.DrugWayCount,
- }
-
- var history_count int64
- var local_count int64
- //查找已经开过的医嘱信息
- adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
-
- local_count += prescribingNumberSevenTy * drug.MinNumber
- }
-
- if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- local_count += prescribingNumberSevenTy
- }
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- local_count += prescribingNumberSevenTy
- }
-
- if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
-
- history_count += prescribingNumberSevenTy * drug.MinNumber
- }
-
- if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- history_count += prescribingNumberSevenTy
- }
-
- if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
- history_count += prescribingNumberSevenTy
- }
-
- //如果当前出库数量大于历史出库数量则需要出库
- if local_count > history_count {
- //按最小单位出库
- var cha_count = local_count - history_count
-
- newadviceInfo.PrescribingNumber = float64(cha_count)
- newadviceInfo.PrescribingNumberUnit = drug.MinUnit
-
- service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
- }
-
- //如果当前出库数量小于历史出库数量则需要退库
- if local_count < history_count {
-
- var cha_count = history_count - local_count
-
- service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
-
- service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
- }
-
- if local_count == history_count {
- if is_user_total == 0 {
- service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
- }
-
- }
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- //更新基础库存
- service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
- //剩余库存
- service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
-
- over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
- service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
-
- //创建医嘱
- service.CreateHisDoctorAdviceOne(&s, tx)
-
- adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
-
- outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
-
- if len(outInfoTwo) > 0 {
- for _, item := range outInfoTwo {
- service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
- }
- }
-
- drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
- if len(drugAutoDetail) > 0 {
- for _, item := range drugAutoDetail {
- service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
- }
- }
- }
- }
- }
-
- //记录日志
- byterequest, _ := json.Marshal(s)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: s.UserOrgId,
- PatientId: s.PatientId,
- AdminUserId: adminInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端新建his医嘱",
- RecordDate: s.AdviceDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
-
- //存储切片中
- adviceList = append(adviceList, s)
-
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
-
- if s.UserOrgId != 10206 {
- if s.ID == 0 {
- //查询改药品是否已经停用
- base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
-
- if base.ID > 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
- return
-
- }
-
- drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
-
- if drugMedical.SumCount == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
- return
-
- }
- }
- }
-
- //赤峰
- if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
-
- drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
-
- info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
-
- if info.RetailPrice > 0 {
- if s.DeliveryWay == "口服" {
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- s.Price = drug.RetailPrice
- }
- if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- s.Price = info.RetailPrice
- }
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- s.Price = info.RetailPrice
- }
- }
-
- }
- }
-
- service.CreateHisDoctorAdviceOne(&s, tx)
-
- tx.Commit()
-
- keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(keySix, "", time.Second)
- keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyFive, "", time.Second)
- keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keyEight, "", time.Second)
- defer redis.Close()
-
- }
- }
-
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- var p models.HisPrescriptionProject
- p.PrescriptionId = tempPrescription.ID
-
- p.PatientId = patient_id
- p.RecordDate = theTime3.Unix()
- p.Doctor = doctor_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.HisPatientId = his_patient_id
- p.Status = 1
- p.StartTime = pTime
-
- errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- if p.ID == 0 {
- p.IsOut = 2
- }
- if p.ID > 0 {
- projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
- p.IsOut = projectDetail.IsOut
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if p.Type == 3 {
- lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
- if p.Price != lastWarehouse.PackingPrice {
- p.Price = lastWarehouse.PackingPrice
- }
- if p.Price == 0 {
- lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
- p.Price = lastWarehouseTwo.PackingPrice
- }
- if p.Unit == "" {
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- p.Unit = goodInfoOne.PackingUnit
- }
- }
-
- }
-
- if adminInfo.CurrentOrgId != 10206 {
- if p.Type == 3 {
-
- if p.ID == 0 {
- //查询该耗材是否停用
- goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
- //表示该耗材已经停用,不能保存
- if goodInfoSeven.ID == 0 {
- tx.Rollback()
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
-
- return
-
- }
-
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- if goodInfoOne.SumCount == 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
-
- return
- }
- }
-
- }
- }
-
- //查询保存耗材出库开关是否打开
- if p.PatientId != 30038 {
- if goodOutConfig.IsOpen == 1 {
- //耗材出库
- if p.Type == 3 {
-
- //对比当前数据和历史出库数据
-
- historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
-
- historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
-
- nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
-
- //fmt.Println("p----------------------------------------------------", p.ProjectId)
- //fmt.Println("p----------------------------------------------------", nowCount)
- //fmt.Println("p----------------------------------------------------", historyCount)
- //如果当前处方数量大于历史数据,则需要出库
- if nowCount > historyCount {
-
- var cha_count int64
- cha_count = nowCount - historyCount
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: nowtime,
- Type: 1,
- StorehouseId: storeConfig.StorehouseOutInfo,
- IsCheck: 1,
- IsSys: 1,
- }
- //查询是否生成出库单
- out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
- if out.ID == 0 {
- service.AddNewSigleWarehouseOut(&warehouseOut, tx)
- }
-
- lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
-
- goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
- houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
-
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: goodObj.GoodTypeId,
- GoodId: p.ProjectId,
- PatientId: p.PatientId,
- RecordDate: p.RecordDate,
- UserOrgId: adminInfo.CurrentOrgId,
- Count: cha_count,
- Ctime: time.Now().Unix(),
- Creater: creater,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- ProjectId: p.ID,
- }
- //出库
- service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
-
- }
-
- //如果当前处方数量小于历史数据,怎需要退库
- if nowCount < historyCount {
-
- var cha_count int64
- cha_count = historyCount - nowCount
- goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- newPrescriptionProject := &models.HisPrescriptionProject{
- ID: p.ID,
- ProjectId: p.ProjectId,
- Price: p.Price,
- UserOrgId: p.UserOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- PatientId: p.PatientId,
- HisPatientId: p.HisPatientId,
- RecordDate: p.RecordDate,
- PrescriptionId: p.PrescriptionId,
- Count: p.Count,
- FeedetlSn: p.FeedetlSn,
- MedListCodg: p.MedListCodg,
- SingleDose: p.SingleDose,
- DeliveryWay: p.DeliveryWay,
- ExecutionFrequency: p.ExecutionFrequency,
- Day: p.Day,
- HisProject: models.HisProject{},
- GoodInfo: models.GoodInfo{},
- Remark: p.Remark,
- Unit: p.Unit,
- Type: p.Type,
- Doctor: p.Doctor,
- ExecutionTime: p.ExecutionTime,
- ExecutionStaff: p.ExecutionStaff,
- ExecutionState: p.ExecutionState,
- CheckTime: p.CheckTime,
- CheckState: p.CheckState,
- Checker: p.Checker,
- StartTime: p.StartTime,
- TeamId: p.TeamId,
- XtHisProjectTeam: models.XtHisProjectTeam{},
- FrequencyType: p.FrequencyType,
- DayCount: p.DayCount,
- WeekDay: p.WeekDay,
- IsCheckTeam: p.IsCheckTeam,
- HisOrderInfo: models.HisOrderInfo{},
- ExecutionFrequencyId: p.ExecutionFrequencyId,
- IsOut: p.IsOut,
- YbSyncStatus: p.YbSyncStatus,
- }
-
- service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
-
- service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
-
- }
-
- if nowCount == historyCount {
- if historyCount == 0 {
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
- goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
- houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
- creater := c.GetAdminUserInfo().AdminUser.Id
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: goodObj.GoodTypeId,
- GoodId: p.ProjectId,
- PatientId: p.PatientId,
- RecordDate: p.RecordDate,
- UserOrgId: adminInfo.CurrentOrgId,
- Count: nowCount,
- Ctime: time.Now().Unix(),
- Creater: creater,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- ProjectId: p.ID,
- }
- //出库
- service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
- }
- }
-
- lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
- //查询历史出库数据
- flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
-
- var out_count_five int64
- for _, item := range flowGood {
- out_count_five += item.Count
- }
- parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
-
- //fmt.Println("p.ProjectId-----------------", p.ProjectId)
- //fmt.Println("out_count_five===============", out_count_five)
- //fmt.Println("parseIntCount===============", parseIntCount)
- //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
- if out_count_five != parseIntCount {
- service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
- detail := models.AutomaticReduceDetail{
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- PatientId: p.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- RecordTime: p.RecordDate,
- OrgId: p.UserOrgId,
- GoodId: p.ProjectId,
- GoodTypeId: 0,
- Count: parseIntCount,
- Type: 0,
- ProjectId: lastHisProject.ID,
- StorehouseId: 0,
- }
-
- service.CreateNewAutoDetail(detail, tx)
- }
- // //查询耗材最后一次出库记录
- // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
- // //查询默认出库仓库库存
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- // if len(wareOut) > 0 {
- //
- // for _, it := range wareOut {
- // //回退库存
- // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
- //
- // //删除出库记录
- // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
- //
- // }
- // }
- //
- // timeStr := time.Now().Format("2006-01-02")
- // timeArr := strings.Split(timeStr, "-")
- // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
- //
- // total = total + 1
- // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- // number = number + total
- // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- //
- // operation_time := time.Now().Unix()
- // creater := c.GetAdminUserInfo().AdminUser.Id
- //
- // recordDateStr := time.Now().Format("2006-01-02")
- // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- // nowtime := recordDate.Unix()
- // warehouseOut := models.WarehouseOut{
- // WarehouseOutOrderNumber: warehousing_out_order,
- // OperationTime: operation_time,
- // OrgId: adminInfo.CurrentOrgId,
- // Creater: creater,
- // Ctime: time.Now().Unix(),
- // Status: 1,
- // WarehouseOutTime: nowtime,
- // Type: 1,
- // StorehouseId: storeConfig.StorehouseOutInfo,
- // IsCheck: 1,
- // IsSys: 1,
- // }
- // //查询是否生成出库单
- // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
- // if out.ID == 0 {
- // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
- // }
- //
- // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
- //
- // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
- // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
- //
- // dialyPrepareOne := models.DialysisBeforePrepare{
- // GoodTypeId: goodObj.GoodTypeId,
- // GoodId: p.ProjectId,
- // PatientId: p.PatientId,
- // RecordDate: p.RecordDate,
- // UserOrgId: adminInfo.CurrentOrgId,
- // Count: parseIntCount,
- // Ctime: time.Now().Unix(),
- // Creater: creater,
- // Status: 1,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // ProjectId: lastHisProject.ID,
- // }
- // //判断是否是零用耗材(非零用)
- // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
- //
- // //查询历史出库数据
- // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
- // var out_count int64
- // for _, item := range flowGood {
- // out_count += item.Count
- // }
- // //如果历史数和当前数据不想等才进行退库出库
- // if out_count != parseIntCount {
- // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
- //
- // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
- // detail := models.AutomaticReduceDetail{
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // PatientId: p.PatientId,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Status: 1,
- // RecordTime: p.RecordDate,
- // OrgId: p.UserOrgId,
- // GoodId: p.ProjectId,
- // GoodTypeId: 0,
- // Count: parseIntCount,
- // Type: 0,
- // ProjectId: lastHisProject.ID,
- // StorehouseId: 0,
- // }
- //
- // service.CreateNewAutoDetail(detail, tx)
- //
- // //查询剩余库存
- // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
- // var sum_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // }
- //
- // //更新剩余库存
- // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
- //
- // //耗材
- // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
- //
- // }
- // //判断是否是零用耗材(零用但是是出库耗材)
- // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
- //
- // //查询历史出库数据
- // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
- // var out_count int64
- // for _, item := range flowGood {
- // out_count += item.Count
- // }
- // //如果历史数和当前数据不想等才进行退库出库
- // if out_count != parseIntCount {
- // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
- //
- // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
- // detail := models.AutomaticReduceDetail{
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // PatientId: p.PatientId,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Status: 1,
- // RecordTime: p.RecordDate,
- // OrgId: p.UserOrgId,
- // GoodId: p.ProjectId,
- // GoodTypeId: 0,
- // Count: parseIntCount,
- // Type: 0,
- // ProjectId: p.ID,
- // StorehouseId: 0,
- // }
- //
- // service.CreateNewAutoDetail(detail, tx)
- //
- // //查询剩余库存
- // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
- // var sum_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // }
- //
- // //更新剩余库存
- // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
- //
- // //耗材
- // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
- // }
- //
- // }
- //
- // }
- //
- //}
-
- //记录日志
- byterequest, _ := json.Marshal(p)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: p.UserOrgId,
- PatientId: p.PatientId,
- AdminUserId: adminInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端新建his项目",
- RecordDate: p.RecordDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
-
- projectList = append(projectList, p)
-
- if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
- //新增或者编辑项目,修改对应的标签数据
- labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
- if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
- var label models.HisLabelPrintInfo
- project, _ := service.GetProjectDetail(p.ProjectId)
- if project.CostClassify == 3 { //类别为检验检查
- if p.TeamId > 0 { //检验检查组套
- tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
- if tempLabel.ID == 0 {
- team, _ := service.GetProjectTeamDetail(p.TeamId)
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.IsPrint = 2
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.ItemId = p.TeamId
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ProjectName = team.ProjectTeam
- label.PatientName = patient.Name
- service.CreateNewHisLabelRecord(&label, tx)
- }
- } else { //单条检验检查项目
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.IsPrint = 2
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ItemId = p.TeamId
- label.ProjectName = project.ProjectName
- label.PatientName = patient.Name
- service.CreateNewHisLabelRecord(&label, tx)
- }
- }
- }
- }
-
- }
- }
- }
-
- //插入检验数据
- if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
- //新增或者编辑项目,修改对应的标签数据
- labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
- if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
- var label models.HisLabelPrintInfo
- project, _ := service.GetProjectDetail(p.ProjectId)
- if project.CostClassify == 3 { //类别为检验检查
- if p.TeamId > 0 { //检验检查组套
- tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
- if tempLabel.ID == 0 {
- team, _ := service.GetProjectTeamDetail(p.TeamId)
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.IsPrint = 2
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.ItemId = p.TeamId
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ProjectName = team.ProjectTeam
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- } else { //单条检验检查项目
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.IsPrint = 2
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ItemId = p.TeamId
- label.ProjectName = project.ProjectName
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- }
- }
- }
-
- service.CreateNewHisProjectTwo(&p, tx)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
-
- goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
-
- if goodBase.ID > 0 {
- tx.Rollback()
- c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
- return
- }
- service.CreateNewHisProjectTwo(&p, tx)
-
- houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
-
- //查询剩余库存
- goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- //更新剩余库存
- service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
-
- //耗材
- service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
-
- adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
-
- outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
-
- if len(outInfoTwo) > 0 {
- for _, item := range outInfoTwo {
- service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
- }
- }
-
- drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
- if len(drugAutoDetail) > 0 {
- for _, item := range drugAutoDetail {
- service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
- }
- }
-
- tx.Commit()
- }
- }
- }
- //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
- // addition := items["addition"].([]interface{})
- // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- // ctime := time.Now().Unix()
- // mtime := ctime
- // if len(addition) > 0 {
- // for _, item := range addition {
- // var s models.HisAdditionalCharge
- // s.PrescriptionId = tempPrescription.ID
- // s.Status = 1
- // s.UserOrgId = adminInfo.CurrentOrgId
- // s.RecordDate = recordDateTime
- // s.CreatedTime = ctime
- // s.UpdatedTime = mtime
- // s.PatientId = patient_id
- // s.HisPatientId = his_patient_id
- // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- // service.CreateAdditionalCharge(&s)
- // var randNum int
- // randNum = rand.Intn(10000) + 1000
- // timestamp := time.Now().Unix()
- // tempTime := time.Unix(timestamp, 0)
- // timeFormat := tempTime.Format("20060102150405")
- // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
- // service.CreateAdditionalCharge(&s)
- //
- // }
- // }
- //}
-
- }
-
- }
- }
-
- tx.Commit()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- } else {
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- var tempPrescription *models.HisPrescription
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
- tempPrescription = &new_prescription
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- if med_type == "0" {
- med_type = "14"
- }
-
- //if order_status == 0 {
- // order_status = 1
- //}
-
- if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
- utils.ErrorLog("pre_time")
- }
- preTime, _ := items["pre_time"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
- //result := strings.Split(preTime, " ")
- theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- pTime := theTime2.Unix()
-
- ctime := time.Now().Unix()
-
- if tempPrescription.ID == 0 {
- prescription := &models.HisPrescription{
- ID: 0,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- Doctor: role.UserName,
- HisPatientId: his_patient_id,
- OrderStatus: 1,
- BatchNumber: "",
- PrescriptionNumber: hpInfo.PrescriptionNumber,
- PreTime: pTime,
- PType: p_type,
- MedType: med_type,
- }
- tempPrescription = prescription
- service.SaveHisPrescription(tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- } else {
- tempPrescription.ID = id
- tempPrescription.Type = types
- tempPrescription.Modifier = adminInfo.AdminUser.Id
- tempPrescription.Mtime = time.Now().Unix()
- tempPrescription.Doctor = role.UserName
- //tempPrescription.OrderStatus = order_status
- tempPrescription.PreTime = pTime
- tempPrescription.MedType = med_type
- service.SaveHisPrescription(tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- }
- //service.SaveHisPrescription(prescription)
- //更改患者挂号状态
- _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
- fmt.Println("更改失败", err2)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisDoctorAdviceInfo
- s.PrescriptionId = tempPrescription.ID
- s.AdviceType = 2
- s.AdviceDoctor = doctor_id
- s.StopState = 2
- s.ExecutionState = 2
- s.AdviceDate = theTime3.Unix()
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.RecordDate = theTime3.Unix()
- s.StartTime = tempPrescription.PreTime
- s.Groupno = groupNo
-
- s.PatientId = patient_id
- s.HisPatientId = his_patient_id
- s.StartTime = pTime
- s.IsSettle = 2
- errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- s.StartTime = pTime
- var total_count int64 //处方总库存
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(s.DrugId)
- prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven * medical.MinNumber
- }
-
- if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- total_count += prescribingNumberSeven
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
- if s.Price != lastWarehouse.RetailPrice {
- s.Price = lastWarehouse.RetailPrice
- }
- if s.Price == 0 {
- if lastWarehouse.ID == 0 {
- lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
- s.Price = lastWarehouseTwo.RetailPrice
- }
-
- }
- }
-
- if adminInfo.CurrentOrgId != 10206 {
- if s.ID == 0 {
- //查询改药品是否已经停用
- base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
-
- if base.ID > 0 {
- c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
- return
-
- }
-
- drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
-
- if drugMedical.SumCount == 0 {
- c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
- return
-
- }
- }
- }
-
- //赤峰
- if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
- drug, _ := service.GetDrugByGoodId(s.DrugId)
- info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
- if info.RetailPrice > 0 {
- if s.DeliveryWay == "口服" {
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- s.Price = drug.RetailPrice
- }
- if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- s.Price = info.RetailPrice
- }
-
- if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- s.Price = info.RetailPrice
- }
- }
- }
- }
-
- service.CreateHisDoctorAdvice(&s)
-
- //记录日志
- byterequest, _ := json.Marshal(s)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: s.UserOrgId,
- PatientId: s.PatientId,
- AdminUserId: adminInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端新建his医嘱",
- RecordDate: s.AdviceDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
-
- //存储切片中
- adviceList = append(adviceList, s)
-
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
- service.CreateHisDoctorAdvice(&s)
- keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(keySix, "", time.Second)
- keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyFive, "", time.Second)
- keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keyEight, "", time.Second)
- defer redis.Close()
-
- }
- }
-
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
-
- var p models.HisPrescriptionProject
- p.PrescriptionId = tempPrescription.ID
-
- p.PatientId = patient_id
- p.RecordDate = theTime3.Unix()
- p.Doctor = doctor_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.HisPatientId = his_patient_id
- p.Status = 1
- p.StartTime = pTime
-
- errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- if p.ID == 0 {
- p.IsOut = 2
- }
- if p.ID > 0 {
- projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
- p.IsOut = projectDetail.IsOut
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if p.Type == 3 {
- lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
- if p.Price != lastWarehouse.PackingPrice {
- p.Price = lastWarehouse.PackingPrice
- }
- if p.Price == 0 {
- lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
- p.Price = lastWarehouseTwo.PackingPrice
- }
-
- if p.Unit == "" {
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- p.Unit = goodInfoOne.PackingUnit
- }
- }
-
- }
-
- if adminInfo.CurrentOrgId != 10206 {
- if p.Type == 3 {
- if p.ID == 0 {
- //查询该耗材是否停用
- goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
- //表示该耗材已经停用,不能保存
- if goodInfoSeven.ID == 0 {
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
- return
- }
-
- goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
- if goodInfoOne.SumCount == 0 {
- c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
- return
- }
- }
-
- }
- }
-
- service.CreateHisProjectTwo(&p)
- //记录日志
- byterequest, _ := json.Marshal(p)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: p.UserOrgId,
- PatientId: p.PatientId,
- AdminUserId: adminInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端新建his项目",
- RecordDate: p.RecordDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
-
- projectList = append(projectList, p)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
-
- if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
- //新增或者编辑项目,修改对应的标签数据
- labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
- if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
- var label models.HisLabelPrintInfo
- project, _ := service.GetProjectDetail(p.ProjectId)
- if project.CostClassify == 3 { //类别为检验检查
- if p.TeamId > 0 { //检验检查组套
- tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
- if tempLabel.ID == 0 {
- team, _ := service.GetProjectTeamDetail(p.TeamId)
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.IsPrint = 2
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.ItemId = p.TeamId
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ProjectName = team.ProjectTeam
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- } else { //单条检验检查项目
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.IsPrint = 2
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ItemId = p.TeamId
- label.ProjectName = project.ProjectName
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- }
- }
- }
-
- service.SaveHisProjectTwo(&p)
-
- }
- }
- }
- //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
- // addition := items["addition"].([]interface{})
- // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- // ctime := time.Now().Unix()
- // mtime := ctime
- // if len(addition) > 0 {
- // for _, item := range addition {
- // var s models.HisAdditionalCharge
- // s.PrescriptionId = tempPrescription.ID
- // s.Status = 1
- // s.UserOrgId = adminInfo.CurrentOrgId
- // s.RecordDate = recordDateTime
- // s.CreatedTime = ctime
- // s.UpdatedTime = mtime
- // s.PatientId = patient_id
- // s.HisPatientId = his_patient_id
- // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- // service.CreateAdditionalCharge(&s)
- // var randNum int
- // randNum = rand.Intn(10000) + 1000
- // timestamp := time.Now().Unix()
- // tempTime := time.Unix(timestamp, 0)
- // timeFormat := tempTime.Format("20060102150405")
- // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
- // service.CreateAdditionalCharge(&s)
- //
- // }
- // }
- //}
-
- }
-
- }
-
- //查询今日该患者开的药品处方
- hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
-
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
- //药品出库
- if drugOutConfig.IsOpen == 1 {
- for _, item := range hisdoctorlist {
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
-
- // 查询该药品最后一次出库记录
- druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
-
- if len(druginfo) > 0 {
- //回退库存
- for _, it := range druginfo {
-
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- }
- }
-
- //删除记录
- service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
- //查询最后一次数据
- if drugOutConfig.IsOpen == 1 {
- //出库
- if drug.IsUse == 2 {
- creater := adminInfo.AdminUser.Id
- service.HisDrugsDelivery(item.UserOrgId, creater, item)
-
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- //更新基础库存
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
-
- over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
- service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
-
- }
- }
- }
-
- //耗材保存处方出库
- if goodOutConfig.IsOpen == 1 {
-
- //查询今日耗材出库数量
- hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
-
- for _, item := range hisgoodlist {
-
- //查询历史出库数据
- flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
- var out_count_five int64
- for _, item := range flowGood {
- out_count_five += item.Count
- }
-
- parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
-
- if out_count_five != parseIntCount {
-
- //查询耗材最后一次出库记录
- wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if len(wareOut) > 0 {
-
- for _, it := range wareOut {
- //回退库存
- service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
-
- //删除出库记录
- service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
-
- }
- }
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: nowtime,
- Type: 1,
- StorehouseId: storeConfig.StorehouseOutInfo,
- IsCheck: 1,
- IsSys: 1,
- }
- //查询是否生成出库单
- out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
-
- if out.ID == 0 {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
-
- goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
- houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
-
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: goodObj.GoodTypeId,
- GoodId: item.ProjectId,
- PatientId: item.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: adminInfo.CurrentOrgId,
- Count: parseIntCount,
- Ctime: time.Now().Unix(),
- Creater: creater,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- ProjectId: item.ID,
- }
- goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
- if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
-
- //查询历史出库数据
- flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
- var out_count int64
- for _, item := range flowGood {
- out_count += item.Count
- }
-
- //如果历史数和当前数据不想等才进行退库出库
- if out_count != parseIntCount {
- service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
-
- service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
- detail := models.AutomaticReduceDetail{
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- PatientId: item.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- RecordTime: item.RecordDate,
- OrgId: item.UserOrgId,
- GoodId: item.ProjectId,
- GoodTypeId: 0,
- Count: parseIntCount,
- Type: 0,
- ProjectId: item.ID,
- StorehouseId: 0,
- }
-
- service.CreateAutoDetail(detail)
-
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- //更新剩余库存
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
- }
-
- }
-
- if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
- //查询历史出库数据
- flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
- var out_count int64
- for _, item := range flowGood {
- out_count += item.Count
- }
- //如果历史数和当前数据不想等才进行退库出库
- if out_count != parseIntCount {
- service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
-
- service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
- detail := models.AutomaticReduceDetail{
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- PatientId: item.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- RecordTime: item.RecordDate,
- OrgId: item.UserOrgId,
- GoodId: item.ProjectId,
- GoodTypeId: 0,
- Count: parseIntCount,
- Type: 0,
- ProjectId: item.ID,
- StorehouseId: 0,
- }
-
- service.CreateAutoDetail(detail)
-
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- //更新剩余库存
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
- }
-
- }
-
- }
- }
- }
-
- ////同步到自备药
- selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
-
- if selfPrescriptionOpen.IsOpen == 1 {
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
- total = total + 1
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
-
- warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- warehousing := models.XtSelfDrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehousingTime: recordDateTime,
- Type: 0,
- StorehouseId: 0,
- IsCheck: 1,
- PatientId: patient_id,
- IsSys: 1,
- }
-
- selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
-
- if selfDrugWarehouse.ID == 0 {
- service.AddSelfDrugWarehouse(&warehousing, tx)
- }
- if selfDrugWarehouse.ID > 0 {
- service.UpdateSelfDrugWarehouse(&warehousing, tx)
- }
- info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
- fmt.Println(info)
-
- for _, item := range hisdoctorlist {
-
- //查询该病人的该药品是否已经入库
- selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
- selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
- var in_count int64
- if len(selfdruginfo) > 0 {
- for _, item := range selfdruginfo {
- var in_count_one int64
- if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
- }
-
- if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- in_count_one = item.WarehousingCount
- }
-
- if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- in_count_one = item.WarehousingCount
- }
-
- in_count += in_count_one
- }
-
- }
-
- if selfBasedrug.IsSelfDrug == 1 {
- var total_count int64
-
- prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven * selfBasedrug.MinNumber
- }
-
- if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- //入库
- if total_count > in_count {
-
- selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
- WarehousingOrder: warehousing_order,
- WarehousingId: info.ID,
- DrugId: item.DrugId,
- Number: "",
- ProductDate: 0,
- ExpiryDate: 0,
- WarehousingCount: total_count - in_count,
- WarehouseingUnit: selfBasedrug.MinUnit,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminInfo.CurrentOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- StockMaxNumber: total_count - in_count,
- RetailTotalPrice: 0,
- BatchNumber: "",
- MaxUnit: selfBasedrug.MinUnit,
- MinUnit: selfBasedrug.MinUnit,
- RetailPrice: 0,
- StorehouseId: 0,
- IsCheck: 1,
- StockMinNumber: 0,
- PatientId: patient_id,
- IsSys: 1,
- RecordDate: item.RecordDate,
- AdviceId: item.ID,
- }
-
- service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
-
- lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
- Creator := adminInfo.AdminUser.Id
-
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
- var sum_count int64
- for _, it := range list {
- baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- }
- flow := &models.XtSelfDrugFlow{
- WarehousingId: info.ID,
- DrugId: item.DrugId,
- Number: "",
- BatchNumber: "",
- Count: total_count - in_count,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: time.Now().Unix(),
- ConsumableType: 1,
- IsSys: 1,
- WarehousingOrder: warehousing_order,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- Creator: Creator,
- UpdateCreator: Creator,
- Status: 1,
- Ctime: item.AdviceDate,
- Mtime: 0,
- Price: item.Price,
- WarehousingDetailId: lastDrugWarhouseInfo.ID,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: 0,
- ProductDate: 0,
- MaxUnit: selfBasedrug.MinUnit,
- MinUnit: selfBasedrug.MinUnit,
- StorehouseId: 0,
- OverCount: sum_count,
- OperateTime: time.Now().Unix(),
- AdviceId: item.ID,
- }
- service.CreateSelfDrugFlow(flow, tx)
-
- drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
-
- var total_count int64 // 入库总数量
- var over_count int64 //剩余库存
- for _, it := range drugInfolist {
- if it.MaxUnit == selfBasedrug.MaxUnit {
- it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
- it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
- }
- }
- for _, it := range drugInfolist {
- total_count += it.WarehousingCount
- over_count += it.StockMaxNumber + it.StockMinNumber
-
- }
- //查询该仓库是否有默认数据
- selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
-
- if selfDrugStock.ID == 0 {
- drugStock := models.XtSelfDrugStockCount{
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- SumInCount: total_count,
- SumOutCount: 0,
- SumCancelCount: 0,
- DrugId: item.DrugId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- FlushCount: over_count,
- SumActOutCount: 0,
- }
- service.CreateSelfDrugStockSum(drugStock, tx)
-
- }
- if selfDrugStock.ID > 0 {
- service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
- }
-
- }
-
- //查询这个单据的出库数量
-
- drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
-
- var his_out_count int64
- for _, item := range drugFlowList {
- his_out_count += item.Count
- }
-
- //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
- if (total_count + his_out_count) <= in_count {
- // 出库
- if total_count < in_count {
-
- var cha_count int64
-
- cha_count = in_count - total_count
-
- var stock_number int64 = 0
- //查询库存是否充足
- warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
-
- // 将该批次的剩余库存数量转换为拆零数量
- if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
-
- stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
-
- }
- if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
-
- stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
-
- }
- if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
-
- stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
-
- }
-
- if stock_number >= cha_count {
-
- var maxNumber int64 = 0
- var minNumber int64 = 0
-
- maxNumber = cha_count / selfBasedrug.MinNumber
- minNumber = cha_count % selfBasedrug.MinNumber
-
- if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- minNumber = maxNumber
- }
-
- if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
- return
- }
- }
-
- if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
-
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
-
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
- }
- if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
-
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
- }
-
- if warehouse.StockMaxNumber < 0 {
- warehouse.StockMaxNumber = 0
- }
- if warehouse.StockMinNumber < 0 {
- warehouse.StockMinNumber = 0
- }
-
- warehouse.Mtime = time.Now().Unix()
-
- if warehouse.StockMinNumber < minNumber {
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
- if warehouse.MaxUnit != warehouse.MinUnit {
- warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
- }
- if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
- }
- } else {
- if minNumber > 0 {
- if (warehouse.StockMinNumber - minNumber) >= 0 {
- warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
- }
-
- }
-
- if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
-
- if warehouse.StockMinNumber > 0 {
- if warehouse.StockMinNumber-cha_count >= 0 {
- warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
- }
-
- }
-
- }
-
- }
-
- if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
- if (warehouse.StockMinNumber - cha_count) >= 0 {
- warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
- }
-
- }
-
- if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
- return
- }
- }
- if warehouse.StockMinNumber <= 0 {
- warehouse.StockMinNumber = 0
- }
-
- service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
-
- //查询该药品剩余库存
- infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
- var over_count int64
- for _, its := range infolist {
- if its.MaxUnit == selfBasedrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
- }
- over_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
- drugflow := models.XtSelfDrugFlow{
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: warehousing_order,
- WarehousingOrder: warehousing_order,
- DrugId: item.DrugId,
- Number: warehouse.Number,
- ProductDate: warehouse.ProductDate,
- ExpireDate: warehouse.ExpiryDate,
- Count: cha_count,
- Price: warehouse.RetailPrice,
- Status: 1,
- Ctime: item.AdviceDate,
- Mtime: time.Now().Unix(),
- UserOrgId: item.UserOrgId,
- Manufacturer: warehouse.Manufacturer,
- Dealer: warehouse.Dealer,
- BatchNumber: warehouse.BatchNumber,
- MaxUnit: selfBasedrug.MinUnit,
- ConsumableType: 20,
- IsEdit: 1,
- Creator: 0,
- IsSys: 3,
- WarehouseOutDetailId: drugWareInfo.ID,
- AdviceId: item.ID,
- SupplyWarehouseId: warehouse.SupplyWarehouseId,
- StorehouseId: 0,
- AdminUserId: creater,
- LastPrice: warehouse.Price,
- StockCount: "",
- WarehousingDetailId: 0,
- OverCount: over_count,
- RetailPrice: item.Price, //手动出库出库价格
- WarehousingId: warehouse.ID,
- SystemTime: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "保存处方入库数据差",
- OperateTime: time.Now().Unix(),
- }
- if warehouse.RetailPrice == 0 {
- drugflow.Price = item.Price
- }
- service.CreateSelfDrugFlowOne(drugflow, tx)
-
- var out_count int64
- out_count = in_count - total_count
- //
- //fmt.Println("in_count------------------", in_count)
- //fmt.Println("total_count------------------", total_count)
- //添加出库数量
- service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == selfBasedrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
- return
- }
- }
- }
-
- }
-
- }
- }
-
- }
- tx.Commit()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- //func (c *HisApiController) EditHisPrescription() {
- // record_date := c.GetString("record_date")
- // patient_id, _ := c.GetInt64("patient_id")
- // reg_type, _ := c.GetInt64("reg_type")
- // //diagnose, _ := c.GetInt64("diagnose", 0)
- // diagnose := c.GetString("diagnose")
- // sick_type, _ := c.GetInt64("sick_type")
- // sick_history := c.GetString("sick_history")
- // doctor_id, _ := c.GetInt64("doctor", 0)
- // department, _ := c.GetInt64("department", 0)
- // his_patient_id, _ := c.GetInt64("his_patient_id")
- // p_type, _ := c.GetInt64("p_type")
- //
- // dataBody := make(map[string]interface{}, 0)
- // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // timeLayout := "2006-01-02"
- // loc, _ := time.LoadLocation("Local")
- // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // adminInfo := c.GetAdminUserInfo()
- // recordDateTime := theTime.Unix()
- //
- // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
- //
- // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- // var hpInfo models.HisPrescriptionInfo
- // if info.ID == 0 {
- // var randNum int
- // randNum = rand.Intn(10000) + 1000
- // timestamp := time.Now().Unix()
- // tempTime := time.Unix(timestamp, 0)
- // timeFormat := tempTime.Format("20060102150405")
- // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
- //
- // hpInfo = models.HisPrescriptionInfo{
- // UserOrgId: adminInfo.CurrentOrgId,
- // RecordDate: theTime.Unix(),
- // PatientId: patient_id,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: time.Now().Unix(),
- // Creator: adminInfo.AdminUser.Id,
- // Modifier: adminInfo.AdminUser.Id,
- // Diagnosis: diagnose,
- // SickHistory: sick_history,
- // Departments: department,
- // RegisterType: reg_type,
- // PrescriptionNumber: p_number,
- // PrescriptionStatus: 1,
- // Doctor: role.UserName,
- // DoctorId: doctor_id,
- // SickType: sick_type,
- // PType: p_type,
- // }
- // service.SavePatientPrescriptionInfo(hpInfo)
- //
- // } else {
- // hpInfo = models.HisPrescriptionInfo{
- // ID: info.ID,
- // UserOrgId: adminInfo.CurrentOrgId,
- // RecordDate: info.RecordDate,
- // PatientId: info.PatientId,
- // Status: 1,
- // Ctime: info.Ctime,
- // Mtime: time.Now().Unix(),
- // Creator: info.Creator,
- // Modifier: adminInfo.AdminUser.Id,
- // Diagnosis: diagnose,
- // SickHistory: sick_history,
- // Departments: department,
- // RegisterType: reg_type,
- // PrescriptionNumber: info.PrescriptionNumber,
- // Doctor: role.UserName,
- // PrescriptionStatus: info.PrescriptionStatus,
- // DoctorId: doctor_id,
- // SickType: sick_type,
- // PType: info.PType,
- // }
- // service.SavePatientPrescriptionInfo(hpInfo)
- // }
- //
- // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- // prescriptions, _ := dataBody["prescriptions"].([]interface{})
- //
- // if len(prescriptions) > 0 {
- // for _, item := range prescriptions {
- // items := item.(map[string]interface{})
- // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- // utils.ErrorLog("id")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // id := int64(items["id"].(float64))
- //
- // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- // utils.ErrorLog("type")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // types := int64(items["type"].(float64))
- //
- // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- // utils.ErrorLog("med_type")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // med_type := strconv.Itoa(int(items["med_type"].(float64)))
- //
- // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
- //
- // ctime := time.Now().Unix()
- //
- // prescription := &models.HisPrescription{
- // ID: id,
- // PatientId: patient_id,
- // UserOrgId: adminInfo.CurrentOrgId,
- // RecordDate: recordDateTime,
- // Ctime: ctime,
- // Mtime: ctime,
- // Type: types,
- // Modifier: adminInfo.AdminUser.Id,
- // Creator: adminInfo.AdminUser.Id,
- // Status: 1,
- // Doctor: role.UserName,
- // HisPatientId: his_patient_id,
- // OrderStatus: 1,
- // BatchNumber: "",
- // PrescriptionNumber: hpInfo.PrescriptionNumber,
- // PType: hpInfo.PType,
- // MedType: med_type,
- // }
- //
- // if historyPrescription.ID > 0 {
- // prescription.PreTime = historyPrescription.PreTime
- //
- // }
- //
- // service.SaveHisPrescription(prescription)
- //
- // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- // advices := items["advices"].([]interface{})
- // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- // groupNo := int64(0)
- // ctime := time.Now().Unix()
- // mtime := ctime
- // if len(advices) > 0 {
- // for _, advice := range advices {
- // var s models.HisDoctorAdviceInfo
- // s.PrescriptionId = prescription.ID
- // s.AdviceType = 2
- // s.AdviceDoctor = adminInfo.AdminUser.Id
- // s.StopState = 2
- // s.ExecutionState = 2
- // s.AdviceDate = recordDateTime
- // s.Status = 1
- // s.UserOrgId = adminInfo.CurrentOrgId
- // s.RecordDate = recordDateTime
- // s.StartTime = prescription.PreTime
- // s.Groupno = groupNo
- // s.CreatedTime = ctime
- // s.UpdatedTime = mtime
- // s.PatientId = patient_id
- // s.HisPatientId = his_patient_id
- // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- //
- // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
- // if s.Price == 0 {
- // s.Price = lastWarehouse.RetailPrice
- // }
- // }
- //
- // service.CreateHisDoctorAdvice(&s)
- // //记录日志
- // byterequest, _ := json.Marshal(s)
- // adviceLog := models.XtDoctorAdviceLog{
- // UserOrgId: s.UserOrgId,
- // PatientId: s.PatientId,
- // AdminUserId: adminInfo.AdminUser.Id,
- // Module: 1,
- // ErrLog: string(byterequest),
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Source: "电脑端his医嘱修改",
- // RecordDate: s.AdviceDate,
- // }
- // service.CreateDoctorAdviceLog(adviceLog)
- // redis := service.RedisClient()
- // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- // redis.Set(key, "", time.Second)
- // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- // fmt.Println("keyOne", keyOne)
- // redis.Set(keyOne, "", time.Second)
- // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- // redis.Set(keySeven, "", time.Second)
- // redis.Close()
- //
- // }
- // }
- // }
- // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- // projects := items["project"].([]interface{})
- // if len(projects) > 0 {
- // for _, project := range projects {
- // var p models.HisPrescriptionProject
- // p.PrescriptionId = prescription.ID
- // p.Ctime = time.Now().Unix()
- // p.Mtime = time.Now().Unix()
- // p.PatientId = patient_id
- // p.RecordDate = recordDateTime
- // p.UserOrgId = adminInfo.CurrentOrgId
- // p.HisPatientId = his_patient_id
- // p.Status = 1
- // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- // service.CreateHisProjectTwo(&p)
- //
- // //记录日志
- // byterequest, _ := json.Marshal(p)
- // adviceLog := models.XtDoctorAdviceLog{
- // UserOrgId: p.UserOrgId,
- // PatientId: p.PatientId,
- // AdminUserId: adminInfo.AdminUser.Id,
- // Module: 1,
- // ErrLog: string(byterequest),
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Source: "电脑端his项目修改",
- // RecordDate: p.RecordDate,
- // }
- // service.CreateDoctorAdviceLog(adviceLog)
- // }
- // }
- // }
- // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
- // addition := items["addition"].([]interface{})
- // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- // ctime := time.Now().Unix()
- // mtime := ctime
- // if len(addition) > 0 {
- // for _, item := range addition {
- // var s models.HisAdditionalCharge
- // s.PrescriptionId = prescription.ID
- // s.Status = 1
- // s.UserOrgId = adminInfo.CurrentOrgId
- // s.RecordDate = recordDateTime
- // s.CreatedTime = ctime
- // s.UpdatedTime = mtime
- // s.PatientId = patient_id
- // s.HisPatientId = his_patient_id
- // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- // service.CreateAdditionalCharge(&s)
- // }
- // }
- // }
- //
- // }
- // }
- // }
- // if err == nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "保存成功",
- // })
- // return
- //
- // } else {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- // return
- // }
- //}
-
- func (c *HisApiController) DeletePrescription() {
-
- prescription_id, _ := c.GetInt64("id")
- projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
- advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
-
- ////同步到自备药
- selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
-
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
-
- if selfPrescriptionOpen.IsOpen == 1 {
- // 在函数结束时处理事务回滚
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
- for _, item := range advicesList {
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
-
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: item.AdviceDate,
- Type: 0,
- PatientId: item.PatientId,
- IsCheck: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
-
- fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
- selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
-
- var total_count int64
- prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven * selfBasedrug.MinNumber
- }
-
- if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehousing_out_order,
- WarehouseOutId: lastWarehouseOut.ID,
- DrugId: item.DrugId,
- Count: total_count,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: item.AdviceDate,
- Mtime: item.AdviceDate,
- Remark: "",
- OrgId: item.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: selfBasedrug.MinUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 1,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: item.AdviceDate,
- PatientId: item.PatientId,
- ClassType: "",
- AdviceId: item.ID,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
- }
-
- fmt.Println("长度-------------------------------", warehousingOutInfo)
- for _, it := range warehousingOutInfo {
- //查询今日是否有出库数据
- lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
-
- }
-
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- //已收费和已发药限制逻辑
- isCharge := false
- isMedicine := false
- new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
-
- if new_prescription.IsMedicine == 1 {
- isMedicine = true
- }
-
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
-
- if p_err != nil {
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
- }
- for _, item := range advices {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
- //已收费和已发药限制逻辑
-
- if len(projects) > 0 {
- for _, item := range projects {
- service.DeletePrintInfo(item.ID) //删除打印信息
-
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if item.Type == 3 && item.IsOut == 1 {
- good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
- f_count, _ := strconv.ParseFloat(item.Count, 64)
- good.Total = good.Total + f_count
- service.UpdateGoodInfo(&good)
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: item.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //查询该耗材是否出库
- info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
-
- var total_count int64
- count, _ := strconv.ParseInt(item.Count, 10, 64)
- total_count += count
-
- if info.ID > 0 {
- if info.Count >= total_count {
-
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: c.GetAdminUserInfo().CurrentOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count,
- OperateTime: time.Now().Unix(),
- }
- service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
- }
-
- if info.Count < total_count {
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: info.Count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: info.Count,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: c.GetAdminUserInfo().CurrentOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count,
- OperateTime: time.Now().Unix(),
- }
- service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
- }
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
- }
-
- //更新库存
- service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
-
- //更新基础库库存
- service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
-
- }
-
- }
- }
- }
-
- //保存耗材出库
- if goodOutConfig.IsOpen == 1 {
-
- if item.Type == 3 {
- good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
- f_count, _ := strconv.ParseFloat(item.Count, 64)
- good.Total = good.Total + f_count
- service.UpdateGoodInfo(&good)
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: item.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //查询该耗材是否出库
- info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
-
- var total_count int64
- count, _ := strconv.ParseInt(item.Count, 10, 64)
- total_count += count
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- fmt.Println("历史出库数据", info.Count)
- fmt.Println("出库数量", total_count)
- if info.ID > 0 {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- //查询出库数量
- list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
-
- //出库数据 大于 退库数量
- if len(list) > 0 {
- for _, it := range list {
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count_one int64
- for _, it := range goodList {
- flush_count_one += it.StockCount
- }
- //查询该批次是否有退库数据
- //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- flow := models.VmStockFlow{
- WarehousingId: it.WarehouseInfotId,
- GoodId: it.GoodId,
- Number: it.Number,
- LicenseNumber: it.LicenseNumber,
- Count: it.Count,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: it.PatientId,
- SystemTime: it.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: it.WarehouseOutId,
- WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: it.Price,
- WarehousingDetailId: it.WarehouseInfotId,
- WarehouseOutDetailId: it.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: it.ProductDate,
- ExpireDate: it.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count_one,
- }
- service.CreateStockFlowOne(flow)
-
- //if flow.ID > 0 {
- // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
- //}
- }
-
- }
-
- //flow := models.VmStockFlow{
- // WarehousingId: info.WarehouseInfotId,
- // GoodId: item.ProjectId,
- // Number: info.Number,
- // LicenseNumber: info.LicenseNumber,
- // Count: prescribingNumber,
- // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- // PatientId: item.PatientId,
- // SystemTime: info.SysRecordTime,
- // ConsumableType: 7,
- // IsSys: 0,
- // WarehousingOrder: "",
- // WarehouseOutId: info.WarehouseOutId,
- // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- // IsEdit: 0,
- // CancelStockId: cancel.ID,
- // CancelOrderNumber: cancel.OrderNumber,
- // Manufacturer: manufacturer.ID,
- // Dealer: 0,
- // Creator: c.GetAdminUserInfo().CurrentOrgId,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: info.Price,
- // WarehousingDetailId: info.WarehouseInfotId,
- // WarehouseOutDetailId: info.ID,
- // CancelOutDetailId: cancelInfo.ID,
- // ProductDate: info.ProductDate,
- // ExpireDate: info.ExpiryDate,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // OverCount: flush_count,
- //}
- //service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
- }
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count_one int64
- for _, it := range goodList {
- flush_count_one += it.StockCount
- }
-
- //更新库存
- msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
- fmt.Println("msgerrkonde23332323", msgerrkonde)
-
- //更新基础库库存
- service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
-
- }
- }
- }
- }
- err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
- err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- if len(advices) > 0 {
- for _, item := range advices {
- redis := service.RedisClient()
- keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- redis.Close()
-
- }
- }
- if c.GetAdminUserInfo().CurrentOrgId == 10387 {
-
- if len(advices) > 0 {
- for _, item := range advices {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(item, creater)
- }
- }
-
- } else {
-
- if drugOutConfig.IsOpen == 1 {
- if len(advices) > 0 {
- for _, item := range advices {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(item, creater)
- }
- }
- } else {
- if len(advices) > 0 {
- for _, item := range advices {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(item, creater)
- }
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
-
- }
-
- func (c *HisApiController) DeleteDoctorAdvice() {
- id, _ := c.GetInt64("id")
- advice, _ := service.GetHisDoctorAdvicesById(id)
-
- ////同步到自备药
- selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
- if selfPrescriptionOpen.IsOpen == 1 {
-
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
-
- var total_count int64
- prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven * selfBasedrug.MinNumber
- }
-
- if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: advice.AdviceDate,
- Type: 0,
- PatientId: advice.PatientId,
- IsCheck: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutId: lastWarehouseOut.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: advice.DrugId,
- Count: total_count,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: advice.AdviceDate,
- Mtime: advice.AdviceDate,
- Remark: "",
- OrgId: advice.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: advice.PrescribingNumberUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: advice.AdviceDate,
- PatientId: advice.PatientId,
- AdviceId: advice.ID,
- ClassType: "",
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- for _, it := range warehousingOutInfo {
-
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
-
- }
- drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- //已收费和已发药的限制逻辑
- isCharge := false
- isMedicine := false
- new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
-
- //获取今天该患者所有处方,判断是否发药或者收费
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
- //for _, item := range new_prescriptions {
- if new_prescription.IsMedicine == 1 {
- isMedicine = true
- }
- //}
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
- for _, item := range advices {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
- return
- }
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
- return
- }
- //已收费和已发药的限制逻辑
-
- err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
- redis := service.RedisClient()
- keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
-
- if err == nil {
- if c.GetAdminUserInfo().CurrentOrgId == 10387 {
- //查询是否在处方中出库
- openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
-
- if openConfig.IsOpen != 1 {
-
- //判断该医嘱是否执行了
- if advice.ExecutionState == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
- }
- }
-
- //开启保存处方扣减功能
- if openConfig.IsOpen == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
- }
- } else {
-
- if drugOutConfig.IsOpen == 1 {
-
- //查询是否在处方中出库
- openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
-
- if openConfig.IsOpen != 1 {
-
- //判断该医嘱是否执行了
- if advice.ExecutionState == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
-
- }
-
- }
-
- //开启保存处方扣减功能
- if openConfig.IsOpen == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
-
- }
- } else {
- //判断该医嘱是否执行了
- if advice.ExecutionState == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisApiController) DeleteProject() {
- id, _ := c.GetInt64("id")
- adminInfo := c.GetAdminUserInfo()
- project, _ := service.GetHisProjectByID(id)
- // var consumable models.DialysisBeforePrepare
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- isCharge := false
- isMedicine := false
- new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
- for _, item := range new_prescriptions {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
- return
- }
-
- service.DeletePrintInfo(id)
- label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
- label.Status = 0
- service.CreateHisLabelRecordTwo(&label)
-
- fmt.Println(goodOutConfig.IsOpen)
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if project.Type == 2 {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
- if project.Type == 3 && project.IsOut == 1 {
-
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- f_count, _ := strconv.ParseFloat(project.Count, 64)
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: project.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //查询是否有出库
- info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
-
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
- if info.ID > 0 {
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
- if info.Count >= prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
- }
- if info.Count < prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: info.Count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
- }
-
- //查询剩余库存
- goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
- //出库数据 大于 退库数量
- if info.Count >= prescribingNumber {
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- OperateTime: time.Now().Unix(),
- }
- service.CreateStockFlowOne(flow)
- }
-
- //出库数据小于退库数据
- if info.Count < prescribingNumber {
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: info.Count,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- OperateTime: time.Now().Unix(),
- }
- service.CreateStockFlowOne(flow)
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
-
- //fmt.Println("aiwohonguo --------------------", prescribingNumber)
- //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
- }
-
- //更新剩余库存
- service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
-
- stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
- var total_count_one int64
- for _, it := range stockList {
- total_count_one += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
-
- goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: project.UserOrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: project.ProjectId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- } else {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
-
- } else {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
-
- }
- }
-
- //保存处方出库
- if goodOutConfig.IsOpen == 1 {
- if project.Type == 3 {
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
-
- f_count, _ := strconv.ParseFloat(project.Count, 64)
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: project.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //获取出库数据
- info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
-
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
- if info.ID > 0 {
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
- if info.Count >= prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- //退库数量增加
- //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
- //出库数量减少
- //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
- }
- if info.Count < prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
-
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
-
- //查询出库数量
- list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
-
- //出库数据 大于 退库数量
- if len(list) > 0 {
- for _, it := range list {
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
- goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var over_count_one int64
- for _, it := range goodList {
- over_count_one += it.StockCount
- }
- //查询该批次是否有退库数据
- //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
-
- flow := models.VmStockFlow{
- WarehousingId: it.WarehouseInfotId,
- GoodId: it.GoodId,
- Number: it.Number,
- LicenseNumber: it.LicenseNumber,
- Count: it.Count,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: it.PatientId,
- SystemTime: it.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: it.WarehouseOutId,
- WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: it.Price,
- WarehousingDetailId: it.WarehouseInfotId,
- WarehouseOutDetailId: it.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: it.ProductDate,
- ExpireDate: it.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count_one,
- OperateTime: time.Now().Unix(),
- }
- service.CreateStockFlowOne(flow)
-
- }
-
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
- }
-
- //更新剩余库存
- service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
-
- stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
- var total_count_one int64
- for _, it := range stockList {
- total_count_one += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
-
- goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: project.UserOrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: project.ProjectId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- } else {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
-
- }
-
- func (c *HisApiController) CreateHisAdditionalCharge() {
- his_patient_id, _ := c.GetInt64("his_patient_id")
- patient_id, _ := c.GetInt64("patient_id")
- record_date := c.GetString("record_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetAdminUserInfo()
- recordDateTime := theTime.Unix()
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var additions []*models.HisAdditionalCharge
- if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
- additions, _ := dataBody["addition"].([]interface{})
- if len(additions) > 0 {
- for _, item := range additions {
- items := item.(map[string]interface{})
-
- if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
- utils.ErrorLog("item_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- item_id := int64(items["item_id"].(float64))
-
- if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
- utils.ErrorLog("item_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- item_name := items["item_name"].(string)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- ctime := time.Now().Unix()
- additional := &models.HisAdditionalCharge{
- PatientId: patient_id,
- HisPatientId: his_patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- CreatedTime: ctime,
- UpdatedTime: ctime,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Price: price,
- ItemName: item_name,
- ItemId: item_id,
- Status: 1,
- }
- additions = append(additions, additional)
- }
- }
- }
- for _, item := range additions {
- service.CreateAddtionalCharge(item)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
-
- func (c *HisApiController) CreateHisPatientCaseHistory() {
-
- blood_fat := c.GetString("blood_fat")
- bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
-
- blood_sugar := c.GetString("blood_sugar")
- bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
-
- chief_conplaint := c.GetString("chief_conplaint")
-
- dbp := c.GetString("dbp")
- dbpfloat, _ := strconv.ParseFloat(dbp, 64)
- delivery_way, _ := c.GetInt64("delivery_way")
- diagnostic := c.GetString("diagnostic")
-
- family_history := c.GetString("family_history")
-
- height := c.GetString("height")
- history_of_present_illness := c.GetString("history_of_present_illness")
- is_infect, _ := c.GetInt64("is_infect")
-
- past_history := c.GetString("past_history")
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- personal_history := c.GetString("personal_history")
- pulse := c.GetString("pulse")
- pulsefloat, _ := strconv.ParseFloat(pulse, 64)
- sbp := c.GetString("sbp")
- sbpfloat, _ := strconv.ParseFloat(sbp, 64)
- heightfloat, _ := strconv.ParseFloat(height, 64)
- sicktype := c.GetString("sick_type")
-
- sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
- symptom := c.GetString("symptom")
- sick_date := c.GetString("sick_date")
- temperatures := c.GetString("temperature")
-
- temperature, _ := strconv.ParseFloat(temperatures, 64)
- record_date := c.GetString("record_date")
- breathing := c.GetString("breathing")
- doctor_advice := c.GetString("doctor_advice")
- remark := c.GetString("remark")
- breathingfloat, _ := strconv.ParseFloat(breathing, 64)
-
- sick, _ := c.GetInt64("sick")
- diagnose, _ := c.GetInt64("diagnose")
- //id, _ := c.GetInt64("id")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- allergic_history := c.GetString("allergic_history")
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sickTimes := sickTime.Unix()
- ctime := time.Now().Unix()
-
- primary_disease := c.GetString("primary_disease")
- confirm_failure_date := c.GetString("confirm_failure_date")
- confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
- drug_allergy_history := c.GetString("drug_allergy_history")
- physical_examination := c.GetString("physical_examination")
- special_inspection := c.GetString("special_inspection")
- lab_apparatus := c.GetString("lab_apparatus")
- caseHistory := models.HisPatientCaseHistory{
- HisPatientId: his_patient_id,
- PatientId: patient_id,
- Temperature: temperature,
- BloodSugar: bloodsugarfloat,
- Pulse: pulsefloat,
- Sbp: sbpfloat,
- Dbp: dbpfloat,
- Height: heightfloat,
- BloodFat: bloodfatfloat,
- SickType: sick_type,
- Symptom: symptom,
- SickDate: sickTimes,
- IsInfect: is_infect,
- HistoryOfPresentIllness: history_of_present_illness,
- PastHistory: past_history,
- Doctor: c.GetAdminUserInfo().AdminUser.Id,
- ChiefConplaint: chief_conplaint,
- PersonalHistory: personal_history,
- FamilyHistory: family_history,
- Diagnostic: diagnostic,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- Status: 1,
- Ctime: ctime,
- Mtime: ctime,
- RecordDate: recordDateTime,
- DeliveryWay: delivery_way,
- Breathing: breathingfloat,
- DoctorAdvice: doctor_advice,
- Remark: remark,
- Sick: sick,
- Diagnose: diagnose,
- AllergicHistory: allergic_history,
- PrimaryDisease: primary_disease,
- ConfirmFailureDate: confirm_failure_date_time.Unix(),
- DrugAllergyHistory: drug_allergy_history,
- PhysicalExamination: physical_examination,
- SpecialInspection: special_inspection,
- LabApparatus: lab_apparatus,
- }
- //查询该患者是否有病历
- _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
- if errcodes == gorm.ErrRecordNotFound {
- err = service.SaveHisPatientCaseHistory(&caseHistory)
- historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "caseHistory": caseHistory,
- "historyInfo": historyInfo,
- })
- return
- } else if errcodes == nil {
- err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
- historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "caseHistory": caseHistory,
- "historyInfo": historyInfo,
- })
- }
-
- //查询该患者是否有病历
- //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
- //if errcode == gorm.ErrRecordNotFound {
- // err = service.SaveHisPatientCaseHistory(caseHistory)
- // if err != nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "保存成功",
- // })
- // }
- //} else if errcode == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- // return
- //}
-
- }
- func (c *HisApiController) GetHisPatientCaseHistoryList() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminUser := c.GetAdminUserInfo()
- caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": caseHistorys,
- })
-
- }
- func (c *HisApiController) GetHisPatientCaseHistory() {
- record_date, _ := c.GetInt64("record_date", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- admin := c.GetAdminUserInfo()
- info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
- c.ServeSuccessJSON(map[string]interface{}{
- "info": info,
- "case_history": case_history,
- })
-
- }
- func (c *HisApiController) CreateCaseHistoryTemplate() {
- template_name := c.GetString("template_name")
- template_remark := c.GetString("template_remark")
- doctor := c.GetAdminUserInfo().AdminUser.Id
- diagnostic := c.GetString("diagnostic")
- chief_conplaint := c.GetString("chief_conplain")
- history_of_present_illness := c.GetString("history_of_present_illness")
- past_history := c.GetString("past_history")
- personal_history := c.GetString("personal_history")
- family_history := c.GetString("family_history")
- user_name := c.GetString("user_name")
- doctor_advice := c.GetString("doctor_advice")
- remark := c.GetString("remark")
- //record_date := c.GetString("record_date")
- //fmt.Println("record_date--------",record_date)
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //
- //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- //if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //recordDateTime := theTime.Unix()
-
- ctime := time.Now().Unix()
-
- template := models.HisCaseHistoryTemplate{
- HistoryOfPresentIllness: history_of_present_illness,
- PastHistory: past_history,
- ChiefConplaint: chief_conplaint,
- PersonalHistory: personal_history,
- FamilyHistory: family_history,
- Diagnostic: diagnostic,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- Status: 1,
- Ctime: ctime,
- Mtime: ctime,
- RecordDate: time.Now().Unix(),
- TemplateName: template_name,
- TemplateRemark: template_remark,
- Creator: doctor,
- Modifier: doctor,
- UserName: user_name,
- DoctorAdvice: doctor_advice,
- Remark: remark,
- }
-
- err := service.SaveHisPatientCaseHistoryTemplate(template)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *HisApiController) GetCaseHistoryTemplate() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- keyword := c.GetString("keyword")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- admin := c.GetAdminUserInfo()
- template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
- //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- //"history": history,
- })
-
- }
-
- func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
- if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- if advice.ID > 0 {
- hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
- if err == nil {
- if hisAdvice.ID > 0 {
- advice.ExecutionTime = hisAdvice.ExecutionTime
- advice.ExecutionStaff = hisAdvice.ExecutionStaff
- advice.ExecutionState = hisAdvice.ExecutionState
- advice.CheckTime = hisAdvice.CheckTime
- advice.Checker = hisAdvice.Checker
- advice.CheckState = hisAdvice.CheckState
- advice.StartTime = hisAdvice.StartTime
- advice.FeedetlSn = hisAdvice.FeedetlSn
-
- }
- }
- }
- }
-
- //
- //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
- // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
- // advice.ExecutionTime = execution_time
- //}
- //
- //
- //
- //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
- // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
- // advice.ExecutionStaff = execution_staff
- //}
- //
- //
- //
- //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
- // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
- // advice.ExecutionState = execution_state
- //}
- //
- //
- //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
- // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
- // advice.CheckTime = check_time
- //}
- //
- //
- //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
- // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
- // advice.CheckState = check_state
- //}
- //
- //
- //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
- // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
- // advice.Checker = checker
- //}
- //
- //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
- // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
- // advice.StartTime = start_time
- //}
- if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
- is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
- advice.IsSelfDrug = is_self_drug
- }
-
- if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
- //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
- drug_way_count, _ := json["drug_way_count"].(string)
- advice.DrugWayCount = drug_way_count
- }
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
- return 0
- }
-
- func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- historyProject, _ := service.GetHisProjectByID(id)
- project.FeedetlSn = historyProject.FeedetlSn
-
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
-
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // project.Price = float_price
- // }
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- return 0
- }
-
- func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- historyAddtions, _ := service.GetHisAdditionByID(id)
- additionalCharge.ID = id
- additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
- }
- if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
- item_id := int64(json["item_id"].(float64))
- additionalCharge.ItemId = item_id
- config, _ := service.GetAdditionChargeByID(org_id, item_id)
- if config.ID > 0 {
- if len(config.Code) > 0 {
- additionalCharge.MedListCodg = config.Code
- }
- }
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- // }
-
- //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- //}
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- additionalCharge.Price = price
- }
- if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
- count, _ := json["count"].(string)
- counts, _ := strconv.ParseInt(count, 10, 64)
- additionalCharge.Count = counts
- }
- if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
- item_name, _ := json["item_name"].(string)
- additionalCharge.ItemName = item_name
- }
-
- return 0
- }
-
- func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
- if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
- is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
- advice.IsSelfDrug = is_self_drug
- }
- if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
- //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
- drug_way_count, _ := json["drug_way_count"].(string)
- advice.DrugWayCount = drug_way_count
- }
-
- if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
- hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
- advice.HospApprFlag = hosp_appr_flag
- }
-
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // advice.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // advice.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // advice.WeekDay = week_day
- //}
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
-
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- if advice.ID > 0 {
- hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
- if err == nil {
- if hisAdvice.ID > 0 {
-
- advice.ExecutionTime = hisAdvice.ExecutionTime
- advice.ExecutionStaff = hisAdvice.ExecutionStaff
- advice.ExecutionState = hisAdvice.ExecutionState
- advice.CheckTime = hisAdvice.CheckTime
- advice.Checker = hisAdvice.Checker
- advice.CheckState = hisAdvice.CheckState
- advice.StartTime = hisAdvice.StartTime
- advice.HospApprFlag = hisAdvice.HospApprFlag
- advice.IsMedicine = hisAdvice.IsMedicine
- if hisAdvice.UserOrgId == 10028 {
- 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 {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- }
- } else {
- 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 {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- advice.UpdatedTime = time.Now().Unix()
- }
- }
-
- //advice.Groupno = hisAdvice.Groupno
-
- }
- }
- }
- }
-
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
- //
- //if drugStockConfig.IsOpen == 1 {
- //
- // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
- // if advice.ID == 0 { //医嘱不存在
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
- // drug.Total = drug.Total - advice.PrescribingNumber
- // service.UpdateBaseDrugLib(&drug)
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
- // num := advice.PrescribingNumber * float64(drug.MinNumber)
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else if advice.ID > 0 { //医嘱存在
- // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
- // var num float64
- //
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
- // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
- // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
- // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
- // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // if num2 > advice.PrescribingNumber {
- // num = num2 - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - num2
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
- // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
- // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // if num1 > num2 {
- // num = num1 - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num1 < num2 {
- // num = num2 - num1
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
- // if hisAdvice.PrescribingNumber > num2 {
- // num = hisAdvice.PrescribingNumber - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = num2 - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- // }
- // }
- //}
-
- //
- //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
- // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
- // advice.ExecutionTime = execution_time
- //}
- //
- //
- //
- //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
- // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
- // advice.ExecutionStaff = execution_staff
- //}
- //
- //
- //
- //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
- // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
- // advice.ExecutionState = execution_state
- //}
- //
- //
- //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
- // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
- // advice.CheckTime = check_time
- //}
- //
- //
- //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
- // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
- // advice.CheckState = check_state
- //}
- //
- //
- //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
- // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
- // advice.Checker = checker
- //}
- //
- //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
- // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
- // advice.StartTime = start_time
- //}
-
- return 0
- }
-
- func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
- project.ExecutionStaff = 0
- project.ExecutionState = 2
- project.ExecutionTime = 0
- project.Checker = 0
- project.CheckState = 2
- project.CheckTime = 0
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- temp_project, _ := service.GetHisPrescriptionProjectByID(id)
- project.ExecutionStaff = temp_project.ExecutionStaff
- project.ExecutionState = temp_project.ExecutionState
- project.ExecutionTime = temp_project.ExecutionTime
- project.Checker = temp_project.Checker
- project.CheckState = temp_project.CheckState
- project.CheckTime = temp_project.CheckTime
- project.TeamId = temp_project.TeamId
- }
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
-
- }
-
- if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
- team_id := int64(json["team_id"].(float64))
- project.TeamId = team_id
-
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // project.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // project.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // project.WeekDay = week_day
- //}
-
- //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
- //
- //if project.ID == 0 {
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // f_count, _ := strconv.ParseFloat(project.Count, 64)
- // good.Total = good.Total - f_count
- // service.UpdateGoodInfo(&good)
- // }
- // }
- //
- //} else {
- // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
- //
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // if project.Count < temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_two - f_count_one
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total + other_count_two
- // service.UpdateGoodInfo(&good)
- // } else if project.Count > temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_one - f_count_two
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total - other_count_two
- // service.UpdateGoodInfo(&good)
- // }
- //
- // }
- // }
- //
- //}
-
- return 0
- }
-
- func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
- if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
- is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
- advice.IsSelfDrug = is_self_drug
- }
- if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
- //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
- drug_way_count, _ := json["drug_way_count"].(string)
- advice.DrugWayCount = drug_way_count
- }
-
- if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
- hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
- advice.HospApprFlag = hosp_appr_flag
- }
-
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // advice.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // advice.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // advice.WeekDay = week_day
- //}
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
-
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- if advice.ID > 0 {
- hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
- if err == nil {
- if hisAdvice.ID > 0 {
- advice.ExecutionTime = hisAdvice.ExecutionTime
- advice.ExecutionStaff = hisAdvice.ExecutionStaff
- advice.ExecutionState = hisAdvice.ExecutionState
- advice.CheckTime = hisAdvice.CheckTime
- advice.Checker = hisAdvice.Checker
- advice.CheckState = hisAdvice.CheckState
- advice.StartTime = hisAdvice.StartTime
- advice.HospApprFlag = hisAdvice.HospApprFlag
- advice.IsMedicine = hisAdvice.IsMedicine
- if hisAdvice.UserOrgId == 10028 {
- 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 {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- }
- } else {
- if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- //advice.UpdatedTime = time.Now().Unix()
- advice.CreatedTime = hisAdvice.CreatedTime
- advice.UpdatedTime = time.Now().Unix()
- } else {
- advice.CreatedTime = hisAdvice.CreatedTime
- advice.UpdatedTime = hisAdvice.UpdatedTime
-
- }
- }
- //advice.Groupno = hisAdvice.Groupno
- } else {
- advice.IsMedicine = 0
- ctime := time.Now().Unix()
- advice.CreatedTime = ctime
- advice.UpdatedTime = ctime
-
- }
- }
- } else {
- advice.IsMedicine = 0
- ctime := time.Now().Unix()
- advice.CreatedTime = ctime
- advice.UpdatedTime = ctime
-
- }
- }
-
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
- //
- //if drugStockConfig.IsOpen == 1 {
- //
- // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
- // if advice.ID == 0 { //医嘱不存在
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
- // drug.Total = drug.Total - advice.PrescribingNumber
- // service.UpdateBaseDrugLib(&drug)
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
- // num := advice.PrescribingNumber * float64(drug.MinNumber)
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else if advice.ID > 0 { //医嘱存在
- // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
- // var num float64
- //
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
- // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
- // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
- // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
- // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // if num2 > advice.PrescribingNumber {
- // num = num2 - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - num2
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
- // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
- // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // if num1 > num2 {
- // num = num1 - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num1 < num2 {
- // num = num2 - num1
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
- // if hisAdvice.PrescribingNumber > num2 {
- // num = hisAdvice.PrescribingNumber - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = num2 - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- // }
- // }
- //}
-
- //
- //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
- // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
- // advice.ExecutionTime = execution_time
- //}
- //
- //
- //
- //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
- // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
- // advice.ExecutionStaff = execution_staff
- //}
- //
- //
- //
- //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
- // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
- // advice.ExecutionState = execution_state
- //}
- //
- //
- //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
- // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
- // advice.CheckTime = check_time
- //}
- //
- //
- //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
- // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
- // advice.CheckState = check_state
- //}
- //
- //
- //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
- // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
- // advice.Checker = checker
- //}
- //
- //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
- // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
- // advice.StartTime = start_time
- //}
-
- return 0
- }
-
- func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
- project.ExecutionStaff = 0
- project.ExecutionState = 2
- project.ExecutionTime = 0
- project.Checker = 0
- project.CheckState = 2
- project.CheckTime = 0
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- temp_project, _ := service.GetHisPrescriptionProjectByID(id)
- project.ExecutionStaff = temp_project.ExecutionStaff
- project.ExecutionState = temp_project.ExecutionState
- project.ExecutionTime = temp_project.ExecutionTime
- project.Checker = temp_project.Checker
- project.CheckState = temp_project.CheckState
- project.CheckTime = temp_project.CheckTime
- project.TeamId = temp_project.TeamId
-
- }
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
-
- }
-
- if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
- team_id := int64(json["team_id"].(float64))
- project.TeamId = team_id
-
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // project.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // project.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // project.WeekDay = week_day
- //}
-
- //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
- //
- //if project.ID == 0 {
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // f_count, _ := strconv.ParseFloat(project.Count, 64)
- // good.Total = good.Total - f_count
- // service.UpdateGoodInfo(&good)
- // }
- // }
- //
- //} else {
- // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
- //
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // if project.Count < temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_two - f_count_one
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total + other_count_two
- // service.UpdateGoodInfo(&good)
- // } else if project.Count > temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_one - f_count_two
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total - other_count_two
- // service.UpdateGoodInfo(&good)
- // }
- //
- // }
- // }
- //
- //}
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- if id > 0 {
- temp_project, _ := service.GetHisPrescriptionProjectByID(id)
-
- if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
- fmt.Println("666666")
- project.Mtime = time.Now().Unix()
- project.Ctime = temp_project.Ctime
-
- } else {
- project.Mtime = temp_project.Mtime
- project.Ctime = temp_project.Ctime
- }
- } else {
- ctime := time.Now().Unix()
- project.Mtime = ctime
- project.Ctime = ctime
- }
- }
- return 0
- }
-
- func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- additionalCharge.ID = id
- }
-
- if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
- item_id := int64(json["item_id"].(float64))
- additionalCharge.ItemId = item_id
- config, _ := service.GetAdditionChargeByID(org_id, item_id)
- if config.ID > 0 {
- if len(config.Code) > 0 {
- additionalCharge.MedListCodg = config.Code
- }
- }
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- // }
-
- //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- //}
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- additionalCharge.Price = price
- }
- if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
- count, _ := json["count"].(string)
- counts, _ := strconv.ParseInt(count, 10, 64)
- additionalCharge.Count = counts
- }
- if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
- item_name, _ := json["item_name"].(string)
- additionalCharge.ItemName = item_name
- }
-
- return 0
- }
-
- func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
- advice.FrequencyType = 1
- return 0
- }
-
- func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- project.FrequencyType = 1
-
- return 0
- }
-
- func (c *HisApiController) GetHisOrderListTwo() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- //fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUser := c.GetAdminUserInfo()
- org_id := adminUser.CurrentOrgId
- order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order2": order,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetHisOrderList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- p_type, _ := c.GetInt64("p_type", 0)
- sort_type, _ := c.GetInt64("sort_type", 0)
- charge_type, _ := c.GetInt64("charge_type", 0)
- sch_type, _ := c.GetInt64("sch_type", 0)
- zone_type, _ := c.GetInt64("zone_type", 0)
- med_type, _ := c.GetInt64("med_type", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- //fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUser := c.GetAdminUserInfo()
- org_id := adminUser.CurrentOrgId
- 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)
-
- for _, item := range order {
- info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
- item.DoctorName = info.Doctor
- item.DepartmentName = info.XtHisDepartment.Name
- }
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "total": total,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetHisOrder() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- number := c.GetString("number")
- adminInfo := c.GetAdminUserInfo()
- order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
- prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "prescription": prescriptions,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- func (c *HisApiController) GetHisPrescriptionList() {
- record_date := c.GetString("record_date")
- keywords := c.GetString("keywords")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- sch_type, _ := c.GetInt64("sch_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
-
- //adminInfo := c.GetAdminUserInfo()
- //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
- //fmt.Println(prescriptionOrder)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": prescriptionOrder,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetHisPrescriptionInfo() {
- id, _ := c.GetInt64("id")
- adminInfo := c.GetAdminUserInfo()
- prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
- prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": prescriptionOrder,
- "prescription": prescription,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetMedicalInsuranceConfig() {
- adminUser := c.GetAdminUserInfo()
- config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
-
- }
-
- type ResultTwo struct {
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Baseinfo struct {
- Age float64 `json:"age"`
- Brdy string `json:"brdy"`
- Certno string `json:"certno"`
- Gend string `json:"gend"`
- Naty string `json:"naty"`
- PsnCertType string `json:"psn_cert_type"`
- PsnName string `json:"psn_name"`
- PsnNo string `json:"psn_no"`
- } `json:"baseinfo"`
- Idetinfo []interface{} `json:"idetinfo"`
- Iinfo []struct {
- Balc float64 `json:"balc"`
- CvlservFlag string `json:"cvlserv_flag"`
- EmpName string `json:"emp_name"`
- InsuplcAdmdvs string `json:"insuplc_admdvs"`
- Insutype string `json:"insutype"`
- PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
- PausInsuDate interface{} `json:"paus_insu_date"`
- PsnInsuDate string `json:"psn_insu_date"`
- PsnInsuStas string `json:"psn_insu_stas"`
- PsnType string `json:"psn_type"`
- } `json:"insuinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnInfo interface{} `json:"warn_info"`
- }
- type ResultThree struct {
- Cainfo interface{} `json:"cainfo"`
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Data struct {
- IptOtpNo string `json:"ipt_otp_no"`
- MdtrtID string `json:"mdtrt_id"`
- PsnNo string `json:"psn_no"`
- } `json:"data"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
- type ResultFour struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Result []struct {
- BasMednFlag string `json:"bas_medn_flag"`
- ChldMedcFlag string `json:"chld_medc_flag"`
- ChrgitmLv string `json:"chrgitm_lv"`
- Cnt float64 `json:"cnt"`
- DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
- DrtReimFlag string `json:"drt_reim_flag"`
- FeedetlSn string `json:"feedetl_sn"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- ListSpItemFlag string `json:"list_sp_item_flag"`
- LmtUsedFlag string `json:"lmt_used_flag"`
- MedChrgitmType string `json:"med_chrgitm_type"`
- Memo string `json:"memo"`
- OverlmtAmt float64 `json:"overlmt_amt"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- Pric float64 `json:"pric"`
- PricUplmtAmt float64 `json:"pric_uplmt_amt"`
- SelfpayProp float64 `json:"selfpay_prop"`
- } `json:"result"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype string `json:"signtype"`
- WarnMsg string `json:"warn_msg"`
- }
- type ResultFive struct {
- Insutype string `json:"insutype"`
- }
- type ResultSix struct {
- Cainfo interface{} `json:"cainfo"`
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
- type ResultSeven struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Setldetail []interface{} `json:"setldetail"`
- Setlinfo struct {
- AcctMulaidPay float64 `json:"acct_mulaid_pay"`
- AcctPay float64 `json:"acct_pay"`
- ActPayDedc float64 `json:"act_pay_dedc"`
- Age float64 `json:"age"`
- Balc float64 `json:"balc"`
- Brdy string `json:"brdy"`
- Certno string `json:"certno"`
- ClrOptins string `json:"clr_optins"`
- ClrType string `json:"clr_type"`
- ClrWay string `json:"clr_way"`
- CvlservFlag string `json:"cvlserv_flag"`
- CvlservPay float64 `json:"cvlserv_pay"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- FundPaySumamt float64 `json:"fund_pay_sumamt"`
- Gend string `json:"gend"`
- HifesPay float64 `json:"hifes_pay"`
- HifmiPay float64 `json:"hifmi_pay"`
- HifobPay float64 `json:"hifob_pay"`
- HifpPay float64 `json:"hifp_pay"`
- HospPartAmt float64 `json:"hosp_part_amt"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- Insutype string `json:"insutype"`
- MafPay float64 `json:"maf_pay"`
- MdtrtCertType string `json:"mdtrt_cert_type"`
- MdtrtID string `json:"mdtrt_id"`
- MedType string `json:"med_type"`
- MedfeeSumamt float64 `json:"medfee_sumamt"`
- MedinsSetlID string `json:"medins_setl_id"`
- Naty string `json:"naty"`
- OthPay float64 `json:"oth_pay"`
- OverlmtSelfpay float64 `json:"overlmt_selfpay"`
- PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- PsnCashPay float64 `json:"psn_cash_pay"`
- PsnCertType string `json:"psn_cert_type"`
- PsnName string `json:"psn_name"`
- PsnNo string `json:"psn_no"`
- PsnPartAmt float64 `json:"psn_part_amt"`
- PsnType string `json:"psn_type"`
- SetlID string `json:"setl_id"`
- SetlTime string `json:"setl_time"`
- } `json:"setlinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultEight struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Stmtinfo struct {
- SetlOptins string `json:"setl_optins"`
- StmtRslt string `json:"stmt_rslt"`
- StmtRsltDscr string `json:"stmt_rslt_dscr"`
- } `json:"stmtinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultNine struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- FileQuryNo string `json:"file_qury_no"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultTen struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- DldEndtime string `json:"dld_endtime"`
- FileQuryNo string `json:"file_qury_no"`
- Filename string `json:"filename"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultEleven struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Setlinfo struct {
- FixmedinsName string `json:"fixmedins_name"`
- FixmedinsCode string `json:"fixmedins_code"`
- PsnNo string `json:"psn_no"`
- PsnName string `json:"psn_name"`
- HifobPay float64 `json:"hifob_pay"`
- Gend string `json:"gend"`
- Brdy string `json:"brdy"`
- PsnCertType string `json:"psn_cert_type"`
- PsnType string `json:"psn_type"`
- EmpName string `json:"emp_name"`
- Certno string `json:"certno"`
- Insutype string `json:"insutype"`
- MedfeeSumamt float64 `json:"medfee_sumamt"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- OverlmtSelfpay float64 `json:"overlmt_selfpay"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- ActPayDedc float64 `json:"act_pay_dedc"`
- HifpPay float64 `json:"hifp_pay"`
- PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
- CvlservPay float64 `json:"cvlserv_pay"`
- HifesPay float64 `json:"hifes_pay"`
- HifmiPay float64 `json:"hifmi_pay"`
- MafPay float64 `json:"maf_pay"`
- OthPay float64 `json:"oth_pay"`
- FundPaySumamt float64 `json:"fund_pay_sumamt"`
- PsnPay float64 `json:"psn_pay"`
- AcctPay float64 `json:"acct_pay"`
- CashPayamt float64 `json:"cash_payamt"`
- Balc float64 `json:"balc"`
- AcctMulaidPay float64 `json:"acct_mulaid_pay"`
- MedinsSetlId string `json:"medins_setl_id"`
- RefdSetlFlag string `json:"refd_setl_flag"`
- SetlTime string `json:"setl_time"`
- MedType string `json:"med_type"`
- } `json:"setlinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type Custom struct {
- DetItemFeeSumamt string
- Cut string
- FeedetlSn string
- Price string
- MedListCodg string
- Type int64
- AdviceId int64
- ProjectId int64
- ItemId int64
- CostType int64
- }
-
- // 获取个人信息----挂号-----上传就诊信息
- func (c *HisApiController) GetRegisterInfo() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- settlementValue, _ := c.GetInt64("settlement_value")
- medical_insurance_card := c.GetString("medical_insurance_card")
- name := c.GetString("name")
- id_card_type, _ := c.GetInt64("id_card_type")
- certificates, _ := c.GetInt64("certificates")
- medical_care, _ := c.GetInt64("medical_care")
- birthday := c.GetString("birthday")
- age, _ := c.GetInt64("age")
- id_card := c.GetString("id_card")
- register_type, _ := c.GetInt64("register")
- doctor, _ := c.GetInt64("doctor")
- department, _ := c.GetInt64("department")
- gender, _ := c.GetInt64("sex")
- phone := c.GetString("phone")
- registration_fee, _ := c.GetFloat("registration_fee")
- medical_expenses, _ := c.GetFloat("medical_expenses")
- social_type, _ := c.GetInt64("social_type")
-
- //diagnosis_id, _ := c.GetInt64("diagnosis")
-
- diagnosis_ids := c.GetString("diagnosis")
-
- sick_type, _ := c.GetInt64("sick_type")
- reg_type := c.GetString("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
- birthUnix := birthdays.Unix()
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- adminInfo := c.GetAdminUserInfo()
- tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
- if tempPatient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
- return
- }
- var patient service.Patients
- if id == 0 {
- patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
-
- } else {
- patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
-
- }
-
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(patient.IdCardNo) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
- return
- }
-
- his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
- if len(his) >= 1 {
- order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
- if len(his) >= 1 && order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
- return
- }
- }
-
- timeStr := time.Now().Format("2006-01-02 15:04:05")
- fmt.Println(timeStr)
- timeArr := strings.Split(timeStr, " ")
- fmt.Println(timeArr)
-
- timeArrTwo := strings.Split(timeArr[0], "-")
- timeArrThree := strings.Split(timeArr[1], ":")
- var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
-
- lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
-
- if len(lists) == 0 {
- var hisPatient models.XtHisPatient
- hisPatient = models.XtHisPatient{
- Name: name,
- Age: age,
- Gender: gender,
- Birthday: birthUnix,
- Phone: phone,
- MedicalTreatmentType: medical_care,
- IdType: certificates,
- IdCardNo: id_card,
- BalanceAccountsType: settlementValue,
- SocialType: social_type,
- MedicalInsuranceNumber: medical_insurance_card,
- RegisterType: register_type,
- RegisterCost: registration_fee,
- TreatmentCost: medical_expenses,
- AdminUserId: adminInfo.AdminUser.Id,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- RecordDate: recordDateTime,
- IsReturn: 1,
- PatientId: patient.ID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Number: str,
- IdCardType: id_card_type,
- Departments: department,
- Doctor: doctor,
- PType: reg_type,
- Diagnosis: diagnosis_ids,
- SickType: sick_type,
- }
- service.CreateHisPatient(&hisPatient)
-
- service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": hisPatient,
- })
- } else {
- //chrgBchno := rand.Intn(1000000) + 10000
- var hisPatient models.XtHisPatient
- hisPatient = models.XtHisPatient{
- Name: name,
- Age: age,
- Gender: gender,
- Birthday: birthUnix,
- Phone: phone,
- MedicalTreatmentType: medical_care,
- IdType: certificates,
- IdCardNo: id_card,
- BalanceAccountsType: settlementValue,
- SocialType: social_type,
- MedicalInsuranceNumber: medical_insurance_card,
- RegisterType: register_type,
- RegisterCost: registration_fee,
- TreatmentCost: medical_expenses,
- AdminUserId: adminInfo.AdminUser.Id,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- RecordDate: recordDateTime,
- IsReturn: 1,
- PatientId: patient.ID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Number: str,
- IdCardType: id_card_type,
- Departments: department,
- Doctor: doctor,
- PType: reg_type,
- Diagnosis: diagnosis_ids,
- SickType: sick_type,
- }
- service.CreateHisPatient(&hisPatient)
-
- service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": hisPatient,
- })
-
- }
-
- }
-
- // 上传明细----结算
- func (c *HisApiController) GetUploadInfo() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- oth_desc := c.GetString("oth_desc")
- pay_way, _ := c.GetInt64("pay_way")
- pay_ways := c.GetString("pay_ways")
-
- pay_price, _ := c.GetFloat("pay_price")
- pay_card_no := c.GetString("pay_card_no")
- discount_price, _ := c.GetFloat("discount_price")
- preferential_price, _ := c.GetFloat("preferential_price")
- reality_price, _ := c.GetFloat("reality_price")
- found_price, _ := c.GetFloat("found_price")
- medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
- private_price, _ := c.GetFloat("private_price")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
-
- fapiao_code := c.GetString("fapiao_code")
- fapiao_number := c.GetString("fapiao_number")
-
- diagnosis_id := c.GetString("diagnosis")
- sick_type, _ := c.GetInt64("sick_type")
- reg_type, _ := c.GetInt64("p_type")
- order_id, _ := c.GetInt64("order_id")
-
- cash_pay := c.GetString("cash_pay")
- wechat_pay := c.GetString("wechat_pay")
- ali_pay := c.GetString("ali_pay")
- jifen_pay := c.GetString("jifen_pay")
- band_card_pay := c.GetString("band_card_pay")
-
- dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
- tmp_decimal := c.GetString("tmp_decimal")
-
- //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
-
- var decimal float64 //本次使用的押金
- var errmsg error
- tx := service.XTWriteDB().Begin() //开了事务
- //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
- defer func() {
- if errmsg != nil {
- utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- fmt.Println("dec_way", dec_way)
- if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
- return
- }
- if len(tmp_decimal) > 0 {
- if tmp_decimal[0] == 45 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
- return
- }
- }
- tt, errs := strconv.ParseFloat(tmp_decimal, 64)
- fmt.Println(errs)
-
- decimal = tt
-
- his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
-
- tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- var prescriptions []*models.HisPrescription
-
- var prescriptionsOne []*models.HisPrescription
-
- var start_time int64
- var end_time int64
-
- ids_str := c.GetString("ids")
- ids_arr := strings.Split(ids_str, ",")
- if tempOrder.ID == 0 {
- if settle_accounts_type == 1 { //日结
- fmt.Println(reg_type)
-
- if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
-
- prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
-
- prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
- } else {
- prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
-
- prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
- }
- } else { //月结
-
- start_time_str := c.GetString("start_time")
- end_time_str := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time = recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time = recordEndTime
- prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
-
- prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
- }
-
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var oldGoods []*models.OldDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
- var infoList []*models.HisDoctorAdviceInfo
- var hisAdvice []*models.HisDoctorAdviceInfo
- var newGoodOne []*models.NewDialysisBeforePrepareGoods
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
-
- //判断库存不足
- //结算出库开关
- settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
- if settConfig.IsOpen == 1 {
- //判断库存的地方
- for _, info := range prescriptions {
- if info.Type == 1 {
- infos = append(infos, info.HisDoctorAdviceInfo...)
-
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- }
-
- for _, info := range prescriptionsOne {
-
- if info.Type == 1 {
- hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
- }
-
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var newGood models.NewDialysisBeforePrepareGoods
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoodOne = append(newGoodOne, &newGood)
- }
- }
- }
- }
-
- //判断
- for _, itemOne := range infos {
-
- for _, itemTwo := range hisAdvice {
- if itemOne.DrugId == itemTwo.DrugId {
- itemTwo.Child = append(itemTwo.Child, itemOne)
- }
- }
- }
-
- for _, itemTwo := range hisAdvice {
- medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
- var sum_out_count int64
- for _, itemThree := range itemTwo.Child {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
-
- sum_out_count += prescribing_number
- }
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
-
- if sum_out_count > drugStockOut.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- })
- return
- }
- }
- for _, itemOne := range newGoods {
- for _, item := range newGoodOne {
- if itemOne.GoodId == item.GoodId {
- item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
- }
- }
- }
-
- for _, item := range newGoodOne {
- var sum_out_count_one int64
- good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
- for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
- sum_out_count_one += itemOne.Count
- }
- list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- fmt.Println("sum_out_count_one", sum_out_count_one)
- fmt.Println("list.FlushCount", list.FlushCount)
- if sum_out_count_one > list.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "good": good,
- })
- return
- }
- }
- }
-
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
- strconv.FormatInt(his.PatientId, 10)
-
- var ids []int64
-
- for _, item := range prescriptions {
- ids = append(ids, item.ID)
- }
- var total float64
-
- for _, item := range prescriptions {
- fmt.Println(item)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- total = total + (subItem.Price * subItem.PrescribingNumber)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- total = total + (subItem.Price * cnt)
- }
- }
-
- for _, subItem := range item.HisAdditionalCharge {
- total = total + (subItem.Price * float64(subItem.Count))
- }
- }
-
- if reg_type == 1111 || reg_type == 1112 {
- reg_type = 11
- }
-
- tm := time.Unix(time.Now().Unix(), 0)
-
- allTotal := fmt.Sprintf("%.4f", total)
- totals, _ := strconv.ParseFloat(allTotal, 64)
- order := &models.HisOrder{
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- PatientId: id,
- SettleAccountsDate: recordDateTime,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- OrderStatus: 2,
- MdtrtId: his.Number,
- Number: chrg_bchno,
- MedfeeSumamt: totals,
- PayWay: pay_way,
- PayWays: pay_ways,
- PayPrice: pay_price,
- MedType: strconv.Itoa(int(reg_type)),
- PayCardNo: pay_card_no,
- DiscountPrice: discount_price,
- PreferentialPrice: preferential_price,
- RealityPrice: reality_price,
- FoundPrice: found_price,
- MedicalInsurancePrice: medical_insurance_price,
- PrivatePrice: private_price,
- SettleEndTime: end_time,
- SettleStartTime: start_time,
- PsnPartAmt: totals,
- PsnCashPay: totals,
- SettleType: settle_accounts_type,
- FaPiaoCode: fapiao_code,
- FaPiaoNumber: fapiao_number,
- Diagnosis: diagnosis_id,
- PType: 2,
- SetlTime: tm.Format("2006-01-02 15:04:05"),
- Decimal: decimal,
- OthDesc: oth_desc,
- CashPay: cash_pay,
- WechatPay: wechat_pay,
- AliPay: ali_pay,
- JifenPay: jifen_pay,
- BandCardPay: band_card_pay,
- Creator: adminUser.AdminUser.Id,
- }
- err = service.CreateOrderTX(order, tx)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
-
- var customs []*Custom
- for _, item := range prescriptions {
- if item.Type == 1 { //药品a
- for _, subItem := range item.HisDoctorAdviceInfo {
- cus := &Custom{
- AdviceId: subItem.ID,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
- Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", subItem.Price),
- MedListCodg: subItem.MedListCodg,
- Type: 1,
- CostType: 9,
- }
- customs = append(customs, cus)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &Custom{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.4f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
- MedListCodg: subItem.MedListCodg,
- Type: 2,
- CostType: subItem.HisProject.CostClassify,
- }
- customs = append(customs, cus)
- }
- }
- for _, item := range item.HisAdditionalCharge {
- cus := &Custom{
- ItemId: item.ID,
- AdviceId: 0,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
- Cut: fmt.Sprintf("%.4f", float64(item.Count)),
- FeedetlSn: item.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(item.Price)),
- MedListCodg: item.XtHisAddtionConfig.Code,
- Type: 3,
- CostType: 5,
- }
- customs = append(customs, cus)
- }
- }
-
- for _, item := range customs {
- var advice_id int64 = 0
- var project_id int64 = 0
- var item_id int64 = 0
-
- var types int64 = 0
- var med_chrgitm_type string
- if item.Type == 1 {
- advice_id = item.AdviceId
- project_id = 0
- item_id = 0
- med_chrgitm_type = "09"
- } else if item.Type == 2 {
- med_chrgitm_type = "05"
- if item.CostType == 3 {
- med_chrgitm_type = "04"
- }
- if item.CostType == 8 {
- med_chrgitm_type = "03"
- }
- advice_id = 0
- item_id = 0
-
- project_id = item.ProjectId
- } else if item.Type == 3 {
- advice_id = 0
- item_id = item.ItemId
- project_id = 0
- med_chrgitm_type = "08"
-
- }
- detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
- cut, _ := strconv.ParseFloat(item.Cut, 32)
- pric, _ := strconv.ParseFloat(item.Price, 32)
- info := &models.HisOrderInfo{
- OrderNumber: order.Number,
- UploadDate: time.Now().Unix(),
- AdviceId: advice_id,
- DetItemFeeSumamt: detItemFeeSumamt,
- MedChrgitmType: med_chrgitm_type,
- Cnt: cut,
- Pric: pric,
- PatientId: id,
- Status: 1,
- Mtime: time.Now().Unix(),
- Ctime: time.Now().Unix(),
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- OrderId: order.ID,
- ProjectId: project_id,
- Type: types,
- ItemId: item_id,
- }
- service.CreateOrderInfoTX(info, tx)
- }
- his.Diagnosis = diagnosis_id
- his.SickType = sick_type
- his.RegisterType = reg_type
- his.MedicalTreatmentType = reg_type
- service.UpdataHisPateintTX(&his, tx)
- err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
- err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
- err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
- //判断是否使用了押金
- if dec_way == "true" {
-
- tmpstring := strconv.FormatInt(order.ID, 10)
- //扣押金
- errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
- order.Decimal = decimal
- service.UpDateOrderTwo(order, tx)
- if errmsg != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
- //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
- }
-
- if err == nil {
- for _, info := range prescriptions {
- if info.Type == 1 {
- infoList = append(infoList, info.HisDoctorAdviceInfo...)
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- var oldGood models.OldDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- good.PatientId = sumItem.PatientId
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGood.PatientId = sumItem.HisPatientId
- newGoods = append(newGoods, &newGood)
-
- oldGood.GoodId = sumItem.GoodInfo.ID
- oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count3, _ := strconv.Atoi(sumItem.Count)
- oldGood.Count = int64(count3)
- oldGood.StorehouseId = houseConfig.StorehouseOutInfo
- oldGood.ProjectId = sumItem.ID
- oldGood.RecordDate = sumItem.RecordDate
- oldGood.PatientId = sumItem.HisPatientId
-
- oldGoods = append(oldGoods, &oldGood)
- }
-
- }
-
- }
- }
- if settConfig.IsOpen == 1 {
-
- for _, item := range infoList {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if medical.IsUse == 2 {
- //药品出库
- service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
- service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
-
- }
-
- }
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- if len(oldGoods) > 0 {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: nowtime,
- Type: 1,
- StorehouseId: storeConfig.StorehouseOutInfo,
- IsCheck: 1,
- OrderId: order.ID,
- IsSys: 5,
- }
- //查询是否生成出库单
- out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
- if out.ID == 0 {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
-
- for _, item := range oldGoods {
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: his.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: adminUser.CurrentOrgId,
- Count: item.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- CommdityCode: item.CommdityCode,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
- //非零用
- if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
- service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
- }
-
- if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
- service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
- }
-
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "结算成功",
- })
-
- }
- }
-
- }
-
- // 退款
- func (c *HisApiController) Refund() {
- order_id, _ := c.GetInt64("order_id")
- order, _ := service.GetHisOrderByID(order_id)
- adminUser := c.GetAdminUserInfo()
- orgid := c.GetAdminUserInfo().CurrentOrgId
-
- err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- tmp := strconv.FormatInt(order.ID, 10)
- //当押金不为零时产生退费记录
- if order.Decimal != 0 {
- err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
-
- for _, info := range orders {
- if info.AdviceId > 0 && info.ProjectId == 0 {
- infos = append(infos, &info.HisDoctorAdviceInfo)
- }
- if info.ProjectId > 0 && info.AdviceId == 0 {
- if info.HisPrescriptionProject.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = info.HisPrescriptionProject.ID
- good.PatientId = info.PatientId
- good.OrderId = order_id
- goods = append(goods, &good)
-
- newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = info.HisPrescriptionProject.ID
- newGood.RecordDate = order.SettleAccountsDate
- newGood.UserOrgId = order.UserOrgId
- newGood.PatientId = info.PatientId
- newGood.OrderId = order_id
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
- if settConfig.IsOpen == 1 {
- for _, item := range infos {
-
- service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
-
- }
-
- for _, item := range newGoods {
- service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退费成功",
- })
- }
-
- func (c *HisApiController) RefundNumber() {
- his_patient_id, _ := c.GetInt64("id")
- info, _ := service.GetNewHisPatientInfo(his_patient_id)
- info.Status = 0
- count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
- return
- }
-
- err := service.SaveHisPatient(info)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退号成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- func (this *HisApiController) AdditionalCharge() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- his_patient_id := int64(dataBody["his_patient_id"].(float64))
- patient_id := int64(dataBody["patient_id"].(float64))
- medicineData, _ := dataBody["medicineData"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- admin_user_id := adminUserInfo.AdminUser.Id
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- var additionalCharges []*models.HisAdditionalCharge
- for _, item := range medicineData {
-
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
-
- items := item.(map[string]interface{})
- money := items["price"].(string)
- item_id_str := items["item_id"].(string)
- name := items["name"].(string)
- id_str := items["id"].(string)
- moneys, _ := strconv.ParseInt(money, 10, 64)
- monStr := strconv.FormatInt(moneys, 10)
- monneyStr, _ := strconv.ParseFloat(monStr, 64)
- item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
- id, _ := strconv.ParseInt(id_str, 10, 64)
- additionalCharge := &models.HisAdditionalCharge{
- ID: id,
- HisPatientId: his_patient_id,
- UserOrgId: orgId,
- PatientId: patient_id,
- RecordDate: timenow,
- Price: monneyStr,
- Status: 1,
- ItemName: name,
- ItemId: item_id,
- AdminUserId: admin_user_id,
- CreatedTime: time.Now().Unix(),
- OrderStatus: 0,
- PrescriptionNumber: "",
- BatchNumber: "",
- FeedetlSn: p_number,
- }
- service.CreateAdditionalCharge(additionalCharge)
-
- additionalCharges = append(additionalCharges, additionalCharge)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "添加成功",
- "additional_charges": additionalCharges,
- })
- }
-
- func (this *HisApiController) DeleteAddition() {
- id, _ := this.GetInt64("id")
- //TODO 需要判断是否已经结算
- err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *HisApiController) GetAdminUsers() {
- adminUser := this.GetAdminUserInfo()
- doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "doctors": doctors,
- })
- }
-
- func (this *HisApiController) GetLastOrNextHisPrescription() {
- change_type, _ := this.GetInt64("type", 0)
- record_date := this.GetString("record_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
- p_type, _ := this.GetInt64("p_type", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theAdviceRecordTime.Unix()
- adminUserInfo := this.GetAdminUserInfo()
- prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
-
- if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
- _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, subitems := range prescriptions {
- for _, item := range subitems.VMHisPrescription {
- for _, subItem := range item.HisDoctorAdviceInfo {
- drug, _ := service.GetDrugByGoodId(subItem.DrugId)
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
- if info.RetailPrice > 0 {
- if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- subItem.Drug.RetailPrice = drug.RetailPrice
- }
- if subItem.PrescribingNumberUnit == drug.MinUnit {
- subItem.Drug.MinPrice = info.RetailPrice
- subItem.Drug.RetailPrice = info.RetailPrice
- }
-
- }
- }
- }
- }
- }
-
- if config.ID > 0 && config.IsOpen == 1 {
- for _, subitems := range prescriptions {
- for _, item := range subitems.VMHisPrescription {
- for _, subItem := range item.HisPrescriptionProject {
- if subItem.Type == 3 {
- info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
- if info.Price > 0 {
- subItem.GoodInfo.PackingPrice = info.Price
- }
- }
- }
- }
- }
- }
- }
-
- if err == nil {
- if len(prescriptions) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- })
- return
- }
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *HisApiController) GetCallHisPrescription() {
- patient_id, _ := this.GetInt64("patient_id", 0)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- p_type, _ := this.GetInt64("p_type")
-
- endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- adminUserInfo := this.GetAdminUserInfo()
- prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
-
- //if
- //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- //
- //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
-
- if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
- _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, subitems := range prescriptions {
- for _, item := range subitems.VMHisPrescription {
- for _, subItem := range item.HisDoctorAdviceInfo {
- drug, _ := service.GetDrugByGoodId(subItem.DrugId)
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
- if info.RetailPrice > 0 {
- if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- subItem.Drug.RetailPrice = drug.RetailPrice
- }
- if subItem.PrescribingNumberUnit == drug.MinUnit {
- subItem.Drug.MinPrice = info.RetailPrice
- subItem.Drug.RetailPrice = info.RetailPrice
- }
-
- }
- }
- }
- }
- }
- if config.ID > 0 && config.IsOpen == 1 {
- for _, subitems := range prescriptions {
- for _, item := range subitems.VMHisPrescription {
- for _, subItem := range item.HisPrescriptionProject {
- if subItem.Type == 3 {
- info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
- if info.Price > 0 {
- subItem.GoodInfo.PackingPrice = info.Price
- }
- }
- }
- }
- }
- }
- }
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *HisApiController) GetHisDayPrescription() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
- startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- p_type, _ := this.GetInt64("p_type")
-
- order_status, _ := this.GetInt64("type")
-
- endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- adminUserInfo := this.GetAdminUserInfo()
-
- var dayHisPrescription []*models.HisPrescription
- var err error
- if order_status == 1 || order_status == 0 {
-
- dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
-
- } else if order_status == 2 {
- dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
-
- }
-
- var settle_total float64
- for _, item := range dayHisPrescription {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "day_prescription": dayHisPrescription,
- "settle_total": settle_total,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisApiController) GetHisChargePatientList() {
- record_date := c.GetString("record_date")
- order_status, _ := c.GetInt64("type")
- sch_type, _ := c.GetInt64("sch_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempPatients []*service.NewTempPatients
- //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
- if order_status != 2 {
- tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- } else {
- tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- }
-
- } else {
-
- if order_status != 2 {
- tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- } else {
- tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- }
-
- }
-
- var patients []*service.NewTempPatients
- var patients_two []*service.NewTempPatients
-
- for _, item := range tempPatients {
- if c.GetAdminUserInfo().CurrentOrgId != 10206 {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
- //过滤掉没挂号的
- if len(item.HisPatient) > 0 {
- patients_two = append(patients_two, item)
- }
-
- } else {
- if len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- })
- }
-
- func (c *HisApiController) GetHisUnRegisterPatientList() {
- record_date := c.GetString("record_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
-
- tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
-
- var patients []*service.Patients
- for _, item := range tempPatients {
- if item.HisPatient.ID == 0 {
- patients = append(patients, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- //"list_two": patients_two,
- })
-
- }
-
- func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
- newArr = make([]*service.Patients, 0)
- for i := 0; i < len(patient); i++ {
- repeat := false
- for j := i + 1; j < len(patient); j++ {
- if patient[i].ID == patient[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, patient[i])
- }
- }
- return
- }
-
- func (c *HisApiController) GetHisChargePatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- //start_time := c.GetString("start_time")
- //end_time := c.GetString("end_time")
- order_status, _ := c.GetInt64("type", 0)
- p_type, _ := c.GetInt64("p_type", 0)
- order_id, _ := c.GetInt64("order_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- //if err != nil {
- //
- //}
- //startRecordDateTime := startTime.Unix()
- //
- //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- //if err != nil {
- //
- //}
- //endRecordDateTime := endTime.Unix()
-
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- var prescriptions []*models.HisPrescription
- //var unChargeMonthPrescriptions []*models.HisPrescription
-
- order, _ := service.GetHisOrderByID(order_id)
-
- if order_status == 1 || order_status == 0 {
- prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
- } else if order_status == 2 {
- prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
- //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- }
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
-
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
-
- sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "last_info": lastPatientPrescriptionInfo,
- "order": order,
- "doctors": doctors,
- "department": department,
- "sch": sch,
- })
- return
- }
-
- func (c *HisApiController) GetAllOrderDetail() {
- order_id, _ := c.GetInt64("id", 0)
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
- record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
- order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "hospital_record": record,
- })
- return
-
- }
-
- func (c *HisApiController) GetAllOrderDetailCollect() {
- order_id, _ := c.GetInt64("id", 0)
-
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
- patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
-
- his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
- //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
- record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- var bedCostTotal float64 = 0 //床位总费
- //var bedCostSelfTotal float64 = 0 //床位自费
-
- var operationCostTotal float64 = 0 //手术费
- //var operationCostSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- //var otherCostSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- //var materialCostSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- //var westernMedicineCostSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- //var checkCostSelfTotal float64 = 0 //检查费
-
- var laboratoryCostTotal float64 = 0 //化验费
- //var laboratoryCostSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- //var treatCostSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
- var BalanceAccountsType int64
- if his.ID > 0 {
- BalanceAccountsType = his.BalanceAccountsType
- } else {
- BalanceAccountsType = record.BalanceAccountsType
- }
- if BalanceAccountsType != 2 {
- for _, item := range order_info {
- if org_id == 10215 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else if org_id == 10188 || org_id == 10217 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
- //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else {
-
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- //if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //zhenChaCostSelfTotal = zhenChaCostTotal
- //}
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "his_hospital": record,
- "bedCostTotal": bedCostTotal,
- "operationCostTotal": operationCostTotal,
- "otherCostTotal": otherCostTotal,
- "materialCostTotal": materialCostTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "checkCostTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "treatCostTotal": treatCostTotal,
- })
- } else {
- for _, item := range order_info {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "14"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
-
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "14"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- }
- }
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- for _, item := range order_info {
- if org_id == 10215 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else {
-
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- //if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //zhenChaCostSelfTotal = zhenChaCostTotal
- //}
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "his_hospital": record,
- "bedCostTotal": bedCostTotal,
- "operationCostTotal": operationCostTotal,
- "otherCostTotal": otherCostTotal,
- "materialCostTotal": materialCostTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "checkCostTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "treatCostTotal": treatCostTotal,
- })
-
- }
- }
-
- func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- keywords := c.GetString("keywords")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- //clr_type := c.GetString("clr_type")
- insutype := c.GetString("insutype")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- theEndtTIme = theTime.Unix()
- }
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- })
- return
-
- }
-
- func (c *HisApiController) GetPutOnRecordList() {
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- keywords := c.GetString("keywords")
- is_put_on_record, _ := c.GetInt64("is_put_on_record")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- })
- return
-
- }
-
- func (c *HisApiController) GetCompareData() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- insutype := c.GetString("insutype")
- clr_type := c.GetString("clr_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
- formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": formData,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
-
- }
- }
-
- func (c *HisApiController) GetFaPiaoData() {
- order_id, _ := c.GetInt64("order_id")
- patient_id, _ := c.GetInt64("patient_id")
- //number := c.GetString("number")
-
- adminUser := c.GetAdminUserInfo()
- order, _ := service.GetHisOrderByID(order_id)
- orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
-
- patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
-
- department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
-
- his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
-
- prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
-
- doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
- his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
-
- var bedCostTotal float64 = 0 //床位总费
- var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
-
- var hiliCostTotal float64 = 0 //护理费
- var hiliCostSelfTotal float64 = 0 //护理费
- var hiliCostPartSelfTotal float64 = 0 //护理费
-
- var laboratoryCostTotal float64 = 0 //化验费
- var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- var zhenChaCostSelfTotal float64 = 0 //其他费用
- var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
- orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
-
- var balanceAccountsType int64
- if his.ID > 0 {
-
- balanceAccountsType = his.BalanceAccountsType
- } else {
-
- balanceAccountsType = his_hospital_record.BalanceAccountsType
- }
-
- if balanceAccountsType == 2 {
- //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- for _, item := range orderInfos_two {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
-
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "02"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
-
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
-
- }
-
- }
-
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- for _, item := range orderInfos_two {
- fmt.Println(item.MedChrgitmType)
- if item.MedChrgitmType == "07" { //床位费
- hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- hiliCostSelfTotal = hiliCostTotal
- }
-
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal = bedCostTotal
- }
-
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal = checkCostTotal
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal = laboratoryCostTotal
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "06" { //手术费
- treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal = materialCostTotal
- }
-
- if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal = westernMedicineCostTotal
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10106 {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
- } else {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
-
- }
-
- }
-
- } else {
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
- } else {
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "07" { //护理
- hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
- sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
- admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "charge_admin_name": charge_admin.UserName,
- "order_number": order.Number, //业务流水号
- "id_card_no": his.IdCardNo, //社会保障号
- "patient": patient,
- "department_name": department.Name, //科室
- "number": his.Number, //门诊号
- "date": order.SettleAccountsDate, //结算日期
- "name": order.PsnName, //姓名
- "gender": patient.Gender, //性别
- "psn_cash_money": order.PsnCashPay, //个人支付
- "pay_way": "门诊", //结算方式
- "medfee_sumamt": order.MedfeeSumamt, //总费用
- "admin_user_name": admin.UserName, //收款员
- "order": order,
- "order_info": orderInfos_two,
- "his": his,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostSelfTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostSelfTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostSelfTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostSelfTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostSelfTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostSelfTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
- "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
- "his_hospital_record": his_hospital_record,
- "pre_pay_money": pre_pay_money,
- "refund_sum": sum,
- "doctor_info": doctor_info,
- "hiliCostTotal": hiliCostTotal,
- "hiliCostSelfTotal": hiliCostSelfTotal,
- "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
- })
-
- }
-
- //func (c *HisApiController) GetFaPiaoDatas() {
- // order_ids := c.GetString("order_ids")
- // patient_id, _ := c.GetInt64("patient_id")
- // adminUser := c.GetAdminUserInfo()
- //
- // orders := strings.Split(order_ids, ",")
- // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
- //
- // for _, item := range orders {
- // order_id, _ := strconv.ParseInt(item, 10, 64)
- // order, _ := service.GetHisOrderByID(order_id)
- // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
- // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
- // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
- // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
- // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
- //
- // }
- //
- // var bedCostTotal float64 = 0 //床位总费
- // var bedCostSelfTotal float64 = 0 //床位自费
- // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
- //
- // var operationCostTotal float64 = 0 //手术费
- // var operationCostSelfTotal float64 = 0 //手术费
- // var operationCostPartSelfTotal float64 = 0 //手术费
- //
- // var otherCostTotal float64 = 0 //其他费用
- // var otherCostSelfTotal float64 = 0 //其他费用
- // var otherCostPartSelfTotal float64 = 0 //其他费用
- //
- // var materialCostTotal float64 = 0 //材料费
- // var materialCostSelfTotal float64 = 0 //材料费
- // var materialCostPartSelfTotal float64 = 0 //材料费
- //
- // var westernMedicineCostTotal float64 = 0 //西药费
- // var westernMedicineCostSelfTotal float64 = 0 //西药费
- // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
- //
- // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
- //
- // var checkCostTotal float64 = 0 //检查费
- // var checkCostSelfTotal float64 = 0 //检查费
- // var checkCostPartSelfTotal float64 = 0 //检查费
- //
- // var laboratoryCostTotal float64 = 0 //化验费
- // var laboratoryCostSelfTotal float64 = 0 //化验费
- // var laboratoryCostPartSelfTotal float64 = 0 //化验费
- //
- // var treatCostTotal float64 = 0 //治疗费用
- // var treatCostSelfTotal float64 = 0 //治疗费用
- // var treatCostPartSelfTotal float64 = 0 //治疗费用
- //
- // var zhenChaCostTotal float64 = 0 //其他费用
- // var zhenChaCostSelfTotal float64 = 0 //其他费用
- // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
- //
- // decimal.DivisionPrecision = 2
- // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- //
- // var balanceAccountsType int64
- // if his.ID > 0 {
- // balanceAccountsType = his.BalanceAccountsType
- // } else {
- // balanceAccountsType = his_hospital_record.BalanceAccountsType
- // }
- // if balanceAccountsType == 2 {
- // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- // for _, item := range orderInfos_two {
- // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- // item.MedChrgitmType = "09"
- // }
- //
- // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- // if item.HisPrescriptionProject.Type == 2 {
- // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- // case 0:
- // item.MedChrgitmType = "0"
- // break
- // case 1:
- // item.MedChrgitmType = "14"
- // break
- // case 2:
- // item.MedChrgitmType = "05"
- //
- // break
- // case 3:
- // item.MedChrgitmType = "03"
- //
- // break
- // case 4:
- // item.MedChrgitmType = "03"
- //
- // break
- // case 5:
- // item.MedChrgitmType = "08"
- //
- // break
- // case 6:
- // item.MedChrgitmType = "14"
- //
- // break
- // case 7:
- // item.MedChrgitmType = "14"
- //
- // break
- // case 8:
- // item.MedChrgitmType = "03"
- // break
- // case 9:
- // item.MedChrgitmType = "14"
- // break
- // case 10:
- // item.MedChrgitmType = "14"
- // break
- // case 11:
- // item.MedChrgitmType = "06"
- // break
- // case 12:
- // item.MedChrgitmType = "12"
- // break
- // case 13:
- // item.MedChrgitmType = "01"
- // break
- // case 14:
- // item.MedChrgitmType = "04"
- // break
- // case 15:
- // item.MedChrgitmType = "02"
- // break
- //
- // }
- //
- // } else {
- // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- //
- // case 1:
- // item.MedChrgitmType = "14"
- // break
- // case 2:
- // item.MedChrgitmType = "05"
- //
- // break
- // case 3:
- // item.MedChrgitmType = "03"
- //
- // break
- // case 4:
- // item.MedChrgitmType = "03"
- //
- // break
- // case 5:
- // item.MedChrgitmType = "08"
- //
- // break
- // case 6:
- // item.MedChrgitmType = "14"
- //
- // break
- // case 7:
- // item.MedChrgitmType = "14"
- //
- // break
- // case 8:
- // item.MedChrgitmType = "03"
- // break
- // case 9:
- // item.MedChrgitmType = "14"
- // break
- //
- // }
- //
- // }
- //
- // } else if item.HisPrescriptionProject.Type == 3 {
- // item.MedChrgitmType = "08"
- // }
- // }
- // }
- //
- // for _, item := range orderInfos_two {
- // fmt.Println(item.MedChrgitmType)
- // if item.MedChrgitmType == "01" { //床位费
- // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // bedCostSelfTotal = bedCostTotal
- // }
- //
- // if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // zhenChaCostSelfTotal = zhenChaCostTotal
- // }
- //
- // if item.MedChrgitmType == "03" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // checkCostSelfTotal = checkCostTotal
- // }
- //
- // if item.MedChrgitmType == "04" { //化验费
- // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // laboratoryCostSelfTotal = laboratoryCostTotal
- // }
- //
- // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
- // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // treatCostSelfTotal = treatCostTotal
- // }
- //
- // if item.MedChrgitmType == "06" { //手术费
- // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // operationCostSelfTotal = treatCostTotal
- // }
- //
- // if item.MedChrgitmType == "08" { //材料费
- // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // materialCostSelfTotal = materialCostTotal
- // }
- //
- // if item.MedChrgitmType == "09" { //西药费
- // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // westernMedicineCostSelfTotal = westernMedicineCostTotal
- // }
- //
- // if item.MedChrgitmType == "11" { //中成费
- // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
- // }
- //
- // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
- // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // otherCostSelfTotal = otherCostTotal
- // }
- // } else {
- // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // otherCostSelfTotal = otherCostTotal
- // }
- //
- // }
- //
- // }
- //
- // } else {
- // for _, item := range orderInfos {
- // if item.MedChrgitmType == "01" { //床位费
- // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- // if item.MedChrgitmType == "03" { //检查费
- // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //
- // }
- // } else {
- // if item.MedChrgitmType == "03" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // }
- //
- // if item.MedChrgitmType == "04" { //化验费
- // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //
- // }
- //
- // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //
- // }
- //
- // if item.MedChrgitmType == "06" { //手术费
- // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
- // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if item.MedChrgitmType == "09" { //西药费
- // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if item.MedChrgitmType == "11" { //中成费
- // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- // }
- //
- // }
- // }
- // timeLayout := "2006-01-02"
- // loc, _ := time.LoadLocation("Local")
- // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
- // if err != nil {
- // }
- // startRecordDateTime := startTime.Unix()
- // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
- // if err != nil {
- // }
- // endRecordDateTime := endTime.Unix()
- // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
- // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
- // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "order_number": order.Number, //业务流水号
- // "id_card_no": his.IdCardNo, //社会保障号
- // "department_name": department.Name, //科室
- // "number": his.Number, //门诊号
- // "date": order.SettleAccountsDate, //结算日期
- // "name": order.PsnName, //姓名
- // "gender": patient.Gender, //性别
- // "psn_cash_money": order.PsnCashPay, //个人支付
- // "pay_way": "门诊", //结算方式
- // "medfee_sumamt": order.MedfeeSumamt, //总费用
- // "admin_user_name": admin.UserName, //收款员
- // "order": order,
- // "order_info": orderInfos_two,
- // "his": his,
- // "bedCostTotal": bedCostTotal,
- // "bedCostSelfTotal": bedCostSelfTotal,
- // "bedCostPartSelfTotal": bedCostPartSelfTotal,
- // "operationCostTotal": operationCostTotal,
- // "operationCostSelfTotal": operationCostSelfTotal,
- // "operationCostPartSelfTotal": operationCostPartSelfTotal,
- // "otherCostTotal": otherCostTotal,
- // "otherCostSelfTotal": otherCostSelfTotal,
- // "otherCostPartSelfTotal": otherCostPartSelfTotal,
- // "materialCostTotal": materialCostTotal,
- // "materialCostSelfTotal": materialCostSelfTotal,
- // "materialCostPartSelfTotal": materialCostPartSelfTotal,
- // "westernMedicineCostTotal": westernMedicineCostTotal,
- // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
- // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
- // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- // "checkCostTotal": checkCostTotal,
- // "checkCostSelfTotal": checkCostSelfTotal,
- // "checkCostPartSelfTotal": checkCostPartSelfTotal,
- // "laboratoryCostTotal": laboratoryCostTotal,
- // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
- // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- // "treatCostTotal": treatCostTotal,
- // "treatCostSelfTotal": treatCostSelfTotal,
- // "treatCostPartSelfTotal": treatCostPartSelfTotal,
- // "zhenChaCostTotal": zhenChaCostTotal,
- // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
- // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
- // "his_hospital_record": his_hospital_record,
- // "pre_pay_money": pre_pay_money,
- // "refund_sum": sum,
- // })
- //
- //}
-
- func (this *HisApiController) GetIncomeStatisticsData() {
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- key_words := this.GetString("key_words")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- statistics_type, _ := this.GetInt64("statistics_type")
- admin := this.GetAdminUserInfo()
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- if statistics_type == 1 {
- list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- } else {
- list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
-
- }
-
- }
-
- func (c *HisApiController) PostProjectInformation() {
- adminUser := c.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var projectList []*models.HisProject
- var total_goods []interface{}
- tempProjects := dataBody["projects"].([]interface{})
-
- total_goods = tempProjects
- for index, projectMap := range tempProjects {
-
- projectM := projectMap.(map[string]interface{})
-
- var project models.HisProject
- if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
- utils.ErrorLog("project_name")
- return
- }
-
- project_name, _ := projectM["project_name"].(string)
- if len(project_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- project.ProjectName = project_name
-
- prices := projectM["price"].(string)
-
- price, _ := strconv.ParseFloat(prices, 64)
- if price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- project.Price = price
-
- if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
- utils.ErrorLog("unit_id")
- return
- }
-
- unit := projectM["unit"].(string)
- if len(unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- project.Unit = unit
-
- cost_classify := projectM["cost_classify"].(string)
- if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- var costClassify = "费用类别"
- var cost_classify_id int64
-
- costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
-
- if len(cost_classify) != 0 {
- _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
- if errcode == gorm.ErrRecordNotFound {
- costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: costClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: cost_classify,
- FieldName: "",
- Value: costConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
-
- for _, it := range costClassList {
- if cost_classify == it.Name {
- cost_classify_id = int64(it.Value)
- }
- }
- project.CostClassify = cost_classify_id
-
- executive_section := projectM["executive_section"].(string)
- if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(executive_section) != 0 {
- //查找科室是否有内容
- _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
- if errcodedepart == gorm.ErrRecordNotFound {
- department := models.XtHisDepartment{
- Name: executive_section,
- Status: 1,
- UserOrgId: adminUser.CurrentOrgId,
- CreatedTime: time.Now().Unix(),
- }
- service.CreateDePartment(&department)
- }
- }
- var executive_section_id int64
- departMentList, _ := service.GetAllDepartMent(orgId)
- for _, it := range departMentList {
- if executive_section == it.Name {
- executive_section_id = it.ID
- }
- }
- project.ExecutiveSection = executive_section_id
-
- medical_coverage := projectM["medical_coverage"].(string)
-
- if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var medicalCoverage = "医保等级"
- var medical_coverage_id int64
-
- medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
- if len(medical_coverage) != 0 {
-
- _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
- if errormedicalcoverage == gorm.ErrRecordNotFound {
- medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: medicalCoverageConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_coverage,
- FieldName: "",
- Value: medicalCoverageConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
- medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
- for _, it := range medicalCoverageList {
- if medical_coverage == it.Name {
- medical_coverage_id = int64(it.Value)
- }
- }
- project.MedicalCoverage = medical_coverage_id
-
- pinyin := projectM["pinyin"].(string)
- project.Pinyin = pinyin
-
- wubi := projectM["wubi"].(string)
-
- project.Wubi = wubi
-
- statistical_classification := projectM["statistical_classification"].(string)
-
- var statisticalClassification = "统计分类"
- var statistical_classification_id int64
- classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
- if len(statistical_classification) != 0 {
-
- _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
-
- if classificationerrcodes == gorm.ErrRecordNotFound {
- classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: classiFication.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistical_classification,
- FieldName: "",
- Value: classiFicationConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
- classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
-
- for _, it := range classiFicationList {
- if statistical_classification == it.Name {
-
- statistical_classification_id = int64(it.Value)
- }
- }
-
- project.StatisticalClassification = statistical_classification_id
-
- disease_directory := int64(projectM["disease_directory"].(float64))
- project.DiseaseDirectory = disease_directory
-
- is_record := int64(projectM["is_record"].(float64))
- project.IsRecord = is_record
-
- medical_code := projectM["medical_code"].(string)
- project.MedicalCode = medical_code
-
- tube_color := projectM["tube_color"].(string)
-
- var tubeColor = "试管颜色"
- var tube_color_id int64
- tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
- if len(tube_color) != 0 {
- _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
- if errcodetube == gorm.ErrRecordNotFound {
- tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: tubeColorConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: tube_color,
- FieldName: "",
- Value: tubeConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
-
- tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
- for _, it := range tubeColorList {
- if tube_color == it.Name {
- tube_color_id = int64(it.Value)
- }
- }
-
- project.TubeColor = tube_color_id
-
- single_dose := projectM["single_dose"].(string)
- project.SingleDose = single_dose
- execution_frequency := projectM["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
-
- delivery_way := projectM["delivery_way"].(string)
- project.DeliveryWay = delivery_way
-
- number_days := projectM["number_days"].(string)
- project.NumberDays = number_days
-
- total := projectM["total"].(string)
- project.Total = total
-
- medical_status := int64(projectM["medical_status"].(float64))
- project.MedicalStatus = medical_status
-
- category := int64(projectM["category"].(float64))
- project.Category = category
-
- specail_project := int64(projectM["specail_project"].(float64))
- project.SpecailProject = specail_project
-
- social_security_directory_code := projectM["social_security_directory_code"].(string)
-
- project.SocialSecurityDirectoryCode = social_security_directory_code
-
- remark := projectM["remark"].(string)
- project.Remark = remark
-
- record_date := projectM["record_date"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- project.RecordDate = theTime.Unix()
- projectList = append(projectList, &project)
- }
-
- export_time := time.Now().Unix()
-
- errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
- if len(projectList) > 0 {
- for _, item := range projectList {
-
- hans := item.ProjectName // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 输出拼音
- fmt.Println("Pinyin:", pinyinSlice)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- item.FirstLetter = firstLetter
- project := models.HisProject{
- ProjectName: item.ProjectName,
- Price: item.Price,
- Unit: item.Unit,
- CostClassify: item.CostClassify,
- ExecutiveSection: item.ExecutiveSection,
- MedicalCoverage: item.MedicalCoverage,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- Pinyin: item.Pinyin,
- Wubi: item.Wubi,
- StatisticalClassification: item.StatisticalClassification,
- DiseaseDirectory: item.DiseaseDirectory,
- IsRecord: item.IsRecord,
- MedicalCode: item.MedicalCode,
- TubeColor: item.TubeColor,
- SingleDose: item.SingleDose,
- DeliveryWay: item.DeliveryWay,
- NumberDays: item.NumberDays,
- Total: item.Total,
- Category: item.Category,
- MedicalStatus: item.MedicalStatus,
- SpecailProject: item.SpecailProject,
- RecordDate: item.RecordDate,
- Remark: item.Remark,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- ExecutionFrequency: item.ExecutionFrequency,
- FirstLetter: item.FirstLetter,
- }
-
- _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
- if errcodeproject == gorm.ErrRecordNotFound {
- service.CreateProjectInfomation(&project)
- } else if errcodeproject == nil {
- service.UpdateProjectByName(&project, item.ProjectName, orgId)
- }
-
- log := models.ExportLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(projectList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(projectList),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(projectList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(projectList),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- //func (this *HisApiController) EditProjectInformation(){
- //
- // id, _ := this.GetInt64("id")
- // project_team := this.GetString("project_team")
- // price := this.GetString("price")
- // price_float, _ := strconv.ParseFloat(price, 64)
- // pinyin := this.GetString("pinyin")
- // wubi := this.GetString("wubi")
- // tube_color, _ := this.GetInt64("tube_color")
- // team_type, _ := this.GetInt64("team_type")
- // remark := this.GetString("remark")
- // ids := this.GetString("ids")
- // item_id := this.GetString("item_id")
- // projectTeam := models.XtHisProjectTeam{
- // ProjectTeam: project_team,
- // Price: price_float,
- // Pinyin: pinyin,
- // Wubi: wubi,
- // TubeColor: tube_color,
- // TeamType: team_type,
- // Remark: remark,
- // ProjectId: ids,
- // ItemId: item_id,
- // }
- //
- //
- // dataBody := make(map[string]interface{}, 0)
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // err = service.UpdatedProjectTeam(id, &projectTeam)
- //
- //
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- // return
- // }
- //
- // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
- // infos, _ := dataBody["info"].([]interface{})
- // if len(infos) > 0 {
- // var ids []string
- //
- // for _, item := range infos {
- // items := item.(map[string]interface{})
- // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- // utils.ErrorLog("id")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // id := int64(items["id"].(float64))
- //
- // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- // utils.ErrorLog("type")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // types := int64(items["type"].(float64))
- //
- // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- // utils.ErrorLog("number")
- // }
- //
- // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
- //
- // projectList := models.XtHisProjectList{
- // Number: number,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ProjectId: id,
- // Status: 1,
- // CreatedTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- // TeamId: projectTeam.ID,
- // Type: types,
- // }
- // list := projectList
- //
- // service.CreateProjectList(&list)
- //
- // ids = append(ids, strconv.FormatInt(list.ID, 10))
- //
- // }
- // ids_str := strings.Join(ids, ",")
- // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
- // service.SaveProjectTeam(&projectTeam)
- // this.ServeSuccessJSON(map[string]interface{}{
- // "projectTeam": projectTeam,
- // })
- // }
- // }
- //}
-
- func (c *HisApiController) CreateHisPrescriptionTemplate() {
- name := c.GetString("name")
- mode_id, _ := c.GetInt64("mode", 0)
- types, _ := c.GetInt64("type", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- types = 1
- adminInfo := c.GetAdminUserInfo()
- template := &models.HisPrescriptionTemplate{
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: patient_id,
- Type: types,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Name: name,
- Mode: mode_id,
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
-
- //如果已经存在记录则删除处方
- if template_one.ID > 0 {
- ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
- var ids []int64
- var org_id int64
- for _, item := range ps {
- org_id = c.GetAdminUserInfo().CurrentOrgId
- ids = append(ids, item.ID)
- }
- err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
-
- if err2 == nil {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoTemplate{
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: template_one.ID,
- MedType: med_type,
- }
- service.CreateHisPrescriptionInfoTemplate(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisPrescriptionAdviceTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- service.CreateHisPrescriptionAdviceTemplate(&s)
-
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisPrescriptionProjectTemplate(&p)
-
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
- }
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- } else {
- err3 := service.CreateHisPrescriptionTemplate(template)
- if err3 == nil {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoTemplate{
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: template.ID,
- MedType: med_type,
- }
- service.CreateHisPrescriptionInfoTemplate(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisPrescriptionAdviceTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- service.CreateHisPrescriptionAdviceTemplate(&s)
-
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisPrescriptionProjectTemplate(&p)
-
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
- }
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- func (c *HisApiController) PreSettle() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
- diagnosis_id := c.GetString("diagnosis")
- sick_type, _ := c.GetInt64("sick_type")
- reg_type, _ := c.GetInt64("p_type")
-
- his, _ := service.GetHisPatientByIdThree(his_patient_id)
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- var prescriptions []*models.HisPrescription
- var start_time int64
- var end_time int64
-
- ids_str := c.GetString("ids")
- ids_arr := strings.Split(ids_str, ",")
-
- fmt.Println(reg_type)
-
- if settle_accounts_type == 1 { //日结
-
- if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
-
- prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
- } else {
- prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
- }
-
- fmt.Println(prescriptions)
- } else { //月结
- start_time_str := c.GetString("start_time")
- end_time_str := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time = recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time = recordEndTime
- prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
- }
-
- if reg_type == 1111 || reg_type == 1112 {
- reg_type = 11
- }
-
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
- strconv.FormatInt(his.PatientId, 10)
-
- var ids []int64
-
- for _, item := range prescriptions {
- ids = append(ids, item.ID)
- }
-
- fmt.Println(ids)
-
- var total float64
- for _, item := range prescriptions {
- fmt.Println(item)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- total = total + (subItem.Price * subItem.PrescribingNumber)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- total = total + (subItem.Price * cnt)
- }
- }
-
- for _, subItem := range item.HisAdditionalCharge {
- total = total + (subItem.Price * float64(subItem.Count))
- }
- }
-
- allTotal := fmt.Sprintf("%.2f", total)
- totals, _ := strconv.ParseFloat(allTotal, 64)
- order := &models.HisOrder{
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- PatientId: id,
- SettleAccountsDate: recordDateTime,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- OrderStatus: 1,
- MdtrtId: his.Number,
- Number: chrg_bchno,
- MedfeeSumamt: totals,
- SettleEndTime: end_time,
- SettleStartTime: start_time,
- SettleType: settle_accounts_type,
- PsnPartAmt: totals,
- PsnCashPay: totals,
- PType: 2,
- IsPre: 1,
- MedType: strconv.Itoa(int(reg_type)),
- Diagnosis: diagnosis_id,
- }
- err = service.CreateOrder(order)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
-
- var customs []*Custom
- for _, item := range prescriptions {
- fmt.Println(item.Type)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- cus := &Custom{
- AdviceId: subItem.ID,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
- Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.2f", subItem.Price),
- MedListCodg: subItem.MedListCodg,
- Type: 1,
- }
- customs = append(customs, cus)
- }
- }
-
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &Custom{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.2f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
- MedListCodg: subItem.MedListCodg,
- Type: 2,
- }
-
- customs = append(customs, cus)
- }
- }
-
- for _, item := range item.HisAdditionalCharge {
- cus := &Custom{
- ItemId: item.ID,
- AdviceId: 0,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
- Cut: fmt.Sprintf("%.2f", float64(item.Count)),
- FeedetlSn: item.FeedetlSn,
- Price: fmt.Sprintf("%.2f", float64(item.Price)),
- MedListCodg: item.XtHisAddtionConfig.Code,
- Type: 3,
- }
-
- customs = append(customs, cus)
- }
-
- }
-
- fmt.Println(customs)
-
- for _, item := range customs {
- var advice_id int64 = 0
- var project_id int64 = 0
- var item_id int64 = 0
-
- var types int64 = 0
-
- if item.Type == 1 {
- advice_id = item.AdviceId
- project_id = 0
- item_id = 0
- } else if item.Type == 2 {
- advice_id = 0
- item_id = 0
-
- project_id = item.ProjectId
- } else if item.Type == 3 {
- advice_id = 0
- item_id = item.ItemId
- project_id = 0
- }
-
- detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
- cut, _ := strconv.ParseFloat(item.Cut, 32)
- pric, _ := strconv.ParseFloat(item.Price, 32)
-
- info := &models.HisOrderInfo{
- OrderNumber: order.Number,
- UploadDate: time.Now().Unix(),
- AdviceId: advice_id,
- DetItemFeeSumamt: detItemFeeSumamt,
- Cnt: cut,
- Pric: pric,
- PatientId: id,
- Status: 1,
- Mtime: time.Now().Unix(),
- Ctime: time.Now().Unix(),
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- OrderId: order.ID,
- ProjectId: project_id,
- Type: types,
- ItemId: item_id,
- }
- service.CreateOrderInfo(info)
- }
- his.SickType = sick_type
- service.UpdataHisPateint(&his)
- err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
- err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
- //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "结算成功",
- })
- }
- }
-
- type CustomOrderInfo struct {
- Name string
- Spec string
- Unit string
- Count float64
- Price float64
- Total float64
- }
-
- func (c *HisApiController) GetPrivateExpensesInfo() {
- order_id, _ := c.GetInt64("id", 0)
- his_patient_id, _ := c.GetInt64("his_patient_id", 0)
- order, _ := service.GetHisOrderByID(order_id)
- role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
- miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
- his, _ := service.GetHisPatientByIdThree(his_patient_id)
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
-
- orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
- orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
- //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
-
- //var orderInfos_four []*models.HisOrderInfoTwo
- //for _, item := range orderInfos_three {
- // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
- // item.HisPrescriptionProject.IsCheckTeam = 1
- // orderInfos_four = append(orderInfos_four, item)
- //
- // }
- // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
- // item.HisPrescriptionProject.IsCheckTeam = 2
- // orderInfos_two = append(orderInfos_two, item)
- // }
- //}
-
- //new_order_info := RemoveRepeatedTeam(orderInfos_four)
- //var cus_slice []CustomOrderInfo
- //for _, item := range new_order_info {
- // var cus CustomOrderInfo
- // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
- // cus.Unit = ""
- // cus.Spec = ""
- // var total float64
- // for _, subItem := range orderInfos_four {
- // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
- // total = total + subItem.DetItemFeeSumamt
- // fmt.Println(subItem.DetItemFeeSumamt)
- // }
- // }
- // cus.Count = 1
- // cus.Total = total
- // cus_slice = append(cus_slice, cus)
- //}
-
- orderInfos = append(orderInfos, orderInfos_two...)
- //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
- //orderInfos = append(orderInfos, orderInfos_three...)
-
- //}/**/
-
- patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": orderInfos,
- "patient": patient,
- "admin_info": adminInfo,
- "his": his,
- "current_admin": role,
- "org_config": miConfig,
- //"new_order_info": cus_slice,
- })
-
- }
-
- func (this *HisApiController) ChangeMedType() {
- med_type := this.GetString("med_type")
- old_med_type := this.GetString("old_med_type")
- ids := this.GetString("ids")
- settle_type, _ := this.GetInt64("settle_type")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- ids_arr := strings.Split(ids, ",")
- if settle_type == 1 { //日结
- id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
- prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
- prescription.MedType = med_type
- err := service.SaveHisPrescriptionTwo(&prescription)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- })
-
- } else {
-
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- } else if settle_type == 2 {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time_timestamp := recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time_timestamp := recordEndTime
- updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
- if updateErr == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- func (c *HisApiController) GetHisMonthChargePatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- order_status, _ := c.GetInt64("type", 0)
- p_type, _ := c.GetInt64("p_type", 0)
- order_id, _ := c.GetInt64("order_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- order, _ := service.GetHisOrderByID(order_id)
-
- var monthPrescriptions []*models.HisPrescription
- if order_status == 1 || order_status == 0 {
- monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- } else if order_status == 2 {
- monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
- }
-
- var settle_total float64
- for _, item := range monthPrescriptions {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
-
- month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
-
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
-
- var dia string
- for _, item := range month_p_info {
- if len(dia) == 0 {
- dia = item.Diagnosis
- } else {
- dia = dia + "," + item.Diagnosis
- }
- }
-
- dia_arr := removeDuplicates(strings.Split(dia, ","))
- dia_arr = removeEmptyStrings(dia_arr)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "last_info": lastPatientPrescriptionInfo,
- "month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "settle_total": settle_total,
- "dia_arr": dia_arr,
- })
- return
- }
-
- func removeEmptyStrings(input []string) []string {
- var output []string
-
- for _, s := range input {
- if s != "" {
- output = append(output, s)
- }
- }
-
- return output
- }
-
- func removeDuplicates(input []string) []string {
- seen := make(map[string]bool)
- output := []string{}
-
- for _, s := range input {
- if _, exists := seen[s]; !exists {
- seen[s] = true
- output = append(output, s)
- }
- }
-
- return output
- }
-
- func (c *HisApiController) GetHisMonthPatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- number := c.GetString("number")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- p_type, _ := c.GetInt64("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
-
- monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- var settle_total float64
- for _, item := range monthPrescriptions {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
-
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "count": count,
- "drugStockConfig": drugStockConfig,
- "last_info": lastPatientPrescriptionInfo,
- "settle_total": settle_total,
- })
- return
-
- }
-
- func (c *HisApiController) GetAllOrder() {
- org_id := c.GetAdminUserInfo().CurrentOrgId
- orders, _ := service.GetNewHisOrderList(org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": orders,
- })
- return
-
- }
-
- func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
- newArr = make([]*models.HisOrderInfoTwo, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- // 修改处方退库操作 参数传修改之前的处方数据
- func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
-
- if advice.ExecutionState == 1 {
- //查询该病人该药品是否有库存记录
- info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
- if errcode == gorm.ErrRecordNotFound {
-
- } else {
- //退库
- drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
- if advice.PrescribingNumberUnit == drug.MinUnit {
-
- floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
-
- //退库
- warehouseInfo := models.DrugWarehouseInfo{
- StockMinNumber: prescribingNumber,
- }
-
- service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
-
- operation_time := time.Now().Unix()
- creater := advice.AdviceDoctor
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- }
- service.AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := service.GetManufactureById(info.Manufacturer)
- dealer, _ := service.GetDealerById(info.Dealer)
- cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: info.Count,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: info.CountUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- }
-
- flow := models.DrugFlow{
- WarehousingId: 0,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: info.Count,
- UserOrgId: advice.UserOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: advice.UserOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: info.CountUnit,
- MinUnit: "",
- }
- service.CreatedCancelStock(cancelStockInfo)
- service.CreateDrugFlowOne(flow)
- } else {
-
- floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
-
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
-
- if advice.PrescribingNumberUnit == drug.MaxUnit {
- warehouseInfo := models.DrugWarehouseInfo{
- StockMinNumber: prescribingNumber,
- }
- service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
-
- }
-
- operation_time := time.Now().Unix()
- creater := advice.AdviceDoctor
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- }
- service.AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := service.GetManufactureById(info.Manufacturer)
- dealer, _ := service.GetDealerById(info.Dealer)
- cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: info.Count,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: info.CountUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- }
-
- flow := models.DrugFlow{
- WarehousingId: 0,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: info.Count,
- UserOrgId: advice.UserOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: advice.AdviceDoctor,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: info.CountUnit,
- MinUnit: "",
- }
- service.CreatedCancelStock(cancelStockInfo)
- service.CreateDrugFlowOne(flow)
- }
- }
- }
- return err
- }
-
- func (this *HisApiController) DeleteNCDS() {
- id, _ := this.GetInt64("id", 0)
- if id > 0 {
- service.DeletePsnNCDSRecordById(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
- return
- }
-
- }
-
- func (c *HisApiController) GetHisDoctorAdviceInfo() {
-
- id, _ := c.GetInt64("id")
- advice, _ := service.GetHisDoctorAdviceInfo(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- return
- }
-
- func (c *HisApiController) GetHisMonthChargePatientList() {
- record_date := c.GetString("record_date")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempMonthChargePatients []*service.MonthChargePatients
- tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
- for _, item := range tempPatients {
- //过滤没有处方的
- if len(item.HisPrescription) == 0 {
- tempMonthChargePatients = append(tempMonthChargePatients, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": tempMonthChargePatients,
- })
-
- }
-
- // PrescriptionDifference 医嘱数量差值结构体
- type PrescriptionDrugDifference struct {
- DrugID int64 //基础库药品id
- ID int64 //医嘱id
- Difference float64 //差值
- Unit string //单位
- }
-
- type PrescriptionGoodDifference struct {
- GoodID int64 //基础库项目耗材id
- ID int64 //医嘱id
- Difference int64 //差值
- Unit string //单位
- Type int64 //类型
- }
-
- type EditCustomData struct {
- adviceList []*models.HisDoctorAdviceInfo
- projectList []*models.HisPrescriptionProject
- }
-
- type SrcCustomData struct {
- adviceList []*models.HisDoctorAdviceInfo
- projectList []*models.HisPrescriptionProject
- }
-
- // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
- func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
- differences := make([]*PrescriptionDrugDifference, 0)
- // 创建一个 map 来存储第一个切片中的药品信息
- firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
- for _, advice := range firstPrescription {
- firstMap[advice.DrugId] = advice
- }
-
- // 遍历第二个切片中的药品信息,并比较数量差值
- for _, advice := range secondPrescription {
- if firstAdvice, ok := firstMap[advice.DrugId]; ok {
- diff := &PrescriptionDrugDifference{
- DrugID: advice.DrugId,
- ID: firstAdvice.ID,
- Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
- Unit: firstAdvice.PrescribingNumberUnit,
- }
- differences = append(differences, diff)
- }
- }
-
- return differences
- }
-
- // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
- func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
- differences := make([]*PrescriptionGoodDifference, 0)
- // 创建一个 map 来存储第一个切片中的耗材信息
- firstMap := make(map[int64]*models.HisPrescriptionProject)
- for _, good := range firstPrescription {
- firstMap[good.ProjectId] = good
- }
-
- // 遍历第二个切片中的耗材信息,并比较数量差值
- for _, good := range secondPrescription {
- if firstGood, ok := firstMap[good.ProjectId]; ok {
-
- count, _ := strconv.ParseInt(good.Count, 10, 64)
- firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
- diff := &PrescriptionGoodDifference{
- GoodID: good.ProjectId,
- ID: firstGood.ID,
- Difference: count - firstCount,
- Unit: firstGood.Unit,
- Type: firstGood.Type,
- }
- differences = append(differences, diff)
- }
- }
-
- return differences
- }
- func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
- var adviceList []*models.HisDoctorAdviceInfo
- var projectList []*models.HisPrescriptionProject
-
- var advice_ids []int64
- var project_ids []int64
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- //var tempPrescription *models.HisPrescriptionProjectscription
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisDoctorAdviceInfo
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.IsSettle = 2
- SetAdviceWithJSON(&s, advice.(map[string]interface{}))
- //存储切片中
- if s.ID > 0 {
- advice_ids = append(advice_ids, s.ID)
- adviceList = append(adviceList, &s)
- }
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProject
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.Status = 1
- SetProjectWithJSON(&p, project.(map[string]interface{}))
- if p.ID > 0 {
- project_ids = append(project_ids, p.ID)
- projectList = append(projectList, &p)
- }
- }
- }
- }
- }
-
- }
- }
- editCustomData.projectList = projectList
- editCustomData.adviceList = adviceList
-
- list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
- list2, _ := service.GetBatchHisProjectByIDs(project_ids)
-
- srcCustomData.adviceList = list
- srcCustomData.projectList = list2
-
- return
- }
|