his_api_controller.go 583KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "band_card_pay":
  229. order.BandCardPay = desc
  230. break
  231. case "ali_pay":
  232. order.AliPay = desc
  233. break
  234. case "wechat_pay":
  235. order.WechatPay = desc
  236. break
  237. case "fa_piao_number":
  238. order.FaPiaoNumber = desc
  239. break
  240. case "fa_piao_code":
  241. order.FaPiaoCode = desc
  242. break
  243. }
  244. err := service.SaveHisOrder(&order)
  245. if err == nil {
  246. c.ServeSuccessJSON(map[string]interface{}{
  247. "msg": "修改成功",
  248. })
  249. return
  250. } else {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. return
  253. }
  254. }
  255. func (c *HisApiController) GetMonthHisPatient() {
  256. record_date := c.GetString("record_date")
  257. //order_status, _ := c.GetInt64("type")
  258. timeLayout := "2006-01-02"
  259. loc, _ := time.LoadLocation("Local")
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  261. if err != nil {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. return
  264. }
  265. recordDateTime := theTime.Unix()
  266. adminInfo := c.GetAdminUserInfo()
  267. var tempPatients []service.NewTempPatients
  268. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  269. // 获取当前时间
  270. now := time.Now()
  271. // 获取本月的第一天
  272. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  273. // 获取下个月的第一天
  274. nextMonth := firstDay.AddDate(0, 1, 0)
  275. // 获取本月的最后一天
  276. lastDay := nextMonth.Add(-time.Nanosecond)
  277. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  278. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  279. var patients []service.NewTempPatients
  280. var patients_two []service.NewTempPatients
  281. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  282. for _, item := range tempPatients {
  283. //过滤掉没挂号的和没开处方的
  284. if len(item.HisPrescription) > 0 {
  285. patients = append(patients, item)
  286. patients_two = append(patients_two, item)
  287. }
  288. ////过滤掉没挂号的
  289. //if len(item.HisPatient) > 0 {
  290. //}
  291. }
  292. } else {
  293. for _, item := range tempPatients {
  294. //过滤掉没挂号的和没开处方的
  295. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  296. patients = append(patients, item)
  297. }
  298. ////过滤掉没挂号的
  299. //if len(item.HisPatient) > 0 {
  300. // patients_two = append(patients_two, item)
  301. //}
  302. }
  303. }
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "list": patients,
  306. "list_two": patients_two,
  307. "chargePatients": chargePatients,
  308. })
  309. }
  310. func (c *HisApiController) GetBatchSettleAccounts() {
  311. order_ids := c.GetString("order_ids")
  312. admin_user_id, _ := c.GetInt64("admin_user_id")
  313. adminUser := c.GetAdminUserInfo()
  314. orders := strings.Split(order_ids, ",")
  315. var newOrders []models.Orders
  316. for _, item := range orders {
  317. order, _ := service.GetHisOrderByIDTenOne(item)
  318. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  319. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  320. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  321. orderInfos = append(orderInfos, orderInfos_two...)
  322. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  323. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  324. var diagnosis_ids []string
  325. if his.ID > 0 {
  326. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  327. } else {
  328. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  329. }
  330. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  331. var dia_config []*models.HisXtDiagnoseConfig
  332. var name string
  333. for _, item := range diagnosis_ids {
  334. id, _ := strconv.ParseInt(item, 10, 64)
  335. diagnosisConfig, _ := service.FindDiagnoseById(id)
  336. dia_config = append(dia_config, diagnosisConfig)
  337. if len(name) == 0 {
  338. name = diagnosisConfig.ClassName
  339. } else {
  340. name = name + "," + diagnosisConfig.ClassName
  341. }
  342. }
  343. var bedCostTotal float64 = 0 //床位总费
  344. var bedCostSelfTotal float64 = 0 //床位自费
  345. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  346. var bedSelfTotal float64 = 0 //床位部分项目自费
  347. var bedInscpTotal float64 = 0 //床位部分项目自费
  348. var operationCostTotal float64 = 0 //手术费
  349. var operationCostSelfTotal float64 = 0 //手术费
  350. var operationCostPartSelfTotal float64 = 0 //手术费
  351. var operationSelfTotal float64 = 0 //床位部分项目自费
  352. var operationInscpTotal float64 = 0 //床位部分项目自费
  353. var otherCostTotal float64 = 0 //其他费用
  354. var otherCostSelfTotal float64 = 0 //其他费用
  355. var otherCostPartSelfTotal float64 = 0 //其他费用
  356. var otherSelfTotal float64 = 0 //床位部分项目自费
  357. var otherInscpTotal float64 = 0 //床位部分项目自费
  358. var materialCostTotal float64 = 0 //材料费
  359. var materialCostSelfTotal float64 = 0 //材料费
  360. var materialCostPartSelfTotal float64 = 0 //材料费
  361. var materialSelfTotal float64 = 0 //床位部分项目自费
  362. var materialInscpTotal float64 = 0 //床位部分项目自费
  363. var westernMedicineCostTotal float64 = 0 //西药费
  364. var westernMedicineCostSelfTotal float64 = 0 //西药费
  365. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  366. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  367. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  368. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  369. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  370. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  371. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  372. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  373. var checkCostTotal float64 = 0 //检查费
  374. var checkCostSelfTotal float64 = 0 //检查费
  375. var checkCostPartSelfTotal float64 = 0 //检查费
  376. var checkSelfTotal float64 = 0 //床位部分项目自费
  377. var checkInscpTotal float64 = 0 //床位部分项目自费
  378. var laboratoryCostTotal float64 = 0 //化验费
  379. var laboratoryCostSelfTotal float64 = 0 //化验费
  380. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  381. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  382. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  383. var treatCostTotal float64 = 0 //治疗费用
  384. var treatCostSelfTotal float64 = 0 //治疗费用
  385. var treatCostPartSelfTotal float64 = 0 //治疗费用
  386. var treatSelfTotal float64 = 0 //床位部分项目自费
  387. var treatInscpTotal float64 = 0 //床位部分项目自费
  388. decimal.DivisionPrecision = 2
  389. for _, item := range orderInfos {
  390. if item.MedChrgitmType == "01" { //床位费
  391. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  398. if item.MedChrgitmType == "03" { //检查费
  399. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. } else {
  406. if item.MedChrgitmType == "03" { //检查费
  407. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. }
  414. if item.MedChrgitmType == "04" { //化验费
  415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "05" { //治疗费
  422. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "06" { //手术费
  429. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "09" { //西药费
  443. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "11" { //中成费
  450. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  457. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  458. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  459. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  460. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  461. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  462. }
  463. }
  464. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  465. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  466. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  467. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  468. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. var doctor_name string
  470. if roles.ID == 0 {
  471. doctor_name = "管理员"
  472. } else {
  473. doctor_name = roles.UserName
  474. }
  475. yiliao_leibie := ""
  476. switch order.MedType {
  477. case "11":
  478. yiliao_leibie = "普通门诊"
  479. break
  480. case "12":
  481. yiliao_leibie = "门诊挂号"
  482. break
  483. case "13":
  484. yiliao_leibie = "急诊"
  485. break
  486. case "14":
  487. yiliao_leibie = "门诊特殊病"
  488. break
  489. case "15":
  490. yiliao_leibie = "门诊统筹"
  491. break
  492. case "16":
  493. yiliao_leibie = "门诊慢性病"
  494. break
  495. case "21":
  496. yiliao_leibie = "普通住院"
  497. break
  498. }
  499. var newOrder models.Orders
  500. newOrder.Diagnosis = name
  501. newOrder.OrderInfos = orderInfos
  502. newOrder.Number = order.MdtrtId
  503. newOrder.Date = order.SettleAccountsDate
  504. newOrder.ChargeAdmin = charge_admin
  505. newOrder.PrintorAdmin = printor_admin
  506. newOrder.Order = order
  507. newOrder.BedCostTotal = bedCostTotal
  508. newOrder.BedCostSelfTotal = bedCostSelfTotal
  509. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  510. newOrder.BedSelfTotal = bedSelfTotal
  511. newOrder.BedInscpTotal = bedInscpTotal
  512. newOrder.OperationCostTotal = operationCostTotal
  513. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  514. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  515. newOrder.OperationSelfTotal = operationSelfTotal
  516. newOrder.OperationInscpTotal = operationInscpTotal
  517. newOrder.OtherCostTotal = otherCostTotal
  518. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  519. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  520. newOrder.OtherSelfTotal = otherSelfTotal
  521. newOrder.OtherInscpTotal = otherInscpTotal
  522. newOrder.MaterialCostTotal = materialCostTotal
  523. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  524. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  525. newOrder.MaterialSelfTotal = materialSelfTotal
  526. newOrder.MaterialInscpTotal = materialInscpTotal
  527. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  528. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  529. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  530. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  531. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  532. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  533. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  534. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  535. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  536. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  537. newOrder.CheckCostTotal = checkCostTotal
  538. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  539. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  540. newOrder.CheckSelfTotal = checkSelfTotal
  541. newOrder.CheckInscpTotal = checkInscpTotal
  542. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  543. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  544. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  545. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  546. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  547. newOrder.TreatCostTotal = treatCostTotal
  548. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  549. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  550. newOrder.TreatSelfTotal = treatSelfTotal
  551. newOrder.TreatInscpTotal = treatInscpTotal
  552. newOrder.DoctorInfo = doctor_info
  553. newOrder.DoctorName = doctor_name
  554. newOrder.HealthCardNo = order.PsnNo
  555. newOrder.YiliaoLeibie = yiliao_leibie
  556. newOrder.Patient = patient
  557. newOrder.OrgName = miConfig.OrgName
  558. newOrder.OrgCode = miConfig.Code
  559. newOrder.OrderNumber = order.Number
  560. newOrder.HisPatient = his
  561. newOrder.DiaConfig = dia_config
  562. newOrders = append(newOrders, newOrder)
  563. }
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "orders": newOrders,
  566. })
  567. }
  568. func (c *HisApiController) GetTestOrder() {
  569. order_id, _ := c.GetInt64("order_id")
  570. admin_user_id, _ := c.GetInt64("admin_user_id")
  571. adminUser := c.GetAdminUserInfo()
  572. order, _ := service.GetHisOrderByID(order_id)
  573. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  574. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  575. orderInfos = append(orderInfos, orderInfos_two...)
  576. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  577. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  578. var dia_config []*models.HisXtDiagnoseConfig
  579. var name string
  580. var bedCostTotal float64 = 0 //床位总费
  581. var bedCostSelfTotal float64 = 0 //床位自费
  582. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  583. var bedSelfTotal float64 = 0 //床位部分项目自费
  584. var bedInscpTotal float64 = 0 //床位部分项目自费
  585. var operationCostTotal float64 = 0 //手术费
  586. var operationCostSelfTotal float64 = 0 //手术费
  587. var operationCostPartSelfTotal float64 = 0 //手术费
  588. var operationSelfTotal float64 = 0 //床位部分项目自费
  589. var operationInscpTotal float64 = 0 //床位部分项目自费
  590. var otherCostTotal float64 = 0 //其他费用
  591. var otherCostSelfTotal float64 = 0 //其他费用
  592. var otherCostPartSelfTotal float64 = 0 //其他费用
  593. var otherSelfTotal float64 = 0 //床位部分项目自费
  594. var otherInscpTotal float64 = 0 //床位部分项目自费
  595. var materialCostTotal float64 = 0 //材料费
  596. var materialCostSelfTotal float64 = 0 //材料费
  597. var materialCostPartSelfTotal float64 = 0 //材料费
  598. var materialSelfTotal float64 = 0 //床位部分项目自费
  599. var materialInscpTotal float64 = 0 //床位部分项目自费
  600. var westernMedicineCostTotal float64 = 0 //西药费
  601. var westernMedicineCostSelfTotal float64 = 0 //西药费
  602. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  603. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  604. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  605. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  606. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  607. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  608. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  609. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  610. var checkCostTotal float64 = 0 //检查费
  611. var checkCostSelfTotal float64 = 0 //检查费
  612. var checkCostPartSelfTotal float64 = 0 //检查费
  613. var checkSelfTotal float64 = 0 //床位部分项目自费
  614. var checkInscpTotal float64 = 0 //床位部分项目自费
  615. var laboratoryCostTotal float64 = 0 //化验费
  616. var laboratoryCostSelfTotal float64 = 0 //化验费
  617. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  618. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  619. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  620. var treatCostTotal float64 = 0 //治疗费用
  621. var treatCostSelfTotal float64 = 0 //治疗费用
  622. var treatCostPartSelfTotal float64 = 0 //治疗费用
  623. var treatSelfTotal float64 = 0 //床位部分项目自费
  624. var treatInscpTotal float64 = 0 //床位部分项目自费
  625. decimal.DivisionPrecision = 2
  626. for _, item := range orderInfos {
  627. if item.MedChrgitmType == "01" { //床位费
  628. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  635. if item.MedChrgitmType == "03" { //检查费
  636. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. } else {
  643. if item.MedChrgitmType == "03" { //检查费
  644. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. }
  651. if item.MedChrgitmType == "04" { //化验费
  652. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "05" { //治疗费
  659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "06" { //手术费
  666. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  673. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "09" { //西药费
  680. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "11" { //中成费
  687. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  695. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  696. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  697. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  698. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  699. }
  700. }
  701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  702. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  703. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  704. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  705. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. var doctor_name string
  707. if roles.ID == 0 {
  708. doctor_name = "管理员"
  709. } else {
  710. doctor_name = roles.UserName
  711. }
  712. yiliao_leibie := ""
  713. switch order.MedType {
  714. case "11":
  715. yiliao_leibie = "普通门诊"
  716. break
  717. case "12":
  718. yiliao_leibie = "门诊挂号"
  719. break
  720. case "13":
  721. yiliao_leibie = "急诊"
  722. break
  723. case "14":
  724. yiliao_leibie = "门诊特殊病"
  725. break
  726. case "15":
  727. yiliao_leibie = "门诊统筹"
  728. break
  729. case "16":
  730. yiliao_leibie = "门诊慢性病"
  731. break
  732. case "21":
  733. yiliao_leibie = "普通住院"
  734. break
  735. }
  736. c.ServeSuccessJSON(map[string]interface{}{
  737. "diagnosis": name,
  738. "order_infos": orderInfos,
  739. "number": order.MdtrtId,
  740. "date": order.SettleAccountsDate,
  741. "charge_admin": charge_admin,
  742. "printor_admin": printor_admin,
  743. "info": order,
  744. "order": order,
  745. "bedCostTotal": bedCostTotal,
  746. "bedCostSelfTotal": bedCostSelfTotal,
  747. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  748. "bedSelfTotal": bedSelfTotal,
  749. "bedInscpTotal": bedInscpTotal,
  750. "operationCostTotal": operationCostTotal,
  751. "operationCostSelfTotal": operationCostSelfTotal,
  752. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  753. "operationSelfTotal": operationSelfTotal,
  754. "operationInscpTotal": operationInscpTotal,
  755. "otherCostTotal": otherCostTotal,
  756. "otherCostSelfTotal": otherCostSelfTotal,
  757. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  758. "otherSelfTotal": otherSelfTotal,
  759. "otherInscpTotal": otherInscpTotal,
  760. "materialCostTotal": materialCostTotal,
  761. "materialCostSelfTotal": materialCostSelfTotal,
  762. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  763. "materialSelfTotal": materialSelfTotal,
  764. "materialInscpTotal": materialInscpTotal,
  765. "westernMedicineCostTotal": westernMedicineCostTotal,
  766. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  767. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  768. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  769. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  770. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  771. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  772. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  773. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  774. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  775. "checkCostTotal": checkCostTotal,
  776. "checkCostSelfTotal": checkCostSelfTotal,
  777. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  778. "checkSelfTotal": checkSelfTotal,
  779. "checkInscpTotal": checkInscpTotal,
  780. "laboratoryCostTotal": laboratoryCostTotal,
  781. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  782. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  783. "laboratorySelfTotal": laboratorySelfTotal,
  784. "laboratoryInscpTotal": laboratoryInscpTotal,
  785. "treatCostTotal": treatCostTotal,
  786. "treatCostSelfTotal": treatCostSelfTotal,
  787. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  788. "treatSelfTotal": treatSelfTotal,
  789. "treatInscpTotal": treatInscpTotal,
  790. "doctor_info": doctor_info,
  791. "doctor_name": doctor_name,
  792. "health_card_no": order.PsnNo,
  793. "yiliao_leibie": yiliao_leibie,
  794. "patient": patient,
  795. "org_name": miConfig.OrgName,
  796. "org_code": miConfig.Code,
  797. "order_number": order.Number,
  798. "his_hospital": his_hospital,
  799. "dia_config": dia_config,
  800. })
  801. }
  802. type CustomFundPay struct {
  803. FundPayType string `json:"fund_pay_type"`
  804. FundPayamt float64 `json:"fund_payamt"`
  805. InscpScpAmt float64 `json:"inscp_scp_amt"`
  806. }
  807. func (c *PublicApiController) GetBaiLinExportData() {
  808. data := service.GetBaiLinOrderData()
  809. fmt.Println(len(data))
  810. var new_data []*models.NewCustomHisOrder
  811. for _, item := range data {
  812. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  813. new_data = append(new_data, item)
  814. }
  815. }
  816. fmt.Println(len(new_data))
  817. c.ServeSuccessJSON(map[string]interface{}{
  818. "list": new_data,
  819. })
  820. }
  821. func (c *HisApiController) GetHisUnChargePatientList() {
  822. record_date := c.GetString("record_date")
  823. sch_type, _ := c.GetInt64("sch_type")
  824. timeLayout := "2006-01-02"
  825. loc, _ := time.LoadLocation("Local")
  826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  827. if err != nil {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. recordDateTime := theTime.Unix()
  832. adminInfo := c.GetAdminUserInfo()
  833. var tempPatients []*service.NewTempPatients
  834. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  835. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  836. var patients []*service.NewTempPatients
  837. var patients_two []*service.NewTempPatients
  838. for _, item := range tempPatients {
  839. //过滤掉没挂号的和没开处方的
  840. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  841. patients = append(patients, item)
  842. }
  843. //过滤掉没挂号的
  844. if len(item.HisPatient) > 0 {
  845. patients_two = append(patients_two, item)
  846. }
  847. }
  848. c.ServeSuccessJSON(map[string]interface{}{
  849. "list": patients,
  850. "list_two": patients_two,
  851. })
  852. }
  853. func (c *HisApiController) GetPrivateExpensesOrder() {
  854. //id, _ := c.GetInt64("id")
  855. //record_time := c.GetString("record_time")
  856. order_id, _ := c.GetInt64("order_id")
  857. admin_user_id, _ := c.GetInt64("admin_user_id")
  858. //timeLayout := "2006-01-02"
  859. //loc, _ := time.LoadLocation("Local")
  860. //
  861. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  862. //if err != nil {
  863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. // return
  865. //}
  866. //recordDateTime := theTime.Unix()
  867. adminUser := c.GetAdminUserInfo()
  868. order, _ := service.GetHisOrderByID(order_id)
  869. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  870. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  871. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  872. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  873. //var config []*models.HisXtDiagnoseConfig
  874. var name string
  875. if order.PType == 1 {
  876. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  877. for _, item := range diagnosis_ids {
  878. id, _ := strconv.ParseInt(item, 10, 64)
  879. diagnosisConfig, _ := service.FindDiagnoseById(id)
  880. if len(name) == 0 {
  881. name = diagnosisConfig.ClassName
  882. } else {
  883. name = name + "," + diagnosisConfig.ClassName
  884. }
  885. }
  886. } else {
  887. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  888. for _, item := range diagnosis_ids {
  889. id, _ := strconv.ParseInt(item, 10, 64)
  890. diagnosisConfig, _ := service.FindDiagnoseById(id)
  891. if len(name) == 0 {
  892. name = diagnosisConfig.ClassName
  893. } else {
  894. name = name + "," + diagnosisConfig.ClassName
  895. }
  896. }
  897. }
  898. var bedCostTotal float64 = 0 //床位总费
  899. //var bedCostSelfTotal float64 = 0 //床位自费
  900. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  901. var operationCostTotal float64 = 0 //手术费
  902. //var operationCostSelfTotal float64 = 0 //手术费
  903. var operationCostPartSelfTotal float64 = 0 //手术费
  904. var otherCostTotal float64 = 0 //其他费用
  905. //var otherCostSelfTotal float64 = 0 //其他费用
  906. var otherCostPartSelfTotal float64 = 0 //其他费用
  907. var materialCostTotal float64 = 0 //材料费
  908. //var materialCostSelfTotal float64 = 0 //材料费
  909. var materialCostPartSelfTotal float64 = 0 //材料费
  910. var westernMedicineCostTotal float64 = 0 //西药费
  911. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  912. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  913. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  914. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  915. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  916. var checkCostTotal float64 = 0 //检查费
  917. //var checkCostSelfTotal float64 = 0 //检查费
  918. var checkCostPartSelfTotal float64 = 0 //检查费
  919. var laboratoryCostTotal float64 = 0 //化验费
  920. //var laboratoryCostSelfTotal float64 = 0 //化验费
  921. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  922. var treatCostTotal float64 = 0 //治疗费用
  923. //var treatCostSelfTotal float64 = 0 //治疗费用
  924. var treatCostPartSelfTotal float64 = 0 //治疗费用
  925. var zhenChaCostTotal float64 = 0 //其他费用
  926. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  927. decimal.DivisionPrecision = 2
  928. for _, item := range orderInfos {
  929. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  930. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  931. item.MedChrgitmType = "09"
  932. }
  933. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  934. if item.HisPrescriptionProject.Type == 2 {
  935. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  936. fmt.Println("CostClassify")
  937. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  938. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  939. case 0:
  940. item.MedChrgitmType = "0"
  941. break
  942. case 1:
  943. item.MedChrgitmType = "14"
  944. break
  945. case 2:
  946. item.MedChrgitmType = "05"
  947. break
  948. case 3:
  949. item.MedChrgitmType = "03"
  950. break
  951. case 4:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 5:
  955. item.MedChrgitmType = "08"
  956. break
  957. case 6:
  958. item.MedChrgitmType = "14"
  959. break
  960. case 7:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 8:
  964. item.MedChrgitmType = "03"
  965. break
  966. case 9:
  967. item.MedChrgitmType = "14"
  968. break
  969. case 10:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 11:
  973. item.MedChrgitmType = "06"
  974. break
  975. case 12:
  976. item.MedChrgitmType = "12"
  977. break
  978. case 13:
  979. item.MedChrgitmType = "01"
  980. break
  981. case 14:
  982. item.MedChrgitmType = "04"
  983. break
  984. case 15:
  985. item.MedChrgitmType = "14"
  986. break
  987. }
  988. } else {
  989. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  990. case 1:
  991. item.MedChrgitmType = "14"
  992. break
  993. case 2:
  994. item.MedChrgitmType = "05"
  995. break
  996. case 3:
  997. item.MedChrgitmType = "04"
  998. break
  999. case 4:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 5:
  1003. item.MedChrgitmType = "08"
  1004. break
  1005. case 6:
  1006. item.MedChrgitmType = "14"
  1007. break
  1008. case 7:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 8:
  1012. item.MedChrgitmType = "03"
  1013. break
  1014. case 9:
  1015. item.MedChrgitmType = "14"
  1016. break
  1017. default:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. }
  1021. }
  1022. } else if item.HisPrescriptionProject.Type == 3 {
  1023. item.MedChrgitmType = "08"
  1024. }
  1025. }
  1026. }
  1027. if order.IsMedicineInsurance != 1 {
  1028. order.PsnCashPay = order.MedfeeSumamt
  1029. }
  1030. for _, item := range orderInfos {
  1031. if item.MedChrgitmType == "01" { //床位费
  1032. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //诊察费
  1037. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //zhenChaCostSelfTotal = zhenChaCostTotal
  1039. }
  1040. if item.MedChrgitmType == "03" { //检查费
  1041. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "02" { //检查费
  1046. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "04" { //化验费
  1051. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "05" { //治疗费
  1056. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "06" { //手术费
  1061. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1066. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "09" { //西药费
  1071. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. if item.MedChrgitmType == "11" { //中成费
  1076. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1077. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1078. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1079. }
  1080. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1081. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1082. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1083. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1084. }
  1085. }
  1086. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1087. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1088. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1089. var dia_config []*models.HisXtDiagnoseConfig
  1090. var diagnosis_ids []string
  1091. if his.ID > 0 {
  1092. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1093. } else {
  1094. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1095. }
  1096. for _, item := range diagnosis_ids {
  1097. id, _ := strconv.ParseInt(item, 10, 64)
  1098. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1099. dia_config = append(dia_config, diagnosisConfig)
  1100. }
  1101. var rf []CustomFundPay
  1102. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1103. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1104. c.ServeSuccessJSON(map[string]interface{}{
  1105. "patient": patient,
  1106. "order_infos": orderInfos,
  1107. "diagnosis": name,
  1108. "bedCostTotal": bedCostTotal,
  1109. "bedCostSelfTotal": bedCostTotal,
  1110. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1111. "operationCostTotal": operationCostTotal,
  1112. "operationCostSelfTotal": operationCostTotal,
  1113. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1114. "otherCostTotal": otherCostTotal,
  1115. "otherCostSelfTotal": otherCostTotal,
  1116. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1117. "materialCostTotal": materialCostTotal,
  1118. "materialCostSelfTotal": materialCostTotal,
  1119. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1120. "westernMedicineCostTotal": westernMedicineCostTotal,
  1121. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1122. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1123. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1124. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1125. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1126. "checkCostTotal": checkCostTotal,
  1127. "checkCostSelfTotal": checkCostTotal,
  1128. "zhenChaCostTotal": zhenChaCostTotal,
  1129. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1130. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1131. "laboratoryCostTotal": laboratoryCostTotal,
  1132. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1133. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1134. "treatCostTotal": treatCostTotal,
  1135. "treatCostSelfTotal": treatCostTotal,
  1136. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1137. "charge_admin": charge_admin,
  1138. "printor_admin": printor_admin,
  1139. "org_name": org.OrgName,
  1140. "org_code": miConfig.Code,
  1141. "name": patient.Name,
  1142. "number": order.MdtrtId,
  1143. "date": order.SettleAccountsDate,
  1144. "info": order,
  1145. "new_order": order,
  1146. "his_hospital": his_hospital,
  1147. "his": his,
  1148. "funds": rf,
  1149. "dia_config": dia_config,
  1150. })
  1151. }
  1152. func (c *HisApiController) RefudDetail() {
  1153. order_id, _ := c.GetInt64("order_id")
  1154. order, _ := service.GetHisOrderByID(order_id)
  1155. adminUser := c.GetAdminUserInfo()
  1156. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1157. c.ServeSuccessJSON(map[string]interface{}{
  1158. "msg": "撤销成功",
  1159. })
  1160. }
  1161. func (c *HisApiController) Sscard() {
  1162. //r := CardInit()
  1163. //if r == 0 {
  1164. // GetBaseInfo()
  1165. //}
  1166. //c.ServeSuccessJSON(map[string]interface{}{
  1167. // "list": "11",
  1168. //})
  1169. }
  1170. func GetBaseInfo() error {
  1171. //handle := syscall.MustLoadDLL("SSCard.dll")
  1172. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1173. //
  1174. //str := make([]byte, 256)
  1175. //str1 := make([]byte, 256)
  1176. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1177. //if ferr != nil {
  1178. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1179. // return ferr
  1180. //}
  1181. //
  1182. //fmt.Println(string(str))
  1183. //
  1184. //fmt.Println(r)
  1185. return nil
  1186. }
  1187. func CardInit() int {
  1188. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1189. //add := DllTestDef.MustFindProc("Init")
  1190. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1191. //if err != nil {
  1192. // fmt.Println("SSCard的运算结果为:", ret)
  1193. //}
  1194. //result := int(ret)
  1195. return 0
  1196. }
  1197. func IntPtr(n int) uintptr {
  1198. return uintptr(n)
  1199. }
  1200. func StrPtr(s string) uintptr {
  1201. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1202. }
  1203. func (c *HisApiController) GetHisPatientList() {
  1204. record_date := c.GetString("record_date")
  1205. sch_type, _ := c.GetInt64("sch_type")
  1206. patient_type, _ := c.GetInt64("patient_type")
  1207. fmt.Println("patient_type")
  1208. fmt.Println(patient_type)
  1209. timeLayout := "2006-01-02"
  1210. loc, _ := time.LoadLocation("Local")
  1211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1212. if err != nil {
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. recordDateTime := theTime.Unix()
  1217. adminInfo := c.GetAdminUserInfo()
  1218. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1219. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1220. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1221. fmt.Println("111111")
  1222. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1223. fmt.Println(patients_three)
  1224. //获取当前用户的信息
  1225. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1226. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1227. //获取所有科室信息
  1228. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1229. //var aa []service.PatientThree
  1230. noElementsSlice := make([]service.PatientThree, 0)
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "list": patients_three,
  1233. "list_two": patients_three,
  1234. "list_three": noElementsSlice,
  1235. "info": adminUserInfo,
  1236. "doctors": doctors,
  1237. "department": department,
  1238. })
  1239. } else {
  1240. //获取当前用户的信息
  1241. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1242. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1243. //获取所有科室信息
  1244. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1245. //var aa []service.PatientThree
  1246. noElementsSlice := make([]service.PatientThree, 0)
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "list": patients,
  1249. "list_two": patients_two,
  1250. "list_three": noElementsSlice,
  1251. "info": adminUserInfo,
  1252. "doctors": doctors,
  1253. "department": department,
  1254. })
  1255. }
  1256. }
  1257. type CustomTemplate struct {
  1258. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1259. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1260. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1261. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1262. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1263. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1264. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1265. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1266. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1267. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1268. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1269. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1270. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1271. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1272. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1273. }
  1274. func (c *HisApiController) GetHisPatientInfo() {
  1275. patient_id, _ := c.GetInt64("patient_id")
  1276. his_patient_id, _ := c.GetInt64("his_patient_id")
  1277. record_date := c.GetString("record_date")
  1278. number := c.GetString("number")
  1279. //start_time := c.GetString("start_time")
  1280. //end_time := c.GetString("end_time")
  1281. p_type, _ := c.GetInt64("p_type")
  1282. timeLayout := "2006-01-02"
  1283. loc, _ := time.LoadLocation("Local")
  1284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. recordDateTime := theTime.Unix()
  1290. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1291. //if err != nil {
  1292. //
  1293. //}
  1294. //startRecordDateTime := startTime.Unix()
  1295. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1296. //if err != nil {
  1297. //
  1298. //}
  1299. //endRecordDateTime := endTime.Unix()
  1300. admin := c.GetAdminUserInfo()
  1301. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1302. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1303. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1304. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1306. var prescriptions []*models.HisPrescription
  1307. var last_prescriptions []*models.HisPrescription
  1308. var sch_prescriptions []CustomTemplate
  1309. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1310. if p_type == 1 { //住院
  1311. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1312. for _, item := range prescriptions {
  1313. for _, subItem := range item.HisDoctorAdviceInfo {
  1314. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1315. if info.RetailPrice > 0 {
  1316. subItem.Drug.MinPrice = info.RetailPrice
  1317. }
  1318. }
  1319. }
  1320. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1321. } else { //门诊
  1322. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1323. for _, item := range prescriptions {
  1324. for _, subItem := range item.HisDoctorAdviceInfo {
  1325. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1326. if info.RetailPrice > 0 {
  1327. subItem.Drug.MinPrice = info.RetailPrice
  1328. }
  1329. }
  1330. }
  1331. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1332. }
  1333. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1334. if sch.ID > 0 {
  1335. var week string
  1336. t := time.Now()
  1337. switch t.Weekday().String() {
  1338. case "Monday":
  1339. week = "周一"
  1340. break
  1341. case "Tuesday":
  1342. week = "周二"
  1343. break
  1344. case "Wednesday":
  1345. week = "周三"
  1346. break
  1347. case "Thursday":
  1348. week = "周四"
  1349. break
  1350. case "Friday":
  1351. week = "周五"
  1352. break
  1353. case "Saturday":
  1354. week = "周六"
  1355. break
  1356. case "Sunday":
  1357. week = "周日"
  1358. break
  1359. }
  1360. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1361. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1362. //根据推送频率组装新的数组
  1363. for _, item := range temp_sch_prescriptions {
  1364. var cus CustomTemplate
  1365. cus.ID = item.ID
  1366. cus.UserOrgId = item.UserOrgId
  1367. cus.PatientId = item.PatientId
  1368. cus.MedType = item.MedType
  1369. cus.RecordDate = item.RecordDate
  1370. cus.Type = item.Type
  1371. cus.PType = item.PType
  1372. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1373. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1374. if subItem.FrequencyType == 1 { //每次必推
  1375. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1376. }
  1377. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 2 { //按照天数频率
  1381. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1382. now := p.Unix()
  1383. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1384. dayStr2 := "-" + dayStr
  1385. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1386. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1387. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1388. if len(advices) == 0 {
  1389. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1390. }
  1391. }
  1392. }
  1393. }
  1394. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1395. if subItem.Type == 2 {
  1396. if subItem.XtHisProject.MedicalStatus != 1 {
  1397. if subItem.FrequencyType == 1 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 2 {
  1404. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1405. now := p.Unix()
  1406. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1407. dayStr2 := "-" + dayStr
  1408. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1409. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1410. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1411. if len(projects) == 0 {
  1412. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1413. }
  1414. }
  1415. }
  1416. } else if subItem.Type == 3 {
  1417. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1418. if subItem.FrequencyType == 1 {
  1419. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1420. }
  1421. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 2 {
  1425. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1426. now := p.Unix()
  1427. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1428. dayStr2 := "-" + dayStr
  1429. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1430. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1431. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1432. if len(projects) == 0 {
  1433. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. sch_prescriptions = append(sch_prescriptions, cus)
  1440. }
  1441. for _, item := range sch_prescriptions {
  1442. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1443. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1444. }
  1445. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1446. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1447. }
  1448. }
  1449. }
  1450. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1451. if config.ID > 0 && config.IsOpen == 1 {
  1452. for _, item := range sch_prescriptions {
  1453. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1454. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1455. if info.RetailPrice > 0 {
  1456. subItem.Drug.MinPrice = info.RetailPrice
  1457. if admin.CurrentOrgId != 10598 {
  1458. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1459. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. if config.ID > 0 && config.IsOpen == 1 {
  1466. for _, item := range sch_prescriptions {
  1467. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1468. if subItem.Type == 3 {
  1469. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1470. if info.Price > 0 {
  1471. subItem.GoodInfo.PackingPrice = info.Price
  1472. if admin.CurrentOrgId != 10598 {
  1473. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1474. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1482. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1483. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1484. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1485. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1486. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1487. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1488. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1489. //获取所有科室信息
  1490. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1491. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1492. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1493. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1494. fmt.Println(prescriptions)
  1495. fmt.Println(sch_prescriptions)
  1496. fmt.Println(last_prescriptions)
  1497. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1498. if len(sch_prescriptions) > 0 {
  1499. var index = 0
  1500. for subindex, item := range sch_prescriptions {
  1501. if item.Type == 2 {
  1502. index = subindex
  1503. }
  1504. }
  1505. fmt.Println(index)
  1506. fmt.Println(len(sch_prescriptions))
  1507. if index >= 0 && index < len(sch_prescriptions) {
  1508. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1509. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1510. three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1511. if one.ID > 0 {
  1512. var hpt models.HisPrescriptionProjectTemplate
  1513. hpt.Type = 3
  1514. hpt.ID = 0
  1515. hpt.PatientId = sch_prescriptions[index].PatientId
  1516. hpt.Status = 1
  1517. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1518. hpt.Mtime = time.Now().Unix()
  1519. hpt.Ctime = time.Now().Unix()
  1520. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1521. hpt.Count = "1"
  1522. hpt.Price = one.RetailPrice
  1523. hpt.ProjectId = one.ID
  1524. hpt.FeedetlSn = ""
  1525. hpt.PrescriptionId = sch_prescriptions[index].ID
  1526. hpt.Unit = one.PackingUnit
  1527. hpt.Day = "1"
  1528. hpt.SingleDose = "1"
  1529. hpt.GoodInfo = one
  1530. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1531. }
  1532. if two.ID > 0 {
  1533. var hpt models.HisPrescriptionProjectTemplate
  1534. hpt.Type = 3
  1535. hpt.ID = 0
  1536. hpt.PatientId = sch_prescriptions[index].PatientId
  1537. hpt.Status = 1
  1538. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1539. hpt.Mtime = time.Now().Unix()
  1540. hpt.Ctime = time.Now().Unix()
  1541. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1542. hpt.Count = "1"
  1543. hpt.Price = two.RetailPrice
  1544. hpt.ProjectId = two.ID
  1545. hpt.FeedetlSn = ""
  1546. hpt.PrescriptionId = sch_prescriptions[index].ID
  1547. hpt.Unit = two.PackingUnit
  1548. hpt.Day = "1"
  1549. hpt.SingleDose = "1"
  1550. hpt.GoodInfo = two
  1551. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1552. }
  1553. if three.ID > 0 {
  1554. var hpt models.HisPrescriptionProjectTemplate
  1555. hpt.Type = 3
  1556. hpt.ID = 0
  1557. hpt.PatientId = sch_prescriptions[index].PatientId
  1558. hpt.Status = 1
  1559. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1560. hpt.Mtime = time.Now().Unix()
  1561. hpt.Ctime = time.Now().Unix()
  1562. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1563. hpt.Count = "1"
  1564. hpt.Price = three.RetailPrice
  1565. hpt.ProjectId = three.ID
  1566. hpt.FeedetlSn = ""
  1567. hpt.PrescriptionId = sch_prescriptions[index].ID
  1568. hpt.Unit = three.PackingUnit
  1569. hpt.Day = "1"
  1570. hpt.SingleDose = "1"
  1571. hpt.GoodInfo = three
  1572. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1573. }
  1574. fmt.Println(sch_prescriptions)
  1575. }
  1576. } else {
  1577. if len(last_prescriptions) > 0 {
  1578. var index = 0
  1579. for subindex, item := range last_prescriptions {
  1580. if item.Type == 2 {
  1581. index = subindex
  1582. }
  1583. }
  1584. if index >= 0 && index < len(last_prescriptions) {
  1585. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1586. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1587. three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1588. if one.ID > 0 {
  1589. var hpt models.HisPrescriptionProject
  1590. hpt.Type = 3
  1591. hpt.ID = 0
  1592. hpt.PatientId = last_prescriptions[index].PatientId
  1593. hpt.Status = 1
  1594. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1595. hpt.Mtime = time.Now().Unix()
  1596. hpt.Ctime = time.Now().Unix()
  1597. hpt.RecordDate = last_prescriptions[index].RecordDate
  1598. hpt.Count = "1"
  1599. hpt.Price = one.RetailPrice
  1600. hpt.ProjectId = one.ID
  1601. hpt.FeedetlSn = ""
  1602. hpt.PrescriptionId = last_prescriptions[index].ID
  1603. hpt.Unit = one.PackingUnit
  1604. hpt.Day = "1"
  1605. hpt.SingleDose = "1"
  1606. hpt.GoodInfo = one
  1607. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1608. }
  1609. if two.ID > 0 {
  1610. var hpt models.HisPrescriptionProject
  1611. hpt.Type = 3
  1612. hpt.ID = 0
  1613. hpt.PatientId = last_prescriptions[index].PatientId
  1614. hpt.Status = 1
  1615. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1616. hpt.Mtime = time.Now().Unix()
  1617. hpt.Ctime = time.Now().Unix()
  1618. hpt.RecordDate = last_prescriptions[index].RecordDate
  1619. hpt.Count = "1"
  1620. hpt.Price = two.RetailPrice
  1621. hpt.ProjectId = two.ID
  1622. hpt.FeedetlSn = ""
  1623. hpt.PrescriptionId = last_prescriptions[index].ID
  1624. hpt.Unit = two.PackingUnit
  1625. hpt.Day = "1"
  1626. hpt.SingleDose = "1"
  1627. hpt.GoodInfo = two
  1628. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1629. }
  1630. if three.ID > 0 {
  1631. var hpt models.HisPrescriptionProject
  1632. hpt.Type = 3
  1633. hpt.ID = 0
  1634. hpt.PatientId = last_prescriptions[index].PatientId
  1635. hpt.Status = 1
  1636. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1637. hpt.Mtime = time.Now().Unix()
  1638. hpt.Ctime = time.Now().Unix()
  1639. hpt.RecordDate = last_prescriptions[index].RecordDate
  1640. hpt.Count = "1"
  1641. hpt.Price = three.RetailPrice
  1642. hpt.ProjectId = three.ID
  1643. hpt.FeedetlSn = ""
  1644. hpt.PrescriptionId = last_prescriptions[index].ID
  1645. hpt.Unit = three.PackingUnit
  1646. hpt.Day = "1"
  1647. hpt.SingleDose = "1"
  1648. hpt.GoodInfo = three
  1649. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. c.ServeSuccessJSON(map[string]interface{}{
  1656. "his_info": his_patient_info,
  1657. "xt_info": xt_patient_info,
  1658. "prescription": prescriptions,
  1659. "case_history": case_history,
  1660. "info": patientPrescriptionInfo,
  1661. //"month_prescriptions": monthPrescriptions,
  1662. "order": order,
  1663. "doctors": doctors,
  1664. "department": department,
  1665. "sch_prescriptions": sch_prescriptions,
  1666. "last_prescriptions": last_prescriptions,
  1667. "schedule": sch,
  1668. "count": count,
  1669. "drugStockConfig": drugStockConfig,
  1670. "last_info": lastPatientPrescriptionInfo,
  1671. "befor": beforThrity,
  1672. "LastCaseHistory": LastCaseHistory,
  1673. "prescriptionInfo": prescriptionInfo,
  1674. })
  1675. return
  1676. }
  1677. func (c *HisApiController) GetHisPrescriptionConfig() {
  1678. adminInfo := c.GetAdminUserInfo()
  1679. //获取医嘱模版
  1680. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1681. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1682. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1683. //获取所有基础药
  1684. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1685. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1686. if config.ID > 0 && config.IsOpen == 1 {
  1687. for _, item := range drugs {
  1688. var index = 0
  1689. for _, subItem := range item.OtherDrugWarehouseInfo {
  1690. if index == 0 {
  1691. index = index + 1
  1692. if subItem.RetailPrice > 0 {
  1693. item.MinPrice = subItem.RetailPrice
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1700. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1701. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1702. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1703. //获取所有科室信息
  1704. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1705. //获取诊断信息
  1706. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1707. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1708. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1709. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1710. //获取是否开启保存耗材出库的开关
  1711. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1712. c.ServeSuccessJSON(map[string]interface{}{
  1713. "drugs": drugs,
  1714. "advices_template": advices,
  1715. "drugways": drugways,
  1716. "efs": efs,
  1717. "doctors": doctors,
  1718. "department": department,
  1719. "sick": sick,
  1720. "additions": additions,
  1721. "diagnose": diagnose,
  1722. "manufacturers": manufacturers,
  1723. "goodOutOpen": goodOutOpen,
  1724. "patientDiagnose": patientDiagnose,
  1725. })
  1726. }
  1727. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1728. //获取所有基础药
  1729. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1730. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1731. if config.ID > 0 && config.IsOpen == 1 {
  1732. for _, item := range drugs {
  1733. var index = 0
  1734. for _, subItem := range item.OtherDrugWarehouseInfo {
  1735. if index == 0 {
  1736. index = index + 1
  1737. if subItem.RetailPrice > 0 {
  1738. item.MinPrice = subItem.RetailPrice
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1745. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1746. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1747. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1748. //获取所有科室信息
  1749. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1750. //获取诊断信息
  1751. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1752. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1753. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1754. //获取是否开启保存耗材出库的开关
  1755. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1756. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1757. c.ServeSuccessJSON(map[string]interface{}{
  1758. "drugs": drugs,
  1759. "advices_template": advices,
  1760. "drugways": drugways,
  1761. "efs": efs,
  1762. "doctors": doctors,
  1763. "department": department,
  1764. "sick": sick,
  1765. "additions": additions,
  1766. "diagnose": diagnose,
  1767. "manufacturers": manufacturers,
  1768. "goodOutOpen": goodOutOpen,
  1769. "patientDiagnose": patientDiagnose,
  1770. })
  1771. }
  1772. }
  1773. func (c *HisApiController) CreateHisPrescription() {
  1774. record_date := c.GetString("record_date")
  1775. patient_id, _ := c.GetInt64("patient_id")
  1776. reg_type, _ := c.GetInt64("reg_type")
  1777. diagnose := c.GetString("diagnose")
  1778. sick_type, _ := c.GetInt64("sick_type")
  1779. sick_history := c.GetString("sick_history")
  1780. doctor_id, _ := c.GetInt64("doctor", 0)
  1781. department, _ := c.GetInt64("department", 0)
  1782. his_patient_id, _ := c.GetInt64("his_patient_id")
  1783. p_type, _ := c.GetInt64("p_type")
  1784. patient_diagnose := c.GetString("patient_diagnose")
  1785. dataBody := make(map[string]interface{}, 0)
  1786. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. //edit, src := GetCompareData(dataBody)
  1793. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1794. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1795. //fmt.Println(drugResult)
  1796. //fmt.Println(goodResult)
  1797. timeLayout := "2006-01-02"
  1798. loc, _ := time.LoadLocation("Local")
  1799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1800. if err != nil {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. adminInfo := c.GetAdminUserInfo()
  1805. recordDateTime := theTime.Unix()
  1806. //查询默认出库仓库库存
  1807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1808. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1809. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1810. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1811. if len(lists) == 1 {
  1812. his_patient_id = lists[0].ID
  1813. }
  1814. }
  1815. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1816. //自动出库的开关开启
  1817. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1818. //自动出库
  1819. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1820. //耗材保存处方出库
  1821. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1822. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1823. //已发药和已收费限制逻辑
  1824. isMidicine := false
  1825. isCharge := false
  1826. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1827. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1828. if len(prescriptions) > 0 {
  1829. for _, item := range prescriptions {
  1830. items := item.(map[string]interface{})
  1831. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1832. utils.ErrorLog("id")
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. id := int64(items["id"].(float64))
  1837. if id > 0 {
  1838. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1839. if err != nil {
  1840. if new_prescription.OrderStatus == 4 {
  1841. isCharge = true
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. if isMidicine == true {
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1850. return
  1851. }
  1852. if isCharge == true {
  1853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1854. return
  1855. }
  1856. // 开始主事务
  1857. db := service.XTWriteDB()
  1858. tx := db.Begin()
  1859. // 在函数结束时处理事务回滚
  1860. defer func() {
  1861. if r := recover(); r != nil {
  1862. tx.Rollback()
  1863. }
  1864. }()
  1865. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1866. //药品发药出库
  1867. if pharmacyConfig.IsOpen == 1 {
  1868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1870. if len(prescriptions) > 0 {
  1871. for _, item := range prescriptions {
  1872. items := item.(map[string]interface{})
  1873. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1874. advices := items["advices"].([]interface{})
  1875. if len(advices) > 0 {
  1876. for _, advice := range advices {
  1877. var drug_id int64
  1878. var prescribing_number float64
  1879. var prescribingNumberUnit string
  1880. var adviceId int64
  1881. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1882. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1883. }
  1884. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1885. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1886. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1887. }
  1888. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1889. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1890. }
  1891. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1892. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1893. }
  1894. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1895. if drug.ID == 0 {
  1896. tx.Rollback()
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. //查询药品的所有库存
  1901. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1902. var total_count int64
  1903. for _, it := range list {
  1904. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1905. }
  1906. totals := strconv.FormatInt(total_count, 10)
  1907. //查询该药品是否存在开药记录
  1908. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1909. //新增处方盘点库存是否充足
  1910. if advicelist.ID == 0 {
  1911. all_count, _ := strconv.ParseFloat(totals, 64)
  1912. if prescribingNumberUnit == drug.MinUnit {
  1913. if drug.IsUse != 1 {
  1914. if drug.IsProject == 0 || drug.IsProject == 2 {
  1915. if all_count == 0 {
  1916. tx.Rollback()
  1917. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1918. return
  1919. }
  1920. if prescribing_number > all_count {
  1921. tx.Rollback()
  1922. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1923. return
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if prescribingNumberUnit == drug.MaxUnit {
  1929. num := prescribing_number * float64(drug.MinNumber)
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1935. return
  1936. }
  1937. if num > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1940. return
  1941. }
  1942. }
  1943. }
  1944. }
  1945. }
  1946. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1947. //不使用保存处方出库
  1948. if drugOutConfig.IsOpen != 1 {
  1949. //修改处方
  1950. for _, advice := range advices {
  1951. var drug_id int64
  1952. var prescribing_number float64
  1953. var prescribingNumberUnit string
  1954. var prescribingNumber string
  1955. var adviceId int64
  1956. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1957. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1960. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1961. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1962. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1963. }
  1964. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1965. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1968. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1969. }
  1970. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1971. if drug.ID == 0 {
  1972. tx.Rollback()
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. //查询药品的所有库存
  1977. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1978. var total_count int64
  1979. for _, it := range list {
  1980. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1981. }
  1982. totals := strconv.FormatInt(total_count, 10)
  1983. //查询该药品是否存在开药记录
  1984. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1985. //新增处方
  1986. if advicelist.ID == 0 {
  1987. all_count, _ := strconv.ParseFloat(totals, 64)
  1988. if prescribingNumberUnit == drug.MinUnit {
  1989. if drug.IsUse != 1 {
  1990. if drug.IsProject == 0 || drug.IsProject == 2 {
  1991. if all_count == 0 {
  1992. tx.Rollback()
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1994. return
  1995. }
  1996. if prescribing_number > all_count {
  1997. tx.Rollback()
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1999. return
  2000. }
  2001. }
  2002. }
  2003. } else {
  2004. if prescribingNumberUnit == drug.MaxUnit {
  2005. num := prescribing_number * float64(drug.MinNumber)
  2006. if drug.IsUse != 1 {
  2007. if drug.IsProject == 0 || drug.IsProject == 2 {
  2008. if all_count == 0 {
  2009. tx.Rollback()
  2010. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2011. return
  2012. }
  2013. if num > all_count {
  2014. tx.Rollback()
  2015. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2016. return
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. //修改处方
  2024. if advicelist.ID > 0 {
  2025. var device_number int64
  2026. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2027. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2028. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2029. device_number = prescribingNumberInt * drug.MinNumber
  2030. }
  2031. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2032. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2033. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2034. device_number = prescribingNumberInt
  2035. }
  2036. var number_count int64
  2037. if prescribingNumberUnit == drug.MaxUnit {
  2038. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2039. number_count = prescribingNumberInt * drug.MinNumber
  2040. }
  2041. if prescribingNumberUnit == drug.MinUnit {
  2042. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2043. number_count = prescribingNumberInt
  2044. }
  2045. //如果修改的数量大于之前修改的数量
  2046. if (number_count - device_number) > 0 {
  2047. //如果修改的差数量 大于库存数量
  2048. if drug.IsUse != 1 {
  2049. if (number_count - device_number) > total_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. //已发药和已收费限制逻辑
  2067. //执行出库的逻辑
  2068. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2069. //校验库存总量
  2070. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2071. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2072. if len(prescriptions) > 0 {
  2073. for _, item := range prescriptions {
  2074. items := item.(map[string]interface{})
  2075. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2076. advices := items["advices"].([]interface{})
  2077. if len(advices) > 0 {
  2078. for _, advice := range advices {
  2079. var drug_id int64
  2080. var prescribing_number float64
  2081. var prescribingNumberUnit string
  2082. var adviceId int64
  2083. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2084. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2085. }
  2086. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2087. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2088. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2089. }
  2090. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2091. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2092. }
  2093. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2094. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2095. }
  2096. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2097. if drug.ID == 0 {
  2098. tx.Rollback()
  2099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2100. return
  2101. }
  2102. //查询药品的所有库存
  2103. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2104. var total_count int64
  2105. for _, it := range list {
  2106. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2107. }
  2108. totals := strconv.FormatInt(total_count, 10)
  2109. //查询该药品是否存在开药记录
  2110. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2111. //查询最新批次库存
  2112. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2113. var batch_number_count int64
  2114. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2115. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2116. //新增处方
  2117. if advicelist.ID == 0 {
  2118. all_count, _ := strconv.ParseFloat(totals, 64)
  2119. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2120. if prescribingNumberUnit == drug.MinUnit {
  2121. if drug.IsUse != 1 {
  2122. if drug.IsProject == 0 || drug.IsProject == 2 {
  2123. if all_count == 0 {
  2124. tx.Rollback()
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if prescribing_number > all_count {
  2129. tx.Rollback()
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2131. return
  2132. }
  2133. }
  2134. if adminInfo.CurrentOrgId == 10215 {
  2135. if prescribing_number > batch_number_all_count {
  2136. tx.Rollback()
  2137. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2138. return
  2139. }
  2140. }
  2141. }
  2142. }
  2143. if prescribingNumberUnit == drug.MaxUnit {
  2144. num := prescribing_number * float64(drug.MinNumber)
  2145. if drug.IsUse != 1 {
  2146. if drug.IsProject == 0 || drug.IsProject == 2 {
  2147. if all_count == 0 {
  2148. tx.Rollback()
  2149. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2150. return
  2151. }
  2152. if num > all_count {
  2153. tx.Rollback()
  2154. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2155. return
  2156. }
  2157. }
  2158. if adminInfo.CurrentOrgId == 10215 {
  2159. if num > batch_number_all_count {
  2160. tx.Rollback()
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2162. return
  2163. }
  2164. }
  2165. }
  2166. }
  2167. }
  2168. //不是保存处方出库
  2169. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2170. if drugOutConfig.IsOpen != 1 {
  2171. //修改处方
  2172. for _, advice := range advices {
  2173. var drug_id int64
  2174. var prescribing_number float64
  2175. var prescribingNumberUnit string
  2176. var prescribingNumber string
  2177. var adviceId int64
  2178. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2179. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2180. }
  2181. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2182. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2183. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2184. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2185. }
  2186. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2187. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2190. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2191. }
  2192. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2193. if drug.ID == 0 {
  2194. tx.Rollback()
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if all_count == 0 {
  2216. tx.Rollback()
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2218. return
  2219. }
  2220. if prescribingNumberUnit == drug.MinUnit {
  2221. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2222. if drug.IsUse != 1 {
  2223. if drug.IsProject == 0 || drug.IsProject == 2 {
  2224. if all_count == 0 {
  2225. tx.Rollback()
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. if prescribing_number > all_count {
  2230. tx.Rollback()
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. }
  2235. if adminInfo.CurrentOrgId == 10215 {
  2236. if prescribing_number > batch_number_all_count {
  2237. tx.Rollback()
  2238. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2239. return
  2240. }
  2241. }
  2242. }
  2243. } else {
  2244. if prescribingNumberUnit == drug.MaxUnit {
  2245. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2246. num := prescribing_number * float64(drug.MinNumber)
  2247. if drug.IsUse != 1 {
  2248. if drug.IsProject == 0 || drug.IsProject == 2 {
  2249. if all_count == 0 {
  2250. tx.Rollback()
  2251. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2252. return
  2253. }
  2254. if num > all_count {
  2255. tx.Rollback()
  2256. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2257. return
  2258. }
  2259. }
  2260. if adminInfo.CurrentOrgId == 10215 {
  2261. if prescribing_number > batch_number_all_count {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2264. return
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. //修改处方
  2272. if advicelist.ID > 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. var device_number int64
  2278. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2281. device_number = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2285. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2286. device_number = prescribingNumberInt
  2287. //回退库存
  2288. }
  2289. var number_count int64
  2290. if prescribingNumberUnit == drug.MaxUnit {
  2291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2292. number_count = prescribingNumberInt * drug.MinNumber
  2293. //回退库存
  2294. }
  2295. if prescribingNumberUnit == drug.MinUnit {
  2296. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2297. number_count = prescribingNumberInt
  2298. //回退库存
  2299. }
  2300. //如果修改的数量大于之前修改的数量
  2301. if (number_count - device_number) > 0 {
  2302. //如果修改的差数量 大于库存数量
  2303. if drug.IsUse != 1 {
  2304. if drug.IsProject == 0 || drug.IsProject == 2 {
  2305. if total_count == 0 {
  2306. tx.Rollback()
  2307. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2308. return
  2309. }
  2310. if (number_count - device_number) > total_count {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if (number_count - device_number) > batch_number_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. // 查询该药品最后一次出库记录
  2323. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2324. var out_count int64
  2325. var in_count int64
  2326. var stock_max_number int64
  2327. var stock_min_number int64
  2328. for _, it := range outInfo {
  2329. if it.CountUnit == drug.MaxUnit {
  2330. it.Count = it.Count * drug.MinNumber
  2331. }
  2332. out_count += it.Count
  2333. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2334. stock_max_number = warehouseInfoList.StockMaxNumber
  2335. stock_min_number = warehouseInfoList.StockMinNumber
  2336. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2337. }
  2338. if out_count > 0 {
  2339. if (number_count - device_number) > in_count {
  2340. tx.Rollback()
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. // 未出库
  2346. if out_count == 0 {
  2347. var sum_in_count int64
  2348. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2349. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2350. //如果修改的数量大于有库存的第一个批次
  2351. if number_count > sum_in_count {
  2352. tx.Rollback()
  2353. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2354. return
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. //药品发药
  2361. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2362. //不使用药品发药的功能
  2363. //if pharmacyConfig.IsOpen != 1 {
  2364. // if device_number != number_count {
  2365. //
  2366. // //查询该药品的出库记录
  2367. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2368. // if len(outListExport) > 0 {
  2369. // //
  2370. // for _, item := range outListExport {
  2371. // //回退库存
  2372. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2373. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2374. // }
  2375. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2376. // var stock_max_number int64
  2377. // var stock_min_number int64
  2378. //
  2379. // if number_count >= drug.MinNumber {
  2380. //
  2381. // stock_max_number = device_number / drug.MinNumber
  2382. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2383. //
  2384. // stock_min_number = device_number % drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2386. //
  2387. // } else {
  2388. //
  2389. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2390. //
  2391. // }
  2392. // }
  2393. //
  2394. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2395. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2396. // }
  2397. // }
  2398. // }
  2399. //
  2400. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2401. // var sum_count int64
  2402. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2403. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2404. // for _, its := range stockInfo {
  2405. // if its.MaxUnit == drug.MaxUnit {
  2406. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2407. // }
  2408. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2409. // }
  2410. // //更新字典里面的库存
  2411. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2412. //
  2413. // //剩余库存
  2414. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2415. //
  2416. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2417. // //减少出库数量
  2418. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2419. //
  2420. // }
  2421. //}
  2422. }
  2423. }
  2424. }
  2425. //保存处方开药
  2426. if drugOutConfig.IsOpen == 1 {
  2427. //修改处方
  2428. for _, advice := range advices {
  2429. var drug_id int64
  2430. var prescribing_number float64
  2431. var prescribingNumberUnit string
  2432. var prescribingNumber string
  2433. var adviceId int64
  2434. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2435. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2436. }
  2437. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2438. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2439. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2440. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2441. }
  2442. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2443. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2446. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2447. }
  2448. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2449. if drug.ID == 0 {
  2450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2451. return
  2452. }
  2453. //查询药品的所有库存
  2454. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2455. var total_count int64
  2456. for _, it := range list {
  2457. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2458. }
  2459. totals := strconv.FormatInt(total_count, 10)
  2460. //查询该药品是否存在开药记录
  2461. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2462. //新增处方
  2463. if advicelist.ID == 0 {
  2464. //查询最新批次库存
  2465. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2466. var batch_number_count int64
  2467. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2468. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2469. all_count, _ := strconv.ParseFloat(totals, 64)
  2470. if prescribingNumberUnit == drug.MinUnit {
  2471. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2472. if drug.IsUse != 1 {
  2473. if drug.IsProject == 0 || drug.IsProject == 2 {
  2474. if all_count == 0 {
  2475. tx.Rollback()
  2476. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2477. return
  2478. }
  2479. if prescribing_number > all_count {
  2480. tx.Rollback()
  2481. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2482. return
  2483. }
  2484. }
  2485. if adminInfo.CurrentOrgId == 10215 {
  2486. if prescribing_number > batch_number_all_count {
  2487. tx.Rollback()
  2488. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2489. return
  2490. }
  2491. }
  2492. }
  2493. } else {
  2494. if prescribingNumberUnit == drug.MaxUnit {
  2495. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2496. num := prescribing_number * float64(drug.MinNumber)
  2497. if drug.IsUse != 1 {
  2498. if drug.IsProject == 0 || drug.IsProject == 2 {
  2499. if all_count == 0 {
  2500. tx.Rollback()
  2501. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2502. return
  2503. }
  2504. if num > all_count {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2507. return
  2508. }
  2509. }
  2510. if adminInfo.CurrentOrgId == 10215 {
  2511. if prescribing_number > batch_number_all_count {
  2512. tx.Rollback()
  2513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2514. return
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. //修改处方
  2522. if advicelist.ID > 0 {
  2523. //查询最新批次库存
  2524. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2525. var batch_number_count int64
  2526. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2527. var device_number int64
  2528. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2529. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2530. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2531. device_number = prescribingNumberInt * drug.MinNumber
  2532. }
  2533. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2534. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2535. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2536. device_number = prescribingNumberInt
  2537. }
  2538. var number_count int64
  2539. if prescribingNumberUnit == drug.MaxUnit {
  2540. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2541. number_count = prescribingNumberInt * drug.MinNumber
  2542. }
  2543. if prescribingNumberUnit == drug.MinUnit {
  2544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2545. number_count = prescribingNumberInt
  2546. }
  2547. //如果修改的数量大于之前修改的数量
  2548. if (number_count - device_number) > 0 {
  2549. //如果修改的差数量 大于库存数量
  2550. if drug.IsUse != 1 {
  2551. if drug.IsProject == 0 || drug.IsProject == 2 {
  2552. if total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2555. return
  2556. }
  2557. if (number_count - device_number) > total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2560. return
  2561. }
  2562. }
  2563. if adminInfo.CurrentOrgId == 10215 {
  2564. if (number_count - device_number) > batch_number_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2571. //查询历史出库数据总批次
  2572. // 查询该药品最后一次出库记录
  2573. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2574. var out_count int64
  2575. var in_count int64
  2576. var stock_max_number int64
  2577. var stock_min_number int64
  2578. for _, it := range outInfo {
  2579. if it.CountUnit == drug.MaxUnit {
  2580. it.Count = it.Count * drug.MinNumber
  2581. }
  2582. out_count += it.Count
  2583. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2584. stock_max_number = warehouseInfoList.StockMaxNumber
  2585. stock_min_number = warehouseInfoList.StockMinNumber
  2586. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2587. }
  2588. if out_count > 0 {
  2589. if (number_count - device_number) > in_count {
  2590. tx.Rollback()
  2591. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2592. return
  2593. }
  2594. }
  2595. // 未出库
  2596. if out_count == 0 {
  2597. var sum_in_count int64
  2598. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2599. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2600. if sum_in_count == 0 {
  2601. tx.Rollback()
  2602. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2603. return
  2604. }
  2605. //如果修改的数量大于有库存的第一个批次
  2606. if number_count > sum_in_count {
  2607. tx.Rollback()
  2608. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2609. return
  2610. }
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. //校验耗材库存
  2626. if goodOutConfig.IsOpen == 1 {
  2627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2629. if len(prescriptions) > 0 {
  2630. for _, item := range prescriptions {
  2631. items := item.(map[string]interface{})
  2632. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2633. projects := items["project"].([]interface{})
  2634. if len(projects) > 0 {
  2635. for _, project := range projects {
  2636. var project_id int64
  2637. var project_type int64
  2638. var totals float64
  2639. var project_name string
  2640. var parsetotal int64
  2641. var id int64
  2642. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2643. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2644. }
  2645. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2646. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2649. total, _ := project.(map[string]interface{})["total"].(string)
  2650. totals, _ = strconv.ParseFloat(total, 64)
  2651. }
  2652. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2653. project_name = project.(map[string]interface{})["project_name"].(string)
  2654. }
  2655. if project_type == 3 {
  2656. //查找该耗材的出库记录
  2657. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2658. if len(goodWarehouseInfo) == 0 {
  2659. //查询耗材库存
  2660. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2661. var stock_count int64
  2662. for _, it := range list {
  2663. stock_count += it.StockCount
  2664. }
  2665. stock_counts := strconv.FormatInt(stock_count, 10)
  2666. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2667. if stock_total_count == 0 {
  2668. tx.Rollback()
  2669. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2670. return
  2671. }
  2672. if totals > stock_total_count {
  2673. tx.Rollback()
  2674. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2675. return
  2676. }
  2677. }
  2678. if len(goodWarehouseInfo) > 0 {
  2679. //查询该患者耗材的历史数据
  2680. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2681. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2682. //数量发生改变
  2683. if parsetotal != count {
  2684. //如果现在的数量大于历史数量,就要看库存是否足够
  2685. if parsetotal > count {
  2686. //查询耗材所有库存
  2687. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2688. var stock_count int64
  2689. for _, it := range list {
  2690. stock_count += it.StockCount
  2691. }
  2692. //库存不足
  2693. if stock_count == 0 {
  2694. tx.Rollback()
  2695. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2696. return
  2697. }
  2698. if (parsetotal - count) > stock_count {
  2699. tx.Rollback()
  2700. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2701. return
  2702. }
  2703. }
  2704. }
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. //不使用耗材保存处方出库
  2715. if goodOutConfig.IsOpen != 1 {
  2716. if stockConfig.IsOpen == 1 {
  2717. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2718. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2719. if len(prescriptions) > 0 {
  2720. for _, item := range prescriptions {
  2721. items := item.(map[string]interface{})
  2722. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2723. projects := items["project"].([]interface{})
  2724. if len(projects) > 0 {
  2725. for _, project := range projects {
  2726. var project_id int64
  2727. var project_type int64
  2728. var totals float64
  2729. var project_name string
  2730. var parsetotal int64
  2731. var id int64
  2732. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2733. id = int64(project.(map[string]interface{})["id"].(float64))
  2734. }
  2735. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2736. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2739. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2742. total, _ := project.(map[string]interface{})["total"].(string)
  2743. totals, _ = strconv.ParseFloat(total, 64)
  2744. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2745. }
  2746. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2747. project_name = project.(map[string]interface{})["project_name"].(string)
  2748. }
  2749. if project_type == 3 {
  2750. //查找该耗材的出库记录
  2751. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2752. //没有出库记录
  2753. if len(goodWarehouseInfo) == 0 {
  2754. //查询耗材库存
  2755. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2756. var stock_count int64
  2757. for _, it := range list {
  2758. stock_count += it.StockCount
  2759. }
  2760. stock_counts := strconv.FormatInt(stock_count, 10)
  2761. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2762. if stock_total_count == 0 {
  2763. tx.Rollback()
  2764. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2765. return
  2766. }
  2767. if totals > stock_total_count {
  2768. tx.Rollback()
  2769. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2770. return
  2771. }
  2772. //查找今日该患者已经出库的所有耗材
  2773. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2774. for _, item := range goodList {
  2775. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2776. var flush_count int64
  2777. for _, it := range goodListSix {
  2778. flush_count += it.StockCount
  2779. }
  2780. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2781. creater := adminInfo.AdminUser.Id
  2782. if errs != nil {
  2783. goodErrcode := models.XtGoodErrcode{
  2784. UserOrgId: item.OrgId,
  2785. Errcode: "手动出库更新剩余出库失败",
  2786. GoodId: item.GoodId,
  2787. Status: 1,
  2788. Ctime: time.Now().Unix(),
  2789. Mtime: 0,
  2790. Count: 0,
  2791. StockCount: 0,
  2792. Creater: creater,
  2793. BatchNumberId: 0,
  2794. WarehouseOutId: 0,
  2795. }
  2796. service.CreateGoodErrcode(goodErrcode)
  2797. }
  2798. }
  2799. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2800. }
  2801. //有出库记录
  2802. if len(goodWarehouseInfo) > 0 {
  2803. //查询该患者耗材的历史数据
  2804. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2805. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2806. //数量发生改变
  2807. if parsetotal != count {
  2808. //查找今日该患者已经出库的所有耗材
  2809. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2810. for _, item := range goodList {
  2811. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2812. var flush_count int64
  2813. for _, it := range goodListSix {
  2814. flush_count += it.StockCount
  2815. }
  2816. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2817. //减少出库数量
  2818. creater := adminInfo.AdminUser.Id
  2819. if errs != nil {
  2820. goodErrcode := models.XtGoodErrcode{
  2821. UserOrgId: item.OrgId,
  2822. Errcode: "手动出库更新剩余出库失败",
  2823. GoodId: item.GoodId,
  2824. Status: 1,
  2825. Ctime: time.Now().Unix(),
  2826. Mtime: 0,
  2827. Count: 0,
  2828. StockCount: 0,
  2829. Creater: creater,
  2830. BatchNumberId: 0,
  2831. WarehouseOutId: 0,
  2832. }
  2833. service.CreateGoodErrcode(goodErrcode)
  2834. }
  2835. //查询默认仓库
  2836. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2837. var total_count int64
  2838. for _, it := range stockList {
  2839. total_count += it.StockCount
  2840. }
  2841. //基础库插入数据
  2842. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2843. }
  2844. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2857. var hpInfo models.HisPrescriptionInfo
  2858. if info.ID == 0 {
  2859. var randNum int
  2860. randNum = rand.Intn(10000) + 1000
  2861. timestamp := time.Now().Unix()
  2862. tempTime := time.Unix(timestamp, 0)
  2863. timeFormat := tempTime.Format("20060102150405")
  2864. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2865. hpInfo = models.HisPrescriptionInfo{
  2866. HisPatientId: his_patient_id,
  2867. UserOrgId: adminInfo.CurrentOrgId,
  2868. RecordDate: theTime.Unix(),
  2869. PatientId: patient_id,
  2870. Status: 1,
  2871. Ctime: time.Now().Unix(),
  2872. Mtime: time.Now().Unix(),
  2873. Creator: adminInfo.AdminUser.Id,
  2874. Modifier: adminInfo.AdminUser.Id,
  2875. Diagnosis: diagnose,
  2876. SickHistory: sick_history,
  2877. Departments: department,
  2878. RegisterType: reg_type,
  2879. PrescriptionNumber: p_number,
  2880. PrescriptionStatus: 1,
  2881. Doctor: role.UserName,
  2882. DoctorId: doctor_id,
  2883. SickType: sick_type,
  2884. PType: p_type,
  2885. PatientDiagnosis: patient_diagnose,
  2886. }
  2887. service.SavePatientPrescriptionInfo(hpInfo)
  2888. //创建步骤表
  2889. finish := models.XtDialysisFinish{
  2890. IsFinish: 1,
  2891. UserOrgId: adminInfo.CurrentOrgId,
  2892. Status: 1,
  2893. Ctime: time.Now().Unix(),
  2894. Mtime: 0,
  2895. Module: 4,
  2896. RecordDate: theTime.Unix(),
  2897. Sourse: 1,
  2898. PatientId: patient_id,
  2899. }
  2900. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2901. if dialysisFinish.ID == 0 {
  2902. service.CreateDialysisFinish(finish)
  2903. }
  2904. redis := service.RedisClient()
  2905. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2906. redis.Set(key, "", time.Second)
  2907. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2908. redis.Set(keyOne, "", time.Second)
  2909. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2910. redis.Set(keySeven, "", time.Second)
  2911. defer redis.Close()
  2912. } else {
  2913. hpInfo = models.HisPrescriptionInfo{
  2914. ID: info.ID,
  2915. UserOrgId: adminInfo.CurrentOrgId,
  2916. RecordDate: info.RecordDate,
  2917. PatientId: info.PatientId,
  2918. Status: 1,
  2919. Ctime: info.Ctime,
  2920. Mtime: time.Now().Unix(),
  2921. Creator: info.Creator,
  2922. Modifier: adminInfo.AdminUser.Id,
  2923. Diagnosis: diagnose,
  2924. SickHistory: sick_history,
  2925. Departments: department,
  2926. RegisterType: reg_type,
  2927. PrescriptionNumber: info.PrescriptionNumber,
  2928. Doctor: role.UserName,
  2929. PrescriptionStatus: info.PrescriptionStatus,
  2930. DoctorId: doctor_id,
  2931. SickType: sick_type,
  2932. PType: info.PType,
  2933. HisPatientId: info.HisPatientId,
  2934. PatientDiagnosis: patient_diagnose,
  2935. }
  2936. service.SavePatientPrescriptionInfo(hpInfo)
  2937. //创建步骤表
  2938. finish := models.XtDialysisFinish{
  2939. IsFinish: 1,
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. Status: 1,
  2942. Ctime: time.Now().Unix(),
  2943. Mtime: 0,
  2944. Module: 4,
  2945. RecordDate: info.RecordDate,
  2946. Sourse: 1,
  2947. PatientId: info.PatientId,
  2948. }
  2949. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2950. if dialysisFinish.ID == 0 {
  2951. service.CreateDialysisFinish(finish)
  2952. }
  2953. redis := service.RedisClient()
  2954. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2955. redis.Set(key, "", time.Second)
  2956. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2957. redis.Set(keyOne, "", time.Second)
  2958. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2959. redis.Set(keySeven, "", time.Second)
  2960. defer redis.Close()
  2961. }
  2962. //定义切片
  2963. var adviceList []models.HisDoctorAdviceInfo
  2964. var projectList []models.HisPrescriptionProject
  2965. 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 == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 {
  2966. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2967. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2968. var tempPrescription *models.HisPrescription
  2969. if len(prescriptions) > 0 {
  2970. for _, item := range prescriptions {
  2971. // 开始外部循环的事务
  2972. tx := db.Begin()
  2973. // 在函数结束时处理事务回滚
  2974. defer func() {
  2975. if r := recover(); r != nil {
  2976. tx.Rollback()
  2977. }
  2978. }()
  2979. items := item.(map[string]interface{})
  2980. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2981. utils.ErrorLog("id")
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2983. return
  2984. }
  2985. id := int64(items["id"].(float64))
  2986. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2987. tempPrescription = &new_prescription
  2988. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2989. utils.ErrorLog("type")
  2990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2991. return
  2992. }
  2993. types := int64(items["type"].(float64))
  2994. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2995. utils.ErrorLog("med_type")
  2996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2997. return
  2998. }
  2999. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3000. if med_type == "0" {
  3001. med_type = "14"
  3002. }
  3003. //if order_status == 0 {
  3004. // order_status = 1
  3005. //}
  3006. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3007. utils.ErrorLog("pre_time")
  3008. }
  3009. preTime, _ := items["pre_time"].(string)
  3010. fmt.Println("preTime", preTime)
  3011. timeLayout := "2006-01-02"
  3012. loc, _ := time.LoadLocation("Local")
  3013. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3014. //result := strings.Split(preTime, " ")
  3015. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3016. if err != nil {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. pTime := theTime2.Unix()
  3021. ctime := time.Now().Unix()
  3022. if tempPrescription.ID == 0 {
  3023. prescription := &models.HisPrescription{
  3024. ID: 0,
  3025. PatientId: patient_id,
  3026. UserOrgId: adminInfo.CurrentOrgId,
  3027. RecordDate: recordDateTime,
  3028. Ctime: ctime,
  3029. Mtime: ctime,
  3030. Type: types,
  3031. Modifier: adminInfo.AdminUser.Id,
  3032. Creator: adminInfo.AdminUser.Id,
  3033. Status: 1,
  3034. Doctor: role.UserName,
  3035. HisPatientId: his_patient_id,
  3036. OrderStatus: 1,
  3037. BatchNumber: "",
  3038. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3039. PreTime: pTime,
  3040. PType: p_type,
  3041. MedType: med_type,
  3042. }
  3043. tempPrescription = prescription
  3044. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3045. redis := service.RedisClient()
  3046. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3047. redis.Set(key, "", time.Second)
  3048. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3049. redis.Set(keyOne, "", time.Second)
  3050. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3051. redis.Set(keySeven, "", time.Second)
  3052. defer redis.Close()
  3053. } else {
  3054. tempPrescription.ID = id
  3055. tempPrescription.Type = types
  3056. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3057. tempPrescription.Mtime = time.Now().Unix()
  3058. tempPrescription.Doctor = role.UserName
  3059. //tempPrescription.OrderStatus = order_status
  3060. tempPrescription.PreTime = pTime
  3061. tempPrescription.MedType = med_type
  3062. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3063. redis := service.RedisClient()
  3064. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3065. redis.Set(key, "", time.Second)
  3066. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3067. redis.Set(keyOne, "", time.Second)
  3068. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3069. redis.Set(keySeven, "", time.Second)
  3070. defer redis.Close()
  3071. }
  3072. //service.SaveHisPrescription(prescription)
  3073. //更改患者挂号状态
  3074. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3075. fmt.Println("更改失败", err2)
  3076. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3077. advices := items["advices"].([]interface{})
  3078. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3079. groupNo := int64(0)
  3080. if len(advices) > 0 {
  3081. for _, advice := range advices {
  3082. tx := db.Begin()
  3083. // 在函数结束时处理事务回滚
  3084. defer func() {
  3085. if r := recover(); r != nil {
  3086. tx.Rollback()
  3087. }
  3088. }()
  3089. var s models.HisDoctorAdviceInfo
  3090. s.PrescriptionId = tempPrescription.ID
  3091. s.AdviceType = 2
  3092. s.AdviceDoctor = doctor_id
  3093. s.StopState = 2
  3094. s.ExecutionState = 2
  3095. s.AdviceDate = theTime3.Unix()
  3096. s.Status = 1
  3097. s.UserOrgId = adminInfo.CurrentOrgId
  3098. s.RecordDate = theTime3.Unix()
  3099. s.StartTime = tempPrescription.PreTime
  3100. s.Groupno = groupNo
  3101. s.PatientId = patient_id
  3102. s.HisPatientId = his_patient_id
  3103. s.StartTime = pTime
  3104. s.IsSettle = 2
  3105. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3106. if errcode > 0 {
  3107. c.ServeFailJSONWithSGJErrorCode(errcode)
  3108. return
  3109. }
  3110. s.StartTime = pTime
  3111. var total_count int64 //处方总库存
  3112. //查询改药品信息
  3113. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3114. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3115. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3116. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3117. total_count += prescribingNumberSeven * medical.MinNumber
  3118. }
  3119. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3120. total_count += prescribingNumberSeven
  3121. }
  3122. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3123. total_count += prescribingNumberSeven
  3124. }
  3125. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3126. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3127. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3128. if s.Price != lastWarehouse.RetailPrice {
  3129. s.Price = lastWarehouse.RetailPrice
  3130. }
  3131. if s.Price == 0 {
  3132. if lastWarehouse.ID == 0 {
  3133. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3134. s.Price = lastWarehouseTwo.RetailPrice
  3135. }
  3136. }
  3137. }
  3138. //查询保存处方出库开关是否打开
  3139. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3140. if s.PatientId != 30038 {
  3141. if drugOutConfig.IsOpen == 1 {
  3142. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3143. // 查询该药品最后一次出库记录
  3144. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3145. var is_user_total int64
  3146. var no_user_total int64
  3147. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3148. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3149. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3150. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3151. }
  3152. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3153. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3154. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3155. no_user_total += prescribingNumberSevenTy
  3156. }
  3157. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3158. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3159. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3160. no_user_total += prescribingNumberSevenTy
  3161. }
  3162. if len(druginfo) > 0 {
  3163. for _, it := range druginfo {
  3164. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3165. it.Count = it.Count * drug.MinNumber
  3166. is_user_total += it.Count
  3167. }
  3168. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3169. is_user_total += it.Count
  3170. }
  3171. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3172. is_user_total += it.Count
  3173. }
  3174. }
  3175. }
  3176. //fmt.Println("药品名称----------------------", drug.DrugName)
  3177. //fmt.Println("药品名称----------------------", drug.IsUse)
  3178. //fmt.Println("is_user_total-------------------------", is_user_total)
  3179. //fmt.Println("no_user_total-------------------------", no_user_total)
  3180. if is_user_total != no_user_total {
  3181. //出库
  3182. if drug.IsUse == 2 {
  3183. creater := adminInfo.AdminUser.Id
  3184. newadviceInfo := &models.HisDoctorAdviceInfo{
  3185. ID: s.ID,
  3186. UserOrgId: s.UserOrgId,
  3187. PatientId: s.PatientId,
  3188. HisPatientId: s.HisPatientId,
  3189. AdviceType: s.AdviceType,
  3190. AdviceDate: s.AdviceDate,
  3191. StartTime: s.StartTime,
  3192. AdviceName: s.AdviceName,
  3193. AdviceDesc: s.AdviceDesc,
  3194. ReminderDate: s.ReminderDate,
  3195. SingleDose: s.SingleDose,
  3196. SingleDoseUnit: s.SingleDoseUnit,
  3197. PrescribingNumber: s.PrescribingNumber,
  3198. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3199. DeliveryWay: s.DeliveryWay,
  3200. ExecutionFrequency: s.ExecutionFrequency,
  3201. AdviceDoctor: s.AdviceDoctor,
  3202. Status: s.Status,
  3203. CreatedTime: s.CreatedTime,
  3204. UpdatedTime: s.UpdatedTime,
  3205. AdviceAffirm: s.AdviceAffirm,
  3206. Remark: s.Remark,
  3207. StopTime: s.StopTime,
  3208. StopReason: s.StopReason,
  3209. StopDoctor: s.StopDoctor,
  3210. StopState: s.StopState,
  3211. ParentId: s.ParentId,
  3212. ExecutionTime: s.ExecutionTime,
  3213. ExecutionStaff: s.ExecutionStaff,
  3214. ExecutionState: s.ExecutionState,
  3215. Checker: s.Checker,
  3216. RecordDate: s.RecordDate,
  3217. DialysisOrderId: s.DialysisOrderId,
  3218. CheckTime: s.CheckTime,
  3219. CheckState: s.CheckState,
  3220. DrugSpec: s.DrugSpec,
  3221. DrugSpecUnit: s.DrugSpecUnit,
  3222. Groupno: s.Groupno,
  3223. RemindType: s.RemindType,
  3224. FrequencyType: s.FrequencyType,
  3225. DayCount: s.DayCount,
  3226. WeekDay: s.WeekDay,
  3227. TemplateId: s.TemplateId,
  3228. Modifier: s.Modifier,
  3229. DrugId: s.DrugId,
  3230. Price: s.Price,
  3231. PrescriptionId: s.PrescriptionId,
  3232. MedListCodg: s.MedListCodg,
  3233. FeedetlSn: s.FeedetlSn,
  3234. Day: s.DayCount,
  3235. ChildDoctorAdvice: nil,
  3236. Drug: models.Drug{},
  3237. Diagnosis: s.Diagnosis,
  3238. Way: s.Way,
  3239. HospApprFlag: s.HospApprFlag,
  3240. LmtUsedFlag: s.LmtUsedFlag,
  3241. HisOrderInfo: models.HisOrderInfo{},
  3242. IsMedicine: s.IsMedicine,
  3243. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3244. Child: nil,
  3245. IsSettle: s.IsSettle,
  3246. IsMobile: s.IsMobile,
  3247. IsSelfDrug: s.IsSelfDrug,
  3248. DrugWayCount: s.DrugWayCount,
  3249. }
  3250. var history_count int64
  3251. var local_count int64
  3252. //查找已经开过的医嘱信息
  3253. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3254. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3255. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3256. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3257. local_count += prescribingNumberSevenTy * drug.MinNumber
  3258. }
  3259. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3260. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3261. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3262. local_count += prescribingNumberSevenTy
  3263. }
  3264. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3265. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3266. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3267. local_count += prescribingNumberSevenTy
  3268. }
  3269. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3270. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3271. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3272. history_count += prescribingNumberSevenTy * drug.MinNumber
  3273. }
  3274. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3275. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3276. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3277. history_count += prescribingNumberSevenTy
  3278. }
  3279. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3280. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3281. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3282. history_count += prescribingNumberSevenTy
  3283. }
  3284. //如果当前出库数量大于历史出库数量则需要出库
  3285. if local_count > history_count {
  3286. //按最小单位出库
  3287. var cha_count = local_count - history_count
  3288. newadviceInfo.PrescribingNumber = float64(cha_count)
  3289. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3290. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3291. }
  3292. //如果当前出库数量小于历史出库数量则需要退库
  3293. if local_count < history_count {
  3294. var cha_count = history_count - local_count
  3295. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3296. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3297. }
  3298. if local_count == history_count {
  3299. if is_user_total == 0 {
  3300. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3301. }
  3302. }
  3303. }
  3304. //更新字典里面的库存
  3305. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3306. var sum_count int64
  3307. for _, its := range stockInfo {
  3308. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3309. if its.MaxUnit == baseDrug.MaxUnit {
  3310. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3311. }
  3312. sum_count += its.StockMaxNumber + its.StockMinNumber
  3313. }
  3314. //更新基础库存
  3315. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3316. //剩余库存
  3317. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3318. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3319. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3320. //创建医嘱
  3321. service.CreateHisDoctorAdviceOne(&s, tx)
  3322. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3323. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3324. if len(outInfoTwo) > 0 {
  3325. for _, item := range outInfoTwo {
  3326. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3327. }
  3328. }
  3329. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3330. if len(drugAutoDetail) > 0 {
  3331. for _, item := range drugAutoDetail {
  3332. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. //记录日志
  3339. byterequest, _ := json.Marshal(s)
  3340. adviceLog := models.XtDoctorAdviceLog{
  3341. UserOrgId: s.UserOrgId,
  3342. PatientId: s.PatientId,
  3343. AdminUserId: adminInfo.AdminUser.Id,
  3344. Module: 1,
  3345. ErrLog: string(byterequest),
  3346. Status: 1,
  3347. Ctime: time.Now().Unix(),
  3348. Mtime: 0,
  3349. Source: "电脑端新建his医嘱",
  3350. RecordDate: s.AdviceDate,
  3351. }
  3352. service.CreateDoctorAdviceLog(adviceLog)
  3353. //存储切片中
  3354. adviceList = append(adviceList, s)
  3355. redis := service.RedisClient()
  3356. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3357. redis.Set(key, "", time.Second)
  3358. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3359. redis.Set(keyOne, "", time.Second)
  3360. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3361. redis.Set(keySeven, "", time.Second)
  3362. var randNum int
  3363. randNum = rand.Intn(10000) + 1000
  3364. timestamp := time.Now().Unix()
  3365. tempTime := time.Unix(timestamp, 0)
  3366. timeFormat := tempTime.Format("20060102150405")
  3367. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3368. if s.UserOrgId != 10206 {
  3369. if s.ID == 0 {
  3370. //查询改药品是否已经停用
  3371. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3372. if base.ID > 0 {
  3373. tx.Rollback()
  3374. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3375. return
  3376. }
  3377. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3378. if drugMedical.SumCount == 0 {
  3379. tx.Rollback()
  3380. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3381. return
  3382. }
  3383. }
  3384. }
  3385. //赤峰
  3386. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3387. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3388. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3389. if info.RetailPrice > 0 {
  3390. if s.DeliveryWay == "口服" {
  3391. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3392. s.Price = drug.RetailPrice
  3393. }
  3394. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3395. s.Price = info.RetailPrice
  3396. }
  3397. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3398. s.Price = info.RetailPrice
  3399. }
  3400. }
  3401. }
  3402. }
  3403. service.CreateHisDoctorAdviceOne(&s, tx)
  3404. tx.Commit()
  3405. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3406. redis.Set(keySix, "", time.Second)
  3407. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3408. redis.Set(keyFive, "", time.Second)
  3409. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3410. redis.Set(keyEight, "", time.Second)
  3411. defer redis.Close()
  3412. }
  3413. }
  3414. }
  3415. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3416. projects := items["project"].([]interface{})
  3417. if len(projects) > 0 {
  3418. for _, project := range projects {
  3419. tx := db.Begin()
  3420. // 在函数结束时处理事务回滚
  3421. defer func() {
  3422. if r := recover(); r != nil {
  3423. tx.Rollback()
  3424. }
  3425. }()
  3426. var p models.HisPrescriptionProject
  3427. p.PrescriptionId = tempPrescription.ID
  3428. p.PatientId = patient_id
  3429. p.RecordDate = theTime3.Unix()
  3430. p.Doctor = doctor_id
  3431. p.UserOrgId = adminInfo.CurrentOrgId
  3432. p.HisPatientId = his_patient_id
  3433. p.Status = 1
  3434. p.StartTime = pTime
  3435. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3436. if errcode > 0 {
  3437. tx.Rollback()
  3438. c.ServeFailJSONWithSGJErrorCode(errcode)
  3439. return
  3440. }
  3441. if p.ID == 0 {
  3442. p.IsOut = 2
  3443. }
  3444. if p.ID > 0 {
  3445. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3446. p.IsOut = projectDetail.IsOut
  3447. }
  3448. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3449. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3450. if p.Type == 3 {
  3451. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3452. if p.Price != lastWarehouse.PackingPrice {
  3453. p.Price = lastWarehouse.PackingPrice
  3454. }
  3455. if p.Price == 0 {
  3456. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3457. p.Price = lastWarehouseTwo.PackingPrice
  3458. }
  3459. if p.Unit == "" {
  3460. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3461. p.Unit = goodInfoOne.PackingUnit
  3462. }
  3463. }
  3464. }
  3465. if adminInfo.CurrentOrgId != 10206 {
  3466. if p.Type == 3 {
  3467. if p.ID == 0 {
  3468. //查询该耗材是否停用
  3469. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3470. //表示该耗材已经停用,不能保存
  3471. if goodInfoSeven.ID == 0 {
  3472. tx.Rollback()
  3473. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3474. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3475. return
  3476. }
  3477. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3478. if goodInfoOne.SumCount == 0 {
  3479. tx.Rollback()
  3480. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3481. return
  3482. }
  3483. }
  3484. }
  3485. }
  3486. //查询保存耗材出库开关是否打开
  3487. if p.PatientId != 30038 {
  3488. //用机构ID区分
  3489. if adminInfo.CurrentOrgId != 10721 && adminInfo.CurrentOrgId != 10164 {
  3490. if goodOutConfig.IsOpen == 1 {
  3491. //耗材出库
  3492. if p.Type == 3 {
  3493. //对比当前数据和历史出库数据
  3494. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3495. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3496. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3497. //如果当前处方数量大于历史数据,则需要出库
  3498. if nowCount > historyCount {
  3499. var cha_count int64
  3500. cha_count = nowCount - historyCount
  3501. timeStr := time.Now().Format("2006-01-02")
  3502. timeArr := strings.Split(timeStr, "-")
  3503. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3504. total = total + 1
  3505. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3506. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3507. number = number + total
  3508. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3509. operation_time := time.Now().Unix()
  3510. creater := c.GetAdminUserInfo().AdminUser.Id
  3511. recordDateStr := time.Now().Format("2006-01-02")
  3512. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3513. nowtime := recordDate.Unix()
  3514. warehouseOut := models.WarehouseOut{
  3515. WarehouseOutOrderNumber: warehousing_out_order,
  3516. OperationTime: operation_time,
  3517. OrgId: adminInfo.CurrentOrgId,
  3518. Creater: creater,
  3519. Ctime: time.Now().Unix(),
  3520. Status: 1,
  3521. WarehouseOutTime: nowtime,
  3522. Type: 1,
  3523. StorehouseId: storeConfig.StorehouseOutInfo,
  3524. IsCheck: 1,
  3525. IsSys: 1,
  3526. }
  3527. //查询是否生成出库单
  3528. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3529. if out.ID == 0 {
  3530. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3531. }
  3532. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3533. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3534. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3535. dialyPrepareOne := models.DialysisBeforePrepare{
  3536. GoodTypeId: goodObj.GoodTypeId,
  3537. GoodId: p.ProjectId,
  3538. PatientId: p.PatientId,
  3539. RecordDate: p.RecordDate,
  3540. UserOrgId: adminInfo.CurrentOrgId,
  3541. Count: cha_count,
  3542. Ctime: time.Now().Unix(),
  3543. Creater: creater,
  3544. Status: 1,
  3545. StorehouseId: houseConfig.StorehouseOutInfo,
  3546. ProjectId: p.ID,
  3547. }
  3548. //出库
  3549. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3550. }
  3551. //如果当前处方数量小于历史数据,怎需要退库
  3552. if nowCount < historyCount {
  3553. var cha_count int64
  3554. cha_count = historyCount - nowCount
  3555. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3556. creater := c.GetAdminUserInfo().AdminUser.Id
  3557. newPrescriptionProject := &models.HisPrescriptionProject{
  3558. ID: p.ID,
  3559. ProjectId: p.ProjectId,
  3560. Price: p.Price,
  3561. UserOrgId: p.UserOrgId,
  3562. Status: 1,
  3563. Ctime: time.Now().Unix(),
  3564. Mtime: time.Now().Unix(),
  3565. PatientId: p.PatientId,
  3566. HisPatientId: p.HisPatientId,
  3567. RecordDate: p.RecordDate,
  3568. PrescriptionId: p.PrescriptionId,
  3569. Count: p.Count,
  3570. FeedetlSn: p.FeedetlSn,
  3571. MedListCodg: p.MedListCodg,
  3572. SingleDose: p.SingleDose,
  3573. DeliveryWay: p.DeliveryWay,
  3574. ExecutionFrequency: p.ExecutionFrequency,
  3575. Day: p.Day,
  3576. HisProject: models.HisProject{},
  3577. GoodInfo: models.GoodInfo{},
  3578. Remark: p.Remark,
  3579. Unit: p.Unit,
  3580. Type: p.Type,
  3581. Doctor: p.Doctor,
  3582. ExecutionTime: p.ExecutionTime,
  3583. ExecutionStaff: p.ExecutionStaff,
  3584. ExecutionState: p.ExecutionState,
  3585. CheckTime: p.CheckTime,
  3586. CheckState: p.CheckState,
  3587. Checker: p.Checker,
  3588. StartTime: p.StartTime,
  3589. TeamId: p.TeamId,
  3590. XtHisProjectTeam: models.XtHisProjectTeam{},
  3591. FrequencyType: p.FrequencyType,
  3592. DayCount: p.DayCount,
  3593. WeekDay: p.WeekDay,
  3594. IsCheckTeam: p.IsCheckTeam,
  3595. HisOrderInfo: models.HisOrderInfo{},
  3596. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3597. IsOut: p.IsOut,
  3598. YbSyncStatus: p.YbSyncStatus,
  3599. }
  3600. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3601. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3602. }
  3603. if nowCount == historyCount {
  3604. if historyCount == 0 {
  3605. recordDateStr := time.Now().Format("2006-01-02")
  3606. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3607. nowtime := recordDate.Unix()
  3608. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3609. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3610. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3611. creater := c.GetAdminUserInfo().AdminUser.Id
  3612. dialyPrepareOne := models.DialysisBeforePrepare{
  3613. GoodTypeId: goodObj.GoodTypeId,
  3614. GoodId: p.ProjectId,
  3615. PatientId: p.PatientId,
  3616. RecordDate: p.RecordDate,
  3617. UserOrgId: adminInfo.CurrentOrgId,
  3618. Count: nowCount,
  3619. Ctime: time.Now().Unix(),
  3620. Creater: creater,
  3621. Status: 1,
  3622. StorehouseId: houseConfig.StorehouseOutInfo,
  3623. ProjectId: p.ID,
  3624. }
  3625. //出库
  3626. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3627. }
  3628. }
  3629. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3630. //查询历史出库数据
  3631. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3632. var out_count_five int64
  3633. for _, item := range flowGood {
  3634. out_count_five += item.Count
  3635. }
  3636. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3637. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3638. if out_count_five != parseIntCount {
  3639. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3640. detail := models.AutomaticReduceDetail{
  3641. WarehouseOutId: 0,
  3642. WarehouseOutOrderNumber: "",
  3643. PatientId: p.PatientId,
  3644. Ctime: time.Now().Unix(),
  3645. Mtime: 0,
  3646. Status: 1,
  3647. RecordTime: p.RecordDate,
  3648. OrgId: p.UserOrgId,
  3649. GoodId: p.ProjectId,
  3650. GoodTypeId: 0,
  3651. Count: parseIntCount,
  3652. Type: 0,
  3653. ProjectId: lastHisProject.ID,
  3654. StorehouseId: 0,
  3655. }
  3656. service.CreateNewAutoDetail(detail, tx)
  3657. }
  3658. // //查询耗材最后一次出库记录
  3659. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3660. // //查询默认出库仓库库存
  3661. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3662. // if len(wareOut) > 0 {
  3663. //
  3664. // for _, it := range wareOut {
  3665. // //回退库存
  3666. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3667. //
  3668. // //删除出库记录
  3669. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3670. //
  3671. // }
  3672. // }
  3673. //
  3674. // timeStr := time.Now().Format("2006-01-02")
  3675. // timeArr := strings.Split(timeStr, "-")
  3676. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3677. //
  3678. // total = total + 1
  3679. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3680. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3681. // number = number + total
  3682. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3683. //
  3684. // operation_time := time.Now().Unix()
  3685. // creater := c.GetAdminUserInfo().AdminUser.Id
  3686. //
  3687. // recordDateStr := time.Now().Format("2006-01-02")
  3688. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3689. // nowtime := recordDate.Unix()
  3690. // warehouseOut := models.WarehouseOut{
  3691. // WarehouseOutOrderNumber: warehousing_out_order,
  3692. // OperationTime: operation_time,
  3693. // OrgId: adminInfo.CurrentOrgId,
  3694. // Creater: creater,
  3695. // Ctime: time.Now().Unix(),
  3696. // Status: 1,
  3697. // WarehouseOutTime: nowtime,
  3698. // Type: 1,
  3699. // StorehouseId: storeConfig.StorehouseOutInfo,
  3700. // IsCheck: 1,
  3701. // IsSys: 1,
  3702. // }
  3703. // //查询是否生成出库单
  3704. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3705. // if out.ID == 0 {
  3706. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3707. // }
  3708. //
  3709. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3710. //
  3711. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3712. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3713. //
  3714. // dialyPrepareOne := models.DialysisBeforePrepare{
  3715. // GoodTypeId: goodObj.GoodTypeId,
  3716. // GoodId: p.ProjectId,
  3717. // PatientId: p.PatientId,
  3718. // RecordDate: p.RecordDate,
  3719. // UserOrgId: adminInfo.CurrentOrgId,
  3720. // Count: parseIntCount,
  3721. // Ctime: time.Now().Unix(),
  3722. // Creater: creater,
  3723. // Status: 1,
  3724. // StorehouseId: houseConfig.StorehouseOutInfo,
  3725. // ProjectId: lastHisProject.ID,
  3726. // }
  3727. // //判断是否是零用耗材(非零用)
  3728. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3729. //
  3730. // //查询历史出库数据
  3731. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3732. // var out_count int64
  3733. // for _, item := range flowGood {
  3734. // out_count += item.Count
  3735. // }
  3736. // //如果历史数和当前数据不想等才进行退库出库
  3737. // if out_count != parseIntCount {
  3738. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3739. //
  3740. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3741. // detail := models.AutomaticReduceDetail{
  3742. // WarehouseOutId: 0,
  3743. // WarehouseOutOrderNumber: "",
  3744. // PatientId: p.PatientId,
  3745. // Ctime: time.Now().Unix(),
  3746. // Mtime: 0,
  3747. // Status: 1,
  3748. // RecordTime: p.RecordDate,
  3749. // OrgId: p.UserOrgId,
  3750. // GoodId: p.ProjectId,
  3751. // GoodTypeId: 0,
  3752. // Count: parseIntCount,
  3753. // Type: 0,
  3754. // ProjectId: lastHisProject.ID,
  3755. // StorehouseId: 0,
  3756. // }
  3757. //
  3758. // service.CreateNewAutoDetail(detail, tx)
  3759. //
  3760. // //查询剩余库存
  3761. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3762. // var sum_count int64
  3763. // for _, item := range goodList {
  3764. // sum_count += item.StockCount
  3765. // }
  3766. //
  3767. // //更新剩余库存
  3768. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3769. //
  3770. // //耗材
  3771. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3772. //
  3773. // }
  3774. // //判断是否是零用耗材(零用但是是出库耗材)
  3775. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3776. //
  3777. // //查询历史出库数据
  3778. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3779. // var out_count int64
  3780. // for _, item := range flowGood {
  3781. // out_count += item.Count
  3782. // }
  3783. // //如果历史数和当前数据不想等才进行退库出库
  3784. // if out_count != parseIntCount {
  3785. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3786. //
  3787. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3788. // detail := models.AutomaticReduceDetail{
  3789. // WarehouseOutId: 0,
  3790. // WarehouseOutOrderNumber: "",
  3791. // PatientId: p.PatientId,
  3792. // Ctime: time.Now().Unix(),
  3793. // Mtime: 0,
  3794. // Status: 1,
  3795. // RecordTime: p.RecordDate,
  3796. // OrgId: p.UserOrgId,
  3797. // GoodId: p.ProjectId,
  3798. // GoodTypeId: 0,
  3799. // Count: parseIntCount,
  3800. // Type: 0,
  3801. // ProjectId: p.ID,
  3802. // StorehouseId: 0,
  3803. // }
  3804. //
  3805. // service.CreateNewAutoDetail(detail, tx)
  3806. //
  3807. // //查询剩余库存
  3808. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3809. // var sum_count int64
  3810. // for _, item := range goodList {
  3811. // sum_count += item.StockCount
  3812. // }
  3813. //
  3814. // //更新剩余库存
  3815. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3816. //
  3817. // //耗材
  3818. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3819. // }
  3820. //
  3821. // }
  3822. //
  3823. // }
  3824. //
  3825. //}
  3826. //记录日志
  3827. byterequest, _ := json.Marshal(p)
  3828. adviceLog := models.XtDoctorAdviceLog{
  3829. UserOrgId: p.UserOrgId,
  3830. PatientId: p.PatientId,
  3831. AdminUserId: adminInfo.AdminUser.Id,
  3832. Module: 1,
  3833. ErrLog: string(byterequest),
  3834. Status: 1,
  3835. Ctime: time.Now().Unix(),
  3836. Mtime: 0,
  3837. Source: "电脑端新建his项目",
  3838. RecordDate: p.RecordDate,
  3839. }
  3840. service.CreateDoctorAdviceLog(adviceLog)
  3841. projectList = append(projectList, p)
  3842. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3843. //新增或者编辑项目,修改对应的标签数据
  3844. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3845. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3846. var label models.HisLabelPrintInfo
  3847. project, _ := service.GetProjectDetail(p.ProjectId)
  3848. if project.CostClassify == 3 { //类别为检验检查
  3849. if p.TeamId > 0 { //检验检查组套
  3850. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3851. if tempLabel.ID == 0 {
  3852. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3853. label.Number = tempPrescription.PrescriptionNumber
  3854. label.ProjectId = project.ID
  3855. label.Status = 1
  3856. label.IsPrint = 2
  3857. label.DoctorId = info.DoctorId
  3858. label.UserOrgId = p.UserOrgId
  3859. label.PatientId = patient_id
  3860. label.RecordDate = recordDateTime
  3861. label.Ctime = time.Now().Unix()
  3862. label.Mtime = time.Now().Unix()
  3863. label.ItemId = p.TeamId
  3864. label.FeedetlSn = p.FeedetlSn
  3865. label.PProjectId = p.ID
  3866. label.ProjectName = team.ProjectTeam
  3867. label.PatientName = patient.Name
  3868. service.CreateNewHisLabelRecord(&label, tx)
  3869. }
  3870. } else { //单条检验检查项目
  3871. label.Number = tempPrescription.PrescriptionNumber
  3872. label.ProjectId = project.ID
  3873. label.Status = 1
  3874. label.DoctorId = info.DoctorId
  3875. label.UserOrgId = p.UserOrgId
  3876. label.PatientId = patient_id
  3877. label.RecordDate = recordDateTime
  3878. label.IsPrint = 2
  3879. label.Ctime = time.Now().Unix()
  3880. label.Mtime = time.Now().Unix()
  3881. label.FeedetlSn = p.FeedetlSn
  3882. label.PProjectId = p.ID
  3883. label.ItemId = p.TeamId
  3884. label.ProjectName = project.ProjectName
  3885. label.PatientName = patient.Name
  3886. service.CreateNewHisLabelRecord(&label, tx)
  3887. }
  3888. }
  3889. }
  3890. }
  3891. }
  3892. }
  3893. }
  3894. if adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10164 {
  3895. //耗材出库
  3896. if p.Type == 3 {
  3897. //对比当前数据和历史出库数据
  3898. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3899. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3900. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3901. //如果当前处方数量大于历史数据,则需要出库
  3902. if nowCount > historyCount {
  3903. var cha_count int64
  3904. cha_count = nowCount - historyCount
  3905. timeStr := time.Now().Format("2006-01-02")
  3906. timeArr := strings.Split(timeStr, "-")
  3907. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3908. total = total + 1
  3909. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3910. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3911. number = number + total
  3912. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3913. operation_time := time.Now().Unix()
  3914. creater := c.GetAdminUserInfo().AdminUser.Id
  3915. recordDateStr := time.Now().Format("2006-01-02")
  3916. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3917. nowtime := recordDate.Unix()
  3918. warehouseOut := models.WarehouseOut{
  3919. WarehouseOutOrderNumber: warehousing_out_order,
  3920. OperationTime: operation_time,
  3921. OrgId: adminInfo.CurrentOrgId,
  3922. Creater: creater,
  3923. Ctime: time.Now().Unix(),
  3924. Status: 1,
  3925. WarehouseOutTime: nowtime,
  3926. Type: 1,
  3927. StorehouseId: storeConfig.StorehouseOutInfo,
  3928. IsCheck: 1,
  3929. IsSys: 1,
  3930. }
  3931. //查询是否生成出库单
  3932. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3933. if out.ID == 0 {
  3934. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3935. }
  3936. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3937. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3938. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3939. dialyPrepareOne := models.DialysisBeforePrepare{
  3940. GoodTypeId: goodObj.GoodTypeId,
  3941. GoodId: p.ProjectId,
  3942. PatientId: p.PatientId,
  3943. RecordDate: p.RecordDate,
  3944. UserOrgId: adminInfo.CurrentOrgId,
  3945. Count: cha_count,
  3946. Ctime: time.Now().Unix(),
  3947. Creater: creater,
  3948. Status: 1,
  3949. StorehouseId: houseConfig.StorehouseOutInfo,
  3950. ProjectId: p.ID,
  3951. }
  3952. //出库
  3953. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3954. }
  3955. //如果当前处方数量小于历史数据,怎需要退库
  3956. if nowCount < historyCount {
  3957. var cha_count int64
  3958. cha_count = historyCount - nowCount
  3959. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3960. creater := c.GetAdminUserInfo().AdminUser.Id
  3961. newPrescriptionProject := &models.HisPrescriptionProject{
  3962. ID: p.ID,
  3963. ProjectId: p.ProjectId,
  3964. Price: p.Price,
  3965. UserOrgId: p.UserOrgId,
  3966. Status: 1,
  3967. Ctime: time.Now().Unix(),
  3968. Mtime: time.Now().Unix(),
  3969. PatientId: p.PatientId,
  3970. HisPatientId: p.HisPatientId,
  3971. RecordDate: p.RecordDate,
  3972. PrescriptionId: p.PrescriptionId,
  3973. Count: p.Count,
  3974. FeedetlSn: p.FeedetlSn,
  3975. MedListCodg: p.MedListCodg,
  3976. SingleDose: p.SingleDose,
  3977. DeliveryWay: p.DeliveryWay,
  3978. ExecutionFrequency: p.ExecutionFrequency,
  3979. Day: p.Day,
  3980. HisProject: models.HisProject{},
  3981. GoodInfo: models.GoodInfo{},
  3982. Remark: p.Remark,
  3983. Unit: p.Unit,
  3984. Type: p.Type,
  3985. Doctor: p.Doctor,
  3986. ExecutionTime: p.ExecutionTime,
  3987. ExecutionStaff: p.ExecutionStaff,
  3988. ExecutionState: p.ExecutionState,
  3989. CheckTime: p.CheckTime,
  3990. CheckState: p.CheckState,
  3991. Checker: p.Checker,
  3992. StartTime: p.StartTime,
  3993. TeamId: p.TeamId,
  3994. XtHisProjectTeam: models.XtHisProjectTeam{},
  3995. FrequencyType: p.FrequencyType,
  3996. DayCount: p.DayCount,
  3997. WeekDay: p.WeekDay,
  3998. IsCheckTeam: p.IsCheckTeam,
  3999. HisOrderInfo: models.HisOrderInfo{},
  4000. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4001. IsOut: p.IsOut,
  4002. YbSyncStatus: p.YbSyncStatus,
  4003. }
  4004. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4005. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4006. }
  4007. if nowCount == historyCount {
  4008. if historyCount == 0 {
  4009. recordDateStr := time.Now().Format("2006-01-02")
  4010. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4011. nowtime := recordDate.Unix()
  4012. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4013. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4014. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4015. creater := c.GetAdminUserInfo().AdminUser.Id
  4016. dialyPrepareOne := models.DialysisBeforePrepare{
  4017. GoodTypeId: goodObj.GoodTypeId,
  4018. GoodId: p.ProjectId,
  4019. PatientId: p.PatientId,
  4020. RecordDate: p.RecordDate,
  4021. UserOrgId: adminInfo.CurrentOrgId,
  4022. Count: nowCount,
  4023. Ctime: time.Now().Unix(),
  4024. Creater: creater,
  4025. Status: 1,
  4026. StorehouseId: houseConfig.StorehouseOutInfo,
  4027. ProjectId: p.ID,
  4028. }
  4029. //出库
  4030. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4031. }
  4032. }
  4033. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4034. //查询历史出库数据
  4035. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4036. var out_count_five int64
  4037. for _, item := range flowGood {
  4038. out_count_five += item.Count
  4039. }
  4040. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4041. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4042. if out_count_five != parseIntCount {
  4043. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4044. detail := models.AutomaticReduceDetail{
  4045. WarehouseOutId: 0,
  4046. WarehouseOutOrderNumber: "",
  4047. PatientId: p.PatientId,
  4048. Ctime: time.Now().Unix(),
  4049. Mtime: 0,
  4050. Status: 1,
  4051. RecordTime: p.RecordDate,
  4052. OrgId: p.UserOrgId,
  4053. GoodId: p.ProjectId,
  4054. GoodTypeId: 0,
  4055. Count: parseIntCount,
  4056. Type: 0,
  4057. ProjectId: lastHisProject.ID,
  4058. StorehouseId: 0,
  4059. }
  4060. service.CreateNewAutoDetail(detail, tx)
  4061. }
  4062. // //查询耗材最后一次出库记录
  4063. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4064. // //查询默认出库仓库库存
  4065. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4066. // if len(wareOut) > 0 {
  4067. //
  4068. // for _, it := range wareOut {
  4069. // //回退库存
  4070. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4071. //
  4072. // //删除出库记录
  4073. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4074. //
  4075. // }
  4076. // }
  4077. //
  4078. // timeStr := time.Now().Format("2006-01-02")
  4079. // timeArr := strings.Split(timeStr, "-")
  4080. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4081. //
  4082. // total = total + 1
  4083. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4084. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4085. // number = number + total
  4086. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4087. //
  4088. // operation_time := time.Now().Unix()
  4089. // creater := c.GetAdminUserInfo().AdminUser.Id
  4090. //
  4091. // recordDateStr := time.Now().Format("2006-01-02")
  4092. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4093. // nowtime := recordDate.Unix()
  4094. // warehouseOut := models.WarehouseOut{
  4095. // WarehouseOutOrderNumber: warehousing_out_order,
  4096. // OperationTime: operation_time,
  4097. // OrgId: adminInfo.CurrentOrgId,
  4098. // Creater: creater,
  4099. // Ctime: time.Now().Unix(),
  4100. // Status: 1,
  4101. // WarehouseOutTime: nowtime,
  4102. // Type: 1,
  4103. // StorehouseId: storeConfig.StorehouseOutInfo,
  4104. // IsCheck: 1,
  4105. // IsSys: 1,
  4106. // }
  4107. // //查询是否生成出库单
  4108. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4109. // if out.ID == 0 {
  4110. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4111. // }
  4112. //
  4113. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4114. //
  4115. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4116. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4117. //
  4118. // dialyPrepareOne := models.DialysisBeforePrepare{
  4119. // GoodTypeId: goodObj.GoodTypeId,
  4120. // GoodId: p.ProjectId,
  4121. // PatientId: p.PatientId,
  4122. // RecordDate: p.RecordDate,
  4123. // UserOrgId: adminInfo.CurrentOrgId,
  4124. // Count: parseIntCount,
  4125. // Ctime: time.Now().Unix(),
  4126. // Creater: creater,
  4127. // Status: 1,
  4128. // StorehouseId: houseConfig.StorehouseOutInfo,
  4129. // ProjectId: lastHisProject.ID,
  4130. // }
  4131. // //判断是否是零用耗材(非零用)
  4132. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4133. //
  4134. // //查询历史出库数据
  4135. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4136. // var out_count int64
  4137. // for _, item := range flowGood {
  4138. // out_count += item.Count
  4139. // }
  4140. // //如果历史数和当前数据不想等才进行退库出库
  4141. // if out_count != parseIntCount {
  4142. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4143. //
  4144. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4145. // detail := models.AutomaticReduceDetail{
  4146. // WarehouseOutId: 0,
  4147. // WarehouseOutOrderNumber: "",
  4148. // PatientId: p.PatientId,
  4149. // Ctime: time.Now().Unix(),
  4150. // Mtime: 0,
  4151. // Status: 1,
  4152. // RecordTime: p.RecordDate,
  4153. // OrgId: p.UserOrgId,
  4154. // GoodId: p.ProjectId,
  4155. // GoodTypeId: 0,
  4156. // Count: parseIntCount,
  4157. // Type: 0,
  4158. // ProjectId: lastHisProject.ID,
  4159. // StorehouseId: 0,
  4160. // }
  4161. //
  4162. // service.CreateNewAutoDetail(detail, tx)
  4163. //
  4164. // //查询剩余库存
  4165. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4166. // var sum_count int64
  4167. // for _, item := range goodList {
  4168. // sum_count += item.StockCount
  4169. // }
  4170. //
  4171. // //更新剩余库存
  4172. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4173. //
  4174. // //耗材
  4175. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4176. //
  4177. // }
  4178. // //判断是否是零用耗材(零用但是是出库耗材)
  4179. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4180. //
  4181. // //查询历史出库数据
  4182. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4183. // var out_count int64
  4184. // for _, item := range flowGood {
  4185. // out_count += item.Count
  4186. // }
  4187. // //如果历史数和当前数据不想等才进行退库出库
  4188. // if out_count != parseIntCount {
  4189. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4190. //
  4191. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4192. // detail := models.AutomaticReduceDetail{
  4193. // WarehouseOutId: 0,
  4194. // WarehouseOutOrderNumber: "",
  4195. // PatientId: p.PatientId,
  4196. // Ctime: time.Now().Unix(),
  4197. // Mtime: 0,
  4198. // Status: 1,
  4199. // RecordTime: p.RecordDate,
  4200. // OrgId: p.UserOrgId,
  4201. // GoodId: p.ProjectId,
  4202. // GoodTypeId: 0,
  4203. // Count: parseIntCount,
  4204. // Type: 0,
  4205. // ProjectId: p.ID,
  4206. // StorehouseId: 0,
  4207. // }
  4208. //
  4209. // service.CreateNewAutoDetail(detail, tx)
  4210. //
  4211. // //查询剩余库存
  4212. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4213. // var sum_count int64
  4214. // for _, item := range goodList {
  4215. // sum_count += item.StockCount
  4216. // }
  4217. //
  4218. // //更新剩余库存
  4219. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4220. //
  4221. // //耗材
  4222. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4223. // }
  4224. //
  4225. // }
  4226. //
  4227. // }
  4228. //
  4229. //}
  4230. //记录日志
  4231. byterequest, _ := json.Marshal(p)
  4232. adviceLog := models.XtDoctorAdviceLog{
  4233. UserOrgId: p.UserOrgId,
  4234. PatientId: p.PatientId,
  4235. AdminUserId: adminInfo.AdminUser.Id,
  4236. Module: 1,
  4237. ErrLog: string(byterequest),
  4238. Status: 1,
  4239. Ctime: time.Now().Unix(),
  4240. Mtime: 0,
  4241. Source: "电脑端新建his项目",
  4242. RecordDate: p.RecordDate,
  4243. }
  4244. service.CreateDoctorAdviceLog(adviceLog)
  4245. projectList = append(projectList, p)
  4246. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4247. //新增或者编辑项目,修改对应的标签数据
  4248. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4249. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4250. var label models.HisLabelPrintInfo
  4251. project, _ := service.GetProjectDetail(p.ProjectId)
  4252. if project.CostClassify == 3 { //类别为检验检查
  4253. if p.TeamId > 0 { //检验检查组套
  4254. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4255. if tempLabel.ID == 0 {
  4256. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4257. label.Number = tempPrescription.PrescriptionNumber
  4258. label.ProjectId = project.ID
  4259. label.Status = 1
  4260. label.IsPrint = 2
  4261. label.DoctorId = info.DoctorId
  4262. label.UserOrgId = p.UserOrgId
  4263. label.PatientId = patient_id
  4264. label.RecordDate = recordDateTime
  4265. label.Ctime = time.Now().Unix()
  4266. label.Mtime = time.Now().Unix()
  4267. label.ItemId = p.TeamId
  4268. label.FeedetlSn = p.FeedetlSn
  4269. label.PProjectId = p.ID
  4270. label.ProjectName = team.ProjectTeam
  4271. label.PatientName = patient.Name
  4272. service.CreateNewHisLabelRecord(&label, tx)
  4273. }
  4274. } else { //单条检验检查项目
  4275. label.Number = tempPrescription.PrescriptionNumber
  4276. label.ProjectId = project.ID
  4277. label.Status = 1
  4278. label.DoctorId = info.DoctorId
  4279. label.UserOrgId = p.UserOrgId
  4280. label.PatientId = patient_id
  4281. label.RecordDate = recordDateTime
  4282. label.IsPrint = 2
  4283. label.Ctime = time.Now().Unix()
  4284. label.Mtime = time.Now().Unix()
  4285. label.FeedetlSn = p.FeedetlSn
  4286. label.PProjectId = p.ID
  4287. label.ItemId = p.TeamId
  4288. label.ProjectName = project.ProjectName
  4289. label.PatientName = patient.Name
  4290. service.CreateNewHisLabelRecord(&label, tx)
  4291. }
  4292. }
  4293. }
  4294. }
  4295. }
  4296. }
  4297. }
  4298. //插入检验数据
  4299. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4300. //新增或者编辑项目,修改对应的标签数据
  4301. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4302. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4303. var label models.HisLabelPrintInfo
  4304. project, _ := service.GetProjectDetail(p.ProjectId)
  4305. if project.CostClassify == 3 { //类别为检验检查
  4306. if p.TeamId > 0 { //检验检查组套
  4307. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4308. if tempLabel.ID == 0 {
  4309. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4310. label.Number = tempPrescription.PrescriptionNumber
  4311. label.ProjectId = project.ID
  4312. label.Status = 1
  4313. label.IsPrint = 2
  4314. label.DoctorId = info.DoctorId
  4315. label.UserOrgId = p.UserOrgId
  4316. label.PatientId = patient_id
  4317. label.RecordDate = recordDateTime
  4318. label.Ctime = time.Now().Unix()
  4319. label.Mtime = time.Now().Unix()
  4320. label.ItemId = p.TeamId
  4321. label.FeedetlSn = p.FeedetlSn
  4322. label.PProjectId = p.ID
  4323. label.ProjectName = team.ProjectTeam
  4324. label.PatientName = patient.Name
  4325. service.CreateHisLabelRecord(&label)
  4326. }
  4327. } else { //单条检验检查项目
  4328. label.Number = tempPrescription.PrescriptionNumber
  4329. label.ProjectId = project.ID
  4330. label.Status = 1
  4331. label.DoctorId = info.DoctorId
  4332. label.UserOrgId = p.UserOrgId
  4333. label.PatientId = patient_id
  4334. label.RecordDate = recordDateTime
  4335. label.IsPrint = 2
  4336. label.Ctime = time.Now().Unix()
  4337. label.Mtime = time.Now().Unix()
  4338. label.FeedetlSn = p.FeedetlSn
  4339. label.PProjectId = p.ID
  4340. label.ItemId = p.TeamId
  4341. label.ProjectName = project.ProjectName
  4342. label.PatientName = patient.Name
  4343. service.CreateHisLabelRecord(&label)
  4344. }
  4345. }
  4346. }
  4347. }
  4348. service.CreateNewHisProjectTwo(&p, tx)
  4349. var randNum int
  4350. randNum = rand.Intn(10000) + 1000
  4351. timestamp := time.Now().Unix()
  4352. tempTime := time.Unix(timestamp, 0)
  4353. timeFormat := tempTime.Format("20060102150405")
  4354. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4355. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4356. if goodBase.ID > 0 {
  4357. tx.Rollback()
  4358. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4359. return
  4360. }
  4361. service.CreateNewHisProjectTwo(&p, tx)
  4362. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4363. //查询剩余库存
  4364. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4365. var sum_count int64
  4366. for _, item := range goodList {
  4367. sum_count += item.StockCount
  4368. }
  4369. //更新剩余库存
  4370. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4371. //耗材
  4372. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4373. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4374. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4375. if len(outInfoTwo) > 0 {
  4376. for _, item := range outInfoTwo {
  4377. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4378. }
  4379. }
  4380. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4381. if len(drugAutoDetail) > 0 {
  4382. for _, item := range drugAutoDetail {
  4383. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4384. }
  4385. }
  4386. tx.Commit()
  4387. }
  4388. }
  4389. }
  4390. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4391. // addition := items["addition"].([]interface{})
  4392. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4393. // ctime := time.Now().Unix()
  4394. // mtime := ctime
  4395. // if len(addition) > 0 {
  4396. // for _, item := range addition {
  4397. // var s models.HisAdditionalCharge
  4398. // s.PrescriptionId = tempPrescription.ID
  4399. // s.Status = 1
  4400. // s.UserOrgId = adminInfo.CurrentOrgId
  4401. // s.RecordDate = recordDateTime
  4402. // s.CreatedTime = ctime
  4403. // s.UpdatedTime = mtime
  4404. // s.PatientId = patient_id
  4405. // s.HisPatientId = his_patient_id
  4406. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4407. // if errcode > 0 {
  4408. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4409. // return
  4410. // }
  4411. // service.CreateAdditionalCharge(&s)
  4412. // var randNum int
  4413. // randNum = rand.Intn(10000) + 1000
  4414. // timestamp := time.Now().Unix()
  4415. // tempTime := time.Unix(timestamp, 0)
  4416. // timeFormat := tempTime.Format("20060102150405")
  4417. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4418. // service.CreateAdditionalCharge(&s)
  4419. //
  4420. // }
  4421. // }
  4422. //}
  4423. }
  4424. }
  4425. }
  4426. tx.Commit()
  4427. if err == nil {
  4428. c.ServeSuccessJSON(map[string]interface{}{
  4429. "msg": "保存成功",
  4430. })
  4431. return
  4432. } else {
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4434. return
  4435. }
  4436. } else {
  4437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4439. var tempPrescription *models.HisPrescription
  4440. if len(prescriptions) > 0 {
  4441. for _, item := range prescriptions {
  4442. items := item.(map[string]interface{})
  4443. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4444. utils.ErrorLog("id")
  4445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4446. return
  4447. }
  4448. id := int64(items["id"].(float64))
  4449. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4450. tempPrescription = &new_prescription
  4451. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4452. utils.ErrorLog("type")
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4454. return
  4455. }
  4456. types := int64(items["type"].(float64))
  4457. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4458. utils.ErrorLog("med_type")
  4459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4460. return
  4461. }
  4462. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4463. if med_type == "0" {
  4464. med_type = "14"
  4465. }
  4466. //if order_status == 0 {
  4467. // order_status = 1
  4468. //}
  4469. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4470. utils.ErrorLog("pre_time")
  4471. }
  4472. preTime, _ := items["pre_time"].(string)
  4473. timeLayout := "2006-01-02"
  4474. loc, _ := time.LoadLocation("Local")
  4475. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4476. //result := strings.Split(preTime, " ")
  4477. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4478. if err != nil {
  4479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4480. return
  4481. }
  4482. pTime := theTime2.Unix()
  4483. ctime := time.Now().Unix()
  4484. if tempPrescription.ID == 0 {
  4485. prescription := &models.HisPrescription{
  4486. ID: 0,
  4487. PatientId: patient_id,
  4488. UserOrgId: adminInfo.CurrentOrgId,
  4489. RecordDate: recordDateTime,
  4490. Ctime: ctime,
  4491. Mtime: ctime,
  4492. Type: types,
  4493. Modifier: adminInfo.AdminUser.Id,
  4494. Creator: adminInfo.AdminUser.Id,
  4495. Status: 1,
  4496. Doctor: role.UserName,
  4497. HisPatientId: his_patient_id,
  4498. OrderStatus: 1,
  4499. BatchNumber: "",
  4500. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4501. PreTime: pTime,
  4502. PType: p_type,
  4503. MedType: med_type,
  4504. }
  4505. tempPrescription = prescription
  4506. service.SaveHisPrescription(tempPrescription)
  4507. redis := service.RedisClient()
  4508. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4509. redis.Set(key, "", time.Second)
  4510. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4511. redis.Set(keyOne, "", time.Second)
  4512. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4513. redis.Set(keySeven, "", time.Second)
  4514. defer redis.Close()
  4515. } else {
  4516. tempPrescription.ID = id
  4517. tempPrescription.Type = types
  4518. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4519. tempPrescription.Mtime = time.Now().Unix()
  4520. tempPrescription.Doctor = role.UserName
  4521. //tempPrescription.OrderStatus = order_status
  4522. tempPrescription.PreTime = pTime
  4523. tempPrescription.MedType = med_type
  4524. service.SaveHisPrescription(tempPrescription)
  4525. redis := service.RedisClient()
  4526. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4527. redis.Set(key, "", time.Second)
  4528. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4529. redis.Set(keyOne, "", time.Second)
  4530. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4531. redis.Set(keySeven, "", time.Second)
  4532. defer redis.Close()
  4533. }
  4534. //service.SaveHisPrescription(prescription)
  4535. //更改患者挂号状态
  4536. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4537. fmt.Println("更改失败", err2)
  4538. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4539. advices := items["advices"].([]interface{})
  4540. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4541. groupNo := int64(0)
  4542. if len(advices) > 0 {
  4543. for _, advice := range advices {
  4544. var s models.HisDoctorAdviceInfo
  4545. s.PrescriptionId = tempPrescription.ID
  4546. s.AdviceType = 2
  4547. s.AdviceDoctor = doctor_id
  4548. s.StopState = 2
  4549. s.ExecutionState = 2
  4550. s.AdviceDate = theTime3.Unix()
  4551. s.Status = 1
  4552. s.UserOrgId = adminInfo.CurrentOrgId
  4553. s.RecordDate = theTime3.Unix()
  4554. s.StartTime = tempPrescription.PreTime
  4555. s.Groupno = groupNo
  4556. s.PatientId = patient_id
  4557. s.HisPatientId = his_patient_id
  4558. s.StartTime = pTime
  4559. s.IsSettle = 2
  4560. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4561. if errcode > 0 {
  4562. c.ServeFailJSONWithSGJErrorCode(errcode)
  4563. return
  4564. }
  4565. s.StartTime = pTime
  4566. var total_count int64 //处方总库存
  4567. //查询改药品信息
  4568. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4569. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4570. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4571. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4572. total_count += prescribingNumberSeven * medical.MinNumber
  4573. }
  4574. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4575. total_count += prescribingNumberSeven
  4576. }
  4577. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4578. total_count += prescribingNumberSeven
  4579. }
  4580. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4581. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4582. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4583. if s.Price != lastWarehouse.RetailPrice {
  4584. s.Price = lastWarehouse.RetailPrice
  4585. }
  4586. if s.Price == 0 {
  4587. if lastWarehouse.ID == 0 {
  4588. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4589. s.Price = lastWarehouseTwo.RetailPrice
  4590. }
  4591. }
  4592. }
  4593. if adminInfo.CurrentOrgId != 10206 {
  4594. if s.ID == 0 {
  4595. //查询改药品是否已经停用
  4596. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4597. if base.ID > 0 {
  4598. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4599. return
  4600. }
  4601. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4602. if drugMedical.SumCount == 0 {
  4603. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4604. return
  4605. }
  4606. }
  4607. }
  4608. //赤峰
  4609. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4610. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4611. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4612. if info.RetailPrice > 0 {
  4613. if s.DeliveryWay == "口服" {
  4614. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4615. s.Price = drug.RetailPrice
  4616. }
  4617. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4618. s.Price = info.RetailPrice
  4619. }
  4620. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4621. s.Price = info.RetailPrice
  4622. }
  4623. }
  4624. }
  4625. }
  4626. service.CreateHisDoctorAdvice(&s)
  4627. //记录日志
  4628. byterequest, _ := json.Marshal(s)
  4629. adviceLog := models.XtDoctorAdviceLog{
  4630. UserOrgId: s.UserOrgId,
  4631. PatientId: s.PatientId,
  4632. AdminUserId: adminInfo.AdminUser.Id,
  4633. Module: 1,
  4634. ErrLog: string(byterequest),
  4635. Status: 1,
  4636. Ctime: time.Now().Unix(),
  4637. Mtime: 0,
  4638. Source: "电脑端新建his医嘱",
  4639. RecordDate: s.AdviceDate,
  4640. }
  4641. service.CreateDoctorAdviceLog(adviceLog)
  4642. //存储切片中
  4643. adviceList = append(adviceList, s)
  4644. redis := service.RedisClient()
  4645. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4646. redis.Set(key, "", time.Second)
  4647. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4648. redis.Set(keyOne, "", time.Second)
  4649. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4650. redis.Set(keySeven, "", time.Second)
  4651. var randNum int
  4652. randNum = rand.Intn(10000) + 1000
  4653. timestamp := time.Now().Unix()
  4654. tempTime := time.Unix(timestamp, 0)
  4655. timeFormat := tempTime.Format("20060102150405")
  4656. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4657. service.CreateHisDoctorAdvice(&s)
  4658. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4659. redis.Set(keySix, "", time.Second)
  4660. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4661. redis.Set(keyFive, "", time.Second)
  4662. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4663. redis.Set(keyEight, "", time.Second)
  4664. defer redis.Close()
  4665. }
  4666. }
  4667. }
  4668. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4669. projects := items["project"].([]interface{})
  4670. if len(projects) > 0 {
  4671. for _, project := range projects {
  4672. var p models.HisPrescriptionProject
  4673. p.PrescriptionId = tempPrescription.ID
  4674. p.PatientId = patient_id
  4675. p.RecordDate = theTime3.Unix()
  4676. p.Doctor = doctor_id
  4677. p.UserOrgId = adminInfo.CurrentOrgId
  4678. p.HisPatientId = his_patient_id
  4679. p.Status = 1
  4680. p.StartTime = pTime
  4681. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4682. if errcode > 0 {
  4683. c.ServeFailJSONWithSGJErrorCode(errcode)
  4684. return
  4685. }
  4686. if p.ID == 0 {
  4687. p.IsOut = 2
  4688. }
  4689. if p.ID > 0 {
  4690. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4691. p.IsOut = projectDetail.IsOut
  4692. }
  4693. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4694. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4695. if p.Type == 3 {
  4696. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4697. if p.Price != lastWarehouse.PackingPrice {
  4698. p.Price = lastWarehouse.PackingPrice
  4699. }
  4700. if p.Price == 0 {
  4701. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4702. p.Price = lastWarehouseTwo.PackingPrice
  4703. }
  4704. if p.Unit == "" {
  4705. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4706. p.Unit = goodInfoOne.PackingUnit
  4707. }
  4708. }
  4709. }
  4710. if adminInfo.CurrentOrgId != 10206 {
  4711. if p.Type == 3 {
  4712. if p.ID == 0 {
  4713. //查询该耗材是否停用
  4714. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4715. //表示该耗材已经停用,不能保存
  4716. if goodInfoSeven.ID == 0 {
  4717. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4718. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4719. return
  4720. }
  4721. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4722. if goodInfoOne.SumCount == 0 {
  4723. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4724. return
  4725. }
  4726. }
  4727. }
  4728. }
  4729. service.CreateHisProjectTwo(&p)
  4730. //记录日志
  4731. byterequest, _ := json.Marshal(p)
  4732. adviceLog := models.XtDoctorAdviceLog{
  4733. UserOrgId: p.UserOrgId,
  4734. PatientId: p.PatientId,
  4735. AdminUserId: adminInfo.AdminUser.Id,
  4736. Module: 1,
  4737. ErrLog: string(byterequest),
  4738. Status: 1,
  4739. Ctime: time.Now().Unix(),
  4740. Mtime: 0,
  4741. Source: "电脑端新建his项目",
  4742. RecordDate: p.RecordDate,
  4743. }
  4744. service.CreateDoctorAdviceLog(adviceLog)
  4745. projectList = append(projectList, p)
  4746. var randNum int
  4747. randNum = rand.Intn(10000) + 1000
  4748. timestamp := time.Now().Unix()
  4749. tempTime := time.Unix(timestamp, 0)
  4750. timeFormat := tempTime.Format("20060102150405")
  4751. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4752. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4753. //新增或者编辑项目,修改对应的标签数据
  4754. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4755. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4756. var label models.HisLabelPrintInfo
  4757. project, _ := service.GetProjectDetail(p.ProjectId)
  4758. if project.CostClassify == 3 { //类别为检验检查
  4759. if p.TeamId > 0 { //检验检查组套
  4760. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4761. if tempLabel.ID == 0 {
  4762. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4763. label.Number = tempPrescription.PrescriptionNumber
  4764. label.ProjectId = project.ID
  4765. label.Status = 1
  4766. label.IsPrint = 2
  4767. label.DoctorId = info.DoctorId
  4768. label.UserOrgId = p.UserOrgId
  4769. label.PatientId = patient_id
  4770. label.RecordDate = recordDateTime
  4771. label.Ctime = time.Now().Unix()
  4772. label.Mtime = time.Now().Unix()
  4773. label.ItemId = p.TeamId
  4774. label.FeedetlSn = p.FeedetlSn
  4775. label.PProjectId = p.ID
  4776. label.ProjectName = team.ProjectTeam
  4777. label.PatientName = patient.Name
  4778. service.CreateHisLabelRecord(&label)
  4779. }
  4780. } else { //单条检验检查项目
  4781. label.Number = tempPrescription.PrescriptionNumber
  4782. label.ProjectId = project.ID
  4783. label.Status = 1
  4784. label.DoctorId = info.DoctorId
  4785. label.UserOrgId = p.UserOrgId
  4786. label.PatientId = patient_id
  4787. label.RecordDate = recordDateTime
  4788. label.IsPrint = 2
  4789. label.Ctime = time.Now().Unix()
  4790. label.Mtime = time.Now().Unix()
  4791. label.FeedetlSn = p.FeedetlSn
  4792. label.PProjectId = p.ID
  4793. label.ItemId = p.TeamId
  4794. label.ProjectName = project.ProjectName
  4795. label.PatientName = patient.Name
  4796. service.CreateHisLabelRecord(&label)
  4797. }
  4798. }
  4799. }
  4800. }
  4801. service.SaveHisProjectTwo(&p)
  4802. }
  4803. }
  4804. }
  4805. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4806. // addition := items["addition"].([]interface{})
  4807. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4808. // ctime := time.Now().Unix()
  4809. // mtime := ctime
  4810. // if len(addition) > 0 {
  4811. // for _, item := range addition {
  4812. // var s models.HisAdditionalCharge
  4813. // s.PrescriptionId = tempPrescription.ID
  4814. // s.Status = 1
  4815. // s.UserOrgId = adminInfo.CurrentOrgId
  4816. // s.RecordDate = recordDateTime
  4817. // s.CreatedTime = ctime
  4818. // s.UpdatedTime = mtime
  4819. // s.PatientId = patient_id
  4820. // s.HisPatientId = his_patient_id
  4821. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4822. // if errcode > 0 {
  4823. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4824. // return
  4825. // }
  4826. // service.CreateAdditionalCharge(&s)
  4827. // var randNum int
  4828. // randNum = rand.Intn(10000) + 1000
  4829. // timestamp := time.Now().Unix()
  4830. // tempTime := time.Unix(timestamp, 0)
  4831. // timeFormat := tempTime.Format("20060102150405")
  4832. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4833. // service.CreateAdditionalCharge(&s)
  4834. //
  4835. // }
  4836. // }
  4837. //}
  4838. }
  4839. }
  4840. //查询今日该患者开的药品处方
  4841. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4842. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4843. //药品出库
  4844. if drugOutConfig.IsOpen == 1 {
  4845. for _, item := range hisdoctorlist {
  4846. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4847. // 查询该药品最后一次出库记录
  4848. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4849. if len(druginfo) > 0 {
  4850. //回退库存
  4851. for _, it := range druginfo {
  4852. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4853. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4854. }
  4855. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4856. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4857. }
  4858. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4859. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4860. }
  4861. }
  4862. }
  4863. //删除记录
  4864. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4865. //查询最后一次数据
  4866. if drugOutConfig.IsOpen == 1 {
  4867. //出库
  4868. if drug.IsUse == 2 {
  4869. creater := adminInfo.AdminUser.Id
  4870. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4871. }
  4872. //更新字典里面的库存
  4873. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4874. var sum_count int64
  4875. for _, its := range stockInfo {
  4876. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4877. if its.MaxUnit == baseDrug.MaxUnit {
  4878. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4879. }
  4880. sum_count += its.StockMaxNumber + its.StockMinNumber
  4881. }
  4882. //更新基础库存
  4883. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4884. //剩余库存
  4885. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4886. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4887. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4888. }
  4889. }
  4890. }
  4891. //耗材保存处方出库
  4892. if goodOutConfig.IsOpen == 1 {
  4893. //查询今日耗材出库数量
  4894. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4895. for _, item := range hisgoodlist {
  4896. //查询历史出库数据
  4897. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4898. var out_count_five int64
  4899. for _, item := range flowGood {
  4900. out_count_five += item.Count
  4901. }
  4902. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4903. if out_count_five != parseIntCount {
  4904. //查询耗材最后一次出库记录
  4905. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4906. //查询默认出库仓库库存
  4907. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4908. if len(wareOut) > 0 {
  4909. for _, it := range wareOut {
  4910. //回退库存
  4911. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4912. //删除出库记录
  4913. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4914. }
  4915. }
  4916. timeStr := time.Now().Format("2006-01-02")
  4917. timeArr := strings.Split(timeStr, "-")
  4918. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4919. total = total + 1
  4920. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4921. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4922. number = number + total
  4923. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4924. operation_time := time.Now().Unix()
  4925. creater := c.GetAdminUserInfo().AdminUser.Id
  4926. recordDateStr := time.Now().Format("2006-01-02")
  4927. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4928. nowtime := recordDate.Unix()
  4929. warehouseOut := models.WarehouseOut{
  4930. WarehouseOutOrderNumber: warehousing_out_order,
  4931. OperationTime: operation_time,
  4932. OrgId: adminInfo.CurrentOrgId,
  4933. Creater: creater,
  4934. Ctime: time.Now().Unix(),
  4935. Status: 1,
  4936. WarehouseOutTime: nowtime,
  4937. Type: 1,
  4938. StorehouseId: storeConfig.StorehouseOutInfo,
  4939. IsCheck: 1,
  4940. IsSys: 1,
  4941. }
  4942. //查询是否生成出库单
  4943. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4944. if out.ID == 0 {
  4945. service.AddSigleWarehouseOut(&warehouseOut)
  4946. }
  4947. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4948. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4949. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4950. dialyPrepareOne := models.DialysisBeforePrepare{
  4951. GoodTypeId: goodObj.GoodTypeId,
  4952. GoodId: item.ProjectId,
  4953. PatientId: item.PatientId,
  4954. RecordDate: item.RecordDate,
  4955. UserOrgId: adminInfo.CurrentOrgId,
  4956. Count: parseIntCount,
  4957. Ctime: time.Now().Unix(),
  4958. Creater: creater,
  4959. Status: 1,
  4960. StorehouseId: houseConfig.StorehouseOutInfo,
  4961. ProjectId: item.ID,
  4962. }
  4963. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4964. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4965. //查询历史出库数据
  4966. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4967. var out_count int64
  4968. for _, item := range flowGood {
  4969. out_count += item.Count
  4970. }
  4971. //如果历史数和当前数据不想等才进行退库出库
  4972. if out_count != parseIntCount {
  4973. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4974. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4975. detail := models.AutomaticReduceDetail{
  4976. WarehouseOutId: 0,
  4977. WarehouseOutOrderNumber: "",
  4978. PatientId: item.PatientId,
  4979. Ctime: time.Now().Unix(),
  4980. Mtime: 0,
  4981. Status: 1,
  4982. RecordTime: item.RecordDate,
  4983. OrgId: item.UserOrgId,
  4984. GoodId: item.ProjectId,
  4985. GoodTypeId: 0,
  4986. Count: parseIntCount,
  4987. Type: 0,
  4988. ProjectId: item.ID,
  4989. StorehouseId: 0,
  4990. }
  4991. service.CreateAutoDetail(detail)
  4992. //查询剩余库存
  4993. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4994. var sum_count int64
  4995. for _, item := range goodList {
  4996. sum_count += item.StockCount
  4997. }
  4998. //更新剩余库存
  4999. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5000. //耗材
  5001. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5002. }
  5003. }
  5004. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5005. //查询历史出库数据
  5006. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5007. var out_count int64
  5008. for _, item := range flowGood {
  5009. out_count += item.Count
  5010. }
  5011. //如果历史数和当前数据不想等才进行退库出库
  5012. if out_count != parseIntCount {
  5013. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5014. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5015. detail := models.AutomaticReduceDetail{
  5016. WarehouseOutId: 0,
  5017. WarehouseOutOrderNumber: "",
  5018. PatientId: item.PatientId,
  5019. Ctime: time.Now().Unix(),
  5020. Mtime: 0,
  5021. Status: 1,
  5022. RecordTime: item.RecordDate,
  5023. OrgId: item.UserOrgId,
  5024. GoodId: item.ProjectId,
  5025. GoodTypeId: 0,
  5026. Count: parseIntCount,
  5027. Type: 0,
  5028. ProjectId: item.ID,
  5029. StorehouseId: 0,
  5030. }
  5031. service.CreateAutoDetail(detail)
  5032. //查询剩余库存
  5033. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5034. var sum_count int64
  5035. for _, item := range goodList {
  5036. sum_count += item.StockCount
  5037. }
  5038. //更新剩余库存
  5039. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5040. //耗材
  5041. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5042. }
  5043. }
  5044. }
  5045. }
  5046. }
  5047. ////同步到自备药
  5048. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5049. if selfPrescriptionOpen.IsOpen == 1 {
  5050. timeStr := time.Now().Format("2006-01-02")
  5051. timeArr := strings.Split(timeStr, "-")
  5052. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5053. total = total + 1
  5054. operation_time := time.Now().Unix()
  5055. creater := adminInfo.AdminUser.Id
  5056. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5057. warehousing := models.XtSelfDrugWarehouse{
  5058. WarehousingOrder: warehousing_order,
  5059. OperationTime: operation_time,
  5060. OrgId: adminInfo.CurrentOrgId,
  5061. Creater: creater,
  5062. Ctime: time.Now().Unix(),
  5063. Status: 1,
  5064. WarehousingTime: recordDateTime,
  5065. Type: 0,
  5066. StorehouseId: 0,
  5067. IsCheck: 1,
  5068. PatientId: patient_id,
  5069. IsSys: 1,
  5070. }
  5071. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5072. if selfDrugWarehouse.ID == 0 {
  5073. service.AddSelfDrugWarehouse(&warehousing, tx)
  5074. }
  5075. if selfDrugWarehouse.ID > 0 {
  5076. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5077. }
  5078. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5079. fmt.Println(info)
  5080. for _, item := range hisdoctorlist {
  5081. //查询该病人的该药品是否已经入库
  5082. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5083. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5084. var in_count int64
  5085. if len(selfdruginfo) > 0 {
  5086. for _, item := range selfdruginfo {
  5087. var in_count_one int64
  5088. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5089. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5090. }
  5091. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5092. in_count_one = item.WarehousingCount
  5093. }
  5094. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5095. in_count_one = item.WarehousingCount
  5096. }
  5097. in_count += in_count_one
  5098. }
  5099. }
  5100. if selfBasedrug.IsSelfDrug == 1 {
  5101. var total_count int64
  5102. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5103. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5104. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5105. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5106. }
  5107. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5108. total_count += prescribingNumberSeven
  5109. }
  5110. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5111. total_count += prescribingNumberSeven
  5112. }
  5113. //入库
  5114. if total_count > in_count {
  5115. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5116. WarehousingOrder: warehousing_order,
  5117. WarehousingId: info.ID,
  5118. DrugId: item.DrugId,
  5119. Number: "",
  5120. ProductDate: 0,
  5121. ExpiryDate: 0,
  5122. WarehousingCount: total_count - in_count,
  5123. WarehouseingUnit: selfBasedrug.MinUnit,
  5124. Price: 0,
  5125. TotalPrice: 0,
  5126. Status: 1,
  5127. Ctime: time.Now().Unix(),
  5128. Remark: "",
  5129. OrgId: adminInfo.CurrentOrgId,
  5130. Type: 0,
  5131. Manufacturer: selfBasedrug.Manufacturer,
  5132. Dealer: selfBasedrug.Dealer,
  5133. StockMaxNumber: total_count - in_count,
  5134. RetailTotalPrice: 0,
  5135. BatchNumber: "",
  5136. MaxUnit: selfBasedrug.MinUnit,
  5137. MinUnit: selfBasedrug.MinUnit,
  5138. RetailPrice: 0,
  5139. StorehouseId: 0,
  5140. IsCheck: 1,
  5141. StockMinNumber: 0,
  5142. PatientId: patient_id,
  5143. IsSys: 1,
  5144. RecordDate: item.RecordDate,
  5145. AdviceId: item.ID,
  5146. }
  5147. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5148. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5149. Creator := adminInfo.AdminUser.Id
  5150. //查询默认仓库剩余多少库存
  5151. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5152. var sum_count int64
  5153. for _, it := range list {
  5154. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5155. if it.MaxUnit == baseDrug.MaxUnit {
  5156. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5157. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5158. }
  5159. sum_count += it.StockMaxNumber + it.StockMinNumber
  5160. }
  5161. flow := &models.XtSelfDrugFlow{
  5162. WarehousingId: info.ID,
  5163. DrugId: item.DrugId,
  5164. Number: "",
  5165. BatchNumber: "",
  5166. Count: total_count - in_count,
  5167. UserOrgId: adminInfo.CurrentOrgId,
  5168. PatientId: item.PatientId,
  5169. SystemTime: time.Now().Unix(),
  5170. ConsumableType: 1,
  5171. IsSys: 1,
  5172. WarehousingOrder: warehousing_order,
  5173. WarehouseOutId: 0,
  5174. WarehouseOutOrderNumber: "",
  5175. IsEdit: 0,
  5176. CancelStockId: 0,
  5177. CancelOrderNumber: "",
  5178. Manufacturer: selfBasedrug.Manufacturer,
  5179. Dealer: selfBasedrug.Dealer,
  5180. Creator: Creator,
  5181. UpdateCreator: Creator,
  5182. Status: 1,
  5183. Ctime: item.AdviceDate,
  5184. Mtime: 0,
  5185. Price: item.Price,
  5186. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5187. WarehouseOutDetailId: 0,
  5188. CancelOutDetailId: 0,
  5189. ExpireDate: 0,
  5190. ProductDate: 0,
  5191. MaxUnit: selfBasedrug.MinUnit,
  5192. MinUnit: selfBasedrug.MinUnit,
  5193. StorehouseId: 0,
  5194. OverCount: sum_count,
  5195. OperateTime: time.Now().Unix(),
  5196. AdviceId: item.ID,
  5197. }
  5198. service.CreateSelfDrugFlow(flow, tx)
  5199. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5200. var total_count int64 // 入库总数量
  5201. var over_count int64 //剩余库存
  5202. for _, it := range drugInfolist {
  5203. if it.MaxUnit == selfBasedrug.MaxUnit {
  5204. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5205. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5206. }
  5207. }
  5208. for _, it := range drugInfolist {
  5209. total_count += it.WarehousingCount
  5210. over_count += it.StockMaxNumber + it.StockMinNumber
  5211. }
  5212. //查询该仓库是否有默认数据
  5213. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5214. if selfDrugStock.ID == 0 {
  5215. drugStock := models.XtSelfDrugStockCount{
  5216. UserOrgId: item.UserOrgId,
  5217. PatientId: item.PatientId,
  5218. SumInCount: total_count,
  5219. SumOutCount: 0,
  5220. SumCancelCount: 0,
  5221. DrugId: item.DrugId,
  5222. Ctime: time.Now().Unix(),
  5223. Mtime: 0,
  5224. Status: 1,
  5225. FlushCount: over_count,
  5226. SumActOutCount: 0,
  5227. }
  5228. service.CreateSelfDrugStockSum(drugStock, tx)
  5229. }
  5230. if selfDrugStock.ID > 0 {
  5231. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5232. }
  5233. }
  5234. //查询这个单据的出库数量
  5235. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5236. var his_out_count int64
  5237. for _, item := range drugFlowList {
  5238. his_out_count += item.Count
  5239. }
  5240. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5241. if (total_count + his_out_count) <= in_count {
  5242. // 出库
  5243. if total_count < in_count {
  5244. var cha_count int64
  5245. cha_count = in_count - total_count
  5246. var stock_number int64 = 0
  5247. //查询库存是否充足
  5248. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5249. // 将该批次的剩余库存数量转换为拆零数量
  5250. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5251. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5252. }
  5253. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5254. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5255. }
  5256. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5257. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5258. }
  5259. if stock_number >= cha_count {
  5260. var maxNumber int64 = 0
  5261. var minNumber int64 = 0
  5262. maxNumber = cha_count / selfBasedrug.MinNumber
  5263. minNumber = cha_count % selfBasedrug.MinNumber
  5264. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5265. minNumber = maxNumber
  5266. }
  5267. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5268. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5270. return
  5271. }
  5272. }
  5273. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5274. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5275. }
  5276. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5277. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5278. }
  5279. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5280. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5281. }
  5282. if warehouse.StockMaxNumber < 0 {
  5283. warehouse.StockMaxNumber = 0
  5284. }
  5285. if warehouse.StockMinNumber < 0 {
  5286. warehouse.StockMinNumber = 0
  5287. }
  5288. warehouse.Mtime = time.Now().Unix()
  5289. if warehouse.StockMinNumber < minNumber {
  5290. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5291. if warehouse.MaxUnit != warehouse.MinUnit {
  5292. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5293. }
  5294. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5295. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5296. }
  5297. } else {
  5298. if minNumber > 0 {
  5299. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5300. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5301. }
  5302. }
  5303. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5304. if warehouse.StockMinNumber > 0 {
  5305. if warehouse.StockMinNumber-cha_count >= 0 {
  5306. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5307. }
  5308. }
  5309. }
  5310. }
  5311. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5312. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5313. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5314. }
  5315. }
  5316. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5317. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5319. return
  5320. }
  5321. }
  5322. if warehouse.StockMinNumber <= 0 {
  5323. warehouse.StockMinNumber = 0
  5324. }
  5325. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5326. //查询该药品剩余库存
  5327. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5328. var over_count int64
  5329. for _, its := range infolist {
  5330. if its.MaxUnit == selfBasedrug.MaxUnit {
  5331. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5332. }
  5333. over_count += its.StockMaxNumber + its.StockMinNumber
  5334. }
  5335. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5336. drugflow := models.XtSelfDrugFlow{
  5337. WarehouseOutId: 0,
  5338. WarehouseOutOrderNumber: warehousing_order,
  5339. WarehousingOrder: warehousing_order,
  5340. DrugId: item.DrugId,
  5341. Number: warehouse.Number,
  5342. ProductDate: warehouse.ProductDate,
  5343. ExpireDate: warehouse.ExpiryDate,
  5344. Count: cha_count,
  5345. Price: warehouse.RetailPrice,
  5346. Status: 1,
  5347. Ctime: item.AdviceDate,
  5348. Mtime: time.Now().Unix(),
  5349. UserOrgId: item.UserOrgId,
  5350. Manufacturer: warehouse.Manufacturer,
  5351. Dealer: warehouse.Dealer,
  5352. BatchNumber: warehouse.BatchNumber,
  5353. MaxUnit: selfBasedrug.MinUnit,
  5354. ConsumableType: 20,
  5355. IsEdit: 1,
  5356. Creator: 0,
  5357. IsSys: 3,
  5358. WarehouseOutDetailId: drugWareInfo.ID,
  5359. AdviceId: item.ID,
  5360. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5361. StorehouseId: 0,
  5362. AdminUserId: creater,
  5363. LastPrice: warehouse.Price,
  5364. StockCount: "",
  5365. WarehousingDetailId: 0,
  5366. OverCount: over_count,
  5367. RetailPrice: item.Price, //手动出库出库价格
  5368. WarehousingId: warehouse.ID,
  5369. SystemTime: item.AdviceDate,
  5370. PatientId: item.PatientId,
  5371. Remark: "保存处方入库数据差",
  5372. OperateTime: time.Now().Unix(),
  5373. }
  5374. if warehouse.RetailPrice == 0 {
  5375. drugflow.Price = item.Price
  5376. }
  5377. service.CreateSelfDrugFlowOne(drugflow, tx)
  5378. var out_count int64
  5379. out_count = in_count - total_count
  5380. //
  5381. //fmt.Println("in_count------------------", in_count)
  5382. //fmt.Println("total_count------------------", total_count)
  5383. //添加出库数量
  5384. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5385. //查询剩余库存
  5386. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5387. var sum_count int64
  5388. for _, its := range stockInfo {
  5389. if its.MaxUnit == selfBasedrug.MaxUnit {
  5390. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5391. }
  5392. sum_count += its.StockMaxNumber + its.StockMinNumber
  5393. }
  5394. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5395. } else {
  5396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5397. return
  5398. }
  5399. }
  5400. }
  5401. }
  5402. }
  5403. }
  5404. }
  5405. tx.Commit()
  5406. if err == nil {
  5407. c.ServeSuccessJSON(map[string]interface{}{
  5408. "msg": "保存成功",
  5409. })
  5410. return
  5411. } else {
  5412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5413. return
  5414. }
  5415. }
  5416. }
  5417. //func (c *HisApiController) EditHisPrescription() {
  5418. // record_date := c.GetString("record_date")
  5419. // patient_id, _ := c.GetInt64("patient_id")
  5420. // reg_type, _ := c.GetInt64("reg_type")
  5421. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5422. // diagnose := c.GetString("diagnose")
  5423. // sick_type, _ := c.GetInt64("sick_type")
  5424. // sick_history := c.GetString("sick_history")
  5425. // doctor_id, _ := c.GetInt64("doctor", 0)
  5426. // department, _ := c.GetInt64("department", 0)
  5427. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5428. // p_type, _ := c.GetInt64("p_type")
  5429. //
  5430. // dataBody := make(map[string]interface{}, 0)
  5431. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5432. // if err != nil {
  5433. // utils.ErrorLog(err.Error())
  5434. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5435. // return
  5436. // }
  5437. //
  5438. // timeLayout := "2006-01-02"
  5439. // loc, _ := time.LoadLocation("Local")
  5440. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5441. // if err != nil {
  5442. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5443. // return
  5444. // }
  5445. // adminInfo := c.GetAdminUserInfo()
  5446. // recordDateTime := theTime.Unix()
  5447. //
  5448. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5449. //
  5450. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5451. // var hpInfo models.HisPrescriptionInfo
  5452. // if info.ID == 0 {
  5453. // var randNum int
  5454. // randNum = rand.Intn(10000) + 1000
  5455. // timestamp := time.Now().Unix()
  5456. // tempTime := time.Unix(timestamp, 0)
  5457. // timeFormat := tempTime.Format("20060102150405")
  5458. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5459. //
  5460. // hpInfo = models.HisPrescriptionInfo{
  5461. // UserOrgId: adminInfo.CurrentOrgId,
  5462. // RecordDate: theTime.Unix(),
  5463. // PatientId: patient_id,
  5464. // Status: 1,
  5465. // Ctime: time.Now().Unix(),
  5466. // Mtime: time.Now().Unix(),
  5467. // Creator: adminInfo.AdminUser.Id,
  5468. // Modifier: adminInfo.AdminUser.Id,
  5469. // Diagnosis: diagnose,
  5470. // SickHistory: sick_history,
  5471. // Departments: department,
  5472. // RegisterType: reg_type,
  5473. // PrescriptionNumber: p_number,
  5474. // PrescriptionStatus: 1,
  5475. // Doctor: role.UserName,
  5476. // DoctorId: doctor_id,
  5477. // SickType: sick_type,
  5478. // PType: p_type,
  5479. // }
  5480. // service.SavePatientPrescriptionInfo(hpInfo)
  5481. //
  5482. // } else {
  5483. // hpInfo = models.HisPrescriptionInfo{
  5484. // ID: info.ID,
  5485. // UserOrgId: adminInfo.CurrentOrgId,
  5486. // RecordDate: info.RecordDate,
  5487. // PatientId: info.PatientId,
  5488. // Status: 1,
  5489. // Ctime: info.Ctime,
  5490. // Mtime: time.Now().Unix(),
  5491. // Creator: info.Creator,
  5492. // Modifier: adminInfo.AdminUser.Id,
  5493. // Diagnosis: diagnose,
  5494. // SickHistory: sick_history,
  5495. // Departments: department,
  5496. // RegisterType: reg_type,
  5497. // PrescriptionNumber: info.PrescriptionNumber,
  5498. // Doctor: role.UserName,
  5499. // PrescriptionStatus: info.PrescriptionStatus,
  5500. // DoctorId: doctor_id,
  5501. // SickType: sick_type,
  5502. // PType: info.PType,
  5503. // }
  5504. // service.SavePatientPrescriptionInfo(hpInfo)
  5505. // }
  5506. //
  5507. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5508. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5509. //
  5510. // if len(prescriptions) > 0 {
  5511. // for _, item := range prescriptions {
  5512. // items := item.(map[string]interface{})
  5513. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5514. // utils.ErrorLog("id")
  5515. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5516. // return
  5517. // }
  5518. // id := int64(items["id"].(float64))
  5519. //
  5520. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5521. // utils.ErrorLog("type")
  5522. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5523. // return
  5524. // }
  5525. // types := int64(items["type"].(float64))
  5526. //
  5527. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5528. // utils.ErrorLog("med_type")
  5529. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5530. // return
  5531. // }
  5532. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5533. //
  5534. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5535. //
  5536. // ctime := time.Now().Unix()
  5537. //
  5538. // prescription := &models.HisPrescription{
  5539. // ID: id,
  5540. // PatientId: patient_id,
  5541. // UserOrgId: adminInfo.CurrentOrgId,
  5542. // RecordDate: recordDateTime,
  5543. // Ctime: ctime,
  5544. // Mtime: ctime,
  5545. // Type: types,
  5546. // Modifier: adminInfo.AdminUser.Id,
  5547. // Creator: adminInfo.AdminUser.Id,
  5548. // Status: 1,
  5549. // Doctor: role.UserName,
  5550. // HisPatientId: his_patient_id,
  5551. // OrderStatus: 1,
  5552. // BatchNumber: "",
  5553. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5554. // PType: hpInfo.PType,
  5555. // MedType: med_type,
  5556. // }
  5557. //
  5558. // if historyPrescription.ID > 0 {
  5559. // prescription.PreTime = historyPrescription.PreTime
  5560. //
  5561. // }
  5562. //
  5563. // service.SaveHisPrescription(prescription)
  5564. //
  5565. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5566. // advices := items["advices"].([]interface{})
  5567. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5568. // groupNo := int64(0)
  5569. // ctime := time.Now().Unix()
  5570. // mtime := ctime
  5571. // if len(advices) > 0 {
  5572. // for _, advice := range advices {
  5573. // var s models.HisDoctorAdviceInfo
  5574. // s.PrescriptionId = prescription.ID
  5575. // s.AdviceType = 2
  5576. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5577. // s.StopState = 2
  5578. // s.ExecutionState = 2
  5579. // s.AdviceDate = recordDateTime
  5580. // s.Status = 1
  5581. // s.UserOrgId = adminInfo.CurrentOrgId
  5582. // s.RecordDate = recordDateTime
  5583. // s.StartTime = prescription.PreTime
  5584. // s.Groupno = groupNo
  5585. // s.CreatedTime = ctime
  5586. // s.UpdatedTime = mtime
  5587. // s.PatientId = patient_id
  5588. // s.HisPatientId = his_patient_id
  5589. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5590. // if errcode > 0 {
  5591. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5592. // return
  5593. // }
  5594. //
  5595. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5596. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5597. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5598. // if s.Price == 0 {
  5599. // s.Price = lastWarehouse.RetailPrice
  5600. // }
  5601. // }
  5602. //
  5603. // service.CreateHisDoctorAdvice(&s)
  5604. // //记录日志
  5605. // byterequest, _ := json.Marshal(s)
  5606. // adviceLog := models.XtDoctorAdviceLog{
  5607. // UserOrgId: s.UserOrgId,
  5608. // PatientId: s.PatientId,
  5609. // AdminUserId: adminInfo.AdminUser.Id,
  5610. // Module: 1,
  5611. // ErrLog: string(byterequest),
  5612. // Status: 1,
  5613. // Ctime: time.Now().Unix(),
  5614. // Mtime: 0,
  5615. // Source: "电脑端his医嘱修改",
  5616. // RecordDate: s.AdviceDate,
  5617. // }
  5618. // service.CreateDoctorAdviceLog(adviceLog)
  5619. // redis := service.RedisClient()
  5620. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5621. // redis.Set(key, "", time.Second)
  5622. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5623. // fmt.Println("keyOne", keyOne)
  5624. // redis.Set(keyOne, "", time.Second)
  5625. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5626. // redis.Set(keySeven, "", time.Second)
  5627. // redis.Close()
  5628. //
  5629. // }
  5630. // }
  5631. // }
  5632. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5633. // projects := items["project"].([]interface{})
  5634. // if len(projects) > 0 {
  5635. // for _, project := range projects {
  5636. // var p models.HisPrescriptionProject
  5637. // p.PrescriptionId = prescription.ID
  5638. // p.Ctime = time.Now().Unix()
  5639. // p.Mtime = time.Now().Unix()
  5640. // p.PatientId = patient_id
  5641. // p.RecordDate = recordDateTime
  5642. // p.UserOrgId = adminInfo.CurrentOrgId
  5643. // p.HisPatientId = his_patient_id
  5644. // p.Status = 1
  5645. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5646. // if errcode > 0 {
  5647. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5648. // return
  5649. // }
  5650. // service.CreateHisProjectTwo(&p)
  5651. //
  5652. // //记录日志
  5653. // byterequest, _ := json.Marshal(p)
  5654. // adviceLog := models.XtDoctorAdviceLog{
  5655. // UserOrgId: p.UserOrgId,
  5656. // PatientId: p.PatientId,
  5657. // AdminUserId: adminInfo.AdminUser.Id,
  5658. // Module: 1,
  5659. // ErrLog: string(byterequest),
  5660. // Status: 1,
  5661. // Ctime: time.Now().Unix(),
  5662. // Mtime: 0,
  5663. // Source: "电脑端his项目修改",
  5664. // RecordDate: p.RecordDate,
  5665. // }
  5666. // service.CreateDoctorAdviceLog(adviceLog)
  5667. // }
  5668. // }
  5669. // }
  5670. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5671. // addition := items["addition"].([]interface{})
  5672. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5673. // ctime := time.Now().Unix()
  5674. // mtime := ctime
  5675. // if len(addition) > 0 {
  5676. // for _, item := range addition {
  5677. // var s models.HisAdditionalCharge
  5678. // s.PrescriptionId = prescription.ID
  5679. // s.Status = 1
  5680. // s.UserOrgId = adminInfo.CurrentOrgId
  5681. // s.RecordDate = recordDateTime
  5682. // s.CreatedTime = ctime
  5683. // s.UpdatedTime = mtime
  5684. // s.PatientId = patient_id
  5685. // s.HisPatientId = his_patient_id
  5686. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5687. // if errcode > 0 {
  5688. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5689. // return
  5690. // }
  5691. // service.CreateAdditionalCharge(&s)
  5692. // }
  5693. // }
  5694. // }
  5695. //
  5696. // }
  5697. // }
  5698. // }
  5699. // if err == nil {
  5700. // c.ServeSuccessJSON(map[string]interface{}{
  5701. // "msg": "保存成功",
  5702. // })
  5703. // return
  5704. //
  5705. // } else {
  5706. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5707. // return
  5708. // }
  5709. //}
  5710. func (c *HisApiController) DeletePrescription() {
  5711. prescription_id, _ := c.GetInt64("id")
  5712. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5713. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5714. ////同步到自备药
  5715. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5716. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5717. if selfPrescriptionOpen.IsOpen == 1 {
  5718. // 在函数结束时处理事务回滚
  5719. db := service.XTWriteDB()
  5720. tx := db.Begin()
  5721. defer func() {
  5722. if r := recover(); r != nil {
  5723. tx.Rollback()
  5724. } else {
  5725. tx.Commit()
  5726. }
  5727. }()
  5728. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5729. for _, item := range advicesList {
  5730. timeStr := time.Now().Format("2006-01-02")
  5731. timeArr := strings.Split(timeStr, "-")
  5732. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5733. total = total + 1
  5734. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5735. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5736. number = number + total
  5737. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5738. operation_time := time.Now().Unix()
  5739. creater := c.GetAdminUserInfo().AdminUser.Id
  5740. //创建一个出库单
  5741. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5742. WarehouseOutOrderNumber: warehousing_out_order,
  5743. OperationTime: operation_time,
  5744. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5745. Creater: creater,
  5746. Ctime: time.Now().Unix(),
  5747. Status: 1,
  5748. WarehouseOutTime: item.AdviceDate,
  5749. Type: 0,
  5750. PatientId: item.PatientId,
  5751. IsCheck: 1,
  5752. }
  5753. //查询今日是否有出库数据
  5754. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5755. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5756. if lastWarehouseOut.ID == 0 {
  5757. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5758. }
  5759. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5760. var total_count int64
  5761. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5762. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5763. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5764. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5765. }
  5766. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5767. total_count += prescribingNumberSeven
  5768. }
  5769. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5770. total_count += prescribingNumberSeven
  5771. }
  5772. //出库
  5773. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5774. WarehouseOutOrderNumber: warehousing_out_order,
  5775. WarehouseOutId: lastWarehouseOut.ID,
  5776. DrugId: item.DrugId,
  5777. Count: total_count,
  5778. Price: 0,
  5779. TotalPrice: 0,
  5780. Status: 1,
  5781. Ctime: item.AdviceDate,
  5782. Mtime: item.AdviceDate,
  5783. Remark: "",
  5784. OrgId: item.UserOrgId,
  5785. Type: 0,
  5786. Manufacturer: selfBasedrug.Manufacturer,
  5787. Dealer: selfBasedrug.Dealer,
  5788. RetailPrice: 0,
  5789. RetailTotalPrice: 0,
  5790. CountUnit: selfBasedrug.MinUnit,
  5791. ExpiryDate: 0,
  5792. ProductDate: 0,
  5793. Number: "",
  5794. BatchNumber: "",
  5795. IsSys: 1,
  5796. WarehouseInfoId: 0,
  5797. AdminUserId: 0,
  5798. StockCount: "",
  5799. IsCheck: 1,
  5800. SysRecordTime: item.AdviceDate,
  5801. PatientId: item.PatientId,
  5802. ClassType: "",
  5803. AdviceId: item.ID,
  5804. }
  5805. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5806. }
  5807. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5808. for _, it := range warehousingOutInfo {
  5809. //查询今日是否有出库数据
  5810. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5811. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5812. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5813. //出库逻辑
  5814. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5815. //查询剩余库存
  5816. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5817. var sum_count int64
  5818. for _, its := range stockInfo {
  5819. if its.MaxUnit == medical.MaxUnit {
  5820. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5821. }
  5822. sum_count += its.StockMaxNumber + its.StockMinNumber
  5823. }
  5824. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5825. }
  5826. }
  5827. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5828. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5829. //耗材保存处方出库
  5830. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5831. //已收费和已发药限制逻辑
  5832. isCharge := false
  5833. isMedicine := false
  5834. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5835. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5836. if new_prescription.IsMedicine == 1 {
  5837. isMedicine = true
  5838. }
  5839. for _, item := range new_prescriptions {
  5840. if item.OrderStatus == 4 {
  5841. isCharge = true
  5842. }
  5843. }
  5844. if p_err != nil {
  5845. if new_prescription.ID > 0 {
  5846. if new_prescription.OrderStatus == 2 {
  5847. isCharge = true
  5848. }
  5849. }
  5850. }
  5851. for _, item := range advices {
  5852. if item.IsMedicine == 1 {
  5853. isMedicine = true
  5854. }
  5855. }
  5856. if isCharge {
  5857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5858. return
  5859. }
  5860. if isMedicine {
  5861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5862. return
  5863. }
  5864. //已收费和已发药限制逻辑
  5865. if len(projects) > 0 {
  5866. for _, item := range projects {
  5867. service.DeletePrintInfo(item.ID) //删除打印信息
  5868. if goodOutConfig.IsOpen != 1 {
  5869. if stockConfig.IsOpen == 1 {
  5870. if item.Type == 3 && item.IsOut == 1 {
  5871. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5872. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5873. good.Total = good.Total + f_count
  5874. service.UpdateGoodInfo(&good)
  5875. operation_time := time.Now().Unix()
  5876. creater := c.GetAdminUserInfo().AdminUser.Id
  5877. //创建退库单
  5878. timeStr := time.Now().Format("2006-01-02")
  5879. timeArr := strings.Split(timeStr, "-")
  5880. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5881. total = total + 1
  5882. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5883. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5884. cancelStock := models.CancelStock{
  5885. OrderNumber: orderNumber,
  5886. OperaTime: operation_time,
  5887. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5888. Creater: creater,
  5889. Ctime: time.Now().Unix(),
  5890. Status: 1,
  5891. ReturnTime: item.RecordDate,
  5892. Type: 1,
  5893. StorehouseId: houseConfig.StorehouseOutInfo,
  5894. IsCheck: 1,
  5895. }
  5896. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5897. if msgerrkonde == gorm.ErrRecordNotFound {
  5898. service.AddSigleCancelStock(&cancelStock)
  5899. }
  5900. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5901. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5902. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5903. //查询该耗材是否出库
  5904. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5905. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5906. deaerler, _ := service.GetDealerById(info.Dealer)
  5907. var total_count int64
  5908. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5909. total_count += count
  5910. if info.ID > 0 {
  5911. if info.Count >= total_count {
  5912. //回退库存
  5913. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5914. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5915. var flush_count int64
  5916. for _, it := range goodList {
  5917. flush_count += it.StockCount
  5918. }
  5919. cancelStockInfo := models.CancelStockInfo{
  5920. GoodId: item.ProjectId,
  5921. CancelStockId: cancel.ID,
  5922. GoodTypeId: good.GoodTypeId,
  5923. Count: prescribingNumber,
  5924. Price: info.Price,
  5925. Total: 0,
  5926. ProductDate: info.ProductDate,
  5927. ExpiryDate: info.ExpiryDate,
  5928. Ctime: time.Now().Unix(),
  5929. Status: 1,
  5930. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5931. OrderNumber: cancel.OrderNumber,
  5932. Type: 0,
  5933. Dealer: deaerler.DealerName,
  5934. Manufacturer: manufacturer.ManufacturerName,
  5935. Number: info.Number,
  5936. RegisterAccount: "",
  5937. Remark: "",
  5938. WarehouseInfoId: info.WarehouseInfotId,
  5939. PatientId: info.PatientId,
  5940. RecordDate: info.SysRecordTime,
  5941. StorehouseId: houseConfig.StorehouseOutInfo,
  5942. IsCheck: 1,
  5943. }
  5944. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5945. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5946. flow := models.VmStockFlow{
  5947. WarehousingId: info.WarehouseInfotId,
  5948. GoodId: item.ProjectId,
  5949. Number: info.Number,
  5950. LicenseNumber: info.LicenseNumber,
  5951. Count: prescribingNumber,
  5952. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5953. PatientId: item.PatientId,
  5954. SystemTime: info.SysRecordTime,
  5955. ConsumableType: 7,
  5956. IsSys: 0,
  5957. WarehousingOrder: "",
  5958. WarehouseOutId: info.WarehouseOutId,
  5959. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5960. IsEdit: 0,
  5961. CancelStockId: cancel.ID,
  5962. CancelOrderNumber: cancel.OrderNumber,
  5963. Manufacturer: manufacturer.ID,
  5964. Dealer: 0,
  5965. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5966. UpdateCreator: 0,
  5967. Status: 1,
  5968. Ctime: time.Now().Unix(),
  5969. Mtime: 0,
  5970. Price: info.Price,
  5971. WarehousingDetailId: info.WarehouseInfotId,
  5972. WarehouseOutDetailId: info.ID,
  5973. CancelOutDetailId: cancelInfo.ID,
  5974. ProductDate: info.ProductDate,
  5975. ExpireDate: info.ExpiryDate,
  5976. StorehouseId: houseConfig.StorehouseOutInfo,
  5977. OverCount: flush_count,
  5978. OperateTime: time.Now().Unix(),
  5979. }
  5980. service.CreateStockFlowOne(flow)
  5981. //退库数量增加
  5982. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5983. //出库数量减少
  5984. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5985. }
  5986. if info.Count < total_count {
  5987. //回退库存
  5988. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5989. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5990. var flush_count int64
  5991. for _, it := range goodList {
  5992. flush_count += it.StockCount
  5993. }
  5994. cancelStockInfo := models.CancelStockInfo{
  5995. GoodId: item.ProjectId,
  5996. CancelStockId: cancel.ID,
  5997. GoodTypeId: good.GoodTypeId,
  5998. Count: info.Count,
  5999. Price: info.Price,
  6000. Total: 0,
  6001. ProductDate: info.ProductDate,
  6002. ExpiryDate: info.ExpiryDate,
  6003. Ctime: time.Now().Unix(),
  6004. Status: 1,
  6005. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6006. OrderNumber: cancel.OrderNumber,
  6007. Type: 0,
  6008. Dealer: deaerler.DealerName,
  6009. Manufacturer: manufacturer.ManufacturerName,
  6010. Number: info.Number,
  6011. RegisterAccount: "",
  6012. Remark: "",
  6013. WarehouseInfoId: info.WarehouseInfotId,
  6014. PatientId: info.PatientId,
  6015. RecordDate: info.SysRecordTime,
  6016. StorehouseId: houseConfig.StorehouseOutInfo,
  6017. IsCheck: 1,
  6018. }
  6019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6021. flow := models.VmStockFlow{
  6022. WarehousingId: info.WarehouseInfotId,
  6023. GoodId: item.ProjectId,
  6024. Number: info.Number,
  6025. LicenseNumber: info.LicenseNumber,
  6026. Count: info.Count,
  6027. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6028. PatientId: item.PatientId,
  6029. SystemTime: info.SysRecordTime,
  6030. ConsumableType: 7,
  6031. IsSys: 0,
  6032. WarehousingOrder: "",
  6033. WarehouseOutId: info.WarehouseOutId,
  6034. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6035. IsEdit: 0,
  6036. CancelStockId: cancel.ID,
  6037. CancelOrderNumber: cancel.OrderNumber,
  6038. Manufacturer: manufacturer.ID,
  6039. Dealer: 0,
  6040. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6041. UpdateCreator: 0,
  6042. Status: 1,
  6043. Ctime: time.Now().Unix(),
  6044. Mtime: 0,
  6045. Price: info.Price,
  6046. WarehousingDetailId: info.WarehouseInfotId,
  6047. WarehouseOutDetailId: info.ID,
  6048. CancelOutDetailId: cancelInfo.ID,
  6049. ProductDate: info.ProductDate,
  6050. ExpireDate: info.ExpiryDate,
  6051. StorehouseId: houseConfig.StorehouseOutInfo,
  6052. OverCount: flush_count,
  6053. OperateTime: time.Now().Unix(),
  6054. }
  6055. service.CreateStockFlowOne(flow)
  6056. //退库数量增加
  6057. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6058. //出库数量减少
  6059. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6060. }
  6061. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6062. var flush_count int64
  6063. for _, it := range goodList {
  6064. flush_count += it.StockCount
  6065. }
  6066. //查询已出库数量
  6067. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6068. if prescribingNumber < dialysisInfo.Count {
  6069. //改变数量
  6070. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6071. }
  6072. if prescribingNumber >= dialysisInfo.Count {
  6073. //删除出库表
  6074. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6075. }
  6076. //更新库存
  6077. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6078. //更新基础库库存
  6079. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6080. }
  6081. }
  6082. }
  6083. }
  6084. //保存耗材出库
  6085. if goodOutConfig.IsOpen == 1 {
  6086. if item.Type == 3 {
  6087. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6088. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6089. good.Total = good.Total + f_count
  6090. service.UpdateGoodInfo(&good)
  6091. operation_time := time.Now().Unix()
  6092. creater := c.GetAdminUserInfo().AdminUser.Id
  6093. //创建退库单
  6094. timeStr := time.Now().Format("2006-01-02")
  6095. timeArr := strings.Split(timeStr, "-")
  6096. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6097. total = total + 1
  6098. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6099. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6100. cancelStock := models.CancelStock{
  6101. OrderNumber: orderNumber,
  6102. OperaTime: operation_time,
  6103. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6104. Creater: creater,
  6105. Ctime: time.Now().Unix(),
  6106. Status: 1,
  6107. ReturnTime: item.RecordDate,
  6108. Type: 1,
  6109. StorehouseId: houseConfig.StorehouseOutInfo,
  6110. IsCheck: 1,
  6111. }
  6112. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6113. if msgerrkonde == gorm.ErrRecordNotFound {
  6114. service.AddSigleCancelStock(&cancelStock)
  6115. }
  6116. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6117. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6118. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6119. //查询该耗材是否出库
  6120. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6121. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6122. deaerler, _ := service.GetDealerById(info.Dealer)
  6123. var total_count int64
  6124. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6125. total_count += count
  6126. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6127. var flush_count int64
  6128. for _, it := range goodList {
  6129. flush_count += it.StockCount
  6130. }
  6131. fmt.Println("历史出库数据", info.Count)
  6132. fmt.Println("出库数量", total_count)
  6133. if info.ID > 0 {
  6134. cancelStockInfo := models.CancelStockInfo{
  6135. GoodId: item.ProjectId,
  6136. CancelStockId: cancel.ID,
  6137. GoodTypeId: good.GoodTypeId,
  6138. Count: prescribingNumber,
  6139. Price: info.Price,
  6140. Total: 0,
  6141. ProductDate: info.ProductDate,
  6142. ExpiryDate: info.ExpiryDate,
  6143. Ctime: time.Now().Unix(),
  6144. Status: 1,
  6145. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6146. OrderNumber: cancel.OrderNumber,
  6147. Type: 0,
  6148. Dealer: deaerler.DealerName,
  6149. Manufacturer: manufacturer.ManufacturerName,
  6150. Number: info.Number,
  6151. RegisterAccount: "",
  6152. Remark: "",
  6153. WarehouseInfoId: info.WarehouseInfotId,
  6154. PatientId: info.PatientId,
  6155. RecordDate: info.SysRecordTime,
  6156. StorehouseId: houseConfig.StorehouseOutInfo,
  6157. IsCheck: 1,
  6158. }
  6159. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6160. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6161. //查询出库数量
  6162. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6163. //出库数据 大于 退库数量
  6164. if len(list) > 0 {
  6165. for _, it := range list {
  6166. //回退库存
  6167. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6168. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6169. var flush_count_one int64
  6170. for _, it := range goodList {
  6171. flush_count_one += it.StockCount
  6172. }
  6173. //查询该批次是否有退库数据
  6174. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6175. creater := c.GetAdminUserInfo().AdminUser.Id
  6176. flow := models.VmStockFlow{
  6177. WarehousingId: it.WarehouseInfotId,
  6178. GoodId: it.GoodId,
  6179. Number: it.Number,
  6180. LicenseNumber: it.LicenseNumber,
  6181. Count: it.Count,
  6182. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6183. PatientId: it.PatientId,
  6184. SystemTime: it.SysRecordTime,
  6185. ConsumableType: 7,
  6186. IsSys: 0,
  6187. WarehousingOrder: "",
  6188. WarehouseOutId: it.WarehouseOutId,
  6189. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6190. IsEdit: 0,
  6191. CancelStockId: cancel.ID,
  6192. CancelOrderNumber: cancel.OrderNumber,
  6193. Manufacturer: manufacturer.ID,
  6194. Dealer: 0,
  6195. Creator: creater,
  6196. UpdateCreator: 0,
  6197. Status: 1,
  6198. Ctime: time.Now().Unix(),
  6199. Mtime: 0,
  6200. Price: it.Price,
  6201. WarehousingDetailId: it.WarehouseInfotId,
  6202. WarehouseOutDetailId: it.ID,
  6203. CancelOutDetailId: cancelInfo.ID,
  6204. ProductDate: it.ProductDate,
  6205. ExpireDate: it.ExpiryDate,
  6206. StorehouseId: houseConfig.StorehouseOutInfo,
  6207. OverCount: flush_count_one,
  6208. }
  6209. service.CreateStockFlowOne(flow)
  6210. //if flow.ID > 0 {
  6211. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6212. //}
  6213. }
  6214. }
  6215. //flow := models.VmStockFlow{
  6216. // WarehousingId: info.WarehouseInfotId,
  6217. // GoodId: item.ProjectId,
  6218. // Number: info.Number,
  6219. // LicenseNumber: info.LicenseNumber,
  6220. // Count: prescribingNumber,
  6221. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6222. // PatientId: item.PatientId,
  6223. // SystemTime: info.SysRecordTime,
  6224. // ConsumableType: 7,
  6225. // IsSys: 0,
  6226. // WarehousingOrder: "",
  6227. // WarehouseOutId: info.WarehouseOutId,
  6228. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6229. // IsEdit: 0,
  6230. // CancelStockId: cancel.ID,
  6231. // CancelOrderNumber: cancel.OrderNumber,
  6232. // Manufacturer: manufacturer.ID,
  6233. // Dealer: 0,
  6234. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6235. // UpdateCreator: 0,
  6236. // Status: 1,
  6237. // Ctime: time.Now().Unix(),
  6238. // Mtime: 0,
  6239. // Price: info.Price,
  6240. // WarehousingDetailId: info.WarehouseInfotId,
  6241. // WarehouseOutDetailId: info.ID,
  6242. // CancelOutDetailId: cancelInfo.ID,
  6243. // ProductDate: info.ProductDate,
  6244. // ExpireDate: info.ExpiryDate,
  6245. // StorehouseId: houseConfig.StorehouseOutInfo,
  6246. // OverCount: flush_count,
  6247. //}
  6248. //service.CreateStockFlowOne(flow)
  6249. //退库数量增加
  6250. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6251. //出库数量减少
  6252. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6253. //查询已出库数量
  6254. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6255. if prescribingNumber < dialysisInfo.Count {
  6256. //改变数量
  6257. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6258. }
  6259. if prescribingNumber >= dialysisInfo.Count {
  6260. //删除出库表
  6261. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6262. }
  6263. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6264. var flush_count_one int64
  6265. for _, it := range goodList {
  6266. flush_count_one += it.StockCount
  6267. }
  6268. //更新库存
  6269. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6270. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6271. //更新基础库库存
  6272. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6273. }
  6274. }
  6275. }
  6276. }
  6277. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6278. fmt.Println(err)
  6279. }
  6280. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6281. fmt.Println(err)
  6282. if len(advices) > 0 {
  6283. for _, item := range advices {
  6284. redis := service.RedisClient()
  6285. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6286. redis.Set(keyFive, "", time.Second)
  6287. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6288. redis.Set(keyOne, "", time.Second)
  6289. redis.Close()
  6290. }
  6291. }
  6292. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6293. if len(advices) > 0 {
  6294. for _, item := range advices {
  6295. creater := c.GetAdminUserInfo().AdminUser.Id
  6296. service.DrugAutoAddCancelInfo(item, creater)
  6297. }
  6298. }
  6299. } else {
  6300. if drugOutConfig.IsOpen == 1 {
  6301. if len(advices) > 0 {
  6302. for _, item := range advices {
  6303. creater := c.GetAdminUserInfo().AdminUser.Id
  6304. service.DrugAutoAddCancelInfo(item, creater)
  6305. }
  6306. }
  6307. } else {
  6308. if len(advices) > 0 {
  6309. for _, item := range advices {
  6310. creater := c.GetAdminUserInfo().AdminUser.Id
  6311. service.DrugAutoAddCancelInfo(item, creater)
  6312. }
  6313. }
  6314. }
  6315. }
  6316. c.ServeSuccessJSON(map[string]interface{}{
  6317. "msg": "删除成功",
  6318. })
  6319. return
  6320. }
  6321. func (c *HisApiController) DeleteDoctorAdvice() {
  6322. id, _ := c.GetInt64("id")
  6323. advice, _ := service.GetHisDoctorAdvicesById(id)
  6324. ////同步到自备药
  6325. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6326. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6327. if selfPrescriptionOpen.IsOpen == 1 {
  6328. db := service.XTWriteDB()
  6329. tx := db.Begin()
  6330. defer func() {
  6331. if r := recover(); r != nil {
  6332. tx.Rollback()
  6333. } else {
  6334. tx.Commit()
  6335. }
  6336. }()
  6337. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6338. var total_count int64
  6339. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6340. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6341. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6342. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6343. }
  6344. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6345. total_count += prescribingNumberSeven
  6346. }
  6347. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6348. total_count += prescribingNumberSeven
  6349. }
  6350. timeStr := time.Now().Format("2006-01-02")
  6351. timeArr := strings.Split(timeStr, "-")
  6352. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6353. total = total + 1
  6354. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6355. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6356. number = number + total
  6357. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6358. operation_time := time.Now().Unix()
  6359. creater := c.GetAdminUserInfo().AdminUser.Id
  6360. //创建一个出库单
  6361. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6362. WarehouseOutOrderNumber: warehousing_out_order,
  6363. OperationTime: operation_time,
  6364. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6365. Creater: creater,
  6366. Ctime: time.Now().Unix(),
  6367. Status: 1,
  6368. WarehouseOutTime: advice.AdviceDate,
  6369. Type: 0,
  6370. PatientId: advice.PatientId,
  6371. IsCheck: 1,
  6372. }
  6373. //查询今日是否有出库数据
  6374. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6375. if lastWarehouseOut.ID == 0 {
  6376. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6377. }
  6378. //出库
  6379. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6380. WarehouseOutId: lastWarehouseOut.ID,
  6381. WarehouseOutOrderNumber: warehousing_out_order,
  6382. DrugId: advice.DrugId,
  6383. Count: total_count,
  6384. Price: 0,
  6385. TotalPrice: 0,
  6386. Status: 1,
  6387. Ctime: advice.AdviceDate,
  6388. Mtime: advice.AdviceDate,
  6389. Remark: "",
  6390. OrgId: advice.UserOrgId,
  6391. Type: 0,
  6392. Manufacturer: selfBasedrug.Manufacturer,
  6393. Dealer: selfBasedrug.Dealer,
  6394. RetailPrice: 0,
  6395. RetailTotalPrice: 0,
  6396. CountUnit: advice.PrescribingNumberUnit,
  6397. ExpiryDate: 0,
  6398. ProductDate: 0,
  6399. Number: "",
  6400. BatchNumber: "",
  6401. IsSys: 0,
  6402. WarehouseInfoId: 0,
  6403. AdminUserId: 0,
  6404. StockCount: "",
  6405. IsCheck: 1,
  6406. SysRecordTime: advice.AdviceDate,
  6407. PatientId: advice.PatientId,
  6408. AdviceId: advice.ID,
  6409. ClassType: "",
  6410. }
  6411. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6412. for _, it := range warehousingOutInfo {
  6413. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6414. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6415. //出库逻辑
  6416. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6417. //查询剩余库存
  6418. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6419. var sum_count int64
  6420. for _, its := range stockInfo {
  6421. if its.MaxUnit == medical.MaxUnit {
  6422. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6423. }
  6424. sum_count += its.StockMaxNumber + its.StockMinNumber
  6425. }
  6426. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6427. }
  6428. }
  6429. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6430. //已收费和已发药的限制逻辑
  6431. isCharge := false
  6432. isMedicine := false
  6433. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6434. //获取今天该患者所有处方,判断是否发药或者收费
  6435. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6436. //for _, item := range new_prescriptions {
  6437. if new_prescription.IsMedicine == 1 {
  6438. isMedicine = true
  6439. }
  6440. //}
  6441. for _, item := range new_prescriptions {
  6442. if item.OrderStatus == 4 {
  6443. isCharge = true
  6444. }
  6445. }
  6446. if isMedicine {
  6447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6448. return
  6449. }
  6450. if isCharge {
  6451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6452. return
  6453. }
  6454. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6455. for _, item := range advices {
  6456. if item.IsMedicine == 1 {
  6457. isMedicine = true
  6458. }
  6459. }
  6460. if isMedicine {
  6461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6462. return
  6463. }
  6464. if new_prescription.ID > 0 {
  6465. if new_prescription.OrderStatus == 2 {
  6466. isCharge = true
  6467. }
  6468. }
  6469. if isCharge {
  6470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6471. return
  6472. }
  6473. //已收费和已发药的限制逻辑
  6474. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6475. redis := service.RedisClient()
  6476. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6477. redis.Set(keyFive, "", time.Second)
  6478. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6479. redis.Set(keyOne, "", time.Second)
  6480. defer redis.Close()
  6481. if err == nil {
  6482. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6483. //查询是否在处方中出库
  6484. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6485. if openConfig.IsOpen != 1 {
  6486. //判断该医嘱是否执行了
  6487. if advice.ExecutionState == 1 {
  6488. creater := c.GetAdminUserInfo().AdminUser.Id
  6489. service.DrugAutoAddCancelInfo(&advice, creater)
  6490. }
  6491. }
  6492. //开启保存处方扣减功能
  6493. if openConfig.IsOpen == 1 {
  6494. creater := c.GetAdminUserInfo().AdminUser.Id
  6495. service.DrugAutoAddCancelInfo(&advice, creater)
  6496. }
  6497. } else {
  6498. if drugOutConfig.IsOpen == 1 {
  6499. //查询是否在处方中出库
  6500. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6501. if openConfig.IsOpen != 1 {
  6502. //判断该医嘱是否执行了
  6503. if advice.ExecutionState == 1 {
  6504. creater := c.GetAdminUserInfo().AdminUser.Id
  6505. service.DrugAutoAddCancelInfo(&advice, creater)
  6506. }
  6507. }
  6508. //开启保存处方扣减功能
  6509. if openConfig.IsOpen == 1 {
  6510. creater := c.GetAdminUserInfo().AdminUser.Id
  6511. service.DrugAutoAddCancelInfo(&advice, creater)
  6512. }
  6513. } else {
  6514. //判断该医嘱是否执行了
  6515. if advice.ExecutionState == 1 {
  6516. creater := c.GetAdminUserInfo().AdminUser.Id
  6517. service.DrugAutoAddCancelInfo(&advice, creater)
  6518. }
  6519. }
  6520. }
  6521. c.ServeSuccessJSON(map[string]interface{}{
  6522. "msg": "删除成功",
  6523. })
  6524. return
  6525. } else {
  6526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6527. return
  6528. }
  6529. }
  6530. func (c *HisApiController) DeleteProject() {
  6531. id, _ := c.GetInt64("id")
  6532. adminInfo := c.GetAdminUserInfo()
  6533. project, _ := service.GetHisProjectByID(id)
  6534. // var consumable models.DialysisBeforePrepare
  6535. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6536. //耗材保存处方出库
  6537. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6538. isCharge := false
  6539. isMedicine := false
  6540. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6541. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6542. for _, item := range new_prescriptions {
  6543. if item.IsMedicine == 1 {
  6544. isMedicine = true
  6545. }
  6546. }
  6547. for _, item := range new_prescriptions {
  6548. if item.OrderStatus == 4 {
  6549. isCharge = true
  6550. }
  6551. }
  6552. if isMedicine {
  6553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6554. return
  6555. }
  6556. if isCharge {
  6557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6558. return
  6559. }
  6560. if new_prescription.ID > 0 {
  6561. if new_prescription.OrderStatus == 2 {
  6562. isCharge = true
  6563. }
  6564. }
  6565. if isCharge {
  6566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6567. return
  6568. }
  6569. service.DeletePrintInfo(id)
  6570. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6571. label.Status = 0
  6572. service.CreateHisLabelRecordTwo(&label)
  6573. fmt.Println(goodOutConfig.IsOpen)
  6574. if goodOutConfig.IsOpen != 1 {
  6575. if stockConfig.IsOpen == 1 {
  6576. if project.Type == 2 {
  6577. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6578. fmt.Println(err)
  6579. }
  6580. if project.Type == 3 && project.IsOut == 1 {
  6581. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6582. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6583. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6584. operation_time := time.Now().Unix()
  6585. creater := adminInfo.AdminUser.Id
  6586. //创建退库单
  6587. timeStr := time.Now().Format("2006-01-02")
  6588. timeArr := strings.Split(timeStr, "-")
  6589. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6590. total = total + 1
  6591. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6592. cancelStock := models.CancelStock{
  6593. OrderNumber: orderNumber,
  6594. OperaTime: operation_time,
  6595. OrgId: adminInfo.CurrentOrgId,
  6596. Creater: creater,
  6597. Ctime: time.Now().Unix(),
  6598. Status: 1,
  6599. ReturnTime: project.RecordDate,
  6600. Type: 1,
  6601. StorehouseId: houseConfig.StorehouseOutInfo,
  6602. IsCheck: 1,
  6603. }
  6604. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6605. if msgerrkonde == gorm.ErrRecordNotFound {
  6606. service.AddSigleCancelStock(&cancelStock)
  6607. }
  6608. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6609. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6610. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6611. //查询是否有出库
  6612. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6613. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6614. deaerler, _ := service.GetDealerById(info.Dealer)
  6615. if info.ID > 0 {
  6616. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6617. if info.Count >= prescribingNumber {
  6618. cancelStockInfo := models.CancelStockInfo{
  6619. GoodId: project.ProjectId,
  6620. CancelStockId: cancel.ID,
  6621. GoodTypeId: good.GoodTypeId,
  6622. Count: prescribingNumber,
  6623. Price: info.Price,
  6624. Total: 0,
  6625. ProductDate: info.ProductDate,
  6626. ExpiryDate: info.ExpiryDate,
  6627. Ctime: time.Now().Unix(),
  6628. Status: 1,
  6629. OrgId: adminInfo.CurrentOrgId,
  6630. OrderNumber: cancel.OrderNumber,
  6631. Type: 0,
  6632. Dealer: deaerler.DealerName,
  6633. Manufacturer: manufacturer.ManufacturerName,
  6634. Number: info.Number,
  6635. RegisterAccount: "",
  6636. Remark: "",
  6637. WarehouseInfoId: info.WarehouseInfotId,
  6638. PatientId: info.PatientId,
  6639. RecordDate: info.SysRecordTime,
  6640. StorehouseId: houseConfig.StorehouseOutInfo,
  6641. IsCheck: 1,
  6642. }
  6643. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6644. //回退库存
  6645. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6646. //退库数量增加
  6647. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6648. //出库数量减少
  6649. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6650. }
  6651. if info.Count < prescribingNumber {
  6652. cancelStockInfo := models.CancelStockInfo{
  6653. GoodId: project.ProjectId,
  6654. CancelStockId: cancel.ID,
  6655. GoodTypeId: good.GoodTypeId,
  6656. Count: info.Count,
  6657. Price: info.Price,
  6658. Total: 0,
  6659. ProductDate: info.ProductDate,
  6660. ExpiryDate: info.ExpiryDate,
  6661. Ctime: time.Now().Unix(),
  6662. Status: 1,
  6663. OrgId: adminInfo.CurrentOrgId,
  6664. OrderNumber: cancel.OrderNumber,
  6665. Type: 0,
  6666. Dealer: deaerler.DealerName,
  6667. Manufacturer: manufacturer.ManufacturerName,
  6668. Number: info.Number,
  6669. RegisterAccount: "",
  6670. Remark: "",
  6671. WarehouseInfoId: info.WarehouseInfotId,
  6672. PatientId: info.PatientId,
  6673. RecordDate: info.SysRecordTime,
  6674. StorehouseId: houseConfig.StorehouseOutInfo,
  6675. IsCheck: 1,
  6676. }
  6677. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6678. //回退库存
  6679. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6680. //退库数量增加
  6681. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6682. //出库数量减少
  6683. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6684. }
  6685. //查询剩余库存
  6686. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6687. var over_count int64
  6688. for _, it := range goodList {
  6689. over_count += it.StockCount
  6690. }
  6691. //出库数据 大于 退库数量
  6692. if info.Count >= prescribingNumber {
  6693. flow := models.VmStockFlow{
  6694. WarehousingId: info.WarehouseInfotId,
  6695. GoodId: project.ProjectId,
  6696. Number: info.Number,
  6697. LicenseNumber: info.LicenseNumber,
  6698. Count: prescribingNumber,
  6699. UserOrgId: adminInfo.CurrentOrgId,
  6700. PatientId: project.PatientId,
  6701. SystemTime: info.SysRecordTime,
  6702. ConsumableType: 7,
  6703. IsSys: 0,
  6704. WarehousingOrder: "",
  6705. WarehouseOutId: info.WarehouseOutId,
  6706. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6707. IsEdit: 0,
  6708. CancelStockId: cancel.ID,
  6709. CancelOrderNumber: cancel.OrderNumber,
  6710. Manufacturer: manufacturer.ID,
  6711. Dealer: 0,
  6712. Creator: adminInfo.AdminUser.Id,
  6713. UpdateCreator: 0,
  6714. Status: 1,
  6715. Ctime: time.Now().Unix(),
  6716. Mtime: 0,
  6717. Price: info.Price,
  6718. WarehousingDetailId: info.WarehouseInfotId,
  6719. WarehouseOutDetailId: info.ID,
  6720. CancelOutDetailId: cancelInfo.ID,
  6721. ProductDate: info.ProductDate,
  6722. ExpireDate: info.ExpiryDate,
  6723. StorehouseId: houseConfig.StorehouseOutInfo,
  6724. OverCount: over_count,
  6725. OperateTime: time.Now().Unix(),
  6726. }
  6727. service.CreateStockFlowOne(flow)
  6728. }
  6729. //出库数据小于退库数据
  6730. if info.Count < prescribingNumber {
  6731. flow := models.VmStockFlow{
  6732. WarehousingId: info.WarehouseInfotId,
  6733. GoodId: project.ProjectId,
  6734. Number: info.Number,
  6735. LicenseNumber: info.LicenseNumber,
  6736. Count: info.Count,
  6737. UserOrgId: adminInfo.CurrentOrgId,
  6738. PatientId: project.PatientId,
  6739. SystemTime: info.SysRecordTime,
  6740. ConsumableType: 7,
  6741. IsSys: 0,
  6742. WarehousingOrder: "",
  6743. WarehouseOutId: info.WarehouseOutId,
  6744. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6745. IsEdit: 0,
  6746. CancelStockId: cancel.ID,
  6747. CancelOrderNumber: cancel.OrderNumber,
  6748. Manufacturer: manufacturer.ID,
  6749. Dealer: 0,
  6750. Creator: adminInfo.AdminUser.Id,
  6751. UpdateCreator: 0,
  6752. Status: 1,
  6753. Ctime: time.Now().Unix(),
  6754. Mtime: 0,
  6755. Price: info.Price,
  6756. WarehousingDetailId: info.WarehouseInfotId,
  6757. WarehouseOutDetailId: info.ID,
  6758. CancelOutDetailId: cancelInfo.ID,
  6759. ProductDate: info.ProductDate,
  6760. ExpireDate: info.ExpiryDate,
  6761. StorehouseId: houseConfig.StorehouseOutInfo,
  6762. OverCount: over_count,
  6763. OperateTime: time.Now().Unix(),
  6764. }
  6765. service.CreateStockFlowOne(flow)
  6766. }
  6767. //查询已出库数量
  6768. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6769. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6770. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6771. if prescribingNumber < dialysisInfo.Count {
  6772. //改变数量
  6773. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6774. }
  6775. if prescribingNumber >= dialysisInfo.Count {
  6776. //删除出库表
  6777. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6778. }
  6779. //更新剩余库存
  6780. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6781. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6782. var total_count_one int64
  6783. for _, it := range stockList {
  6784. total_count_one += it.StockCount
  6785. }
  6786. //基础库插入数据
  6787. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6788. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6789. var flush_count int64
  6790. for _, it := range goodListOne {
  6791. flush_count += it.StockCount
  6792. }
  6793. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6794. if errs != nil {
  6795. goodErrcode := models.XtGoodErrcode{
  6796. UserOrgId: project.UserOrgId,
  6797. Errcode: "手动出库更新剩余出库失败",
  6798. GoodId: project.ProjectId,
  6799. Status: 1,
  6800. Ctime: time.Now().Unix(),
  6801. Mtime: 0,
  6802. Count: 0,
  6803. StockCount: 0,
  6804. Creater: creater,
  6805. BatchNumberId: 0,
  6806. WarehouseOutId: 0,
  6807. }
  6808. service.CreateGoodErrcode(goodErrcode)
  6809. }
  6810. }
  6811. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6812. fmt.Println(err)
  6813. } else {
  6814. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6815. fmt.Println(err)
  6816. }
  6817. } else {
  6818. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6819. fmt.Println(err)
  6820. }
  6821. }
  6822. //保存处方出库
  6823. if goodOutConfig.IsOpen == 1 {
  6824. if project.Type == 3 {
  6825. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6826. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6827. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6828. operation_time := time.Now().Unix()
  6829. creater := adminInfo.AdminUser.Id
  6830. //创建退库单
  6831. timeStr := time.Now().Format("2006-01-02")
  6832. timeArr := strings.Split(timeStr, "-")
  6833. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6834. total = total + 1
  6835. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6836. cancelStock := models.CancelStock{
  6837. OrderNumber: orderNumber,
  6838. OperaTime: operation_time,
  6839. OrgId: adminInfo.CurrentOrgId,
  6840. Creater: creater,
  6841. Ctime: time.Now().Unix(),
  6842. Status: 1,
  6843. ReturnTime: project.RecordDate,
  6844. Type: 1,
  6845. StorehouseId: houseConfig.StorehouseOutInfo,
  6846. IsCheck: 1,
  6847. }
  6848. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6849. if msgerrkonde == gorm.ErrRecordNotFound {
  6850. service.AddSigleCancelStock(&cancelStock)
  6851. }
  6852. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6853. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6854. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6855. //获取出库数据
  6856. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6857. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6858. deaerler, _ := service.GetDealerById(info.Dealer)
  6859. if info.ID > 0 {
  6860. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6861. if info.Count >= prescribingNumber {
  6862. cancelStockInfo := models.CancelStockInfo{
  6863. GoodId: project.ProjectId,
  6864. CancelStockId: cancel.ID,
  6865. GoodTypeId: good.GoodTypeId,
  6866. Count: prescribingNumber,
  6867. Price: info.Price,
  6868. Total: 0,
  6869. ProductDate: info.ProductDate,
  6870. ExpiryDate: info.ExpiryDate,
  6871. Ctime: time.Now().Unix(),
  6872. Status: 1,
  6873. OrgId: adminInfo.CurrentOrgId,
  6874. OrderNumber: cancel.OrderNumber,
  6875. Type: 0,
  6876. Dealer: deaerler.DealerName,
  6877. Manufacturer: manufacturer.ManufacturerName,
  6878. Number: info.Number,
  6879. RegisterAccount: "",
  6880. Remark: "",
  6881. WarehouseInfoId: info.WarehouseInfotId,
  6882. PatientId: info.PatientId,
  6883. RecordDate: info.SysRecordTime,
  6884. StorehouseId: houseConfig.StorehouseOutInfo,
  6885. IsCheck: 1,
  6886. }
  6887. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6888. //退库数量增加
  6889. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6890. //出库数量减少
  6891. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6892. }
  6893. if info.Count < prescribingNumber {
  6894. cancelStockInfo := models.CancelStockInfo{
  6895. GoodId: project.ProjectId,
  6896. CancelStockId: cancel.ID,
  6897. GoodTypeId: good.GoodTypeId,
  6898. Count: prescribingNumber,
  6899. Price: info.Price,
  6900. Total: 0,
  6901. ProductDate: info.ProductDate,
  6902. ExpiryDate: info.ExpiryDate,
  6903. Ctime: time.Now().Unix(),
  6904. Status: 1,
  6905. OrgId: adminInfo.CurrentOrgId,
  6906. OrderNumber: cancel.OrderNumber,
  6907. Type: 0,
  6908. Dealer: deaerler.DealerName,
  6909. Manufacturer: manufacturer.ManufacturerName,
  6910. Number: info.Number,
  6911. RegisterAccount: "",
  6912. Remark: "",
  6913. WarehouseInfoId: info.WarehouseInfotId,
  6914. PatientId: info.PatientId,
  6915. RecordDate: info.SysRecordTime,
  6916. StorehouseId: houseConfig.StorehouseOutInfo,
  6917. IsCheck: 1,
  6918. }
  6919. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6920. //回退库存
  6921. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6922. }
  6923. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6924. var over_count int64
  6925. for _, it := range goodList {
  6926. over_count += it.StockCount
  6927. }
  6928. //查询出库数量
  6929. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6930. //出库数据 大于 退库数量
  6931. if len(list) > 0 {
  6932. for _, it := range list {
  6933. //回退库存
  6934. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6935. //退库数量增加
  6936. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6937. //出库数量减少
  6938. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6939. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6940. var over_count_one int64
  6941. for _, it := range goodList {
  6942. over_count_one += it.StockCount
  6943. }
  6944. //查询该批次是否有退库数据
  6945. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6946. flow := models.VmStockFlow{
  6947. WarehousingId: it.WarehouseInfotId,
  6948. GoodId: it.GoodId,
  6949. Number: it.Number,
  6950. LicenseNumber: it.LicenseNumber,
  6951. Count: it.Count,
  6952. UserOrgId: adminInfo.CurrentOrgId,
  6953. PatientId: it.PatientId,
  6954. SystemTime: it.SysRecordTime,
  6955. ConsumableType: 7,
  6956. IsSys: 0,
  6957. WarehousingOrder: "",
  6958. WarehouseOutId: it.WarehouseOutId,
  6959. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6960. IsEdit: 0,
  6961. CancelStockId: cancel.ID,
  6962. CancelOrderNumber: cancel.OrderNumber,
  6963. Manufacturer: manufacturer.ID,
  6964. Dealer: 0,
  6965. Creator: adminInfo.AdminUser.Id,
  6966. UpdateCreator: 0,
  6967. Status: 1,
  6968. Ctime: time.Now().Unix(),
  6969. Mtime: 0,
  6970. Price: it.Price,
  6971. WarehousingDetailId: it.WarehouseInfotId,
  6972. WarehouseOutDetailId: it.ID,
  6973. CancelOutDetailId: cancelInfo.ID,
  6974. ProductDate: it.ProductDate,
  6975. ExpireDate: it.ExpiryDate,
  6976. StorehouseId: houseConfig.StorehouseOutInfo,
  6977. OverCount: over_count_one,
  6978. OperateTime: time.Now().Unix(),
  6979. }
  6980. service.CreateStockFlowOne(flow)
  6981. }
  6982. }
  6983. //查询已出库数量
  6984. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6985. if prescribingNumber < dialysisInfo.Count {
  6986. //改变数量
  6987. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6988. }
  6989. if prescribingNumber >= dialysisInfo.Count {
  6990. //删除出库表
  6991. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6992. }
  6993. //更新剩余库存
  6994. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6995. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6996. var total_count_one int64
  6997. for _, it := range stockList {
  6998. total_count_one += it.StockCount
  6999. }
  7000. //基础库插入数据
  7001. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7002. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7003. var flush_count int64
  7004. for _, it := range goodListOne {
  7005. flush_count += it.StockCount
  7006. }
  7007. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7008. if errs != nil {
  7009. goodErrcode := models.XtGoodErrcode{
  7010. UserOrgId: project.UserOrgId,
  7011. Errcode: "手动出库更新剩余出库失败",
  7012. GoodId: project.ProjectId,
  7013. Status: 1,
  7014. Ctime: time.Now().Unix(),
  7015. Mtime: 0,
  7016. Count: 0,
  7017. StockCount: 0,
  7018. Creater: creater,
  7019. BatchNumberId: 0,
  7020. WarehouseOutId: 0,
  7021. }
  7022. service.CreateGoodErrcode(goodErrcode)
  7023. }
  7024. }
  7025. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7026. fmt.Println(err)
  7027. } else {
  7028. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7029. fmt.Println(err)
  7030. }
  7031. }
  7032. c.ServeSuccessJSON(map[string]interface{}{
  7033. "msg": "删除成功",
  7034. })
  7035. return
  7036. }
  7037. func (c *HisApiController) CreateHisAdditionalCharge() {
  7038. his_patient_id, _ := c.GetInt64("his_patient_id")
  7039. patient_id, _ := c.GetInt64("patient_id")
  7040. record_date := c.GetString("record_date")
  7041. timeLayout := "2006-01-02"
  7042. loc, _ := time.LoadLocation("Local")
  7043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7044. if err != nil {
  7045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7046. return
  7047. }
  7048. adminInfo := c.GetAdminUserInfo()
  7049. recordDateTime := theTime.Unix()
  7050. dataBody := make(map[string]interface{}, 0)
  7051. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7052. if err != nil {
  7053. utils.ErrorLog(err.Error())
  7054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7055. return
  7056. }
  7057. var additions []*models.HisAdditionalCharge
  7058. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7059. additions, _ := dataBody["addition"].([]interface{})
  7060. if len(additions) > 0 {
  7061. for _, item := range additions {
  7062. items := item.(map[string]interface{})
  7063. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7064. utils.ErrorLog("item_id")
  7065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7066. return
  7067. }
  7068. item_id := int64(items["item_id"].(float64))
  7069. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7070. utils.ErrorLog("item_name")
  7071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7072. return
  7073. }
  7074. item_name := items["item_name"].(string)
  7075. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7076. utils.ErrorLog("price")
  7077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7078. return
  7079. }
  7080. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7081. ctime := time.Now().Unix()
  7082. additional := &models.HisAdditionalCharge{
  7083. PatientId: patient_id,
  7084. HisPatientId: his_patient_id,
  7085. UserOrgId: adminInfo.CurrentOrgId,
  7086. RecordDate: recordDateTime,
  7087. CreatedTime: ctime,
  7088. UpdatedTime: ctime,
  7089. Modifier: adminInfo.AdminUser.Id,
  7090. Creator: adminInfo.AdminUser.Id,
  7091. Price: price,
  7092. ItemName: item_name,
  7093. ItemId: item_id,
  7094. Status: 1,
  7095. }
  7096. additions = append(additions, additional)
  7097. }
  7098. }
  7099. }
  7100. for _, item := range additions {
  7101. service.CreateAddtionalCharge(item)
  7102. }
  7103. c.ServeSuccessJSON(map[string]interface{}{
  7104. "msg": "创建成功",
  7105. })
  7106. }
  7107. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7108. blood_fat := c.GetString("blood_fat")
  7109. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7110. blood_sugar := c.GetString("blood_sugar")
  7111. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7112. chief_conplaint := c.GetString("chief_conplaint")
  7113. dbp := c.GetString("dbp")
  7114. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7115. delivery_way, _ := c.GetInt64("delivery_way")
  7116. diagnostic := c.GetString("diagnostic")
  7117. family_history := c.GetString("family_history")
  7118. height := c.GetString("height")
  7119. history_of_present_illness := c.GetString("history_of_present_illness")
  7120. is_infect, _ := c.GetInt64("is_infect")
  7121. past_history := c.GetString("past_history")
  7122. patient_id, _ := c.GetInt64("patient_id")
  7123. his_patient_id, _ := c.GetInt64("his_patient_id")
  7124. personal_history := c.GetString("personal_history")
  7125. pulse := c.GetString("pulse")
  7126. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7127. sbp := c.GetString("sbp")
  7128. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7129. heightfloat, _ := strconv.ParseFloat(height, 64)
  7130. sicktype := c.GetString("sick_type")
  7131. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7132. symptom := c.GetString("symptom")
  7133. sick_date := c.GetString("sick_date")
  7134. temperatures := c.GetString("temperature")
  7135. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7136. record_date := c.GetString("record_date")
  7137. breathing := c.GetString("breathing")
  7138. doctor_advice := c.GetString("doctor_advice")
  7139. remark := c.GetString("remark")
  7140. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7141. sick, _ := c.GetInt64("sick")
  7142. diagnose, _ := c.GetInt64("diagnose")
  7143. //id, _ := c.GetInt64("id")
  7144. timeLayout := "2006-01-02"
  7145. loc, _ := time.LoadLocation("Local")
  7146. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7147. allergic_history := c.GetString("allergic_history")
  7148. if err != nil {
  7149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7150. return
  7151. }
  7152. recordDateTime := theTime.Unix()
  7153. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7154. if err != nil {
  7155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7156. return
  7157. }
  7158. sickTimes := sickTime.Unix()
  7159. ctime := time.Now().Unix()
  7160. primary_disease := c.GetString("primary_disease")
  7161. confirm_failure_date := c.GetString("confirm_failure_date")
  7162. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7163. drug_allergy_history := c.GetString("drug_allergy_history")
  7164. physical_examination := c.GetString("physical_examination")
  7165. special_inspection := c.GetString("special_inspection")
  7166. lab_apparatus := c.GetString("lab_apparatus")
  7167. caseHistory := models.HisPatientCaseHistory{
  7168. HisPatientId: his_patient_id,
  7169. PatientId: patient_id,
  7170. Temperature: temperature,
  7171. BloodSugar: bloodsugarfloat,
  7172. Pulse: pulsefloat,
  7173. Sbp: sbpfloat,
  7174. Dbp: dbpfloat,
  7175. Height: heightfloat,
  7176. BloodFat: bloodfatfloat,
  7177. SickType: sick_type,
  7178. Symptom: symptom,
  7179. SickDate: sickTimes,
  7180. IsInfect: is_infect,
  7181. HistoryOfPresentIllness: history_of_present_illness,
  7182. PastHistory: past_history,
  7183. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7184. ChiefConplaint: chief_conplaint,
  7185. PersonalHistory: personal_history,
  7186. FamilyHistory: family_history,
  7187. Diagnostic: diagnostic,
  7188. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7189. Status: 1,
  7190. Ctime: ctime,
  7191. Mtime: ctime,
  7192. RecordDate: recordDateTime,
  7193. DeliveryWay: delivery_way,
  7194. Breathing: breathingfloat,
  7195. DoctorAdvice: doctor_advice,
  7196. Remark: remark,
  7197. Sick: sick,
  7198. Diagnose: diagnose,
  7199. AllergicHistory: allergic_history,
  7200. PrimaryDisease: primary_disease,
  7201. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7202. DrugAllergyHistory: drug_allergy_history,
  7203. PhysicalExamination: physical_examination,
  7204. SpecialInspection: special_inspection,
  7205. LabApparatus: lab_apparatus,
  7206. }
  7207. //查询该患者是否有病历
  7208. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7209. if errcodes == gorm.ErrRecordNotFound {
  7210. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7211. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7212. if err != nil {
  7213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7214. return
  7215. }
  7216. c.ServeSuccessJSON(map[string]interface{}{
  7217. "caseHistory": caseHistory,
  7218. "historyInfo": historyInfo,
  7219. })
  7220. return
  7221. } else if errcodes == nil {
  7222. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7223. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7224. if err != nil {
  7225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7226. return
  7227. }
  7228. c.ServeSuccessJSON(map[string]interface{}{
  7229. "caseHistory": caseHistory,
  7230. "historyInfo": historyInfo,
  7231. })
  7232. }
  7233. //查询该患者是否有病历
  7234. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7235. //if errcode == gorm.ErrRecordNotFound {
  7236. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7237. // if err != nil {
  7238. // c.ServeSuccessJSON(map[string]interface{}{
  7239. // "msg": "保存成功",
  7240. // })
  7241. // }
  7242. //} else if errcode == nil {
  7243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7244. // return
  7245. //}
  7246. }
  7247. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7248. patient_id, _ := c.GetInt64("patient_id", 0)
  7249. adminUser := c.GetAdminUserInfo()
  7250. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7251. c.ServeSuccessJSON(map[string]interface{}{
  7252. "list": caseHistorys,
  7253. })
  7254. }
  7255. func (c *HisApiController) GetHisPatientCaseHistory() {
  7256. record_date, _ := c.GetInt64("record_date", 0)
  7257. patient_id, _ := c.GetInt64("patient_id", 0)
  7258. admin := c.GetAdminUserInfo()
  7259. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7260. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7261. c.ServeSuccessJSON(map[string]interface{}{
  7262. "info": info,
  7263. "case_history": case_history,
  7264. })
  7265. }
  7266. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7267. template_name := c.GetString("template_name")
  7268. template_remark := c.GetString("template_remark")
  7269. doctor := c.GetAdminUserInfo().AdminUser.Id
  7270. diagnostic := c.GetString("diagnostic")
  7271. chief_conplaint := c.GetString("chief_conplain")
  7272. history_of_present_illness := c.GetString("history_of_present_illness")
  7273. past_history := c.GetString("past_history")
  7274. personal_history := c.GetString("personal_history")
  7275. family_history := c.GetString("family_history")
  7276. user_name := c.GetString("user_name")
  7277. doctor_advice := c.GetString("doctor_advice")
  7278. remark := c.GetString("remark")
  7279. //record_date := c.GetString("record_date")
  7280. //fmt.Println("record_date--------",record_date)
  7281. //timeLayout := "2006-01-02"
  7282. //loc, _ := time.LoadLocation("Local")
  7283. //
  7284. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7285. //if err != nil {
  7286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7287. // return
  7288. //}
  7289. //recordDateTime := theTime.Unix()
  7290. ctime := time.Now().Unix()
  7291. template := models.HisCaseHistoryTemplate{
  7292. HistoryOfPresentIllness: history_of_present_illness,
  7293. PastHistory: past_history,
  7294. ChiefConplaint: chief_conplaint,
  7295. PersonalHistory: personal_history,
  7296. FamilyHistory: family_history,
  7297. Diagnostic: diagnostic,
  7298. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7299. Status: 1,
  7300. Ctime: ctime,
  7301. Mtime: ctime,
  7302. RecordDate: time.Now().Unix(),
  7303. TemplateName: template_name,
  7304. TemplateRemark: template_remark,
  7305. Creator: doctor,
  7306. Modifier: doctor,
  7307. UserName: user_name,
  7308. DoctorAdvice: doctor_advice,
  7309. Remark: remark,
  7310. }
  7311. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7312. if err == nil {
  7313. c.ServeSuccessJSON(map[string]interface{}{
  7314. "msg": "保存成功",
  7315. })
  7316. } else {
  7317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7318. return
  7319. }
  7320. }
  7321. func (c *HisApiController) GetCaseHistoryTemplate() {
  7322. timeLayout := "2006-01-02"
  7323. loc, _ := time.LoadLocation("Local")
  7324. keyword := c.GetString("keyword")
  7325. start_time := c.GetString("start_time")
  7326. end_time := c.GetString("end_time")
  7327. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7328. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7329. admin := c.GetAdminUserInfo()
  7330. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7331. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7332. c.ServeSuccessJSON(map[string]interface{}{
  7333. "template": template,
  7334. //"history": history,
  7335. })
  7336. }
  7337. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7338. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7339. utils.ErrorLog("drug_name")
  7340. return enums.ErrorCodeParamWrong
  7341. }
  7342. adviceName, _ := json["drug_name"].(string)
  7343. if len(adviceName) == 0 {
  7344. utils.ErrorLog("len(advice_name) == 0")
  7345. return enums.ErrorCodeParamWrong
  7346. }
  7347. advice.AdviceName = adviceName
  7348. adviceDesc, _ := json["advice_desc"].(string)
  7349. advice.AdviceDesc = adviceDesc
  7350. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7351. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7352. advice.DrugSpec = drugSpec
  7353. }
  7354. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7355. remark, _ := json["remark"].(string)
  7356. advice.Remark = remark
  7357. }
  7358. if json["id"] == nil {
  7359. advice.DrugId = 0
  7360. } else {
  7361. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7362. drug_id := int64(json["id"].(float64))
  7363. advice.DrugId = drug_id
  7364. }
  7365. }
  7366. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7367. advice_id := int64(json["advice_id"].(float64))
  7368. advice.ID = advice_id
  7369. if advice.ID > 0 {
  7370. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7371. if err == nil {
  7372. if hisAdvice.ID > 0 {
  7373. advice.ExecutionTime = hisAdvice.ExecutionTime
  7374. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7375. advice.ExecutionState = hisAdvice.ExecutionState
  7376. advice.CheckTime = hisAdvice.CheckTime
  7377. advice.Checker = hisAdvice.Checker
  7378. advice.CheckState = hisAdvice.CheckState
  7379. advice.StartTime = hisAdvice.StartTime
  7380. advice.FeedetlSn = hisAdvice.FeedetlSn
  7381. }
  7382. }
  7383. }
  7384. }
  7385. //
  7386. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7387. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7388. // advice.ExecutionTime = execution_time
  7389. //}
  7390. //
  7391. //
  7392. //
  7393. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7394. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7395. // advice.ExecutionStaff = execution_staff
  7396. //}
  7397. //
  7398. //
  7399. //
  7400. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7401. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7402. // advice.ExecutionState = execution_state
  7403. //}
  7404. //
  7405. //
  7406. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7407. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7408. // advice.CheckTime = check_time
  7409. //}
  7410. //
  7411. //
  7412. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7413. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7414. // advice.CheckState = check_state
  7415. //}
  7416. //
  7417. //
  7418. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7419. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7420. // advice.Checker = checker
  7421. //}
  7422. //
  7423. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7424. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7425. // advice.StartTime = start_time
  7426. //}
  7427. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7428. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7429. advice.IsSelfDrug = is_self_drug
  7430. }
  7431. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7432. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7433. drug_way_count, _ := json["drug_way_count"].(string)
  7434. advice.DrugWayCount = drug_way_count
  7435. }
  7436. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7437. drugSpecUnit, _ := json["min_unit"].(string)
  7438. advice.DrugSpecUnit = drugSpecUnit
  7439. }
  7440. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7441. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7442. advice.SingleDose = singleDose
  7443. }
  7444. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7445. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7446. advice.SingleDoseUnit = singleDoseUnit
  7447. }
  7448. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7449. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7450. advice.PrescribingNumber = prescribingNumber
  7451. }
  7452. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7453. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7454. advice.PrescribingNumberUnit = prescribingNumberUnit
  7455. }
  7456. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7457. deliveryWay, _ := json["delivery_way"].(string)
  7458. advice.DeliveryWay = deliveryWay
  7459. }
  7460. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7461. executionFrequency, _ := json["execution_frequency"].(string)
  7462. advice.ExecutionFrequency = executionFrequency
  7463. }
  7464. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7465. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7466. advice.Price = price
  7467. }
  7468. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7469. med_list_codg, _ := json["medical_insurance_number"].(string)
  7470. advice.MedListCodg = med_list_codg
  7471. }
  7472. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7473. day := int64(json["day"].(float64))
  7474. advice.Day = day
  7475. }
  7476. return 0
  7477. }
  7478. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7479. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7480. id := int64(json["id"].(float64))
  7481. project.ID = id
  7482. historyProject, _ := service.GetHisProjectByID(id)
  7483. project.FeedetlSn = historyProject.FeedetlSn
  7484. }
  7485. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7486. project_id := int64(json["project_id"].(float64))
  7487. project.ProjectId = project_id
  7488. }
  7489. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7490. // price := int64(json["price"].(float64))
  7491. // formatInt_price := strconv.FormatInt(price, 10)
  7492. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7493. // project.Price = float_price
  7494. // }
  7495. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7496. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7497. project.Price = price
  7498. }
  7499. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7500. total, _ := json["total"].(string)
  7501. project.Count = total
  7502. }
  7503. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7504. medical_code, _ := json["medical_code"].(string)
  7505. project.MedListCodg = medical_code
  7506. }
  7507. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7508. single_dose, _ := json["single_dose"].(string)
  7509. project.SingleDose = single_dose
  7510. }
  7511. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7512. delivery_way, _ := json["delivery_way"].(string)
  7513. project.DeliveryWay = delivery_way
  7514. }
  7515. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7516. execution_frequency, _ := json["execution_frequency"].(string)
  7517. project.ExecutionFrequency = execution_frequency
  7518. }
  7519. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7520. remark, _ := json["remark"].(string)
  7521. project.Remark = remark
  7522. }
  7523. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7524. day, _ := json["number_days"].(string)
  7525. project.Day = day
  7526. }
  7527. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7528. unit, _ := json["unit"].(string)
  7529. project.Unit = unit
  7530. }
  7531. return 0
  7532. }
  7533. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7534. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7535. id := int64(json["id"].(float64))
  7536. historyAddtions, _ := service.GetHisAdditionByID(id)
  7537. additionalCharge.ID = id
  7538. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7539. }
  7540. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7541. item_id := int64(json["item_id"].(float64))
  7542. additionalCharge.ItemId = item_id
  7543. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7544. if config.ID > 0 {
  7545. if len(config.Code) > 0 {
  7546. additionalCharge.MedListCodg = config.Code
  7547. }
  7548. }
  7549. }
  7550. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7551. // price := int64(json["price"].(float64))
  7552. // formatInt_price := strconv.FormatInt(price, 10)
  7553. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7554. // additionalCharge.Price = float_price
  7555. // }
  7556. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7557. // price := int64(json["price"].(float64))
  7558. // formatInt_price := strconv.FormatInt(price, 10)
  7559. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7560. // additionalCharge.Price = float_price
  7561. //}
  7562. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7563. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7564. additionalCharge.Price = price
  7565. }
  7566. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7567. count, _ := json["count"].(string)
  7568. counts, _ := strconv.ParseInt(count, 10, 64)
  7569. additionalCharge.Count = counts
  7570. }
  7571. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7572. item_name, _ := json["item_name"].(string)
  7573. additionalCharge.ItemName = item_name
  7574. }
  7575. return 0
  7576. }
  7577. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7578. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7579. utils.ErrorLog("drug_name")
  7580. return enums.ErrorCodeParamWrong
  7581. }
  7582. adviceName, _ := json["drug_name"].(string)
  7583. if len(adviceName) == 0 {
  7584. utils.ErrorLog("len(advice_name) == 0")
  7585. return enums.ErrorCodeParamWrong
  7586. }
  7587. advice.AdviceName = adviceName
  7588. adviceDesc, _ := json["advice_desc"].(string)
  7589. advice.AdviceDesc = adviceDesc
  7590. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7591. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7592. advice.DrugSpec = drugSpec
  7593. }
  7594. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7595. remark, _ := json["remark"].(string)
  7596. advice.Remark = remark
  7597. }
  7598. if json["id"] == nil {
  7599. advice.DrugId = 0
  7600. } else {
  7601. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7602. drug_id := int64(json["id"].(float64))
  7603. advice.DrugId = drug_id
  7604. }
  7605. }
  7606. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7607. groupno := int64(json["groupno"].(float64))
  7608. advice.Groupno = groupno
  7609. }
  7610. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7611. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7612. advice.IsSelfDrug = is_self_drug
  7613. }
  7614. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7615. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7616. drug_way_count, _ := json["drug_way_count"].(string)
  7617. advice.DrugWayCount = drug_way_count
  7618. }
  7619. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7620. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7621. advice.HospApprFlag = hosp_appr_flag
  7622. }
  7623. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7624. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7625. advice.PrescribingNumber = prescribingNumber
  7626. }
  7627. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7628. // frequency_type := int64(json["frequency_type"].(float64))
  7629. // advice.FrequencyType = frequency_type
  7630. //}
  7631. //
  7632. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7633. // day_count := int64(json["day_count"].(float64))
  7634. // advice.DayCount = day_count
  7635. //}
  7636. //
  7637. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7638. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7639. // week_day, _ := json["week_day"].(string)
  7640. // advice.WeekDay = week_day
  7641. //}
  7642. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7643. drugSpecUnit, _ := json["min_unit"].(string)
  7644. advice.DrugSpecUnit = drugSpecUnit
  7645. }
  7646. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7647. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7648. advice.SingleDose = singleDose
  7649. }
  7650. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7651. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7652. advice.SingleDoseUnit = singleDoseUnit
  7653. }
  7654. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7655. deliveryWay, _ := json["delivery_way"].(string)
  7656. advice.DeliveryWay = deliveryWay
  7657. }
  7658. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7659. executionFrequency, _ := json["execution_frequency"].(string)
  7660. advice.ExecutionFrequency = executionFrequency
  7661. }
  7662. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7663. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7664. advice.Price = price
  7665. }
  7666. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7667. med_list_codg, _ := json["medical_insurance_number"].(string)
  7668. advice.MedListCodg = med_list_codg
  7669. }
  7670. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7671. day := int64(json["day"].(float64))
  7672. advice.Day = day
  7673. }
  7674. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7675. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7676. advice.PrescribingNumberUnit = prescribingNumberUnit
  7677. }
  7678. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7679. advice_id := int64(json["advice_id"].(float64))
  7680. advice.ID = advice_id
  7681. if advice.ID > 0 {
  7682. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7683. if err == nil {
  7684. if hisAdvice.ID > 0 {
  7685. advice.ExecutionTime = hisAdvice.ExecutionTime
  7686. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7687. advice.ExecutionState = hisAdvice.ExecutionState
  7688. advice.CheckTime = hisAdvice.CheckTime
  7689. advice.Checker = hisAdvice.Checker
  7690. advice.CheckState = hisAdvice.CheckState
  7691. advice.StartTime = hisAdvice.StartTime
  7692. advice.HospApprFlag = hisAdvice.HospApprFlag
  7693. advice.IsMedicine = hisAdvice.IsMedicine
  7694. if hisAdvice.UserOrgId == 10028 {
  7695. 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 {
  7696. advice.ExecutionTime = 0
  7697. advice.ExecutionStaff = 0
  7698. advice.ExecutionState = 2
  7699. advice.CheckTime = 0
  7700. advice.Checker = 0
  7701. advice.CheckState = 2
  7702. }
  7703. } else {
  7704. 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 {
  7705. advice.ExecutionTime = 0
  7706. advice.ExecutionStaff = 0
  7707. advice.ExecutionState = 2
  7708. advice.CheckTime = 0
  7709. advice.Checker = 0
  7710. advice.CheckState = 2
  7711. advice.UpdatedTime = time.Now().Unix()
  7712. }
  7713. }
  7714. //advice.Groupno = hisAdvice.Groupno
  7715. }
  7716. }
  7717. }
  7718. }
  7719. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7720. //
  7721. //if drugStockConfig.IsOpen == 1 {
  7722. //
  7723. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7724. // if advice.ID == 0 { //医嘱不存在
  7725. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7726. // drug.Total = drug.Total - advice.PrescribingNumber
  7727. // service.UpdateBaseDrugLib(&drug)
  7728. //
  7729. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7730. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7731. // drug.Total = drug.Total - num
  7732. // service.UpdateBaseDrugLib(&drug)
  7733. // }
  7734. //
  7735. // } else if advice.ID > 0 { //医嘱存在
  7736. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7737. // var num float64
  7738. //
  7739. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7740. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7741. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7742. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7743. // drug.Total = drug.Total + num
  7744. // service.UpdateBaseDrugLib(&drug)
  7745. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7746. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7747. // drug.Total = drug.Total - num
  7748. // service.UpdateBaseDrugLib(&drug)
  7749. // }
  7750. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7751. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7752. // if num2 > advice.PrescribingNumber {
  7753. // num = num2 - advice.PrescribingNumber
  7754. // drug.Total = drug.Total + num
  7755. // service.UpdateBaseDrugLib(&drug)
  7756. // } else if num2 < advice.PrescribingNumber {
  7757. // num = advice.PrescribingNumber - num2
  7758. // drug.Total = drug.Total - num
  7759. // service.UpdateBaseDrugLib(&drug)
  7760. // }
  7761. //
  7762. // }
  7763. //
  7764. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7765. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7766. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7767. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7768. // if num1 > num2 {
  7769. // num = num1 - num2
  7770. // drug.Total = drug.Total + num
  7771. // service.UpdateBaseDrugLib(&drug)
  7772. // } else if num1 < num2 {
  7773. // num = num2 - num1
  7774. // drug.Total = drug.Total - num
  7775. // service.UpdateBaseDrugLib(&drug)
  7776. // }
  7777. //
  7778. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7779. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7780. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7781. // if hisAdvice.PrescribingNumber > num2 {
  7782. // num = hisAdvice.PrescribingNumber - num2
  7783. // drug.Total = drug.Total + num
  7784. // service.UpdateBaseDrugLib(&drug)
  7785. // } else if num2 < advice.PrescribingNumber {
  7786. // num = num2 - hisAdvice.PrescribingNumber
  7787. // drug.Total = drug.Total - num
  7788. // service.UpdateBaseDrugLib(&drug)
  7789. // }
  7790. //
  7791. // }
  7792. // }
  7793. // }
  7794. //}
  7795. //
  7796. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7797. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7798. // advice.ExecutionTime = execution_time
  7799. //}
  7800. //
  7801. //
  7802. //
  7803. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7804. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7805. // advice.ExecutionStaff = execution_staff
  7806. //}
  7807. //
  7808. //
  7809. //
  7810. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7811. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7812. // advice.ExecutionState = execution_state
  7813. //}
  7814. //
  7815. //
  7816. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7817. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7818. // advice.CheckTime = check_time
  7819. //}
  7820. //
  7821. //
  7822. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7823. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7824. // advice.CheckState = check_state
  7825. //}
  7826. //
  7827. //
  7828. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7829. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7830. // advice.Checker = checker
  7831. //}
  7832. //
  7833. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7834. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7835. // advice.StartTime = start_time
  7836. //}
  7837. return 0
  7838. }
  7839. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7840. project.ExecutionStaff = 0
  7841. project.ExecutionState = 2
  7842. project.ExecutionTime = 0
  7843. project.Checker = 0
  7844. project.CheckState = 2
  7845. project.CheckTime = 0
  7846. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7847. id := int64(json["id"].(float64))
  7848. project.ID = id
  7849. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7850. project.ExecutionStaff = temp_project.ExecutionStaff
  7851. project.ExecutionState = temp_project.ExecutionState
  7852. project.ExecutionTime = temp_project.ExecutionTime
  7853. project.Checker = temp_project.Checker
  7854. project.CheckState = temp_project.CheckState
  7855. project.CheckTime = temp_project.CheckTime
  7856. project.TeamId = temp_project.TeamId
  7857. }
  7858. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7859. types := int64(json["type"].(float64))
  7860. project.Type = types
  7861. }
  7862. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7863. project_id := int64(json["project_id"].(float64))
  7864. project.ProjectId = project_id
  7865. }
  7866. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7867. team_id := int64(json["team_id"].(float64))
  7868. project.TeamId = team_id
  7869. }
  7870. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7871. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7872. project.Price = price
  7873. }
  7874. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7875. total, _ := json["total"].(string)
  7876. //totals, _ := strconv.ParseInt(total, 10, 64)
  7877. project.Count = total
  7878. }
  7879. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7880. medical_code, _ := json["medical_code"].(string)
  7881. project.MedListCodg = medical_code
  7882. }
  7883. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7884. single_dose, _ := json["single_dose"].(string)
  7885. project.SingleDose = single_dose
  7886. }
  7887. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7888. delivery_way, _ := json["delivery_way"].(string)
  7889. project.DeliveryWay = delivery_way
  7890. }
  7891. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7892. execution_frequency, _ := json["execution_frequency"].(string)
  7893. project.ExecutionFrequency = execution_frequency
  7894. }
  7895. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7896. remark, _ := json["remark"].(string)
  7897. project.Remark = remark
  7898. }
  7899. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7900. day, _ := json["number_days"].(string)
  7901. project.Day = day
  7902. }
  7903. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7904. unit, _ := json["unit"].(string)
  7905. project.Unit = unit
  7906. }
  7907. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7908. // frequency_type := int64(json["frequency_type"].(float64))
  7909. // project.FrequencyType = frequency_type
  7910. //}
  7911. //
  7912. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7913. // day_count := int64(json["day_count"].(float64))
  7914. // project.DayCount = day_count
  7915. //}
  7916. //
  7917. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7918. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7919. // week_day, _ := json["week_day"].(string)
  7920. // project.WeekDay = week_day
  7921. //}
  7922. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7923. //
  7924. //if project.ID == 0 {
  7925. // if stockConfig.IsOpen == 1 {
  7926. // if project.Type == 3 {
  7927. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7928. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7929. // good.Total = good.Total - f_count
  7930. // service.UpdateGoodInfo(&good)
  7931. // }
  7932. // }
  7933. //
  7934. //} else {
  7935. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7936. //
  7937. // if stockConfig.IsOpen == 1 {
  7938. // if project.Type == 3 {
  7939. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7940. // if project.Count < temp_project.Count {
  7941. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7942. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7943. //
  7944. // other_count := f_count_two - f_count_one
  7945. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7946. // good.Total = good.Total + other_count_two
  7947. // service.UpdateGoodInfo(&good)
  7948. // } else if project.Count > temp_project.Count {
  7949. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7950. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7951. //
  7952. // other_count := f_count_one - f_count_two
  7953. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7954. // good.Total = good.Total - other_count_two
  7955. // service.UpdateGoodInfo(&good)
  7956. // }
  7957. //
  7958. // }
  7959. // }
  7960. //
  7961. //}
  7962. return 0
  7963. }
  7964. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7965. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7966. utils.ErrorLog("drug_name")
  7967. return enums.ErrorCodeParamWrong
  7968. }
  7969. adviceName, _ := json["drug_name"].(string)
  7970. if len(adviceName) == 0 {
  7971. utils.ErrorLog("len(advice_name) == 0")
  7972. return enums.ErrorCodeParamWrong
  7973. }
  7974. advice.AdviceName = adviceName
  7975. adviceDesc, _ := json["advice_desc"].(string)
  7976. advice.AdviceDesc = adviceDesc
  7977. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7978. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7979. advice.DrugSpec = drugSpec
  7980. }
  7981. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7982. remark, _ := json["remark"].(string)
  7983. advice.Remark = remark
  7984. }
  7985. if json["id"] == nil {
  7986. advice.DrugId = 0
  7987. } else {
  7988. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7989. drug_id := int64(json["id"].(float64))
  7990. advice.DrugId = drug_id
  7991. }
  7992. }
  7993. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7994. groupno := int64(json["groupno"].(float64))
  7995. advice.Groupno = groupno
  7996. }
  7997. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7998. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7999. advice.IsSelfDrug = is_self_drug
  8000. }
  8001. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8002. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8003. drug_way_count, _ := json["drug_way_count"].(string)
  8004. advice.DrugWayCount = drug_way_count
  8005. }
  8006. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8007. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8008. advice.HospApprFlag = hosp_appr_flag
  8009. }
  8010. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8011. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8012. advice.PrescribingNumber = prescribingNumber
  8013. }
  8014. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8015. // frequency_type := int64(json["frequency_type"].(float64))
  8016. // advice.FrequencyType = frequency_type
  8017. //}
  8018. //
  8019. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8020. // day_count := int64(json["day_count"].(float64))
  8021. // advice.DayCount = day_count
  8022. //}
  8023. //
  8024. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8025. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8026. // week_day, _ := json["week_day"].(string)
  8027. // advice.WeekDay = week_day
  8028. //}
  8029. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8030. drugSpecUnit, _ := json["min_unit"].(string)
  8031. advice.DrugSpecUnit = drugSpecUnit
  8032. }
  8033. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8034. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8035. advice.SingleDose = singleDose
  8036. }
  8037. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8038. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8039. advice.SingleDoseUnit = singleDoseUnit
  8040. }
  8041. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8042. deliveryWay, _ := json["delivery_way"].(string)
  8043. advice.DeliveryWay = deliveryWay
  8044. }
  8045. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8046. executionFrequency, _ := json["execution_frequency"].(string)
  8047. advice.ExecutionFrequency = executionFrequency
  8048. }
  8049. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8050. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8051. advice.Price = price
  8052. }
  8053. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8054. med_list_codg, _ := json["medical_insurance_number"].(string)
  8055. advice.MedListCodg = med_list_codg
  8056. }
  8057. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8058. day := int64(json["day"].(float64))
  8059. advice.Day = day
  8060. }
  8061. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8062. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8063. advice.PrescribingNumberUnit = prescribingNumberUnit
  8064. }
  8065. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8066. advice_id := int64(json["advice_id"].(float64))
  8067. advice.ID = advice_id
  8068. if advice.ID > 0 {
  8069. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8070. if err == nil {
  8071. if hisAdvice.ID > 0 {
  8072. advice.ExecutionTime = hisAdvice.ExecutionTime
  8073. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8074. advice.ExecutionState = hisAdvice.ExecutionState
  8075. advice.CheckTime = hisAdvice.CheckTime
  8076. advice.Checker = hisAdvice.Checker
  8077. advice.DrugCode = hisAdvice.DrugCode
  8078. advice.CheckState = hisAdvice.CheckState
  8079. advice.StartTime = hisAdvice.StartTime
  8080. advice.HospApprFlag = hisAdvice.HospApprFlag
  8081. advice.IsMedicine = hisAdvice.IsMedicine
  8082. if hisAdvice.UserOrgId == 10028 {
  8083. 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 {
  8084. advice.ExecutionTime = 0
  8085. advice.ExecutionStaff = 0
  8086. advice.ExecutionState = 2
  8087. advice.CheckTime = 0
  8088. advice.Checker = 0
  8089. advice.CheckState = 2
  8090. }
  8091. } else {
  8092. 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 {
  8093. advice.ExecutionTime = 0
  8094. advice.ExecutionStaff = 0
  8095. advice.ExecutionState = 2
  8096. advice.CheckTime = 0
  8097. advice.Checker = 0
  8098. advice.CheckState = 2
  8099. //advice.UpdatedTime = time.Now().Unix()
  8100. advice.CreatedTime = hisAdvice.CreatedTime
  8101. advice.UpdatedTime = time.Now().Unix()
  8102. } else {
  8103. advice.CreatedTime = hisAdvice.CreatedTime
  8104. advice.UpdatedTime = hisAdvice.UpdatedTime
  8105. }
  8106. }
  8107. //advice.Groupno = hisAdvice.Groupno
  8108. } else {
  8109. advice.IsMedicine = 0
  8110. ctime := time.Now().Unix()
  8111. advice.CreatedTime = ctime
  8112. advice.UpdatedTime = ctime
  8113. }
  8114. }
  8115. } else {
  8116. advice.IsMedicine = 0
  8117. ctime := time.Now().Unix()
  8118. advice.CreatedTime = ctime
  8119. advice.UpdatedTime = ctime
  8120. }
  8121. }
  8122. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8123. //
  8124. //if drugStockConfig.IsOpen == 1 {
  8125. //
  8126. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8127. // if advice.ID == 0 { //医嘱不存在
  8128. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8129. // drug.Total = drug.Total - advice.PrescribingNumber
  8130. // service.UpdateBaseDrugLib(&drug)
  8131. //
  8132. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8133. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8134. // drug.Total = drug.Total - num
  8135. // service.UpdateBaseDrugLib(&drug)
  8136. // }
  8137. //
  8138. // } else if advice.ID > 0 { //医嘱存在
  8139. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8140. // var num float64
  8141. //
  8142. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8143. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8144. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8145. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8146. // drug.Total = drug.Total + num
  8147. // service.UpdateBaseDrugLib(&drug)
  8148. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8149. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8150. // drug.Total = drug.Total - num
  8151. // service.UpdateBaseDrugLib(&drug)
  8152. // }
  8153. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8154. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8155. // if num2 > advice.PrescribingNumber {
  8156. // num = num2 - advice.PrescribingNumber
  8157. // drug.Total = drug.Total + num
  8158. // service.UpdateBaseDrugLib(&drug)
  8159. // } else if num2 < advice.PrescribingNumber {
  8160. // num = advice.PrescribingNumber - num2
  8161. // drug.Total = drug.Total - num
  8162. // service.UpdateBaseDrugLib(&drug)
  8163. // }
  8164. //
  8165. // }
  8166. //
  8167. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8168. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8169. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8170. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8171. // if num1 > num2 {
  8172. // num = num1 - num2
  8173. // drug.Total = drug.Total + num
  8174. // service.UpdateBaseDrugLib(&drug)
  8175. // } else if num1 < num2 {
  8176. // num = num2 - num1
  8177. // drug.Total = drug.Total - num
  8178. // service.UpdateBaseDrugLib(&drug)
  8179. // }
  8180. //
  8181. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8182. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8183. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8184. // if hisAdvice.PrescribingNumber > num2 {
  8185. // num = hisAdvice.PrescribingNumber - num2
  8186. // drug.Total = drug.Total + num
  8187. // service.UpdateBaseDrugLib(&drug)
  8188. // } else if num2 < advice.PrescribingNumber {
  8189. // num = num2 - hisAdvice.PrescribingNumber
  8190. // drug.Total = drug.Total - num
  8191. // service.UpdateBaseDrugLib(&drug)
  8192. // }
  8193. //
  8194. // }
  8195. // }
  8196. // }
  8197. //}
  8198. //
  8199. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8200. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8201. // advice.ExecutionTime = execution_time
  8202. //}
  8203. //
  8204. //
  8205. //
  8206. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8207. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8208. // advice.ExecutionStaff = execution_staff
  8209. //}
  8210. //
  8211. //
  8212. //
  8213. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8214. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8215. // advice.ExecutionState = execution_state
  8216. //}
  8217. //
  8218. //
  8219. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8220. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8221. // advice.CheckTime = check_time
  8222. //}
  8223. //
  8224. //
  8225. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8226. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8227. // advice.CheckState = check_state
  8228. //}
  8229. //
  8230. //
  8231. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8232. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8233. // advice.Checker = checker
  8234. //}
  8235. //
  8236. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8237. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8238. // advice.StartTime = start_time
  8239. //}
  8240. return 0
  8241. }
  8242. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8243. project.ExecutionStaff = 0
  8244. project.ExecutionState = 2
  8245. project.ExecutionTime = 0
  8246. project.Checker = 0
  8247. project.CheckState = 2
  8248. project.CheckTime = 0
  8249. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8250. id := int64(json["id"].(float64))
  8251. project.ID = id
  8252. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8253. project.ExecutionStaff = temp_project.ExecutionStaff
  8254. project.ExecutionState = temp_project.ExecutionState
  8255. project.ExecutionTime = temp_project.ExecutionTime
  8256. project.Checker = temp_project.Checker
  8257. project.CheckState = temp_project.CheckState
  8258. project.CheckTime = temp_project.CheckTime
  8259. project.TeamId = temp_project.TeamId
  8260. }
  8261. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8262. types := int64(json["type"].(float64))
  8263. project.Type = types
  8264. }
  8265. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8266. project_id := int64(json["project_id"].(float64))
  8267. project.ProjectId = project_id
  8268. }
  8269. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8270. team_id := int64(json["team_id"].(float64))
  8271. project.TeamId = team_id
  8272. }
  8273. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8274. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8275. project.Price = price
  8276. }
  8277. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8278. total, _ := json["total"].(string)
  8279. //totals, _ := strconv.ParseInt(total, 10, 64)
  8280. project.Count = total
  8281. }
  8282. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8283. medical_code, _ := json["medical_code"].(string)
  8284. project.MedListCodg = medical_code
  8285. }
  8286. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8287. single_dose, _ := json["single_dose"].(string)
  8288. project.SingleDose = single_dose
  8289. }
  8290. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8291. delivery_way, _ := json["delivery_way"].(string)
  8292. project.DeliveryWay = delivery_way
  8293. }
  8294. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8295. execution_frequency, _ := json["execution_frequency"].(string)
  8296. project.ExecutionFrequency = execution_frequency
  8297. }
  8298. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8299. remark, _ := json["remark"].(string)
  8300. project.Remark = remark
  8301. }
  8302. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8303. day, _ := json["number_days"].(string)
  8304. project.Day = day
  8305. }
  8306. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8307. unit, _ := json["unit"].(string)
  8308. project.Unit = unit
  8309. }
  8310. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8311. // frequency_type := int64(json["frequency_type"].(float64))
  8312. // project.FrequencyType = frequency_type
  8313. //}
  8314. //
  8315. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8316. // day_count := int64(json["day_count"].(float64))
  8317. // project.DayCount = day_count
  8318. //}
  8319. //
  8320. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8321. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8322. // week_day, _ := json["week_day"].(string)
  8323. // project.WeekDay = week_day
  8324. //}
  8325. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8326. //
  8327. //if project.ID == 0 {
  8328. // if stockConfig.IsOpen == 1 {
  8329. // if project.Type == 3 {
  8330. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8331. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8332. // good.Total = good.Total - f_count
  8333. // service.UpdateGoodInfo(&good)
  8334. // }
  8335. // }
  8336. //
  8337. //} else {
  8338. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8339. //
  8340. // if stockConfig.IsOpen == 1 {
  8341. // if project.Type == 3 {
  8342. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8343. // if project.Count < temp_project.Count {
  8344. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8345. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8346. //
  8347. // other_count := f_count_two - f_count_one
  8348. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8349. // good.Total = good.Total + other_count_two
  8350. // service.UpdateGoodInfo(&good)
  8351. // } else if project.Count > temp_project.Count {
  8352. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8353. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8354. //
  8355. // other_count := f_count_one - f_count_two
  8356. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8357. // good.Total = good.Total - other_count_two
  8358. // service.UpdateGoodInfo(&good)
  8359. // }
  8360. //
  8361. // }
  8362. // }
  8363. //
  8364. //}
  8365. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8366. id := int64(json["id"].(float64))
  8367. if id > 0 {
  8368. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8369. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8370. fmt.Println("666666")
  8371. project.Mtime = time.Now().Unix()
  8372. project.Ctime = temp_project.Ctime
  8373. } else {
  8374. project.Mtime = temp_project.Mtime
  8375. project.Ctime = temp_project.Ctime
  8376. }
  8377. } else {
  8378. ctime := time.Now().Unix()
  8379. project.Mtime = ctime
  8380. project.Ctime = ctime
  8381. }
  8382. }
  8383. return 0
  8384. }
  8385. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8386. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8387. id := int64(json["id"].(float64))
  8388. additionalCharge.ID = id
  8389. }
  8390. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8391. item_id := int64(json["item_id"].(float64))
  8392. additionalCharge.ItemId = item_id
  8393. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8394. if config.ID > 0 {
  8395. if len(config.Code) > 0 {
  8396. additionalCharge.MedListCodg = config.Code
  8397. }
  8398. }
  8399. }
  8400. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8401. // price := int64(json["price"].(float64))
  8402. // formatInt_price := strconv.FormatInt(price, 10)
  8403. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8404. // additionalCharge.Price = float_price
  8405. // }
  8406. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8407. // price := int64(json["price"].(float64))
  8408. // formatInt_price := strconv.FormatInt(price, 10)
  8409. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8410. // additionalCharge.Price = float_price
  8411. //}
  8412. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8413. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8414. additionalCharge.Price = price
  8415. }
  8416. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8417. count, _ := json["count"].(string)
  8418. counts, _ := strconv.ParseInt(count, 10, 64)
  8419. additionalCharge.Count = counts
  8420. }
  8421. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8422. item_name, _ := json["item_name"].(string)
  8423. additionalCharge.ItemName = item_name
  8424. }
  8425. return 0
  8426. }
  8427. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8428. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8429. utils.ErrorLog("drug_name")
  8430. return enums.ErrorCodeParamWrong
  8431. }
  8432. adviceName, _ := json["drug_name"].(string)
  8433. if len(adviceName) == 0 {
  8434. utils.ErrorLog("len(advice_name) == 0")
  8435. return enums.ErrorCodeParamWrong
  8436. }
  8437. advice.AdviceName = adviceName
  8438. adviceDesc, _ := json["advice_desc"].(string)
  8439. advice.AdviceDesc = adviceDesc
  8440. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8441. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8442. advice.DrugSpec = drugSpec
  8443. }
  8444. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8445. remark, _ := json["remark"].(string)
  8446. advice.Remark = remark
  8447. }
  8448. if json["id"] == nil {
  8449. advice.DrugId = 0
  8450. } else {
  8451. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8452. drug_id := int64(json["id"].(float64))
  8453. advice.DrugId = drug_id
  8454. }
  8455. }
  8456. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8457. groupno := int64(json["groupno"].(float64))
  8458. advice.Groupno = groupno
  8459. }
  8460. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8461. drugSpecUnit, _ := json["min_unit"].(string)
  8462. advice.DrugSpecUnit = drugSpecUnit
  8463. }
  8464. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8465. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8466. advice.SingleDose = singleDose
  8467. }
  8468. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8469. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8470. advice.SingleDoseUnit = singleDoseUnit
  8471. }
  8472. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8473. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8474. advice.PrescribingNumber = prescribingNumber
  8475. }
  8476. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8477. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8478. advice.PrescribingNumberUnit = prescribingNumberUnit
  8479. }
  8480. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8481. deliveryWay, _ := json["delivery_way"].(string)
  8482. advice.DeliveryWay = deliveryWay
  8483. }
  8484. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8485. executionFrequency, _ := json["execution_frequency"].(string)
  8486. advice.ExecutionFrequency = executionFrequency
  8487. }
  8488. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8489. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8490. advice.Price = price
  8491. }
  8492. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8493. med_list_codg, _ := json["medical_insurance_number"].(string)
  8494. advice.MedListCodg = med_list_codg
  8495. }
  8496. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8497. day := int64(json["day"].(float64))
  8498. advice.Day = day
  8499. }
  8500. advice.FrequencyType = 1
  8501. return 0
  8502. }
  8503. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8504. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8505. types := int64(json["type"].(float64))
  8506. project.Type = types
  8507. }
  8508. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8509. project_id := int64(json["project_id"].(float64))
  8510. project.ProjectId = project_id
  8511. }
  8512. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8513. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8514. project.Price = price
  8515. }
  8516. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8517. total, _ := json["total"].(string)
  8518. //totals, _ := strconv.ParseInt(total, 10, 64)
  8519. project.Count = total
  8520. }
  8521. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8522. medical_code, _ := json["medical_code"].(string)
  8523. project.MedListCodg = medical_code
  8524. }
  8525. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8526. single_dose, _ := json["single_dose"].(string)
  8527. project.SingleDose = single_dose
  8528. }
  8529. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8530. delivery_way, _ := json["delivery_way"].(string)
  8531. project.DeliveryWay = delivery_way
  8532. }
  8533. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8534. execution_frequency, _ := json["execution_frequency"].(string)
  8535. project.ExecutionFrequency = execution_frequency
  8536. }
  8537. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8538. remark, _ := json["remark"].(string)
  8539. project.Remark = remark
  8540. }
  8541. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8542. day, _ := json["number_days"].(string)
  8543. project.Day = day
  8544. }
  8545. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8546. unit, _ := json["unit"].(string)
  8547. project.Unit = unit
  8548. }
  8549. project.FrequencyType = 1
  8550. return 0
  8551. }
  8552. func (c *HisApiController) GetHisOrderListTwo() {
  8553. start_time := c.GetString("start_time")
  8554. end_time := c.GetString("end_time")
  8555. timeLayout := "2006-01-02"
  8556. loc, _ := time.LoadLocation("Local")
  8557. var startTime int64
  8558. if len(start_time) > 0 {
  8559. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8560. if err != nil {
  8561. //fmt.Println(err)
  8562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8563. return
  8564. }
  8565. startTime = theTime.Unix()
  8566. }
  8567. var endTime int64
  8568. if len(end_time) > 0 {
  8569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8570. if err != nil {
  8571. utils.ErrorLog(err.Error())
  8572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8573. return
  8574. }
  8575. endTime = theTime.Unix()
  8576. }
  8577. adminUser := c.GetAdminUserInfo()
  8578. org_id := adminUser.CurrentOrgId
  8579. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8580. if err == nil {
  8581. c.ServeSuccessJSON(map[string]interface{}{
  8582. "order2": order,
  8583. })
  8584. } else {
  8585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8586. return
  8587. }
  8588. }
  8589. func (c *HisApiController) GetHisOrderList() {
  8590. page, _ := c.GetInt64("page", -1)
  8591. limit, _ := c.GetInt64("limit", -1)
  8592. start_time := c.GetString("start_time")
  8593. end_time := c.GetString("end_time")
  8594. types, _ := c.GetInt64("type", 0)
  8595. keywords := c.GetString("keywords")
  8596. p_type, _ := c.GetInt64("p_type", 0)
  8597. sort_type, _ := c.GetInt64("sort_type", 0)
  8598. charge_type, _ := c.GetInt64("charge_type", 0)
  8599. sch_type, _ := c.GetInt64("sch_type", 0)
  8600. zone_type, _ := c.GetInt64("zone_type", 0)
  8601. med_type, _ := c.GetInt64("med_type", 0)
  8602. timeLayout := "2006-01-02"
  8603. loc, _ := time.LoadLocation("Local")
  8604. var startTime int64
  8605. if len(start_time) > 0 {
  8606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8607. if err != nil {
  8608. //fmt.Println(err)
  8609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8610. return
  8611. }
  8612. startTime = theTime.Unix()
  8613. }
  8614. var endTime int64
  8615. if len(end_time) > 0 {
  8616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8617. if err != nil {
  8618. utils.ErrorLog(err.Error())
  8619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8620. return
  8621. }
  8622. endTime = theTime.Unix()
  8623. }
  8624. adminUser := c.GetAdminUserInfo()
  8625. org_id := adminUser.CurrentOrgId
  8626. 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)
  8627. for _, item := range order {
  8628. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8629. item.DoctorName = info.Doctor
  8630. item.DepartmentName = info.XtHisDepartment.Name
  8631. }
  8632. if err == nil {
  8633. c.ServeSuccessJSON(map[string]interface{}{
  8634. "order": order,
  8635. "total": total,
  8636. })
  8637. } else {
  8638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8639. return
  8640. }
  8641. }
  8642. func (c *HisApiController) GetHisOrder() {
  8643. patient_id, _ := c.GetInt64("patient_id", 0)
  8644. number := c.GetString("number")
  8645. adminInfo := c.GetAdminUserInfo()
  8646. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8647. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8648. if err == nil {
  8649. c.ServeSuccessJSON(map[string]interface{}{
  8650. "order": order,
  8651. "prescription": prescriptions,
  8652. })
  8653. } else {
  8654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8655. return
  8656. }
  8657. }
  8658. func (c *HisApiController) GetHisPrescriptionList() {
  8659. record_date := c.GetString("record_date")
  8660. keywords := c.GetString("keywords")
  8661. page, _ := c.GetInt64("page")
  8662. limit, _ := c.GetInt64("limit")
  8663. sch_type, _ := c.GetInt64("sch_type")
  8664. timeLayout := "2006-01-02"
  8665. loc, _ := time.LoadLocation("Local")
  8666. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8667. if err != nil {
  8668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8669. return
  8670. }
  8671. recordDateTime := theTime.Unix()
  8672. adminInfo := c.GetAdminUserInfo()
  8673. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8674. //adminInfo := c.GetAdminUserInfo()
  8675. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8676. //fmt.Println(prescriptionOrder)
  8677. if err == nil {
  8678. c.ServeSuccessJSON(map[string]interface{}{
  8679. "order": prescriptionOrder,
  8680. "total": total,
  8681. })
  8682. } else {
  8683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8684. return
  8685. }
  8686. }
  8687. func (c *HisApiController) GetHisPrescriptionInfo() {
  8688. id, _ := c.GetInt64("id")
  8689. adminInfo := c.GetAdminUserInfo()
  8690. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8691. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8692. if err == nil {
  8693. c.ServeSuccessJSON(map[string]interface{}{
  8694. "order": prescriptionOrder,
  8695. "prescription": prescription,
  8696. })
  8697. } else {
  8698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8699. return
  8700. }
  8701. }
  8702. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8703. adminUser := c.GetAdminUserInfo()
  8704. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8705. c.ServeSuccessJSON(map[string]interface{}{
  8706. "config": config,
  8707. })
  8708. }
  8709. type ResultTwo struct {
  8710. ErrMsg interface{} `json:"err_msg"`
  8711. InfRefmsgid string `json:"inf_refmsgid"`
  8712. Infcode int64 `json:"infcode"`
  8713. Output struct {
  8714. Baseinfo struct {
  8715. Age float64 `json:"age"`
  8716. Brdy string `json:"brdy"`
  8717. Certno string `json:"certno"`
  8718. Gend string `json:"gend"`
  8719. Naty string `json:"naty"`
  8720. PsnCertType string `json:"psn_cert_type"`
  8721. PsnName string `json:"psn_name"`
  8722. PsnNo string `json:"psn_no"`
  8723. } `json:"baseinfo"`
  8724. Idetinfo []interface{} `json:"idetinfo"`
  8725. Iinfo []struct {
  8726. Balc float64 `json:"balc"`
  8727. CvlservFlag string `json:"cvlserv_flag"`
  8728. EmpName string `json:"emp_name"`
  8729. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8730. Insutype string `json:"insutype"`
  8731. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8732. PausInsuDate interface{} `json:"paus_insu_date"`
  8733. PsnInsuDate string `json:"psn_insu_date"`
  8734. PsnInsuStas string `json:"psn_insu_stas"`
  8735. PsnType string `json:"psn_type"`
  8736. } `json:"insuinfo"`
  8737. } `json:"output"`
  8738. RefmsgTime string `json:"refmsg_time"`
  8739. RespondTime string `json:"respond_time"`
  8740. Signtype interface{} `json:"signtype"`
  8741. WarnInfo interface{} `json:"warn_info"`
  8742. }
  8743. type ResultThree struct {
  8744. Cainfo interface{} `json:"cainfo"`
  8745. ErrMsg interface{} `json:"err_msg"`
  8746. InfRefmsgid string `json:"inf_refmsgid"`
  8747. Infcode int64 `json:"infcode"`
  8748. Output struct {
  8749. Data struct {
  8750. IptOtpNo string `json:"ipt_otp_no"`
  8751. MdtrtID string `json:"mdtrt_id"`
  8752. PsnNo string `json:"psn_no"`
  8753. } `json:"data"`
  8754. } `json:"output"`
  8755. RefmsgTime string `json:"refmsg_time"`
  8756. RespondTime string `json:"respond_time"`
  8757. Signtype interface{} `json:"signtype"`
  8758. WarnMsg interface{} `json:"warn_msg"`
  8759. }
  8760. type ResultFour struct {
  8761. Cainfo string `json:"cainfo"`
  8762. ErrMsg string `json:"err_msg"`
  8763. InfRefmsgid string `json:"inf_refmsgid"`
  8764. Infcode int64 `json:"infcode"`
  8765. Output struct {
  8766. Result []struct {
  8767. BasMednFlag string `json:"bas_medn_flag"`
  8768. ChldMedcFlag string `json:"chld_medc_flag"`
  8769. ChrgitmLv string `json:"chrgitm_lv"`
  8770. Cnt float64 `json:"cnt"`
  8771. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8772. DrtReimFlag string `json:"drt_reim_flag"`
  8773. FeedetlSn string `json:"feedetl_sn"`
  8774. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8775. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8776. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8777. ListSpItemFlag string `json:"list_sp_item_flag"`
  8778. LmtUsedFlag string `json:"lmt_used_flag"`
  8779. MedChrgitmType string `json:"med_chrgitm_type"`
  8780. Memo string `json:"memo"`
  8781. OverlmtAmt float64 `json:"overlmt_amt"`
  8782. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8783. Pric float64 `json:"pric"`
  8784. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8785. SelfpayProp float64 `json:"selfpay_prop"`
  8786. } `json:"result"`
  8787. } `json:"output"`
  8788. RefmsgTime string `json:"refmsg_time"`
  8789. RespondTime string `json:"respond_time"`
  8790. Signtype string `json:"signtype"`
  8791. WarnMsg string `json:"warn_msg"`
  8792. }
  8793. type ResultFive struct {
  8794. Insutype string `json:"insutype"`
  8795. }
  8796. type ResultSix struct {
  8797. Cainfo interface{} `json:"cainfo"`
  8798. ErrMsg interface{} `json:"err_msg"`
  8799. InfRefmsgid string `json:"inf_refmsgid"`
  8800. Infcode int64 `json:"infcode"`
  8801. Output struct {
  8802. } `json:"output"`
  8803. RefmsgTime string `json:"refmsg_time"`
  8804. RespondTime string `json:"respond_time"`
  8805. Signtype interface{} `json:"signtype"`
  8806. WarnMsg interface{} `json:"warn_msg"`
  8807. }
  8808. type ResultSeven struct {
  8809. Cainfo string `json:"cainfo"`
  8810. ErrMsg string `json:"err_msg"`
  8811. InfRefmsgid string `json:"inf_refmsgid"`
  8812. Infcode int64 `json:"infcode"`
  8813. Output struct {
  8814. Setldetail []interface{} `json:"setldetail"`
  8815. Setlinfo struct {
  8816. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8817. AcctPay float64 `json:"acct_pay"`
  8818. ActPayDedc float64 `json:"act_pay_dedc"`
  8819. Age float64 `json:"age"`
  8820. Balc float64 `json:"balc"`
  8821. Brdy string `json:"brdy"`
  8822. Certno string `json:"certno"`
  8823. ClrOptins string `json:"clr_optins"`
  8824. ClrType string `json:"clr_type"`
  8825. ClrWay string `json:"clr_way"`
  8826. CvlservFlag string `json:"cvlserv_flag"`
  8827. CvlservPay float64 `json:"cvlserv_pay"`
  8828. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8829. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8830. Gend string `json:"gend"`
  8831. HifesPay float64 `json:"hifes_pay"`
  8832. HifmiPay float64 `json:"hifmi_pay"`
  8833. HifobPay float64 `json:"hifob_pay"`
  8834. HifpPay float64 `json:"hifp_pay"`
  8835. HospPartAmt float64 `json:"hosp_part_amt"`
  8836. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8837. Insutype string `json:"insutype"`
  8838. MafPay float64 `json:"maf_pay"`
  8839. MdtrtCertType string `json:"mdtrt_cert_type"`
  8840. MdtrtID string `json:"mdtrt_id"`
  8841. MedType string `json:"med_type"`
  8842. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8843. MedinsSetlID string `json:"medins_setl_id"`
  8844. Naty string `json:"naty"`
  8845. OthPay float64 `json:"oth_pay"`
  8846. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8847. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8848. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8849. PsnCashPay float64 `json:"psn_cash_pay"`
  8850. PsnCertType string `json:"psn_cert_type"`
  8851. PsnName string `json:"psn_name"`
  8852. PsnNo string `json:"psn_no"`
  8853. PsnPartAmt float64 `json:"psn_part_amt"`
  8854. PsnType string `json:"psn_type"`
  8855. SetlID string `json:"setl_id"`
  8856. SetlTime string `json:"setl_time"`
  8857. } `json:"setlinfo"`
  8858. } `json:"output"`
  8859. RefmsgTime string `json:"refmsg_time"`
  8860. RespondTime string `json:"respond_time"`
  8861. Signtype interface{} `json:"signtype"`
  8862. WarnMsg interface{} `json:"warn_msg"`
  8863. }
  8864. type ResultEight struct {
  8865. Cainfo string `json:"cainfo"`
  8866. ErrMsg string `json:"err_msg"`
  8867. InfRefmsgid string `json:"inf_refmsgid"`
  8868. Infcode int64 `json:"infcode"`
  8869. Output struct {
  8870. Stmtinfo struct {
  8871. SetlOptins string `json:"setl_optins"`
  8872. StmtRslt string `json:"stmt_rslt"`
  8873. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8874. } `json:"stmtinfo"`
  8875. } `json:"output"`
  8876. RefmsgTime string `json:"refmsg_time"`
  8877. RespondTime string `json:"respond_time"`
  8878. Signtype interface{} `json:"signtype"`
  8879. WarnMsg interface{} `json:"warn_msg"`
  8880. }
  8881. type ResultNine struct {
  8882. Cainfo string `json:"cainfo"`
  8883. ErrMsg string `json:"err_msg"`
  8884. InfRefmsgid string `json:"inf_refmsgid"`
  8885. Infcode int64 `json:"infcode"`
  8886. Output struct {
  8887. FileQuryNo string `json:"file_qury_no"`
  8888. } `json:"output"`
  8889. RefmsgTime string `json:"refmsg_time"`
  8890. RespondTime string `json:"respond_time"`
  8891. Signtype interface{} `json:"signtype"`
  8892. WarnMsg interface{} `json:"warn_msg"`
  8893. }
  8894. type ResultTen struct {
  8895. Cainfo string `json:"cainfo"`
  8896. ErrMsg string `json:"err_msg"`
  8897. InfRefmsgid string `json:"inf_refmsgid"`
  8898. Infcode int64 `json:"infcode"`
  8899. Output struct {
  8900. DldEndtime string `json:"dld_endtime"`
  8901. FileQuryNo string `json:"file_qury_no"`
  8902. Filename string `json:"filename"`
  8903. } `json:"output"`
  8904. RefmsgTime string `json:"refmsg_time"`
  8905. RespondTime string `json:"respond_time"`
  8906. Signtype interface{} `json:"signtype"`
  8907. WarnMsg interface{} `json:"warn_msg"`
  8908. }
  8909. type ResultEleven struct {
  8910. Cainfo string `json:"cainfo"`
  8911. ErrMsg string `json:"err_msg"`
  8912. InfRefmsgid string `json:"inf_refmsgid"`
  8913. Infcode int64 `json:"infcode"`
  8914. Output struct {
  8915. Setlinfo struct {
  8916. FixmedinsName string `json:"fixmedins_name"`
  8917. FixmedinsCode string `json:"fixmedins_code"`
  8918. PsnNo string `json:"psn_no"`
  8919. PsnName string `json:"psn_name"`
  8920. HifobPay float64 `json:"hifob_pay"`
  8921. Gend string `json:"gend"`
  8922. Brdy string `json:"brdy"`
  8923. PsnCertType string `json:"psn_cert_type"`
  8924. PsnType string `json:"psn_type"`
  8925. EmpName string `json:"emp_name"`
  8926. Certno string `json:"certno"`
  8927. Insutype string `json:"insutype"`
  8928. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8929. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8930. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8931. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8932. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8933. ActPayDedc float64 `json:"act_pay_dedc"`
  8934. HifpPay float64 `json:"hifp_pay"`
  8935. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8936. CvlservPay float64 `json:"cvlserv_pay"`
  8937. HifesPay float64 `json:"hifes_pay"`
  8938. HifmiPay float64 `json:"hifmi_pay"`
  8939. MafPay float64 `json:"maf_pay"`
  8940. OthPay float64 `json:"oth_pay"`
  8941. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8942. PsnPay float64 `json:"psn_pay"`
  8943. AcctPay float64 `json:"acct_pay"`
  8944. CashPayamt float64 `json:"cash_payamt"`
  8945. Balc float64 `json:"balc"`
  8946. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8947. MedinsSetlId string `json:"medins_setl_id"`
  8948. RefdSetlFlag string `json:"refd_setl_flag"`
  8949. SetlTime string `json:"setl_time"`
  8950. MedType string `json:"med_type"`
  8951. } `json:"setlinfo"`
  8952. } `json:"output"`
  8953. RefmsgTime string `json:"refmsg_time"`
  8954. RespondTime string `json:"respond_time"`
  8955. Signtype interface{} `json:"signtype"`
  8956. WarnMsg interface{} `json:"warn_msg"`
  8957. }
  8958. type Custom struct {
  8959. DetItemFeeSumamt string
  8960. Cut string
  8961. FeedetlSn string
  8962. Price string
  8963. MedListCodg string
  8964. Type int64
  8965. AdviceId int64
  8966. ProjectId int64
  8967. ItemId int64
  8968. CostType int64
  8969. }
  8970. // 获取个人信息----挂号-----上传就诊信息
  8971. func (c *HisApiController) GetRegisterInfo() {
  8972. id, _ := c.GetInt64("id")
  8973. record_time := c.GetString("record_time")
  8974. settlementValue, _ := c.GetInt64("settlement_value")
  8975. medical_insurance_card := c.GetString("medical_insurance_card")
  8976. name := c.GetString("name")
  8977. id_card_type, _ := c.GetInt64("id_card_type")
  8978. certificates, _ := c.GetInt64("certificates")
  8979. medical_care, _ := c.GetInt64("medical_care")
  8980. birthday := c.GetString("birthday")
  8981. age, _ := c.GetInt64("age")
  8982. id_card := c.GetString("id_card")
  8983. register_type, _ := c.GetInt64("register")
  8984. doctor, _ := c.GetInt64("doctor")
  8985. department, _ := c.GetInt64("department")
  8986. gender, _ := c.GetInt64("sex")
  8987. phone := c.GetString("phone")
  8988. registration_fee, _ := c.GetFloat("registration_fee")
  8989. medical_expenses, _ := c.GetFloat("medical_expenses")
  8990. social_type, _ := c.GetInt64("social_type")
  8991. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8992. diagnosis_ids := c.GetString("diagnosis")
  8993. sick_type, _ := c.GetInt64("sick_type")
  8994. reg_type := c.GetString("p_type")
  8995. timeLayout := "2006-01-02"
  8996. loc, _ := time.LoadLocation("Local")
  8997. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8998. birthUnix := birthdays.Unix()
  8999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9000. if err != nil {
  9001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9002. return
  9003. }
  9004. recordDateTime := theTime.Unix()
  9005. adminInfo := c.GetAdminUserInfo()
  9006. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9007. if tempPatient.ID == 0 {
  9008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9009. return
  9010. }
  9011. var patient service.Patients
  9012. if id == 0 {
  9013. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9014. } else {
  9015. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9016. }
  9017. if patient.ID == 0 {
  9018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9019. return
  9020. }
  9021. if len(patient.IdCardNo) == 0 {
  9022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9023. return
  9024. }
  9025. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9026. if len(his) >= 1 {
  9027. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9028. if len(his) >= 1 && order.ID == 0 {
  9029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9030. return
  9031. }
  9032. }
  9033. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9034. fmt.Println(timeStr)
  9035. timeArr := strings.Split(timeStr, " ")
  9036. fmt.Println(timeArr)
  9037. timeArrTwo := strings.Split(timeArr[0], "-")
  9038. timeArrThree := strings.Split(timeArr[1], ":")
  9039. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9040. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9041. if len(lists) == 0 {
  9042. var hisPatient models.XtHisPatient
  9043. hisPatient = models.XtHisPatient{
  9044. Name: name,
  9045. Age: age,
  9046. Gender: gender,
  9047. Birthday: birthUnix,
  9048. Phone: phone,
  9049. MedicalTreatmentType: medical_care,
  9050. IdType: certificates,
  9051. IdCardNo: id_card,
  9052. BalanceAccountsType: settlementValue,
  9053. SocialType: social_type,
  9054. MedicalInsuranceNumber: medical_insurance_card,
  9055. RegisterType: register_type,
  9056. RegisterCost: registration_fee,
  9057. TreatmentCost: medical_expenses,
  9058. AdminUserId: adminInfo.AdminUser.Id,
  9059. UserOrgId: adminInfo.CurrentOrgId,
  9060. Status: 1,
  9061. RecordDate: recordDateTime,
  9062. IsReturn: 1,
  9063. PatientId: patient.ID,
  9064. Ctime: time.Now().Unix(),
  9065. Mtime: time.Now().Unix(),
  9066. Number: str,
  9067. IdCardType: id_card_type,
  9068. Departments: department,
  9069. Doctor: doctor,
  9070. PType: reg_type,
  9071. Diagnosis: diagnosis_ids,
  9072. SickType: sick_type,
  9073. }
  9074. service.CreateHisPatient(&hisPatient)
  9075. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9076. c.ServeSuccessJSON(map[string]interface{}{
  9077. "his_info": hisPatient,
  9078. })
  9079. } else {
  9080. //chrgBchno := rand.Intn(1000000) + 10000
  9081. var hisPatient models.XtHisPatient
  9082. hisPatient = models.XtHisPatient{
  9083. Name: name,
  9084. Age: age,
  9085. Gender: gender,
  9086. Birthday: birthUnix,
  9087. Phone: phone,
  9088. MedicalTreatmentType: medical_care,
  9089. IdType: certificates,
  9090. IdCardNo: id_card,
  9091. BalanceAccountsType: settlementValue,
  9092. SocialType: social_type,
  9093. MedicalInsuranceNumber: medical_insurance_card,
  9094. RegisterType: register_type,
  9095. RegisterCost: registration_fee,
  9096. TreatmentCost: medical_expenses,
  9097. AdminUserId: adminInfo.AdminUser.Id,
  9098. UserOrgId: adminInfo.CurrentOrgId,
  9099. Status: 1,
  9100. RecordDate: recordDateTime,
  9101. IsReturn: 1,
  9102. PatientId: patient.ID,
  9103. Ctime: time.Now().Unix(),
  9104. Mtime: time.Now().Unix(),
  9105. Number: str,
  9106. IdCardType: id_card_type,
  9107. Departments: department,
  9108. Doctor: doctor,
  9109. PType: reg_type,
  9110. Diagnosis: diagnosis_ids,
  9111. SickType: sick_type,
  9112. }
  9113. service.CreateHisPatient(&hisPatient)
  9114. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9115. c.ServeSuccessJSON(map[string]interface{}{
  9116. "his_info": hisPatient,
  9117. })
  9118. }
  9119. }
  9120. // 上传明细----结算
  9121. func (c *HisApiController) GetUploadInfo() {
  9122. id, _ := c.GetInt64("id")
  9123. record_time := c.GetString("record_time")
  9124. his_patient_id, _ := c.GetInt64("his_patient_id")
  9125. oth_desc := c.GetString("oth_desc")
  9126. pay_way, _ := c.GetInt64("pay_way")
  9127. pay_ways := c.GetString("pay_ways")
  9128. pay_price, _ := c.GetFloat("pay_price")
  9129. pay_card_no := c.GetString("pay_card_no")
  9130. discount_price, _ := c.GetFloat("discount_price")
  9131. preferential_price, _ := c.GetFloat("preferential_price")
  9132. reality_price, _ := c.GetFloat("reality_price")
  9133. found_price, _ := c.GetFloat("found_price")
  9134. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9135. private_price, _ := c.GetFloat("private_price")
  9136. timeLayout := "2006-01-02"
  9137. loc, _ := time.LoadLocation("Local")
  9138. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9139. fapiao_code := c.GetString("fapiao_code")
  9140. fapiao_number := c.GetString("fapiao_number")
  9141. diagnosis_id := c.GetString("diagnosis")
  9142. sick_type, _ := c.GetInt64("sick_type")
  9143. reg_type, _ := c.GetInt64("p_type")
  9144. order_id, _ := c.GetInt64("order_id")
  9145. cash_pay := c.GetString("cash_pay")
  9146. wechat_pay := c.GetString("wechat_pay")
  9147. ali_pay := c.GetString("ali_pay")
  9148. jifen_pay := c.GetString("jifen_pay")
  9149. band_card_pay := c.GetString("band_card_pay")
  9150. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9151. tmp_decimal := c.GetString("tmp_decimal")
  9152. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9153. var decimal float64 //本次使用的押金
  9154. var errmsg error
  9155. tx := service.XTWriteDB().Begin() //开了事务
  9156. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9157. defer func() {
  9158. if errmsg != nil {
  9159. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9160. tx.Rollback()
  9161. } else {
  9162. tx.Commit()
  9163. }
  9164. }()
  9165. fmt.Println("dec_way", dec_way)
  9166. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9167. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9168. return
  9169. }
  9170. if len(tmp_decimal) > 0 {
  9171. if tmp_decimal[0] == 45 {
  9172. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9173. return
  9174. }
  9175. }
  9176. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9177. fmt.Println(errs)
  9178. decimal = tt
  9179. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9180. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9182. if err != nil {
  9183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9184. return
  9185. }
  9186. recordDateTime := theTime.Unix()
  9187. adminUser := c.GetAdminUserInfo()
  9188. var prescriptions []*models.HisPrescription
  9189. var prescriptionsOne []*models.HisPrescription
  9190. var start_time int64
  9191. var end_time int64
  9192. ids_str := c.GetString("ids")
  9193. ids_arr := strings.Split(ids_str, ",")
  9194. if tempOrder.ID == 0 {
  9195. if settle_accounts_type == 1 { //日结
  9196. fmt.Println(reg_type)
  9197. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9198. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9199. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9200. } else {
  9201. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9202. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9203. }
  9204. } else { //月结
  9205. start_time_str := c.GetString("start_time")
  9206. end_time_str := c.GetString("end_time")
  9207. timeLayout := "2006-01-02"
  9208. loc, _ := time.LoadLocation("Local")
  9209. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9210. if err != nil {
  9211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9212. return
  9213. }
  9214. recordStartTime := theStartTime.Unix()
  9215. start_time = recordStartTime
  9216. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9217. if err != nil {
  9218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9219. return
  9220. }
  9221. recordEndTime := theEndTime.Unix()
  9222. end_time = recordEndTime
  9223. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9224. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9225. }
  9226. var goods []*models.DialysisBeforePrepareGoods
  9227. var newGoods []*models.NewDialysisBeforePrepareGoods
  9228. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9229. var infos []*models.HisDoctorAdviceInfo
  9230. var infoList []*models.HisDoctorAdviceInfo
  9231. var hisAdvice []*models.HisDoctorAdviceInfo
  9232. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9233. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9234. //判断库存不足
  9235. //结算出库开关
  9236. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9237. if settConfig.IsOpen == 1 {
  9238. //判断库存的地方
  9239. for _, info := range prescriptions {
  9240. if info.Type == 1 {
  9241. infos = append(infos, info.HisDoctorAdviceInfo...)
  9242. }
  9243. if info.Type == 2 {
  9244. for _, sumItem := range info.HisPrescriptionProject {
  9245. if sumItem.Type == 3 {
  9246. var good models.DialysisBeforePrepareGoods
  9247. var newGood models.NewDialysisBeforePrepareGoods
  9248. good.GoodId = sumItem.GoodInfo.ID
  9249. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9250. count, _ := strconv.Atoi(sumItem.Count)
  9251. good.Count = int64(count)
  9252. good.StorehouseId = houseConfig.StorehouseOutInfo
  9253. good.ProjectId = sumItem.ID
  9254. goods = append(goods, &good)
  9255. newGood.GoodId = sumItem.GoodInfo.ID
  9256. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9257. count2, _ := strconv.Atoi(sumItem.Count)
  9258. newGood.Count = int64(count2)
  9259. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9260. newGood.ProjectId = sumItem.ID
  9261. newGoods = append(newGoods, &newGood)
  9262. }
  9263. }
  9264. }
  9265. }
  9266. for _, info := range prescriptionsOne {
  9267. if info.Type == 1 {
  9268. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9269. }
  9270. if info.Type == 2 {
  9271. for _, sumItem := range info.HisPrescriptionProject {
  9272. if sumItem.Type == 3 {
  9273. var newGood models.NewDialysisBeforePrepareGoods
  9274. newGood.GoodId = sumItem.GoodInfo.ID
  9275. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9276. count2, _ := strconv.Atoi(sumItem.Count)
  9277. newGood.Count = int64(count2)
  9278. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9279. newGood.ProjectId = sumItem.ID
  9280. newGoodOne = append(newGoodOne, &newGood)
  9281. }
  9282. }
  9283. }
  9284. }
  9285. //判断
  9286. for _, itemOne := range infos {
  9287. for _, itemTwo := range hisAdvice {
  9288. if itemOne.DrugId == itemTwo.DrugId {
  9289. itemTwo.Child = append(itemTwo.Child, itemOne)
  9290. }
  9291. }
  9292. }
  9293. for _, itemTwo := range hisAdvice {
  9294. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9295. var sum_out_count int64
  9296. for _, itemThree := range itemTwo.Child {
  9297. var prescribing_number int64
  9298. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9299. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9300. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9301. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9302. }
  9303. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9304. prescribing_number = parseIntPrescribingNumber
  9305. }
  9306. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9307. prescribing_number = parseIntPrescribingNumber
  9308. }
  9309. sum_out_count += prescribing_number
  9310. }
  9311. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9312. if sum_out_count > drugStockOut.FlushCount {
  9313. c.ServeSuccessJSON(map[string]interface{}{
  9314. "msg": "2",
  9315. "drug": medical,
  9316. })
  9317. return
  9318. }
  9319. }
  9320. for _, itemOne := range newGoods {
  9321. for _, item := range newGoodOne {
  9322. if itemOne.GoodId == item.GoodId {
  9323. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9324. }
  9325. }
  9326. }
  9327. for _, item := range newGoodOne {
  9328. var sum_out_count_one int64
  9329. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9330. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9331. sum_out_count_one += itemOne.Count
  9332. }
  9333. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9334. fmt.Println("sum_out_count_one", sum_out_count_one)
  9335. fmt.Println("list.FlushCount", list.FlushCount)
  9336. if sum_out_count_one > list.FlushCount {
  9337. c.ServeSuccessJSON(map[string]interface{}{
  9338. "msg": "3",
  9339. "good": good,
  9340. })
  9341. return
  9342. }
  9343. }
  9344. }
  9345. timestamp := time.Now().Unix()
  9346. tempTime := time.Unix(timestamp, 0)
  9347. timeFormat := tempTime.Format("20060102150405")
  9348. chrgBchno := rand.Intn(100000) + 10000
  9349. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9350. strconv.FormatInt(his.PatientId, 10)
  9351. var ids []int64
  9352. for _, item := range prescriptions {
  9353. ids = append(ids, item.ID)
  9354. }
  9355. var total float64
  9356. for _, item := range prescriptions {
  9357. fmt.Println(item)
  9358. if item.Type == 1 { //药品
  9359. for _, subItem := range item.HisDoctorAdviceInfo {
  9360. total = total + (subItem.Price * subItem.PrescribingNumber)
  9361. }
  9362. }
  9363. if item.Type == 2 { //项目
  9364. for _, subItem := range item.HisPrescriptionProject {
  9365. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9366. total = total + (subItem.Price * cnt)
  9367. }
  9368. }
  9369. for _, subItem := range item.HisAdditionalCharge {
  9370. total = total + (subItem.Price * float64(subItem.Count))
  9371. }
  9372. }
  9373. if reg_type == 1111 || reg_type == 1112 {
  9374. reg_type = 11
  9375. }
  9376. tm := time.Unix(time.Now().Unix(), 0)
  9377. allTotal := fmt.Sprintf("%.4f", total)
  9378. totals, _ := strconv.ParseFloat(allTotal, 64)
  9379. order := &models.HisOrder{
  9380. UserOrgId: adminUser.CurrentOrgId,
  9381. HisPatientId: his.ID,
  9382. PatientId: id,
  9383. SettleAccountsDate: recordDateTime,
  9384. Ctime: time.Now().Unix(),
  9385. Mtime: time.Now().Unix(),
  9386. Status: 1,
  9387. OrderStatus: 2,
  9388. MdtrtId: his.Number,
  9389. Number: chrg_bchno,
  9390. MedfeeSumamt: totals,
  9391. PayWay: pay_way,
  9392. PayWays: pay_ways,
  9393. PayPrice: pay_price,
  9394. MedType: strconv.Itoa(int(reg_type)),
  9395. PayCardNo: pay_card_no,
  9396. DiscountPrice: discount_price,
  9397. PreferentialPrice: preferential_price,
  9398. RealityPrice: reality_price,
  9399. FoundPrice: found_price,
  9400. MedicalInsurancePrice: medical_insurance_price,
  9401. PrivatePrice: private_price,
  9402. SettleEndTime: end_time,
  9403. SettleStartTime: start_time,
  9404. PsnPartAmt: totals,
  9405. PsnCashPay: totals,
  9406. SettleType: settle_accounts_type,
  9407. FaPiaoCode: fapiao_code,
  9408. FaPiaoNumber: fapiao_number,
  9409. Diagnosis: diagnosis_id,
  9410. PType: 2,
  9411. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9412. Decimal: decimal,
  9413. OthDesc: oth_desc,
  9414. CashPay: cash_pay,
  9415. WechatPay: wechat_pay,
  9416. AliPay: ali_pay,
  9417. JifenPay: jifen_pay,
  9418. BandCardPay: band_card_pay,
  9419. Creator: adminUser.AdminUser.Id,
  9420. }
  9421. err = service.CreateOrderTX(order, tx)
  9422. if err != nil {
  9423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9424. return
  9425. }
  9426. var customs []*Custom
  9427. for _, item := range prescriptions {
  9428. if item.Type == 1 { //药品a
  9429. for _, subItem := range item.HisDoctorAdviceInfo {
  9430. cus := &Custom{
  9431. AdviceId: subItem.ID,
  9432. ProjectId: 0,
  9433. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9434. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9435. FeedetlSn: subItem.FeedetlSn,
  9436. Price: fmt.Sprintf("%.4f", subItem.Price),
  9437. MedListCodg: subItem.MedListCodg,
  9438. Type: 1,
  9439. CostType: 9,
  9440. }
  9441. customs = append(customs, cus)
  9442. }
  9443. }
  9444. if item.Type == 2 { //项目
  9445. for _, subItem := range item.HisPrescriptionProject {
  9446. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9447. cus := &Custom{
  9448. AdviceId: 0,
  9449. ProjectId: subItem.ID,
  9450. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9451. Cut: fmt.Sprintf("%.4f", cnt),
  9452. FeedetlSn: subItem.FeedetlSn,
  9453. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9454. MedListCodg: subItem.MedListCodg,
  9455. Type: 2,
  9456. CostType: subItem.HisProject.CostClassify,
  9457. }
  9458. customs = append(customs, cus)
  9459. }
  9460. }
  9461. for _, item := range item.HisAdditionalCharge {
  9462. cus := &Custom{
  9463. ItemId: item.ID,
  9464. AdviceId: 0,
  9465. ProjectId: 0,
  9466. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9467. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9468. FeedetlSn: item.FeedetlSn,
  9469. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9470. MedListCodg: item.XtHisAddtionConfig.Code,
  9471. Type: 3,
  9472. CostType: 5,
  9473. }
  9474. customs = append(customs, cus)
  9475. }
  9476. }
  9477. for _, item := range customs {
  9478. var advice_id int64 = 0
  9479. var project_id int64 = 0
  9480. var item_id int64 = 0
  9481. var types int64 = 0
  9482. var med_chrgitm_type string
  9483. if item.Type == 1 {
  9484. advice_id = item.AdviceId
  9485. project_id = 0
  9486. item_id = 0
  9487. med_chrgitm_type = "09"
  9488. } else if item.Type == 2 {
  9489. med_chrgitm_type = "05"
  9490. if item.CostType == 3 {
  9491. med_chrgitm_type = "04"
  9492. }
  9493. if item.CostType == 8 {
  9494. med_chrgitm_type = "03"
  9495. }
  9496. advice_id = 0
  9497. item_id = 0
  9498. project_id = item.ProjectId
  9499. } else if item.Type == 3 {
  9500. advice_id = 0
  9501. item_id = item.ItemId
  9502. project_id = 0
  9503. med_chrgitm_type = "08"
  9504. }
  9505. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9506. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9507. pric, _ := strconv.ParseFloat(item.Price, 32)
  9508. info := &models.HisOrderInfo{
  9509. OrderNumber: order.Number,
  9510. UploadDate: time.Now().Unix(),
  9511. AdviceId: advice_id,
  9512. DetItemFeeSumamt: detItemFeeSumamt,
  9513. MedChrgitmType: med_chrgitm_type,
  9514. Cnt: cut,
  9515. Pric: pric,
  9516. PatientId: id,
  9517. Status: 1,
  9518. Mtime: time.Now().Unix(),
  9519. Ctime: time.Now().Unix(),
  9520. UserOrgId: adminUser.CurrentOrgId,
  9521. HisPatientId: his.ID,
  9522. OrderId: order.ID,
  9523. ProjectId: project_id,
  9524. Type: types,
  9525. ItemId: item_id,
  9526. }
  9527. service.CreateOrderInfoTX(info, tx)
  9528. }
  9529. his.Diagnosis = diagnosis_id
  9530. his.SickType = sick_type
  9531. his.RegisterType = reg_type
  9532. his.MedicalTreatmentType = reg_type
  9533. service.UpdataHisPateintTX(&his, tx)
  9534. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9535. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9536. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9537. //判断是否使用了押金
  9538. if dec_way == "true" {
  9539. tmpstring := strconv.FormatInt(order.ID, 10)
  9540. //扣押金
  9541. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9542. order.Decimal = decimal
  9543. service.UpDateOrderTwo(order, tx)
  9544. if errmsg != nil {
  9545. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9546. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9547. return
  9548. }
  9549. }
  9550. if err == nil {
  9551. for _, info := range prescriptions {
  9552. if info.Type == 1 {
  9553. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9554. }
  9555. if info.Type == 2 {
  9556. for _, sumItem := range info.HisPrescriptionProject {
  9557. if sumItem.Type == 3 {
  9558. var good models.DialysisBeforePrepareGoods
  9559. var newGood models.NewDialysisBeforePrepareGoods
  9560. var oldGood models.OldDialysisBeforePrepareGoods
  9561. good.GoodId = sumItem.GoodInfo.ID
  9562. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9563. count, _ := strconv.Atoi(sumItem.Count)
  9564. good.Count = int64(count)
  9565. good.StorehouseId = houseConfig.StorehouseOutInfo
  9566. good.ProjectId = sumItem.ID
  9567. good.PatientId = sumItem.PatientId
  9568. goods = append(goods, &good)
  9569. newGood.GoodId = sumItem.GoodInfo.ID
  9570. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9571. count2, _ := strconv.Atoi(sumItem.Count)
  9572. newGood.Count = int64(count2)
  9573. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9574. newGood.ProjectId = sumItem.ID
  9575. newGood.PatientId = sumItem.HisPatientId
  9576. newGoods = append(newGoods, &newGood)
  9577. oldGood.GoodId = sumItem.GoodInfo.ID
  9578. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9579. count3, _ := strconv.Atoi(sumItem.Count)
  9580. oldGood.Count = int64(count3)
  9581. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9582. oldGood.ProjectId = sumItem.ID
  9583. oldGood.RecordDate = sumItem.RecordDate
  9584. oldGood.PatientId = sumItem.HisPatientId
  9585. oldGoods = append(oldGoods, &oldGood)
  9586. }
  9587. }
  9588. }
  9589. }
  9590. if settConfig.IsOpen == 1 {
  9591. for _, item := range infoList {
  9592. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9593. if medical.IsUse == 2 {
  9594. //药品出库
  9595. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9596. //查询默认仓库
  9597. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9598. //查询默认仓库剩余多少库存
  9599. var sum_count int64
  9600. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9601. for _, its := range stockInfo {
  9602. if its.MaxUnit == medical.MaxUnit {
  9603. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9604. }
  9605. sum_count += its.StockMaxNumber + its.StockMinNumber
  9606. }
  9607. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9608. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9609. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9610. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9611. }
  9612. }
  9613. orgId := c.GetAdminUserInfo().CurrentOrgId
  9614. if len(oldGoods) > 0 {
  9615. timeStr := time.Now().Format("2006-01-02")
  9616. timeArr := strings.Split(timeStr, "-")
  9617. total, _ := service.FindAllWarehouseOut(orgId)
  9618. total = total + 1
  9619. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9620. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9621. number = number + total
  9622. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9623. operation_time := time.Now().Unix()
  9624. creater := c.GetAdminUserInfo().AdminUser.Id
  9625. //查询默认出库仓库库存
  9626. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9627. recordDateStr := time.Now().Format("2006-01-02")
  9628. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9629. nowtime := recordDate.Unix()
  9630. warehouseOut := models.WarehouseOut{
  9631. WarehouseOutOrderNumber: warehousing_out_order,
  9632. OperationTime: operation_time,
  9633. OrgId: orgId,
  9634. Creater: creater,
  9635. Ctime: time.Now().Unix(),
  9636. Status: 1,
  9637. WarehouseOutTime: nowtime,
  9638. Type: 1,
  9639. StorehouseId: storeConfig.StorehouseOutInfo,
  9640. IsCheck: 1,
  9641. OrderId: order.ID,
  9642. IsSys: 5,
  9643. }
  9644. //查询是否生成出库单
  9645. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9646. if out.ID == 0 {
  9647. service.AddSigleWarehouseOut(&warehouseOut)
  9648. }
  9649. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9650. for _, item := range oldGoods {
  9651. dialyPrepareOne := models.DialysisBeforePrepare{
  9652. GoodTypeId: item.GoodTypeId,
  9653. GoodId: item.GoodId,
  9654. PatientId: his.PatientId,
  9655. RecordDate: item.RecordDate,
  9656. UserOrgId: adminUser.CurrentOrgId,
  9657. Count: item.Count,
  9658. Ctime: time.Now().Unix(),
  9659. Creater: adminUser.AdminUser.Id,
  9660. CommdityCode: item.CommdityCode,
  9661. Status: 1,
  9662. StorehouseId: houseConfig.StorehouseOutInfo,
  9663. }
  9664. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9665. //非零用
  9666. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9667. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9668. //查询剩余库存
  9669. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9670. var sum_count int64
  9671. for _, item := range goodList {
  9672. sum_count += item.StockCount
  9673. }
  9674. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9675. //耗材
  9676. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9677. }
  9678. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9679. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9680. //查询剩余库存
  9681. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9682. var sum_count int64
  9683. for _, item := range goodList {
  9684. sum_count += item.StockCount
  9685. }
  9686. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9687. //耗材
  9688. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9689. }
  9690. }
  9691. }
  9692. }
  9693. c.ServeSuccessJSON(map[string]interface{}{
  9694. "msg": "结算成功",
  9695. })
  9696. }
  9697. }
  9698. }
  9699. // 退款
  9700. func (c *HisApiController) Refund() {
  9701. order_id, _ := c.GetInt64("order_id")
  9702. order, _ := service.GetHisOrderByID(order_id)
  9703. adminUser := c.GetAdminUserInfo()
  9704. orgid := c.GetAdminUserInfo().CurrentOrgId
  9705. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9706. if err != nil {
  9707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9708. return
  9709. }
  9710. tmp := strconv.FormatInt(order.ID, 10)
  9711. //当押金不为零时产生退费记录
  9712. if order.Decimal != 0 {
  9713. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9714. if err != nil {
  9715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9716. return
  9717. }
  9718. }
  9719. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9720. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9721. var goods []*models.DialysisBeforePrepareGoods
  9722. var newGoods []*models.NewDialysisBeforePrepareGoods
  9723. var infos []*models.HisDoctorAdviceInfo
  9724. for _, info := range orders {
  9725. if info.AdviceId > 0 && info.ProjectId == 0 {
  9726. infos = append(infos, &info.HisDoctorAdviceInfo)
  9727. }
  9728. if info.ProjectId > 0 && info.AdviceId == 0 {
  9729. if info.HisPrescriptionProject.Type == 3 {
  9730. var good models.DialysisBeforePrepareGoods
  9731. var newGood models.NewDialysisBeforePrepareGoods
  9732. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9733. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9734. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9735. good.Count = int64(count)
  9736. good.StorehouseId = houseConfig.StorehouseOutInfo
  9737. good.ProjectId = info.HisPrescriptionProject.ID
  9738. good.PatientId = info.PatientId
  9739. good.OrderId = order_id
  9740. goods = append(goods, &good)
  9741. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9742. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9743. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9744. newGood.Count = int64(count2)
  9745. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9746. newGood.ProjectId = info.HisPrescriptionProject.ID
  9747. newGood.RecordDate = order.SettleAccountsDate
  9748. newGood.UserOrgId = order.UserOrgId
  9749. newGood.PatientId = info.PatientId
  9750. newGood.OrderId = order_id
  9751. newGoods = append(newGoods, &newGood)
  9752. }
  9753. }
  9754. }
  9755. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9756. if settConfig.IsOpen == 1 {
  9757. for _, item := range infos {
  9758. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9759. }
  9760. for _, item := range newGoods {
  9761. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9762. }
  9763. }
  9764. c.ServeSuccessJSON(map[string]interface{}{
  9765. "msg": "退费成功",
  9766. })
  9767. }
  9768. func (c *HisApiController) RefundNumber() {
  9769. his_patient_id, _ := c.GetInt64("id")
  9770. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9771. info.Status = 0
  9772. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9773. if count > 0 {
  9774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9775. return
  9776. }
  9777. err := service.SaveHisPatient(info)
  9778. if err == nil {
  9779. c.ServeSuccessJSON(map[string]interface{}{
  9780. "msg": "退号成功",
  9781. })
  9782. } else {
  9783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9784. return
  9785. }
  9786. }
  9787. func (this *HisApiController) AdditionalCharge() {
  9788. dataBody := make(map[string]interface{}, 0)
  9789. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9790. fmt.Println(err)
  9791. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9792. patient_id := int64(dataBody["patient_id"].(float64))
  9793. medicineData, _ := dataBody["medicineData"].([]interface{})
  9794. adminUserInfo := this.GetAdminUserInfo()
  9795. orgId := adminUserInfo.CurrentOrgId
  9796. admin_user_id := adminUserInfo.AdminUser.Id
  9797. timeStr := time.Now().Format("2006-01-02")
  9798. timeLayout := "2006-01-02 15:04:05"
  9799. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9800. timenow := timeStringToTime.Unix()
  9801. var additionalCharges []*models.HisAdditionalCharge
  9802. for _, item := range medicineData {
  9803. var randNum int
  9804. randNum = rand.Intn(10000) + 1000
  9805. timestamp := time.Now().Unix()
  9806. tempTime := time.Unix(timestamp, 0)
  9807. timeFormat := tempTime.Format("20060102150405")
  9808. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9809. items := item.(map[string]interface{})
  9810. money := items["price"].(string)
  9811. item_id_str := items["item_id"].(string)
  9812. name := items["name"].(string)
  9813. id_str := items["id"].(string)
  9814. moneys, _ := strconv.ParseInt(money, 10, 64)
  9815. monStr := strconv.FormatInt(moneys, 10)
  9816. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9817. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9818. id, _ := strconv.ParseInt(id_str, 10, 64)
  9819. additionalCharge := &models.HisAdditionalCharge{
  9820. ID: id,
  9821. HisPatientId: his_patient_id,
  9822. UserOrgId: orgId,
  9823. PatientId: patient_id,
  9824. RecordDate: timenow,
  9825. Price: monneyStr,
  9826. Status: 1,
  9827. ItemName: name,
  9828. ItemId: item_id,
  9829. AdminUserId: admin_user_id,
  9830. CreatedTime: time.Now().Unix(),
  9831. OrderStatus: 0,
  9832. PrescriptionNumber: "",
  9833. BatchNumber: "",
  9834. FeedetlSn: p_number,
  9835. }
  9836. service.CreateAdditionalCharge(additionalCharge)
  9837. additionalCharges = append(additionalCharges, additionalCharge)
  9838. }
  9839. this.ServeSuccessJSON(map[string]interface{}{
  9840. "msg": "添加成功",
  9841. "additional_charges": additionalCharges,
  9842. })
  9843. }
  9844. func (this *HisApiController) DeleteAddition() {
  9845. id, _ := this.GetInt64("id")
  9846. //TODO 需要判断是否已经结算
  9847. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9848. if err == nil {
  9849. this.ServeSuccessJSON(map[string]interface{}{
  9850. "msg": "删除成功",
  9851. })
  9852. return
  9853. } else {
  9854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9855. return
  9856. }
  9857. }
  9858. func (this *HisApiController) GetAdminUsers() {
  9859. adminUser := this.GetAdminUserInfo()
  9860. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9861. this.ServeSuccessJSON(map[string]interface{}{
  9862. "doctors": doctors,
  9863. })
  9864. }
  9865. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9866. change_type, _ := this.GetInt64("type", 0)
  9867. record_date := this.GetString("record_time")
  9868. patient_id, _ := this.GetInt64("patient_id", 0)
  9869. p_type, _ := this.GetInt64("p_type", 0)
  9870. timeLayout := "2006-01-02"
  9871. loc, _ := time.LoadLocation("Local")
  9872. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9873. record_time := theAdviceRecordTime.Unix()
  9874. adminUserInfo := this.GetAdminUserInfo()
  9875. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9876. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9877. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9878. if config.ID > 0 && config.IsOpen == 1 {
  9879. for _, subitems := range prescriptions {
  9880. for _, item := range subitems.VMHisPrescription {
  9881. for _, subItem := range item.HisDoctorAdviceInfo {
  9882. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9883. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9884. if info.RetailPrice > 0 {
  9885. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9886. subItem.Drug.RetailPrice = drug.RetailPrice
  9887. }
  9888. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9889. subItem.Drug.MinPrice = info.RetailPrice
  9890. subItem.Drug.RetailPrice = info.RetailPrice
  9891. }
  9892. }
  9893. }
  9894. }
  9895. }
  9896. }
  9897. if config.ID > 0 && config.IsOpen == 1 {
  9898. for _, subitems := range prescriptions {
  9899. for _, item := range subitems.VMHisPrescription {
  9900. for _, subItem := range item.HisPrescriptionProject {
  9901. if subItem.Type == 3 {
  9902. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9903. if info.Price > 0 {
  9904. subItem.GoodInfo.PackingPrice = info.Price
  9905. }
  9906. }
  9907. }
  9908. }
  9909. }
  9910. }
  9911. }
  9912. if err == nil {
  9913. if len(prescriptions) == 0 {
  9914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9915. return
  9916. } else {
  9917. this.ServeSuccessJSON(map[string]interface{}{
  9918. "prescriptions": prescriptions,
  9919. })
  9920. return
  9921. }
  9922. } else {
  9923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9924. return
  9925. }
  9926. }
  9927. func (this *HisApiController) GetCallHisPrescription() {
  9928. patient_id, _ := this.GetInt64("patient_id", 0)
  9929. timeLayout := "2006-01-02"
  9930. loc, _ := time.LoadLocation("Local")
  9931. start_time := this.GetString("start_time")
  9932. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9933. end_time := this.GetString("end_time")
  9934. p_type, _ := this.GetInt64("p_type")
  9935. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9936. adminUserInfo := this.GetAdminUserInfo()
  9937. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9938. //if
  9939. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9940. //
  9941. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9942. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9943. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9944. if config.ID > 0 && config.IsOpen == 1 {
  9945. for _, subitems := range prescriptions {
  9946. for _, item := range subitems.VMHisPrescription {
  9947. for _, subItem := range item.HisDoctorAdviceInfo {
  9948. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9949. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9950. if info.RetailPrice > 0 {
  9951. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9952. subItem.Drug.RetailPrice = drug.RetailPrice
  9953. }
  9954. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9955. subItem.Drug.MinPrice = info.RetailPrice
  9956. subItem.Drug.RetailPrice = info.RetailPrice
  9957. }
  9958. }
  9959. }
  9960. }
  9961. }
  9962. }
  9963. if config.ID > 0 && config.IsOpen == 1 {
  9964. for _, subitems := range prescriptions {
  9965. for _, item := range subitems.VMHisPrescription {
  9966. for _, subItem := range item.HisPrescriptionProject {
  9967. if subItem.Type == 3 {
  9968. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9969. if info.Price > 0 {
  9970. subItem.GoodInfo.PackingPrice = info.Price
  9971. }
  9972. }
  9973. }
  9974. }
  9975. }
  9976. }
  9977. }
  9978. if err == nil {
  9979. this.ServeSuccessJSON(map[string]interface{}{
  9980. "prescriptions": prescriptions,
  9981. })
  9982. return
  9983. } else {
  9984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9985. return
  9986. }
  9987. }
  9988. func (this *HisApiController) GetHisDayPrescription() {
  9989. timeLayout := "2006-01-02"
  9990. loc, _ := time.LoadLocation("Local")
  9991. start_time := this.GetString("start_time")
  9992. patient_id, _ := this.GetInt64("patient_id", 0)
  9993. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9994. end_time := this.GetString("end_time")
  9995. p_type, _ := this.GetInt64("p_type")
  9996. order_status, _ := this.GetInt64("type")
  9997. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9998. adminUserInfo := this.GetAdminUserInfo()
  9999. var dayHisPrescription []*models.HisPrescription
  10000. var err error
  10001. if order_status == 1 || order_status == 0 {
  10002. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10003. } else if order_status == 2 {
  10004. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10005. }
  10006. var settle_total float64
  10007. for _, item := range dayHisPrescription {
  10008. if len(item.HisPrescriptionProject) > 0 {
  10009. for _, subItem := range item.HisPrescriptionProject {
  10010. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10011. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10012. settle_total = settle_total + total
  10013. }
  10014. }
  10015. if len(item.HisDoctorAdviceInfo) > 0 {
  10016. for _, subItem := range item.HisDoctorAdviceInfo {
  10017. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10018. settle_total = settle_total + total
  10019. }
  10020. }
  10021. }
  10022. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10023. if err == nil {
  10024. this.ServeSuccessJSON(map[string]interface{}{
  10025. "day_prescription": dayHisPrescription,
  10026. "settle_total": settle_total,
  10027. })
  10028. return
  10029. } else {
  10030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10031. return
  10032. }
  10033. }
  10034. func (c *HisApiController) GetHisChargePatientList() {
  10035. record_date := c.GetString("record_date")
  10036. order_status, _ := c.GetInt64("type")
  10037. sch_type, _ := c.GetInt64("sch_type")
  10038. timeLayout := "2006-01-02"
  10039. loc, _ := time.LoadLocation("Local")
  10040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10041. if err != nil {
  10042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10043. return
  10044. }
  10045. recordDateTime := theTime.Unix()
  10046. adminInfo := c.GetAdminUserInfo()
  10047. var tempPatients []*service.NewTempPatients
  10048. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10049. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10050. if order_status != 2 {
  10051. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10052. } else {
  10053. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10054. }
  10055. } else {
  10056. if order_status != 2 {
  10057. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10058. } else {
  10059. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10060. }
  10061. }
  10062. var patients []*service.NewTempPatients
  10063. var patients_two []*service.NewTempPatients
  10064. for _, item := range tempPatients {
  10065. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10066. //过滤掉没挂号的和没开处方的
  10067. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10068. patients = append(patients, item)
  10069. }
  10070. //过滤掉没挂号的
  10071. if len(item.HisPatient) > 0 {
  10072. patients_two = append(patients_two, item)
  10073. }
  10074. } else {
  10075. if len(item.HisPrescription) > 0 {
  10076. patients = append(patients, item)
  10077. }
  10078. }
  10079. }
  10080. c.ServeSuccessJSON(map[string]interface{}{
  10081. "list": patients,
  10082. "list_two": patients_two,
  10083. })
  10084. }
  10085. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10086. record_date := c.GetString("record_date")
  10087. timeLayout := "2006-01-02"
  10088. loc, _ := time.LoadLocation("Local")
  10089. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10090. if err != nil {
  10091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10092. return
  10093. }
  10094. recordDateTime := theTime.Unix()
  10095. adminUser := c.GetAdminUserInfo()
  10096. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10097. var patients []*service.Patients
  10098. for _, item := range tempPatients {
  10099. if item.HisPatient.ID == 0 {
  10100. patients = append(patients, item)
  10101. }
  10102. }
  10103. c.ServeSuccessJSON(map[string]interface{}{
  10104. "list": patients,
  10105. //"list_two": patients_two,
  10106. })
  10107. }
  10108. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10109. newArr = make([]*service.Patients, 0)
  10110. for i := 0; i < len(patient); i++ {
  10111. repeat := false
  10112. for j := i + 1; j < len(patient); j++ {
  10113. if patient[i].ID == patient[j].ID {
  10114. repeat = true
  10115. break
  10116. }
  10117. }
  10118. if !repeat {
  10119. newArr = append(newArr, patient[i])
  10120. }
  10121. }
  10122. return
  10123. }
  10124. func (c *HisApiController) GetHisChargePatientInfo() {
  10125. patient_id, _ := c.GetInt64("patient_id")
  10126. his_patient_id, _ := c.GetInt64("his_patient_id")
  10127. record_date := c.GetString("record_date")
  10128. //start_time := c.GetString("start_time")
  10129. //end_time := c.GetString("end_time")
  10130. order_status, _ := c.GetInt64("type", 0)
  10131. p_type, _ := c.GetInt64("p_type", 0)
  10132. order_id, _ := c.GetInt64("order_id", 0)
  10133. timeLayout := "2006-01-02"
  10134. loc, _ := time.LoadLocation("Local")
  10135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10136. if err != nil {
  10137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10138. return
  10139. }
  10140. recordDateTime := theTime.Unix()
  10141. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10142. //if err != nil {
  10143. //
  10144. //}
  10145. //startRecordDateTime := startTime.Unix()
  10146. //
  10147. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10148. //if err != nil {
  10149. //
  10150. //}
  10151. //endRecordDateTime := endTime.Unix()
  10152. admin := c.GetAdminUserInfo()
  10153. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10154. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10155. var prescriptions []*models.HisPrescription
  10156. //var unChargeMonthPrescriptions []*models.HisPrescription
  10157. order, _ := service.GetHisOrderByID(order_id)
  10158. if order_status == 1 || order_status == 0 {
  10159. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10160. } else if order_status == 2 {
  10161. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10162. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10163. }
  10164. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10165. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10166. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10167. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10168. //获取所有科室信息
  10169. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10170. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10171. c.ServeSuccessJSON(map[string]interface{}{
  10172. "his_info": his_patient_info,
  10173. "xt_info": xt_patient_info,
  10174. "prescription": prescriptions,
  10175. "case_history": case_history,
  10176. "info": patientPrescriptionInfo,
  10177. "last_info": lastPatientPrescriptionInfo,
  10178. "order": order,
  10179. "doctors": doctors,
  10180. "department": department,
  10181. "sch": sch,
  10182. })
  10183. return
  10184. }
  10185. func (c *HisApiController) GetAllOrderDetail() {
  10186. order_id, _ := c.GetInt64("id", 0)
  10187. order, _ := service.GetHisOrderByID(order_id)
  10188. if order.ID == 0 {
  10189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10190. return
  10191. }
  10192. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10193. org_id := c.GetAdminUserInfo().CurrentOrgId
  10194. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10195. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10196. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10197. c.ServeSuccessJSON(map[string]interface{}{
  10198. "order": order,
  10199. "order_info": order_info,
  10200. "patient": patient,
  10201. "admin_info": adminInfo,
  10202. "hospital_record": record,
  10203. })
  10204. return
  10205. }
  10206. func (c *HisApiController) GetAllOrderDetailCollect() {
  10207. order_id, _ := c.GetInt64("id", 0)
  10208. order, _ := service.GetHisOrderByID(order_id)
  10209. if order.ID == 0 {
  10210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10211. return
  10212. }
  10213. org_id := c.GetAdminUserInfo().CurrentOrgId
  10214. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10215. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10216. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10217. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10218. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10219. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10220. var bedCostTotal float64 = 0 //床位总费
  10221. //var bedCostSelfTotal float64 = 0 //床位自费
  10222. var operationCostTotal float64 = 0 //手术费
  10223. //var operationCostSelfTotal float64 = 0 //手术费
  10224. var otherCostTotal float64 = 0 //其他费用
  10225. //var otherCostSelfTotal float64 = 0 //其他费用
  10226. var materialCostTotal float64 = 0 //材料费
  10227. //var materialCostSelfTotal float64 = 0 //材料费
  10228. var westernMedicineCostTotal float64 = 0 //西药费
  10229. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10230. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10231. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10232. var checkCostTotal float64 = 0 //检查费
  10233. //var checkCostSelfTotal float64 = 0 //检查费
  10234. var laboratoryCostTotal float64 = 0 //化验费
  10235. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10236. var treatCostTotal float64 = 0 //治疗费用
  10237. //var treatCostSelfTotal float64 = 0 //治疗费用
  10238. var zhenChaCostTotal float64 = 0 //其他费用
  10239. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10240. decimal.DivisionPrecision = 2
  10241. var BalanceAccountsType int64
  10242. if his.ID > 0 {
  10243. BalanceAccountsType = his.BalanceAccountsType
  10244. } else {
  10245. BalanceAccountsType = record.BalanceAccountsType
  10246. }
  10247. if BalanceAccountsType != 2 {
  10248. for _, item := range order_info {
  10249. if org_id == 10215 {
  10250. if item.MedChrgitmType == "01" { //床位费
  10251. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10252. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10253. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10254. }
  10255. if item.MedChrgitmType == "02" { //诊察费
  10256. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10257. //zhenChaCostSelfTotal = zhenChaCostTotal
  10258. }
  10259. if item.MedChrgitmType == "03" { //检查费
  10260. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10261. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10262. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10263. }
  10264. //if item.MedChrgitmType == "02" { //检查费
  10265. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10266. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10267. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10268. //}
  10269. if item.MedChrgitmType == "04" { //化验费
  10270. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10271. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10272. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10273. }
  10274. if item.MedChrgitmType == "05" { //治疗费
  10275. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10276. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10277. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10278. }
  10279. if item.MedChrgitmType == "06" { //手术费
  10280. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10281. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10282. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10283. }
  10284. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10285. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10286. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10287. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10288. }
  10289. if item.MedChrgitmType == "09" { //西药费
  10290. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10291. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10292. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10293. }
  10294. if item.MedChrgitmType == "11" { //中成费
  10295. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10296. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10297. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10298. }
  10299. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10300. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10301. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10302. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10303. }
  10304. } else if org_id == 10188 || org_id == 10217 {
  10305. if item.MedChrgitmType == "01" { //床位费
  10306. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10307. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10308. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10309. }
  10310. if item.MedChrgitmType == "02" { //诊察费
  10311. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. //zhenChaCostSelfTotal = zhenChaCostTotal
  10313. }
  10314. if item.MedChrgitmType == "03" { //检查费
  10315. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10319. }
  10320. //if item.MedChrgitmType == "02" { //检查费
  10321. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10322. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10323. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10324. //}
  10325. if item.MedChrgitmType == "04" { //化验费
  10326. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10328. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10329. }
  10330. if item.MedChrgitmType == "05" { //治疗费
  10331. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10333. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10334. }
  10335. if item.MedChrgitmType == "06" { //手术费
  10336. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10337. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10338. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10339. }
  10340. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10341. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10342. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10343. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10344. }
  10345. if item.MedChrgitmType == "09" { //西药费
  10346. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10348. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10349. }
  10350. if item.MedChrgitmType == "11" { //中成费
  10351. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10353. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10354. }
  10355. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10356. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10358. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10359. }
  10360. } else {
  10361. if item.MedChrgitmType == "01" { //床位费
  10362. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10363. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10364. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10365. }
  10366. //if item.MedChrgitmType == "02" { //诊察费
  10367. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10368. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10369. //}
  10370. if item.MedChrgitmType == "03" { //检查费
  10371. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10372. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10373. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10374. }
  10375. //if item.MedChrgitmType == "02" { //检查费
  10376. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10377. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10378. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10379. //}
  10380. if item.MedChrgitmType == "04" { //化验费
  10381. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10382. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10383. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10384. }
  10385. if item.MedChrgitmType == "05" { //治疗费
  10386. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10387. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10388. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10389. }
  10390. if item.MedChrgitmType == "06" { //手术费
  10391. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10392. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10393. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10394. }
  10395. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10396. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10397. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10398. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10399. }
  10400. if item.MedChrgitmType == "09" { //西药费
  10401. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10402. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10403. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10404. }
  10405. if item.MedChrgitmType == "11" { //中成费
  10406. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10407. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10408. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10409. }
  10410. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10411. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10412. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10413. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10414. }
  10415. }
  10416. }
  10417. c.ServeSuccessJSON(map[string]interface{}{
  10418. "order": order,
  10419. "order_info": order_info,
  10420. "patient": patient,
  10421. "admin_info": adminInfo,
  10422. "his_hospital": record,
  10423. "bedCostTotal": bedCostTotal,
  10424. "operationCostTotal": operationCostTotal,
  10425. "otherCostTotal": otherCostTotal,
  10426. "materialCostTotal": materialCostTotal,
  10427. "westernMedicineCostTotal": westernMedicineCostTotal,
  10428. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10429. "checkCostTotal": checkCostTotal,
  10430. "zhenChaCostTotal": zhenChaCostTotal,
  10431. "laboratoryCostTotal": laboratoryCostTotal,
  10432. "treatCostTotal": treatCostTotal,
  10433. })
  10434. } else {
  10435. for _, item := range order_info {
  10436. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10437. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10438. item.MedChrgitmType = "09"
  10439. }
  10440. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10441. if item.HisPrescriptionProject.Type == 2 {
  10442. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10443. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10444. case 0:
  10445. item.MedChrgitmType = "0"
  10446. break
  10447. case 1:
  10448. item.MedChrgitmType = "14"
  10449. break
  10450. case 2:
  10451. item.MedChrgitmType = "05"
  10452. break
  10453. case 3:
  10454. item.MedChrgitmType = "03"
  10455. break
  10456. case 4:
  10457. item.MedChrgitmType = "03"
  10458. break
  10459. case 5:
  10460. item.MedChrgitmType = "08"
  10461. break
  10462. case 6:
  10463. item.MedChrgitmType = "14"
  10464. break
  10465. case 7:
  10466. item.MedChrgitmType = "14"
  10467. break
  10468. case 8:
  10469. item.MedChrgitmType = "03"
  10470. break
  10471. case 9:
  10472. item.MedChrgitmType = "14"
  10473. break
  10474. case 10:
  10475. item.MedChrgitmType = "14"
  10476. break
  10477. case 11:
  10478. item.MedChrgitmType = "06"
  10479. break
  10480. case 12:
  10481. item.MedChrgitmType = "12"
  10482. break
  10483. case 13:
  10484. item.MedChrgitmType = "01"
  10485. break
  10486. case 14:
  10487. item.MedChrgitmType = "04"
  10488. break
  10489. case 15:
  10490. item.MedChrgitmType = "14"
  10491. break
  10492. }
  10493. } else {
  10494. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10495. case 1:
  10496. item.MedChrgitmType = "14"
  10497. break
  10498. case 2:
  10499. item.MedChrgitmType = "05"
  10500. break
  10501. case 3:
  10502. item.MedChrgitmType = "04"
  10503. break
  10504. case 4:
  10505. item.MedChrgitmType = "14"
  10506. break
  10507. case 5:
  10508. item.MedChrgitmType = "08"
  10509. break
  10510. case 6:
  10511. item.MedChrgitmType = "14"
  10512. break
  10513. case 7:
  10514. item.MedChrgitmType = "14"
  10515. break
  10516. case 8:
  10517. item.MedChrgitmType = "03"
  10518. break
  10519. case 9:
  10520. item.MedChrgitmType = "14"
  10521. break
  10522. }
  10523. }
  10524. } else if item.HisPrescriptionProject.Type == 3 {
  10525. item.MedChrgitmType = "08"
  10526. }
  10527. }
  10528. }
  10529. for _, item := range order_info {
  10530. if org_id == 10215 {
  10531. if item.MedChrgitmType == "01" { //床位费
  10532. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10533. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10534. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10535. }
  10536. if item.MedChrgitmType == "02" { //诊察费
  10537. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10538. //zhenChaCostSelfTotal = zhenChaCostTotal
  10539. }
  10540. if item.MedChrgitmType == "03" { //检查费
  10541. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10542. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10543. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10544. }
  10545. //if item.MedChrgitmType == "02" { //检查费
  10546. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10547. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10548. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10549. //}
  10550. if item.MedChrgitmType == "04" { //化验费
  10551. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10552. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10553. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10554. }
  10555. if item.MedChrgitmType == "05" { //治疗费
  10556. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10557. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10558. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10559. }
  10560. if item.MedChrgitmType == "06" { //手术费
  10561. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10562. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10563. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10564. }
  10565. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10566. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10567. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10568. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10569. }
  10570. if item.MedChrgitmType == "09" { //西药费
  10571. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10572. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10573. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10574. }
  10575. if item.MedChrgitmType == "11" { //中成费
  10576. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10577. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10578. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10579. }
  10580. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10581. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10582. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10583. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10584. }
  10585. } else {
  10586. if item.MedChrgitmType == "01" { //床位费
  10587. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10588. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10589. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10590. }
  10591. //if item.MedChrgitmType == "02" { //诊察费
  10592. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10593. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10594. //}
  10595. if item.MedChrgitmType == "03" { //检查费
  10596. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10597. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10598. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10599. }
  10600. //if item.MedChrgitmType == "02" { //检查费
  10601. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. //}
  10605. if item.MedChrgitmType == "04" { //化验费
  10606. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10607. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10608. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10609. }
  10610. if item.MedChrgitmType == "05" { //治疗费
  10611. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10612. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10613. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10614. }
  10615. if item.MedChrgitmType == "06" { //手术费
  10616. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10617. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10618. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10619. }
  10620. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10621. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10622. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10623. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10624. }
  10625. if item.MedChrgitmType == "09" { //西药费
  10626. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10627. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10628. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10629. }
  10630. if item.MedChrgitmType == "11" { //中成费
  10631. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10632. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10633. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10634. }
  10635. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10636. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10637. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10638. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10639. }
  10640. }
  10641. }
  10642. c.ServeSuccessJSON(map[string]interface{}{
  10643. "order": order,
  10644. "order_info": order_info,
  10645. "patient": patient,
  10646. "admin_info": adminInfo,
  10647. "his_hospital": record,
  10648. "bedCostTotal": bedCostTotal,
  10649. "operationCostTotal": operationCostTotal,
  10650. "otherCostTotal": otherCostTotal,
  10651. "materialCostTotal": materialCostTotal,
  10652. "westernMedicineCostTotal": westernMedicineCostTotal,
  10653. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10654. "checkCostTotal": checkCostTotal,
  10655. "zhenChaCostTotal": zhenChaCostTotal,
  10656. "laboratoryCostTotal": laboratoryCostTotal,
  10657. "treatCostTotal": treatCostTotal,
  10658. })
  10659. }
  10660. }
  10661. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10662. page, _ := c.GetInt64("page")
  10663. limit, _ := c.GetInt64("limit")
  10664. keywords := c.GetString("keywords")
  10665. start_time := c.GetString("start_time")
  10666. end_time := c.GetString("end_time")
  10667. //clr_type := c.GetString("clr_type")
  10668. insutype := c.GetString("insutype")
  10669. timeLayout := "2006-01-02"
  10670. loc, _ := time.LoadLocation("Local")
  10671. var theStartTIme int64
  10672. if len(start_time) > 0 {
  10673. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10674. theStartTIme = theTime.Unix()
  10675. }
  10676. var theEndtTIme int64
  10677. if len(end_time) > 0 {
  10678. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10679. theEndtTIme = theTime.Unix()
  10680. }
  10681. if page <= 0 {
  10682. page = 1
  10683. }
  10684. if limit <= 0 {
  10685. limit = 10
  10686. }
  10687. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10688. c.ServeSuccessJSON(map[string]interface{}{
  10689. "total": total,
  10690. "list": list,
  10691. })
  10692. return
  10693. }
  10694. func (c *HisApiController) GetPutOnRecordList() {
  10695. page, _ := c.GetInt64("page")
  10696. limit, _ := c.GetInt64("limit")
  10697. keywords := c.GetString("keywords")
  10698. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10699. if page <= 0 {
  10700. page = 1
  10701. }
  10702. if limit <= 0 {
  10703. limit = 10
  10704. }
  10705. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10706. c.ServeSuccessJSON(map[string]interface{}{
  10707. "total": total,
  10708. "list": list,
  10709. })
  10710. return
  10711. }
  10712. func (c *HisApiController) GetCompareData() {
  10713. start_time := c.GetString("start_time")
  10714. end_time := c.GetString("end_time")
  10715. insutype := c.GetString("insutype")
  10716. clr_type := c.GetString("clr_type")
  10717. timeLayout := "2006-01-02"
  10718. loc, _ := time.LoadLocation("Local")
  10719. var theStartTIme int64
  10720. if len(start_time) > 0 {
  10721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10722. if err != nil {
  10723. theStartTIme = 0
  10724. }
  10725. theStartTIme = theTime.Unix()
  10726. }
  10727. var theEndtTIme int64
  10728. if len(end_time) > 0 {
  10729. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10730. if err != nil {
  10731. theEndtTIme = 0
  10732. }
  10733. theEndtTIme = theTime.Unix()
  10734. }
  10735. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10736. fmt.Println(err)
  10737. if err == nil {
  10738. c.ServeSuccessJSON(map[string]interface{}{
  10739. "list": formData,
  10740. })
  10741. } else {
  10742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10743. return
  10744. }
  10745. }
  10746. func (c *HisApiController) GetFaPiaoData() {
  10747. order_id, _ := c.GetInt64("order_id")
  10748. patient_id, _ := c.GetInt64("patient_id")
  10749. //number := c.GetString("number")
  10750. adminUser := c.GetAdminUserInfo()
  10751. order, _ := service.GetHisOrderByID(order_id)
  10752. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10753. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10754. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10755. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10756. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10757. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10758. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10759. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10760. var bedCostTotal float64 = 0 //床位总费
  10761. var bedCostSelfTotal float64 = 0 //床位自费
  10762. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10763. var operationCostTotal float64 = 0 //手术费
  10764. var operationCostSelfTotal float64 = 0 //手术费
  10765. var operationCostPartSelfTotal float64 = 0 //手术费
  10766. var otherCostTotal float64 = 0 //其他费用
  10767. var otherCostSelfTotal float64 = 0 //其他费用
  10768. var otherCostPartSelfTotal float64 = 0 //其他费用
  10769. var materialCostTotal float64 = 0 //材料费
  10770. var materialCostSelfTotal float64 = 0 //材料费
  10771. var materialCostPartSelfTotal float64 = 0 //材料费
  10772. var westernMedicineCostTotal float64 = 0 //西药费
  10773. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10774. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10775. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10776. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10777. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10778. var checkCostTotal float64 = 0 //检查费
  10779. var checkCostSelfTotal float64 = 0 //检查费
  10780. var checkCostPartSelfTotal float64 = 0 //检查费
  10781. var hiliCostTotal float64 = 0 //护理费
  10782. var hiliCostSelfTotal float64 = 0 //护理费
  10783. var hiliCostPartSelfTotal float64 = 0 //护理费
  10784. var laboratoryCostTotal float64 = 0 //化验费
  10785. var laboratoryCostSelfTotal float64 = 0 //化验费
  10786. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10787. var treatCostTotal float64 = 0 //治疗费用
  10788. var treatCostSelfTotal float64 = 0 //治疗费用
  10789. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10790. var zhenChaCostTotal float64 = 0 //其他费用
  10791. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10792. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10793. decimal.DivisionPrecision = 2
  10794. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10795. var balanceAccountsType int64
  10796. if his.ID > 0 {
  10797. balanceAccountsType = his.BalanceAccountsType
  10798. } else {
  10799. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10800. }
  10801. if balanceAccountsType == 2 {
  10802. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10803. for _, item := range orderInfos_two {
  10804. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10805. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10806. item.MedChrgitmType = "09"
  10807. }
  10808. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10809. if item.HisPrescriptionProject.Type == 2 {
  10810. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10811. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10812. case 0:
  10813. item.MedChrgitmType = "0"
  10814. break
  10815. case 1:
  10816. item.MedChrgitmType = "14"
  10817. break
  10818. case 2:
  10819. item.MedChrgitmType = "05"
  10820. break
  10821. case 3:
  10822. item.MedChrgitmType = "03"
  10823. break
  10824. case 4:
  10825. item.MedChrgitmType = "03"
  10826. break
  10827. case 5:
  10828. item.MedChrgitmType = "08"
  10829. break
  10830. case 6:
  10831. item.MedChrgitmType = "14"
  10832. break
  10833. case 7:
  10834. item.MedChrgitmType = "14"
  10835. break
  10836. case 8:
  10837. item.MedChrgitmType = "03"
  10838. break
  10839. case 9:
  10840. item.MedChrgitmType = "14"
  10841. break
  10842. case 10:
  10843. item.MedChrgitmType = "14"
  10844. break
  10845. case 11:
  10846. item.MedChrgitmType = "06"
  10847. break
  10848. case 12:
  10849. item.MedChrgitmType = "12"
  10850. break
  10851. case 13:
  10852. item.MedChrgitmType = "01"
  10853. break
  10854. case 14:
  10855. item.MedChrgitmType = "04"
  10856. break
  10857. case 15:
  10858. item.MedChrgitmType = "02"
  10859. break
  10860. }
  10861. } else {
  10862. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10863. case 1:
  10864. item.MedChrgitmType = "14"
  10865. break
  10866. case 2:
  10867. item.MedChrgitmType = "05"
  10868. break
  10869. case 3:
  10870. item.MedChrgitmType = "04"
  10871. break
  10872. case 4:
  10873. item.MedChrgitmType = "03"
  10874. break
  10875. case 5:
  10876. item.MedChrgitmType = "08"
  10877. break
  10878. case 6:
  10879. item.MedChrgitmType = "14"
  10880. break
  10881. case 7:
  10882. item.MedChrgitmType = "14"
  10883. break
  10884. case 8:
  10885. item.MedChrgitmType = "03"
  10886. break
  10887. case 9:
  10888. item.MedChrgitmType = "14"
  10889. break
  10890. }
  10891. }
  10892. } else if item.HisPrescriptionProject.Type == 3 {
  10893. item.MedChrgitmType = "08"
  10894. }
  10895. }
  10896. }
  10897. for _, item := range orderInfos_two {
  10898. fmt.Println(item.MedChrgitmType)
  10899. if item.MedChrgitmType == "07" { //床位费
  10900. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. hiliCostSelfTotal = hiliCostTotal
  10902. }
  10903. if item.MedChrgitmType == "01" { //床位费
  10904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10905. bedCostSelfTotal = bedCostTotal
  10906. }
  10907. if item.MedChrgitmType == "02" { //诊察费
  10908. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10909. zhenChaCostSelfTotal = zhenChaCostTotal
  10910. }
  10911. if item.MedChrgitmType == "03" { //检查费
  10912. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10913. checkCostSelfTotal = checkCostTotal
  10914. }
  10915. if item.MedChrgitmType == "04" { //化验费
  10916. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10917. laboratoryCostSelfTotal = laboratoryCostTotal
  10918. }
  10919. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10920. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. treatCostSelfTotal = treatCostTotal
  10922. }
  10923. if item.MedChrgitmType == "06" { //手术费
  10924. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10925. operationCostSelfTotal = treatCostTotal
  10926. }
  10927. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10928. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10929. materialCostSelfTotal = materialCostTotal
  10930. }
  10931. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10932. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10933. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10934. }
  10935. if item.MedChrgitmType == "11" { //中成费
  10936. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10937. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10938. }
  10939. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10940. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10941. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10942. otherCostSelfTotal = otherCostTotal
  10943. }
  10944. } else {
  10945. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10946. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10947. otherCostSelfTotal = otherCostTotal
  10948. }
  10949. }
  10950. }
  10951. } else {
  10952. for _, item := range orderInfos {
  10953. if item.MedChrgitmType == "01" { //床位费
  10954. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10955. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10956. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10957. }
  10958. if item.MedChrgitmType == "02" { //诊察费
  10959. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10960. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10961. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10962. }
  10963. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10964. if item.MedChrgitmType == "03" { //检查费
  10965. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10966. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10967. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10968. }
  10969. } else {
  10970. if item.MedChrgitmType == "03" { //检查费
  10971. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10972. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10973. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10974. }
  10975. }
  10976. if item.MedChrgitmType == "04" { //化验费
  10977. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10978. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10979. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10980. }
  10981. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10982. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10983. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10984. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10985. }
  10986. if item.MedChrgitmType == "06" { //手术费
  10987. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10988. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10989. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10990. }
  10991. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10992. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10993. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10994. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10995. }
  10996. if item.MedChrgitmType == "07" { //护理
  10997. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10998. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10999. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11000. }
  11001. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11002. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11003. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11004. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11005. }
  11006. if item.MedChrgitmType == "11" { //中成费
  11007. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11008. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11009. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11010. }
  11011. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11012. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11013. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11014. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11015. }
  11016. }
  11017. }
  11018. timeLayout := "2006-01-02"
  11019. loc, _ := time.LoadLocation("Local")
  11020. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11021. if err != nil {
  11022. }
  11023. startRecordDateTime := startTime.Unix()
  11024. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11025. if err != nil {
  11026. }
  11027. endRecordDateTime := endTime.Unix()
  11028. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11029. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11030. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11031. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11032. c.ServeSuccessJSON(map[string]interface{}{
  11033. "charge_admin_name": charge_admin.UserName,
  11034. "order_number": order.Number, //业务流水号
  11035. "id_card_no": his.IdCardNo, //社会保障号
  11036. "patient": patient,
  11037. "department_name": department.Name, //科室
  11038. "number": his.Number, //门诊号
  11039. "date": order.SettleAccountsDate, //结算日期
  11040. "name": order.PsnName, //姓名
  11041. "gender": patient.Gender, //性别
  11042. "psn_cash_money": order.PsnCashPay, //个人支付
  11043. "pay_way": "门诊", //结算方式
  11044. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11045. "admin_user_name": admin.UserName, //收款员
  11046. "order": order,
  11047. "order_info": orderInfos_two,
  11048. "his": his,
  11049. "bedCostTotal": bedCostTotal,
  11050. "bedCostSelfTotal": bedCostSelfTotal,
  11051. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11052. "operationCostTotal": operationCostTotal,
  11053. "operationCostSelfTotal": operationCostSelfTotal,
  11054. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11055. "otherCostTotal": otherCostTotal,
  11056. "otherCostSelfTotal": otherCostSelfTotal,
  11057. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11058. "materialCostTotal": materialCostTotal,
  11059. "materialCostSelfTotal": materialCostSelfTotal,
  11060. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11061. "westernMedicineCostTotal": westernMedicineCostTotal,
  11062. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11063. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11064. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11065. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11066. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11067. "checkCostTotal": checkCostTotal,
  11068. "checkCostSelfTotal": checkCostSelfTotal,
  11069. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11070. "laboratoryCostTotal": laboratoryCostTotal,
  11071. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11072. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11073. "treatCostTotal": treatCostTotal,
  11074. "treatCostSelfTotal": treatCostSelfTotal,
  11075. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11076. "zhenChaCostTotal": zhenChaCostTotal,
  11077. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11078. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11079. "his_hospital_record": his_hospital_record,
  11080. "pre_pay_money": pre_pay_money,
  11081. "refund_sum": sum,
  11082. "doctor_info": doctor_info,
  11083. "hiliCostTotal": hiliCostTotal,
  11084. "hiliCostSelfTotal": hiliCostSelfTotal,
  11085. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11086. })
  11087. }
  11088. //func (c *HisApiController) GetFaPiaoDatas() {
  11089. // order_ids := c.GetString("order_ids")
  11090. // patient_id, _ := c.GetInt64("patient_id")
  11091. // adminUser := c.GetAdminUserInfo()
  11092. //
  11093. // orders := strings.Split(order_ids, ",")
  11094. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11095. //
  11096. // for _, item := range orders {
  11097. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11098. // order, _ := service.GetHisOrderByID(order_id)
  11099. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11100. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11101. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11102. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11103. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11104. //
  11105. // }
  11106. //
  11107. // var bedCostTotal float64 = 0 //床位总费
  11108. // var bedCostSelfTotal float64 = 0 //床位自费
  11109. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11110. //
  11111. // var operationCostTotal float64 = 0 //手术费
  11112. // var operationCostSelfTotal float64 = 0 //手术费
  11113. // var operationCostPartSelfTotal float64 = 0 //手术费
  11114. //
  11115. // var otherCostTotal float64 = 0 //其他费用
  11116. // var otherCostSelfTotal float64 = 0 //其他费用
  11117. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11118. //
  11119. // var materialCostTotal float64 = 0 //材料费
  11120. // var materialCostSelfTotal float64 = 0 //材料费
  11121. // var materialCostPartSelfTotal float64 = 0 //材料费
  11122. //
  11123. // var westernMedicineCostTotal float64 = 0 //西药费
  11124. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11125. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11126. //
  11127. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11128. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11129. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11130. //
  11131. // var checkCostTotal float64 = 0 //检查费
  11132. // var checkCostSelfTotal float64 = 0 //检查费
  11133. // var checkCostPartSelfTotal float64 = 0 //检查费
  11134. //
  11135. // var laboratoryCostTotal float64 = 0 //化验费
  11136. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11137. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11138. //
  11139. // var treatCostTotal float64 = 0 //治疗费用
  11140. // var treatCostSelfTotal float64 = 0 //治疗费用
  11141. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11142. //
  11143. // var zhenChaCostTotal float64 = 0 //其他费用
  11144. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11145. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11146. //
  11147. // decimal.DivisionPrecision = 2
  11148. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11149. //
  11150. // var balanceAccountsType int64
  11151. // if his.ID > 0 {
  11152. // balanceAccountsType = his.BalanceAccountsType
  11153. // } else {
  11154. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11155. // }
  11156. // if balanceAccountsType == 2 {
  11157. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11158. // for _, item := range orderInfos_two {
  11159. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11160. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11161. // item.MedChrgitmType = "09"
  11162. // }
  11163. //
  11164. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11165. // if item.HisPrescriptionProject.Type == 2 {
  11166. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11167. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11168. // case 0:
  11169. // item.MedChrgitmType = "0"
  11170. // break
  11171. // case 1:
  11172. // item.MedChrgitmType = "14"
  11173. // break
  11174. // case 2:
  11175. // item.MedChrgitmType = "05"
  11176. //
  11177. // break
  11178. // case 3:
  11179. // item.MedChrgitmType = "03"
  11180. //
  11181. // break
  11182. // case 4:
  11183. // item.MedChrgitmType = "03"
  11184. //
  11185. // break
  11186. // case 5:
  11187. // item.MedChrgitmType = "08"
  11188. //
  11189. // break
  11190. // case 6:
  11191. // item.MedChrgitmType = "14"
  11192. //
  11193. // break
  11194. // case 7:
  11195. // item.MedChrgitmType = "14"
  11196. //
  11197. // break
  11198. // case 8:
  11199. // item.MedChrgitmType = "03"
  11200. // break
  11201. // case 9:
  11202. // item.MedChrgitmType = "14"
  11203. // break
  11204. // case 10:
  11205. // item.MedChrgitmType = "14"
  11206. // break
  11207. // case 11:
  11208. // item.MedChrgitmType = "06"
  11209. // break
  11210. // case 12:
  11211. // item.MedChrgitmType = "12"
  11212. // break
  11213. // case 13:
  11214. // item.MedChrgitmType = "01"
  11215. // break
  11216. // case 14:
  11217. // item.MedChrgitmType = "04"
  11218. // break
  11219. // case 15:
  11220. // item.MedChrgitmType = "02"
  11221. // break
  11222. //
  11223. // }
  11224. //
  11225. // } else {
  11226. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11227. //
  11228. // case 1:
  11229. // item.MedChrgitmType = "14"
  11230. // break
  11231. // case 2:
  11232. // item.MedChrgitmType = "05"
  11233. //
  11234. // break
  11235. // case 3:
  11236. // item.MedChrgitmType = "03"
  11237. //
  11238. // break
  11239. // case 4:
  11240. // item.MedChrgitmType = "03"
  11241. //
  11242. // break
  11243. // case 5:
  11244. // item.MedChrgitmType = "08"
  11245. //
  11246. // break
  11247. // case 6:
  11248. // item.MedChrgitmType = "14"
  11249. //
  11250. // break
  11251. // case 7:
  11252. // item.MedChrgitmType = "14"
  11253. //
  11254. // break
  11255. // case 8:
  11256. // item.MedChrgitmType = "03"
  11257. // break
  11258. // case 9:
  11259. // item.MedChrgitmType = "14"
  11260. // break
  11261. //
  11262. // }
  11263. //
  11264. // }
  11265. //
  11266. // } else if item.HisPrescriptionProject.Type == 3 {
  11267. // item.MedChrgitmType = "08"
  11268. // }
  11269. // }
  11270. // }
  11271. //
  11272. // for _, item := range orderInfos_two {
  11273. // fmt.Println(item.MedChrgitmType)
  11274. // if item.MedChrgitmType == "01" { //床位费
  11275. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11276. // bedCostSelfTotal = bedCostTotal
  11277. // }
  11278. //
  11279. // if item.MedChrgitmType == "02" { //诊察费
  11280. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11281. // zhenChaCostSelfTotal = zhenChaCostTotal
  11282. // }
  11283. //
  11284. // if item.MedChrgitmType == "03" { //检查费
  11285. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11286. // checkCostSelfTotal = checkCostTotal
  11287. // }
  11288. //
  11289. // if item.MedChrgitmType == "04" { //化验费
  11290. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11291. // laboratoryCostSelfTotal = laboratoryCostTotal
  11292. // }
  11293. //
  11294. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11295. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11296. // treatCostSelfTotal = treatCostTotal
  11297. // }
  11298. //
  11299. // if item.MedChrgitmType == "06" { //手术费
  11300. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11301. // operationCostSelfTotal = treatCostTotal
  11302. // }
  11303. //
  11304. // if item.MedChrgitmType == "08" { //材料费
  11305. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11306. // materialCostSelfTotal = materialCostTotal
  11307. // }
  11308. //
  11309. // if item.MedChrgitmType == "09" { //西药费
  11310. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11311. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11312. // }
  11313. //
  11314. // if item.MedChrgitmType == "11" { //中成费
  11315. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11316. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11317. // }
  11318. //
  11319. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11320. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11321. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11322. // otherCostSelfTotal = otherCostTotal
  11323. // }
  11324. // } else {
  11325. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11326. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11327. // otherCostSelfTotal = otherCostTotal
  11328. // }
  11329. //
  11330. // }
  11331. //
  11332. // }
  11333. //
  11334. // } else {
  11335. // for _, item := range orderInfos {
  11336. // if item.MedChrgitmType == "01" { //床位费
  11337. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11338. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11339. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11340. // }
  11341. //
  11342. // if item.MedChrgitmType == "02" { //诊察费
  11343. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11344. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11345. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11346. // }
  11347. //
  11348. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11349. // if item.MedChrgitmType == "03" { //检查费
  11350. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11351. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11352. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11353. //
  11354. // }
  11355. // } else {
  11356. // if item.MedChrgitmType == "03" { //检查费
  11357. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11358. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11359. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11360. // }
  11361. //
  11362. // }
  11363. //
  11364. // if item.MedChrgitmType == "04" { //化验费
  11365. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11366. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11367. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11368. //
  11369. // }
  11370. //
  11371. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11372. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11373. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11374. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11375. //
  11376. // }
  11377. //
  11378. // if item.MedChrgitmType == "06" { //手术费
  11379. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11380. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11381. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11382. // }
  11383. //
  11384. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11385. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11386. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11387. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11388. // }
  11389. //
  11390. // if item.MedChrgitmType == "09" { //西药费
  11391. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11392. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11393. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11394. // }
  11395. //
  11396. // if item.MedChrgitmType == "11" { //中成费
  11397. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11398. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11399. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11400. // }
  11401. //
  11402. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11403. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11404. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11405. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11406. // }
  11407. //
  11408. // }
  11409. // }
  11410. // timeLayout := "2006-01-02"
  11411. // loc, _ := time.LoadLocation("Local")
  11412. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11413. // if err != nil {
  11414. // }
  11415. // startRecordDateTime := startTime.Unix()
  11416. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11417. // if err != nil {
  11418. // }
  11419. // endRecordDateTime := endTime.Unix()
  11420. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11421. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11422. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11423. //
  11424. // c.ServeSuccessJSON(map[string]interface{}{
  11425. // "order_number": order.Number, //业务流水号
  11426. // "id_card_no": his.IdCardNo, //社会保障号
  11427. // "department_name": department.Name, //科室
  11428. // "number": his.Number, //门诊号
  11429. // "date": order.SettleAccountsDate, //结算日期
  11430. // "name": order.PsnName, //姓名
  11431. // "gender": patient.Gender, //性别
  11432. // "psn_cash_money": order.PsnCashPay, //个人支付
  11433. // "pay_way": "门诊", //结算方式
  11434. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11435. // "admin_user_name": admin.UserName, //收款员
  11436. // "order": order,
  11437. // "order_info": orderInfos_two,
  11438. // "his": his,
  11439. // "bedCostTotal": bedCostTotal,
  11440. // "bedCostSelfTotal": bedCostSelfTotal,
  11441. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11442. // "operationCostTotal": operationCostTotal,
  11443. // "operationCostSelfTotal": operationCostSelfTotal,
  11444. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11445. // "otherCostTotal": otherCostTotal,
  11446. // "otherCostSelfTotal": otherCostSelfTotal,
  11447. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11448. // "materialCostTotal": materialCostTotal,
  11449. // "materialCostSelfTotal": materialCostSelfTotal,
  11450. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11451. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11452. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11453. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11454. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11455. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11456. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11457. // "checkCostTotal": checkCostTotal,
  11458. // "checkCostSelfTotal": checkCostSelfTotal,
  11459. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11460. // "laboratoryCostTotal": laboratoryCostTotal,
  11461. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11462. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11463. // "treatCostTotal": treatCostTotal,
  11464. // "treatCostSelfTotal": treatCostSelfTotal,
  11465. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11466. // "zhenChaCostTotal": zhenChaCostTotal,
  11467. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11468. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11469. // "his_hospital_record": his_hospital_record,
  11470. // "pre_pay_money": pre_pay_money,
  11471. // "refund_sum": sum,
  11472. // })
  11473. //
  11474. //}
  11475. func (this *HisApiController) GetIncomeStatisticsData() {
  11476. start_time := this.GetString("start_time")
  11477. end_time := this.GetString("end_time")
  11478. key_words := this.GetString("key_words")
  11479. limit, _ := this.GetInt64("limit")
  11480. page, _ := this.GetInt64("page")
  11481. if page <= 0 {
  11482. page = 1
  11483. }
  11484. if limit <= 0 {
  11485. limit = 10
  11486. }
  11487. statistics_type, _ := this.GetInt64("statistics_type")
  11488. admin := this.GetAdminUserInfo()
  11489. timeLayout := "2006-01-02"
  11490. loc, _ := time.LoadLocation("Local")
  11491. var theStartTIme int64
  11492. if len(start_time) > 0 {
  11493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11494. if err != nil {
  11495. theStartTIme = 0
  11496. }
  11497. theStartTIme = theTime.Unix()
  11498. }
  11499. var theEndtTIme int64
  11500. if len(end_time) > 0 {
  11501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11502. if err != nil {
  11503. theEndtTIme = 0
  11504. }
  11505. theEndtTIme = theTime.Unix()
  11506. }
  11507. if statistics_type == 1 {
  11508. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11509. this.ServeSuccessJSON(map[string]interface{}{
  11510. "list": list,
  11511. "total": total,
  11512. })
  11513. } else {
  11514. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11515. this.ServeSuccessJSON(map[string]interface{}{
  11516. "list": list,
  11517. "total": total,
  11518. })
  11519. }
  11520. }
  11521. func (c *HisApiController) PostProjectInformation() {
  11522. adminUser := c.GetAdminUserInfo()
  11523. orgId := adminUser.CurrentOrgId
  11524. dataBody := make(map[string]interface{}, 0)
  11525. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11526. if err != nil {
  11527. utils.ErrorLog(err.Error())
  11528. return
  11529. }
  11530. utils.ErrorLog("%v", dataBody)
  11531. var projectList []*models.HisProject
  11532. var total_goods []interface{}
  11533. tempProjects := dataBody["projects"].([]interface{})
  11534. total_goods = tempProjects
  11535. for index, projectMap := range tempProjects {
  11536. projectM := projectMap.(map[string]interface{})
  11537. var project models.HisProject
  11538. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11539. utils.ErrorLog("project_name")
  11540. return
  11541. }
  11542. project_name, _ := projectM["project_name"].(string)
  11543. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11544. err_log := models.ExportErrLog{
  11545. LogType: 6,
  11546. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11547. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11548. Status: 1,
  11549. CreateTime: time.Now().Unix(),
  11550. UpdateTime: time.Now().Unix(),
  11551. ExportTime: time.Now().Unix(),
  11552. }
  11553. service.CreateExportErrLog(&err_log)
  11554. continue
  11555. }
  11556. project.ProjectName = project_name
  11557. prices := projectM["price"].(string)
  11558. price, _ := strconv.ParseFloat(prices, 64)
  11559. if price <= 0 { //名字为空则生成一条导入错误日志
  11560. err_log := models.ExportErrLog{
  11561. LogType: 6,
  11562. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11563. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11564. Status: 1,
  11565. CreateTime: time.Now().Unix(),
  11566. UpdateTime: time.Now().Unix(),
  11567. ExportTime: time.Now().Unix(),
  11568. }
  11569. service.CreateExportErrLog(&err_log)
  11570. continue
  11571. }
  11572. project.Price = price
  11573. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11574. utils.ErrorLog("unit_id")
  11575. return
  11576. }
  11577. unit := projectM["unit"].(string)
  11578. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11579. err_log := models.ExportErrLog{
  11580. LogType: 6,
  11581. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11582. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11583. Status: 1,
  11584. CreateTime: time.Now().Unix(),
  11585. UpdateTime: time.Now().Unix(),
  11586. ExportTime: time.Now().Unix(),
  11587. }
  11588. service.CreateExportErrLog(&err_log)
  11589. continue
  11590. }
  11591. project.Unit = unit
  11592. cost_classify := projectM["cost_classify"].(string)
  11593. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11594. err_log := models.ExportErrLog{
  11595. LogType: 6,
  11596. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11597. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11598. Status: 1,
  11599. CreateTime: time.Now().Unix(),
  11600. UpdateTime: time.Now().Unix(),
  11601. ExportTime: time.Now().Unix(),
  11602. }
  11603. service.CreateExportErrLog(&err_log)
  11604. continue
  11605. }
  11606. var costClassify = "费用类别"
  11607. var cost_classify_id int64
  11608. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11609. if len(cost_classify) != 0 {
  11610. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11611. if errcode == gorm.ErrRecordNotFound {
  11612. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11613. dataconfig := models.DictDataconfig{
  11614. ParentId: costClassifyConfig.ID,
  11615. Module: "system",
  11616. OrgId: orgId,
  11617. Name: cost_classify,
  11618. FieldName: "",
  11619. Value: costConfig.Value + 1,
  11620. CreatedTime: "",
  11621. UpdatedTime: "",
  11622. CreateUserId: adminUser.AdminUser.Id,
  11623. Status: 1,
  11624. Remark: "",
  11625. DeleteIdSystem: 0,
  11626. Title: "",
  11627. Content: "",
  11628. Order: 0,
  11629. Code: "",
  11630. }
  11631. service.CreatedDicConfig(&dataconfig)
  11632. }
  11633. }
  11634. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11635. for _, it := range costClassList {
  11636. if cost_classify == it.Name {
  11637. cost_classify_id = int64(it.Value)
  11638. }
  11639. }
  11640. project.CostClassify = cost_classify_id
  11641. executive_section := projectM["executive_section"].(string)
  11642. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11643. err_log := models.ExportErrLog{
  11644. LogType: 6,
  11645. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11646. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11647. Status: 1,
  11648. CreateTime: time.Now().Unix(),
  11649. UpdateTime: time.Now().Unix(),
  11650. ExportTime: time.Now().Unix(),
  11651. }
  11652. service.CreateExportErrLog(&err_log)
  11653. continue
  11654. }
  11655. if len(executive_section) != 0 {
  11656. //查找科室是否有内容
  11657. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11658. if errcodedepart == gorm.ErrRecordNotFound {
  11659. department := models.XtHisDepartment{
  11660. Name: executive_section,
  11661. Status: 1,
  11662. UserOrgId: adminUser.CurrentOrgId,
  11663. CreatedTime: time.Now().Unix(),
  11664. }
  11665. service.CreateDePartment(&department)
  11666. }
  11667. }
  11668. var executive_section_id int64
  11669. departMentList, _ := service.GetAllDepartMent(orgId)
  11670. for _, it := range departMentList {
  11671. if executive_section == it.Name {
  11672. executive_section_id = it.ID
  11673. }
  11674. }
  11675. project.ExecutiveSection = executive_section_id
  11676. medical_coverage := projectM["medical_coverage"].(string)
  11677. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11678. err_log := models.ExportErrLog{
  11679. LogType: 6,
  11680. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11681. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11682. Status: 1,
  11683. CreateTime: time.Now().Unix(),
  11684. UpdateTime: time.Now().Unix(),
  11685. ExportTime: time.Now().Unix(),
  11686. }
  11687. service.CreateExportErrLog(&err_log)
  11688. continue
  11689. }
  11690. var medicalCoverage = "医保等级"
  11691. var medical_coverage_id int64
  11692. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11693. if len(medical_coverage) != 0 {
  11694. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11695. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11696. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11697. dataconfig := models.DictDataconfig{
  11698. ParentId: medicalCoverageConfig.ID,
  11699. Module: "system",
  11700. OrgId: orgId,
  11701. Name: medical_coverage,
  11702. FieldName: "",
  11703. Value: medicalCoverageConfig.Value + 1,
  11704. CreatedTime: "",
  11705. UpdatedTime: "",
  11706. CreateUserId: adminUser.AdminUser.Id,
  11707. Status: 1,
  11708. Remark: "",
  11709. DeleteIdSystem: 0,
  11710. Title: "",
  11711. Content: "",
  11712. Order: 0,
  11713. Code: "",
  11714. }
  11715. service.CreatedDicConfig(&dataconfig)
  11716. }
  11717. }
  11718. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11719. for _, it := range medicalCoverageList {
  11720. if medical_coverage == it.Name {
  11721. medical_coverage_id = int64(it.Value)
  11722. }
  11723. }
  11724. project.MedicalCoverage = medical_coverage_id
  11725. pinyin := projectM["pinyin"].(string)
  11726. project.Pinyin = pinyin
  11727. wubi := projectM["wubi"].(string)
  11728. project.Wubi = wubi
  11729. statistical_classification := projectM["statistical_classification"].(string)
  11730. var statisticalClassification = "统计分类"
  11731. var statistical_classification_id int64
  11732. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11733. if len(statistical_classification) != 0 {
  11734. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11735. if classificationerrcodes == gorm.ErrRecordNotFound {
  11736. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11737. dataconfig := models.DictDataconfig{
  11738. ParentId: classiFication.ID,
  11739. Module: "system",
  11740. OrgId: orgId,
  11741. Name: statistical_classification,
  11742. FieldName: "",
  11743. Value: classiFicationConfig.Value + 1,
  11744. CreatedTime: "",
  11745. UpdatedTime: "",
  11746. CreateUserId: adminUser.AdminUser.Id,
  11747. Status: 1,
  11748. Remark: "",
  11749. DeleteIdSystem: 0,
  11750. Title: "",
  11751. Content: "",
  11752. Order: 0,
  11753. Code: "",
  11754. }
  11755. service.CreatedDicConfig(&dataconfig)
  11756. }
  11757. }
  11758. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11759. for _, it := range classiFicationList {
  11760. if statistical_classification == it.Name {
  11761. statistical_classification_id = int64(it.Value)
  11762. }
  11763. }
  11764. project.StatisticalClassification = statistical_classification_id
  11765. disease_directory := int64(projectM["disease_directory"].(float64))
  11766. project.DiseaseDirectory = disease_directory
  11767. is_record := int64(projectM["is_record"].(float64))
  11768. project.IsRecord = is_record
  11769. medical_code := projectM["medical_code"].(string)
  11770. project.MedicalCode = medical_code
  11771. tube_color := projectM["tube_color"].(string)
  11772. var tubeColor = "试管颜色"
  11773. var tube_color_id int64
  11774. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11775. if len(tube_color) != 0 {
  11776. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11777. if errcodetube == gorm.ErrRecordNotFound {
  11778. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11779. dataconfig := models.DictDataconfig{
  11780. ParentId: tubeColorConfig.ID,
  11781. Module: "system",
  11782. OrgId: orgId,
  11783. Name: tube_color,
  11784. FieldName: "",
  11785. Value: tubeConfig.Value + 1,
  11786. CreatedTime: "",
  11787. UpdatedTime: "",
  11788. CreateUserId: adminUser.AdminUser.Id,
  11789. Status: 1,
  11790. Remark: "",
  11791. DeleteIdSystem: 0,
  11792. Title: "",
  11793. Content: "",
  11794. Order: 0,
  11795. Code: "",
  11796. }
  11797. service.CreatedDicConfig(&dataconfig)
  11798. }
  11799. }
  11800. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11801. for _, it := range tubeColorList {
  11802. if tube_color == it.Name {
  11803. tube_color_id = int64(it.Value)
  11804. }
  11805. }
  11806. project.TubeColor = tube_color_id
  11807. single_dose := projectM["single_dose"].(string)
  11808. project.SingleDose = single_dose
  11809. execution_frequency := projectM["execution_frequency"].(string)
  11810. project.ExecutionFrequency = execution_frequency
  11811. delivery_way := projectM["delivery_way"].(string)
  11812. project.DeliveryWay = delivery_way
  11813. number_days := projectM["number_days"].(string)
  11814. project.NumberDays = number_days
  11815. total := projectM["total"].(string)
  11816. project.Total = total
  11817. medical_status := int64(projectM["medical_status"].(float64))
  11818. project.MedicalStatus = medical_status
  11819. category := int64(projectM["category"].(float64))
  11820. project.Category = category
  11821. specail_project := int64(projectM["specail_project"].(float64))
  11822. project.SpecailProject = specail_project
  11823. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11824. project.SocialSecurityDirectoryCode = social_security_directory_code
  11825. remark := projectM["remark"].(string)
  11826. project.Remark = remark
  11827. record_date := projectM["record_date"].(string)
  11828. timeLayout := "2006-01-02"
  11829. loc, _ := time.LoadLocation("Local")
  11830. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11831. project.RecordDate = theTime.Unix()
  11832. projectList = append(projectList, &project)
  11833. }
  11834. export_time := time.Now().Unix()
  11835. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11836. if len(projectList) > 0 {
  11837. for _, item := range projectList {
  11838. hans := item.ProjectName // 要转换的汉字字符串
  11839. // 创建一个拼音转换器
  11840. p := pinyin.NewArgs()
  11841. // 将汉字转为拼音
  11842. pinyinSlice := pinyin.Pinyin(hans, p)
  11843. // 输出拼音
  11844. fmt.Println("Pinyin:", pinyinSlice)
  11845. // 获取首字母
  11846. firstLetter := ""
  11847. for _, py := range pinyinSlice {
  11848. if len(py) > 0 {
  11849. firstLetter += string(py[0][0])
  11850. }
  11851. }
  11852. item.FirstLetter = firstLetter
  11853. project := models.HisProject{
  11854. ProjectName: item.ProjectName,
  11855. Price: item.Price,
  11856. Unit: item.Unit,
  11857. CostClassify: item.CostClassify,
  11858. ExecutiveSection: item.ExecutiveSection,
  11859. MedicalCoverage: item.MedicalCoverage,
  11860. UserOrgId: orgId,
  11861. Status: 1,
  11862. CreatedTime: time.Now().Unix(),
  11863. Pinyin: item.Pinyin,
  11864. Wubi: item.Wubi,
  11865. StatisticalClassification: item.StatisticalClassification,
  11866. DiseaseDirectory: item.DiseaseDirectory,
  11867. IsRecord: item.IsRecord,
  11868. MedicalCode: item.MedicalCode,
  11869. TubeColor: item.TubeColor,
  11870. SingleDose: item.SingleDose,
  11871. DeliveryWay: item.DeliveryWay,
  11872. NumberDays: item.NumberDays,
  11873. Total: item.Total,
  11874. Category: item.Category,
  11875. MedicalStatus: item.MedicalStatus,
  11876. SpecailProject: item.SpecailProject,
  11877. RecordDate: item.RecordDate,
  11878. Remark: item.Remark,
  11879. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11880. ExecutionFrequency: item.ExecutionFrequency,
  11881. FirstLetter: item.FirstLetter,
  11882. }
  11883. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11884. if errcodeproject == gorm.ErrRecordNotFound {
  11885. service.CreateProjectInfomation(&project)
  11886. } else if errcodeproject == nil {
  11887. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11888. }
  11889. log := models.ExportLog{
  11890. LogType: 6,
  11891. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11892. TotalNum: int64(len(total_goods)),
  11893. FailNum: int64(len(errLogs)),
  11894. SuccessNum: int64(len(projectList)),
  11895. CreateTime: time.Now().Unix(),
  11896. UpdateTime: time.Now().Unix(),
  11897. ExportTime: export_time,
  11898. Status: 1,
  11899. }
  11900. service.CreateExportLog(&log)
  11901. c.ServeSuccessJSON(map[string]interface{}{
  11902. "msg": "导入成功",
  11903. "total_num": len(total_goods),
  11904. "success_num": len(projectList),
  11905. "fail_num": int64(len(errLogs)),
  11906. })
  11907. }
  11908. } else {
  11909. log := models.ExportLog{
  11910. LogType: 6,
  11911. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11912. TotalNum: int64(len(total_goods)),
  11913. FailNum: int64(len(errLogs)),
  11914. SuccessNum: int64(len(projectList)),
  11915. CreateTime: time.Now().Unix(),
  11916. UpdateTime: time.Now().Unix(),
  11917. ExportTime: export_time,
  11918. Status: 1,
  11919. }
  11920. service.CreateExportLog(&log)
  11921. c.ServeSuccessJSON(map[string]interface{}{
  11922. "msg": "导入成功",
  11923. "total_num": len(total_goods),
  11924. "success_num": len(projectList),
  11925. "fail_num": int64(len(errLogs)),
  11926. })
  11927. }
  11928. }
  11929. //func (this *HisApiController) EditProjectInformation(){
  11930. //
  11931. // id, _ := this.GetInt64("id")
  11932. // project_team := this.GetString("project_team")
  11933. // price := this.GetString("price")
  11934. // price_float, _ := strconv.ParseFloat(price, 64)
  11935. // pinyin := this.GetString("pinyin")
  11936. // wubi := this.GetString("wubi")
  11937. // tube_color, _ := this.GetInt64("tube_color")
  11938. // team_type, _ := this.GetInt64("team_type")
  11939. // remark := this.GetString("remark")
  11940. // ids := this.GetString("ids")
  11941. // item_id := this.GetString("item_id")
  11942. // projectTeam := models.XtHisProjectTeam{
  11943. // ProjectTeam: project_team,
  11944. // Price: price_float,
  11945. // Pinyin: pinyin,
  11946. // Wubi: wubi,
  11947. // TubeColor: tube_color,
  11948. // TeamType: team_type,
  11949. // Remark: remark,
  11950. // ProjectId: ids,
  11951. // ItemId: item_id,
  11952. // }
  11953. //
  11954. //
  11955. // dataBody := make(map[string]interface{}, 0)
  11956. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11957. // if err != nil {
  11958. // utils.ErrorLog(err.Error())
  11959. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11960. // return
  11961. // }
  11962. //
  11963. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11964. //
  11965. //
  11966. // if err != nil {
  11967. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11968. // return
  11969. // }
  11970. //
  11971. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11972. // infos, _ := dataBody["info"].([]interface{})
  11973. // if len(infos) > 0 {
  11974. // var ids []string
  11975. //
  11976. // for _, item := range infos {
  11977. // items := item.(map[string]interface{})
  11978. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11979. // utils.ErrorLog("id")
  11980. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11981. // return
  11982. // }
  11983. // id := int64(items["id"].(float64))
  11984. //
  11985. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11986. // utils.ErrorLog("type")
  11987. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11988. // return
  11989. // }
  11990. // types := int64(items["type"].(float64))
  11991. //
  11992. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11993. // utils.ErrorLog("number")
  11994. // }
  11995. //
  11996. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11997. //
  11998. // projectList := models.XtHisProjectList{
  11999. // Number: number,
  12000. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12001. // ProjectId: id,
  12002. // Status: 1,
  12003. // CreatedTime: time.Now().Unix(),
  12004. // UpdatedTime: time.Now().Unix(),
  12005. // TeamId: projectTeam.ID,
  12006. // Type: types,
  12007. // }
  12008. // list := projectList
  12009. //
  12010. // service.CreateProjectList(&list)
  12011. //
  12012. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12013. //
  12014. // }
  12015. // ids_str := strings.Join(ids, ",")
  12016. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12017. // service.SaveProjectTeam(&projectTeam)
  12018. // this.ServeSuccessJSON(map[string]interface{}{
  12019. // "projectTeam": projectTeam,
  12020. // })
  12021. // }
  12022. // }
  12023. //}
  12024. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12025. name := c.GetString("name")
  12026. mode_id, _ := c.GetInt64("mode", 0)
  12027. types, _ := c.GetInt64("type", 0)
  12028. patient_id, _ := c.GetInt64("patient_id", 0)
  12029. types = 1
  12030. adminInfo := c.GetAdminUserInfo()
  12031. template := &models.HisPrescriptionTemplate{
  12032. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12033. PatientId: patient_id,
  12034. Type: types,
  12035. Status: 1,
  12036. Ctime: time.Now().Unix(),
  12037. Mtime: time.Now().Unix(),
  12038. Name: name,
  12039. Mode: mode_id,
  12040. }
  12041. dataBody := make(map[string]interface{}, 0)
  12042. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12043. if err != nil {
  12044. utils.ErrorLog(err.Error())
  12045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12046. return
  12047. }
  12048. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12049. //如果已经存在记录则删除处方
  12050. if template_one.ID > 0 {
  12051. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12052. var ids []int64
  12053. var org_id int64
  12054. for _, item := range ps {
  12055. org_id = c.GetAdminUserInfo().CurrentOrgId
  12056. ids = append(ids, item.ID)
  12057. }
  12058. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12059. if err2 == nil {
  12060. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12061. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12062. if len(prescriptions) > 0 {
  12063. for _, item := range prescriptions {
  12064. items := item.(map[string]interface{})
  12065. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12066. utils.ErrorLog("type")
  12067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12068. return
  12069. }
  12070. types := int64(items["type"].(float64))
  12071. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12072. utils.ErrorLog("med_type")
  12073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12074. return
  12075. }
  12076. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12077. ctime := time.Now().Unix()
  12078. prescription := &models.HisPrescriptionInfoTemplate{
  12079. PatientId: patient_id,
  12080. UserOrgId: adminInfo.CurrentOrgId,
  12081. Ctime: ctime,
  12082. Mtime: ctime,
  12083. Type: types,
  12084. Modifier: adminInfo.AdminUser.Id,
  12085. Creator: adminInfo.AdminUser.Id,
  12086. Status: 1,
  12087. PTemplateId: template_one.ID,
  12088. MedType: med_type,
  12089. }
  12090. service.CreateHisPrescriptionInfoTemplate(prescription)
  12091. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12092. advices := items["advices"].([]interface{})
  12093. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12094. ctime := time.Now().Unix()
  12095. mtime := ctime
  12096. if len(advices) > 0 {
  12097. for _, advice := range advices {
  12098. var s models.HisPrescriptionAdviceTemplate
  12099. s.PrescriptionId = prescription.ID
  12100. s.AdviceType = 2
  12101. s.StopState = 2
  12102. s.ExecutionState = 2
  12103. s.Status = 1
  12104. s.UserOrgId = adminInfo.CurrentOrgId
  12105. s.CreatedTime = ctime
  12106. s.UpdatedTime = mtime
  12107. s.PatientId = patient_id
  12108. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12109. if errcode > 0 {
  12110. c.ServeFailJSONWithSGJErrorCode(errcode)
  12111. return
  12112. }
  12113. service.CreateHisPrescriptionAdviceTemplate(&s)
  12114. }
  12115. }
  12116. }
  12117. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12118. projects := items["project"].([]interface{})
  12119. if len(projects) > 0 {
  12120. for _, project := range projects {
  12121. var p models.HisPrescriptionProjectTemplate
  12122. p.PrescriptionId = prescription.ID
  12123. p.Ctime = time.Now().Unix()
  12124. p.Mtime = time.Now().Unix()
  12125. p.PatientId = patient_id
  12126. p.UserOrgId = adminInfo.CurrentOrgId
  12127. p.Status = 1
  12128. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12129. if errcode > 0 {
  12130. c.ServeFailJSONWithSGJErrorCode(errcode)
  12131. return
  12132. }
  12133. service.CreateHisPrescriptionProjectTemplate(&p)
  12134. }
  12135. }
  12136. }
  12137. }
  12138. c.ServeSuccessJSON(map[string]interface{}{
  12139. "msg": "创建成功",
  12140. })
  12141. }
  12142. }
  12143. } else {
  12144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12145. return
  12146. }
  12147. } else {
  12148. err3 := service.CreateHisPrescriptionTemplate(template)
  12149. if err3 == nil {
  12150. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12151. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12152. if len(prescriptions) > 0 {
  12153. for _, item := range prescriptions {
  12154. items := item.(map[string]interface{})
  12155. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12156. utils.ErrorLog("type")
  12157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12158. return
  12159. }
  12160. types := int64(items["type"].(float64))
  12161. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12162. utils.ErrorLog("med_type")
  12163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12164. return
  12165. }
  12166. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12167. ctime := time.Now().Unix()
  12168. prescription := &models.HisPrescriptionInfoTemplate{
  12169. PatientId: patient_id,
  12170. UserOrgId: adminInfo.CurrentOrgId,
  12171. Ctime: ctime,
  12172. Mtime: ctime,
  12173. Type: types,
  12174. Modifier: adminInfo.AdminUser.Id,
  12175. Creator: adminInfo.AdminUser.Id,
  12176. Status: 1,
  12177. PTemplateId: template.ID,
  12178. MedType: med_type,
  12179. }
  12180. service.CreateHisPrescriptionInfoTemplate(prescription)
  12181. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12182. advices := items["advices"].([]interface{})
  12183. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12184. ctime := time.Now().Unix()
  12185. mtime := ctime
  12186. if len(advices) > 0 {
  12187. for _, advice := range advices {
  12188. var s models.HisPrescriptionAdviceTemplate
  12189. s.PrescriptionId = prescription.ID
  12190. s.AdviceType = 2
  12191. s.StopState = 2
  12192. s.ExecutionState = 2
  12193. s.Status = 1
  12194. s.UserOrgId = adminInfo.CurrentOrgId
  12195. s.CreatedTime = ctime
  12196. s.UpdatedTime = mtime
  12197. s.PatientId = patient_id
  12198. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12199. if errcode > 0 {
  12200. c.ServeFailJSONWithSGJErrorCode(errcode)
  12201. return
  12202. }
  12203. service.CreateHisPrescriptionAdviceTemplate(&s)
  12204. }
  12205. }
  12206. }
  12207. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12208. projects := items["project"].([]interface{})
  12209. if len(projects) > 0 {
  12210. for _, project := range projects {
  12211. var p models.HisPrescriptionProjectTemplate
  12212. p.PrescriptionId = prescription.ID
  12213. p.Ctime = time.Now().Unix()
  12214. p.Mtime = time.Now().Unix()
  12215. p.PatientId = patient_id
  12216. p.UserOrgId = adminInfo.CurrentOrgId
  12217. p.Status = 1
  12218. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12219. if errcode > 0 {
  12220. c.ServeFailJSONWithSGJErrorCode(errcode)
  12221. return
  12222. }
  12223. service.CreateHisPrescriptionProjectTemplate(&p)
  12224. }
  12225. }
  12226. }
  12227. }
  12228. c.ServeSuccessJSON(map[string]interface{}{
  12229. "msg": "创建成功",
  12230. })
  12231. }
  12232. }
  12233. } else {
  12234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12235. return
  12236. }
  12237. }
  12238. }
  12239. func (c *HisApiController) PreSettle() {
  12240. id, _ := c.GetInt64("id")
  12241. record_time := c.GetString("record_time")
  12242. his_patient_id, _ := c.GetInt64("his_patient_id")
  12243. timeLayout := "2006-01-02"
  12244. loc, _ := time.LoadLocation("Local")
  12245. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12246. diagnosis_id := c.GetString("diagnosis")
  12247. sick_type, _ := c.GetInt64("sick_type")
  12248. reg_type, _ := c.GetInt64("p_type")
  12249. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12251. if err != nil {
  12252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12253. return
  12254. }
  12255. recordDateTime := theTime.Unix()
  12256. adminUser := c.GetAdminUserInfo()
  12257. var prescriptions []*models.HisPrescription
  12258. var start_time int64
  12259. var end_time int64
  12260. ids_str := c.GetString("ids")
  12261. ids_arr := strings.Split(ids_str, ",")
  12262. fmt.Println(reg_type)
  12263. if settle_accounts_type == 1 { //日结
  12264. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12265. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12266. } else {
  12267. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12268. }
  12269. fmt.Println(prescriptions)
  12270. } else { //月结
  12271. start_time_str := c.GetString("start_time")
  12272. end_time_str := c.GetString("end_time")
  12273. timeLayout := "2006-01-02"
  12274. loc, _ := time.LoadLocation("Local")
  12275. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12276. if err != nil {
  12277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12278. return
  12279. }
  12280. recordStartTime := theStartTime.Unix()
  12281. start_time = recordStartTime
  12282. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12283. if err != nil {
  12284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12285. return
  12286. }
  12287. recordEndTime := theEndTime.Unix()
  12288. end_time = recordEndTime
  12289. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12290. }
  12291. if reg_type == 1111 || reg_type == 1112 {
  12292. reg_type = 11
  12293. }
  12294. timestamp := time.Now().Unix()
  12295. tempTime := time.Unix(timestamp, 0)
  12296. timeFormat := tempTime.Format("20060102150405")
  12297. chrgBchno := rand.Intn(100000) + 10000
  12298. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12299. strconv.FormatInt(his.PatientId, 10)
  12300. var ids []int64
  12301. for _, item := range prescriptions {
  12302. ids = append(ids, item.ID)
  12303. }
  12304. fmt.Println(ids)
  12305. var total float64
  12306. for _, item := range prescriptions {
  12307. fmt.Println(item)
  12308. if item.Type == 1 { //药品
  12309. for _, subItem := range item.HisDoctorAdviceInfo {
  12310. total = total + (subItem.Price * subItem.PrescribingNumber)
  12311. }
  12312. }
  12313. if item.Type == 2 { //项目
  12314. for _, subItem := range item.HisPrescriptionProject {
  12315. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12316. total = total + (subItem.Price * cnt)
  12317. }
  12318. }
  12319. for _, subItem := range item.HisAdditionalCharge {
  12320. total = total + (subItem.Price * float64(subItem.Count))
  12321. }
  12322. }
  12323. allTotal := fmt.Sprintf("%.2f", total)
  12324. totals, _ := strconv.ParseFloat(allTotal, 64)
  12325. order := &models.HisOrder{
  12326. UserOrgId: adminUser.CurrentOrgId,
  12327. HisPatientId: his.ID,
  12328. PatientId: id,
  12329. SettleAccountsDate: recordDateTime,
  12330. Ctime: time.Now().Unix(),
  12331. Mtime: time.Now().Unix(),
  12332. Status: 1,
  12333. OrderStatus: 1,
  12334. MdtrtId: his.Number,
  12335. Number: chrg_bchno,
  12336. MedfeeSumamt: totals,
  12337. SettleEndTime: end_time,
  12338. SettleStartTime: start_time,
  12339. SettleType: settle_accounts_type,
  12340. PsnPartAmt: totals,
  12341. PsnCashPay: totals,
  12342. PType: 2,
  12343. IsPre: 1,
  12344. MedType: strconv.Itoa(int(reg_type)),
  12345. Diagnosis: diagnosis_id,
  12346. }
  12347. err = service.CreateOrder(order)
  12348. if err != nil {
  12349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12350. return
  12351. }
  12352. var customs []*Custom
  12353. for _, item := range prescriptions {
  12354. fmt.Println(item.Type)
  12355. if item.Type == 1 { //药品
  12356. for _, subItem := range item.HisDoctorAdviceInfo {
  12357. cus := &Custom{
  12358. AdviceId: subItem.ID,
  12359. ProjectId: 0,
  12360. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12361. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12362. FeedetlSn: subItem.FeedetlSn,
  12363. Price: fmt.Sprintf("%.2f", subItem.Price),
  12364. MedListCodg: subItem.MedListCodg,
  12365. Type: 1,
  12366. }
  12367. customs = append(customs, cus)
  12368. }
  12369. }
  12370. if item.Type == 2 { //项目
  12371. for _, subItem := range item.HisPrescriptionProject {
  12372. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12373. cus := &Custom{
  12374. AdviceId: 0,
  12375. ProjectId: subItem.ID,
  12376. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12377. Cut: fmt.Sprintf("%.2f", cnt),
  12378. FeedetlSn: subItem.FeedetlSn,
  12379. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12380. MedListCodg: subItem.MedListCodg,
  12381. Type: 2,
  12382. }
  12383. customs = append(customs, cus)
  12384. }
  12385. }
  12386. for _, item := range item.HisAdditionalCharge {
  12387. cus := &Custom{
  12388. ItemId: item.ID,
  12389. AdviceId: 0,
  12390. ProjectId: 0,
  12391. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12392. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12393. FeedetlSn: item.FeedetlSn,
  12394. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12395. MedListCodg: item.XtHisAddtionConfig.Code,
  12396. Type: 3,
  12397. }
  12398. customs = append(customs, cus)
  12399. }
  12400. }
  12401. fmt.Println(customs)
  12402. for _, item := range customs {
  12403. var advice_id int64 = 0
  12404. var project_id int64 = 0
  12405. var item_id int64 = 0
  12406. var types int64 = 0
  12407. if item.Type == 1 {
  12408. advice_id = item.AdviceId
  12409. project_id = 0
  12410. item_id = 0
  12411. } else if item.Type == 2 {
  12412. advice_id = 0
  12413. item_id = 0
  12414. project_id = item.ProjectId
  12415. } else if item.Type == 3 {
  12416. advice_id = 0
  12417. item_id = item.ItemId
  12418. project_id = 0
  12419. }
  12420. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12421. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12422. pric, _ := strconv.ParseFloat(item.Price, 32)
  12423. info := &models.HisOrderInfo{
  12424. OrderNumber: order.Number,
  12425. UploadDate: time.Now().Unix(),
  12426. AdviceId: advice_id,
  12427. DetItemFeeSumamt: detItemFeeSumamt,
  12428. Cnt: cut,
  12429. Pric: pric,
  12430. PatientId: id,
  12431. Status: 1,
  12432. Mtime: time.Now().Unix(),
  12433. Ctime: time.Now().Unix(),
  12434. UserOrgId: adminUser.CurrentOrgId,
  12435. HisPatientId: his.ID,
  12436. OrderId: order.ID,
  12437. ProjectId: project_id,
  12438. Type: types,
  12439. ItemId: item_id,
  12440. }
  12441. service.CreateOrderInfo(info)
  12442. }
  12443. his.SickType = sick_type
  12444. service.UpdataHisPateint(&his)
  12445. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12446. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12447. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12448. if err == nil {
  12449. c.ServeSuccessJSON(map[string]interface{}{
  12450. "msg": "结算成功",
  12451. })
  12452. }
  12453. }
  12454. type CustomOrderInfo struct {
  12455. Name string
  12456. Spec string
  12457. Unit string
  12458. Count float64
  12459. Price float64
  12460. Total float64
  12461. }
  12462. func (c *HisApiController) GetPrivateExpensesInfo() {
  12463. order_id, _ := c.GetInt64("id", 0)
  12464. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12465. order, _ := service.GetHisOrderByID(order_id)
  12466. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12467. if order.ID == 0 {
  12468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12469. return
  12470. }
  12471. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12472. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12473. org_id := c.GetAdminUserInfo().CurrentOrgId
  12474. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12475. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12476. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12477. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12478. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12479. //var orderInfos_four []*models.HisOrderInfoTwo
  12480. //for _, item := range orderInfos_three {
  12481. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12482. // item.HisPrescriptionProject.IsCheckTeam = 1
  12483. // orderInfos_four = append(orderInfos_four, item)
  12484. //
  12485. // }
  12486. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12487. // item.HisPrescriptionProject.IsCheckTeam = 2
  12488. // orderInfos_two = append(orderInfos_two, item)
  12489. // }
  12490. //}
  12491. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12492. //var cus_slice []CustomOrderInfo
  12493. //for _, item := range new_order_info {
  12494. // var cus CustomOrderInfo
  12495. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12496. // cus.Unit = ""
  12497. // cus.Spec = ""
  12498. // var total float64
  12499. // for _, subItem := range orderInfos_four {
  12500. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12501. // total = total + subItem.DetItemFeeSumamt
  12502. // fmt.Println(subItem.DetItemFeeSumamt)
  12503. // }
  12504. // }
  12505. // cus.Count = 1
  12506. // cus.Total = total
  12507. // cus_slice = append(cus_slice, cus)
  12508. //}
  12509. orderInfos = append(orderInfos, orderInfos_two...)
  12510. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12511. //orderInfos = append(orderInfos, orderInfos_three...)
  12512. //}/**/
  12513. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12514. c.ServeSuccessJSON(map[string]interface{}{
  12515. "order": order,
  12516. "order_info": orderInfos,
  12517. "patient": patient,
  12518. "admin_info": adminInfo,
  12519. "his": his,
  12520. "current_admin": role,
  12521. "org_config": miConfig,
  12522. //"new_order_info": cus_slice,
  12523. })
  12524. }
  12525. func (this *HisApiController) ChangeMedType() {
  12526. med_type := this.GetString("med_type")
  12527. old_med_type := this.GetString("old_med_type")
  12528. ids := this.GetString("ids")
  12529. settle_type, _ := this.GetInt64("settle_type")
  12530. start_time := this.GetString("start_time")
  12531. end_time := this.GetString("end_time")
  12532. ids_arr := strings.Split(ids, ",")
  12533. if settle_type == 1 { //日结
  12534. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12535. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12536. prescription.MedType = med_type
  12537. err := service.SaveHisPrescriptionTwo(&prescription)
  12538. if err == nil {
  12539. this.ServeSuccessJSON(map[string]interface{}{
  12540. "msg": "修改成功",
  12541. })
  12542. } else {
  12543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12544. return
  12545. }
  12546. } else if settle_type == 2 {
  12547. timeLayout := "2006-01-02"
  12548. loc, _ := time.LoadLocation("Local")
  12549. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12550. if err != nil {
  12551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12552. return
  12553. }
  12554. recordStartTime := theStartTime.Unix()
  12555. start_time_timestamp := recordStartTime
  12556. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12557. if err != nil {
  12558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12559. return
  12560. }
  12561. recordEndTime := theEndTime.Unix()
  12562. end_time_timestamp := recordEndTime
  12563. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12564. if updateErr == nil {
  12565. this.ServeSuccessJSON(map[string]interface{}{
  12566. "msg": "修改成功",
  12567. })
  12568. } else {
  12569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12570. return
  12571. }
  12572. }
  12573. }
  12574. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12575. patient_id, _ := c.GetInt64("patient_id")
  12576. his_patient_id, _ := c.GetInt64("his_patient_id")
  12577. record_date := c.GetString("record_date")
  12578. start_time := c.GetString("start_time")
  12579. end_time := c.GetString("end_time")
  12580. order_status, _ := c.GetInt64("type", 0)
  12581. p_type, _ := c.GetInt64("p_type", 0)
  12582. order_id, _ := c.GetInt64("order_id", 0)
  12583. timeLayout := "2006-01-02"
  12584. loc, _ := time.LoadLocation("Local")
  12585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12586. if err != nil {
  12587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12588. return
  12589. }
  12590. recordDateTime := theTime.Unix()
  12591. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12592. if err != nil {
  12593. }
  12594. startRecordDateTime := startTime.Unix()
  12595. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12596. if err != nil {
  12597. }
  12598. endRecordDateTime := endTime.Unix()
  12599. admin := c.GetAdminUserInfo()
  12600. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12601. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12602. order, _ := service.GetHisOrderByID(order_id)
  12603. var monthPrescriptions []*models.HisPrescription
  12604. if order_status == 1 || order_status == 0 {
  12605. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12606. } else if order_status == 2 {
  12607. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12608. }
  12609. var settle_total float64
  12610. for _, item := range monthPrescriptions {
  12611. if len(item.HisPrescriptionProject) > 0 {
  12612. for _, subItem := range item.HisPrescriptionProject {
  12613. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12614. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12615. settle_total = settle_total + total
  12616. }
  12617. }
  12618. if len(item.HisDoctorAdviceInfo) > 0 {
  12619. for _, subItem := range item.HisDoctorAdviceInfo {
  12620. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12621. settle_total = settle_total + total
  12622. }
  12623. }
  12624. }
  12625. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12626. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12627. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12628. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12629. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12630. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12631. //获取所有科室信息
  12632. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12633. var dia string
  12634. for _, item := range month_p_info {
  12635. if len(dia) == 0 {
  12636. dia = item.Diagnosis
  12637. } else {
  12638. dia = dia + "," + item.Diagnosis
  12639. }
  12640. }
  12641. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12642. dia_arr = removeEmptyStrings(dia_arr)
  12643. c.ServeSuccessJSON(map[string]interface{}{
  12644. "his_info": his_patient_info,
  12645. "xt_info": xt_patient_info,
  12646. "case_history": case_history,
  12647. "info": patientPrescriptionInfo,
  12648. "last_info": lastPatientPrescriptionInfo,
  12649. "month_prescriptions": monthPrescriptions,
  12650. "order": order,
  12651. "doctors": doctors,
  12652. "department": department,
  12653. "settle_total": settle_total,
  12654. "dia_arr": dia_arr,
  12655. })
  12656. return
  12657. }
  12658. func removeEmptyStrings(input []string) []string {
  12659. var output []string
  12660. for _, s := range input {
  12661. if s != "" {
  12662. output = append(output, s)
  12663. }
  12664. }
  12665. return output
  12666. }
  12667. func removeDuplicates(input []string) []string {
  12668. seen := make(map[string]bool)
  12669. output := []string{}
  12670. for _, s := range input {
  12671. if _, exists := seen[s]; !exists {
  12672. seen[s] = true
  12673. output = append(output, s)
  12674. }
  12675. }
  12676. return output
  12677. }
  12678. func (c *HisApiController) GetHisMonthPatientInfo() {
  12679. patient_id, _ := c.GetInt64("patient_id")
  12680. his_patient_id, _ := c.GetInt64("his_patient_id")
  12681. record_date := c.GetString("record_date")
  12682. number := c.GetString("number")
  12683. start_time := c.GetString("start_time")
  12684. end_time := c.GetString("end_time")
  12685. p_type, _ := c.GetInt64("p_type")
  12686. timeLayout := "2006-01-02"
  12687. loc, _ := time.LoadLocation("Local")
  12688. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12689. if err != nil {
  12690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12691. return
  12692. }
  12693. recordDateTime := theTime.Unix()
  12694. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12695. if err != nil {
  12696. }
  12697. startRecordDateTime := startTime.Unix()
  12698. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12699. if err != nil {
  12700. }
  12701. endRecordDateTime := endTime.Unix()
  12702. admin := c.GetAdminUserInfo()
  12703. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12704. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12705. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12706. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12707. var settle_total float64
  12708. for _, item := range monthPrescriptions {
  12709. if len(item.HisPrescriptionProject) > 0 {
  12710. for _, subItem := range item.HisPrescriptionProject {
  12711. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12712. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12713. settle_total = settle_total + total
  12714. }
  12715. }
  12716. if len(item.HisDoctorAdviceInfo) > 0 {
  12717. for _, subItem := range item.HisDoctorAdviceInfo {
  12718. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12719. settle_total = settle_total + total
  12720. }
  12721. }
  12722. }
  12723. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12724. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12725. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12726. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12727. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12728. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12729. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12730. //获取所有科室信息
  12731. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12732. c.ServeSuccessJSON(map[string]interface{}{
  12733. "his_info": his_patient_info,
  12734. "xt_info": xt_patient_info,
  12735. "case_history": case_history,
  12736. "info": patientPrescriptionInfo,
  12737. "month_prescriptions": monthPrescriptions,
  12738. "order": order,
  12739. "doctors": doctors,
  12740. "department": department,
  12741. "count": count,
  12742. "drugStockConfig": drugStockConfig,
  12743. "last_info": lastPatientPrescriptionInfo,
  12744. "settle_total": settle_total,
  12745. })
  12746. return
  12747. }
  12748. func (c *HisApiController) GetAllOrder() {
  12749. org_id := c.GetAdminUserInfo().CurrentOrgId
  12750. orders, _ := service.GetNewHisOrderList(org_id)
  12751. c.ServeSuccessJSON(map[string]interface{}{
  12752. "order": orders,
  12753. })
  12754. return
  12755. }
  12756. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12757. newArr = make([]*models.HisOrderInfoTwo, 0)
  12758. for i := 0; i < len(arr); i++ {
  12759. repeat := false
  12760. for j := i + 1; j < len(arr); j++ {
  12761. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12762. repeat = true
  12763. break
  12764. }
  12765. }
  12766. if !repeat {
  12767. newArr = append(newArr, arr[i])
  12768. }
  12769. }
  12770. return
  12771. }
  12772. // 修改处方退库操作 参数传修改之前的处方数据
  12773. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12774. if advice.ExecutionState == 1 {
  12775. //查询该病人该药品是否有库存记录
  12776. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12777. if errcode == gorm.ErrRecordNotFound {
  12778. } else {
  12779. //退库
  12780. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12781. if advice.PrescribingNumberUnit == drug.MinUnit {
  12782. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12783. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12784. //退库
  12785. warehouseInfo := models.DrugWarehouseInfo{
  12786. StockMinNumber: prescribingNumber,
  12787. }
  12788. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12789. operation_time := time.Now().Unix()
  12790. creater := advice.AdviceDoctor
  12791. ctime := time.Now().Unix()
  12792. timeStr := time.Now().Format("2006-01-02")
  12793. timeArr := strings.Split(timeStr, "-")
  12794. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12795. total = total + 1
  12796. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12797. cancelStock := models.DrugCancelStock{
  12798. OrderNumber: orderNumber,
  12799. OperaTime: operation_time,
  12800. OrgId: advice.UserOrgId,
  12801. Creater: creater,
  12802. Ctime: ctime,
  12803. Status: 1,
  12804. ReturnTime: advice.AdviceDate,
  12805. Dealer: info.Dealer,
  12806. Manufacturer: info.Manufacturer,
  12807. Type: 1,
  12808. }
  12809. service.AddSigleDrugCancelStock(&cancelStock)
  12810. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12811. dealer, _ := service.GetDealerById(info.Dealer)
  12812. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12813. cancelStockInfo := models.DrugCancelStockInfo{
  12814. OrderNumber: cancelInfo.OrderNumber,
  12815. CancelStockId: cancelInfo.ID,
  12816. DrugId: info.DrugId,
  12817. Count: info.Count,
  12818. Status: 1,
  12819. Ctime: ctime,
  12820. OrgId: advice.UserOrgId,
  12821. Type: 1,
  12822. Manufacturer: manufactureName.ManufacturerName,
  12823. Dealer: dealer.DealerName,
  12824. Total: 0,
  12825. RetailPrice: info.RetailPrice,
  12826. RetailTotalPrice: info.RetailTotalPrice,
  12827. Price: info.Price,
  12828. RegisterAccount: "",
  12829. Remark: info.Remark,
  12830. BatchNumber: info.BatchNumber,
  12831. MaxUnit: info.CountUnit,
  12832. ProductDate: info.ProductDate,
  12833. ExpiryDate: info.ExpiryDate,
  12834. BatchNumberId: info.WarehouseInfoId,
  12835. }
  12836. flow := models.DrugFlow{
  12837. WarehousingId: 0,
  12838. DrugId: info.DrugId,
  12839. Number: "",
  12840. BatchNumber: info.BatchNumber,
  12841. Count: info.Count,
  12842. UserOrgId: advice.UserOrgId,
  12843. PatientId: 0,
  12844. SystemTime: ctime,
  12845. ConsumableType: 4,
  12846. IsSys: 0,
  12847. WarehousingOrder: "",
  12848. WarehouseOutId: 0,
  12849. WarehouseOutOrderNumber: "",
  12850. IsEdit: 0,
  12851. CancelStockId: cancelStock.ID,
  12852. CancelOrderNumber: cancelStock.OrderNumber,
  12853. Manufacturer: info.Manufacturer,
  12854. Dealer: info.Dealer,
  12855. Creator: advice.UserOrgId,
  12856. UpdateCreator: 0,
  12857. Status: 1,
  12858. Ctime: time.Now().Unix(),
  12859. Mtime: 0,
  12860. Price: info.Price,
  12861. WarehousingDetailId: 0,
  12862. WarehouseOutDetailId: 0,
  12863. CancelOutDetailId: 0,
  12864. ExpireDate: info.ExpiryDate,
  12865. ProductDate: info.ProductDate,
  12866. MaxUnit: info.CountUnit,
  12867. MinUnit: "",
  12868. }
  12869. service.CreatedCancelStock(cancelStockInfo)
  12870. service.CreateDrugFlowOne(flow)
  12871. } else {
  12872. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12873. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12874. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12875. warehouseInfo := models.DrugWarehouseInfo{
  12876. StockMinNumber: prescribingNumber,
  12877. }
  12878. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12879. }
  12880. operation_time := time.Now().Unix()
  12881. creater := advice.AdviceDoctor
  12882. ctime := time.Now().Unix()
  12883. timeStr := time.Now().Format("2006-01-02")
  12884. timeArr := strings.Split(timeStr, "-")
  12885. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12886. total = total + 1
  12887. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12888. cancelStock := models.DrugCancelStock{
  12889. OrderNumber: orderNumber,
  12890. OperaTime: operation_time,
  12891. OrgId: advice.UserOrgId,
  12892. Creater: creater,
  12893. Ctime: ctime,
  12894. Status: 1,
  12895. ReturnTime: advice.AdviceDate,
  12896. Dealer: info.Dealer,
  12897. Manufacturer: info.Manufacturer,
  12898. Type: 1,
  12899. }
  12900. service.AddSigleDrugCancelStock(&cancelStock)
  12901. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12902. dealer, _ := service.GetDealerById(info.Dealer)
  12903. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12904. cancelStockInfo := models.DrugCancelStockInfo{
  12905. OrderNumber: cancelInfo.OrderNumber,
  12906. CancelStockId: cancelInfo.ID,
  12907. DrugId: info.DrugId,
  12908. Count: info.Count,
  12909. Status: 1,
  12910. Ctime: ctime,
  12911. OrgId: advice.UserOrgId,
  12912. Type: 1,
  12913. Manufacturer: manufactureName.ManufacturerName,
  12914. Dealer: dealer.DealerName,
  12915. Total: 0,
  12916. RetailPrice: info.RetailPrice,
  12917. RetailTotalPrice: info.RetailTotalPrice,
  12918. Price: info.Price,
  12919. RegisterAccount: "",
  12920. Remark: info.Remark,
  12921. BatchNumber: info.BatchNumber,
  12922. MaxUnit: info.CountUnit,
  12923. ProductDate: info.ProductDate,
  12924. ExpiryDate: info.ExpiryDate,
  12925. BatchNumberId: info.WarehouseInfoId,
  12926. }
  12927. flow := models.DrugFlow{
  12928. WarehousingId: 0,
  12929. DrugId: info.DrugId,
  12930. Number: "",
  12931. BatchNumber: info.BatchNumber,
  12932. Count: info.Count,
  12933. UserOrgId: advice.UserOrgId,
  12934. PatientId: 0,
  12935. SystemTime: ctime,
  12936. ConsumableType: 4,
  12937. IsSys: 0,
  12938. WarehousingOrder: "",
  12939. WarehouseOutId: 0,
  12940. WarehouseOutOrderNumber: "",
  12941. IsEdit: 0,
  12942. CancelStockId: cancelStock.ID,
  12943. CancelOrderNumber: cancelStock.OrderNumber,
  12944. Manufacturer: info.Manufacturer,
  12945. Dealer: info.Dealer,
  12946. Creator: advice.AdviceDoctor,
  12947. UpdateCreator: 0,
  12948. Status: 1,
  12949. Ctime: time.Now().Unix(),
  12950. Mtime: 0,
  12951. Price: info.Price,
  12952. WarehousingDetailId: 0,
  12953. WarehouseOutDetailId: 0,
  12954. CancelOutDetailId: 0,
  12955. ExpireDate: info.ExpiryDate,
  12956. ProductDate: info.ProductDate,
  12957. MaxUnit: info.CountUnit,
  12958. MinUnit: "",
  12959. }
  12960. service.CreatedCancelStock(cancelStockInfo)
  12961. service.CreateDrugFlowOne(flow)
  12962. }
  12963. }
  12964. }
  12965. return err
  12966. }
  12967. func (this *HisApiController) DeleteNCDS() {
  12968. id, _ := this.GetInt64("id", 0)
  12969. if id > 0 {
  12970. service.DeletePsnNCDSRecordById(id)
  12971. this.ServeSuccessJSON(map[string]interface{}{
  12972. "msg": "删除成功",
  12973. })
  12974. } else {
  12975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12976. return
  12977. }
  12978. }
  12979. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12980. id, _ := c.GetInt64("id")
  12981. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12982. c.ServeSuccessJSON(map[string]interface{}{
  12983. "advice": advice,
  12984. })
  12985. return
  12986. }
  12987. func (c *HisApiController) GetHisMonthChargePatientList() {
  12988. record_date := c.GetString("record_date")
  12989. start_time := c.GetString("start_time")
  12990. end_time := c.GetString("end_time")
  12991. timeLayout := "2006-01-02"
  12992. loc, _ := time.LoadLocation("Local")
  12993. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12994. if err != nil {
  12995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12996. return
  12997. }
  12998. if err != nil {
  12999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13000. return
  13001. }
  13002. recordDateTime := theTime.Unix()
  13003. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13004. if err != nil {
  13005. }
  13006. startRecordDateTime := startTime.Unix()
  13007. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13008. if err != nil {
  13009. }
  13010. endRecordDateTime := endTime.Unix()
  13011. adminInfo := c.GetAdminUserInfo()
  13012. var tempMonthChargePatients []*service.MonthChargePatients
  13013. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13014. for _, item := range tempPatients {
  13015. //过滤没有处方的
  13016. if len(item.HisPrescription) == 0 {
  13017. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13018. }
  13019. }
  13020. c.ServeSuccessJSON(map[string]interface{}{
  13021. "list": tempMonthChargePatients,
  13022. })
  13023. }
  13024. // PrescriptionDifference 医嘱数量差值结构体
  13025. type PrescriptionDrugDifference struct {
  13026. DrugID int64 //基础库药品id
  13027. ID int64 //医嘱id
  13028. Difference float64 //差值
  13029. Unit string //单位
  13030. }
  13031. type PrescriptionGoodDifference struct {
  13032. GoodID int64 //基础库项目耗材id
  13033. ID int64 //医嘱id
  13034. Difference int64 //差值
  13035. Unit string //单位
  13036. Type int64 //类型
  13037. }
  13038. type EditCustomData struct {
  13039. adviceList []*models.HisDoctorAdviceInfo
  13040. projectList []*models.HisPrescriptionProject
  13041. }
  13042. type SrcCustomData struct {
  13043. adviceList []*models.HisDoctorAdviceInfo
  13044. projectList []*models.HisPrescriptionProject
  13045. }
  13046. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13047. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13048. differences := make([]*PrescriptionDrugDifference, 0)
  13049. // 创建一个 map 来存储第一个切片中的药品信息
  13050. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13051. for _, advice := range firstPrescription {
  13052. firstMap[advice.DrugId] = advice
  13053. }
  13054. // 遍历第二个切片中的药品信息,并比较数量差值
  13055. for _, advice := range secondPrescription {
  13056. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13057. diff := &PrescriptionDrugDifference{
  13058. DrugID: advice.DrugId,
  13059. ID: firstAdvice.ID,
  13060. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13061. Unit: firstAdvice.PrescribingNumberUnit,
  13062. }
  13063. differences = append(differences, diff)
  13064. }
  13065. }
  13066. return differences
  13067. }
  13068. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13069. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13070. differences := make([]*PrescriptionGoodDifference, 0)
  13071. // 创建一个 map 来存储第一个切片中的耗材信息
  13072. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13073. for _, good := range firstPrescription {
  13074. firstMap[good.ProjectId] = good
  13075. }
  13076. // 遍历第二个切片中的耗材信息,并比较数量差值
  13077. for _, good := range secondPrescription {
  13078. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13079. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13080. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13081. diff := &PrescriptionGoodDifference{
  13082. GoodID: good.ProjectId,
  13083. ID: firstGood.ID,
  13084. Difference: count - firstCount,
  13085. Unit: firstGood.Unit,
  13086. Type: firstGood.Type,
  13087. }
  13088. differences = append(differences, diff)
  13089. }
  13090. }
  13091. return differences
  13092. }
  13093. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13094. var adviceList []*models.HisDoctorAdviceInfo
  13095. var projectList []*models.HisPrescriptionProject
  13096. var advice_ids []int64
  13097. var project_ids []int64
  13098. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13099. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13100. //var tempPrescription *models.HisPrescriptionProjectscription
  13101. if len(prescriptions) > 0 {
  13102. for _, item := range prescriptions {
  13103. items := item.(map[string]interface{})
  13104. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13105. advices := items["advices"].([]interface{})
  13106. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13107. groupNo := int64(0)
  13108. ctime := time.Now().Unix()
  13109. mtime := ctime
  13110. if len(advices) > 0 {
  13111. for _, advice := range advices {
  13112. var s models.HisDoctorAdviceInfo
  13113. s.AdviceType = 2
  13114. s.StopState = 2
  13115. s.ExecutionState = 2
  13116. s.Status = 1
  13117. s.Groupno = groupNo
  13118. s.CreatedTime = ctime
  13119. s.UpdatedTime = mtime
  13120. s.IsSettle = 2
  13121. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13122. //存储切片中
  13123. if s.ID > 0 {
  13124. advice_ids = append(advice_ids, s.ID)
  13125. adviceList = append(adviceList, &s)
  13126. }
  13127. }
  13128. }
  13129. }
  13130. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13131. projects := items["project"].([]interface{})
  13132. if len(projects) > 0 {
  13133. for _, project := range projects {
  13134. var p models.HisPrescriptionProject
  13135. p.Ctime = time.Now().Unix()
  13136. p.Mtime = time.Now().Unix()
  13137. p.Status = 1
  13138. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13139. if p.ID > 0 {
  13140. project_ids = append(project_ids, p.ID)
  13141. projectList = append(projectList, &p)
  13142. }
  13143. }
  13144. }
  13145. }
  13146. }
  13147. }
  13148. }
  13149. editCustomData.projectList = projectList
  13150. editCustomData.adviceList = adviceList
  13151. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13152. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13153. srcCustomData.adviceList = list
  13154. srcCustomData.projectList = list2
  13155. return
  13156. }
  13157. func (c *HisApiController) GetAllGoodInforList() {
  13158. orgId := c.GetAdminUserInfo().CurrentOrgId
  13159. goodList, _ := service.GetAllGoodList(orgId)
  13160. c.ServeSuccessJSON(map[string]interface{}{
  13161. "goodList": goodList,
  13162. })
  13163. return
  13164. }
  13165. func (this *HisApiController) SaveGoodList() {
  13166. project_name := this.GetString("project_name")
  13167. sort, _ := this.GetInt64("sort")
  13168. orgId := this.GetAdminUserInfo().CurrentOrgId
  13169. dataBody := make(map[string]interface{}, 0)
  13170. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13171. if err != nil {
  13172. utils.ErrorLog(err.Error())
  13173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13174. return
  13175. }
  13176. goodTeam := models.XtGoodTeam{
  13177. ProjectName: project_name,
  13178. Sort: sort,
  13179. UserOrgId: orgId,
  13180. Status: 1,
  13181. Ctime: time.Now().Unix(),
  13182. Mtime: time.Now().Unix(),
  13183. }
  13184. service.CreateGoodTeam(goodTeam)
  13185. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13186. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13187. infos, _ := dataBody["info"].([]interface{})
  13188. if len(infos) > 0 {
  13189. for _, item := range infos {
  13190. items := item.(map[string]interface{})
  13191. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13192. utils.ErrorLog("good_id")
  13193. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13194. return
  13195. }
  13196. good_id := int64(items["good_id"].(float64))
  13197. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13198. utils.ErrorLog("number")
  13199. }
  13200. number := int64(items["number"].(float64))
  13201. xtGoodTeamList := models.XtGoodTeamList{
  13202. GoodId: good_id,
  13203. Count: number,
  13204. TeamId: lastGoodTeam.ID,
  13205. UserOrgId: orgId,
  13206. Status: 1,
  13207. Ctime: time.Now().Unix(),
  13208. Mtime: time.Now().Unix(),
  13209. }
  13210. service.CreateGoodList(xtGoodTeamList)
  13211. }
  13212. this.ServeSuccessJSON(map[string]interface{}{
  13213. "lastGoodTeam": lastGoodTeam,
  13214. })
  13215. }
  13216. }
  13217. return
  13218. }
  13219. func (this *HisApiController) GetGoodList() {
  13220. orgId := this.GetAdminUserInfo().CurrentOrgId
  13221. limit, _ := this.GetInt64("limit")
  13222. page, _ := this.GetInt64("page")
  13223. keyword := this.GetString("keyword")
  13224. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13225. this.ServeSuccessJSON(map[string]interface{}{
  13226. "list": list,
  13227. "total": total,
  13228. })
  13229. }
  13230. func (this *HisApiController) GetGoodNameDetail() {
  13231. id, _ := this.GetInt64("id")
  13232. orgId := this.GetAdminUserInfo().CurrentOrgId
  13233. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13234. goodList, _ := service.GetAllGoodList(orgId)
  13235. this.ServeSuccessJSON(map[string]interface{}{
  13236. "goodNameDetail": goodNameDetail,
  13237. "goodList": goodList,
  13238. })
  13239. }
  13240. func (this *HisApiController) UpdateGoodList() {
  13241. project_name := this.GetString("project_name")
  13242. sort, _ := this.GetInt64("sort")
  13243. id, _ := this.GetInt64("id")
  13244. orgId := this.GetAdminUserInfo().CurrentOrgId
  13245. dataBody := make(map[string]interface{}, 0)
  13246. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13247. if err != nil {
  13248. utils.ErrorLog(err.Error())
  13249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13250. return
  13251. }
  13252. goodTeam := models.XtGoodTeam{
  13253. ProjectName: project_name,
  13254. Sort: sort,
  13255. UserOrgId: orgId,
  13256. Status: 1,
  13257. Ctime: time.Now().Unix(),
  13258. Mtime: time.Now().Unix(),
  13259. ID: id,
  13260. }
  13261. service.SaveGoodTeam(goodTeam)
  13262. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13263. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13264. infos, _ := dataBody["info"].([]interface{})
  13265. if len(infos) > 0 {
  13266. for _, item := range infos {
  13267. items := item.(map[string]interface{})
  13268. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13269. utils.ErrorLog("good_id")
  13270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13271. return
  13272. }
  13273. good_id := int64(items["good_id"].(float64))
  13274. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13275. utils.ErrorLog("id")
  13276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13277. return
  13278. }
  13279. id := int64(items["id"].(float64))
  13280. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13281. utils.ErrorLog("number")
  13282. }
  13283. number := int64(items["number"].(float64))
  13284. xtGoodTeamList := models.XtGoodTeamList{
  13285. ID: id,
  13286. GoodId: good_id,
  13287. Count: number,
  13288. TeamId: lastGoodTeam.ID,
  13289. UserOrgId: orgId,
  13290. Status: 1,
  13291. Ctime: time.Now().Unix(),
  13292. Mtime: time.Now().Unix(),
  13293. }
  13294. service.SaveGoodList(xtGoodTeamList)
  13295. }
  13296. this.ServeSuccessJSON(map[string]interface{}{
  13297. "lastGoodTeam": lastGoodTeam,
  13298. })
  13299. }
  13300. }
  13301. return
  13302. }
  13303. func (this *HisApiController) DeleteGoodTeam() {
  13304. id, _ := this.GetInt64("id")
  13305. team, _ := service.DeleteGoodTeam(id)
  13306. this.ServeSuccessJSON(map[string]interface{}{
  13307. "team": team,
  13308. })
  13309. }
  13310. func (this *HisApiController) DeleteGood() {
  13311. id, _ := this.GetInt64("id")
  13312. good, _ := service.DeleteGood(id)
  13313. this.ServeSuccessJSON(map[string]interface{}{
  13314. "good": good,
  13315. })
  13316. }