his_api_controller.go 577KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822
  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. //types, _ := c.GetInt64("type", 0)
  1205. record_date := c.GetString("record_date")
  1206. sch_type, _ := c.GetInt64("sch_type")
  1207. timeLayout := "2006-01-02"
  1208. loc, _ := time.LoadLocation("Local")
  1209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1210. if err != nil {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. recordDateTime := theTime.Unix()
  1215. adminInfo := c.GetAdminUserInfo()
  1216. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1217. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1218. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1219. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1220. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1221. //获取当前用户的信息
  1222. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1223. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1224. //获取所有科室信息
  1225. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1226. //var aa []service.PatientThree
  1227. noElementsSlice := make([]service.PatientThree, 0)
  1228. c.ServeSuccessJSON(map[string]interface{}{
  1229. "list": patients,
  1230. "list_two": patients_two,
  1231. "list_three": noElementsSlice,
  1232. "info": adminUserInfo,
  1233. "doctors": doctors,
  1234. "department": department,
  1235. })
  1236. }
  1237. type CustomTemplate struct {
  1238. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1239. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1240. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1241. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1242. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1243. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1244. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1245. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1246. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1247. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1248. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1249. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1250. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1251. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1252. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1253. }
  1254. func (c *HisApiController) GetHisPatientInfo() {
  1255. patient_id, _ := c.GetInt64("patient_id")
  1256. his_patient_id, _ := c.GetInt64("his_patient_id")
  1257. record_date := c.GetString("record_date")
  1258. number := c.GetString("number")
  1259. //start_time := c.GetString("start_time")
  1260. //end_time := c.GetString("end_time")
  1261. p_type, _ := c.GetInt64("p_type")
  1262. timeLayout := "2006-01-02"
  1263. loc, _ := time.LoadLocation("Local")
  1264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1265. if err != nil {
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. recordDateTime := theTime.Unix()
  1270. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1271. //if err != nil {
  1272. //
  1273. //}
  1274. //startRecordDateTime := startTime.Unix()
  1275. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1276. //if err != nil {
  1277. //
  1278. //}
  1279. //endRecordDateTime := endTime.Unix()
  1280. admin := c.GetAdminUserInfo()
  1281. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1282. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1283. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1284. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1285. var prescriptions []*models.HisPrescription
  1286. var last_prescriptions []*models.HisPrescription
  1287. var sch_prescriptions []CustomTemplate
  1288. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1289. if p_type == 1 { //住院
  1290. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. } else { //门诊
  1301. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1302. for _, item := range prescriptions {
  1303. for _, subItem := range item.HisDoctorAdviceInfo {
  1304. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1305. if info.RetailPrice > 0 {
  1306. subItem.Drug.MinPrice = info.RetailPrice
  1307. }
  1308. }
  1309. }
  1310. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1311. }
  1312. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1313. if sch.ID > 0 {
  1314. var week string
  1315. t := time.Now()
  1316. switch t.Weekday().String() {
  1317. case "Monday":
  1318. week = "周一"
  1319. break
  1320. case "Tuesday":
  1321. week = "周二"
  1322. break
  1323. case "Wednesday":
  1324. week = "周三"
  1325. break
  1326. case "Thursday":
  1327. week = "周四"
  1328. break
  1329. case "Friday":
  1330. week = "周五"
  1331. break
  1332. case "Saturday":
  1333. week = "周六"
  1334. break
  1335. case "Sunday":
  1336. week = "周日"
  1337. break
  1338. }
  1339. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1340. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1341. //根据推送频率组装新的数组
  1342. for _, item := range temp_sch_prescriptions {
  1343. var cus CustomTemplate
  1344. cus.ID = item.ID
  1345. cus.UserOrgId = item.UserOrgId
  1346. cus.PatientId = item.PatientId
  1347. cus.MedType = item.MedType
  1348. cus.RecordDate = item.RecordDate
  1349. cus.Type = item.Type
  1350. cus.PType = item.PType
  1351. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1352. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1353. if subItem.FrequencyType == 1 { //每次必推
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. if subItem.FrequencyType == 2 { //按照天数频率
  1360. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1361. now := p.Unix()
  1362. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1363. dayStr2 := "-" + dayStr
  1364. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1365. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1366. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1367. if len(advices) == 0 {
  1368. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1369. }
  1370. }
  1371. }
  1372. }
  1373. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1374. if subItem.Type == 2 {
  1375. if subItem.XtHisProject.MedicalStatus != 1 {
  1376. if subItem.FrequencyType == 1 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. if subItem.FrequencyType == 2 {
  1383. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1384. now := p.Unix()
  1385. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1386. dayStr2 := "-" + dayStr
  1387. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1388. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1389. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1390. if len(projects) == 0 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. }
  1394. }
  1395. } else if subItem.Type == 3 {
  1396. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  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. }
  1417. }
  1418. sch_prescriptions = append(sch_prescriptions, cus)
  1419. }
  1420. for _, item := range sch_prescriptions {
  1421. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1422. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1423. }
  1424. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1425. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1426. }
  1427. }
  1428. }
  1429. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1430. if config.ID > 0 && config.IsOpen == 1 {
  1431. for _, item := range sch_prescriptions {
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1434. if info.RetailPrice > 0 {
  1435. subItem.Drug.MinPrice = info.RetailPrice
  1436. if admin.CurrentOrgId != 10598 {
  1437. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1438. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1439. }
  1440. }
  1441. }
  1442. }
  1443. }
  1444. if config.ID > 0 && config.IsOpen == 1 {
  1445. for _, item := range sch_prescriptions {
  1446. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1447. if subItem.Type == 3 {
  1448. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1449. if info.Price > 0 {
  1450. subItem.GoodInfo.PackingPrice = info.Price
  1451. if admin.CurrentOrgId != 10598 {
  1452. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1453. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1461. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1462. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1463. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1464. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1465. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1466. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1467. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1468. //获取所有科室信息
  1469. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1470. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1471. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1472. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "his_info": his_patient_info,
  1475. "xt_info": xt_patient_info,
  1476. "prescription": prescriptions,
  1477. "case_history": case_history,
  1478. "info": patientPrescriptionInfo,
  1479. //"month_prescriptions": monthPrescriptions,
  1480. "order": order,
  1481. "doctors": doctors,
  1482. "department": department,
  1483. "sch_prescriptions": sch_prescriptions,
  1484. "last_prescriptions": last_prescriptions,
  1485. "schedule": sch,
  1486. "count": count,
  1487. "drugStockConfig": drugStockConfig,
  1488. "last_info": lastPatientPrescriptionInfo,
  1489. "befor": beforThrity,
  1490. "LastCaseHistory": LastCaseHistory,
  1491. "prescriptionInfo": prescriptionInfo,
  1492. })
  1493. return
  1494. }
  1495. func (c *HisApiController) GetHisPrescriptionConfig() {
  1496. adminInfo := c.GetAdminUserInfo()
  1497. //获取医嘱模版
  1498. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1499. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1500. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1501. //获取所有基础药
  1502. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1503. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1504. if config.ID > 0 && config.IsOpen == 1 {
  1505. for _, item := range drugs {
  1506. var index = 0
  1507. for _, subItem := range item.OtherDrugWarehouseInfo {
  1508. if index == 0 {
  1509. index = index + 1
  1510. if subItem.RetailPrice > 0 {
  1511. item.MinPrice = subItem.RetailPrice
  1512. }
  1513. }
  1514. }
  1515. }
  1516. }
  1517. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1518. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1519. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1520. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1521. //获取所有科室信息
  1522. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1523. //获取诊断信息
  1524. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1525. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1526. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1527. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1528. //获取是否开启保存耗材出库的开关
  1529. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1530. c.ServeSuccessJSON(map[string]interface{}{
  1531. "drugs": drugs,
  1532. "advices_template": advices,
  1533. "drugways": drugways,
  1534. "efs": efs,
  1535. "doctors": doctors,
  1536. "department": department,
  1537. "sick": sick,
  1538. "additions": additions,
  1539. "diagnose": diagnose,
  1540. "manufacturers": manufacturers,
  1541. "goodOutOpen": goodOutOpen,
  1542. "patientDiagnose": patientDiagnose,
  1543. })
  1544. }
  1545. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1546. //获取所有基础药
  1547. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1548. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1549. if config.ID > 0 && config.IsOpen == 1 {
  1550. for _, item := range drugs {
  1551. var index = 0
  1552. for _, subItem := range item.OtherDrugWarehouseInfo {
  1553. if index == 0 {
  1554. index = index + 1
  1555. if subItem.RetailPrice > 0 {
  1556. item.MinPrice = subItem.RetailPrice
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1563. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1564. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1565. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1566. //获取所有科室信息
  1567. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1568. //获取诊断信息
  1569. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1570. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1571. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1572. //获取是否开启保存耗材出库的开关
  1573. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1574. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1575. c.ServeSuccessJSON(map[string]interface{}{
  1576. "drugs": drugs,
  1577. "advices_template": advices,
  1578. "drugways": drugways,
  1579. "efs": efs,
  1580. "doctors": doctors,
  1581. "department": department,
  1582. "sick": sick,
  1583. "additions": additions,
  1584. "diagnose": diagnose,
  1585. "manufacturers": manufacturers,
  1586. "goodOutOpen": goodOutOpen,
  1587. "patientDiagnose": patientDiagnose,
  1588. })
  1589. }
  1590. }
  1591. func (c *HisApiController) CreateHisPrescription() {
  1592. record_date := c.GetString("record_date")
  1593. patient_id, _ := c.GetInt64("patient_id")
  1594. reg_type, _ := c.GetInt64("reg_type")
  1595. diagnose := c.GetString("diagnose")
  1596. sick_type, _ := c.GetInt64("sick_type")
  1597. sick_history := c.GetString("sick_history")
  1598. doctor_id, _ := c.GetInt64("doctor", 0)
  1599. department, _ := c.GetInt64("department", 0)
  1600. his_patient_id, _ := c.GetInt64("his_patient_id")
  1601. p_type, _ := c.GetInt64("p_type")
  1602. patient_diagnose := c.GetString("patient_diagnose")
  1603. dataBody := make(map[string]interface{}, 0)
  1604. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1605. if err != nil {
  1606. utils.ErrorLog(err.Error())
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. //edit, src := GetCompareData(dataBody)
  1611. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1612. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1613. //fmt.Println(drugResult)
  1614. //fmt.Println(goodResult)
  1615. timeLayout := "2006-01-02"
  1616. loc, _ := time.LoadLocation("Local")
  1617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. adminInfo := c.GetAdminUserInfo()
  1623. recordDateTime := theTime.Unix()
  1624. //查询默认出库仓库库存
  1625. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1626. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1627. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1628. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1629. if len(lists) == 1 {
  1630. his_patient_id = lists[0].ID
  1631. }
  1632. }
  1633. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1634. //自动出库的开关开启
  1635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1636. //自动出库
  1637. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1638. //耗材保存处方出库
  1639. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1640. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1641. //已发药和已收费限制逻辑
  1642. isMidicine := false
  1643. isCharge := false
  1644. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1645. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1646. if len(prescriptions) > 0 {
  1647. for _, item := range prescriptions {
  1648. items := item.(map[string]interface{})
  1649. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1650. utils.ErrorLog("id")
  1651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1652. return
  1653. }
  1654. id := int64(items["id"].(float64))
  1655. if id > 0 {
  1656. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1657. if err != nil {
  1658. if new_prescription.OrderStatus == 4 {
  1659. isCharge = true
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. if isMidicine == true {
  1667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1668. return
  1669. }
  1670. if isCharge == true {
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1672. return
  1673. }
  1674. // 开始主事务
  1675. db := service.XTWriteDB()
  1676. tx := db.Begin()
  1677. // 在函数结束时处理事务回滚
  1678. defer func() {
  1679. if r := recover(); r != nil {
  1680. tx.Rollback()
  1681. }
  1682. }()
  1683. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1684. //药品发药出库
  1685. if pharmacyConfig.IsOpen == 1 {
  1686. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1687. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1688. if len(prescriptions) > 0 {
  1689. for _, item := range prescriptions {
  1690. items := item.(map[string]interface{})
  1691. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1692. advices := items["advices"].([]interface{})
  1693. if len(advices) > 0 {
  1694. for _, advice := range advices {
  1695. var drug_id int64
  1696. var prescribing_number float64
  1697. var prescribingNumberUnit string
  1698. var adviceId int64
  1699. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1700. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1701. }
  1702. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1703. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1704. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1705. }
  1706. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1707. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1708. }
  1709. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1710. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1711. }
  1712. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1713. if drug.ID == 0 {
  1714. tx.Rollback()
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1716. return
  1717. }
  1718. //查询药品的所有库存
  1719. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1720. var total_count int64
  1721. for _, it := range list {
  1722. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1723. }
  1724. totals := strconv.FormatInt(total_count, 10)
  1725. //查询该药品是否存在开药记录
  1726. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1727. //新增处方盘点库存是否充足
  1728. if advicelist.ID == 0 {
  1729. all_count, _ := strconv.ParseFloat(totals, 64)
  1730. if prescribingNumberUnit == drug.MinUnit {
  1731. if drug.IsUse != 1 {
  1732. if drug.IsProject == 0 || drug.IsProject == 2 {
  1733. if all_count == 0 {
  1734. tx.Rollback()
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1736. return
  1737. }
  1738. if prescribing_number > all_count {
  1739. tx.Rollback()
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. if prescribingNumberUnit == drug.MaxUnit {
  1747. num := prescribing_number * float64(drug.MinNumber)
  1748. if drug.IsUse != 1 {
  1749. if drug.IsProject == 0 || drug.IsProject == 2 {
  1750. if all_count == 0 {
  1751. tx.Rollback()
  1752. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1753. return
  1754. }
  1755. if num > all_count {
  1756. tx.Rollback()
  1757. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1758. return
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1765. //不使用保存处方出库
  1766. if drugOutConfig.IsOpen != 1 {
  1767. //修改处方
  1768. for _, advice := range advices {
  1769. var drug_id int64
  1770. var prescribing_number float64
  1771. var prescribingNumberUnit string
  1772. var prescribingNumber string
  1773. var adviceId int64
  1774. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1775. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1776. }
  1777. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1778. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1779. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1780. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1781. }
  1782. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1783. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1784. }
  1785. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1786. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1787. }
  1788. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1789. if drug.ID == 0 {
  1790. tx.Rollback()
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. //查询药品的所有库存
  1795. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1796. var total_count int64
  1797. for _, it := range list {
  1798. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1799. }
  1800. totals := strconv.FormatInt(total_count, 10)
  1801. //查询该药品是否存在开药记录
  1802. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1803. //新增处方
  1804. if advicelist.ID == 0 {
  1805. all_count, _ := strconv.ParseFloat(totals, 64)
  1806. if prescribingNumberUnit == drug.MinUnit {
  1807. if drug.IsUse != 1 {
  1808. if drug.IsProject == 0 || drug.IsProject == 2 {
  1809. if all_count == 0 {
  1810. tx.Rollback()
  1811. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1812. return
  1813. }
  1814. if prescribing_number > all_count {
  1815. tx.Rollback()
  1816. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1817. return
  1818. }
  1819. }
  1820. }
  1821. } else {
  1822. if prescribingNumberUnit == drug.MaxUnit {
  1823. num := prescribing_number * float64(drug.MinNumber)
  1824. if drug.IsUse != 1 {
  1825. if drug.IsProject == 0 || drug.IsProject == 2 {
  1826. if all_count == 0 {
  1827. tx.Rollback()
  1828. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1829. return
  1830. }
  1831. if num > all_count {
  1832. tx.Rollback()
  1833. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1834. return
  1835. }
  1836. }
  1837. }
  1838. }
  1839. }
  1840. }
  1841. //修改处方
  1842. if advicelist.ID > 0 {
  1843. var device_number int64
  1844. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1845. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1846. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1847. device_number = prescribingNumberInt * drug.MinNumber
  1848. }
  1849. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1850. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1852. device_number = prescribingNumberInt
  1853. }
  1854. var number_count int64
  1855. if prescribingNumberUnit == drug.MaxUnit {
  1856. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1857. number_count = prescribingNumberInt * drug.MinNumber
  1858. }
  1859. if prescribingNumberUnit == drug.MinUnit {
  1860. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1861. number_count = prescribingNumberInt
  1862. }
  1863. //如果修改的数量大于之前修改的数量
  1864. if (number_count - device_number) > 0 {
  1865. //如果修改的差数量 大于库存数量
  1866. if drug.IsUse != 1 {
  1867. if (number_count - device_number) > total_count {
  1868. tx.Rollback()
  1869. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1870. return
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. //已发药和已收费限制逻辑
  1885. //执行出库的逻辑
  1886. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1887. //校验库存总量
  1888. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1889. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1890. if len(prescriptions) > 0 {
  1891. for _, item := range prescriptions {
  1892. items := item.(map[string]interface{})
  1893. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1894. advices := items["advices"].([]interface{})
  1895. if len(advices) > 0 {
  1896. for _, advice := range advices {
  1897. var drug_id int64
  1898. var prescribing_number float64
  1899. var prescribingNumberUnit string
  1900. var adviceId int64
  1901. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1902. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1903. }
  1904. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1905. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1906. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1907. }
  1908. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1909. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1910. }
  1911. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1912. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1913. }
  1914. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1915. if drug.ID == 0 {
  1916. tx.Rollback()
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1918. return
  1919. }
  1920. //查询药品的所有库存
  1921. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1922. var total_count int64
  1923. for _, it := range list {
  1924. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1925. }
  1926. totals := strconv.FormatInt(total_count, 10)
  1927. //查询该药品是否存在开药记录
  1928. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1929. //查询最新批次库存
  1930. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1931. var batch_number_count int64
  1932. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1933. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1934. //新增处方
  1935. if advicelist.ID == 0 {
  1936. all_count, _ := strconv.ParseFloat(totals, 64)
  1937. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1938. if prescribingNumberUnit == drug.MinUnit {
  1939. if drug.IsUse != 1 {
  1940. if drug.IsProject == 0 || drug.IsProject == 2 {
  1941. if all_count == 0 {
  1942. tx.Rollback()
  1943. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1944. return
  1945. }
  1946. if prescribing_number > all_count {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. }
  1952. if adminInfo.CurrentOrgId == 10215 {
  1953. if prescribing_number > batch_number_all_count {
  1954. tx.Rollback()
  1955. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1956. return
  1957. }
  1958. }
  1959. }
  1960. }
  1961. if prescribingNumberUnit == drug.MaxUnit {
  1962. num := prescribing_number * float64(drug.MinNumber)
  1963. if drug.IsUse != 1 {
  1964. if drug.IsProject == 0 || drug.IsProject == 2 {
  1965. if all_count == 0 {
  1966. tx.Rollback()
  1967. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1968. return
  1969. }
  1970. if num > all_count {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1973. return
  1974. }
  1975. }
  1976. if adminInfo.CurrentOrgId == 10215 {
  1977. if num > batch_number_all_count {
  1978. tx.Rollback()
  1979. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1980. return
  1981. }
  1982. }
  1983. }
  1984. }
  1985. }
  1986. //不是保存处方出库
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribingNumberUnit == drug.MinUnit {
  2039. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2040. if drug.IsUse != 1 {
  2041. if drug.IsProject == 0 || drug.IsProject == 2 {
  2042. if all_count == 0 {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. if prescribing_number > all_count {
  2048. tx.Rollback()
  2049. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2050. return
  2051. }
  2052. }
  2053. if adminInfo.CurrentOrgId == 10215 {
  2054. if prescribing_number > batch_number_all_count {
  2055. tx.Rollback()
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. }
  2061. } else {
  2062. if prescribingNumberUnit == drug.MaxUnit {
  2063. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2064. num := prescribing_number * float64(drug.MinNumber)
  2065. if drug.IsUse != 1 {
  2066. if drug.IsProject == 0 || drug.IsProject == 2 {
  2067. if all_count == 0 {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. if num > all_count {
  2073. tx.Rollback()
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2075. return
  2076. }
  2077. }
  2078. if adminInfo.CurrentOrgId == 10215 {
  2079. if prescribing_number > batch_number_all_count {
  2080. tx.Rollback()
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2082. return
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. //修改处方
  2090. if advicelist.ID > 0 {
  2091. //查询最新批次库存
  2092. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2093. var batch_number_count int64
  2094. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2095. var device_number int64
  2096. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2104. device_number = prescribingNumberInt
  2105. //回退库存
  2106. }
  2107. var number_count int64
  2108. if prescribingNumberUnit == drug.MaxUnit {
  2109. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2110. number_count = prescribingNumberInt * drug.MinNumber
  2111. //回退库存
  2112. }
  2113. if prescribingNumberUnit == drug.MinUnit {
  2114. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2115. number_count = prescribingNumberInt
  2116. //回退库存
  2117. }
  2118. //如果修改的数量大于之前修改的数量
  2119. if (number_count - device_number) > 0 {
  2120. //如果修改的差数量 大于库存数量
  2121. if drug.IsUse != 1 {
  2122. if drug.IsProject == 0 || drug.IsProject == 2 {
  2123. if total_count == 0 {
  2124. tx.Rollback()
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if (number_count - device_number) > total_count {
  2129. tx.Rollback()
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2131. return
  2132. }
  2133. if (number_count - device_number) > batch_number_count {
  2134. tx.Rollback()
  2135. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2136. return
  2137. }
  2138. }
  2139. if adminInfo.CurrentOrgId == 10215 {
  2140. // 查询该药品最后一次出库记录
  2141. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2142. var out_count int64
  2143. var in_count int64
  2144. var stock_max_number int64
  2145. var stock_min_number int64
  2146. for _, it := range outInfo {
  2147. if it.CountUnit == drug.MaxUnit {
  2148. it.Count = it.Count * drug.MinNumber
  2149. }
  2150. out_count += it.Count
  2151. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2152. stock_max_number = warehouseInfoList.StockMaxNumber
  2153. stock_min_number = warehouseInfoList.StockMinNumber
  2154. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2155. }
  2156. if out_count > 0 {
  2157. if (number_count - device_number) > in_count {
  2158. tx.Rollback()
  2159. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2160. return
  2161. }
  2162. }
  2163. // 未出库
  2164. if out_count == 0 {
  2165. var sum_in_count int64
  2166. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2167. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2168. //如果修改的数量大于有库存的第一个批次
  2169. if number_count > sum_in_count {
  2170. tx.Rollback()
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2172. return
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. //药品发药
  2179. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2180. //不使用药品发药的功能
  2181. //if pharmacyConfig.IsOpen != 1 {
  2182. // if device_number != number_count {
  2183. //
  2184. // //查询该药品的出库记录
  2185. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2186. // if len(outListExport) > 0 {
  2187. // //
  2188. // for _, item := range outListExport {
  2189. // //回退库存
  2190. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2192. // }
  2193. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2194. // var stock_max_number int64
  2195. // var stock_min_number int64
  2196. //
  2197. // if number_count >= drug.MinNumber {
  2198. //
  2199. // stock_max_number = device_number / drug.MinNumber
  2200. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2201. //
  2202. // stock_min_number = device_number % drug.MinNumber
  2203. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2204. //
  2205. // } else {
  2206. //
  2207. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2208. //
  2209. // }
  2210. // }
  2211. //
  2212. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2213. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2214. // }
  2215. // }
  2216. // }
  2217. //
  2218. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2219. // var sum_count int64
  2220. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2221. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2222. // for _, its := range stockInfo {
  2223. // if its.MaxUnit == drug.MaxUnit {
  2224. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2225. // }
  2226. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2227. // }
  2228. // //更新字典里面的库存
  2229. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2230. //
  2231. // //剩余库存
  2232. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2233. //
  2234. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2235. // //减少出库数量
  2236. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2237. //
  2238. // }
  2239. //}
  2240. }
  2241. }
  2242. }
  2243. //保存处方开药
  2244. if drugOutConfig.IsOpen == 1 {
  2245. //修改处方
  2246. for _, advice := range advices {
  2247. var drug_id int64
  2248. var prescribing_number float64
  2249. var prescribingNumberUnit string
  2250. var prescribingNumber string
  2251. var adviceId int64
  2252. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2253. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2254. }
  2255. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2256. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2257. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2258. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2259. }
  2260. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2261. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2262. }
  2263. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2264. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2265. }
  2266. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2267. if drug.ID == 0 {
  2268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2269. return
  2270. }
  2271. //查询药品的所有库存
  2272. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2273. var total_count int64
  2274. for _, it := range list {
  2275. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2276. }
  2277. totals := strconv.FormatInt(total_count, 10)
  2278. //查询该药品是否存在开药记录
  2279. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2280. //新增处方
  2281. if advicelist.ID == 0 {
  2282. //查询最新批次库存
  2283. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2284. var batch_number_count int64
  2285. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2286. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2287. all_count, _ := strconv.ParseFloat(totals, 64)
  2288. if prescribingNumberUnit == drug.MinUnit {
  2289. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2290. if drug.IsUse != 1 {
  2291. if drug.IsProject == 0 || drug.IsProject == 2 {
  2292. if all_count == 0 {
  2293. tx.Rollback()
  2294. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2295. return
  2296. }
  2297. if prescribing_number > all_count {
  2298. tx.Rollback()
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2300. return
  2301. }
  2302. }
  2303. if adminInfo.CurrentOrgId == 10215 {
  2304. if prescribing_number > batch_number_all_count {
  2305. tx.Rollback()
  2306. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2307. return
  2308. }
  2309. }
  2310. }
  2311. } else {
  2312. if prescribingNumberUnit == drug.MaxUnit {
  2313. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2314. num := prescribing_number * float64(drug.MinNumber)
  2315. if drug.IsUse != 1 {
  2316. if drug.IsProject == 0 || drug.IsProject == 2 {
  2317. if all_count == 0 {
  2318. tx.Rollback()
  2319. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2320. return
  2321. }
  2322. if num > all_count {
  2323. tx.Rollback()
  2324. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2325. return
  2326. }
  2327. }
  2328. if adminInfo.CurrentOrgId == 10215 {
  2329. if prescribing_number > batch_number_all_count {
  2330. tx.Rollback()
  2331. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2332. return
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. //修改处方
  2340. if advicelist.ID > 0 {
  2341. //查询最新批次库存
  2342. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2343. var batch_number_count int64
  2344. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2345. var device_number int64
  2346. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2347. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2348. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2349. device_number = prescribingNumberInt * drug.MinNumber
  2350. }
  2351. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2352. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2354. device_number = prescribingNumberInt
  2355. }
  2356. var number_count int64
  2357. if prescribingNumberUnit == drug.MaxUnit {
  2358. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2359. number_count = prescribingNumberInt * drug.MinNumber
  2360. }
  2361. if prescribingNumberUnit == drug.MinUnit {
  2362. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2363. number_count = prescribingNumberInt
  2364. }
  2365. //如果修改的数量大于之前修改的数量
  2366. if (number_count - device_number) > 0 {
  2367. //如果修改的差数量 大于库存数量
  2368. if drug.IsUse != 1 {
  2369. if drug.IsProject == 0 || drug.IsProject == 2 {
  2370. if total_count == 0 {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > total_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. if (number_count - device_number) > batch_number_count {
  2383. tx.Rollback()
  2384. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2385. return
  2386. }
  2387. }
  2388. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2389. //查询历史出库数据总批次
  2390. // 查询该药品最后一次出库记录
  2391. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2392. var out_count int64
  2393. var in_count int64
  2394. var stock_max_number int64
  2395. var stock_min_number int64
  2396. for _, it := range outInfo {
  2397. if it.CountUnit == drug.MaxUnit {
  2398. it.Count = it.Count * drug.MinNumber
  2399. }
  2400. out_count += it.Count
  2401. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2402. stock_max_number = warehouseInfoList.StockMaxNumber
  2403. stock_min_number = warehouseInfoList.StockMinNumber
  2404. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2405. }
  2406. if out_count > 0 {
  2407. if (number_count - device_number) > in_count {
  2408. tx.Rollback()
  2409. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2410. return
  2411. }
  2412. }
  2413. // 未出库
  2414. if out_count == 0 {
  2415. var sum_in_count int64
  2416. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2417. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2418. if sum_in_count == 0 {
  2419. tx.Rollback()
  2420. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2421. return
  2422. }
  2423. //如果修改的数量大于有库存的第一个批次
  2424. if number_count > sum_in_count {
  2425. tx.Rollback()
  2426. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2427. return
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. //校验耗材库存
  2444. if goodOutConfig.IsOpen == 1 {
  2445. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2446. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2447. if len(prescriptions) > 0 {
  2448. for _, item := range prescriptions {
  2449. items := item.(map[string]interface{})
  2450. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2451. projects := items["project"].([]interface{})
  2452. if len(projects) > 0 {
  2453. for _, project := range projects {
  2454. var project_id int64
  2455. var project_type int64
  2456. var totals float64
  2457. var project_name string
  2458. var parsetotal int64
  2459. var id int64
  2460. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2461. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2462. }
  2463. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2464. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2465. }
  2466. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2467. total, _ := project.(map[string]interface{})["total"].(string)
  2468. totals, _ = strconv.ParseFloat(total, 64)
  2469. }
  2470. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2471. project_name = project.(map[string]interface{})["project_name"].(string)
  2472. }
  2473. if project_type == 3 {
  2474. //查找该耗材的出库记录
  2475. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2476. if len(goodWarehouseInfo) == 0 {
  2477. //查询耗材库存
  2478. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2479. var stock_count int64
  2480. for _, it := range list {
  2481. stock_count += it.StockCount
  2482. }
  2483. stock_counts := strconv.FormatInt(stock_count, 10)
  2484. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2485. if stock_total_count == 0 {
  2486. tx.Rollback()
  2487. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2488. return
  2489. }
  2490. if totals > stock_total_count {
  2491. tx.Rollback()
  2492. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2493. return
  2494. }
  2495. }
  2496. if len(goodWarehouseInfo) > 0 {
  2497. //查询该患者耗材的历史数据
  2498. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2499. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2500. //数量发生改变
  2501. if parsetotal != count {
  2502. //如果现在的数量大于历史数量,就要看库存是否足够
  2503. if parsetotal > count {
  2504. //查询耗材所有库存
  2505. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2506. var stock_count int64
  2507. for _, it := range list {
  2508. stock_count += it.StockCount
  2509. }
  2510. //库存不足
  2511. if stock_count == 0 {
  2512. tx.Rollback()
  2513. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2514. return
  2515. }
  2516. if (parsetotal - count) > stock_count {
  2517. tx.Rollback()
  2518. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2519. return
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. }
  2532. //不使用耗材保存处方出库
  2533. if goodOutConfig.IsOpen != 1 {
  2534. if stockConfig.IsOpen == 1 {
  2535. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2536. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2537. if len(prescriptions) > 0 {
  2538. for _, item := range prescriptions {
  2539. items := item.(map[string]interface{})
  2540. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2541. projects := items["project"].([]interface{})
  2542. if len(projects) > 0 {
  2543. for _, project := range projects {
  2544. var project_id int64
  2545. var project_type int64
  2546. var totals float64
  2547. var project_name string
  2548. var parsetotal int64
  2549. var id int64
  2550. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2551. id = int64(project.(map[string]interface{})["id"].(float64))
  2552. }
  2553. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2554. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2555. }
  2556. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2557. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2558. }
  2559. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2560. total, _ := project.(map[string]interface{})["total"].(string)
  2561. totals, _ = strconv.ParseFloat(total, 64)
  2562. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2563. }
  2564. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2565. project_name = project.(map[string]interface{})["project_name"].(string)
  2566. }
  2567. if project_type == 3 {
  2568. //查找该耗材的出库记录
  2569. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2570. //没有出库记录
  2571. if len(goodWarehouseInfo) == 0 {
  2572. //查询耗材库存
  2573. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2574. var stock_count int64
  2575. for _, it := range list {
  2576. stock_count += it.StockCount
  2577. }
  2578. stock_counts := strconv.FormatInt(stock_count, 10)
  2579. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2580. if stock_total_count == 0 {
  2581. tx.Rollback()
  2582. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2583. return
  2584. }
  2585. if totals > stock_total_count {
  2586. tx.Rollback()
  2587. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2588. return
  2589. }
  2590. //查找今日该患者已经出库的所有耗材
  2591. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2592. for _, item := range goodList {
  2593. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2594. var flush_count int64
  2595. for _, it := range goodListSix {
  2596. flush_count += it.StockCount
  2597. }
  2598. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2599. creater := adminInfo.AdminUser.Id
  2600. if errs != nil {
  2601. goodErrcode := models.XtGoodErrcode{
  2602. UserOrgId: item.OrgId,
  2603. Errcode: "手动出库更新剩余出库失败",
  2604. GoodId: item.GoodId,
  2605. Status: 1,
  2606. Ctime: time.Now().Unix(),
  2607. Mtime: 0,
  2608. Count: 0,
  2609. StockCount: 0,
  2610. Creater: creater,
  2611. BatchNumberId: 0,
  2612. WarehouseOutId: 0,
  2613. }
  2614. service.CreateGoodErrcode(goodErrcode)
  2615. }
  2616. }
  2617. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2618. }
  2619. //有出库记录
  2620. if len(goodWarehouseInfo) > 0 {
  2621. //查询该患者耗材的历史数据
  2622. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2623. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2624. //数量发生改变
  2625. if parsetotal != count {
  2626. //查找今日该患者已经出库的所有耗材
  2627. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2628. for _, item := range goodList {
  2629. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2630. var flush_count int64
  2631. for _, it := range goodListSix {
  2632. flush_count += it.StockCount
  2633. }
  2634. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2635. //减少出库数量
  2636. creater := adminInfo.AdminUser.Id
  2637. if errs != nil {
  2638. goodErrcode := models.XtGoodErrcode{
  2639. UserOrgId: item.OrgId,
  2640. Errcode: "手动出库更新剩余出库失败",
  2641. GoodId: item.GoodId,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Count: 0,
  2646. StockCount: 0,
  2647. Creater: creater,
  2648. BatchNumberId: 0,
  2649. WarehouseOutId: 0,
  2650. }
  2651. service.CreateGoodErrcode(goodErrcode)
  2652. }
  2653. //查询默认仓库
  2654. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2655. var total_count int64
  2656. for _, it := range stockList {
  2657. total_count += it.StockCount
  2658. }
  2659. //基础库插入数据
  2660. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2661. }
  2662. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. }
  2674. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2675. var hpInfo models.HisPrescriptionInfo
  2676. if info.ID == 0 {
  2677. var randNum int
  2678. randNum = rand.Intn(10000) + 1000
  2679. timestamp := time.Now().Unix()
  2680. tempTime := time.Unix(timestamp, 0)
  2681. timeFormat := tempTime.Format("20060102150405")
  2682. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2683. hpInfo = models.HisPrescriptionInfo{
  2684. HisPatientId: his_patient_id,
  2685. UserOrgId: adminInfo.CurrentOrgId,
  2686. RecordDate: theTime.Unix(),
  2687. PatientId: patient_id,
  2688. Status: 1,
  2689. Ctime: time.Now().Unix(),
  2690. Mtime: time.Now().Unix(),
  2691. Creator: adminInfo.AdminUser.Id,
  2692. Modifier: adminInfo.AdminUser.Id,
  2693. Diagnosis: diagnose,
  2694. SickHistory: sick_history,
  2695. Departments: department,
  2696. RegisterType: reg_type,
  2697. PrescriptionNumber: p_number,
  2698. PrescriptionStatus: 1,
  2699. Doctor: role.UserName,
  2700. DoctorId: doctor_id,
  2701. SickType: sick_type,
  2702. PType: p_type,
  2703. PatientDiagnosis: patient_diagnose,
  2704. }
  2705. service.SavePatientPrescriptionInfo(hpInfo)
  2706. //创建步骤表
  2707. finish := models.XtDialysisFinish{
  2708. IsFinish: 1,
  2709. UserOrgId: adminInfo.CurrentOrgId,
  2710. Status: 1,
  2711. Ctime: time.Now().Unix(),
  2712. Mtime: 0,
  2713. Module: 4,
  2714. RecordDate: theTime.Unix(),
  2715. Sourse: 1,
  2716. PatientId: patient_id,
  2717. }
  2718. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2719. if dialysisFinish.ID == 0 {
  2720. service.CreateDialysisFinish(finish)
  2721. }
  2722. redis := service.RedisClient()
  2723. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2724. redis.Set(key, "", time.Second)
  2725. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2726. redis.Set(keyOne, "", time.Second)
  2727. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2728. redis.Set(keySeven, "", time.Second)
  2729. defer redis.Close()
  2730. } else {
  2731. hpInfo = models.HisPrescriptionInfo{
  2732. ID: info.ID,
  2733. UserOrgId: adminInfo.CurrentOrgId,
  2734. RecordDate: info.RecordDate,
  2735. PatientId: info.PatientId,
  2736. Status: 1,
  2737. Ctime: info.Ctime,
  2738. Mtime: time.Now().Unix(),
  2739. Creator: info.Creator,
  2740. Modifier: adminInfo.AdminUser.Id,
  2741. Diagnosis: diagnose,
  2742. SickHistory: sick_history,
  2743. Departments: department,
  2744. RegisterType: reg_type,
  2745. PrescriptionNumber: info.PrescriptionNumber,
  2746. Doctor: role.UserName,
  2747. PrescriptionStatus: info.PrescriptionStatus,
  2748. DoctorId: doctor_id,
  2749. SickType: sick_type,
  2750. PType: info.PType,
  2751. HisPatientId: info.HisPatientId,
  2752. PatientDiagnosis: patient_diagnose,
  2753. }
  2754. service.SavePatientPrescriptionInfo(hpInfo)
  2755. //创建步骤表
  2756. finish := models.XtDialysisFinish{
  2757. IsFinish: 1,
  2758. UserOrgId: adminInfo.CurrentOrgId,
  2759. Status: 1,
  2760. Ctime: time.Now().Unix(),
  2761. Mtime: 0,
  2762. Module: 4,
  2763. RecordDate: info.RecordDate,
  2764. Sourse: 1,
  2765. PatientId: info.PatientId,
  2766. }
  2767. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2768. if dialysisFinish.ID == 0 {
  2769. service.CreateDialysisFinish(finish)
  2770. }
  2771. redis := service.RedisClient()
  2772. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2773. redis.Set(key, "", time.Second)
  2774. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2775. redis.Set(keyOne, "", time.Second)
  2776. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2777. redis.Set(keySeven, "", time.Second)
  2778. defer redis.Close()
  2779. }
  2780. //定义切片
  2781. var adviceList []models.HisDoctorAdviceInfo
  2782. var projectList []models.HisPrescriptionProject
  2783. 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 {
  2784. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2785. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2786. var tempPrescription *models.HisPrescription
  2787. if len(prescriptions) > 0 {
  2788. for _, item := range prescriptions {
  2789. // 开始外部循环的事务
  2790. tx := db.Begin()
  2791. // 在函数结束时处理事务回滚
  2792. defer func() {
  2793. if r := recover(); r != nil {
  2794. tx.Rollback()
  2795. }
  2796. }()
  2797. items := item.(map[string]interface{})
  2798. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2799. utils.ErrorLog("id")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. id := int64(items["id"].(float64))
  2804. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2805. tempPrescription = &new_prescription
  2806. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2807. utils.ErrorLog("type")
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2809. return
  2810. }
  2811. types := int64(items["type"].(float64))
  2812. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2813. utils.ErrorLog("med_type")
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2815. return
  2816. }
  2817. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2818. if med_type == "0" {
  2819. med_type = "14"
  2820. }
  2821. //if order_status == 0 {
  2822. // order_status = 1
  2823. //}
  2824. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2825. utils.ErrorLog("pre_time")
  2826. }
  2827. preTime, _ := items["pre_time"].(string)
  2828. fmt.Println("preTime", preTime)
  2829. timeLayout := "2006-01-02"
  2830. loc, _ := time.LoadLocation("Local")
  2831. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2832. //result := strings.Split(preTime, " ")
  2833. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2834. if err != nil {
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2836. return
  2837. }
  2838. pTime := theTime2.Unix()
  2839. ctime := time.Now().Unix()
  2840. if tempPrescription.ID == 0 {
  2841. prescription := &models.HisPrescription{
  2842. ID: 0,
  2843. PatientId: patient_id,
  2844. UserOrgId: adminInfo.CurrentOrgId,
  2845. RecordDate: recordDateTime,
  2846. Ctime: ctime,
  2847. Mtime: ctime,
  2848. Type: types,
  2849. Modifier: adminInfo.AdminUser.Id,
  2850. Creator: adminInfo.AdminUser.Id,
  2851. Status: 1,
  2852. Doctor: role.UserName,
  2853. HisPatientId: his_patient_id,
  2854. OrderStatus: 1,
  2855. BatchNumber: "",
  2856. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2857. PreTime: pTime,
  2858. PType: p_type,
  2859. MedType: med_type,
  2860. }
  2861. tempPrescription = prescription
  2862. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2863. redis := service.RedisClient()
  2864. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2865. redis.Set(key, "", time.Second)
  2866. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2867. redis.Set(keyOne, "", time.Second)
  2868. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2869. redis.Set(keySeven, "", time.Second)
  2870. defer redis.Close()
  2871. } else {
  2872. tempPrescription.ID = id
  2873. tempPrescription.Type = types
  2874. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2875. tempPrescription.Mtime = time.Now().Unix()
  2876. tempPrescription.Doctor = role.UserName
  2877. //tempPrescription.OrderStatus = order_status
  2878. tempPrescription.PreTime = pTime
  2879. tempPrescription.MedType = med_type
  2880. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2881. redis := service.RedisClient()
  2882. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2883. redis.Set(key, "", time.Second)
  2884. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2885. redis.Set(keyOne, "", time.Second)
  2886. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2887. redis.Set(keySeven, "", time.Second)
  2888. defer redis.Close()
  2889. }
  2890. //service.SaveHisPrescription(prescription)
  2891. //更改患者挂号状态
  2892. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2893. fmt.Println("更改失败", err2)
  2894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2895. advices := items["advices"].([]interface{})
  2896. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2897. groupNo := int64(0)
  2898. if len(advices) > 0 {
  2899. for _, advice := range advices {
  2900. tx := db.Begin()
  2901. // 在函数结束时处理事务回滚
  2902. defer func() {
  2903. if r := recover(); r != nil {
  2904. tx.Rollback()
  2905. }
  2906. }()
  2907. var s models.HisDoctorAdviceInfo
  2908. s.PrescriptionId = tempPrescription.ID
  2909. s.AdviceType = 2
  2910. s.AdviceDoctor = doctor_id
  2911. s.StopState = 2
  2912. s.ExecutionState = 2
  2913. s.AdviceDate = theTime3.Unix()
  2914. s.Status = 1
  2915. s.UserOrgId = adminInfo.CurrentOrgId
  2916. s.RecordDate = theTime3.Unix()
  2917. s.StartTime = tempPrescription.PreTime
  2918. s.Groupno = groupNo
  2919. s.PatientId = patient_id
  2920. s.HisPatientId = his_patient_id
  2921. s.StartTime = pTime
  2922. s.IsSettle = 2
  2923. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2924. if errcode > 0 {
  2925. c.ServeFailJSONWithSGJErrorCode(errcode)
  2926. return
  2927. }
  2928. s.StartTime = pTime
  2929. var total_count int64 //处方总库存
  2930. //查询改药品信息
  2931. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2932. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2933. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2934. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2935. total_count += prescribingNumberSeven * medical.MinNumber
  2936. }
  2937. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2938. total_count += prescribingNumberSeven
  2939. }
  2940. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2941. total_count += prescribingNumberSeven
  2942. }
  2943. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2944. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2945. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2946. if s.Price != lastWarehouse.RetailPrice {
  2947. s.Price = lastWarehouse.RetailPrice
  2948. }
  2949. if s.Price == 0 {
  2950. if lastWarehouse.ID == 0 {
  2951. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2952. s.Price = lastWarehouseTwo.RetailPrice
  2953. }
  2954. }
  2955. }
  2956. //查询保存处方出库开关是否打开
  2957. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2958. if s.PatientId != 30038 {
  2959. if drugOutConfig.IsOpen == 1 {
  2960. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2961. // 查询该药品最后一次出库记录
  2962. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2963. var is_user_total int64
  2964. var no_user_total int64
  2965. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2966. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2967. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2968. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2969. }
  2970. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2971. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2972. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2973. no_user_total += prescribingNumberSevenTy
  2974. }
  2975. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2976. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2977. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2978. no_user_total += prescribingNumberSevenTy
  2979. }
  2980. if len(druginfo) > 0 {
  2981. for _, it := range druginfo {
  2982. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2983. it.Count = it.Count * drug.MinNumber
  2984. is_user_total += it.Count
  2985. }
  2986. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2987. is_user_total += it.Count
  2988. }
  2989. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2990. is_user_total += it.Count
  2991. }
  2992. }
  2993. }
  2994. //fmt.Println("药品名称----------------------", drug.DrugName)
  2995. //fmt.Println("药品名称----------------------", drug.IsUse)
  2996. //fmt.Println("is_user_total-------------------------", is_user_total)
  2997. //fmt.Println("no_user_total-------------------------", no_user_total)
  2998. if is_user_total != no_user_total {
  2999. //出库
  3000. if drug.IsUse == 2 {
  3001. creater := adminInfo.AdminUser.Id
  3002. newadviceInfo := &models.HisDoctorAdviceInfo{
  3003. ID: s.ID,
  3004. UserOrgId: s.UserOrgId,
  3005. PatientId: s.PatientId,
  3006. HisPatientId: s.HisPatientId,
  3007. AdviceType: s.AdviceType,
  3008. AdviceDate: s.AdviceDate,
  3009. StartTime: s.StartTime,
  3010. AdviceName: s.AdviceName,
  3011. AdviceDesc: s.AdviceDesc,
  3012. ReminderDate: s.ReminderDate,
  3013. SingleDose: s.SingleDose,
  3014. SingleDoseUnit: s.SingleDoseUnit,
  3015. PrescribingNumber: s.PrescribingNumber,
  3016. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3017. DeliveryWay: s.DeliveryWay,
  3018. ExecutionFrequency: s.ExecutionFrequency,
  3019. AdviceDoctor: s.AdviceDoctor,
  3020. Status: s.Status,
  3021. CreatedTime: s.CreatedTime,
  3022. UpdatedTime: s.UpdatedTime,
  3023. AdviceAffirm: s.AdviceAffirm,
  3024. Remark: s.Remark,
  3025. StopTime: s.StopTime,
  3026. StopReason: s.StopReason,
  3027. StopDoctor: s.StopDoctor,
  3028. StopState: s.StopState,
  3029. ParentId: s.ParentId,
  3030. ExecutionTime: s.ExecutionTime,
  3031. ExecutionStaff: s.ExecutionStaff,
  3032. ExecutionState: s.ExecutionState,
  3033. Checker: s.Checker,
  3034. RecordDate: s.RecordDate,
  3035. DialysisOrderId: s.DialysisOrderId,
  3036. CheckTime: s.CheckTime,
  3037. CheckState: s.CheckState,
  3038. DrugSpec: s.DrugSpec,
  3039. DrugSpecUnit: s.DrugSpecUnit,
  3040. Groupno: s.Groupno,
  3041. RemindType: s.RemindType,
  3042. FrequencyType: s.FrequencyType,
  3043. DayCount: s.DayCount,
  3044. WeekDay: s.WeekDay,
  3045. TemplateId: s.TemplateId,
  3046. Modifier: s.Modifier,
  3047. DrugId: s.DrugId,
  3048. Price: s.Price,
  3049. PrescriptionId: s.PrescriptionId,
  3050. MedListCodg: s.MedListCodg,
  3051. FeedetlSn: s.FeedetlSn,
  3052. Day: s.DayCount,
  3053. ChildDoctorAdvice: nil,
  3054. Drug: models.Drug{},
  3055. Diagnosis: s.Diagnosis,
  3056. Way: s.Way,
  3057. HospApprFlag: s.HospApprFlag,
  3058. LmtUsedFlag: s.LmtUsedFlag,
  3059. HisOrderInfo: models.HisOrderInfo{},
  3060. IsMedicine: s.IsMedicine,
  3061. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3062. Child: nil,
  3063. IsSettle: s.IsSettle,
  3064. IsMobile: s.IsMobile,
  3065. IsSelfDrug: s.IsSelfDrug,
  3066. DrugWayCount: s.DrugWayCount,
  3067. }
  3068. var history_count int64
  3069. var local_count int64
  3070. //查找已经开过的医嘱信息
  3071. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3072. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3073. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3074. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3075. local_count += prescribingNumberSevenTy * drug.MinNumber
  3076. }
  3077. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3078. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3079. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3080. local_count += prescribingNumberSevenTy
  3081. }
  3082. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3083. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3084. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3085. local_count += prescribingNumberSevenTy
  3086. }
  3087. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3088. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3089. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3090. history_count += prescribingNumberSevenTy * drug.MinNumber
  3091. }
  3092. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3093. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3094. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3095. history_count += prescribingNumberSevenTy
  3096. }
  3097. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3098. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3099. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3100. history_count += prescribingNumberSevenTy
  3101. }
  3102. //如果当前出库数量大于历史出库数量则需要出库
  3103. if local_count > history_count {
  3104. //按最小单位出库
  3105. var cha_count = local_count - history_count
  3106. newadviceInfo.PrescribingNumber = float64(cha_count)
  3107. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3108. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3109. }
  3110. //如果当前出库数量小于历史出库数量则需要退库
  3111. if local_count < history_count {
  3112. var cha_count = history_count - local_count
  3113. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3114. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3115. }
  3116. if local_count == history_count {
  3117. if is_user_total == 0 {
  3118. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3119. }
  3120. }
  3121. }
  3122. //更新字典里面的库存
  3123. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3124. var sum_count int64
  3125. for _, its := range stockInfo {
  3126. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3127. if its.MaxUnit == baseDrug.MaxUnit {
  3128. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3129. }
  3130. sum_count += its.StockMaxNumber + its.StockMinNumber
  3131. }
  3132. //更新基础库存
  3133. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3134. //剩余库存
  3135. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3136. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3137. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3138. //创建医嘱
  3139. service.CreateHisDoctorAdviceOne(&s, tx)
  3140. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3141. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3142. if len(outInfoTwo) > 0 {
  3143. for _, item := range outInfoTwo {
  3144. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3145. }
  3146. }
  3147. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3148. if len(drugAutoDetail) > 0 {
  3149. for _, item := range drugAutoDetail {
  3150. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. //记录日志
  3157. byterequest, _ := json.Marshal(s)
  3158. adviceLog := models.XtDoctorAdviceLog{
  3159. UserOrgId: s.UserOrgId,
  3160. PatientId: s.PatientId,
  3161. AdminUserId: adminInfo.AdminUser.Id,
  3162. Module: 1,
  3163. ErrLog: string(byterequest),
  3164. Status: 1,
  3165. Ctime: time.Now().Unix(),
  3166. Mtime: 0,
  3167. Source: "电脑端新建his医嘱",
  3168. RecordDate: s.AdviceDate,
  3169. }
  3170. service.CreateDoctorAdviceLog(adviceLog)
  3171. //存储切片中
  3172. adviceList = append(adviceList, s)
  3173. redis := service.RedisClient()
  3174. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3175. redis.Set(key, "", time.Second)
  3176. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3177. redis.Set(keyOne, "", time.Second)
  3178. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3179. redis.Set(keySeven, "", time.Second)
  3180. var randNum int
  3181. randNum = rand.Intn(10000) + 1000
  3182. timestamp := time.Now().Unix()
  3183. tempTime := time.Unix(timestamp, 0)
  3184. timeFormat := tempTime.Format("20060102150405")
  3185. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3186. if s.UserOrgId != 10206 {
  3187. if s.ID == 0 {
  3188. //查询改药品是否已经停用
  3189. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3190. if base.ID > 0 {
  3191. tx.Rollback()
  3192. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3193. return
  3194. }
  3195. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3196. if drugMedical.SumCount == 0 {
  3197. tx.Rollback()
  3198. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3199. return
  3200. }
  3201. }
  3202. }
  3203. //赤峰
  3204. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3205. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3206. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3207. if info.RetailPrice > 0 {
  3208. if s.DeliveryWay == "口服" {
  3209. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3210. s.Price = drug.RetailPrice
  3211. }
  3212. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3213. s.Price = info.RetailPrice
  3214. }
  3215. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3216. s.Price = info.RetailPrice
  3217. }
  3218. }
  3219. }
  3220. }
  3221. service.CreateHisDoctorAdviceOne(&s, tx)
  3222. tx.Commit()
  3223. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3224. redis.Set(keySix, "", time.Second)
  3225. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3226. redis.Set(keyFive, "", time.Second)
  3227. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3228. redis.Set(keyEight, "", time.Second)
  3229. defer redis.Close()
  3230. }
  3231. }
  3232. }
  3233. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3234. projects := items["project"].([]interface{})
  3235. if len(projects) > 0 {
  3236. for _, project := range projects {
  3237. tx := db.Begin()
  3238. // 在函数结束时处理事务回滚
  3239. defer func() {
  3240. if r := recover(); r != nil {
  3241. tx.Rollback()
  3242. }
  3243. }()
  3244. var p models.HisPrescriptionProject
  3245. p.PrescriptionId = tempPrescription.ID
  3246. p.PatientId = patient_id
  3247. p.RecordDate = theTime3.Unix()
  3248. p.Doctor = doctor_id
  3249. p.UserOrgId = adminInfo.CurrentOrgId
  3250. p.HisPatientId = his_patient_id
  3251. p.Status = 1
  3252. p.StartTime = pTime
  3253. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3254. if errcode > 0 {
  3255. tx.Rollback()
  3256. c.ServeFailJSONWithSGJErrorCode(errcode)
  3257. return
  3258. }
  3259. if p.ID == 0 {
  3260. p.IsOut = 2
  3261. }
  3262. if p.ID > 0 {
  3263. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3264. p.IsOut = projectDetail.IsOut
  3265. }
  3266. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3267. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3268. if p.Type == 3 {
  3269. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3270. if p.Price != lastWarehouse.PackingPrice {
  3271. p.Price = lastWarehouse.PackingPrice
  3272. }
  3273. if p.Price == 0 {
  3274. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3275. p.Price = lastWarehouseTwo.PackingPrice
  3276. }
  3277. if p.Unit == "" {
  3278. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3279. p.Unit = goodInfoOne.PackingUnit
  3280. }
  3281. }
  3282. }
  3283. if adminInfo.CurrentOrgId != 10206 {
  3284. if p.Type == 3 {
  3285. if p.ID == 0 {
  3286. //查询该耗材是否停用
  3287. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3288. //表示该耗材已经停用,不能保存
  3289. if goodInfoSeven.ID == 0 {
  3290. tx.Rollback()
  3291. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3292. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3293. return
  3294. }
  3295. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3296. if goodInfoOne.SumCount == 0 {
  3297. tx.Rollback()
  3298. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3299. return
  3300. }
  3301. }
  3302. }
  3303. }
  3304. //查询保存耗材出库开关是否打开
  3305. if p.PatientId != 30038 {
  3306. //用机构ID区分
  3307. if adminInfo.CurrentOrgId != 10721 && adminInfo.CurrentOrgId != 10164 {
  3308. if goodOutConfig.IsOpen == 1 {
  3309. //耗材出库
  3310. if p.Type == 3 {
  3311. //对比当前数据和历史出库数据
  3312. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3313. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3314. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3315. //如果当前处方数量大于历史数据,则需要出库
  3316. if nowCount > historyCount {
  3317. var cha_count int64
  3318. cha_count = nowCount - historyCount
  3319. timeStr := time.Now().Format("2006-01-02")
  3320. timeArr := strings.Split(timeStr, "-")
  3321. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3322. total = total + 1
  3323. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3324. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3325. number = number + total
  3326. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3327. operation_time := time.Now().Unix()
  3328. creater := c.GetAdminUserInfo().AdminUser.Id
  3329. recordDateStr := time.Now().Format("2006-01-02")
  3330. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3331. nowtime := recordDate.Unix()
  3332. warehouseOut := models.WarehouseOut{
  3333. WarehouseOutOrderNumber: warehousing_out_order,
  3334. OperationTime: operation_time,
  3335. OrgId: adminInfo.CurrentOrgId,
  3336. Creater: creater,
  3337. Ctime: time.Now().Unix(),
  3338. Status: 1,
  3339. WarehouseOutTime: nowtime,
  3340. Type: 1,
  3341. StorehouseId: storeConfig.StorehouseOutInfo,
  3342. IsCheck: 1,
  3343. IsSys: 1,
  3344. }
  3345. //查询是否生成出库单
  3346. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3347. if out.ID == 0 {
  3348. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3349. }
  3350. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3351. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3352. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3353. dialyPrepareOne := models.DialysisBeforePrepare{
  3354. GoodTypeId: goodObj.GoodTypeId,
  3355. GoodId: p.ProjectId,
  3356. PatientId: p.PatientId,
  3357. RecordDate: p.RecordDate,
  3358. UserOrgId: adminInfo.CurrentOrgId,
  3359. Count: cha_count,
  3360. Ctime: time.Now().Unix(),
  3361. Creater: creater,
  3362. Status: 1,
  3363. StorehouseId: houseConfig.StorehouseOutInfo,
  3364. ProjectId: p.ID,
  3365. }
  3366. //出库
  3367. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3368. }
  3369. //如果当前处方数量小于历史数据,怎需要退库
  3370. if nowCount < historyCount {
  3371. var cha_count int64
  3372. cha_count = historyCount - nowCount
  3373. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3374. creater := c.GetAdminUserInfo().AdminUser.Id
  3375. newPrescriptionProject := &models.HisPrescriptionProject{
  3376. ID: p.ID,
  3377. ProjectId: p.ProjectId,
  3378. Price: p.Price,
  3379. UserOrgId: p.UserOrgId,
  3380. Status: 1,
  3381. Ctime: time.Now().Unix(),
  3382. Mtime: time.Now().Unix(),
  3383. PatientId: p.PatientId,
  3384. HisPatientId: p.HisPatientId,
  3385. RecordDate: p.RecordDate,
  3386. PrescriptionId: p.PrescriptionId,
  3387. Count: p.Count,
  3388. FeedetlSn: p.FeedetlSn,
  3389. MedListCodg: p.MedListCodg,
  3390. SingleDose: p.SingleDose,
  3391. DeliveryWay: p.DeliveryWay,
  3392. ExecutionFrequency: p.ExecutionFrequency,
  3393. Day: p.Day,
  3394. HisProject: models.HisProject{},
  3395. GoodInfo: models.GoodInfo{},
  3396. Remark: p.Remark,
  3397. Unit: p.Unit,
  3398. Type: p.Type,
  3399. Doctor: p.Doctor,
  3400. ExecutionTime: p.ExecutionTime,
  3401. ExecutionStaff: p.ExecutionStaff,
  3402. ExecutionState: p.ExecutionState,
  3403. CheckTime: p.CheckTime,
  3404. CheckState: p.CheckState,
  3405. Checker: p.Checker,
  3406. StartTime: p.StartTime,
  3407. TeamId: p.TeamId,
  3408. XtHisProjectTeam: models.XtHisProjectTeam{},
  3409. FrequencyType: p.FrequencyType,
  3410. DayCount: p.DayCount,
  3411. WeekDay: p.WeekDay,
  3412. IsCheckTeam: p.IsCheckTeam,
  3413. HisOrderInfo: models.HisOrderInfo{},
  3414. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3415. IsOut: p.IsOut,
  3416. YbSyncStatus: p.YbSyncStatus,
  3417. }
  3418. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3419. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3420. }
  3421. if nowCount == historyCount {
  3422. if historyCount == 0 {
  3423. recordDateStr := time.Now().Format("2006-01-02")
  3424. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3425. nowtime := recordDate.Unix()
  3426. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3427. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3428. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3429. creater := c.GetAdminUserInfo().AdminUser.Id
  3430. dialyPrepareOne := models.DialysisBeforePrepare{
  3431. GoodTypeId: goodObj.GoodTypeId,
  3432. GoodId: p.ProjectId,
  3433. PatientId: p.PatientId,
  3434. RecordDate: p.RecordDate,
  3435. UserOrgId: adminInfo.CurrentOrgId,
  3436. Count: nowCount,
  3437. Ctime: time.Now().Unix(),
  3438. Creater: creater,
  3439. Status: 1,
  3440. StorehouseId: houseConfig.StorehouseOutInfo,
  3441. ProjectId: p.ID,
  3442. }
  3443. //出库
  3444. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3445. }
  3446. }
  3447. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3448. //查询历史出库数据
  3449. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3450. var out_count_five int64
  3451. for _, item := range flowGood {
  3452. out_count_five += item.Count
  3453. }
  3454. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3455. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3456. if out_count_five != parseIntCount {
  3457. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3458. detail := models.AutomaticReduceDetail{
  3459. WarehouseOutId: 0,
  3460. WarehouseOutOrderNumber: "",
  3461. PatientId: p.PatientId,
  3462. Ctime: time.Now().Unix(),
  3463. Mtime: 0,
  3464. Status: 1,
  3465. RecordTime: p.RecordDate,
  3466. OrgId: p.UserOrgId,
  3467. GoodId: p.ProjectId,
  3468. GoodTypeId: 0,
  3469. Count: parseIntCount,
  3470. Type: 0,
  3471. ProjectId: lastHisProject.ID,
  3472. StorehouseId: 0,
  3473. }
  3474. service.CreateNewAutoDetail(detail, tx)
  3475. }
  3476. // //查询耗材最后一次出库记录
  3477. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3478. // //查询默认出库仓库库存
  3479. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3480. // if len(wareOut) > 0 {
  3481. //
  3482. // for _, it := range wareOut {
  3483. // //回退库存
  3484. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3485. //
  3486. // //删除出库记录
  3487. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3488. //
  3489. // }
  3490. // }
  3491. //
  3492. // timeStr := time.Now().Format("2006-01-02")
  3493. // timeArr := strings.Split(timeStr, "-")
  3494. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3495. //
  3496. // total = total + 1
  3497. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3498. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3499. // number = number + total
  3500. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3501. //
  3502. // operation_time := time.Now().Unix()
  3503. // creater := c.GetAdminUserInfo().AdminUser.Id
  3504. //
  3505. // recordDateStr := time.Now().Format("2006-01-02")
  3506. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3507. // nowtime := recordDate.Unix()
  3508. // warehouseOut := models.WarehouseOut{
  3509. // WarehouseOutOrderNumber: warehousing_out_order,
  3510. // OperationTime: operation_time,
  3511. // OrgId: adminInfo.CurrentOrgId,
  3512. // Creater: creater,
  3513. // Ctime: time.Now().Unix(),
  3514. // Status: 1,
  3515. // WarehouseOutTime: nowtime,
  3516. // Type: 1,
  3517. // StorehouseId: storeConfig.StorehouseOutInfo,
  3518. // IsCheck: 1,
  3519. // IsSys: 1,
  3520. // }
  3521. // //查询是否生成出库单
  3522. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3523. // if out.ID == 0 {
  3524. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3525. // }
  3526. //
  3527. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3528. //
  3529. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3530. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3531. //
  3532. // dialyPrepareOne := models.DialysisBeforePrepare{
  3533. // GoodTypeId: goodObj.GoodTypeId,
  3534. // GoodId: p.ProjectId,
  3535. // PatientId: p.PatientId,
  3536. // RecordDate: p.RecordDate,
  3537. // UserOrgId: adminInfo.CurrentOrgId,
  3538. // Count: parseIntCount,
  3539. // Ctime: time.Now().Unix(),
  3540. // Creater: creater,
  3541. // Status: 1,
  3542. // StorehouseId: houseConfig.StorehouseOutInfo,
  3543. // ProjectId: lastHisProject.ID,
  3544. // }
  3545. // //判断是否是零用耗材(非零用)
  3546. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3547. //
  3548. // //查询历史出库数据
  3549. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3550. // var out_count int64
  3551. // for _, item := range flowGood {
  3552. // out_count += item.Count
  3553. // }
  3554. // //如果历史数和当前数据不想等才进行退库出库
  3555. // if out_count != parseIntCount {
  3556. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3557. //
  3558. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3559. // detail := models.AutomaticReduceDetail{
  3560. // WarehouseOutId: 0,
  3561. // WarehouseOutOrderNumber: "",
  3562. // PatientId: p.PatientId,
  3563. // Ctime: time.Now().Unix(),
  3564. // Mtime: 0,
  3565. // Status: 1,
  3566. // RecordTime: p.RecordDate,
  3567. // OrgId: p.UserOrgId,
  3568. // GoodId: p.ProjectId,
  3569. // GoodTypeId: 0,
  3570. // Count: parseIntCount,
  3571. // Type: 0,
  3572. // ProjectId: lastHisProject.ID,
  3573. // StorehouseId: 0,
  3574. // }
  3575. //
  3576. // service.CreateNewAutoDetail(detail, tx)
  3577. //
  3578. // //查询剩余库存
  3579. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3580. // var sum_count int64
  3581. // for _, item := range goodList {
  3582. // sum_count += item.StockCount
  3583. // }
  3584. //
  3585. // //更新剩余库存
  3586. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3587. //
  3588. // //耗材
  3589. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3590. //
  3591. // }
  3592. // //判断是否是零用耗材(零用但是是出库耗材)
  3593. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3594. //
  3595. // //查询历史出库数据
  3596. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3597. // var out_count int64
  3598. // for _, item := range flowGood {
  3599. // out_count += item.Count
  3600. // }
  3601. // //如果历史数和当前数据不想等才进行退库出库
  3602. // if out_count != parseIntCount {
  3603. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3604. //
  3605. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3606. // detail := models.AutomaticReduceDetail{
  3607. // WarehouseOutId: 0,
  3608. // WarehouseOutOrderNumber: "",
  3609. // PatientId: p.PatientId,
  3610. // Ctime: time.Now().Unix(),
  3611. // Mtime: 0,
  3612. // Status: 1,
  3613. // RecordTime: p.RecordDate,
  3614. // OrgId: p.UserOrgId,
  3615. // GoodId: p.ProjectId,
  3616. // GoodTypeId: 0,
  3617. // Count: parseIntCount,
  3618. // Type: 0,
  3619. // ProjectId: p.ID,
  3620. // StorehouseId: 0,
  3621. // }
  3622. //
  3623. // service.CreateNewAutoDetail(detail, tx)
  3624. //
  3625. // //查询剩余库存
  3626. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3627. // var sum_count int64
  3628. // for _, item := range goodList {
  3629. // sum_count += item.StockCount
  3630. // }
  3631. //
  3632. // //更新剩余库存
  3633. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3634. //
  3635. // //耗材
  3636. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3637. // }
  3638. //
  3639. // }
  3640. //
  3641. // }
  3642. //
  3643. //}
  3644. //记录日志
  3645. byterequest, _ := json.Marshal(p)
  3646. adviceLog := models.XtDoctorAdviceLog{
  3647. UserOrgId: p.UserOrgId,
  3648. PatientId: p.PatientId,
  3649. AdminUserId: adminInfo.AdminUser.Id,
  3650. Module: 1,
  3651. ErrLog: string(byterequest),
  3652. Status: 1,
  3653. Ctime: time.Now().Unix(),
  3654. Mtime: 0,
  3655. Source: "电脑端新建his项目",
  3656. RecordDate: p.RecordDate,
  3657. }
  3658. service.CreateDoctorAdviceLog(adviceLog)
  3659. projectList = append(projectList, p)
  3660. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3661. //新增或者编辑项目,修改对应的标签数据
  3662. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3663. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3664. var label models.HisLabelPrintInfo
  3665. project, _ := service.GetProjectDetail(p.ProjectId)
  3666. if project.CostClassify == 3 { //类别为检验检查
  3667. if p.TeamId > 0 { //检验检查组套
  3668. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3669. if tempLabel.ID == 0 {
  3670. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3671. label.Number = tempPrescription.PrescriptionNumber
  3672. label.ProjectId = project.ID
  3673. label.Status = 1
  3674. label.IsPrint = 2
  3675. label.DoctorId = info.DoctorId
  3676. label.UserOrgId = p.UserOrgId
  3677. label.PatientId = patient_id
  3678. label.RecordDate = recordDateTime
  3679. label.Ctime = time.Now().Unix()
  3680. label.Mtime = time.Now().Unix()
  3681. label.ItemId = p.TeamId
  3682. label.FeedetlSn = p.FeedetlSn
  3683. label.PProjectId = p.ID
  3684. label.ProjectName = team.ProjectTeam
  3685. label.PatientName = patient.Name
  3686. service.CreateNewHisLabelRecord(&label, tx)
  3687. }
  3688. } else { //单条检验检查项目
  3689. label.Number = tempPrescription.PrescriptionNumber
  3690. label.ProjectId = project.ID
  3691. label.Status = 1
  3692. label.DoctorId = info.DoctorId
  3693. label.UserOrgId = p.UserOrgId
  3694. label.PatientId = patient_id
  3695. label.RecordDate = recordDateTime
  3696. label.IsPrint = 2
  3697. label.Ctime = time.Now().Unix()
  3698. label.Mtime = time.Now().Unix()
  3699. label.FeedetlSn = p.FeedetlSn
  3700. label.PProjectId = p.ID
  3701. label.ItemId = p.TeamId
  3702. label.ProjectName = project.ProjectName
  3703. label.PatientName = patient.Name
  3704. service.CreateNewHisLabelRecord(&label, tx)
  3705. }
  3706. }
  3707. }
  3708. }
  3709. }
  3710. }
  3711. }
  3712. if adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10164 {
  3713. //耗材出库
  3714. if p.Type == 3 {
  3715. //对比当前数据和历史出库数据
  3716. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3717. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3718. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3719. //如果当前处方数量大于历史数据,则需要出库
  3720. if nowCount > historyCount {
  3721. var cha_count int64
  3722. cha_count = nowCount - historyCount
  3723. timeStr := time.Now().Format("2006-01-02")
  3724. timeArr := strings.Split(timeStr, "-")
  3725. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3726. total = total + 1
  3727. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3728. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3729. number = number + total
  3730. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3731. operation_time := time.Now().Unix()
  3732. creater := c.GetAdminUserInfo().AdminUser.Id
  3733. recordDateStr := time.Now().Format("2006-01-02")
  3734. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3735. nowtime := recordDate.Unix()
  3736. warehouseOut := models.WarehouseOut{
  3737. WarehouseOutOrderNumber: warehousing_out_order,
  3738. OperationTime: operation_time,
  3739. OrgId: adminInfo.CurrentOrgId,
  3740. Creater: creater,
  3741. Ctime: time.Now().Unix(),
  3742. Status: 1,
  3743. WarehouseOutTime: nowtime,
  3744. Type: 1,
  3745. StorehouseId: storeConfig.StorehouseOutInfo,
  3746. IsCheck: 1,
  3747. IsSys: 1,
  3748. }
  3749. //查询是否生成出库单
  3750. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3751. if out.ID == 0 {
  3752. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3753. }
  3754. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3755. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3756. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3757. dialyPrepareOne := models.DialysisBeforePrepare{
  3758. GoodTypeId: goodObj.GoodTypeId,
  3759. GoodId: p.ProjectId,
  3760. PatientId: p.PatientId,
  3761. RecordDate: p.RecordDate,
  3762. UserOrgId: adminInfo.CurrentOrgId,
  3763. Count: cha_count,
  3764. Ctime: time.Now().Unix(),
  3765. Creater: creater,
  3766. Status: 1,
  3767. StorehouseId: houseConfig.StorehouseOutInfo,
  3768. ProjectId: p.ID,
  3769. }
  3770. //出库
  3771. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3772. }
  3773. //如果当前处方数量小于历史数据,怎需要退库
  3774. if nowCount < historyCount {
  3775. var cha_count int64
  3776. cha_count = historyCount - nowCount
  3777. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3778. creater := c.GetAdminUserInfo().AdminUser.Id
  3779. newPrescriptionProject := &models.HisPrescriptionProject{
  3780. ID: p.ID,
  3781. ProjectId: p.ProjectId,
  3782. Price: p.Price,
  3783. UserOrgId: p.UserOrgId,
  3784. Status: 1,
  3785. Ctime: time.Now().Unix(),
  3786. Mtime: time.Now().Unix(),
  3787. PatientId: p.PatientId,
  3788. HisPatientId: p.HisPatientId,
  3789. RecordDate: p.RecordDate,
  3790. PrescriptionId: p.PrescriptionId,
  3791. Count: p.Count,
  3792. FeedetlSn: p.FeedetlSn,
  3793. MedListCodg: p.MedListCodg,
  3794. SingleDose: p.SingleDose,
  3795. DeliveryWay: p.DeliveryWay,
  3796. ExecutionFrequency: p.ExecutionFrequency,
  3797. Day: p.Day,
  3798. HisProject: models.HisProject{},
  3799. GoodInfo: models.GoodInfo{},
  3800. Remark: p.Remark,
  3801. Unit: p.Unit,
  3802. Type: p.Type,
  3803. Doctor: p.Doctor,
  3804. ExecutionTime: p.ExecutionTime,
  3805. ExecutionStaff: p.ExecutionStaff,
  3806. ExecutionState: p.ExecutionState,
  3807. CheckTime: p.CheckTime,
  3808. CheckState: p.CheckState,
  3809. Checker: p.Checker,
  3810. StartTime: p.StartTime,
  3811. TeamId: p.TeamId,
  3812. XtHisProjectTeam: models.XtHisProjectTeam{},
  3813. FrequencyType: p.FrequencyType,
  3814. DayCount: p.DayCount,
  3815. WeekDay: p.WeekDay,
  3816. IsCheckTeam: p.IsCheckTeam,
  3817. HisOrderInfo: models.HisOrderInfo{},
  3818. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3819. IsOut: p.IsOut,
  3820. YbSyncStatus: p.YbSyncStatus,
  3821. }
  3822. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3823. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3824. }
  3825. if nowCount == historyCount {
  3826. if historyCount == 0 {
  3827. recordDateStr := time.Now().Format("2006-01-02")
  3828. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3829. nowtime := recordDate.Unix()
  3830. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3831. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3832. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3833. creater := c.GetAdminUserInfo().AdminUser.Id
  3834. dialyPrepareOne := models.DialysisBeforePrepare{
  3835. GoodTypeId: goodObj.GoodTypeId,
  3836. GoodId: p.ProjectId,
  3837. PatientId: p.PatientId,
  3838. RecordDate: p.RecordDate,
  3839. UserOrgId: adminInfo.CurrentOrgId,
  3840. Count: nowCount,
  3841. Ctime: time.Now().Unix(),
  3842. Creater: creater,
  3843. Status: 1,
  3844. StorehouseId: houseConfig.StorehouseOutInfo,
  3845. ProjectId: p.ID,
  3846. }
  3847. //出库
  3848. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3849. }
  3850. }
  3851. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3852. //查询历史出库数据
  3853. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3854. var out_count_five int64
  3855. for _, item := range flowGood {
  3856. out_count_five += item.Count
  3857. }
  3858. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3859. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3860. if out_count_five != parseIntCount {
  3861. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3862. detail := models.AutomaticReduceDetail{
  3863. WarehouseOutId: 0,
  3864. WarehouseOutOrderNumber: "",
  3865. PatientId: p.PatientId,
  3866. Ctime: time.Now().Unix(),
  3867. Mtime: 0,
  3868. Status: 1,
  3869. RecordTime: p.RecordDate,
  3870. OrgId: p.UserOrgId,
  3871. GoodId: p.ProjectId,
  3872. GoodTypeId: 0,
  3873. Count: parseIntCount,
  3874. Type: 0,
  3875. ProjectId: lastHisProject.ID,
  3876. StorehouseId: 0,
  3877. }
  3878. service.CreateNewAutoDetail(detail, tx)
  3879. }
  3880. // //查询耗材最后一次出库记录
  3881. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3882. // //查询默认出库仓库库存
  3883. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3884. // if len(wareOut) > 0 {
  3885. //
  3886. // for _, it := range wareOut {
  3887. // //回退库存
  3888. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3889. //
  3890. // //删除出库记录
  3891. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3892. //
  3893. // }
  3894. // }
  3895. //
  3896. // timeStr := time.Now().Format("2006-01-02")
  3897. // timeArr := strings.Split(timeStr, "-")
  3898. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3899. //
  3900. // total = total + 1
  3901. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3902. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3903. // number = number + total
  3904. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3905. //
  3906. // operation_time := time.Now().Unix()
  3907. // creater := c.GetAdminUserInfo().AdminUser.Id
  3908. //
  3909. // recordDateStr := time.Now().Format("2006-01-02")
  3910. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3911. // nowtime := recordDate.Unix()
  3912. // warehouseOut := models.WarehouseOut{
  3913. // WarehouseOutOrderNumber: warehousing_out_order,
  3914. // OperationTime: operation_time,
  3915. // OrgId: adminInfo.CurrentOrgId,
  3916. // Creater: creater,
  3917. // Ctime: time.Now().Unix(),
  3918. // Status: 1,
  3919. // WarehouseOutTime: nowtime,
  3920. // Type: 1,
  3921. // StorehouseId: storeConfig.StorehouseOutInfo,
  3922. // IsCheck: 1,
  3923. // IsSys: 1,
  3924. // }
  3925. // //查询是否生成出库单
  3926. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3927. // if out.ID == 0 {
  3928. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3929. // }
  3930. //
  3931. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3932. //
  3933. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3934. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3935. //
  3936. // dialyPrepareOne := models.DialysisBeforePrepare{
  3937. // GoodTypeId: goodObj.GoodTypeId,
  3938. // GoodId: p.ProjectId,
  3939. // PatientId: p.PatientId,
  3940. // RecordDate: p.RecordDate,
  3941. // UserOrgId: adminInfo.CurrentOrgId,
  3942. // Count: parseIntCount,
  3943. // Ctime: time.Now().Unix(),
  3944. // Creater: creater,
  3945. // Status: 1,
  3946. // StorehouseId: houseConfig.StorehouseOutInfo,
  3947. // ProjectId: lastHisProject.ID,
  3948. // }
  3949. // //判断是否是零用耗材(非零用)
  3950. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3951. //
  3952. // //查询历史出库数据
  3953. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3954. // var out_count int64
  3955. // for _, item := range flowGood {
  3956. // out_count += item.Count
  3957. // }
  3958. // //如果历史数和当前数据不想等才进行退库出库
  3959. // if out_count != parseIntCount {
  3960. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3961. //
  3962. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3963. // detail := models.AutomaticReduceDetail{
  3964. // WarehouseOutId: 0,
  3965. // WarehouseOutOrderNumber: "",
  3966. // PatientId: p.PatientId,
  3967. // Ctime: time.Now().Unix(),
  3968. // Mtime: 0,
  3969. // Status: 1,
  3970. // RecordTime: p.RecordDate,
  3971. // OrgId: p.UserOrgId,
  3972. // GoodId: p.ProjectId,
  3973. // GoodTypeId: 0,
  3974. // Count: parseIntCount,
  3975. // Type: 0,
  3976. // ProjectId: lastHisProject.ID,
  3977. // StorehouseId: 0,
  3978. // }
  3979. //
  3980. // service.CreateNewAutoDetail(detail, tx)
  3981. //
  3982. // //查询剩余库存
  3983. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3984. // var sum_count int64
  3985. // for _, item := range goodList {
  3986. // sum_count += item.StockCount
  3987. // }
  3988. //
  3989. // //更新剩余库存
  3990. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3991. //
  3992. // //耗材
  3993. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3994. //
  3995. // }
  3996. // //判断是否是零用耗材(零用但是是出库耗材)
  3997. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3998. //
  3999. // //查询历史出库数据
  4000. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4001. // var out_count int64
  4002. // for _, item := range flowGood {
  4003. // out_count += item.Count
  4004. // }
  4005. // //如果历史数和当前数据不想等才进行退库出库
  4006. // if out_count != parseIntCount {
  4007. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4008. //
  4009. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4010. // detail := models.AutomaticReduceDetail{
  4011. // WarehouseOutId: 0,
  4012. // WarehouseOutOrderNumber: "",
  4013. // PatientId: p.PatientId,
  4014. // Ctime: time.Now().Unix(),
  4015. // Mtime: 0,
  4016. // Status: 1,
  4017. // RecordTime: p.RecordDate,
  4018. // OrgId: p.UserOrgId,
  4019. // GoodId: p.ProjectId,
  4020. // GoodTypeId: 0,
  4021. // Count: parseIntCount,
  4022. // Type: 0,
  4023. // ProjectId: p.ID,
  4024. // StorehouseId: 0,
  4025. // }
  4026. //
  4027. // service.CreateNewAutoDetail(detail, tx)
  4028. //
  4029. // //查询剩余库存
  4030. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4031. // var sum_count int64
  4032. // for _, item := range goodList {
  4033. // sum_count += item.StockCount
  4034. // }
  4035. //
  4036. // //更新剩余库存
  4037. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4038. //
  4039. // //耗材
  4040. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4041. // }
  4042. //
  4043. // }
  4044. //
  4045. // }
  4046. //
  4047. //}
  4048. //记录日志
  4049. byterequest, _ := json.Marshal(p)
  4050. adviceLog := models.XtDoctorAdviceLog{
  4051. UserOrgId: p.UserOrgId,
  4052. PatientId: p.PatientId,
  4053. AdminUserId: adminInfo.AdminUser.Id,
  4054. Module: 1,
  4055. ErrLog: string(byterequest),
  4056. Status: 1,
  4057. Ctime: time.Now().Unix(),
  4058. Mtime: 0,
  4059. Source: "电脑端新建his项目",
  4060. RecordDate: p.RecordDate,
  4061. }
  4062. service.CreateDoctorAdviceLog(adviceLog)
  4063. projectList = append(projectList, p)
  4064. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4065. //新增或者编辑项目,修改对应的标签数据
  4066. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4067. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4068. var label models.HisLabelPrintInfo
  4069. project, _ := service.GetProjectDetail(p.ProjectId)
  4070. if project.CostClassify == 3 { //类别为检验检查
  4071. if p.TeamId > 0 { //检验检查组套
  4072. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4073. if tempLabel.ID == 0 {
  4074. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4075. label.Number = tempPrescription.PrescriptionNumber
  4076. label.ProjectId = project.ID
  4077. label.Status = 1
  4078. label.IsPrint = 2
  4079. label.DoctorId = info.DoctorId
  4080. label.UserOrgId = p.UserOrgId
  4081. label.PatientId = patient_id
  4082. label.RecordDate = recordDateTime
  4083. label.Ctime = time.Now().Unix()
  4084. label.Mtime = time.Now().Unix()
  4085. label.ItemId = p.TeamId
  4086. label.FeedetlSn = p.FeedetlSn
  4087. label.PProjectId = p.ID
  4088. label.ProjectName = team.ProjectTeam
  4089. label.PatientName = patient.Name
  4090. service.CreateNewHisLabelRecord(&label, tx)
  4091. }
  4092. } else { //单条检验检查项目
  4093. label.Number = tempPrescription.PrescriptionNumber
  4094. label.ProjectId = project.ID
  4095. label.Status = 1
  4096. label.DoctorId = info.DoctorId
  4097. label.UserOrgId = p.UserOrgId
  4098. label.PatientId = patient_id
  4099. label.RecordDate = recordDateTime
  4100. label.IsPrint = 2
  4101. label.Ctime = time.Now().Unix()
  4102. label.Mtime = time.Now().Unix()
  4103. label.FeedetlSn = p.FeedetlSn
  4104. label.PProjectId = p.ID
  4105. label.ItemId = p.TeamId
  4106. label.ProjectName = project.ProjectName
  4107. label.PatientName = patient.Name
  4108. service.CreateNewHisLabelRecord(&label, tx)
  4109. }
  4110. }
  4111. }
  4112. }
  4113. }
  4114. }
  4115. }
  4116. //插入检验数据
  4117. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4118. //新增或者编辑项目,修改对应的标签数据
  4119. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4120. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4121. var label models.HisLabelPrintInfo
  4122. project, _ := service.GetProjectDetail(p.ProjectId)
  4123. if project.CostClassify == 3 { //类别为检验检查
  4124. if p.TeamId > 0 { //检验检查组套
  4125. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4126. if tempLabel.ID == 0 {
  4127. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4128. label.Number = tempPrescription.PrescriptionNumber
  4129. label.ProjectId = project.ID
  4130. label.Status = 1
  4131. label.IsPrint = 2
  4132. label.DoctorId = info.DoctorId
  4133. label.UserOrgId = p.UserOrgId
  4134. label.PatientId = patient_id
  4135. label.RecordDate = recordDateTime
  4136. label.Ctime = time.Now().Unix()
  4137. label.Mtime = time.Now().Unix()
  4138. label.ItemId = p.TeamId
  4139. label.FeedetlSn = p.FeedetlSn
  4140. label.PProjectId = p.ID
  4141. label.ProjectName = team.ProjectTeam
  4142. label.PatientName = patient.Name
  4143. service.CreateHisLabelRecord(&label)
  4144. }
  4145. } else { //单条检验检查项目
  4146. label.Number = tempPrescription.PrescriptionNumber
  4147. label.ProjectId = project.ID
  4148. label.Status = 1
  4149. label.DoctorId = info.DoctorId
  4150. label.UserOrgId = p.UserOrgId
  4151. label.PatientId = patient_id
  4152. label.RecordDate = recordDateTime
  4153. label.IsPrint = 2
  4154. label.Ctime = time.Now().Unix()
  4155. label.Mtime = time.Now().Unix()
  4156. label.FeedetlSn = p.FeedetlSn
  4157. label.PProjectId = p.ID
  4158. label.ItemId = p.TeamId
  4159. label.ProjectName = project.ProjectName
  4160. label.PatientName = patient.Name
  4161. service.CreateHisLabelRecord(&label)
  4162. }
  4163. }
  4164. }
  4165. }
  4166. service.CreateNewHisProjectTwo(&p, tx)
  4167. var randNum int
  4168. randNum = rand.Intn(10000) + 1000
  4169. timestamp := time.Now().Unix()
  4170. tempTime := time.Unix(timestamp, 0)
  4171. timeFormat := tempTime.Format("20060102150405")
  4172. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4173. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4174. if goodBase.ID > 0 {
  4175. tx.Rollback()
  4176. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4177. return
  4178. }
  4179. service.CreateNewHisProjectTwo(&p, tx)
  4180. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4181. //查询剩余库存
  4182. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4183. var sum_count int64
  4184. for _, item := range goodList {
  4185. sum_count += item.StockCount
  4186. }
  4187. //更新剩余库存
  4188. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4189. //耗材
  4190. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4191. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4192. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4193. if len(outInfoTwo) > 0 {
  4194. for _, item := range outInfoTwo {
  4195. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4196. }
  4197. }
  4198. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4199. if len(drugAutoDetail) > 0 {
  4200. for _, item := range drugAutoDetail {
  4201. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4202. }
  4203. }
  4204. tx.Commit()
  4205. }
  4206. }
  4207. }
  4208. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4209. // addition := items["addition"].([]interface{})
  4210. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4211. // ctime := time.Now().Unix()
  4212. // mtime := ctime
  4213. // if len(addition) > 0 {
  4214. // for _, item := range addition {
  4215. // var s models.HisAdditionalCharge
  4216. // s.PrescriptionId = tempPrescription.ID
  4217. // s.Status = 1
  4218. // s.UserOrgId = adminInfo.CurrentOrgId
  4219. // s.RecordDate = recordDateTime
  4220. // s.CreatedTime = ctime
  4221. // s.UpdatedTime = mtime
  4222. // s.PatientId = patient_id
  4223. // s.HisPatientId = his_patient_id
  4224. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4225. // if errcode > 0 {
  4226. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4227. // return
  4228. // }
  4229. // service.CreateAdditionalCharge(&s)
  4230. // var randNum int
  4231. // randNum = rand.Intn(10000) + 1000
  4232. // timestamp := time.Now().Unix()
  4233. // tempTime := time.Unix(timestamp, 0)
  4234. // timeFormat := tempTime.Format("20060102150405")
  4235. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4236. // service.CreateAdditionalCharge(&s)
  4237. //
  4238. // }
  4239. // }
  4240. //}
  4241. }
  4242. }
  4243. }
  4244. tx.Commit()
  4245. if err == nil {
  4246. c.ServeSuccessJSON(map[string]interface{}{
  4247. "msg": "保存成功",
  4248. })
  4249. return
  4250. } else {
  4251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4252. return
  4253. }
  4254. } else {
  4255. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4256. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4257. var tempPrescription *models.HisPrescription
  4258. if len(prescriptions) > 0 {
  4259. for _, item := range prescriptions {
  4260. items := item.(map[string]interface{})
  4261. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4262. utils.ErrorLog("id")
  4263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4264. return
  4265. }
  4266. id := int64(items["id"].(float64))
  4267. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4268. tempPrescription = &new_prescription
  4269. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4270. utils.ErrorLog("type")
  4271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4272. return
  4273. }
  4274. types := int64(items["type"].(float64))
  4275. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4276. utils.ErrorLog("med_type")
  4277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4278. return
  4279. }
  4280. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4281. if med_type == "0" {
  4282. med_type = "14"
  4283. }
  4284. //if order_status == 0 {
  4285. // order_status = 1
  4286. //}
  4287. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4288. utils.ErrorLog("pre_time")
  4289. }
  4290. preTime, _ := items["pre_time"].(string)
  4291. timeLayout := "2006-01-02"
  4292. loc, _ := time.LoadLocation("Local")
  4293. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4294. //result := strings.Split(preTime, " ")
  4295. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4296. if err != nil {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4298. return
  4299. }
  4300. pTime := theTime2.Unix()
  4301. ctime := time.Now().Unix()
  4302. if tempPrescription.ID == 0 {
  4303. prescription := &models.HisPrescription{
  4304. ID: 0,
  4305. PatientId: patient_id,
  4306. UserOrgId: adminInfo.CurrentOrgId,
  4307. RecordDate: recordDateTime,
  4308. Ctime: ctime,
  4309. Mtime: ctime,
  4310. Type: types,
  4311. Modifier: adminInfo.AdminUser.Id,
  4312. Creator: adminInfo.AdminUser.Id,
  4313. Status: 1,
  4314. Doctor: role.UserName,
  4315. HisPatientId: his_patient_id,
  4316. OrderStatus: 1,
  4317. BatchNumber: "",
  4318. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4319. PreTime: pTime,
  4320. PType: p_type,
  4321. MedType: med_type,
  4322. }
  4323. tempPrescription = prescription
  4324. service.SaveHisPrescription(tempPrescription)
  4325. redis := service.RedisClient()
  4326. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4327. redis.Set(key, "", time.Second)
  4328. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4329. redis.Set(keyOne, "", time.Second)
  4330. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4331. redis.Set(keySeven, "", time.Second)
  4332. defer redis.Close()
  4333. } else {
  4334. tempPrescription.ID = id
  4335. tempPrescription.Type = types
  4336. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4337. tempPrescription.Mtime = time.Now().Unix()
  4338. tempPrescription.Doctor = role.UserName
  4339. //tempPrescription.OrderStatus = order_status
  4340. tempPrescription.PreTime = pTime
  4341. tempPrescription.MedType = med_type
  4342. service.SaveHisPrescription(tempPrescription)
  4343. redis := service.RedisClient()
  4344. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4345. redis.Set(key, "", time.Second)
  4346. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4347. redis.Set(keyOne, "", time.Second)
  4348. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4349. redis.Set(keySeven, "", time.Second)
  4350. defer redis.Close()
  4351. }
  4352. //service.SaveHisPrescription(prescription)
  4353. //更改患者挂号状态
  4354. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4355. fmt.Println("更改失败", err2)
  4356. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4357. advices := items["advices"].([]interface{})
  4358. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4359. groupNo := int64(0)
  4360. if len(advices) > 0 {
  4361. for _, advice := range advices {
  4362. var s models.HisDoctorAdviceInfo
  4363. s.PrescriptionId = tempPrescription.ID
  4364. s.AdviceType = 2
  4365. s.AdviceDoctor = doctor_id
  4366. s.StopState = 2
  4367. s.ExecutionState = 2
  4368. s.AdviceDate = theTime3.Unix()
  4369. s.Status = 1
  4370. s.UserOrgId = adminInfo.CurrentOrgId
  4371. s.RecordDate = theTime3.Unix()
  4372. s.StartTime = tempPrescription.PreTime
  4373. s.Groupno = groupNo
  4374. s.PatientId = patient_id
  4375. s.HisPatientId = his_patient_id
  4376. s.StartTime = pTime
  4377. s.IsSettle = 2
  4378. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4379. if errcode > 0 {
  4380. c.ServeFailJSONWithSGJErrorCode(errcode)
  4381. return
  4382. }
  4383. s.StartTime = pTime
  4384. var total_count int64 //处方总库存
  4385. //查询改药品信息
  4386. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4387. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4388. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4389. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4390. total_count += prescribingNumberSeven * medical.MinNumber
  4391. }
  4392. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4393. total_count += prescribingNumberSeven
  4394. }
  4395. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4396. total_count += prescribingNumberSeven
  4397. }
  4398. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4399. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4400. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4401. if s.Price != lastWarehouse.RetailPrice {
  4402. s.Price = lastWarehouse.RetailPrice
  4403. }
  4404. if s.Price == 0 {
  4405. if lastWarehouse.ID == 0 {
  4406. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4407. s.Price = lastWarehouseTwo.RetailPrice
  4408. }
  4409. }
  4410. }
  4411. if adminInfo.CurrentOrgId != 10206 {
  4412. if s.ID == 0 {
  4413. //查询改药品是否已经停用
  4414. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4415. if base.ID > 0 {
  4416. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4417. return
  4418. }
  4419. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4420. if drugMedical.SumCount == 0 {
  4421. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4422. return
  4423. }
  4424. }
  4425. }
  4426. //赤峰
  4427. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4428. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4429. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4430. if info.RetailPrice > 0 {
  4431. if s.DeliveryWay == "口服" {
  4432. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4433. s.Price = drug.RetailPrice
  4434. }
  4435. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4436. s.Price = info.RetailPrice
  4437. }
  4438. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4439. s.Price = info.RetailPrice
  4440. }
  4441. }
  4442. }
  4443. }
  4444. service.CreateHisDoctorAdvice(&s)
  4445. //记录日志
  4446. byterequest, _ := json.Marshal(s)
  4447. adviceLog := models.XtDoctorAdviceLog{
  4448. UserOrgId: s.UserOrgId,
  4449. PatientId: s.PatientId,
  4450. AdminUserId: adminInfo.AdminUser.Id,
  4451. Module: 1,
  4452. ErrLog: string(byterequest),
  4453. Status: 1,
  4454. Ctime: time.Now().Unix(),
  4455. Mtime: 0,
  4456. Source: "电脑端新建his医嘱",
  4457. RecordDate: s.AdviceDate,
  4458. }
  4459. service.CreateDoctorAdviceLog(adviceLog)
  4460. //存储切片中
  4461. adviceList = append(adviceList, s)
  4462. redis := service.RedisClient()
  4463. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4464. redis.Set(key, "", time.Second)
  4465. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4466. redis.Set(keyOne, "", time.Second)
  4467. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4468. redis.Set(keySeven, "", time.Second)
  4469. var randNum int
  4470. randNum = rand.Intn(10000) + 1000
  4471. timestamp := time.Now().Unix()
  4472. tempTime := time.Unix(timestamp, 0)
  4473. timeFormat := tempTime.Format("20060102150405")
  4474. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4475. service.CreateHisDoctorAdvice(&s)
  4476. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4477. redis.Set(keySix, "", time.Second)
  4478. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4479. redis.Set(keyFive, "", time.Second)
  4480. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4481. redis.Set(keyEight, "", time.Second)
  4482. defer redis.Close()
  4483. }
  4484. }
  4485. }
  4486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4487. projects := items["project"].([]interface{})
  4488. if len(projects) > 0 {
  4489. for _, project := range projects {
  4490. var p models.HisPrescriptionProject
  4491. p.PrescriptionId = tempPrescription.ID
  4492. p.PatientId = patient_id
  4493. p.RecordDate = theTime3.Unix()
  4494. p.Doctor = doctor_id
  4495. p.UserOrgId = adminInfo.CurrentOrgId
  4496. p.HisPatientId = his_patient_id
  4497. p.Status = 1
  4498. p.StartTime = pTime
  4499. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4500. if errcode > 0 {
  4501. c.ServeFailJSONWithSGJErrorCode(errcode)
  4502. return
  4503. }
  4504. if p.ID == 0 {
  4505. p.IsOut = 2
  4506. }
  4507. if p.ID > 0 {
  4508. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4509. p.IsOut = projectDetail.IsOut
  4510. }
  4511. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4512. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4513. if p.Type == 3 {
  4514. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4515. if p.Price != lastWarehouse.PackingPrice {
  4516. p.Price = lastWarehouse.PackingPrice
  4517. }
  4518. if p.Price == 0 {
  4519. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4520. p.Price = lastWarehouseTwo.PackingPrice
  4521. }
  4522. if p.Unit == "" {
  4523. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4524. p.Unit = goodInfoOne.PackingUnit
  4525. }
  4526. }
  4527. }
  4528. if adminInfo.CurrentOrgId != 10206 {
  4529. if p.Type == 3 {
  4530. if p.ID == 0 {
  4531. //查询该耗材是否停用
  4532. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4533. //表示该耗材已经停用,不能保存
  4534. if goodInfoSeven.ID == 0 {
  4535. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4536. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4537. return
  4538. }
  4539. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4540. if goodInfoOne.SumCount == 0 {
  4541. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4542. return
  4543. }
  4544. }
  4545. }
  4546. }
  4547. service.CreateHisProjectTwo(&p)
  4548. //记录日志
  4549. byterequest, _ := json.Marshal(p)
  4550. adviceLog := models.XtDoctorAdviceLog{
  4551. UserOrgId: p.UserOrgId,
  4552. PatientId: p.PatientId,
  4553. AdminUserId: adminInfo.AdminUser.Id,
  4554. Module: 1,
  4555. ErrLog: string(byterequest),
  4556. Status: 1,
  4557. Ctime: time.Now().Unix(),
  4558. Mtime: 0,
  4559. Source: "电脑端新建his项目",
  4560. RecordDate: p.RecordDate,
  4561. }
  4562. service.CreateDoctorAdviceLog(adviceLog)
  4563. projectList = append(projectList, p)
  4564. var randNum int
  4565. randNum = rand.Intn(10000) + 1000
  4566. timestamp := time.Now().Unix()
  4567. tempTime := time.Unix(timestamp, 0)
  4568. timeFormat := tempTime.Format("20060102150405")
  4569. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4570. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4571. //新增或者编辑项目,修改对应的标签数据
  4572. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4573. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4574. var label models.HisLabelPrintInfo
  4575. project, _ := service.GetProjectDetail(p.ProjectId)
  4576. if project.CostClassify == 3 { //类别为检验检查
  4577. if p.TeamId > 0 { //检验检查组套
  4578. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4579. if tempLabel.ID == 0 {
  4580. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4581. label.Number = tempPrescription.PrescriptionNumber
  4582. label.ProjectId = project.ID
  4583. label.Status = 1
  4584. label.IsPrint = 2
  4585. label.DoctorId = info.DoctorId
  4586. label.UserOrgId = p.UserOrgId
  4587. label.PatientId = patient_id
  4588. label.RecordDate = recordDateTime
  4589. label.Ctime = time.Now().Unix()
  4590. label.Mtime = time.Now().Unix()
  4591. label.ItemId = p.TeamId
  4592. label.FeedetlSn = p.FeedetlSn
  4593. label.PProjectId = p.ID
  4594. label.ProjectName = team.ProjectTeam
  4595. label.PatientName = patient.Name
  4596. service.CreateHisLabelRecord(&label)
  4597. }
  4598. } else { //单条检验检查项目
  4599. label.Number = tempPrescription.PrescriptionNumber
  4600. label.ProjectId = project.ID
  4601. label.Status = 1
  4602. label.DoctorId = info.DoctorId
  4603. label.UserOrgId = p.UserOrgId
  4604. label.PatientId = patient_id
  4605. label.RecordDate = recordDateTime
  4606. label.IsPrint = 2
  4607. label.Ctime = time.Now().Unix()
  4608. label.Mtime = time.Now().Unix()
  4609. label.FeedetlSn = p.FeedetlSn
  4610. label.PProjectId = p.ID
  4611. label.ItemId = p.TeamId
  4612. label.ProjectName = project.ProjectName
  4613. label.PatientName = patient.Name
  4614. service.CreateHisLabelRecord(&label)
  4615. }
  4616. }
  4617. }
  4618. }
  4619. service.SaveHisProjectTwo(&p)
  4620. }
  4621. }
  4622. }
  4623. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4624. // addition := items["addition"].([]interface{})
  4625. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4626. // ctime := time.Now().Unix()
  4627. // mtime := ctime
  4628. // if len(addition) > 0 {
  4629. // for _, item := range addition {
  4630. // var s models.HisAdditionalCharge
  4631. // s.PrescriptionId = tempPrescription.ID
  4632. // s.Status = 1
  4633. // s.UserOrgId = adminInfo.CurrentOrgId
  4634. // s.RecordDate = recordDateTime
  4635. // s.CreatedTime = ctime
  4636. // s.UpdatedTime = mtime
  4637. // s.PatientId = patient_id
  4638. // s.HisPatientId = his_patient_id
  4639. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4640. // if errcode > 0 {
  4641. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4642. // return
  4643. // }
  4644. // service.CreateAdditionalCharge(&s)
  4645. // var randNum int
  4646. // randNum = rand.Intn(10000) + 1000
  4647. // timestamp := time.Now().Unix()
  4648. // tempTime := time.Unix(timestamp, 0)
  4649. // timeFormat := tempTime.Format("20060102150405")
  4650. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4651. // service.CreateAdditionalCharge(&s)
  4652. //
  4653. // }
  4654. // }
  4655. //}
  4656. }
  4657. }
  4658. //查询今日该患者开的药品处方
  4659. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4660. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4661. //药品出库
  4662. if drugOutConfig.IsOpen == 1 {
  4663. for _, item := range hisdoctorlist {
  4664. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4665. // 查询该药品最后一次出库记录
  4666. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4667. if len(druginfo) > 0 {
  4668. //回退库存
  4669. for _, it := range druginfo {
  4670. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4671. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4672. }
  4673. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4674. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4675. }
  4676. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4677. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4678. }
  4679. }
  4680. }
  4681. //删除记录
  4682. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4683. //查询最后一次数据
  4684. if drugOutConfig.IsOpen == 1 {
  4685. //出库
  4686. if drug.IsUse == 2 {
  4687. creater := adminInfo.AdminUser.Id
  4688. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4689. }
  4690. //更新字典里面的库存
  4691. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4692. var sum_count int64
  4693. for _, its := range stockInfo {
  4694. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4695. if its.MaxUnit == baseDrug.MaxUnit {
  4696. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4697. }
  4698. sum_count += its.StockMaxNumber + its.StockMinNumber
  4699. }
  4700. //更新基础库存
  4701. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4702. //剩余库存
  4703. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4704. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4705. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4706. }
  4707. }
  4708. }
  4709. //耗材保存处方出库
  4710. if goodOutConfig.IsOpen == 1 {
  4711. //查询今日耗材出库数量
  4712. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4713. for _, item := range hisgoodlist {
  4714. //查询历史出库数据
  4715. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4716. var out_count_five int64
  4717. for _, item := range flowGood {
  4718. out_count_five += item.Count
  4719. }
  4720. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4721. if out_count_five != parseIntCount {
  4722. //查询耗材最后一次出库记录
  4723. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4724. //查询默认出库仓库库存
  4725. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4726. if len(wareOut) > 0 {
  4727. for _, it := range wareOut {
  4728. //回退库存
  4729. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4730. //删除出库记录
  4731. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4732. }
  4733. }
  4734. timeStr := time.Now().Format("2006-01-02")
  4735. timeArr := strings.Split(timeStr, "-")
  4736. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4737. total = total + 1
  4738. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4739. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4740. number = number + total
  4741. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4742. operation_time := time.Now().Unix()
  4743. creater := c.GetAdminUserInfo().AdminUser.Id
  4744. recordDateStr := time.Now().Format("2006-01-02")
  4745. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4746. nowtime := recordDate.Unix()
  4747. warehouseOut := models.WarehouseOut{
  4748. WarehouseOutOrderNumber: warehousing_out_order,
  4749. OperationTime: operation_time,
  4750. OrgId: adminInfo.CurrentOrgId,
  4751. Creater: creater,
  4752. Ctime: time.Now().Unix(),
  4753. Status: 1,
  4754. WarehouseOutTime: nowtime,
  4755. Type: 1,
  4756. StorehouseId: storeConfig.StorehouseOutInfo,
  4757. IsCheck: 1,
  4758. IsSys: 1,
  4759. }
  4760. //查询是否生成出库单
  4761. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4762. if out.ID == 0 {
  4763. service.AddSigleWarehouseOut(&warehouseOut)
  4764. }
  4765. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4766. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4767. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4768. dialyPrepareOne := models.DialysisBeforePrepare{
  4769. GoodTypeId: goodObj.GoodTypeId,
  4770. GoodId: item.ProjectId,
  4771. PatientId: item.PatientId,
  4772. RecordDate: item.RecordDate,
  4773. UserOrgId: adminInfo.CurrentOrgId,
  4774. Count: parseIntCount,
  4775. Ctime: time.Now().Unix(),
  4776. Creater: creater,
  4777. Status: 1,
  4778. StorehouseId: houseConfig.StorehouseOutInfo,
  4779. ProjectId: item.ID,
  4780. }
  4781. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4782. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4783. //查询历史出库数据
  4784. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4785. var out_count int64
  4786. for _, item := range flowGood {
  4787. out_count += item.Count
  4788. }
  4789. //如果历史数和当前数据不想等才进行退库出库
  4790. if out_count != parseIntCount {
  4791. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4792. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4793. detail := models.AutomaticReduceDetail{
  4794. WarehouseOutId: 0,
  4795. WarehouseOutOrderNumber: "",
  4796. PatientId: item.PatientId,
  4797. Ctime: time.Now().Unix(),
  4798. Mtime: 0,
  4799. Status: 1,
  4800. RecordTime: item.RecordDate,
  4801. OrgId: item.UserOrgId,
  4802. GoodId: item.ProjectId,
  4803. GoodTypeId: 0,
  4804. Count: parseIntCount,
  4805. Type: 0,
  4806. ProjectId: item.ID,
  4807. StorehouseId: 0,
  4808. }
  4809. service.CreateAutoDetail(detail)
  4810. //查询剩余库存
  4811. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4812. var sum_count int64
  4813. for _, item := range goodList {
  4814. sum_count += item.StockCount
  4815. }
  4816. //更新剩余库存
  4817. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4818. //耗材
  4819. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4820. }
  4821. }
  4822. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4823. //查询历史出库数据
  4824. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4825. var out_count int64
  4826. for _, item := range flowGood {
  4827. out_count += item.Count
  4828. }
  4829. //如果历史数和当前数据不想等才进行退库出库
  4830. if out_count != parseIntCount {
  4831. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4832. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4833. detail := models.AutomaticReduceDetail{
  4834. WarehouseOutId: 0,
  4835. WarehouseOutOrderNumber: "",
  4836. PatientId: item.PatientId,
  4837. Ctime: time.Now().Unix(),
  4838. Mtime: 0,
  4839. Status: 1,
  4840. RecordTime: item.RecordDate,
  4841. OrgId: item.UserOrgId,
  4842. GoodId: item.ProjectId,
  4843. GoodTypeId: 0,
  4844. Count: parseIntCount,
  4845. Type: 0,
  4846. ProjectId: item.ID,
  4847. StorehouseId: 0,
  4848. }
  4849. service.CreateAutoDetail(detail)
  4850. //查询剩余库存
  4851. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4852. var sum_count int64
  4853. for _, item := range goodList {
  4854. sum_count += item.StockCount
  4855. }
  4856. //更新剩余库存
  4857. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4858. //耗材
  4859. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4860. }
  4861. }
  4862. }
  4863. }
  4864. }
  4865. ////同步到自备药
  4866. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4867. if selfPrescriptionOpen.IsOpen == 1 {
  4868. timeStr := time.Now().Format("2006-01-02")
  4869. timeArr := strings.Split(timeStr, "-")
  4870. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4871. total = total + 1
  4872. operation_time := time.Now().Unix()
  4873. creater := adminInfo.AdminUser.Id
  4874. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4875. warehousing := models.XtSelfDrugWarehouse{
  4876. WarehousingOrder: warehousing_order,
  4877. OperationTime: operation_time,
  4878. OrgId: adminInfo.CurrentOrgId,
  4879. Creater: creater,
  4880. Ctime: time.Now().Unix(),
  4881. Status: 1,
  4882. WarehousingTime: recordDateTime,
  4883. Type: 0,
  4884. StorehouseId: 0,
  4885. IsCheck: 1,
  4886. PatientId: patient_id,
  4887. IsSys: 1,
  4888. }
  4889. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4890. if selfDrugWarehouse.ID == 0 {
  4891. service.AddSelfDrugWarehouse(&warehousing, tx)
  4892. }
  4893. if selfDrugWarehouse.ID > 0 {
  4894. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4895. }
  4896. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4897. fmt.Println(info)
  4898. for _, item := range hisdoctorlist {
  4899. //查询该病人的该药品是否已经入库
  4900. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4901. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4902. var in_count int64
  4903. if len(selfdruginfo) > 0 {
  4904. for _, item := range selfdruginfo {
  4905. var in_count_one int64
  4906. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4907. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4908. }
  4909. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4910. in_count_one = item.WarehousingCount
  4911. }
  4912. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4913. in_count_one = item.WarehousingCount
  4914. }
  4915. in_count += in_count_one
  4916. }
  4917. }
  4918. if selfBasedrug.IsSelfDrug == 1 {
  4919. var total_count int64
  4920. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4921. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4922. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4923. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4924. }
  4925. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4926. total_count += prescribingNumberSeven
  4927. }
  4928. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4929. total_count += prescribingNumberSeven
  4930. }
  4931. //入库
  4932. if total_count > in_count {
  4933. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4934. WarehousingOrder: warehousing_order,
  4935. WarehousingId: info.ID,
  4936. DrugId: item.DrugId,
  4937. Number: "",
  4938. ProductDate: 0,
  4939. ExpiryDate: 0,
  4940. WarehousingCount: total_count - in_count,
  4941. WarehouseingUnit: selfBasedrug.MinUnit,
  4942. Price: 0,
  4943. TotalPrice: 0,
  4944. Status: 1,
  4945. Ctime: time.Now().Unix(),
  4946. Remark: "",
  4947. OrgId: adminInfo.CurrentOrgId,
  4948. Type: 0,
  4949. Manufacturer: selfBasedrug.Manufacturer,
  4950. Dealer: selfBasedrug.Dealer,
  4951. StockMaxNumber: total_count - in_count,
  4952. RetailTotalPrice: 0,
  4953. BatchNumber: "",
  4954. MaxUnit: selfBasedrug.MinUnit,
  4955. MinUnit: selfBasedrug.MinUnit,
  4956. RetailPrice: 0,
  4957. StorehouseId: 0,
  4958. IsCheck: 1,
  4959. StockMinNumber: 0,
  4960. PatientId: patient_id,
  4961. IsSys: 1,
  4962. RecordDate: item.RecordDate,
  4963. AdviceId: item.ID,
  4964. }
  4965. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4966. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4967. Creator := adminInfo.AdminUser.Id
  4968. //查询默认仓库剩余多少库存
  4969. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4970. var sum_count int64
  4971. for _, it := range list {
  4972. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4973. if it.MaxUnit == baseDrug.MaxUnit {
  4974. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4975. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4976. }
  4977. sum_count += it.StockMaxNumber + it.StockMinNumber
  4978. }
  4979. flow := &models.XtSelfDrugFlow{
  4980. WarehousingId: info.ID,
  4981. DrugId: item.DrugId,
  4982. Number: "",
  4983. BatchNumber: "",
  4984. Count: total_count - in_count,
  4985. UserOrgId: adminInfo.CurrentOrgId,
  4986. PatientId: item.PatientId,
  4987. SystemTime: time.Now().Unix(),
  4988. ConsumableType: 1,
  4989. IsSys: 1,
  4990. WarehousingOrder: warehousing_order,
  4991. WarehouseOutId: 0,
  4992. WarehouseOutOrderNumber: "",
  4993. IsEdit: 0,
  4994. CancelStockId: 0,
  4995. CancelOrderNumber: "",
  4996. Manufacturer: selfBasedrug.Manufacturer,
  4997. Dealer: selfBasedrug.Dealer,
  4998. Creator: Creator,
  4999. UpdateCreator: Creator,
  5000. Status: 1,
  5001. Ctime: item.AdviceDate,
  5002. Mtime: 0,
  5003. Price: item.Price,
  5004. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5005. WarehouseOutDetailId: 0,
  5006. CancelOutDetailId: 0,
  5007. ExpireDate: 0,
  5008. ProductDate: 0,
  5009. MaxUnit: selfBasedrug.MinUnit,
  5010. MinUnit: selfBasedrug.MinUnit,
  5011. StorehouseId: 0,
  5012. OverCount: sum_count,
  5013. OperateTime: time.Now().Unix(),
  5014. AdviceId: item.ID,
  5015. }
  5016. service.CreateSelfDrugFlow(flow, tx)
  5017. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5018. var total_count int64 // 入库总数量
  5019. var over_count int64 //剩余库存
  5020. for _, it := range drugInfolist {
  5021. if it.MaxUnit == selfBasedrug.MaxUnit {
  5022. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5023. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5024. }
  5025. }
  5026. for _, it := range drugInfolist {
  5027. total_count += it.WarehousingCount
  5028. over_count += it.StockMaxNumber + it.StockMinNumber
  5029. }
  5030. //查询该仓库是否有默认数据
  5031. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5032. if selfDrugStock.ID == 0 {
  5033. drugStock := models.XtSelfDrugStockCount{
  5034. UserOrgId: item.UserOrgId,
  5035. PatientId: item.PatientId,
  5036. SumInCount: total_count,
  5037. SumOutCount: 0,
  5038. SumCancelCount: 0,
  5039. DrugId: item.DrugId,
  5040. Ctime: time.Now().Unix(),
  5041. Mtime: 0,
  5042. Status: 1,
  5043. FlushCount: over_count,
  5044. SumActOutCount: 0,
  5045. }
  5046. service.CreateSelfDrugStockSum(drugStock, tx)
  5047. }
  5048. if selfDrugStock.ID > 0 {
  5049. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5050. }
  5051. }
  5052. //查询这个单据的出库数量
  5053. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5054. var his_out_count int64
  5055. for _, item := range drugFlowList {
  5056. his_out_count += item.Count
  5057. }
  5058. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5059. if (total_count + his_out_count) <= in_count {
  5060. // 出库
  5061. if total_count < in_count {
  5062. var cha_count int64
  5063. cha_count = in_count - total_count
  5064. var stock_number int64 = 0
  5065. //查询库存是否充足
  5066. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5067. // 将该批次的剩余库存数量转换为拆零数量
  5068. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5069. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5070. }
  5071. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5072. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5073. }
  5074. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5075. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5076. }
  5077. if stock_number >= cha_count {
  5078. var maxNumber int64 = 0
  5079. var minNumber int64 = 0
  5080. maxNumber = cha_count / selfBasedrug.MinNumber
  5081. minNumber = cha_count % selfBasedrug.MinNumber
  5082. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5083. minNumber = maxNumber
  5084. }
  5085. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5086. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5088. return
  5089. }
  5090. }
  5091. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5092. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5093. }
  5094. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5095. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5096. }
  5097. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5098. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5099. }
  5100. if warehouse.StockMaxNumber < 0 {
  5101. warehouse.StockMaxNumber = 0
  5102. }
  5103. if warehouse.StockMinNumber < 0 {
  5104. warehouse.StockMinNumber = 0
  5105. }
  5106. warehouse.Mtime = time.Now().Unix()
  5107. if warehouse.StockMinNumber < minNumber {
  5108. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5109. if warehouse.MaxUnit != warehouse.MinUnit {
  5110. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5111. }
  5112. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5113. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5114. }
  5115. } else {
  5116. if minNumber > 0 {
  5117. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5118. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5119. }
  5120. }
  5121. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5122. if warehouse.StockMinNumber > 0 {
  5123. if warehouse.StockMinNumber-cha_count >= 0 {
  5124. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5125. }
  5126. }
  5127. }
  5128. }
  5129. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5130. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5131. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5132. }
  5133. }
  5134. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5135. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5137. return
  5138. }
  5139. }
  5140. if warehouse.StockMinNumber <= 0 {
  5141. warehouse.StockMinNumber = 0
  5142. }
  5143. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5144. //查询该药品剩余库存
  5145. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5146. var over_count int64
  5147. for _, its := range infolist {
  5148. if its.MaxUnit == selfBasedrug.MaxUnit {
  5149. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5150. }
  5151. over_count += its.StockMaxNumber + its.StockMinNumber
  5152. }
  5153. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5154. drugflow := models.XtSelfDrugFlow{
  5155. WarehouseOutId: 0,
  5156. WarehouseOutOrderNumber: warehousing_order,
  5157. WarehousingOrder: warehousing_order,
  5158. DrugId: item.DrugId,
  5159. Number: warehouse.Number,
  5160. ProductDate: warehouse.ProductDate,
  5161. ExpireDate: warehouse.ExpiryDate,
  5162. Count: cha_count,
  5163. Price: warehouse.RetailPrice,
  5164. Status: 1,
  5165. Ctime: item.AdviceDate,
  5166. Mtime: time.Now().Unix(),
  5167. UserOrgId: item.UserOrgId,
  5168. Manufacturer: warehouse.Manufacturer,
  5169. Dealer: warehouse.Dealer,
  5170. BatchNumber: warehouse.BatchNumber,
  5171. MaxUnit: selfBasedrug.MinUnit,
  5172. ConsumableType: 20,
  5173. IsEdit: 1,
  5174. Creator: 0,
  5175. IsSys: 3,
  5176. WarehouseOutDetailId: drugWareInfo.ID,
  5177. AdviceId: item.ID,
  5178. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5179. StorehouseId: 0,
  5180. AdminUserId: creater,
  5181. LastPrice: warehouse.Price,
  5182. StockCount: "",
  5183. WarehousingDetailId: 0,
  5184. OverCount: over_count,
  5185. RetailPrice: item.Price, //手动出库出库价格
  5186. WarehousingId: warehouse.ID,
  5187. SystemTime: item.AdviceDate,
  5188. PatientId: item.PatientId,
  5189. Remark: "保存处方入库数据差",
  5190. OperateTime: time.Now().Unix(),
  5191. }
  5192. if warehouse.RetailPrice == 0 {
  5193. drugflow.Price = item.Price
  5194. }
  5195. service.CreateSelfDrugFlowOne(drugflow, tx)
  5196. var out_count int64
  5197. out_count = in_count - total_count
  5198. //
  5199. //fmt.Println("in_count------------------", in_count)
  5200. //fmt.Println("total_count------------------", total_count)
  5201. //添加出库数量
  5202. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5203. //查询剩余库存
  5204. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5205. var sum_count int64
  5206. for _, its := range stockInfo {
  5207. if its.MaxUnit == selfBasedrug.MaxUnit {
  5208. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5209. }
  5210. sum_count += its.StockMaxNumber + its.StockMinNumber
  5211. }
  5212. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5213. } else {
  5214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5215. return
  5216. }
  5217. }
  5218. }
  5219. }
  5220. }
  5221. }
  5222. }
  5223. tx.Commit()
  5224. if err == nil {
  5225. c.ServeSuccessJSON(map[string]interface{}{
  5226. "msg": "保存成功",
  5227. })
  5228. return
  5229. } else {
  5230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5231. return
  5232. }
  5233. }
  5234. }
  5235. //func (c *HisApiController) EditHisPrescription() {
  5236. // record_date := c.GetString("record_date")
  5237. // patient_id, _ := c.GetInt64("patient_id")
  5238. // reg_type, _ := c.GetInt64("reg_type")
  5239. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5240. // diagnose := c.GetString("diagnose")
  5241. // sick_type, _ := c.GetInt64("sick_type")
  5242. // sick_history := c.GetString("sick_history")
  5243. // doctor_id, _ := c.GetInt64("doctor", 0)
  5244. // department, _ := c.GetInt64("department", 0)
  5245. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5246. // p_type, _ := c.GetInt64("p_type")
  5247. //
  5248. // dataBody := make(map[string]interface{}, 0)
  5249. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5250. // if err != nil {
  5251. // utils.ErrorLog(err.Error())
  5252. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5253. // return
  5254. // }
  5255. //
  5256. // timeLayout := "2006-01-02"
  5257. // loc, _ := time.LoadLocation("Local")
  5258. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5259. // if err != nil {
  5260. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5261. // return
  5262. // }
  5263. // adminInfo := c.GetAdminUserInfo()
  5264. // recordDateTime := theTime.Unix()
  5265. //
  5266. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5267. //
  5268. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5269. // var hpInfo models.HisPrescriptionInfo
  5270. // if info.ID == 0 {
  5271. // var randNum int
  5272. // randNum = rand.Intn(10000) + 1000
  5273. // timestamp := time.Now().Unix()
  5274. // tempTime := time.Unix(timestamp, 0)
  5275. // timeFormat := tempTime.Format("20060102150405")
  5276. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5277. //
  5278. // hpInfo = models.HisPrescriptionInfo{
  5279. // UserOrgId: adminInfo.CurrentOrgId,
  5280. // RecordDate: theTime.Unix(),
  5281. // PatientId: patient_id,
  5282. // Status: 1,
  5283. // Ctime: time.Now().Unix(),
  5284. // Mtime: time.Now().Unix(),
  5285. // Creator: adminInfo.AdminUser.Id,
  5286. // Modifier: adminInfo.AdminUser.Id,
  5287. // Diagnosis: diagnose,
  5288. // SickHistory: sick_history,
  5289. // Departments: department,
  5290. // RegisterType: reg_type,
  5291. // PrescriptionNumber: p_number,
  5292. // PrescriptionStatus: 1,
  5293. // Doctor: role.UserName,
  5294. // DoctorId: doctor_id,
  5295. // SickType: sick_type,
  5296. // PType: p_type,
  5297. // }
  5298. // service.SavePatientPrescriptionInfo(hpInfo)
  5299. //
  5300. // } else {
  5301. // hpInfo = models.HisPrescriptionInfo{
  5302. // ID: info.ID,
  5303. // UserOrgId: adminInfo.CurrentOrgId,
  5304. // RecordDate: info.RecordDate,
  5305. // PatientId: info.PatientId,
  5306. // Status: 1,
  5307. // Ctime: info.Ctime,
  5308. // Mtime: time.Now().Unix(),
  5309. // Creator: info.Creator,
  5310. // Modifier: adminInfo.AdminUser.Id,
  5311. // Diagnosis: diagnose,
  5312. // SickHistory: sick_history,
  5313. // Departments: department,
  5314. // RegisterType: reg_type,
  5315. // PrescriptionNumber: info.PrescriptionNumber,
  5316. // Doctor: role.UserName,
  5317. // PrescriptionStatus: info.PrescriptionStatus,
  5318. // DoctorId: doctor_id,
  5319. // SickType: sick_type,
  5320. // PType: info.PType,
  5321. // }
  5322. // service.SavePatientPrescriptionInfo(hpInfo)
  5323. // }
  5324. //
  5325. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5326. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5327. //
  5328. // if len(prescriptions) > 0 {
  5329. // for _, item := range prescriptions {
  5330. // items := item.(map[string]interface{})
  5331. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5332. // utils.ErrorLog("id")
  5333. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5334. // return
  5335. // }
  5336. // id := int64(items["id"].(float64))
  5337. //
  5338. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5339. // utils.ErrorLog("type")
  5340. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5341. // return
  5342. // }
  5343. // types := int64(items["type"].(float64))
  5344. //
  5345. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5346. // utils.ErrorLog("med_type")
  5347. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5348. // return
  5349. // }
  5350. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5351. //
  5352. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5353. //
  5354. // ctime := time.Now().Unix()
  5355. //
  5356. // prescription := &models.HisPrescription{
  5357. // ID: id,
  5358. // PatientId: patient_id,
  5359. // UserOrgId: adminInfo.CurrentOrgId,
  5360. // RecordDate: recordDateTime,
  5361. // Ctime: ctime,
  5362. // Mtime: ctime,
  5363. // Type: types,
  5364. // Modifier: adminInfo.AdminUser.Id,
  5365. // Creator: adminInfo.AdminUser.Id,
  5366. // Status: 1,
  5367. // Doctor: role.UserName,
  5368. // HisPatientId: his_patient_id,
  5369. // OrderStatus: 1,
  5370. // BatchNumber: "",
  5371. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5372. // PType: hpInfo.PType,
  5373. // MedType: med_type,
  5374. // }
  5375. //
  5376. // if historyPrescription.ID > 0 {
  5377. // prescription.PreTime = historyPrescription.PreTime
  5378. //
  5379. // }
  5380. //
  5381. // service.SaveHisPrescription(prescription)
  5382. //
  5383. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5384. // advices := items["advices"].([]interface{})
  5385. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5386. // groupNo := int64(0)
  5387. // ctime := time.Now().Unix()
  5388. // mtime := ctime
  5389. // if len(advices) > 0 {
  5390. // for _, advice := range advices {
  5391. // var s models.HisDoctorAdviceInfo
  5392. // s.PrescriptionId = prescription.ID
  5393. // s.AdviceType = 2
  5394. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5395. // s.StopState = 2
  5396. // s.ExecutionState = 2
  5397. // s.AdviceDate = recordDateTime
  5398. // s.Status = 1
  5399. // s.UserOrgId = adminInfo.CurrentOrgId
  5400. // s.RecordDate = recordDateTime
  5401. // s.StartTime = prescription.PreTime
  5402. // s.Groupno = groupNo
  5403. // s.CreatedTime = ctime
  5404. // s.UpdatedTime = mtime
  5405. // s.PatientId = patient_id
  5406. // s.HisPatientId = his_patient_id
  5407. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5408. // if errcode > 0 {
  5409. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5410. // return
  5411. // }
  5412. //
  5413. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5414. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5415. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5416. // if s.Price == 0 {
  5417. // s.Price = lastWarehouse.RetailPrice
  5418. // }
  5419. // }
  5420. //
  5421. // service.CreateHisDoctorAdvice(&s)
  5422. // //记录日志
  5423. // byterequest, _ := json.Marshal(s)
  5424. // adviceLog := models.XtDoctorAdviceLog{
  5425. // UserOrgId: s.UserOrgId,
  5426. // PatientId: s.PatientId,
  5427. // AdminUserId: adminInfo.AdminUser.Id,
  5428. // Module: 1,
  5429. // ErrLog: string(byterequest),
  5430. // Status: 1,
  5431. // Ctime: time.Now().Unix(),
  5432. // Mtime: 0,
  5433. // Source: "电脑端his医嘱修改",
  5434. // RecordDate: s.AdviceDate,
  5435. // }
  5436. // service.CreateDoctorAdviceLog(adviceLog)
  5437. // redis := service.RedisClient()
  5438. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5439. // redis.Set(key, "", time.Second)
  5440. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5441. // fmt.Println("keyOne", keyOne)
  5442. // redis.Set(keyOne, "", time.Second)
  5443. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5444. // redis.Set(keySeven, "", time.Second)
  5445. // redis.Close()
  5446. //
  5447. // }
  5448. // }
  5449. // }
  5450. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5451. // projects := items["project"].([]interface{})
  5452. // if len(projects) > 0 {
  5453. // for _, project := range projects {
  5454. // var p models.HisPrescriptionProject
  5455. // p.PrescriptionId = prescription.ID
  5456. // p.Ctime = time.Now().Unix()
  5457. // p.Mtime = time.Now().Unix()
  5458. // p.PatientId = patient_id
  5459. // p.RecordDate = recordDateTime
  5460. // p.UserOrgId = adminInfo.CurrentOrgId
  5461. // p.HisPatientId = his_patient_id
  5462. // p.Status = 1
  5463. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5464. // if errcode > 0 {
  5465. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5466. // return
  5467. // }
  5468. // service.CreateHisProjectTwo(&p)
  5469. //
  5470. // //记录日志
  5471. // byterequest, _ := json.Marshal(p)
  5472. // adviceLog := models.XtDoctorAdviceLog{
  5473. // UserOrgId: p.UserOrgId,
  5474. // PatientId: p.PatientId,
  5475. // AdminUserId: adminInfo.AdminUser.Id,
  5476. // Module: 1,
  5477. // ErrLog: string(byterequest),
  5478. // Status: 1,
  5479. // Ctime: time.Now().Unix(),
  5480. // Mtime: 0,
  5481. // Source: "电脑端his项目修改",
  5482. // RecordDate: p.RecordDate,
  5483. // }
  5484. // service.CreateDoctorAdviceLog(adviceLog)
  5485. // }
  5486. // }
  5487. // }
  5488. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5489. // addition := items["addition"].([]interface{})
  5490. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5491. // ctime := time.Now().Unix()
  5492. // mtime := ctime
  5493. // if len(addition) > 0 {
  5494. // for _, item := range addition {
  5495. // var s models.HisAdditionalCharge
  5496. // s.PrescriptionId = prescription.ID
  5497. // s.Status = 1
  5498. // s.UserOrgId = adminInfo.CurrentOrgId
  5499. // s.RecordDate = recordDateTime
  5500. // s.CreatedTime = ctime
  5501. // s.UpdatedTime = mtime
  5502. // s.PatientId = patient_id
  5503. // s.HisPatientId = his_patient_id
  5504. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5505. // if errcode > 0 {
  5506. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5507. // return
  5508. // }
  5509. // service.CreateAdditionalCharge(&s)
  5510. // }
  5511. // }
  5512. // }
  5513. //
  5514. // }
  5515. // }
  5516. // }
  5517. // if err == nil {
  5518. // c.ServeSuccessJSON(map[string]interface{}{
  5519. // "msg": "保存成功",
  5520. // })
  5521. // return
  5522. //
  5523. // } else {
  5524. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5525. // return
  5526. // }
  5527. //}
  5528. func (c *HisApiController) DeletePrescription() {
  5529. prescription_id, _ := c.GetInt64("id")
  5530. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5531. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5532. ////同步到自备药
  5533. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5534. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5535. if selfPrescriptionOpen.IsOpen == 1 {
  5536. // 在函数结束时处理事务回滚
  5537. db := service.XTWriteDB()
  5538. tx := db.Begin()
  5539. defer func() {
  5540. if r := recover(); r != nil {
  5541. tx.Rollback()
  5542. } else {
  5543. tx.Commit()
  5544. }
  5545. }()
  5546. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5547. for _, item := range advicesList {
  5548. timeStr := time.Now().Format("2006-01-02")
  5549. timeArr := strings.Split(timeStr, "-")
  5550. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5551. total = total + 1
  5552. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5553. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5554. number = number + total
  5555. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5556. operation_time := time.Now().Unix()
  5557. creater := c.GetAdminUserInfo().AdminUser.Id
  5558. //创建一个出库单
  5559. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5560. WarehouseOutOrderNumber: warehousing_out_order,
  5561. OperationTime: operation_time,
  5562. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5563. Creater: creater,
  5564. Ctime: time.Now().Unix(),
  5565. Status: 1,
  5566. WarehouseOutTime: item.AdviceDate,
  5567. Type: 0,
  5568. PatientId: item.PatientId,
  5569. IsCheck: 1,
  5570. }
  5571. //查询今日是否有出库数据
  5572. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5573. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5574. if lastWarehouseOut.ID == 0 {
  5575. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5576. }
  5577. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5578. var total_count int64
  5579. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5580. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5581. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5582. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5583. }
  5584. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5585. total_count += prescribingNumberSeven
  5586. }
  5587. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5588. total_count += prescribingNumberSeven
  5589. }
  5590. //出库
  5591. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5592. WarehouseOutOrderNumber: warehousing_out_order,
  5593. WarehouseOutId: lastWarehouseOut.ID,
  5594. DrugId: item.DrugId,
  5595. Count: total_count,
  5596. Price: 0,
  5597. TotalPrice: 0,
  5598. Status: 1,
  5599. Ctime: item.AdviceDate,
  5600. Mtime: item.AdviceDate,
  5601. Remark: "",
  5602. OrgId: item.UserOrgId,
  5603. Type: 0,
  5604. Manufacturer: selfBasedrug.Manufacturer,
  5605. Dealer: selfBasedrug.Dealer,
  5606. RetailPrice: 0,
  5607. RetailTotalPrice: 0,
  5608. CountUnit: selfBasedrug.MinUnit,
  5609. ExpiryDate: 0,
  5610. ProductDate: 0,
  5611. Number: "",
  5612. BatchNumber: "",
  5613. IsSys: 1,
  5614. WarehouseInfoId: 0,
  5615. AdminUserId: 0,
  5616. StockCount: "",
  5617. IsCheck: 1,
  5618. SysRecordTime: item.AdviceDate,
  5619. PatientId: item.PatientId,
  5620. ClassType: "",
  5621. AdviceId: item.ID,
  5622. }
  5623. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5624. }
  5625. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5626. for _, it := range warehousingOutInfo {
  5627. //查询今日是否有出库数据
  5628. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5629. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5630. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5631. //出库逻辑
  5632. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5633. //查询剩余库存
  5634. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5635. var sum_count int64
  5636. for _, its := range stockInfo {
  5637. if its.MaxUnit == medical.MaxUnit {
  5638. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5639. }
  5640. sum_count += its.StockMaxNumber + its.StockMinNumber
  5641. }
  5642. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5643. }
  5644. }
  5645. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5646. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5647. //耗材保存处方出库
  5648. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5649. //已收费和已发药限制逻辑
  5650. isCharge := false
  5651. isMedicine := false
  5652. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5653. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5654. if new_prescription.IsMedicine == 1 {
  5655. isMedicine = true
  5656. }
  5657. for _, item := range new_prescriptions {
  5658. if item.OrderStatus == 4 {
  5659. isCharge = true
  5660. }
  5661. }
  5662. if p_err != nil {
  5663. if new_prescription.ID > 0 {
  5664. if new_prescription.OrderStatus == 2 {
  5665. isCharge = true
  5666. }
  5667. }
  5668. }
  5669. for _, item := range advices {
  5670. if item.IsMedicine == 1 {
  5671. isMedicine = true
  5672. }
  5673. }
  5674. if isCharge {
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5676. return
  5677. }
  5678. if isMedicine {
  5679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5680. return
  5681. }
  5682. //已收费和已发药限制逻辑
  5683. if len(projects) > 0 {
  5684. for _, item := range projects {
  5685. service.DeletePrintInfo(item.ID) //删除打印信息
  5686. if goodOutConfig.IsOpen != 1 {
  5687. if stockConfig.IsOpen == 1 {
  5688. if item.Type == 3 && item.IsOut == 1 {
  5689. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5690. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5691. good.Total = good.Total + f_count
  5692. service.UpdateGoodInfo(&good)
  5693. operation_time := time.Now().Unix()
  5694. creater := c.GetAdminUserInfo().AdminUser.Id
  5695. //创建退库单
  5696. timeStr := time.Now().Format("2006-01-02")
  5697. timeArr := strings.Split(timeStr, "-")
  5698. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5699. total = total + 1
  5700. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5701. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5702. cancelStock := models.CancelStock{
  5703. OrderNumber: orderNumber,
  5704. OperaTime: operation_time,
  5705. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5706. Creater: creater,
  5707. Ctime: time.Now().Unix(),
  5708. Status: 1,
  5709. ReturnTime: item.RecordDate,
  5710. Type: 1,
  5711. StorehouseId: houseConfig.StorehouseOutInfo,
  5712. IsCheck: 1,
  5713. }
  5714. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5715. if msgerrkonde == gorm.ErrRecordNotFound {
  5716. service.AddSigleCancelStock(&cancelStock)
  5717. }
  5718. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5719. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5720. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5721. //查询该耗材是否出库
  5722. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5723. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5724. deaerler, _ := service.GetDealerById(info.Dealer)
  5725. var total_count int64
  5726. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5727. total_count += count
  5728. if info.ID > 0 {
  5729. if info.Count >= total_count {
  5730. //回退库存
  5731. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5732. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5733. var flush_count int64
  5734. for _, it := range goodList {
  5735. flush_count += it.StockCount
  5736. }
  5737. cancelStockInfo := models.CancelStockInfo{
  5738. GoodId: item.ProjectId,
  5739. CancelStockId: cancel.ID,
  5740. GoodTypeId: good.GoodTypeId,
  5741. Count: prescribingNumber,
  5742. Price: info.Price,
  5743. Total: 0,
  5744. ProductDate: info.ProductDate,
  5745. ExpiryDate: info.ExpiryDate,
  5746. Ctime: time.Now().Unix(),
  5747. Status: 1,
  5748. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5749. OrderNumber: cancel.OrderNumber,
  5750. Type: 0,
  5751. Dealer: deaerler.DealerName,
  5752. Manufacturer: manufacturer.ManufacturerName,
  5753. Number: info.Number,
  5754. RegisterAccount: "",
  5755. Remark: "",
  5756. WarehouseInfoId: info.WarehouseInfotId,
  5757. PatientId: info.PatientId,
  5758. RecordDate: info.SysRecordTime,
  5759. StorehouseId: houseConfig.StorehouseOutInfo,
  5760. IsCheck: 1,
  5761. }
  5762. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5763. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5764. flow := models.VmStockFlow{
  5765. WarehousingId: info.WarehouseInfotId,
  5766. GoodId: item.ProjectId,
  5767. Number: info.Number,
  5768. LicenseNumber: info.LicenseNumber,
  5769. Count: prescribingNumber,
  5770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5771. PatientId: item.PatientId,
  5772. SystemTime: info.SysRecordTime,
  5773. ConsumableType: 7,
  5774. IsSys: 0,
  5775. WarehousingOrder: "",
  5776. WarehouseOutId: info.WarehouseOutId,
  5777. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5778. IsEdit: 0,
  5779. CancelStockId: cancel.ID,
  5780. CancelOrderNumber: cancel.OrderNumber,
  5781. Manufacturer: manufacturer.ID,
  5782. Dealer: 0,
  5783. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5784. UpdateCreator: 0,
  5785. Status: 1,
  5786. Ctime: time.Now().Unix(),
  5787. Mtime: 0,
  5788. Price: info.Price,
  5789. WarehousingDetailId: info.WarehouseInfotId,
  5790. WarehouseOutDetailId: info.ID,
  5791. CancelOutDetailId: cancelInfo.ID,
  5792. ProductDate: info.ProductDate,
  5793. ExpireDate: info.ExpiryDate,
  5794. StorehouseId: houseConfig.StorehouseOutInfo,
  5795. OverCount: flush_count,
  5796. OperateTime: time.Now().Unix(),
  5797. }
  5798. service.CreateStockFlowOne(flow)
  5799. //退库数量增加
  5800. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5801. //出库数量减少
  5802. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5803. }
  5804. if info.Count < total_count {
  5805. //回退库存
  5806. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5807. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5808. var flush_count int64
  5809. for _, it := range goodList {
  5810. flush_count += it.StockCount
  5811. }
  5812. cancelStockInfo := models.CancelStockInfo{
  5813. GoodId: item.ProjectId,
  5814. CancelStockId: cancel.ID,
  5815. GoodTypeId: good.GoodTypeId,
  5816. Count: info.Count,
  5817. Price: info.Price,
  5818. Total: 0,
  5819. ProductDate: info.ProductDate,
  5820. ExpiryDate: info.ExpiryDate,
  5821. Ctime: time.Now().Unix(),
  5822. Status: 1,
  5823. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5824. OrderNumber: cancel.OrderNumber,
  5825. Type: 0,
  5826. Dealer: deaerler.DealerName,
  5827. Manufacturer: manufacturer.ManufacturerName,
  5828. Number: info.Number,
  5829. RegisterAccount: "",
  5830. Remark: "",
  5831. WarehouseInfoId: info.WarehouseInfotId,
  5832. PatientId: info.PatientId,
  5833. RecordDate: info.SysRecordTime,
  5834. StorehouseId: houseConfig.StorehouseOutInfo,
  5835. IsCheck: 1,
  5836. }
  5837. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5838. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5839. flow := models.VmStockFlow{
  5840. WarehousingId: info.WarehouseInfotId,
  5841. GoodId: item.ProjectId,
  5842. Number: info.Number,
  5843. LicenseNumber: info.LicenseNumber,
  5844. Count: info.Count,
  5845. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5846. PatientId: item.PatientId,
  5847. SystemTime: info.SysRecordTime,
  5848. ConsumableType: 7,
  5849. IsSys: 0,
  5850. WarehousingOrder: "",
  5851. WarehouseOutId: info.WarehouseOutId,
  5852. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5853. IsEdit: 0,
  5854. CancelStockId: cancel.ID,
  5855. CancelOrderNumber: cancel.OrderNumber,
  5856. Manufacturer: manufacturer.ID,
  5857. Dealer: 0,
  5858. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5859. UpdateCreator: 0,
  5860. Status: 1,
  5861. Ctime: time.Now().Unix(),
  5862. Mtime: 0,
  5863. Price: info.Price,
  5864. WarehousingDetailId: info.WarehouseInfotId,
  5865. WarehouseOutDetailId: info.ID,
  5866. CancelOutDetailId: cancelInfo.ID,
  5867. ProductDate: info.ProductDate,
  5868. ExpireDate: info.ExpiryDate,
  5869. StorehouseId: houseConfig.StorehouseOutInfo,
  5870. OverCount: flush_count,
  5871. OperateTime: time.Now().Unix(),
  5872. }
  5873. service.CreateStockFlowOne(flow)
  5874. //退库数量增加
  5875. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5876. //出库数量减少
  5877. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5878. }
  5879. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5880. var flush_count int64
  5881. for _, it := range goodList {
  5882. flush_count += it.StockCount
  5883. }
  5884. //查询已出库数量
  5885. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5886. if prescribingNumber < dialysisInfo.Count {
  5887. //改变数量
  5888. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5889. }
  5890. if prescribingNumber >= dialysisInfo.Count {
  5891. //删除出库表
  5892. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5893. }
  5894. //更新库存
  5895. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5896. //更新基础库库存
  5897. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5898. }
  5899. }
  5900. }
  5901. }
  5902. //保存耗材出库
  5903. if goodOutConfig.IsOpen == 1 {
  5904. if item.Type == 3 {
  5905. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5906. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5907. good.Total = good.Total + f_count
  5908. service.UpdateGoodInfo(&good)
  5909. operation_time := time.Now().Unix()
  5910. creater := c.GetAdminUserInfo().AdminUser.Id
  5911. //创建退库单
  5912. timeStr := time.Now().Format("2006-01-02")
  5913. timeArr := strings.Split(timeStr, "-")
  5914. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5915. total = total + 1
  5916. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5917. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5918. cancelStock := models.CancelStock{
  5919. OrderNumber: orderNumber,
  5920. OperaTime: operation_time,
  5921. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5922. Creater: creater,
  5923. Ctime: time.Now().Unix(),
  5924. Status: 1,
  5925. ReturnTime: item.RecordDate,
  5926. Type: 1,
  5927. StorehouseId: houseConfig.StorehouseOutInfo,
  5928. IsCheck: 1,
  5929. }
  5930. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5931. if msgerrkonde == gorm.ErrRecordNotFound {
  5932. service.AddSigleCancelStock(&cancelStock)
  5933. }
  5934. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5935. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5936. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5937. //查询该耗材是否出库
  5938. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5939. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5940. deaerler, _ := service.GetDealerById(info.Dealer)
  5941. var total_count int64
  5942. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5943. total_count += count
  5944. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5945. var flush_count int64
  5946. for _, it := range goodList {
  5947. flush_count += it.StockCount
  5948. }
  5949. fmt.Println("历史出库数据", info.Count)
  5950. fmt.Println("出库数量", total_count)
  5951. if info.ID > 0 {
  5952. cancelStockInfo := models.CancelStockInfo{
  5953. GoodId: item.ProjectId,
  5954. CancelStockId: cancel.ID,
  5955. GoodTypeId: good.GoodTypeId,
  5956. Count: prescribingNumber,
  5957. Price: info.Price,
  5958. Total: 0,
  5959. ProductDate: info.ProductDate,
  5960. ExpiryDate: info.ExpiryDate,
  5961. Ctime: time.Now().Unix(),
  5962. Status: 1,
  5963. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5964. OrderNumber: cancel.OrderNumber,
  5965. Type: 0,
  5966. Dealer: deaerler.DealerName,
  5967. Manufacturer: manufacturer.ManufacturerName,
  5968. Number: info.Number,
  5969. RegisterAccount: "",
  5970. Remark: "",
  5971. WarehouseInfoId: info.WarehouseInfotId,
  5972. PatientId: info.PatientId,
  5973. RecordDate: info.SysRecordTime,
  5974. StorehouseId: houseConfig.StorehouseOutInfo,
  5975. IsCheck: 1,
  5976. }
  5977. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5978. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5979. //查询出库数量
  5980. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5981. //出库数据 大于 退库数量
  5982. if len(list) > 0 {
  5983. for _, it := range list {
  5984. //回退库存
  5985. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5986. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5987. var flush_count_one int64
  5988. for _, it := range goodList {
  5989. flush_count_one += it.StockCount
  5990. }
  5991. //查询该批次是否有退库数据
  5992. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5993. creater := c.GetAdminUserInfo().AdminUser.Id
  5994. flow := models.VmStockFlow{
  5995. WarehousingId: it.WarehouseInfotId,
  5996. GoodId: it.GoodId,
  5997. Number: it.Number,
  5998. LicenseNumber: it.LicenseNumber,
  5999. Count: it.Count,
  6000. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6001. PatientId: it.PatientId,
  6002. SystemTime: it.SysRecordTime,
  6003. ConsumableType: 7,
  6004. IsSys: 0,
  6005. WarehousingOrder: "",
  6006. WarehouseOutId: it.WarehouseOutId,
  6007. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6008. IsEdit: 0,
  6009. CancelStockId: cancel.ID,
  6010. CancelOrderNumber: cancel.OrderNumber,
  6011. Manufacturer: manufacturer.ID,
  6012. Dealer: 0,
  6013. Creator: creater,
  6014. UpdateCreator: 0,
  6015. Status: 1,
  6016. Ctime: time.Now().Unix(),
  6017. Mtime: 0,
  6018. Price: it.Price,
  6019. WarehousingDetailId: it.WarehouseInfotId,
  6020. WarehouseOutDetailId: it.ID,
  6021. CancelOutDetailId: cancelInfo.ID,
  6022. ProductDate: it.ProductDate,
  6023. ExpireDate: it.ExpiryDate,
  6024. StorehouseId: houseConfig.StorehouseOutInfo,
  6025. OverCount: flush_count_one,
  6026. }
  6027. service.CreateStockFlowOne(flow)
  6028. //if flow.ID > 0 {
  6029. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6030. //}
  6031. }
  6032. }
  6033. //flow := models.VmStockFlow{
  6034. // WarehousingId: info.WarehouseInfotId,
  6035. // GoodId: item.ProjectId,
  6036. // Number: info.Number,
  6037. // LicenseNumber: info.LicenseNumber,
  6038. // Count: prescribingNumber,
  6039. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6040. // PatientId: item.PatientId,
  6041. // SystemTime: info.SysRecordTime,
  6042. // ConsumableType: 7,
  6043. // IsSys: 0,
  6044. // WarehousingOrder: "",
  6045. // WarehouseOutId: info.WarehouseOutId,
  6046. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6047. // IsEdit: 0,
  6048. // CancelStockId: cancel.ID,
  6049. // CancelOrderNumber: cancel.OrderNumber,
  6050. // Manufacturer: manufacturer.ID,
  6051. // Dealer: 0,
  6052. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6053. // UpdateCreator: 0,
  6054. // Status: 1,
  6055. // Ctime: time.Now().Unix(),
  6056. // Mtime: 0,
  6057. // Price: info.Price,
  6058. // WarehousingDetailId: info.WarehouseInfotId,
  6059. // WarehouseOutDetailId: info.ID,
  6060. // CancelOutDetailId: cancelInfo.ID,
  6061. // ProductDate: info.ProductDate,
  6062. // ExpireDate: info.ExpiryDate,
  6063. // StorehouseId: houseConfig.StorehouseOutInfo,
  6064. // OverCount: flush_count,
  6065. //}
  6066. //service.CreateStockFlowOne(flow)
  6067. //退库数量增加
  6068. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6069. //出库数量减少
  6070. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6071. //查询已出库数量
  6072. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6073. if prescribingNumber < dialysisInfo.Count {
  6074. //改变数量
  6075. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6076. }
  6077. if prescribingNumber >= dialysisInfo.Count {
  6078. //删除出库表
  6079. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6080. }
  6081. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6082. var flush_count_one int64
  6083. for _, it := range goodList {
  6084. flush_count_one += it.StockCount
  6085. }
  6086. //更新库存
  6087. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6088. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6089. //更新基础库库存
  6090. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6091. }
  6092. }
  6093. }
  6094. }
  6095. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6096. fmt.Println(err)
  6097. }
  6098. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6099. fmt.Println(err)
  6100. if len(advices) > 0 {
  6101. for _, item := range advices {
  6102. redis := service.RedisClient()
  6103. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6104. redis.Set(keyFive, "", time.Second)
  6105. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6106. redis.Set(keyOne, "", time.Second)
  6107. redis.Close()
  6108. }
  6109. }
  6110. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6111. if len(advices) > 0 {
  6112. for _, item := range advices {
  6113. creater := c.GetAdminUserInfo().AdminUser.Id
  6114. service.DrugAutoAddCancelInfo(item, creater)
  6115. }
  6116. }
  6117. } else {
  6118. if drugOutConfig.IsOpen == 1 {
  6119. if len(advices) > 0 {
  6120. for _, item := range advices {
  6121. creater := c.GetAdminUserInfo().AdminUser.Id
  6122. service.DrugAutoAddCancelInfo(item, creater)
  6123. }
  6124. }
  6125. } else {
  6126. if len(advices) > 0 {
  6127. for _, item := range advices {
  6128. creater := c.GetAdminUserInfo().AdminUser.Id
  6129. service.DrugAutoAddCancelInfo(item, creater)
  6130. }
  6131. }
  6132. }
  6133. }
  6134. c.ServeSuccessJSON(map[string]interface{}{
  6135. "msg": "删除成功",
  6136. })
  6137. return
  6138. }
  6139. func (c *HisApiController) DeleteDoctorAdvice() {
  6140. id, _ := c.GetInt64("id")
  6141. advice, _ := service.GetHisDoctorAdvicesById(id)
  6142. ////同步到自备药
  6143. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6144. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6145. if selfPrescriptionOpen.IsOpen == 1 {
  6146. db := service.XTWriteDB()
  6147. tx := db.Begin()
  6148. defer func() {
  6149. if r := recover(); r != nil {
  6150. tx.Rollback()
  6151. } else {
  6152. tx.Commit()
  6153. }
  6154. }()
  6155. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6156. var total_count int64
  6157. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6158. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6159. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6160. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6161. }
  6162. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6163. total_count += prescribingNumberSeven
  6164. }
  6165. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6166. total_count += prescribingNumberSeven
  6167. }
  6168. timeStr := time.Now().Format("2006-01-02")
  6169. timeArr := strings.Split(timeStr, "-")
  6170. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6171. total = total + 1
  6172. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6173. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6174. number = number + total
  6175. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6176. operation_time := time.Now().Unix()
  6177. creater := c.GetAdminUserInfo().AdminUser.Id
  6178. //创建一个出库单
  6179. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6180. WarehouseOutOrderNumber: warehousing_out_order,
  6181. OperationTime: operation_time,
  6182. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6183. Creater: creater,
  6184. Ctime: time.Now().Unix(),
  6185. Status: 1,
  6186. WarehouseOutTime: advice.AdviceDate,
  6187. Type: 0,
  6188. PatientId: advice.PatientId,
  6189. IsCheck: 1,
  6190. }
  6191. //查询今日是否有出库数据
  6192. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6193. if lastWarehouseOut.ID == 0 {
  6194. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6195. }
  6196. //出库
  6197. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6198. WarehouseOutId: lastWarehouseOut.ID,
  6199. WarehouseOutOrderNumber: warehousing_out_order,
  6200. DrugId: advice.DrugId,
  6201. Count: total_count,
  6202. Price: 0,
  6203. TotalPrice: 0,
  6204. Status: 1,
  6205. Ctime: advice.AdviceDate,
  6206. Mtime: advice.AdviceDate,
  6207. Remark: "",
  6208. OrgId: advice.UserOrgId,
  6209. Type: 0,
  6210. Manufacturer: selfBasedrug.Manufacturer,
  6211. Dealer: selfBasedrug.Dealer,
  6212. RetailPrice: 0,
  6213. RetailTotalPrice: 0,
  6214. CountUnit: advice.PrescribingNumberUnit,
  6215. ExpiryDate: 0,
  6216. ProductDate: 0,
  6217. Number: "",
  6218. BatchNumber: "",
  6219. IsSys: 0,
  6220. WarehouseInfoId: 0,
  6221. AdminUserId: 0,
  6222. StockCount: "",
  6223. IsCheck: 1,
  6224. SysRecordTime: advice.AdviceDate,
  6225. PatientId: advice.PatientId,
  6226. AdviceId: advice.ID,
  6227. ClassType: "",
  6228. }
  6229. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6230. for _, it := range warehousingOutInfo {
  6231. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6232. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6233. //出库逻辑
  6234. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6235. //查询剩余库存
  6236. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6237. var sum_count int64
  6238. for _, its := range stockInfo {
  6239. if its.MaxUnit == medical.MaxUnit {
  6240. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6241. }
  6242. sum_count += its.StockMaxNumber + its.StockMinNumber
  6243. }
  6244. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6245. }
  6246. }
  6247. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6248. //已收费和已发药的限制逻辑
  6249. isCharge := false
  6250. isMedicine := false
  6251. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6252. //获取今天该患者所有处方,判断是否发药或者收费
  6253. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6254. //for _, item := range new_prescriptions {
  6255. if new_prescription.IsMedicine == 1 {
  6256. isMedicine = true
  6257. }
  6258. //}
  6259. for _, item := range new_prescriptions {
  6260. if item.OrderStatus == 4 {
  6261. isCharge = true
  6262. }
  6263. }
  6264. if isMedicine {
  6265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6266. return
  6267. }
  6268. if isCharge {
  6269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6270. return
  6271. }
  6272. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6273. for _, item := range advices {
  6274. if item.IsMedicine == 1 {
  6275. isMedicine = true
  6276. }
  6277. }
  6278. if isMedicine {
  6279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6280. return
  6281. }
  6282. if new_prescription.ID > 0 {
  6283. if new_prescription.OrderStatus == 2 {
  6284. isCharge = true
  6285. }
  6286. }
  6287. if isCharge {
  6288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6289. return
  6290. }
  6291. //已收费和已发药的限制逻辑
  6292. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6293. redis := service.RedisClient()
  6294. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6295. redis.Set(keyFive, "", time.Second)
  6296. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6297. redis.Set(keyOne, "", time.Second)
  6298. defer redis.Close()
  6299. if err == nil {
  6300. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6301. //查询是否在处方中出库
  6302. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6303. if openConfig.IsOpen != 1 {
  6304. //判断该医嘱是否执行了
  6305. if advice.ExecutionState == 1 {
  6306. creater := c.GetAdminUserInfo().AdminUser.Id
  6307. service.DrugAutoAddCancelInfo(&advice, creater)
  6308. }
  6309. }
  6310. //开启保存处方扣减功能
  6311. if openConfig.IsOpen == 1 {
  6312. creater := c.GetAdminUserInfo().AdminUser.Id
  6313. service.DrugAutoAddCancelInfo(&advice, creater)
  6314. }
  6315. } else {
  6316. if drugOutConfig.IsOpen == 1 {
  6317. //查询是否在处方中出库
  6318. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6319. if openConfig.IsOpen != 1 {
  6320. //判断该医嘱是否执行了
  6321. if advice.ExecutionState == 1 {
  6322. creater := c.GetAdminUserInfo().AdminUser.Id
  6323. service.DrugAutoAddCancelInfo(&advice, creater)
  6324. }
  6325. }
  6326. //开启保存处方扣减功能
  6327. if openConfig.IsOpen == 1 {
  6328. creater := c.GetAdminUserInfo().AdminUser.Id
  6329. service.DrugAutoAddCancelInfo(&advice, creater)
  6330. }
  6331. } else {
  6332. //判断该医嘱是否执行了
  6333. if advice.ExecutionState == 1 {
  6334. creater := c.GetAdminUserInfo().AdminUser.Id
  6335. service.DrugAutoAddCancelInfo(&advice, creater)
  6336. }
  6337. }
  6338. }
  6339. c.ServeSuccessJSON(map[string]interface{}{
  6340. "msg": "删除成功",
  6341. })
  6342. return
  6343. } else {
  6344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6345. return
  6346. }
  6347. }
  6348. func (c *HisApiController) DeleteProject() {
  6349. id, _ := c.GetInt64("id")
  6350. adminInfo := c.GetAdminUserInfo()
  6351. project, _ := service.GetHisProjectByID(id)
  6352. // var consumable models.DialysisBeforePrepare
  6353. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6354. //耗材保存处方出库
  6355. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6356. isCharge := false
  6357. isMedicine := false
  6358. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6359. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6360. for _, item := range new_prescriptions {
  6361. if item.IsMedicine == 1 {
  6362. isMedicine = true
  6363. }
  6364. }
  6365. for _, item := range new_prescriptions {
  6366. if item.OrderStatus == 4 {
  6367. isCharge = true
  6368. }
  6369. }
  6370. if isMedicine {
  6371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6372. return
  6373. }
  6374. if isCharge {
  6375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6376. return
  6377. }
  6378. if new_prescription.ID > 0 {
  6379. if new_prescription.OrderStatus == 2 {
  6380. isCharge = true
  6381. }
  6382. }
  6383. if isCharge {
  6384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6385. return
  6386. }
  6387. service.DeletePrintInfo(id)
  6388. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6389. label.Status = 0
  6390. service.CreateHisLabelRecordTwo(&label)
  6391. fmt.Println(goodOutConfig.IsOpen)
  6392. if goodOutConfig.IsOpen != 1 {
  6393. if stockConfig.IsOpen == 1 {
  6394. if project.Type == 2 {
  6395. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6396. fmt.Println(err)
  6397. }
  6398. if project.Type == 3 && project.IsOut == 1 {
  6399. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6400. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6401. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6402. operation_time := time.Now().Unix()
  6403. creater := adminInfo.AdminUser.Id
  6404. //创建退库单
  6405. timeStr := time.Now().Format("2006-01-02")
  6406. timeArr := strings.Split(timeStr, "-")
  6407. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6408. total = total + 1
  6409. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6410. cancelStock := models.CancelStock{
  6411. OrderNumber: orderNumber,
  6412. OperaTime: operation_time,
  6413. OrgId: adminInfo.CurrentOrgId,
  6414. Creater: creater,
  6415. Ctime: time.Now().Unix(),
  6416. Status: 1,
  6417. ReturnTime: project.RecordDate,
  6418. Type: 1,
  6419. StorehouseId: houseConfig.StorehouseOutInfo,
  6420. IsCheck: 1,
  6421. }
  6422. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6423. if msgerrkonde == gorm.ErrRecordNotFound {
  6424. service.AddSigleCancelStock(&cancelStock)
  6425. }
  6426. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6427. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6428. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6429. //查询是否有出库
  6430. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6431. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6432. deaerler, _ := service.GetDealerById(info.Dealer)
  6433. if info.ID > 0 {
  6434. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6435. if info.Count >= prescribingNumber {
  6436. cancelStockInfo := models.CancelStockInfo{
  6437. GoodId: project.ProjectId,
  6438. CancelStockId: cancel.ID,
  6439. GoodTypeId: good.GoodTypeId,
  6440. Count: prescribingNumber,
  6441. Price: info.Price,
  6442. Total: 0,
  6443. ProductDate: info.ProductDate,
  6444. ExpiryDate: info.ExpiryDate,
  6445. Ctime: time.Now().Unix(),
  6446. Status: 1,
  6447. OrgId: adminInfo.CurrentOrgId,
  6448. OrderNumber: cancel.OrderNumber,
  6449. Type: 0,
  6450. Dealer: deaerler.DealerName,
  6451. Manufacturer: manufacturer.ManufacturerName,
  6452. Number: info.Number,
  6453. RegisterAccount: "",
  6454. Remark: "",
  6455. WarehouseInfoId: info.WarehouseInfotId,
  6456. PatientId: info.PatientId,
  6457. RecordDate: info.SysRecordTime,
  6458. StorehouseId: houseConfig.StorehouseOutInfo,
  6459. IsCheck: 1,
  6460. }
  6461. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6462. //回退库存
  6463. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6464. //退库数量增加
  6465. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6466. //出库数量减少
  6467. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6468. }
  6469. if info.Count < prescribingNumber {
  6470. cancelStockInfo := models.CancelStockInfo{
  6471. GoodId: project.ProjectId,
  6472. CancelStockId: cancel.ID,
  6473. GoodTypeId: good.GoodTypeId,
  6474. Count: info.Count,
  6475. Price: info.Price,
  6476. Total: 0,
  6477. ProductDate: info.ProductDate,
  6478. ExpiryDate: info.ExpiryDate,
  6479. Ctime: time.Now().Unix(),
  6480. Status: 1,
  6481. OrgId: adminInfo.CurrentOrgId,
  6482. OrderNumber: cancel.OrderNumber,
  6483. Type: 0,
  6484. Dealer: deaerler.DealerName,
  6485. Manufacturer: manufacturer.ManufacturerName,
  6486. Number: info.Number,
  6487. RegisterAccount: "",
  6488. Remark: "",
  6489. WarehouseInfoId: info.WarehouseInfotId,
  6490. PatientId: info.PatientId,
  6491. RecordDate: info.SysRecordTime,
  6492. StorehouseId: houseConfig.StorehouseOutInfo,
  6493. IsCheck: 1,
  6494. }
  6495. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6496. //回退库存
  6497. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6498. //退库数量增加
  6499. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6500. //出库数量减少
  6501. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6502. }
  6503. //查询剩余库存
  6504. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6505. var over_count int64
  6506. for _, it := range goodList {
  6507. over_count += it.StockCount
  6508. }
  6509. //出库数据 大于 退库数量
  6510. if info.Count >= prescribingNumber {
  6511. flow := models.VmStockFlow{
  6512. WarehousingId: info.WarehouseInfotId,
  6513. GoodId: project.ProjectId,
  6514. Number: info.Number,
  6515. LicenseNumber: info.LicenseNumber,
  6516. Count: prescribingNumber,
  6517. UserOrgId: adminInfo.CurrentOrgId,
  6518. PatientId: project.PatientId,
  6519. SystemTime: info.SysRecordTime,
  6520. ConsumableType: 7,
  6521. IsSys: 0,
  6522. WarehousingOrder: "",
  6523. WarehouseOutId: info.WarehouseOutId,
  6524. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6525. IsEdit: 0,
  6526. CancelStockId: cancel.ID,
  6527. CancelOrderNumber: cancel.OrderNumber,
  6528. Manufacturer: manufacturer.ID,
  6529. Dealer: 0,
  6530. Creator: adminInfo.AdminUser.Id,
  6531. UpdateCreator: 0,
  6532. Status: 1,
  6533. Ctime: time.Now().Unix(),
  6534. Mtime: 0,
  6535. Price: info.Price,
  6536. WarehousingDetailId: info.WarehouseInfotId,
  6537. WarehouseOutDetailId: info.ID,
  6538. CancelOutDetailId: cancelInfo.ID,
  6539. ProductDate: info.ProductDate,
  6540. ExpireDate: info.ExpiryDate,
  6541. StorehouseId: houseConfig.StorehouseOutInfo,
  6542. OverCount: over_count,
  6543. OperateTime: time.Now().Unix(),
  6544. }
  6545. service.CreateStockFlowOne(flow)
  6546. }
  6547. //出库数据小于退库数据
  6548. if info.Count < prescribingNumber {
  6549. flow := models.VmStockFlow{
  6550. WarehousingId: info.WarehouseInfotId,
  6551. GoodId: project.ProjectId,
  6552. Number: info.Number,
  6553. LicenseNumber: info.LicenseNumber,
  6554. Count: info.Count,
  6555. UserOrgId: adminInfo.CurrentOrgId,
  6556. PatientId: project.PatientId,
  6557. SystemTime: info.SysRecordTime,
  6558. ConsumableType: 7,
  6559. IsSys: 0,
  6560. WarehousingOrder: "",
  6561. WarehouseOutId: info.WarehouseOutId,
  6562. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6563. IsEdit: 0,
  6564. CancelStockId: cancel.ID,
  6565. CancelOrderNumber: cancel.OrderNumber,
  6566. Manufacturer: manufacturer.ID,
  6567. Dealer: 0,
  6568. Creator: adminInfo.AdminUser.Id,
  6569. UpdateCreator: 0,
  6570. Status: 1,
  6571. Ctime: time.Now().Unix(),
  6572. Mtime: 0,
  6573. Price: info.Price,
  6574. WarehousingDetailId: info.WarehouseInfotId,
  6575. WarehouseOutDetailId: info.ID,
  6576. CancelOutDetailId: cancelInfo.ID,
  6577. ProductDate: info.ProductDate,
  6578. ExpireDate: info.ExpiryDate,
  6579. StorehouseId: houseConfig.StorehouseOutInfo,
  6580. OverCount: over_count,
  6581. OperateTime: time.Now().Unix(),
  6582. }
  6583. service.CreateStockFlowOne(flow)
  6584. }
  6585. //查询已出库数量
  6586. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6587. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6588. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6589. if prescribingNumber < dialysisInfo.Count {
  6590. //改变数量
  6591. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6592. }
  6593. if prescribingNumber >= dialysisInfo.Count {
  6594. //删除出库表
  6595. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6596. }
  6597. //更新剩余库存
  6598. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6599. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6600. var total_count_one int64
  6601. for _, it := range stockList {
  6602. total_count_one += it.StockCount
  6603. }
  6604. //基础库插入数据
  6605. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6606. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6607. var flush_count int64
  6608. for _, it := range goodListOne {
  6609. flush_count += it.StockCount
  6610. }
  6611. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6612. if errs != nil {
  6613. goodErrcode := models.XtGoodErrcode{
  6614. UserOrgId: project.UserOrgId,
  6615. Errcode: "手动出库更新剩余出库失败",
  6616. GoodId: project.ProjectId,
  6617. Status: 1,
  6618. Ctime: time.Now().Unix(),
  6619. Mtime: 0,
  6620. Count: 0,
  6621. StockCount: 0,
  6622. Creater: creater,
  6623. BatchNumberId: 0,
  6624. WarehouseOutId: 0,
  6625. }
  6626. service.CreateGoodErrcode(goodErrcode)
  6627. }
  6628. }
  6629. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6630. fmt.Println(err)
  6631. } else {
  6632. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6633. fmt.Println(err)
  6634. }
  6635. } else {
  6636. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6637. fmt.Println(err)
  6638. }
  6639. }
  6640. //保存处方出库
  6641. if goodOutConfig.IsOpen == 1 {
  6642. if project.Type == 3 {
  6643. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6644. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6645. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6646. operation_time := time.Now().Unix()
  6647. creater := adminInfo.AdminUser.Id
  6648. //创建退库单
  6649. timeStr := time.Now().Format("2006-01-02")
  6650. timeArr := strings.Split(timeStr, "-")
  6651. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6652. total = total + 1
  6653. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6654. cancelStock := models.CancelStock{
  6655. OrderNumber: orderNumber,
  6656. OperaTime: operation_time,
  6657. OrgId: adminInfo.CurrentOrgId,
  6658. Creater: creater,
  6659. Ctime: time.Now().Unix(),
  6660. Status: 1,
  6661. ReturnTime: project.RecordDate,
  6662. Type: 1,
  6663. StorehouseId: houseConfig.StorehouseOutInfo,
  6664. IsCheck: 1,
  6665. }
  6666. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6667. if msgerrkonde == gorm.ErrRecordNotFound {
  6668. service.AddSigleCancelStock(&cancelStock)
  6669. }
  6670. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6671. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6672. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6673. //获取出库数据
  6674. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6675. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6676. deaerler, _ := service.GetDealerById(info.Dealer)
  6677. if info.ID > 0 {
  6678. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6679. if info.Count >= prescribingNumber {
  6680. cancelStockInfo := models.CancelStockInfo{
  6681. GoodId: project.ProjectId,
  6682. CancelStockId: cancel.ID,
  6683. GoodTypeId: good.GoodTypeId,
  6684. Count: prescribingNumber,
  6685. Price: info.Price,
  6686. Total: 0,
  6687. ProductDate: info.ProductDate,
  6688. ExpiryDate: info.ExpiryDate,
  6689. Ctime: time.Now().Unix(),
  6690. Status: 1,
  6691. OrgId: adminInfo.CurrentOrgId,
  6692. OrderNumber: cancel.OrderNumber,
  6693. Type: 0,
  6694. Dealer: deaerler.DealerName,
  6695. Manufacturer: manufacturer.ManufacturerName,
  6696. Number: info.Number,
  6697. RegisterAccount: "",
  6698. Remark: "",
  6699. WarehouseInfoId: info.WarehouseInfotId,
  6700. PatientId: info.PatientId,
  6701. RecordDate: info.SysRecordTime,
  6702. StorehouseId: houseConfig.StorehouseOutInfo,
  6703. IsCheck: 1,
  6704. }
  6705. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6706. //退库数量增加
  6707. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6708. //出库数量减少
  6709. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6710. }
  6711. if info.Count < prescribingNumber {
  6712. cancelStockInfo := models.CancelStockInfo{
  6713. GoodId: project.ProjectId,
  6714. CancelStockId: cancel.ID,
  6715. GoodTypeId: good.GoodTypeId,
  6716. Count: prescribingNumber,
  6717. Price: info.Price,
  6718. Total: 0,
  6719. ProductDate: info.ProductDate,
  6720. ExpiryDate: info.ExpiryDate,
  6721. Ctime: time.Now().Unix(),
  6722. Status: 1,
  6723. OrgId: adminInfo.CurrentOrgId,
  6724. OrderNumber: cancel.OrderNumber,
  6725. Type: 0,
  6726. Dealer: deaerler.DealerName,
  6727. Manufacturer: manufacturer.ManufacturerName,
  6728. Number: info.Number,
  6729. RegisterAccount: "",
  6730. Remark: "",
  6731. WarehouseInfoId: info.WarehouseInfotId,
  6732. PatientId: info.PatientId,
  6733. RecordDate: info.SysRecordTime,
  6734. StorehouseId: houseConfig.StorehouseOutInfo,
  6735. IsCheck: 1,
  6736. }
  6737. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6738. //回退库存
  6739. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6740. }
  6741. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6742. var over_count int64
  6743. for _, it := range goodList {
  6744. over_count += it.StockCount
  6745. }
  6746. //查询出库数量
  6747. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6748. //出库数据 大于 退库数量
  6749. if len(list) > 0 {
  6750. for _, it := range list {
  6751. //回退库存
  6752. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6753. //退库数量增加
  6754. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6755. //出库数量减少
  6756. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6757. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6758. var over_count_one int64
  6759. for _, it := range goodList {
  6760. over_count_one += it.StockCount
  6761. }
  6762. //查询该批次是否有退库数据
  6763. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6764. flow := models.VmStockFlow{
  6765. WarehousingId: it.WarehouseInfotId,
  6766. GoodId: it.GoodId,
  6767. Number: it.Number,
  6768. LicenseNumber: it.LicenseNumber,
  6769. Count: it.Count,
  6770. UserOrgId: adminInfo.CurrentOrgId,
  6771. PatientId: it.PatientId,
  6772. SystemTime: it.SysRecordTime,
  6773. ConsumableType: 7,
  6774. IsSys: 0,
  6775. WarehousingOrder: "",
  6776. WarehouseOutId: it.WarehouseOutId,
  6777. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6778. IsEdit: 0,
  6779. CancelStockId: cancel.ID,
  6780. CancelOrderNumber: cancel.OrderNumber,
  6781. Manufacturer: manufacturer.ID,
  6782. Dealer: 0,
  6783. Creator: adminInfo.AdminUser.Id,
  6784. UpdateCreator: 0,
  6785. Status: 1,
  6786. Ctime: time.Now().Unix(),
  6787. Mtime: 0,
  6788. Price: it.Price,
  6789. WarehousingDetailId: it.WarehouseInfotId,
  6790. WarehouseOutDetailId: it.ID,
  6791. CancelOutDetailId: cancelInfo.ID,
  6792. ProductDate: it.ProductDate,
  6793. ExpireDate: it.ExpiryDate,
  6794. StorehouseId: houseConfig.StorehouseOutInfo,
  6795. OverCount: over_count_one,
  6796. OperateTime: time.Now().Unix(),
  6797. }
  6798. service.CreateStockFlowOne(flow)
  6799. }
  6800. }
  6801. //查询已出库数量
  6802. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6803. if prescribingNumber < dialysisInfo.Count {
  6804. //改变数量
  6805. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6806. }
  6807. if prescribingNumber >= dialysisInfo.Count {
  6808. //删除出库表
  6809. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6810. }
  6811. //更新剩余库存
  6812. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6813. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6814. var total_count_one int64
  6815. for _, it := range stockList {
  6816. total_count_one += it.StockCount
  6817. }
  6818. //基础库插入数据
  6819. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6820. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6821. var flush_count int64
  6822. for _, it := range goodListOne {
  6823. flush_count += it.StockCount
  6824. }
  6825. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6826. if errs != nil {
  6827. goodErrcode := models.XtGoodErrcode{
  6828. UserOrgId: project.UserOrgId,
  6829. Errcode: "手动出库更新剩余出库失败",
  6830. GoodId: project.ProjectId,
  6831. Status: 1,
  6832. Ctime: time.Now().Unix(),
  6833. Mtime: 0,
  6834. Count: 0,
  6835. StockCount: 0,
  6836. Creater: creater,
  6837. BatchNumberId: 0,
  6838. WarehouseOutId: 0,
  6839. }
  6840. service.CreateGoodErrcode(goodErrcode)
  6841. }
  6842. }
  6843. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6844. fmt.Println(err)
  6845. } else {
  6846. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6847. fmt.Println(err)
  6848. }
  6849. }
  6850. c.ServeSuccessJSON(map[string]interface{}{
  6851. "msg": "删除成功",
  6852. })
  6853. return
  6854. }
  6855. func (c *HisApiController) CreateHisAdditionalCharge() {
  6856. his_patient_id, _ := c.GetInt64("his_patient_id")
  6857. patient_id, _ := c.GetInt64("patient_id")
  6858. record_date := c.GetString("record_date")
  6859. timeLayout := "2006-01-02"
  6860. loc, _ := time.LoadLocation("Local")
  6861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6862. if err != nil {
  6863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6864. return
  6865. }
  6866. adminInfo := c.GetAdminUserInfo()
  6867. recordDateTime := theTime.Unix()
  6868. dataBody := make(map[string]interface{}, 0)
  6869. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6870. if err != nil {
  6871. utils.ErrorLog(err.Error())
  6872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6873. return
  6874. }
  6875. var additions []*models.HisAdditionalCharge
  6876. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6877. additions, _ := dataBody["addition"].([]interface{})
  6878. if len(additions) > 0 {
  6879. for _, item := range additions {
  6880. items := item.(map[string]interface{})
  6881. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6882. utils.ErrorLog("item_id")
  6883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6884. return
  6885. }
  6886. item_id := int64(items["item_id"].(float64))
  6887. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6888. utils.ErrorLog("item_name")
  6889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6890. return
  6891. }
  6892. item_name := items["item_name"].(string)
  6893. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6894. utils.ErrorLog("price")
  6895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6896. return
  6897. }
  6898. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6899. ctime := time.Now().Unix()
  6900. additional := &models.HisAdditionalCharge{
  6901. PatientId: patient_id,
  6902. HisPatientId: his_patient_id,
  6903. UserOrgId: adminInfo.CurrentOrgId,
  6904. RecordDate: recordDateTime,
  6905. CreatedTime: ctime,
  6906. UpdatedTime: ctime,
  6907. Modifier: adminInfo.AdminUser.Id,
  6908. Creator: adminInfo.AdminUser.Id,
  6909. Price: price,
  6910. ItemName: item_name,
  6911. ItemId: item_id,
  6912. Status: 1,
  6913. }
  6914. additions = append(additions, additional)
  6915. }
  6916. }
  6917. }
  6918. for _, item := range additions {
  6919. service.CreateAddtionalCharge(item)
  6920. }
  6921. c.ServeSuccessJSON(map[string]interface{}{
  6922. "msg": "创建成功",
  6923. })
  6924. }
  6925. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6926. blood_fat := c.GetString("blood_fat")
  6927. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6928. blood_sugar := c.GetString("blood_sugar")
  6929. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6930. chief_conplaint := c.GetString("chief_conplaint")
  6931. dbp := c.GetString("dbp")
  6932. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6933. delivery_way, _ := c.GetInt64("delivery_way")
  6934. diagnostic := c.GetString("diagnostic")
  6935. family_history := c.GetString("family_history")
  6936. height := c.GetString("height")
  6937. history_of_present_illness := c.GetString("history_of_present_illness")
  6938. is_infect, _ := c.GetInt64("is_infect")
  6939. past_history := c.GetString("past_history")
  6940. patient_id, _ := c.GetInt64("patient_id")
  6941. his_patient_id, _ := c.GetInt64("his_patient_id")
  6942. personal_history := c.GetString("personal_history")
  6943. pulse := c.GetString("pulse")
  6944. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6945. sbp := c.GetString("sbp")
  6946. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6947. heightfloat, _ := strconv.ParseFloat(height, 64)
  6948. sicktype := c.GetString("sick_type")
  6949. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6950. symptom := c.GetString("symptom")
  6951. sick_date := c.GetString("sick_date")
  6952. temperatures := c.GetString("temperature")
  6953. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6954. record_date := c.GetString("record_date")
  6955. breathing := c.GetString("breathing")
  6956. doctor_advice := c.GetString("doctor_advice")
  6957. remark := c.GetString("remark")
  6958. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6959. sick, _ := c.GetInt64("sick")
  6960. diagnose, _ := c.GetInt64("diagnose")
  6961. //id, _ := c.GetInt64("id")
  6962. timeLayout := "2006-01-02"
  6963. loc, _ := time.LoadLocation("Local")
  6964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6965. allergic_history := c.GetString("allergic_history")
  6966. if err != nil {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6968. return
  6969. }
  6970. recordDateTime := theTime.Unix()
  6971. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6972. if err != nil {
  6973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6974. return
  6975. }
  6976. sickTimes := sickTime.Unix()
  6977. ctime := time.Now().Unix()
  6978. primary_disease := c.GetString("primary_disease")
  6979. confirm_failure_date := c.GetString("confirm_failure_date")
  6980. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6981. drug_allergy_history := c.GetString("drug_allergy_history")
  6982. physical_examination := c.GetString("physical_examination")
  6983. special_inspection := c.GetString("special_inspection")
  6984. lab_apparatus := c.GetString("lab_apparatus")
  6985. caseHistory := models.HisPatientCaseHistory{
  6986. HisPatientId: his_patient_id,
  6987. PatientId: patient_id,
  6988. Temperature: temperature,
  6989. BloodSugar: bloodsugarfloat,
  6990. Pulse: pulsefloat,
  6991. Sbp: sbpfloat,
  6992. Dbp: dbpfloat,
  6993. Height: heightfloat,
  6994. BloodFat: bloodfatfloat,
  6995. SickType: sick_type,
  6996. Symptom: symptom,
  6997. SickDate: sickTimes,
  6998. IsInfect: is_infect,
  6999. HistoryOfPresentIllness: history_of_present_illness,
  7000. PastHistory: past_history,
  7001. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7002. ChiefConplaint: chief_conplaint,
  7003. PersonalHistory: personal_history,
  7004. FamilyHistory: family_history,
  7005. Diagnostic: diagnostic,
  7006. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7007. Status: 1,
  7008. Ctime: ctime,
  7009. Mtime: ctime,
  7010. RecordDate: recordDateTime,
  7011. DeliveryWay: delivery_way,
  7012. Breathing: breathingfloat,
  7013. DoctorAdvice: doctor_advice,
  7014. Remark: remark,
  7015. Sick: sick,
  7016. Diagnose: diagnose,
  7017. AllergicHistory: allergic_history,
  7018. PrimaryDisease: primary_disease,
  7019. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7020. DrugAllergyHistory: drug_allergy_history,
  7021. PhysicalExamination: physical_examination,
  7022. SpecialInspection: special_inspection,
  7023. LabApparatus: lab_apparatus,
  7024. }
  7025. //查询该患者是否有病历
  7026. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7027. if errcodes == gorm.ErrRecordNotFound {
  7028. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7029. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7030. if err != nil {
  7031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7032. return
  7033. }
  7034. c.ServeSuccessJSON(map[string]interface{}{
  7035. "caseHistory": caseHistory,
  7036. "historyInfo": historyInfo,
  7037. })
  7038. return
  7039. } else if errcodes == nil {
  7040. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7041. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7042. if err != nil {
  7043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7044. return
  7045. }
  7046. c.ServeSuccessJSON(map[string]interface{}{
  7047. "caseHistory": caseHistory,
  7048. "historyInfo": historyInfo,
  7049. })
  7050. }
  7051. //查询该患者是否有病历
  7052. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7053. //if errcode == gorm.ErrRecordNotFound {
  7054. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7055. // if err != nil {
  7056. // c.ServeSuccessJSON(map[string]interface{}{
  7057. // "msg": "保存成功",
  7058. // })
  7059. // }
  7060. //} else if errcode == nil {
  7061. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7062. // return
  7063. //}
  7064. }
  7065. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7066. patient_id, _ := c.GetInt64("patient_id", 0)
  7067. adminUser := c.GetAdminUserInfo()
  7068. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7069. c.ServeSuccessJSON(map[string]interface{}{
  7070. "list": caseHistorys,
  7071. })
  7072. }
  7073. func (c *HisApiController) GetHisPatientCaseHistory() {
  7074. record_date, _ := c.GetInt64("record_date", 0)
  7075. patient_id, _ := c.GetInt64("patient_id", 0)
  7076. admin := c.GetAdminUserInfo()
  7077. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7078. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7079. c.ServeSuccessJSON(map[string]interface{}{
  7080. "info": info,
  7081. "case_history": case_history,
  7082. })
  7083. }
  7084. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7085. template_name := c.GetString("template_name")
  7086. template_remark := c.GetString("template_remark")
  7087. doctor := c.GetAdminUserInfo().AdminUser.Id
  7088. diagnostic := c.GetString("diagnostic")
  7089. chief_conplaint := c.GetString("chief_conplain")
  7090. history_of_present_illness := c.GetString("history_of_present_illness")
  7091. past_history := c.GetString("past_history")
  7092. personal_history := c.GetString("personal_history")
  7093. family_history := c.GetString("family_history")
  7094. user_name := c.GetString("user_name")
  7095. doctor_advice := c.GetString("doctor_advice")
  7096. remark := c.GetString("remark")
  7097. //record_date := c.GetString("record_date")
  7098. //fmt.Println("record_date--------",record_date)
  7099. //timeLayout := "2006-01-02"
  7100. //loc, _ := time.LoadLocation("Local")
  7101. //
  7102. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7103. //if err != nil {
  7104. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7105. // return
  7106. //}
  7107. //recordDateTime := theTime.Unix()
  7108. ctime := time.Now().Unix()
  7109. template := models.HisCaseHistoryTemplate{
  7110. HistoryOfPresentIllness: history_of_present_illness,
  7111. PastHistory: past_history,
  7112. ChiefConplaint: chief_conplaint,
  7113. PersonalHistory: personal_history,
  7114. FamilyHistory: family_history,
  7115. Diagnostic: diagnostic,
  7116. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7117. Status: 1,
  7118. Ctime: ctime,
  7119. Mtime: ctime,
  7120. RecordDate: time.Now().Unix(),
  7121. TemplateName: template_name,
  7122. TemplateRemark: template_remark,
  7123. Creator: doctor,
  7124. Modifier: doctor,
  7125. UserName: user_name,
  7126. DoctorAdvice: doctor_advice,
  7127. Remark: remark,
  7128. }
  7129. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7130. if err == nil {
  7131. c.ServeSuccessJSON(map[string]interface{}{
  7132. "msg": "保存成功",
  7133. })
  7134. } else {
  7135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7136. return
  7137. }
  7138. }
  7139. func (c *HisApiController) GetCaseHistoryTemplate() {
  7140. timeLayout := "2006-01-02"
  7141. loc, _ := time.LoadLocation("Local")
  7142. keyword := c.GetString("keyword")
  7143. start_time := c.GetString("start_time")
  7144. end_time := c.GetString("end_time")
  7145. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7146. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7147. admin := c.GetAdminUserInfo()
  7148. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7149. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7150. c.ServeSuccessJSON(map[string]interface{}{
  7151. "template": template,
  7152. //"history": history,
  7153. })
  7154. }
  7155. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7156. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7157. utils.ErrorLog("drug_name")
  7158. return enums.ErrorCodeParamWrong
  7159. }
  7160. adviceName, _ := json["drug_name"].(string)
  7161. if len(adviceName) == 0 {
  7162. utils.ErrorLog("len(advice_name) == 0")
  7163. return enums.ErrorCodeParamWrong
  7164. }
  7165. advice.AdviceName = adviceName
  7166. adviceDesc, _ := json["advice_desc"].(string)
  7167. advice.AdviceDesc = adviceDesc
  7168. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7169. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7170. advice.DrugSpec = drugSpec
  7171. }
  7172. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7173. remark, _ := json["remark"].(string)
  7174. advice.Remark = remark
  7175. }
  7176. if json["id"] == nil {
  7177. advice.DrugId = 0
  7178. } else {
  7179. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7180. drug_id := int64(json["id"].(float64))
  7181. advice.DrugId = drug_id
  7182. }
  7183. }
  7184. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7185. advice_id := int64(json["advice_id"].(float64))
  7186. advice.ID = advice_id
  7187. if advice.ID > 0 {
  7188. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7189. if err == nil {
  7190. if hisAdvice.ID > 0 {
  7191. advice.ExecutionTime = hisAdvice.ExecutionTime
  7192. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7193. advice.ExecutionState = hisAdvice.ExecutionState
  7194. advice.CheckTime = hisAdvice.CheckTime
  7195. advice.Checker = hisAdvice.Checker
  7196. advice.CheckState = hisAdvice.CheckState
  7197. advice.StartTime = hisAdvice.StartTime
  7198. advice.FeedetlSn = hisAdvice.FeedetlSn
  7199. }
  7200. }
  7201. }
  7202. }
  7203. //
  7204. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7205. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7206. // advice.ExecutionTime = execution_time
  7207. //}
  7208. //
  7209. //
  7210. //
  7211. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7212. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7213. // advice.ExecutionStaff = execution_staff
  7214. //}
  7215. //
  7216. //
  7217. //
  7218. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7219. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7220. // advice.ExecutionState = execution_state
  7221. //}
  7222. //
  7223. //
  7224. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7225. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7226. // advice.CheckTime = check_time
  7227. //}
  7228. //
  7229. //
  7230. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7231. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7232. // advice.CheckState = check_state
  7233. //}
  7234. //
  7235. //
  7236. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7237. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7238. // advice.Checker = checker
  7239. //}
  7240. //
  7241. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7242. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7243. // advice.StartTime = start_time
  7244. //}
  7245. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7246. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7247. advice.IsSelfDrug = is_self_drug
  7248. }
  7249. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7250. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7251. drug_way_count, _ := json["drug_way_count"].(string)
  7252. advice.DrugWayCount = drug_way_count
  7253. }
  7254. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7255. drugSpecUnit, _ := json["min_unit"].(string)
  7256. advice.DrugSpecUnit = drugSpecUnit
  7257. }
  7258. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7259. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7260. advice.SingleDose = singleDose
  7261. }
  7262. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7263. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7264. advice.SingleDoseUnit = singleDoseUnit
  7265. }
  7266. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7267. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7268. advice.PrescribingNumber = prescribingNumber
  7269. }
  7270. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7271. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7272. advice.PrescribingNumberUnit = prescribingNumberUnit
  7273. }
  7274. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7275. deliveryWay, _ := json["delivery_way"].(string)
  7276. advice.DeliveryWay = deliveryWay
  7277. }
  7278. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7279. executionFrequency, _ := json["execution_frequency"].(string)
  7280. advice.ExecutionFrequency = executionFrequency
  7281. }
  7282. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7283. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7284. advice.Price = price
  7285. }
  7286. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7287. med_list_codg, _ := json["medical_insurance_number"].(string)
  7288. advice.MedListCodg = med_list_codg
  7289. }
  7290. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7291. day := int64(json["day"].(float64))
  7292. advice.Day = day
  7293. }
  7294. return 0
  7295. }
  7296. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7297. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7298. id := int64(json["id"].(float64))
  7299. project.ID = id
  7300. historyProject, _ := service.GetHisProjectByID(id)
  7301. project.FeedetlSn = historyProject.FeedetlSn
  7302. }
  7303. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7304. project_id := int64(json["project_id"].(float64))
  7305. project.ProjectId = project_id
  7306. }
  7307. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7308. // price := int64(json["price"].(float64))
  7309. // formatInt_price := strconv.FormatInt(price, 10)
  7310. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7311. // project.Price = float_price
  7312. // }
  7313. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7314. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7315. project.Price = price
  7316. }
  7317. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7318. total, _ := json["total"].(string)
  7319. project.Count = total
  7320. }
  7321. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7322. medical_code, _ := json["medical_code"].(string)
  7323. project.MedListCodg = medical_code
  7324. }
  7325. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7326. single_dose, _ := json["single_dose"].(string)
  7327. project.SingleDose = single_dose
  7328. }
  7329. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7330. delivery_way, _ := json["delivery_way"].(string)
  7331. project.DeliveryWay = delivery_way
  7332. }
  7333. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7334. execution_frequency, _ := json["execution_frequency"].(string)
  7335. project.ExecutionFrequency = execution_frequency
  7336. }
  7337. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7338. remark, _ := json["remark"].(string)
  7339. project.Remark = remark
  7340. }
  7341. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7342. day, _ := json["number_days"].(string)
  7343. project.Day = day
  7344. }
  7345. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7346. unit, _ := json["unit"].(string)
  7347. project.Unit = unit
  7348. }
  7349. return 0
  7350. }
  7351. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7352. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7353. id := int64(json["id"].(float64))
  7354. historyAddtions, _ := service.GetHisAdditionByID(id)
  7355. additionalCharge.ID = id
  7356. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7357. }
  7358. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7359. item_id := int64(json["item_id"].(float64))
  7360. additionalCharge.ItemId = item_id
  7361. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7362. if config.ID > 0 {
  7363. if len(config.Code) > 0 {
  7364. additionalCharge.MedListCodg = config.Code
  7365. }
  7366. }
  7367. }
  7368. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7369. // price := int64(json["price"].(float64))
  7370. // formatInt_price := strconv.FormatInt(price, 10)
  7371. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7372. // additionalCharge.Price = float_price
  7373. // }
  7374. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7375. // price := int64(json["price"].(float64))
  7376. // formatInt_price := strconv.FormatInt(price, 10)
  7377. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7378. // additionalCharge.Price = float_price
  7379. //}
  7380. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7381. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7382. additionalCharge.Price = price
  7383. }
  7384. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7385. count, _ := json["count"].(string)
  7386. counts, _ := strconv.ParseInt(count, 10, 64)
  7387. additionalCharge.Count = counts
  7388. }
  7389. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7390. item_name, _ := json["item_name"].(string)
  7391. additionalCharge.ItemName = item_name
  7392. }
  7393. return 0
  7394. }
  7395. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7396. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7397. utils.ErrorLog("drug_name")
  7398. return enums.ErrorCodeParamWrong
  7399. }
  7400. adviceName, _ := json["drug_name"].(string)
  7401. if len(adviceName) == 0 {
  7402. utils.ErrorLog("len(advice_name) == 0")
  7403. return enums.ErrorCodeParamWrong
  7404. }
  7405. advice.AdviceName = adviceName
  7406. adviceDesc, _ := json["advice_desc"].(string)
  7407. advice.AdviceDesc = adviceDesc
  7408. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7409. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7410. advice.DrugSpec = drugSpec
  7411. }
  7412. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7413. remark, _ := json["remark"].(string)
  7414. advice.Remark = remark
  7415. }
  7416. if json["id"] == nil {
  7417. advice.DrugId = 0
  7418. } else {
  7419. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7420. drug_id := int64(json["id"].(float64))
  7421. advice.DrugId = drug_id
  7422. }
  7423. }
  7424. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7425. groupno := int64(json["groupno"].(float64))
  7426. advice.Groupno = groupno
  7427. }
  7428. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7429. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7430. advice.IsSelfDrug = is_self_drug
  7431. }
  7432. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7433. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7434. drug_way_count, _ := json["drug_way_count"].(string)
  7435. advice.DrugWayCount = drug_way_count
  7436. }
  7437. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7438. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7439. advice.HospApprFlag = hosp_appr_flag
  7440. }
  7441. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7442. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7443. advice.PrescribingNumber = prescribingNumber
  7444. }
  7445. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7446. // frequency_type := int64(json["frequency_type"].(float64))
  7447. // advice.FrequencyType = frequency_type
  7448. //}
  7449. //
  7450. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7451. // day_count := int64(json["day_count"].(float64))
  7452. // advice.DayCount = day_count
  7453. //}
  7454. //
  7455. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7456. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7457. // week_day, _ := json["week_day"].(string)
  7458. // advice.WeekDay = week_day
  7459. //}
  7460. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7461. drugSpecUnit, _ := json["min_unit"].(string)
  7462. advice.DrugSpecUnit = drugSpecUnit
  7463. }
  7464. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7465. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7466. advice.SingleDose = singleDose
  7467. }
  7468. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7469. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7470. advice.SingleDoseUnit = singleDoseUnit
  7471. }
  7472. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7473. deliveryWay, _ := json["delivery_way"].(string)
  7474. advice.DeliveryWay = deliveryWay
  7475. }
  7476. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7477. executionFrequency, _ := json["execution_frequency"].(string)
  7478. advice.ExecutionFrequency = executionFrequency
  7479. }
  7480. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7481. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7482. advice.Price = price
  7483. }
  7484. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7485. med_list_codg, _ := json["medical_insurance_number"].(string)
  7486. advice.MedListCodg = med_list_codg
  7487. }
  7488. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7489. day := int64(json["day"].(float64))
  7490. advice.Day = day
  7491. }
  7492. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7493. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7494. advice.PrescribingNumberUnit = prescribingNumberUnit
  7495. }
  7496. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7497. advice_id := int64(json["advice_id"].(float64))
  7498. advice.ID = advice_id
  7499. if advice.ID > 0 {
  7500. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7501. if err == nil {
  7502. if hisAdvice.ID > 0 {
  7503. advice.ExecutionTime = hisAdvice.ExecutionTime
  7504. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7505. advice.ExecutionState = hisAdvice.ExecutionState
  7506. advice.CheckTime = hisAdvice.CheckTime
  7507. advice.Checker = hisAdvice.Checker
  7508. advice.CheckState = hisAdvice.CheckState
  7509. advice.StartTime = hisAdvice.StartTime
  7510. advice.HospApprFlag = hisAdvice.HospApprFlag
  7511. advice.IsMedicine = hisAdvice.IsMedicine
  7512. if hisAdvice.UserOrgId == 10028 {
  7513. 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 {
  7514. advice.ExecutionTime = 0
  7515. advice.ExecutionStaff = 0
  7516. advice.ExecutionState = 2
  7517. advice.CheckTime = 0
  7518. advice.Checker = 0
  7519. advice.CheckState = 2
  7520. }
  7521. } else {
  7522. 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 {
  7523. advice.ExecutionTime = 0
  7524. advice.ExecutionStaff = 0
  7525. advice.ExecutionState = 2
  7526. advice.CheckTime = 0
  7527. advice.Checker = 0
  7528. advice.CheckState = 2
  7529. advice.UpdatedTime = time.Now().Unix()
  7530. }
  7531. }
  7532. //advice.Groupno = hisAdvice.Groupno
  7533. }
  7534. }
  7535. }
  7536. }
  7537. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7538. //
  7539. //if drugStockConfig.IsOpen == 1 {
  7540. //
  7541. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7542. // if advice.ID == 0 { //医嘱不存在
  7543. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7544. // drug.Total = drug.Total - advice.PrescribingNumber
  7545. // service.UpdateBaseDrugLib(&drug)
  7546. //
  7547. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7548. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7549. // drug.Total = drug.Total - num
  7550. // service.UpdateBaseDrugLib(&drug)
  7551. // }
  7552. //
  7553. // } else if advice.ID > 0 { //医嘱存在
  7554. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7555. // var num float64
  7556. //
  7557. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7558. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7559. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7560. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7561. // drug.Total = drug.Total + num
  7562. // service.UpdateBaseDrugLib(&drug)
  7563. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7564. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7565. // drug.Total = drug.Total - num
  7566. // service.UpdateBaseDrugLib(&drug)
  7567. // }
  7568. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7569. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7570. // if num2 > advice.PrescribingNumber {
  7571. // num = num2 - advice.PrescribingNumber
  7572. // drug.Total = drug.Total + num
  7573. // service.UpdateBaseDrugLib(&drug)
  7574. // } else if num2 < advice.PrescribingNumber {
  7575. // num = advice.PrescribingNumber - num2
  7576. // drug.Total = drug.Total - num
  7577. // service.UpdateBaseDrugLib(&drug)
  7578. // }
  7579. //
  7580. // }
  7581. //
  7582. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7583. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7584. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7585. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7586. // if num1 > num2 {
  7587. // num = num1 - num2
  7588. // drug.Total = drug.Total + num
  7589. // service.UpdateBaseDrugLib(&drug)
  7590. // } else if num1 < num2 {
  7591. // num = num2 - num1
  7592. // drug.Total = drug.Total - num
  7593. // service.UpdateBaseDrugLib(&drug)
  7594. // }
  7595. //
  7596. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7597. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7598. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7599. // if hisAdvice.PrescribingNumber > num2 {
  7600. // num = hisAdvice.PrescribingNumber - num2
  7601. // drug.Total = drug.Total + num
  7602. // service.UpdateBaseDrugLib(&drug)
  7603. // } else if num2 < advice.PrescribingNumber {
  7604. // num = num2 - hisAdvice.PrescribingNumber
  7605. // drug.Total = drug.Total - num
  7606. // service.UpdateBaseDrugLib(&drug)
  7607. // }
  7608. //
  7609. // }
  7610. // }
  7611. // }
  7612. //}
  7613. //
  7614. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7615. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7616. // advice.ExecutionTime = execution_time
  7617. //}
  7618. //
  7619. //
  7620. //
  7621. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7622. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7623. // advice.ExecutionStaff = execution_staff
  7624. //}
  7625. //
  7626. //
  7627. //
  7628. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7629. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7630. // advice.ExecutionState = execution_state
  7631. //}
  7632. //
  7633. //
  7634. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7635. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7636. // advice.CheckTime = check_time
  7637. //}
  7638. //
  7639. //
  7640. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7641. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7642. // advice.CheckState = check_state
  7643. //}
  7644. //
  7645. //
  7646. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7647. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7648. // advice.Checker = checker
  7649. //}
  7650. //
  7651. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7652. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7653. // advice.StartTime = start_time
  7654. //}
  7655. return 0
  7656. }
  7657. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7658. project.ExecutionStaff = 0
  7659. project.ExecutionState = 2
  7660. project.ExecutionTime = 0
  7661. project.Checker = 0
  7662. project.CheckState = 2
  7663. project.CheckTime = 0
  7664. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7665. id := int64(json["id"].(float64))
  7666. project.ID = id
  7667. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7668. project.ExecutionStaff = temp_project.ExecutionStaff
  7669. project.ExecutionState = temp_project.ExecutionState
  7670. project.ExecutionTime = temp_project.ExecutionTime
  7671. project.Checker = temp_project.Checker
  7672. project.CheckState = temp_project.CheckState
  7673. project.CheckTime = temp_project.CheckTime
  7674. project.TeamId = temp_project.TeamId
  7675. }
  7676. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7677. types := int64(json["type"].(float64))
  7678. project.Type = types
  7679. }
  7680. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7681. project_id := int64(json["project_id"].(float64))
  7682. project.ProjectId = project_id
  7683. }
  7684. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7685. team_id := int64(json["team_id"].(float64))
  7686. project.TeamId = team_id
  7687. }
  7688. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7689. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7690. project.Price = price
  7691. }
  7692. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7693. total, _ := json["total"].(string)
  7694. //totals, _ := strconv.ParseInt(total, 10, 64)
  7695. project.Count = total
  7696. }
  7697. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7698. medical_code, _ := json["medical_code"].(string)
  7699. project.MedListCodg = medical_code
  7700. }
  7701. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7702. single_dose, _ := json["single_dose"].(string)
  7703. project.SingleDose = single_dose
  7704. }
  7705. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7706. delivery_way, _ := json["delivery_way"].(string)
  7707. project.DeliveryWay = delivery_way
  7708. }
  7709. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7710. execution_frequency, _ := json["execution_frequency"].(string)
  7711. project.ExecutionFrequency = execution_frequency
  7712. }
  7713. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7714. remark, _ := json["remark"].(string)
  7715. project.Remark = remark
  7716. }
  7717. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7718. day, _ := json["number_days"].(string)
  7719. project.Day = day
  7720. }
  7721. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7722. unit, _ := json["unit"].(string)
  7723. project.Unit = unit
  7724. }
  7725. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7726. // frequency_type := int64(json["frequency_type"].(float64))
  7727. // project.FrequencyType = frequency_type
  7728. //}
  7729. //
  7730. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7731. // day_count := int64(json["day_count"].(float64))
  7732. // project.DayCount = day_count
  7733. //}
  7734. //
  7735. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7736. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7737. // week_day, _ := json["week_day"].(string)
  7738. // project.WeekDay = week_day
  7739. //}
  7740. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7741. //
  7742. //if project.ID == 0 {
  7743. // if stockConfig.IsOpen == 1 {
  7744. // if project.Type == 3 {
  7745. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7746. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7747. // good.Total = good.Total - f_count
  7748. // service.UpdateGoodInfo(&good)
  7749. // }
  7750. // }
  7751. //
  7752. //} else {
  7753. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7754. //
  7755. // if stockConfig.IsOpen == 1 {
  7756. // if project.Type == 3 {
  7757. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7758. // if project.Count < temp_project.Count {
  7759. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7760. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7761. //
  7762. // other_count := f_count_two - f_count_one
  7763. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7764. // good.Total = good.Total + other_count_two
  7765. // service.UpdateGoodInfo(&good)
  7766. // } else if project.Count > temp_project.Count {
  7767. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7768. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7769. //
  7770. // other_count := f_count_one - f_count_two
  7771. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7772. // good.Total = good.Total - other_count_two
  7773. // service.UpdateGoodInfo(&good)
  7774. // }
  7775. //
  7776. // }
  7777. // }
  7778. //
  7779. //}
  7780. return 0
  7781. }
  7782. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7783. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7784. utils.ErrorLog("drug_name")
  7785. return enums.ErrorCodeParamWrong
  7786. }
  7787. adviceName, _ := json["drug_name"].(string)
  7788. if len(adviceName) == 0 {
  7789. utils.ErrorLog("len(advice_name) == 0")
  7790. return enums.ErrorCodeParamWrong
  7791. }
  7792. advice.AdviceName = adviceName
  7793. adviceDesc, _ := json["advice_desc"].(string)
  7794. advice.AdviceDesc = adviceDesc
  7795. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7796. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7797. advice.DrugSpec = drugSpec
  7798. }
  7799. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7800. remark, _ := json["remark"].(string)
  7801. advice.Remark = remark
  7802. }
  7803. if json["id"] == nil {
  7804. advice.DrugId = 0
  7805. } else {
  7806. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7807. drug_id := int64(json["id"].(float64))
  7808. advice.DrugId = drug_id
  7809. }
  7810. }
  7811. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7812. groupno := int64(json["groupno"].(float64))
  7813. advice.Groupno = groupno
  7814. }
  7815. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7816. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7817. advice.IsSelfDrug = is_self_drug
  7818. }
  7819. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7820. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7821. drug_way_count, _ := json["drug_way_count"].(string)
  7822. advice.DrugWayCount = drug_way_count
  7823. }
  7824. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7825. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7826. advice.HospApprFlag = hosp_appr_flag
  7827. }
  7828. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7829. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7830. advice.PrescribingNumber = prescribingNumber
  7831. }
  7832. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7833. // frequency_type := int64(json["frequency_type"].(float64))
  7834. // advice.FrequencyType = frequency_type
  7835. //}
  7836. //
  7837. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7838. // day_count := int64(json["day_count"].(float64))
  7839. // advice.DayCount = day_count
  7840. //}
  7841. //
  7842. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7843. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7844. // week_day, _ := json["week_day"].(string)
  7845. // advice.WeekDay = week_day
  7846. //}
  7847. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7848. drugSpecUnit, _ := json["min_unit"].(string)
  7849. advice.DrugSpecUnit = drugSpecUnit
  7850. }
  7851. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7852. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7853. advice.SingleDose = singleDose
  7854. }
  7855. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7856. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7857. advice.SingleDoseUnit = singleDoseUnit
  7858. }
  7859. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7860. deliveryWay, _ := json["delivery_way"].(string)
  7861. advice.DeliveryWay = deliveryWay
  7862. }
  7863. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7864. executionFrequency, _ := json["execution_frequency"].(string)
  7865. advice.ExecutionFrequency = executionFrequency
  7866. }
  7867. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7868. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7869. advice.Price = price
  7870. }
  7871. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7872. med_list_codg, _ := json["medical_insurance_number"].(string)
  7873. advice.MedListCodg = med_list_codg
  7874. }
  7875. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7876. day := int64(json["day"].(float64))
  7877. advice.Day = day
  7878. }
  7879. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7880. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7881. advice.PrescribingNumberUnit = prescribingNumberUnit
  7882. }
  7883. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7884. advice_id := int64(json["advice_id"].(float64))
  7885. advice.ID = advice_id
  7886. if advice.ID > 0 {
  7887. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7888. if err == nil {
  7889. if hisAdvice.ID > 0 {
  7890. advice.ExecutionTime = hisAdvice.ExecutionTime
  7891. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7892. advice.ExecutionState = hisAdvice.ExecutionState
  7893. advice.CheckTime = hisAdvice.CheckTime
  7894. advice.Checker = hisAdvice.Checker
  7895. advice.DrugCode = hisAdvice.DrugCode
  7896. advice.CheckState = hisAdvice.CheckState
  7897. advice.StartTime = hisAdvice.StartTime
  7898. advice.HospApprFlag = hisAdvice.HospApprFlag
  7899. advice.IsMedicine = hisAdvice.IsMedicine
  7900. if hisAdvice.UserOrgId == 10028 {
  7901. 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 {
  7902. advice.ExecutionTime = 0
  7903. advice.ExecutionStaff = 0
  7904. advice.ExecutionState = 2
  7905. advice.CheckTime = 0
  7906. advice.Checker = 0
  7907. advice.CheckState = 2
  7908. }
  7909. } else {
  7910. 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 {
  7911. advice.ExecutionTime = 0
  7912. advice.ExecutionStaff = 0
  7913. advice.ExecutionState = 2
  7914. advice.CheckTime = 0
  7915. advice.Checker = 0
  7916. advice.CheckState = 2
  7917. //advice.UpdatedTime = time.Now().Unix()
  7918. advice.CreatedTime = hisAdvice.CreatedTime
  7919. advice.UpdatedTime = time.Now().Unix()
  7920. } else {
  7921. advice.CreatedTime = hisAdvice.CreatedTime
  7922. advice.UpdatedTime = hisAdvice.UpdatedTime
  7923. }
  7924. }
  7925. //advice.Groupno = hisAdvice.Groupno
  7926. } else {
  7927. advice.IsMedicine = 0
  7928. ctime := time.Now().Unix()
  7929. advice.CreatedTime = ctime
  7930. advice.UpdatedTime = ctime
  7931. }
  7932. }
  7933. } else {
  7934. advice.IsMedicine = 0
  7935. ctime := time.Now().Unix()
  7936. advice.CreatedTime = ctime
  7937. advice.UpdatedTime = ctime
  7938. }
  7939. }
  7940. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7941. //
  7942. //if drugStockConfig.IsOpen == 1 {
  7943. //
  7944. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7945. // if advice.ID == 0 { //医嘱不存在
  7946. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7947. // drug.Total = drug.Total - advice.PrescribingNumber
  7948. // service.UpdateBaseDrugLib(&drug)
  7949. //
  7950. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7951. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7952. // drug.Total = drug.Total - num
  7953. // service.UpdateBaseDrugLib(&drug)
  7954. // }
  7955. //
  7956. // } else if advice.ID > 0 { //医嘱存在
  7957. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7958. // var num float64
  7959. //
  7960. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7961. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7962. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7963. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7964. // drug.Total = drug.Total + num
  7965. // service.UpdateBaseDrugLib(&drug)
  7966. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7967. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7968. // drug.Total = drug.Total - num
  7969. // service.UpdateBaseDrugLib(&drug)
  7970. // }
  7971. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7972. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7973. // if num2 > advice.PrescribingNumber {
  7974. // num = num2 - advice.PrescribingNumber
  7975. // drug.Total = drug.Total + num
  7976. // service.UpdateBaseDrugLib(&drug)
  7977. // } else if num2 < advice.PrescribingNumber {
  7978. // num = advice.PrescribingNumber - num2
  7979. // drug.Total = drug.Total - num
  7980. // service.UpdateBaseDrugLib(&drug)
  7981. // }
  7982. //
  7983. // }
  7984. //
  7985. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7986. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7987. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7988. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7989. // if num1 > num2 {
  7990. // num = num1 - num2
  7991. // drug.Total = drug.Total + num
  7992. // service.UpdateBaseDrugLib(&drug)
  7993. // } else if num1 < num2 {
  7994. // num = num2 - num1
  7995. // drug.Total = drug.Total - num
  7996. // service.UpdateBaseDrugLib(&drug)
  7997. // }
  7998. //
  7999. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8000. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8001. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8002. // if hisAdvice.PrescribingNumber > num2 {
  8003. // num = hisAdvice.PrescribingNumber - num2
  8004. // drug.Total = drug.Total + num
  8005. // service.UpdateBaseDrugLib(&drug)
  8006. // } else if num2 < advice.PrescribingNumber {
  8007. // num = num2 - hisAdvice.PrescribingNumber
  8008. // drug.Total = drug.Total - num
  8009. // service.UpdateBaseDrugLib(&drug)
  8010. // }
  8011. //
  8012. // }
  8013. // }
  8014. // }
  8015. //}
  8016. //
  8017. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8018. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8019. // advice.ExecutionTime = execution_time
  8020. //}
  8021. //
  8022. //
  8023. //
  8024. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8025. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8026. // advice.ExecutionStaff = execution_staff
  8027. //}
  8028. //
  8029. //
  8030. //
  8031. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8032. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8033. // advice.ExecutionState = execution_state
  8034. //}
  8035. //
  8036. //
  8037. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8038. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8039. // advice.CheckTime = check_time
  8040. //}
  8041. //
  8042. //
  8043. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8044. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8045. // advice.CheckState = check_state
  8046. //}
  8047. //
  8048. //
  8049. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8050. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8051. // advice.Checker = checker
  8052. //}
  8053. //
  8054. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8055. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8056. // advice.StartTime = start_time
  8057. //}
  8058. return 0
  8059. }
  8060. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8061. project.ExecutionStaff = 0
  8062. project.ExecutionState = 2
  8063. project.ExecutionTime = 0
  8064. project.Checker = 0
  8065. project.CheckState = 2
  8066. project.CheckTime = 0
  8067. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8068. id := int64(json["id"].(float64))
  8069. project.ID = id
  8070. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8071. project.ExecutionStaff = temp_project.ExecutionStaff
  8072. project.ExecutionState = temp_project.ExecutionState
  8073. project.ExecutionTime = temp_project.ExecutionTime
  8074. project.Checker = temp_project.Checker
  8075. project.CheckState = temp_project.CheckState
  8076. project.CheckTime = temp_project.CheckTime
  8077. project.TeamId = temp_project.TeamId
  8078. }
  8079. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8080. types := int64(json["type"].(float64))
  8081. project.Type = types
  8082. }
  8083. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8084. project_id := int64(json["project_id"].(float64))
  8085. project.ProjectId = project_id
  8086. }
  8087. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8088. team_id := int64(json["team_id"].(float64))
  8089. project.TeamId = team_id
  8090. }
  8091. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8092. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8093. project.Price = price
  8094. }
  8095. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8096. total, _ := json["total"].(string)
  8097. //totals, _ := strconv.ParseInt(total, 10, 64)
  8098. project.Count = total
  8099. }
  8100. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8101. medical_code, _ := json["medical_code"].(string)
  8102. project.MedListCodg = medical_code
  8103. }
  8104. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8105. single_dose, _ := json["single_dose"].(string)
  8106. project.SingleDose = single_dose
  8107. }
  8108. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8109. delivery_way, _ := json["delivery_way"].(string)
  8110. project.DeliveryWay = delivery_way
  8111. }
  8112. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8113. execution_frequency, _ := json["execution_frequency"].(string)
  8114. project.ExecutionFrequency = execution_frequency
  8115. }
  8116. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8117. remark, _ := json["remark"].(string)
  8118. project.Remark = remark
  8119. }
  8120. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8121. day, _ := json["number_days"].(string)
  8122. project.Day = day
  8123. }
  8124. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8125. unit, _ := json["unit"].(string)
  8126. project.Unit = unit
  8127. }
  8128. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8129. // frequency_type := int64(json["frequency_type"].(float64))
  8130. // project.FrequencyType = frequency_type
  8131. //}
  8132. //
  8133. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8134. // day_count := int64(json["day_count"].(float64))
  8135. // project.DayCount = day_count
  8136. //}
  8137. //
  8138. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8139. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8140. // week_day, _ := json["week_day"].(string)
  8141. // project.WeekDay = week_day
  8142. //}
  8143. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8144. //
  8145. //if project.ID == 0 {
  8146. // if stockConfig.IsOpen == 1 {
  8147. // if project.Type == 3 {
  8148. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8149. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8150. // good.Total = good.Total - f_count
  8151. // service.UpdateGoodInfo(&good)
  8152. // }
  8153. // }
  8154. //
  8155. //} else {
  8156. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8157. //
  8158. // if stockConfig.IsOpen == 1 {
  8159. // if project.Type == 3 {
  8160. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8161. // if project.Count < temp_project.Count {
  8162. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8163. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8164. //
  8165. // other_count := f_count_two - f_count_one
  8166. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8167. // good.Total = good.Total + other_count_two
  8168. // service.UpdateGoodInfo(&good)
  8169. // } else if project.Count > temp_project.Count {
  8170. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8171. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8172. //
  8173. // other_count := f_count_one - f_count_two
  8174. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8175. // good.Total = good.Total - other_count_two
  8176. // service.UpdateGoodInfo(&good)
  8177. // }
  8178. //
  8179. // }
  8180. // }
  8181. //
  8182. //}
  8183. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8184. id := int64(json["id"].(float64))
  8185. if id > 0 {
  8186. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8187. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8188. fmt.Println("666666")
  8189. project.Mtime = time.Now().Unix()
  8190. project.Ctime = temp_project.Ctime
  8191. } else {
  8192. project.Mtime = temp_project.Mtime
  8193. project.Ctime = temp_project.Ctime
  8194. }
  8195. } else {
  8196. ctime := time.Now().Unix()
  8197. project.Mtime = ctime
  8198. project.Ctime = ctime
  8199. }
  8200. }
  8201. return 0
  8202. }
  8203. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8204. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8205. id := int64(json["id"].(float64))
  8206. additionalCharge.ID = id
  8207. }
  8208. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8209. item_id := int64(json["item_id"].(float64))
  8210. additionalCharge.ItemId = item_id
  8211. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8212. if config.ID > 0 {
  8213. if len(config.Code) > 0 {
  8214. additionalCharge.MedListCodg = config.Code
  8215. }
  8216. }
  8217. }
  8218. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8219. // price := int64(json["price"].(float64))
  8220. // formatInt_price := strconv.FormatInt(price, 10)
  8221. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8222. // additionalCharge.Price = float_price
  8223. // }
  8224. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8225. // price := int64(json["price"].(float64))
  8226. // formatInt_price := strconv.FormatInt(price, 10)
  8227. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8228. // additionalCharge.Price = float_price
  8229. //}
  8230. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8231. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8232. additionalCharge.Price = price
  8233. }
  8234. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8235. count, _ := json["count"].(string)
  8236. counts, _ := strconv.ParseInt(count, 10, 64)
  8237. additionalCharge.Count = counts
  8238. }
  8239. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8240. item_name, _ := json["item_name"].(string)
  8241. additionalCharge.ItemName = item_name
  8242. }
  8243. return 0
  8244. }
  8245. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8246. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8247. utils.ErrorLog("drug_name")
  8248. return enums.ErrorCodeParamWrong
  8249. }
  8250. adviceName, _ := json["drug_name"].(string)
  8251. if len(adviceName) == 0 {
  8252. utils.ErrorLog("len(advice_name) == 0")
  8253. return enums.ErrorCodeParamWrong
  8254. }
  8255. advice.AdviceName = adviceName
  8256. adviceDesc, _ := json["advice_desc"].(string)
  8257. advice.AdviceDesc = adviceDesc
  8258. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8259. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8260. advice.DrugSpec = drugSpec
  8261. }
  8262. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8263. remark, _ := json["remark"].(string)
  8264. advice.Remark = remark
  8265. }
  8266. if json["id"] == nil {
  8267. advice.DrugId = 0
  8268. } else {
  8269. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8270. drug_id := int64(json["id"].(float64))
  8271. advice.DrugId = drug_id
  8272. }
  8273. }
  8274. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8275. groupno := int64(json["groupno"].(float64))
  8276. advice.Groupno = groupno
  8277. }
  8278. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8279. drugSpecUnit, _ := json["min_unit"].(string)
  8280. advice.DrugSpecUnit = drugSpecUnit
  8281. }
  8282. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8283. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8284. advice.SingleDose = singleDose
  8285. }
  8286. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8287. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8288. advice.SingleDoseUnit = singleDoseUnit
  8289. }
  8290. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8291. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8292. advice.PrescribingNumber = prescribingNumber
  8293. }
  8294. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8295. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8296. advice.PrescribingNumberUnit = prescribingNumberUnit
  8297. }
  8298. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8299. deliveryWay, _ := json["delivery_way"].(string)
  8300. advice.DeliveryWay = deliveryWay
  8301. }
  8302. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8303. executionFrequency, _ := json["execution_frequency"].(string)
  8304. advice.ExecutionFrequency = executionFrequency
  8305. }
  8306. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8307. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8308. advice.Price = price
  8309. }
  8310. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8311. med_list_codg, _ := json["medical_insurance_number"].(string)
  8312. advice.MedListCodg = med_list_codg
  8313. }
  8314. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8315. day := int64(json["day"].(float64))
  8316. advice.Day = day
  8317. }
  8318. advice.FrequencyType = 1
  8319. return 0
  8320. }
  8321. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8322. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8323. types := int64(json["type"].(float64))
  8324. project.Type = types
  8325. }
  8326. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8327. project_id := int64(json["project_id"].(float64))
  8328. project.ProjectId = project_id
  8329. }
  8330. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8331. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8332. project.Price = price
  8333. }
  8334. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8335. total, _ := json["total"].(string)
  8336. //totals, _ := strconv.ParseInt(total, 10, 64)
  8337. project.Count = total
  8338. }
  8339. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8340. medical_code, _ := json["medical_code"].(string)
  8341. project.MedListCodg = medical_code
  8342. }
  8343. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8344. single_dose, _ := json["single_dose"].(string)
  8345. project.SingleDose = single_dose
  8346. }
  8347. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8348. delivery_way, _ := json["delivery_way"].(string)
  8349. project.DeliveryWay = delivery_way
  8350. }
  8351. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8352. execution_frequency, _ := json["execution_frequency"].(string)
  8353. project.ExecutionFrequency = execution_frequency
  8354. }
  8355. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8356. remark, _ := json["remark"].(string)
  8357. project.Remark = remark
  8358. }
  8359. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8360. day, _ := json["number_days"].(string)
  8361. project.Day = day
  8362. }
  8363. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8364. unit, _ := json["unit"].(string)
  8365. project.Unit = unit
  8366. }
  8367. project.FrequencyType = 1
  8368. return 0
  8369. }
  8370. func (c *HisApiController) GetHisOrderListTwo() {
  8371. start_time := c.GetString("start_time")
  8372. end_time := c.GetString("end_time")
  8373. timeLayout := "2006-01-02"
  8374. loc, _ := time.LoadLocation("Local")
  8375. var startTime int64
  8376. if len(start_time) > 0 {
  8377. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8378. if err != nil {
  8379. //fmt.Println(err)
  8380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8381. return
  8382. }
  8383. startTime = theTime.Unix()
  8384. }
  8385. var endTime int64
  8386. if len(end_time) > 0 {
  8387. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8388. if err != nil {
  8389. utils.ErrorLog(err.Error())
  8390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8391. return
  8392. }
  8393. endTime = theTime.Unix()
  8394. }
  8395. adminUser := c.GetAdminUserInfo()
  8396. org_id := adminUser.CurrentOrgId
  8397. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8398. if err == nil {
  8399. c.ServeSuccessJSON(map[string]interface{}{
  8400. "order2": order,
  8401. })
  8402. } else {
  8403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8404. return
  8405. }
  8406. }
  8407. func (c *HisApiController) GetHisOrderList() {
  8408. page, _ := c.GetInt64("page", -1)
  8409. limit, _ := c.GetInt64("limit", -1)
  8410. start_time := c.GetString("start_time")
  8411. end_time := c.GetString("end_time")
  8412. types, _ := c.GetInt64("type", 0)
  8413. keywords := c.GetString("keywords")
  8414. p_type, _ := c.GetInt64("p_type", 0)
  8415. sort_type, _ := c.GetInt64("sort_type", 0)
  8416. charge_type, _ := c.GetInt64("charge_type", 0)
  8417. sch_type, _ := c.GetInt64("sch_type", 0)
  8418. zone_type, _ := c.GetInt64("zone_type", 0)
  8419. med_type, _ := c.GetInt64("med_type", 0)
  8420. timeLayout := "2006-01-02"
  8421. loc, _ := time.LoadLocation("Local")
  8422. var startTime int64
  8423. if len(start_time) > 0 {
  8424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8425. if err != nil {
  8426. //fmt.Println(err)
  8427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8428. return
  8429. }
  8430. startTime = theTime.Unix()
  8431. }
  8432. var endTime int64
  8433. if len(end_time) > 0 {
  8434. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8435. if err != nil {
  8436. utils.ErrorLog(err.Error())
  8437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8438. return
  8439. }
  8440. endTime = theTime.Unix()
  8441. }
  8442. adminUser := c.GetAdminUserInfo()
  8443. org_id := adminUser.CurrentOrgId
  8444. 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)
  8445. for _, item := range order {
  8446. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8447. item.DoctorName = info.Doctor
  8448. item.DepartmentName = info.XtHisDepartment.Name
  8449. }
  8450. if err == nil {
  8451. c.ServeSuccessJSON(map[string]interface{}{
  8452. "order": order,
  8453. "total": total,
  8454. })
  8455. } else {
  8456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8457. return
  8458. }
  8459. }
  8460. func (c *HisApiController) GetHisOrder() {
  8461. patient_id, _ := c.GetInt64("patient_id", 0)
  8462. number := c.GetString("number")
  8463. adminInfo := c.GetAdminUserInfo()
  8464. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8465. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8466. if err == nil {
  8467. c.ServeSuccessJSON(map[string]interface{}{
  8468. "order": order,
  8469. "prescription": prescriptions,
  8470. })
  8471. } else {
  8472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8473. return
  8474. }
  8475. }
  8476. func (c *HisApiController) GetHisPrescriptionList() {
  8477. record_date := c.GetString("record_date")
  8478. keywords := c.GetString("keywords")
  8479. page, _ := c.GetInt64("page")
  8480. limit, _ := c.GetInt64("limit")
  8481. sch_type, _ := c.GetInt64("sch_type")
  8482. timeLayout := "2006-01-02"
  8483. loc, _ := time.LoadLocation("Local")
  8484. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8485. if err != nil {
  8486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8487. return
  8488. }
  8489. recordDateTime := theTime.Unix()
  8490. adminInfo := c.GetAdminUserInfo()
  8491. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8492. //adminInfo := c.GetAdminUserInfo()
  8493. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8494. //fmt.Println(prescriptionOrder)
  8495. if err == nil {
  8496. c.ServeSuccessJSON(map[string]interface{}{
  8497. "order": prescriptionOrder,
  8498. "total": total,
  8499. })
  8500. } else {
  8501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8502. return
  8503. }
  8504. }
  8505. func (c *HisApiController) GetHisPrescriptionInfo() {
  8506. id, _ := c.GetInt64("id")
  8507. adminInfo := c.GetAdminUserInfo()
  8508. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8509. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8510. if err == nil {
  8511. c.ServeSuccessJSON(map[string]interface{}{
  8512. "order": prescriptionOrder,
  8513. "prescription": prescription,
  8514. })
  8515. } else {
  8516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8517. return
  8518. }
  8519. }
  8520. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8521. adminUser := c.GetAdminUserInfo()
  8522. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8523. c.ServeSuccessJSON(map[string]interface{}{
  8524. "config": config,
  8525. })
  8526. }
  8527. type ResultTwo struct {
  8528. ErrMsg interface{} `json:"err_msg"`
  8529. InfRefmsgid string `json:"inf_refmsgid"`
  8530. Infcode int64 `json:"infcode"`
  8531. Output struct {
  8532. Baseinfo struct {
  8533. Age float64 `json:"age"`
  8534. Brdy string `json:"brdy"`
  8535. Certno string `json:"certno"`
  8536. Gend string `json:"gend"`
  8537. Naty string `json:"naty"`
  8538. PsnCertType string `json:"psn_cert_type"`
  8539. PsnName string `json:"psn_name"`
  8540. PsnNo string `json:"psn_no"`
  8541. } `json:"baseinfo"`
  8542. Idetinfo []interface{} `json:"idetinfo"`
  8543. Iinfo []struct {
  8544. Balc float64 `json:"balc"`
  8545. CvlservFlag string `json:"cvlserv_flag"`
  8546. EmpName string `json:"emp_name"`
  8547. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8548. Insutype string `json:"insutype"`
  8549. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8550. PausInsuDate interface{} `json:"paus_insu_date"`
  8551. PsnInsuDate string `json:"psn_insu_date"`
  8552. PsnInsuStas string `json:"psn_insu_stas"`
  8553. PsnType string `json:"psn_type"`
  8554. } `json:"insuinfo"`
  8555. } `json:"output"`
  8556. RefmsgTime string `json:"refmsg_time"`
  8557. RespondTime string `json:"respond_time"`
  8558. Signtype interface{} `json:"signtype"`
  8559. WarnInfo interface{} `json:"warn_info"`
  8560. }
  8561. type ResultThree struct {
  8562. Cainfo interface{} `json:"cainfo"`
  8563. ErrMsg interface{} `json:"err_msg"`
  8564. InfRefmsgid string `json:"inf_refmsgid"`
  8565. Infcode int64 `json:"infcode"`
  8566. Output struct {
  8567. Data struct {
  8568. IptOtpNo string `json:"ipt_otp_no"`
  8569. MdtrtID string `json:"mdtrt_id"`
  8570. PsnNo string `json:"psn_no"`
  8571. } `json:"data"`
  8572. } `json:"output"`
  8573. RefmsgTime string `json:"refmsg_time"`
  8574. RespondTime string `json:"respond_time"`
  8575. Signtype interface{} `json:"signtype"`
  8576. WarnMsg interface{} `json:"warn_msg"`
  8577. }
  8578. type ResultFour struct {
  8579. Cainfo string `json:"cainfo"`
  8580. ErrMsg string `json:"err_msg"`
  8581. InfRefmsgid string `json:"inf_refmsgid"`
  8582. Infcode int64 `json:"infcode"`
  8583. Output struct {
  8584. Result []struct {
  8585. BasMednFlag string `json:"bas_medn_flag"`
  8586. ChldMedcFlag string `json:"chld_medc_flag"`
  8587. ChrgitmLv string `json:"chrgitm_lv"`
  8588. Cnt float64 `json:"cnt"`
  8589. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8590. DrtReimFlag string `json:"drt_reim_flag"`
  8591. FeedetlSn string `json:"feedetl_sn"`
  8592. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8593. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8594. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8595. ListSpItemFlag string `json:"list_sp_item_flag"`
  8596. LmtUsedFlag string `json:"lmt_used_flag"`
  8597. MedChrgitmType string `json:"med_chrgitm_type"`
  8598. Memo string `json:"memo"`
  8599. OverlmtAmt float64 `json:"overlmt_amt"`
  8600. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8601. Pric float64 `json:"pric"`
  8602. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8603. SelfpayProp float64 `json:"selfpay_prop"`
  8604. } `json:"result"`
  8605. } `json:"output"`
  8606. RefmsgTime string `json:"refmsg_time"`
  8607. RespondTime string `json:"respond_time"`
  8608. Signtype string `json:"signtype"`
  8609. WarnMsg string `json:"warn_msg"`
  8610. }
  8611. type ResultFive struct {
  8612. Insutype string `json:"insutype"`
  8613. }
  8614. type ResultSix struct {
  8615. Cainfo interface{} `json:"cainfo"`
  8616. ErrMsg interface{} `json:"err_msg"`
  8617. InfRefmsgid string `json:"inf_refmsgid"`
  8618. Infcode int64 `json:"infcode"`
  8619. Output struct {
  8620. } `json:"output"`
  8621. RefmsgTime string `json:"refmsg_time"`
  8622. RespondTime string `json:"respond_time"`
  8623. Signtype interface{} `json:"signtype"`
  8624. WarnMsg interface{} `json:"warn_msg"`
  8625. }
  8626. type ResultSeven struct {
  8627. Cainfo string `json:"cainfo"`
  8628. ErrMsg string `json:"err_msg"`
  8629. InfRefmsgid string `json:"inf_refmsgid"`
  8630. Infcode int64 `json:"infcode"`
  8631. Output struct {
  8632. Setldetail []interface{} `json:"setldetail"`
  8633. Setlinfo struct {
  8634. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8635. AcctPay float64 `json:"acct_pay"`
  8636. ActPayDedc float64 `json:"act_pay_dedc"`
  8637. Age float64 `json:"age"`
  8638. Balc float64 `json:"balc"`
  8639. Brdy string `json:"brdy"`
  8640. Certno string `json:"certno"`
  8641. ClrOptins string `json:"clr_optins"`
  8642. ClrType string `json:"clr_type"`
  8643. ClrWay string `json:"clr_way"`
  8644. CvlservFlag string `json:"cvlserv_flag"`
  8645. CvlservPay float64 `json:"cvlserv_pay"`
  8646. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8647. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8648. Gend string `json:"gend"`
  8649. HifesPay float64 `json:"hifes_pay"`
  8650. HifmiPay float64 `json:"hifmi_pay"`
  8651. HifobPay float64 `json:"hifob_pay"`
  8652. HifpPay float64 `json:"hifp_pay"`
  8653. HospPartAmt float64 `json:"hosp_part_amt"`
  8654. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8655. Insutype string `json:"insutype"`
  8656. MafPay float64 `json:"maf_pay"`
  8657. MdtrtCertType string `json:"mdtrt_cert_type"`
  8658. MdtrtID string `json:"mdtrt_id"`
  8659. MedType string `json:"med_type"`
  8660. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8661. MedinsSetlID string `json:"medins_setl_id"`
  8662. Naty string `json:"naty"`
  8663. OthPay float64 `json:"oth_pay"`
  8664. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8665. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8666. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8667. PsnCashPay float64 `json:"psn_cash_pay"`
  8668. PsnCertType string `json:"psn_cert_type"`
  8669. PsnName string `json:"psn_name"`
  8670. PsnNo string `json:"psn_no"`
  8671. PsnPartAmt float64 `json:"psn_part_amt"`
  8672. PsnType string `json:"psn_type"`
  8673. SetlID string `json:"setl_id"`
  8674. SetlTime string `json:"setl_time"`
  8675. } `json:"setlinfo"`
  8676. } `json:"output"`
  8677. RefmsgTime string `json:"refmsg_time"`
  8678. RespondTime string `json:"respond_time"`
  8679. Signtype interface{} `json:"signtype"`
  8680. WarnMsg interface{} `json:"warn_msg"`
  8681. }
  8682. type ResultEight struct {
  8683. Cainfo string `json:"cainfo"`
  8684. ErrMsg string `json:"err_msg"`
  8685. InfRefmsgid string `json:"inf_refmsgid"`
  8686. Infcode int64 `json:"infcode"`
  8687. Output struct {
  8688. Stmtinfo struct {
  8689. SetlOptins string `json:"setl_optins"`
  8690. StmtRslt string `json:"stmt_rslt"`
  8691. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8692. } `json:"stmtinfo"`
  8693. } `json:"output"`
  8694. RefmsgTime string `json:"refmsg_time"`
  8695. RespondTime string `json:"respond_time"`
  8696. Signtype interface{} `json:"signtype"`
  8697. WarnMsg interface{} `json:"warn_msg"`
  8698. }
  8699. type ResultNine struct {
  8700. Cainfo string `json:"cainfo"`
  8701. ErrMsg string `json:"err_msg"`
  8702. InfRefmsgid string `json:"inf_refmsgid"`
  8703. Infcode int64 `json:"infcode"`
  8704. Output struct {
  8705. FileQuryNo string `json:"file_qury_no"`
  8706. } `json:"output"`
  8707. RefmsgTime string `json:"refmsg_time"`
  8708. RespondTime string `json:"respond_time"`
  8709. Signtype interface{} `json:"signtype"`
  8710. WarnMsg interface{} `json:"warn_msg"`
  8711. }
  8712. type ResultTen struct {
  8713. Cainfo string `json:"cainfo"`
  8714. ErrMsg string `json:"err_msg"`
  8715. InfRefmsgid string `json:"inf_refmsgid"`
  8716. Infcode int64 `json:"infcode"`
  8717. Output struct {
  8718. DldEndtime string `json:"dld_endtime"`
  8719. FileQuryNo string `json:"file_qury_no"`
  8720. Filename string `json:"filename"`
  8721. } `json:"output"`
  8722. RefmsgTime string `json:"refmsg_time"`
  8723. RespondTime string `json:"respond_time"`
  8724. Signtype interface{} `json:"signtype"`
  8725. WarnMsg interface{} `json:"warn_msg"`
  8726. }
  8727. type ResultEleven struct {
  8728. Cainfo string `json:"cainfo"`
  8729. ErrMsg string `json:"err_msg"`
  8730. InfRefmsgid string `json:"inf_refmsgid"`
  8731. Infcode int64 `json:"infcode"`
  8732. Output struct {
  8733. Setlinfo struct {
  8734. FixmedinsName string `json:"fixmedins_name"`
  8735. FixmedinsCode string `json:"fixmedins_code"`
  8736. PsnNo string `json:"psn_no"`
  8737. PsnName string `json:"psn_name"`
  8738. HifobPay float64 `json:"hifob_pay"`
  8739. Gend string `json:"gend"`
  8740. Brdy string `json:"brdy"`
  8741. PsnCertType string `json:"psn_cert_type"`
  8742. PsnType string `json:"psn_type"`
  8743. EmpName string `json:"emp_name"`
  8744. Certno string `json:"certno"`
  8745. Insutype string `json:"insutype"`
  8746. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8747. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8748. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8749. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8750. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8751. ActPayDedc float64 `json:"act_pay_dedc"`
  8752. HifpPay float64 `json:"hifp_pay"`
  8753. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8754. CvlservPay float64 `json:"cvlserv_pay"`
  8755. HifesPay float64 `json:"hifes_pay"`
  8756. HifmiPay float64 `json:"hifmi_pay"`
  8757. MafPay float64 `json:"maf_pay"`
  8758. OthPay float64 `json:"oth_pay"`
  8759. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8760. PsnPay float64 `json:"psn_pay"`
  8761. AcctPay float64 `json:"acct_pay"`
  8762. CashPayamt float64 `json:"cash_payamt"`
  8763. Balc float64 `json:"balc"`
  8764. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8765. MedinsSetlId string `json:"medins_setl_id"`
  8766. RefdSetlFlag string `json:"refd_setl_flag"`
  8767. SetlTime string `json:"setl_time"`
  8768. MedType string `json:"med_type"`
  8769. } `json:"setlinfo"`
  8770. } `json:"output"`
  8771. RefmsgTime string `json:"refmsg_time"`
  8772. RespondTime string `json:"respond_time"`
  8773. Signtype interface{} `json:"signtype"`
  8774. WarnMsg interface{} `json:"warn_msg"`
  8775. }
  8776. type Custom struct {
  8777. DetItemFeeSumamt string
  8778. Cut string
  8779. FeedetlSn string
  8780. Price string
  8781. MedListCodg string
  8782. Type int64
  8783. AdviceId int64
  8784. ProjectId int64
  8785. ItemId int64
  8786. CostType int64
  8787. }
  8788. // 获取个人信息----挂号-----上传就诊信息
  8789. func (c *HisApiController) GetRegisterInfo() {
  8790. id, _ := c.GetInt64("id")
  8791. record_time := c.GetString("record_time")
  8792. settlementValue, _ := c.GetInt64("settlement_value")
  8793. medical_insurance_card := c.GetString("medical_insurance_card")
  8794. name := c.GetString("name")
  8795. id_card_type, _ := c.GetInt64("id_card_type")
  8796. certificates, _ := c.GetInt64("certificates")
  8797. medical_care, _ := c.GetInt64("medical_care")
  8798. birthday := c.GetString("birthday")
  8799. age, _ := c.GetInt64("age")
  8800. id_card := c.GetString("id_card")
  8801. register_type, _ := c.GetInt64("register")
  8802. doctor, _ := c.GetInt64("doctor")
  8803. department, _ := c.GetInt64("department")
  8804. gender, _ := c.GetInt64("sex")
  8805. phone := c.GetString("phone")
  8806. registration_fee, _ := c.GetFloat("registration_fee")
  8807. medical_expenses, _ := c.GetFloat("medical_expenses")
  8808. social_type, _ := c.GetInt64("social_type")
  8809. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8810. diagnosis_ids := c.GetString("diagnosis")
  8811. sick_type, _ := c.GetInt64("sick_type")
  8812. reg_type := c.GetString("p_type")
  8813. timeLayout := "2006-01-02"
  8814. loc, _ := time.LoadLocation("Local")
  8815. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8816. birthUnix := birthdays.Unix()
  8817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8818. if err != nil {
  8819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8820. return
  8821. }
  8822. recordDateTime := theTime.Unix()
  8823. adminInfo := c.GetAdminUserInfo()
  8824. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8825. if tempPatient.ID == 0 {
  8826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8827. return
  8828. }
  8829. var patient service.Patients
  8830. if id == 0 {
  8831. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8832. } else {
  8833. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8834. }
  8835. if patient.ID == 0 {
  8836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8837. return
  8838. }
  8839. if len(patient.IdCardNo) == 0 {
  8840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8841. return
  8842. }
  8843. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8844. if len(his) >= 1 {
  8845. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8846. if len(his) >= 1 && order.ID == 0 {
  8847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8848. return
  8849. }
  8850. }
  8851. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8852. fmt.Println(timeStr)
  8853. timeArr := strings.Split(timeStr, " ")
  8854. fmt.Println(timeArr)
  8855. timeArrTwo := strings.Split(timeArr[0], "-")
  8856. timeArrThree := strings.Split(timeArr[1], ":")
  8857. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8858. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8859. if len(lists) == 0 {
  8860. var hisPatient models.XtHisPatient
  8861. hisPatient = models.XtHisPatient{
  8862. Name: name,
  8863. Age: age,
  8864. Gender: gender,
  8865. Birthday: birthUnix,
  8866. Phone: phone,
  8867. MedicalTreatmentType: medical_care,
  8868. IdType: certificates,
  8869. IdCardNo: id_card,
  8870. BalanceAccountsType: settlementValue,
  8871. SocialType: social_type,
  8872. MedicalInsuranceNumber: medical_insurance_card,
  8873. RegisterType: register_type,
  8874. RegisterCost: registration_fee,
  8875. TreatmentCost: medical_expenses,
  8876. AdminUserId: adminInfo.AdminUser.Id,
  8877. UserOrgId: adminInfo.CurrentOrgId,
  8878. Status: 1,
  8879. RecordDate: recordDateTime,
  8880. IsReturn: 1,
  8881. PatientId: patient.ID,
  8882. Ctime: time.Now().Unix(),
  8883. Mtime: time.Now().Unix(),
  8884. Number: str,
  8885. IdCardType: id_card_type,
  8886. Departments: department,
  8887. Doctor: doctor,
  8888. PType: reg_type,
  8889. Diagnosis: diagnosis_ids,
  8890. SickType: sick_type,
  8891. }
  8892. service.CreateHisPatient(&hisPatient)
  8893. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8894. c.ServeSuccessJSON(map[string]interface{}{
  8895. "his_info": hisPatient,
  8896. })
  8897. } else {
  8898. //chrgBchno := rand.Intn(1000000) + 10000
  8899. var hisPatient models.XtHisPatient
  8900. hisPatient = models.XtHisPatient{
  8901. Name: name,
  8902. Age: age,
  8903. Gender: gender,
  8904. Birthday: birthUnix,
  8905. Phone: phone,
  8906. MedicalTreatmentType: medical_care,
  8907. IdType: certificates,
  8908. IdCardNo: id_card,
  8909. BalanceAccountsType: settlementValue,
  8910. SocialType: social_type,
  8911. MedicalInsuranceNumber: medical_insurance_card,
  8912. RegisterType: register_type,
  8913. RegisterCost: registration_fee,
  8914. TreatmentCost: medical_expenses,
  8915. AdminUserId: adminInfo.AdminUser.Id,
  8916. UserOrgId: adminInfo.CurrentOrgId,
  8917. Status: 1,
  8918. RecordDate: recordDateTime,
  8919. IsReturn: 1,
  8920. PatientId: patient.ID,
  8921. Ctime: time.Now().Unix(),
  8922. Mtime: time.Now().Unix(),
  8923. Number: str,
  8924. IdCardType: id_card_type,
  8925. Departments: department,
  8926. Doctor: doctor,
  8927. PType: reg_type,
  8928. Diagnosis: diagnosis_ids,
  8929. SickType: sick_type,
  8930. }
  8931. service.CreateHisPatient(&hisPatient)
  8932. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8933. c.ServeSuccessJSON(map[string]interface{}{
  8934. "his_info": hisPatient,
  8935. })
  8936. }
  8937. }
  8938. // 上传明细----结算
  8939. func (c *HisApiController) GetUploadInfo() {
  8940. id, _ := c.GetInt64("id")
  8941. record_time := c.GetString("record_time")
  8942. his_patient_id, _ := c.GetInt64("his_patient_id")
  8943. oth_desc := c.GetString("oth_desc")
  8944. pay_way, _ := c.GetInt64("pay_way")
  8945. pay_ways := c.GetString("pay_ways")
  8946. pay_price, _ := c.GetFloat("pay_price")
  8947. pay_card_no := c.GetString("pay_card_no")
  8948. discount_price, _ := c.GetFloat("discount_price")
  8949. preferential_price, _ := c.GetFloat("preferential_price")
  8950. reality_price, _ := c.GetFloat("reality_price")
  8951. found_price, _ := c.GetFloat("found_price")
  8952. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8953. private_price, _ := c.GetFloat("private_price")
  8954. timeLayout := "2006-01-02"
  8955. loc, _ := time.LoadLocation("Local")
  8956. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8957. fapiao_code := c.GetString("fapiao_code")
  8958. fapiao_number := c.GetString("fapiao_number")
  8959. diagnosis_id := c.GetString("diagnosis")
  8960. sick_type, _ := c.GetInt64("sick_type")
  8961. reg_type, _ := c.GetInt64("p_type")
  8962. order_id, _ := c.GetInt64("order_id")
  8963. cash_pay := c.GetString("cash_pay")
  8964. wechat_pay := c.GetString("wechat_pay")
  8965. ali_pay := c.GetString("ali_pay")
  8966. jifen_pay := c.GetString("jifen_pay")
  8967. band_card_pay := c.GetString("band_card_pay")
  8968. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8969. tmp_decimal := c.GetString("tmp_decimal")
  8970. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8971. var decimal float64 //本次使用的押金
  8972. var errmsg error
  8973. tx := service.XTWriteDB().Begin() //开了事务
  8974. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8975. defer func() {
  8976. if errmsg != nil {
  8977. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8978. tx.Rollback()
  8979. } else {
  8980. tx.Commit()
  8981. }
  8982. }()
  8983. fmt.Println("dec_way", dec_way)
  8984. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8985. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8986. return
  8987. }
  8988. if len(tmp_decimal) > 0 {
  8989. if tmp_decimal[0] == 45 {
  8990. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8991. return
  8992. }
  8993. }
  8994. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8995. fmt.Println(errs)
  8996. decimal = tt
  8997. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8998. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  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. adminUser := c.GetAdminUserInfo()
  9006. var prescriptions []*models.HisPrescription
  9007. var prescriptionsOne []*models.HisPrescription
  9008. var start_time int64
  9009. var end_time int64
  9010. ids_str := c.GetString("ids")
  9011. ids_arr := strings.Split(ids_str, ",")
  9012. if tempOrder.ID == 0 {
  9013. if settle_accounts_type == 1 { //日结
  9014. fmt.Println(reg_type)
  9015. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9016. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9017. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9018. } else {
  9019. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9020. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9021. }
  9022. } else { //月结
  9023. start_time_str := c.GetString("start_time")
  9024. end_time_str := c.GetString("end_time")
  9025. timeLayout := "2006-01-02"
  9026. loc, _ := time.LoadLocation("Local")
  9027. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9028. if err != nil {
  9029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9030. return
  9031. }
  9032. recordStartTime := theStartTime.Unix()
  9033. start_time = recordStartTime
  9034. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9035. if err != nil {
  9036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9037. return
  9038. }
  9039. recordEndTime := theEndTime.Unix()
  9040. end_time = recordEndTime
  9041. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9042. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9043. }
  9044. var goods []*models.DialysisBeforePrepareGoods
  9045. var newGoods []*models.NewDialysisBeforePrepareGoods
  9046. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9047. var infos []*models.HisDoctorAdviceInfo
  9048. var infoList []*models.HisDoctorAdviceInfo
  9049. var hisAdvice []*models.HisDoctorAdviceInfo
  9050. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9051. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9052. //判断库存不足
  9053. //结算出库开关
  9054. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9055. if settConfig.IsOpen == 1 {
  9056. //判断库存的地方
  9057. for _, info := range prescriptions {
  9058. if info.Type == 1 {
  9059. infos = append(infos, info.HisDoctorAdviceInfo...)
  9060. }
  9061. if info.Type == 2 {
  9062. for _, sumItem := range info.HisPrescriptionProject {
  9063. if sumItem.Type == 3 {
  9064. var good models.DialysisBeforePrepareGoods
  9065. var newGood models.NewDialysisBeforePrepareGoods
  9066. good.GoodId = sumItem.GoodInfo.ID
  9067. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9068. count, _ := strconv.Atoi(sumItem.Count)
  9069. good.Count = int64(count)
  9070. good.StorehouseId = houseConfig.StorehouseOutInfo
  9071. good.ProjectId = sumItem.ID
  9072. goods = append(goods, &good)
  9073. newGood.GoodId = sumItem.GoodInfo.ID
  9074. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9075. count2, _ := strconv.Atoi(sumItem.Count)
  9076. newGood.Count = int64(count2)
  9077. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9078. newGood.ProjectId = sumItem.ID
  9079. newGoods = append(newGoods, &newGood)
  9080. }
  9081. }
  9082. }
  9083. }
  9084. for _, info := range prescriptionsOne {
  9085. if info.Type == 1 {
  9086. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9087. }
  9088. if info.Type == 2 {
  9089. for _, sumItem := range info.HisPrescriptionProject {
  9090. if sumItem.Type == 3 {
  9091. var newGood models.NewDialysisBeforePrepareGoods
  9092. newGood.GoodId = sumItem.GoodInfo.ID
  9093. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9094. count2, _ := strconv.Atoi(sumItem.Count)
  9095. newGood.Count = int64(count2)
  9096. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9097. newGood.ProjectId = sumItem.ID
  9098. newGoodOne = append(newGoodOne, &newGood)
  9099. }
  9100. }
  9101. }
  9102. }
  9103. //判断
  9104. for _, itemOne := range infos {
  9105. for _, itemTwo := range hisAdvice {
  9106. if itemOne.DrugId == itemTwo.DrugId {
  9107. itemTwo.Child = append(itemTwo.Child, itemOne)
  9108. }
  9109. }
  9110. }
  9111. for _, itemTwo := range hisAdvice {
  9112. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9113. var sum_out_count int64
  9114. for _, itemThree := range itemTwo.Child {
  9115. var prescribing_number int64
  9116. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9117. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9118. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9119. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9120. }
  9121. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9122. prescribing_number = parseIntPrescribingNumber
  9123. }
  9124. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9125. prescribing_number = parseIntPrescribingNumber
  9126. }
  9127. sum_out_count += prescribing_number
  9128. }
  9129. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9130. if sum_out_count > drugStockOut.FlushCount {
  9131. c.ServeSuccessJSON(map[string]interface{}{
  9132. "msg": "2",
  9133. "drug": medical,
  9134. })
  9135. return
  9136. }
  9137. }
  9138. for _, itemOne := range newGoods {
  9139. for _, item := range newGoodOne {
  9140. if itemOne.GoodId == item.GoodId {
  9141. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9142. }
  9143. }
  9144. }
  9145. for _, item := range newGoodOne {
  9146. var sum_out_count_one int64
  9147. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9148. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9149. sum_out_count_one += itemOne.Count
  9150. }
  9151. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9152. fmt.Println("sum_out_count_one", sum_out_count_one)
  9153. fmt.Println("list.FlushCount", list.FlushCount)
  9154. if sum_out_count_one > list.FlushCount {
  9155. c.ServeSuccessJSON(map[string]interface{}{
  9156. "msg": "3",
  9157. "good": good,
  9158. })
  9159. return
  9160. }
  9161. }
  9162. }
  9163. timestamp := time.Now().Unix()
  9164. tempTime := time.Unix(timestamp, 0)
  9165. timeFormat := tempTime.Format("20060102150405")
  9166. chrgBchno := rand.Intn(100000) + 10000
  9167. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9168. strconv.FormatInt(his.PatientId, 10)
  9169. var ids []int64
  9170. for _, item := range prescriptions {
  9171. ids = append(ids, item.ID)
  9172. }
  9173. var total float64
  9174. for _, item := range prescriptions {
  9175. fmt.Println(item)
  9176. if item.Type == 1 { //药品
  9177. for _, subItem := range item.HisDoctorAdviceInfo {
  9178. total = total + (subItem.Price * subItem.PrescribingNumber)
  9179. }
  9180. }
  9181. if item.Type == 2 { //项目
  9182. for _, subItem := range item.HisPrescriptionProject {
  9183. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9184. total = total + (subItem.Price * cnt)
  9185. }
  9186. }
  9187. for _, subItem := range item.HisAdditionalCharge {
  9188. total = total + (subItem.Price * float64(subItem.Count))
  9189. }
  9190. }
  9191. if reg_type == 1111 || reg_type == 1112 {
  9192. reg_type = 11
  9193. }
  9194. tm := time.Unix(time.Now().Unix(), 0)
  9195. allTotal := fmt.Sprintf("%.4f", total)
  9196. totals, _ := strconv.ParseFloat(allTotal, 64)
  9197. order := &models.HisOrder{
  9198. UserOrgId: adminUser.CurrentOrgId,
  9199. HisPatientId: his.ID,
  9200. PatientId: id,
  9201. SettleAccountsDate: recordDateTime,
  9202. Ctime: time.Now().Unix(),
  9203. Mtime: time.Now().Unix(),
  9204. Status: 1,
  9205. OrderStatus: 2,
  9206. MdtrtId: his.Number,
  9207. Number: chrg_bchno,
  9208. MedfeeSumamt: totals,
  9209. PayWay: pay_way,
  9210. PayWays: pay_ways,
  9211. PayPrice: pay_price,
  9212. MedType: strconv.Itoa(int(reg_type)),
  9213. PayCardNo: pay_card_no,
  9214. DiscountPrice: discount_price,
  9215. PreferentialPrice: preferential_price,
  9216. RealityPrice: reality_price,
  9217. FoundPrice: found_price,
  9218. MedicalInsurancePrice: medical_insurance_price,
  9219. PrivatePrice: private_price,
  9220. SettleEndTime: end_time,
  9221. SettleStartTime: start_time,
  9222. PsnPartAmt: totals,
  9223. PsnCashPay: totals,
  9224. SettleType: settle_accounts_type,
  9225. FaPiaoCode: fapiao_code,
  9226. FaPiaoNumber: fapiao_number,
  9227. Diagnosis: diagnosis_id,
  9228. PType: 2,
  9229. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9230. Decimal: decimal,
  9231. OthDesc: oth_desc,
  9232. CashPay: cash_pay,
  9233. WechatPay: wechat_pay,
  9234. AliPay: ali_pay,
  9235. JifenPay: jifen_pay,
  9236. BandCardPay: band_card_pay,
  9237. Creator: adminUser.AdminUser.Id,
  9238. }
  9239. err = service.CreateOrderTX(order, tx)
  9240. if err != nil {
  9241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9242. return
  9243. }
  9244. var customs []*Custom
  9245. for _, item := range prescriptions {
  9246. if item.Type == 1 { //药品a
  9247. for _, subItem := range item.HisDoctorAdviceInfo {
  9248. cus := &Custom{
  9249. AdviceId: subItem.ID,
  9250. ProjectId: 0,
  9251. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9252. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9253. FeedetlSn: subItem.FeedetlSn,
  9254. Price: fmt.Sprintf("%.4f", subItem.Price),
  9255. MedListCodg: subItem.MedListCodg,
  9256. Type: 1,
  9257. CostType: 9,
  9258. }
  9259. customs = append(customs, cus)
  9260. }
  9261. }
  9262. if item.Type == 2 { //项目
  9263. for _, subItem := range item.HisPrescriptionProject {
  9264. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9265. cus := &Custom{
  9266. AdviceId: 0,
  9267. ProjectId: subItem.ID,
  9268. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9269. Cut: fmt.Sprintf("%.4f", cnt),
  9270. FeedetlSn: subItem.FeedetlSn,
  9271. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9272. MedListCodg: subItem.MedListCodg,
  9273. Type: 2,
  9274. CostType: subItem.HisProject.CostClassify,
  9275. }
  9276. customs = append(customs, cus)
  9277. }
  9278. }
  9279. for _, item := range item.HisAdditionalCharge {
  9280. cus := &Custom{
  9281. ItemId: item.ID,
  9282. AdviceId: 0,
  9283. ProjectId: 0,
  9284. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9285. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9286. FeedetlSn: item.FeedetlSn,
  9287. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9288. MedListCodg: item.XtHisAddtionConfig.Code,
  9289. Type: 3,
  9290. CostType: 5,
  9291. }
  9292. customs = append(customs, cus)
  9293. }
  9294. }
  9295. for _, item := range customs {
  9296. var advice_id int64 = 0
  9297. var project_id int64 = 0
  9298. var item_id int64 = 0
  9299. var types int64 = 0
  9300. var med_chrgitm_type string
  9301. if item.Type == 1 {
  9302. advice_id = item.AdviceId
  9303. project_id = 0
  9304. item_id = 0
  9305. med_chrgitm_type = "09"
  9306. } else if item.Type == 2 {
  9307. med_chrgitm_type = "05"
  9308. if item.CostType == 3 {
  9309. med_chrgitm_type = "04"
  9310. }
  9311. if item.CostType == 8 {
  9312. med_chrgitm_type = "03"
  9313. }
  9314. advice_id = 0
  9315. item_id = 0
  9316. project_id = item.ProjectId
  9317. } else if item.Type == 3 {
  9318. advice_id = 0
  9319. item_id = item.ItemId
  9320. project_id = 0
  9321. med_chrgitm_type = "08"
  9322. }
  9323. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9324. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9325. pric, _ := strconv.ParseFloat(item.Price, 32)
  9326. info := &models.HisOrderInfo{
  9327. OrderNumber: order.Number,
  9328. UploadDate: time.Now().Unix(),
  9329. AdviceId: advice_id,
  9330. DetItemFeeSumamt: detItemFeeSumamt,
  9331. MedChrgitmType: med_chrgitm_type,
  9332. Cnt: cut,
  9333. Pric: pric,
  9334. PatientId: id,
  9335. Status: 1,
  9336. Mtime: time.Now().Unix(),
  9337. Ctime: time.Now().Unix(),
  9338. UserOrgId: adminUser.CurrentOrgId,
  9339. HisPatientId: his.ID,
  9340. OrderId: order.ID,
  9341. ProjectId: project_id,
  9342. Type: types,
  9343. ItemId: item_id,
  9344. }
  9345. service.CreateOrderInfoTX(info, tx)
  9346. }
  9347. his.Diagnosis = diagnosis_id
  9348. his.SickType = sick_type
  9349. his.RegisterType = reg_type
  9350. his.MedicalTreatmentType = reg_type
  9351. service.UpdataHisPateintTX(&his, tx)
  9352. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9353. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9354. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9355. //判断是否使用了押金
  9356. if dec_way == "true" {
  9357. tmpstring := strconv.FormatInt(order.ID, 10)
  9358. //扣押金
  9359. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9360. order.Decimal = decimal
  9361. service.UpDateOrderTwo(order, tx)
  9362. if errmsg != nil {
  9363. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9364. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9365. return
  9366. }
  9367. }
  9368. if err == nil {
  9369. for _, info := range prescriptions {
  9370. if info.Type == 1 {
  9371. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9372. }
  9373. if info.Type == 2 {
  9374. for _, sumItem := range info.HisPrescriptionProject {
  9375. if sumItem.Type == 3 {
  9376. var good models.DialysisBeforePrepareGoods
  9377. var newGood models.NewDialysisBeforePrepareGoods
  9378. var oldGood models.OldDialysisBeforePrepareGoods
  9379. good.GoodId = sumItem.GoodInfo.ID
  9380. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9381. count, _ := strconv.Atoi(sumItem.Count)
  9382. good.Count = int64(count)
  9383. good.StorehouseId = houseConfig.StorehouseOutInfo
  9384. good.ProjectId = sumItem.ID
  9385. good.PatientId = sumItem.PatientId
  9386. goods = append(goods, &good)
  9387. newGood.GoodId = sumItem.GoodInfo.ID
  9388. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9389. count2, _ := strconv.Atoi(sumItem.Count)
  9390. newGood.Count = int64(count2)
  9391. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9392. newGood.ProjectId = sumItem.ID
  9393. newGood.PatientId = sumItem.HisPatientId
  9394. newGoods = append(newGoods, &newGood)
  9395. oldGood.GoodId = sumItem.GoodInfo.ID
  9396. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9397. count3, _ := strconv.Atoi(sumItem.Count)
  9398. oldGood.Count = int64(count3)
  9399. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9400. oldGood.ProjectId = sumItem.ID
  9401. oldGood.RecordDate = sumItem.RecordDate
  9402. oldGood.PatientId = sumItem.HisPatientId
  9403. oldGoods = append(oldGoods, &oldGood)
  9404. }
  9405. }
  9406. }
  9407. }
  9408. if settConfig.IsOpen == 1 {
  9409. for _, item := range infoList {
  9410. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9411. if medical.IsUse == 2 {
  9412. //药品出库
  9413. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9414. //查询默认仓库
  9415. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9416. //查询默认仓库剩余多少库存
  9417. var sum_count int64
  9418. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9419. for _, its := range stockInfo {
  9420. if its.MaxUnit == medical.MaxUnit {
  9421. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9422. }
  9423. sum_count += its.StockMaxNumber + its.StockMinNumber
  9424. }
  9425. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9426. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9427. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9428. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9429. }
  9430. }
  9431. orgId := c.GetAdminUserInfo().CurrentOrgId
  9432. if len(oldGoods) > 0 {
  9433. timeStr := time.Now().Format("2006-01-02")
  9434. timeArr := strings.Split(timeStr, "-")
  9435. total, _ := service.FindAllWarehouseOut(orgId)
  9436. total = total + 1
  9437. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9438. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9439. number = number + total
  9440. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9441. operation_time := time.Now().Unix()
  9442. creater := c.GetAdminUserInfo().AdminUser.Id
  9443. //查询默认出库仓库库存
  9444. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9445. recordDateStr := time.Now().Format("2006-01-02")
  9446. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9447. nowtime := recordDate.Unix()
  9448. warehouseOut := models.WarehouseOut{
  9449. WarehouseOutOrderNumber: warehousing_out_order,
  9450. OperationTime: operation_time,
  9451. OrgId: orgId,
  9452. Creater: creater,
  9453. Ctime: time.Now().Unix(),
  9454. Status: 1,
  9455. WarehouseOutTime: nowtime,
  9456. Type: 1,
  9457. StorehouseId: storeConfig.StorehouseOutInfo,
  9458. IsCheck: 1,
  9459. OrderId: order.ID,
  9460. IsSys: 5,
  9461. }
  9462. //查询是否生成出库单
  9463. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9464. if out.ID == 0 {
  9465. service.AddSigleWarehouseOut(&warehouseOut)
  9466. }
  9467. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9468. for _, item := range oldGoods {
  9469. dialyPrepareOne := models.DialysisBeforePrepare{
  9470. GoodTypeId: item.GoodTypeId,
  9471. GoodId: item.GoodId,
  9472. PatientId: his.PatientId,
  9473. RecordDate: item.RecordDate,
  9474. UserOrgId: adminUser.CurrentOrgId,
  9475. Count: item.Count,
  9476. Ctime: time.Now().Unix(),
  9477. Creater: adminUser.AdminUser.Id,
  9478. CommdityCode: item.CommdityCode,
  9479. Status: 1,
  9480. StorehouseId: houseConfig.StorehouseOutInfo,
  9481. }
  9482. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9483. //非零用
  9484. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9485. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9486. //查询剩余库存
  9487. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9488. var sum_count int64
  9489. for _, item := range goodList {
  9490. sum_count += item.StockCount
  9491. }
  9492. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9493. //耗材
  9494. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9495. }
  9496. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9497. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9498. //查询剩余库存
  9499. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9500. var sum_count int64
  9501. for _, item := range goodList {
  9502. sum_count += item.StockCount
  9503. }
  9504. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9505. //耗材
  9506. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9507. }
  9508. }
  9509. }
  9510. }
  9511. c.ServeSuccessJSON(map[string]interface{}{
  9512. "msg": "结算成功",
  9513. })
  9514. }
  9515. }
  9516. }
  9517. // 退款
  9518. func (c *HisApiController) Refund() {
  9519. order_id, _ := c.GetInt64("order_id")
  9520. order, _ := service.GetHisOrderByID(order_id)
  9521. adminUser := c.GetAdminUserInfo()
  9522. orgid := c.GetAdminUserInfo().CurrentOrgId
  9523. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9524. if err != nil {
  9525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9526. return
  9527. }
  9528. tmp := strconv.FormatInt(order.ID, 10)
  9529. //当押金不为零时产生退费记录
  9530. if order.Decimal != 0 {
  9531. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9532. if err != nil {
  9533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9534. return
  9535. }
  9536. }
  9537. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9538. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9539. var goods []*models.DialysisBeforePrepareGoods
  9540. var newGoods []*models.NewDialysisBeforePrepareGoods
  9541. var infos []*models.HisDoctorAdviceInfo
  9542. for _, info := range orders {
  9543. if info.AdviceId > 0 && info.ProjectId == 0 {
  9544. infos = append(infos, &info.HisDoctorAdviceInfo)
  9545. }
  9546. if info.ProjectId > 0 && info.AdviceId == 0 {
  9547. if info.HisPrescriptionProject.Type == 3 {
  9548. var good models.DialysisBeforePrepareGoods
  9549. var newGood models.NewDialysisBeforePrepareGoods
  9550. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9551. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9552. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9553. good.Count = int64(count)
  9554. good.StorehouseId = houseConfig.StorehouseOutInfo
  9555. good.ProjectId = info.HisPrescriptionProject.ID
  9556. good.PatientId = info.PatientId
  9557. good.OrderId = order_id
  9558. goods = append(goods, &good)
  9559. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9560. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9561. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9562. newGood.Count = int64(count2)
  9563. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9564. newGood.ProjectId = info.HisPrescriptionProject.ID
  9565. newGood.RecordDate = order.SettleAccountsDate
  9566. newGood.UserOrgId = order.UserOrgId
  9567. newGood.PatientId = info.PatientId
  9568. newGood.OrderId = order_id
  9569. newGoods = append(newGoods, &newGood)
  9570. }
  9571. }
  9572. }
  9573. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9574. if settConfig.IsOpen == 1 {
  9575. for _, item := range infos {
  9576. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9577. }
  9578. for _, item := range newGoods {
  9579. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9580. }
  9581. }
  9582. c.ServeSuccessJSON(map[string]interface{}{
  9583. "msg": "退费成功",
  9584. })
  9585. }
  9586. func (c *HisApiController) RefundNumber() {
  9587. his_patient_id, _ := c.GetInt64("id")
  9588. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9589. info.Status = 0
  9590. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9591. if count > 0 {
  9592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9593. return
  9594. }
  9595. err := service.SaveHisPatient(info)
  9596. if err == nil {
  9597. c.ServeSuccessJSON(map[string]interface{}{
  9598. "msg": "退号成功",
  9599. })
  9600. } else {
  9601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9602. return
  9603. }
  9604. }
  9605. func (this *HisApiController) AdditionalCharge() {
  9606. dataBody := make(map[string]interface{}, 0)
  9607. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9608. fmt.Println(err)
  9609. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9610. patient_id := int64(dataBody["patient_id"].(float64))
  9611. medicineData, _ := dataBody["medicineData"].([]interface{})
  9612. adminUserInfo := this.GetAdminUserInfo()
  9613. orgId := adminUserInfo.CurrentOrgId
  9614. admin_user_id := adminUserInfo.AdminUser.Id
  9615. timeStr := time.Now().Format("2006-01-02")
  9616. timeLayout := "2006-01-02 15:04:05"
  9617. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9618. timenow := timeStringToTime.Unix()
  9619. var additionalCharges []*models.HisAdditionalCharge
  9620. for _, item := range medicineData {
  9621. var randNum int
  9622. randNum = rand.Intn(10000) + 1000
  9623. timestamp := time.Now().Unix()
  9624. tempTime := time.Unix(timestamp, 0)
  9625. timeFormat := tempTime.Format("20060102150405")
  9626. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9627. items := item.(map[string]interface{})
  9628. money := items["price"].(string)
  9629. item_id_str := items["item_id"].(string)
  9630. name := items["name"].(string)
  9631. id_str := items["id"].(string)
  9632. moneys, _ := strconv.ParseInt(money, 10, 64)
  9633. monStr := strconv.FormatInt(moneys, 10)
  9634. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9635. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9636. id, _ := strconv.ParseInt(id_str, 10, 64)
  9637. additionalCharge := &models.HisAdditionalCharge{
  9638. ID: id,
  9639. HisPatientId: his_patient_id,
  9640. UserOrgId: orgId,
  9641. PatientId: patient_id,
  9642. RecordDate: timenow,
  9643. Price: monneyStr,
  9644. Status: 1,
  9645. ItemName: name,
  9646. ItemId: item_id,
  9647. AdminUserId: admin_user_id,
  9648. CreatedTime: time.Now().Unix(),
  9649. OrderStatus: 0,
  9650. PrescriptionNumber: "",
  9651. BatchNumber: "",
  9652. FeedetlSn: p_number,
  9653. }
  9654. service.CreateAdditionalCharge(additionalCharge)
  9655. additionalCharges = append(additionalCharges, additionalCharge)
  9656. }
  9657. this.ServeSuccessJSON(map[string]interface{}{
  9658. "msg": "添加成功",
  9659. "additional_charges": additionalCharges,
  9660. })
  9661. }
  9662. func (this *HisApiController) DeleteAddition() {
  9663. id, _ := this.GetInt64("id")
  9664. //TODO 需要判断是否已经结算
  9665. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9666. if err == nil {
  9667. this.ServeSuccessJSON(map[string]interface{}{
  9668. "msg": "删除成功",
  9669. })
  9670. return
  9671. } else {
  9672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9673. return
  9674. }
  9675. }
  9676. func (this *HisApiController) GetAdminUsers() {
  9677. adminUser := this.GetAdminUserInfo()
  9678. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9679. this.ServeSuccessJSON(map[string]interface{}{
  9680. "doctors": doctors,
  9681. })
  9682. }
  9683. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9684. change_type, _ := this.GetInt64("type", 0)
  9685. record_date := this.GetString("record_time")
  9686. patient_id, _ := this.GetInt64("patient_id", 0)
  9687. p_type, _ := this.GetInt64("p_type", 0)
  9688. timeLayout := "2006-01-02"
  9689. loc, _ := time.LoadLocation("Local")
  9690. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9691. record_time := theAdviceRecordTime.Unix()
  9692. adminUserInfo := this.GetAdminUserInfo()
  9693. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9694. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9695. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9696. if config.ID > 0 && config.IsOpen == 1 {
  9697. for _, subitems := range prescriptions {
  9698. for _, item := range subitems.VMHisPrescription {
  9699. for _, subItem := range item.HisDoctorAdviceInfo {
  9700. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9701. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9702. if info.RetailPrice > 0 {
  9703. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9704. subItem.Drug.RetailPrice = drug.RetailPrice
  9705. }
  9706. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9707. subItem.Drug.MinPrice = info.RetailPrice
  9708. subItem.Drug.RetailPrice = info.RetailPrice
  9709. }
  9710. }
  9711. }
  9712. }
  9713. }
  9714. }
  9715. if config.ID > 0 && config.IsOpen == 1 {
  9716. for _, subitems := range prescriptions {
  9717. for _, item := range subitems.VMHisPrescription {
  9718. for _, subItem := range item.HisPrescriptionProject {
  9719. if subItem.Type == 3 {
  9720. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9721. if info.Price > 0 {
  9722. subItem.GoodInfo.PackingPrice = info.Price
  9723. }
  9724. }
  9725. }
  9726. }
  9727. }
  9728. }
  9729. }
  9730. if err == nil {
  9731. if len(prescriptions) == 0 {
  9732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9733. return
  9734. } else {
  9735. this.ServeSuccessJSON(map[string]interface{}{
  9736. "prescriptions": prescriptions,
  9737. })
  9738. return
  9739. }
  9740. } else {
  9741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9742. return
  9743. }
  9744. }
  9745. func (this *HisApiController) GetCallHisPrescription() {
  9746. patient_id, _ := this.GetInt64("patient_id", 0)
  9747. timeLayout := "2006-01-02"
  9748. loc, _ := time.LoadLocation("Local")
  9749. start_time := this.GetString("start_time")
  9750. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9751. end_time := this.GetString("end_time")
  9752. p_type, _ := this.GetInt64("p_type")
  9753. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9754. adminUserInfo := this.GetAdminUserInfo()
  9755. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9756. //if
  9757. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9758. //
  9759. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9760. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9761. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9762. if config.ID > 0 && config.IsOpen == 1 {
  9763. for _, subitems := range prescriptions {
  9764. for _, item := range subitems.VMHisPrescription {
  9765. for _, subItem := range item.HisDoctorAdviceInfo {
  9766. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9767. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9768. if info.RetailPrice > 0 {
  9769. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9770. subItem.Drug.RetailPrice = drug.RetailPrice
  9771. }
  9772. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9773. subItem.Drug.MinPrice = info.RetailPrice
  9774. subItem.Drug.RetailPrice = info.RetailPrice
  9775. }
  9776. }
  9777. }
  9778. }
  9779. }
  9780. }
  9781. if config.ID > 0 && config.IsOpen == 1 {
  9782. for _, subitems := range prescriptions {
  9783. for _, item := range subitems.VMHisPrescription {
  9784. for _, subItem := range item.HisPrescriptionProject {
  9785. if subItem.Type == 3 {
  9786. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9787. if info.Price > 0 {
  9788. subItem.GoodInfo.PackingPrice = info.Price
  9789. }
  9790. }
  9791. }
  9792. }
  9793. }
  9794. }
  9795. }
  9796. if err == nil {
  9797. this.ServeSuccessJSON(map[string]interface{}{
  9798. "prescriptions": prescriptions,
  9799. })
  9800. return
  9801. } else {
  9802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9803. return
  9804. }
  9805. }
  9806. func (this *HisApiController) GetHisDayPrescription() {
  9807. timeLayout := "2006-01-02"
  9808. loc, _ := time.LoadLocation("Local")
  9809. start_time := this.GetString("start_time")
  9810. patient_id, _ := this.GetInt64("patient_id", 0)
  9811. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9812. end_time := this.GetString("end_time")
  9813. p_type, _ := this.GetInt64("p_type")
  9814. order_status, _ := this.GetInt64("type")
  9815. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9816. adminUserInfo := this.GetAdminUserInfo()
  9817. var dayHisPrescription []*models.HisPrescription
  9818. var err error
  9819. if order_status == 1 || order_status == 0 {
  9820. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9821. } else if order_status == 2 {
  9822. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9823. }
  9824. var settle_total float64
  9825. for _, item := range dayHisPrescription {
  9826. if len(item.HisPrescriptionProject) > 0 {
  9827. for _, subItem := range item.HisPrescriptionProject {
  9828. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9829. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9830. settle_total = settle_total + total
  9831. }
  9832. }
  9833. if len(item.HisDoctorAdviceInfo) > 0 {
  9834. for _, subItem := range item.HisDoctorAdviceInfo {
  9835. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9836. settle_total = settle_total + total
  9837. }
  9838. }
  9839. }
  9840. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9841. if err == nil {
  9842. this.ServeSuccessJSON(map[string]interface{}{
  9843. "day_prescription": dayHisPrescription,
  9844. "settle_total": settle_total,
  9845. })
  9846. return
  9847. } else {
  9848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9849. return
  9850. }
  9851. }
  9852. func (c *HisApiController) GetHisChargePatientList() {
  9853. record_date := c.GetString("record_date")
  9854. order_status, _ := c.GetInt64("type")
  9855. sch_type, _ := c.GetInt64("sch_type")
  9856. timeLayout := "2006-01-02"
  9857. loc, _ := time.LoadLocation("Local")
  9858. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9859. if err != nil {
  9860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9861. return
  9862. }
  9863. recordDateTime := theTime.Unix()
  9864. adminInfo := c.GetAdminUserInfo()
  9865. var tempPatients []*service.NewTempPatients
  9866. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9867. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9868. if order_status != 2 {
  9869. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9870. } else {
  9871. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9872. }
  9873. } else {
  9874. if order_status != 2 {
  9875. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9876. } else {
  9877. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9878. }
  9879. }
  9880. var patients []*service.NewTempPatients
  9881. var patients_two []*service.NewTempPatients
  9882. for _, item := range tempPatients {
  9883. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9884. //过滤掉没挂号的和没开处方的
  9885. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9886. patients = append(patients, item)
  9887. }
  9888. //过滤掉没挂号的
  9889. if len(item.HisPatient) > 0 {
  9890. patients_two = append(patients_two, item)
  9891. }
  9892. } else {
  9893. if len(item.HisPrescription) > 0 {
  9894. patients = append(patients, item)
  9895. }
  9896. }
  9897. }
  9898. c.ServeSuccessJSON(map[string]interface{}{
  9899. "list": patients,
  9900. "list_two": patients_two,
  9901. })
  9902. }
  9903. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9904. record_date := c.GetString("record_date")
  9905. timeLayout := "2006-01-02"
  9906. loc, _ := time.LoadLocation("Local")
  9907. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9908. if err != nil {
  9909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9910. return
  9911. }
  9912. recordDateTime := theTime.Unix()
  9913. adminUser := c.GetAdminUserInfo()
  9914. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9915. var patients []*service.Patients
  9916. for _, item := range tempPatients {
  9917. if item.HisPatient.ID == 0 {
  9918. patients = append(patients, item)
  9919. }
  9920. }
  9921. c.ServeSuccessJSON(map[string]interface{}{
  9922. "list": patients,
  9923. //"list_two": patients_two,
  9924. })
  9925. }
  9926. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9927. newArr = make([]*service.Patients, 0)
  9928. for i := 0; i < len(patient); i++ {
  9929. repeat := false
  9930. for j := i + 1; j < len(patient); j++ {
  9931. if patient[i].ID == patient[j].ID {
  9932. repeat = true
  9933. break
  9934. }
  9935. }
  9936. if !repeat {
  9937. newArr = append(newArr, patient[i])
  9938. }
  9939. }
  9940. return
  9941. }
  9942. func (c *HisApiController) GetHisChargePatientInfo() {
  9943. patient_id, _ := c.GetInt64("patient_id")
  9944. his_patient_id, _ := c.GetInt64("his_patient_id")
  9945. record_date := c.GetString("record_date")
  9946. //start_time := c.GetString("start_time")
  9947. //end_time := c.GetString("end_time")
  9948. order_status, _ := c.GetInt64("type", 0)
  9949. p_type, _ := c.GetInt64("p_type", 0)
  9950. order_id, _ := c.GetInt64("order_id", 0)
  9951. timeLayout := "2006-01-02"
  9952. loc, _ := time.LoadLocation("Local")
  9953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9954. if err != nil {
  9955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9956. return
  9957. }
  9958. recordDateTime := theTime.Unix()
  9959. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9960. //if err != nil {
  9961. //
  9962. //}
  9963. //startRecordDateTime := startTime.Unix()
  9964. //
  9965. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9966. //if err != nil {
  9967. //
  9968. //}
  9969. //endRecordDateTime := endTime.Unix()
  9970. admin := c.GetAdminUserInfo()
  9971. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9972. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9973. var prescriptions []*models.HisPrescription
  9974. //var unChargeMonthPrescriptions []*models.HisPrescription
  9975. order, _ := service.GetHisOrderByID(order_id)
  9976. if order_status == 1 || order_status == 0 {
  9977. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9978. } else if order_status == 2 {
  9979. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9980. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9981. }
  9982. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9983. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9984. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9985. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9986. //获取所有科室信息
  9987. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9988. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9989. c.ServeSuccessJSON(map[string]interface{}{
  9990. "his_info": his_patient_info,
  9991. "xt_info": xt_patient_info,
  9992. "prescription": prescriptions,
  9993. "case_history": case_history,
  9994. "info": patientPrescriptionInfo,
  9995. "last_info": lastPatientPrescriptionInfo,
  9996. "order": order,
  9997. "doctors": doctors,
  9998. "department": department,
  9999. "sch": sch,
  10000. })
  10001. return
  10002. }
  10003. func (c *HisApiController) GetAllOrderDetail() {
  10004. order_id, _ := c.GetInt64("id", 0)
  10005. order, _ := service.GetHisOrderByID(order_id)
  10006. if order.ID == 0 {
  10007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10008. return
  10009. }
  10010. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10011. org_id := c.GetAdminUserInfo().CurrentOrgId
  10012. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10013. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10014. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10015. c.ServeSuccessJSON(map[string]interface{}{
  10016. "order": order,
  10017. "order_info": order_info,
  10018. "patient": patient,
  10019. "admin_info": adminInfo,
  10020. "hospital_record": record,
  10021. })
  10022. return
  10023. }
  10024. func (c *HisApiController) GetAllOrderDetailCollect() {
  10025. order_id, _ := c.GetInt64("id", 0)
  10026. order, _ := service.GetHisOrderByID(order_id)
  10027. if order.ID == 0 {
  10028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10029. return
  10030. }
  10031. org_id := c.GetAdminUserInfo().CurrentOrgId
  10032. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10033. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10034. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10035. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10036. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10037. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10038. var bedCostTotal float64 = 0 //床位总费
  10039. //var bedCostSelfTotal float64 = 0 //床位自费
  10040. var operationCostTotal float64 = 0 //手术费
  10041. //var operationCostSelfTotal float64 = 0 //手术费
  10042. var otherCostTotal float64 = 0 //其他费用
  10043. //var otherCostSelfTotal float64 = 0 //其他费用
  10044. var materialCostTotal float64 = 0 //材料费
  10045. //var materialCostSelfTotal float64 = 0 //材料费
  10046. var westernMedicineCostTotal float64 = 0 //西药费
  10047. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10048. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10049. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10050. var checkCostTotal float64 = 0 //检查费
  10051. //var checkCostSelfTotal float64 = 0 //检查费
  10052. var laboratoryCostTotal float64 = 0 //化验费
  10053. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10054. var treatCostTotal float64 = 0 //治疗费用
  10055. //var treatCostSelfTotal float64 = 0 //治疗费用
  10056. var zhenChaCostTotal float64 = 0 //其他费用
  10057. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10058. decimal.DivisionPrecision = 2
  10059. var BalanceAccountsType int64
  10060. if his.ID > 0 {
  10061. BalanceAccountsType = his.BalanceAccountsType
  10062. } else {
  10063. BalanceAccountsType = record.BalanceAccountsType
  10064. }
  10065. if BalanceAccountsType != 2 {
  10066. for _, item := range order_info {
  10067. if org_id == 10215 {
  10068. if item.MedChrgitmType == "01" { //床位费
  10069. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10070. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10071. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10072. }
  10073. if item.MedChrgitmType == "02" { //诊察费
  10074. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10075. //zhenChaCostSelfTotal = zhenChaCostTotal
  10076. }
  10077. if item.MedChrgitmType == "03" { //检查费
  10078. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10079. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10080. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10081. }
  10082. //if item.MedChrgitmType == "02" { //检查费
  10083. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10084. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10085. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10086. //}
  10087. if item.MedChrgitmType == "04" { //化验费
  10088. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10089. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10090. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10091. }
  10092. if item.MedChrgitmType == "05" { //治疗费
  10093. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10094. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10095. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10096. }
  10097. if item.MedChrgitmType == "06" { //手术费
  10098. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10099. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10100. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10101. }
  10102. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10103. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10104. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10105. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10106. }
  10107. if item.MedChrgitmType == "09" { //西药费
  10108. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10109. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10110. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10111. }
  10112. if item.MedChrgitmType == "11" { //中成费
  10113. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10114. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10115. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10116. }
  10117. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10118. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10119. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10120. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10121. }
  10122. } else if org_id == 10188 || org_id == 10217 {
  10123. if item.MedChrgitmType == "01" { //床位费
  10124. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10125. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10126. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10127. }
  10128. if item.MedChrgitmType == "02" { //诊察费
  10129. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10130. //zhenChaCostSelfTotal = zhenChaCostTotal
  10131. }
  10132. if item.MedChrgitmType == "03" { //检查费
  10133. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10134. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10135. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10136. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10137. }
  10138. //if item.MedChrgitmType == "02" { //检查费
  10139. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10140. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10141. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10142. //}
  10143. if item.MedChrgitmType == "04" { //化验费
  10144. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10145. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10146. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10147. }
  10148. if item.MedChrgitmType == "05" { //治疗费
  10149. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10150. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10151. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10152. }
  10153. if item.MedChrgitmType == "06" { //手术费
  10154. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10155. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10156. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10157. }
  10158. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10159. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10160. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10161. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10162. }
  10163. if item.MedChrgitmType == "09" { //西药费
  10164. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10165. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10166. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10167. }
  10168. if item.MedChrgitmType == "11" { //中成费
  10169. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10170. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10171. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10172. }
  10173. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10174. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10175. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10176. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10177. }
  10178. } else {
  10179. if item.MedChrgitmType == "01" { //床位费
  10180. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10181. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10182. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10183. }
  10184. //if item.MedChrgitmType == "02" { //诊察费
  10185. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10186. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10187. //}
  10188. if item.MedChrgitmType == "03" { //检查费
  10189. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10190. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10191. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10192. }
  10193. //if item.MedChrgitmType == "02" { //检查费
  10194. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10195. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10196. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10197. //}
  10198. if item.MedChrgitmType == "04" { //化验费
  10199. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10200. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10201. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10202. }
  10203. if item.MedChrgitmType == "05" { //治疗费
  10204. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10205. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10206. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10207. }
  10208. if item.MedChrgitmType == "06" { //手术费
  10209. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10210. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10211. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10212. }
  10213. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10214. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10215. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10216. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10217. }
  10218. if item.MedChrgitmType == "09" { //西药费
  10219. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10220. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10221. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10222. }
  10223. if item.MedChrgitmType == "11" { //中成费
  10224. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10225. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10226. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10227. }
  10228. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10229. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10230. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10231. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10232. }
  10233. }
  10234. }
  10235. c.ServeSuccessJSON(map[string]interface{}{
  10236. "order": order,
  10237. "order_info": order_info,
  10238. "patient": patient,
  10239. "admin_info": adminInfo,
  10240. "his_hospital": record,
  10241. "bedCostTotal": bedCostTotal,
  10242. "operationCostTotal": operationCostTotal,
  10243. "otherCostTotal": otherCostTotal,
  10244. "materialCostTotal": materialCostTotal,
  10245. "westernMedicineCostTotal": westernMedicineCostTotal,
  10246. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10247. "checkCostTotal": checkCostTotal,
  10248. "zhenChaCostTotal": zhenChaCostTotal,
  10249. "laboratoryCostTotal": laboratoryCostTotal,
  10250. "treatCostTotal": treatCostTotal,
  10251. })
  10252. } else {
  10253. for _, item := range order_info {
  10254. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10255. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10256. item.MedChrgitmType = "09"
  10257. }
  10258. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10259. if item.HisPrescriptionProject.Type == 2 {
  10260. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10261. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10262. case 0:
  10263. item.MedChrgitmType = "0"
  10264. break
  10265. case 1:
  10266. item.MedChrgitmType = "14"
  10267. break
  10268. case 2:
  10269. item.MedChrgitmType = "05"
  10270. break
  10271. case 3:
  10272. item.MedChrgitmType = "03"
  10273. break
  10274. case 4:
  10275. item.MedChrgitmType = "03"
  10276. break
  10277. case 5:
  10278. item.MedChrgitmType = "08"
  10279. break
  10280. case 6:
  10281. item.MedChrgitmType = "14"
  10282. break
  10283. case 7:
  10284. item.MedChrgitmType = "14"
  10285. break
  10286. case 8:
  10287. item.MedChrgitmType = "03"
  10288. break
  10289. case 9:
  10290. item.MedChrgitmType = "14"
  10291. break
  10292. case 10:
  10293. item.MedChrgitmType = "14"
  10294. break
  10295. case 11:
  10296. item.MedChrgitmType = "06"
  10297. break
  10298. case 12:
  10299. item.MedChrgitmType = "12"
  10300. break
  10301. case 13:
  10302. item.MedChrgitmType = "01"
  10303. break
  10304. case 14:
  10305. item.MedChrgitmType = "04"
  10306. break
  10307. case 15:
  10308. item.MedChrgitmType = "14"
  10309. break
  10310. }
  10311. } else {
  10312. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10313. case 1:
  10314. item.MedChrgitmType = "14"
  10315. break
  10316. case 2:
  10317. item.MedChrgitmType = "05"
  10318. break
  10319. case 3:
  10320. item.MedChrgitmType = "04"
  10321. break
  10322. case 4:
  10323. item.MedChrgitmType = "14"
  10324. break
  10325. case 5:
  10326. item.MedChrgitmType = "08"
  10327. break
  10328. case 6:
  10329. item.MedChrgitmType = "14"
  10330. break
  10331. case 7:
  10332. item.MedChrgitmType = "14"
  10333. break
  10334. case 8:
  10335. item.MedChrgitmType = "03"
  10336. break
  10337. case 9:
  10338. item.MedChrgitmType = "14"
  10339. break
  10340. }
  10341. }
  10342. } else if item.HisPrescriptionProject.Type == 3 {
  10343. item.MedChrgitmType = "08"
  10344. }
  10345. }
  10346. }
  10347. for _, item := range order_info {
  10348. if org_id == 10215 {
  10349. if item.MedChrgitmType == "01" { //床位费
  10350. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10351. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10352. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10353. }
  10354. if item.MedChrgitmType == "02" { //诊察费
  10355. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10356. //zhenChaCostSelfTotal = zhenChaCostTotal
  10357. }
  10358. if item.MedChrgitmType == "03" { //检查费
  10359. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10360. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10361. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10362. }
  10363. //if item.MedChrgitmType == "02" { //检查费
  10364. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10365. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10366. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10367. //}
  10368. if item.MedChrgitmType == "04" { //化验费
  10369. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10370. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10371. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10372. }
  10373. if item.MedChrgitmType == "05" { //治疗费
  10374. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10375. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10376. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10377. }
  10378. if item.MedChrgitmType == "06" { //手术费
  10379. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10380. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10381. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10382. }
  10383. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10384. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10385. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10386. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10387. }
  10388. if item.MedChrgitmType == "09" { //西药费
  10389. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. }
  10393. if item.MedChrgitmType == "11" { //中成费
  10394. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10395. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10396. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10397. }
  10398. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10399. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10400. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10401. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10402. }
  10403. } else {
  10404. if item.MedChrgitmType == "01" { //床位费
  10405. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10406. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10407. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10408. }
  10409. //if item.MedChrgitmType == "02" { //诊察费
  10410. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10411. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10412. //}
  10413. if item.MedChrgitmType == "03" { //检查费
  10414. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10415. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10416. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10417. }
  10418. //if item.MedChrgitmType == "02" { //检查费
  10419. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10420. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10421. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10422. //}
  10423. if item.MedChrgitmType == "04" { //化验费
  10424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10425. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10426. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10427. }
  10428. if item.MedChrgitmType == "05" { //治疗费
  10429. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10430. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10431. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10432. }
  10433. if item.MedChrgitmType == "06" { //手术费
  10434. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10435. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10436. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10437. }
  10438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10440. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10441. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10442. }
  10443. if item.MedChrgitmType == "09" { //西药费
  10444. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10445. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10446. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10447. }
  10448. if item.MedChrgitmType == "11" { //中成费
  10449. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10450. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10451. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10452. }
  10453. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10454. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10455. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10456. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10457. }
  10458. }
  10459. }
  10460. c.ServeSuccessJSON(map[string]interface{}{
  10461. "order": order,
  10462. "order_info": order_info,
  10463. "patient": patient,
  10464. "admin_info": adminInfo,
  10465. "his_hospital": record,
  10466. "bedCostTotal": bedCostTotal,
  10467. "operationCostTotal": operationCostTotal,
  10468. "otherCostTotal": otherCostTotal,
  10469. "materialCostTotal": materialCostTotal,
  10470. "westernMedicineCostTotal": westernMedicineCostTotal,
  10471. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10472. "checkCostTotal": checkCostTotal,
  10473. "zhenChaCostTotal": zhenChaCostTotal,
  10474. "laboratoryCostTotal": laboratoryCostTotal,
  10475. "treatCostTotal": treatCostTotal,
  10476. })
  10477. }
  10478. }
  10479. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10480. page, _ := c.GetInt64("page")
  10481. limit, _ := c.GetInt64("limit")
  10482. keywords := c.GetString("keywords")
  10483. start_time := c.GetString("start_time")
  10484. end_time := c.GetString("end_time")
  10485. //clr_type := c.GetString("clr_type")
  10486. insutype := c.GetString("insutype")
  10487. timeLayout := "2006-01-02"
  10488. loc, _ := time.LoadLocation("Local")
  10489. var theStartTIme int64
  10490. if len(start_time) > 0 {
  10491. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10492. theStartTIme = theTime.Unix()
  10493. }
  10494. var theEndtTIme int64
  10495. if len(end_time) > 0 {
  10496. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10497. theEndtTIme = theTime.Unix()
  10498. }
  10499. if page <= 0 {
  10500. page = 1
  10501. }
  10502. if limit <= 0 {
  10503. limit = 10
  10504. }
  10505. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10506. c.ServeSuccessJSON(map[string]interface{}{
  10507. "total": total,
  10508. "list": list,
  10509. })
  10510. return
  10511. }
  10512. func (c *HisApiController) GetPutOnRecordList() {
  10513. page, _ := c.GetInt64("page")
  10514. limit, _ := c.GetInt64("limit")
  10515. keywords := c.GetString("keywords")
  10516. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10517. if page <= 0 {
  10518. page = 1
  10519. }
  10520. if limit <= 0 {
  10521. limit = 10
  10522. }
  10523. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10524. c.ServeSuccessJSON(map[string]interface{}{
  10525. "total": total,
  10526. "list": list,
  10527. })
  10528. return
  10529. }
  10530. func (c *HisApiController) GetCompareData() {
  10531. start_time := c.GetString("start_time")
  10532. end_time := c.GetString("end_time")
  10533. insutype := c.GetString("insutype")
  10534. clr_type := c.GetString("clr_type")
  10535. timeLayout := "2006-01-02"
  10536. loc, _ := time.LoadLocation("Local")
  10537. var theStartTIme int64
  10538. if len(start_time) > 0 {
  10539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10540. if err != nil {
  10541. theStartTIme = 0
  10542. }
  10543. theStartTIme = theTime.Unix()
  10544. }
  10545. var theEndtTIme int64
  10546. if len(end_time) > 0 {
  10547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10548. if err != nil {
  10549. theEndtTIme = 0
  10550. }
  10551. theEndtTIme = theTime.Unix()
  10552. }
  10553. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10554. fmt.Println(err)
  10555. if err == nil {
  10556. c.ServeSuccessJSON(map[string]interface{}{
  10557. "list": formData,
  10558. })
  10559. } else {
  10560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10561. return
  10562. }
  10563. }
  10564. func (c *HisApiController) GetFaPiaoData() {
  10565. order_id, _ := c.GetInt64("order_id")
  10566. patient_id, _ := c.GetInt64("patient_id")
  10567. //number := c.GetString("number")
  10568. adminUser := c.GetAdminUserInfo()
  10569. order, _ := service.GetHisOrderByID(order_id)
  10570. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10571. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10572. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10573. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10574. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10575. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10576. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10577. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10578. var bedCostTotal float64 = 0 //床位总费
  10579. var bedCostSelfTotal float64 = 0 //床位自费
  10580. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10581. var operationCostTotal float64 = 0 //手术费
  10582. var operationCostSelfTotal float64 = 0 //手术费
  10583. var operationCostPartSelfTotal float64 = 0 //手术费
  10584. var otherCostTotal float64 = 0 //其他费用
  10585. var otherCostSelfTotal float64 = 0 //其他费用
  10586. var otherCostPartSelfTotal float64 = 0 //其他费用
  10587. var materialCostTotal float64 = 0 //材料费
  10588. var materialCostSelfTotal float64 = 0 //材料费
  10589. var materialCostPartSelfTotal float64 = 0 //材料费
  10590. var westernMedicineCostTotal float64 = 0 //西药费
  10591. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10592. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10593. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10594. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10595. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10596. var checkCostTotal float64 = 0 //检查费
  10597. var checkCostSelfTotal float64 = 0 //检查费
  10598. var checkCostPartSelfTotal float64 = 0 //检查费
  10599. var hiliCostTotal float64 = 0 //护理费
  10600. var hiliCostSelfTotal float64 = 0 //护理费
  10601. var hiliCostPartSelfTotal float64 = 0 //护理费
  10602. var laboratoryCostTotal float64 = 0 //化验费
  10603. var laboratoryCostSelfTotal float64 = 0 //化验费
  10604. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10605. var treatCostTotal float64 = 0 //治疗费用
  10606. var treatCostSelfTotal float64 = 0 //治疗费用
  10607. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10608. var zhenChaCostTotal float64 = 0 //其他费用
  10609. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10610. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10611. decimal.DivisionPrecision = 2
  10612. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10613. var balanceAccountsType int64
  10614. if his.ID > 0 {
  10615. balanceAccountsType = his.BalanceAccountsType
  10616. } else {
  10617. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10618. }
  10619. if balanceAccountsType == 2 {
  10620. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10621. for _, item := range orderInfos_two {
  10622. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10623. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10624. item.MedChrgitmType = "09"
  10625. }
  10626. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10627. if item.HisPrescriptionProject.Type == 2 {
  10628. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10629. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10630. case 0:
  10631. item.MedChrgitmType = "0"
  10632. break
  10633. case 1:
  10634. item.MedChrgitmType = "14"
  10635. break
  10636. case 2:
  10637. item.MedChrgitmType = "05"
  10638. break
  10639. case 3:
  10640. item.MedChrgitmType = "03"
  10641. break
  10642. case 4:
  10643. item.MedChrgitmType = "03"
  10644. break
  10645. case 5:
  10646. item.MedChrgitmType = "08"
  10647. break
  10648. case 6:
  10649. item.MedChrgitmType = "14"
  10650. break
  10651. case 7:
  10652. item.MedChrgitmType = "14"
  10653. break
  10654. case 8:
  10655. item.MedChrgitmType = "03"
  10656. break
  10657. case 9:
  10658. item.MedChrgitmType = "14"
  10659. break
  10660. case 10:
  10661. item.MedChrgitmType = "14"
  10662. break
  10663. case 11:
  10664. item.MedChrgitmType = "06"
  10665. break
  10666. case 12:
  10667. item.MedChrgitmType = "12"
  10668. break
  10669. case 13:
  10670. item.MedChrgitmType = "01"
  10671. break
  10672. case 14:
  10673. item.MedChrgitmType = "04"
  10674. break
  10675. case 15:
  10676. item.MedChrgitmType = "02"
  10677. break
  10678. }
  10679. } else {
  10680. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10681. case 1:
  10682. item.MedChrgitmType = "14"
  10683. break
  10684. case 2:
  10685. item.MedChrgitmType = "05"
  10686. break
  10687. case 3:
  10688. item.MedChrgitmType = "04"
  10689. break
  10690. case 4:
  10691. item.MedChrgitmType = "03"
  10692. break
  10693. case 5:
  10694. item.MedChrgitmType = "08"
  10695. break
  10696. case 6:
  10697. item.MedChrgitmType = "14"
  10698. break
  10699. case 7:
  10700. item.MedChrgitmType = "14"
  10701. break
  10702. case 8:
  10703. item.MedChrgitmType = "03"
  10704. break
  10705. case 9:
  10706. item.MedChrgitmType = "14"
  10707. break
  10708. }
  10709. }
  10710. } else if item.HisPrescriptionProject.Type == 3 {
  10711. item.MedChrgitmType = "08"
  10712. }
  10713. }
  10714. }
  10715. for _, item := range orderInfos_two {
  10716. fmt.Println(item.MedChrgitmType)
  10717. if item.MedChrgitmType == "07" { //床位费
  10718. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10719. hiliCostSelfTotal = hiliCostTotal
  10720. }
  10721. if item.MedChrgitmType == "01" { //床位费
  10722. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. bedCostSelfTotal = bedCostTotal
  10724. }
  10725. if item.MedChrgitmType == "02" { //诊察费
  10726. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10727. zhenChaCostSelfTotal = zhenChaCostTotal
  10728. }
  10729. if item.MedChrgitmType == "03" { //检查费
  10730. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10731. checkCostSelfTotal = checkCostTotal
  10732. }
  10733. if item.MedChrgitmType == "04" { //化验费
  10734. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10735. laboratoryCostSelfTotal = laboratoryCostTotal
  10736. }
  10737. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10738. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10739. treatCostSelfTotal = treatCostTotal
  10740. }
  10741. if item.MedChrgitmType == "06" { //手术费
  10742. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10743. operationCostSelfTotal = treatCostTotal
  10744. }
  10745. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10746. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10747. materialCostSelfTotal = materialCostTotal
  10748. }
  10749. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10750. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10751. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10752. }
  10753. if item.MedChrgitmType == "11" { //中成费
  10754. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10755. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10756. }
  10757. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10758. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10759. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10760. otherCostSelfTotal = otherCostTotal
  10761. }
  10762. } else {
  10763. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10764. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10765. otherCostSelfTotal = otherCostTotal
  10766. }
  10767. }
  10768. }
  10769. } else {
  10770. for _, item := range orderInfos {
  10771. if item.MedChrgitmType == "01" { //床位费
  10772. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10773. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10774. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10775. }
  10776. if item.MedChrgitmType == "02" { //诊察费
  10777. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10778. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10779. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10780. }
  10781. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10782. if item.MedChrgitmType == "03" { //检查费
  10783. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10784. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10785. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10786. }
  10787. } else {
  10788. if item.MedChrgitmType == "03" { //检查费
  10789. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. }
  10793. }
  10794. if item.MedChrgitmType == "04" { //化验费
  10795. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10796. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10797. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10798. }
  10799. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10800. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10801. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10802. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10803. }
  10804. if item.MedChrgitmType == "06" { //手术费
  10805. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10806. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10807. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10808. }
  10809. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10810. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10811. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10812. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10813. }
  10814. if item.MedChrgitmType == "07" { //护理
  10815. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10816. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10817. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10818. }
  10819. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10820. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10821. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10822. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10823. }
  10824. if item.MedChrgitmType == "11" { //中成费
  10825. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10826. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10827. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10828. }
  10829. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10830. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. }
  10834. }
  10835. }
  10836. timeLayout := "2006-01-02"
  10837. loc, _ := time.LoadLocation("Local")
  10838. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10839. if err != nil {
  10840. }
  10841. startRecordDateTime := startTime.Unix()
  10842. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10843. if err != nil {
  10844. }
  10845. endRecordDateTime := endTime.Unix()
  10846. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10847. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10848. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10849. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10850. c.ServeSuccessJSON(map[string]interface{}{
  10851. "charge_admin_name": charge_admin.UserName,
  10852. "order_number": order.Number, //业务流水号
  10853. "id_card_no": his.IdCardNo, //社会保障号
  10854. "patient": patient,
  10855. "department_name": department.Name, //科室
  10856. "number": his.Number, //门诊号
  10857. "date": order.SettleAccountsDate, //结算日期
  10858. "name": order.PsnName, //姓名
  10859. "gender": patient.Gender, //性别
  10860. "psn_cash_money": order.PsnCashPay, //个人支付
  10861. "pay_way": "门诊", //结算方式
  10862. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10863. "admin_user_name": admin.UserName, //收款员
  10864. "order": order,
  10865. "order_info": orderInfos_two,
  10866. "his": his,
  10867. "bedCostTotal": bedCostTotal,
  10868. "bedCostSelfTotal": bedCostSelfTotal,
  10869. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10870. "operationCostTotal": operationCostTotal,
  10871. "operationCostSelfTotal": operationCostSelfTotal,
  10872. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10873. "otherCostTotal": otherCostTotal,
  10874. "otherCostSelfTotal": otherCostSelfTotal,
  10875. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10876. "materialCostTotal": materialCostTotal,
  10877. "materialCostSelfTotal": materialCostSelfTotal,
  10878. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10879. "westernMedicineCostTotal": westernMedicineCostTotal,
  10880. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10881. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10882. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10883. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10884. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10885. "checkCostTotal": checkCostTotal,
  10886. "checkCostSelfTotal": checkCostSelfTotal,
  10887. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10888. "laboratoryCostTotal": laboratoryCostTotal,
  10889. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10890. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10891. "treatCostTotal": treatCostTotal,
  10892. "treatCostSelfTotal": treatCostSelfTotal,
  10893. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10894. "zhenChaCostTotal": zhenChaCostTotal,
  10895. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10896. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10897. "his_hospital_record": his_hospital_record,
  10898. "pre_pay_money": pre_pay_money,
  10899. "refund_sum": sum,
  10900. "doctor_info": doctor_info,
  10901. "hiliCostTotal": hiliCostTotal,
  10902. "hiliCostSelfTotal": hiliCostSelfTotal,
  10903. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10904. })
  10905. }
  10906. //func (c *HisApiController) GetFaPiaoDatas() {
  10907. // order_ids := c.GetString("order_ids")
  10908. // patient_id, _ := c.GetInt64("patient_id")
  10909. // adminUser := c.GetAdminUserInfo()
  10910. //
  10911. // orders := strings.Split(order_ids, ",")
  10912. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10913. //
  10914. // for _, item := range orders {
  10915. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10916. // order, _ := service.GetHisOrderByID(order_id)
  10917. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10918. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10919. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10920. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10921. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10922. //
  10923. // }
  10924. //
  10925. // var bedCostTotal float64 = 0 //床位总费
  10926. // var bedCostSelfTotal float64 = 0 //床位自费
  10927. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10928. //
  10929. // var operationCostTotal float64 = 0 //手术费
  10930. // var operationCostSelfTotal float64 = 0 //手术费
  10931. // var operationCostPartSelfTotal float64 = 0 //手术费
  10932. //
  10933. // var otherCostTotal float64 = 0 //其他费用
  10934. // var otherCostSelfTotal float64 = 0 //其他费用
  10935. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10936. //
  10937. // var materialCostTotal float64 = 0 //材料费
  10938. // var materialCostSelfTotal float64 = 0 //材料费
  10939. // var materialCostPartSelfTotal float64 = 0 //材料费
  10940. //
  10941. // var westernMedicineCostTotal float64 = 0 //西药费
  10942. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10943. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10944. //
  10945. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10946. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10947. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10948. //
  10949. // var checkCostTotal float64 = 0 //检查费
  10950. // var checkCostSelfTotal float64 = 0 //检查费
  10951. // var checkCostPartSelfTotal float64 = 0 //检查费
  10952. //
  10953. // var laboratoryCostTotal float64 = 0 //化验费
  10954. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10955. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10956. //
  10957. // var treatCostTotal float64 = 0 //治疗费用
  10958. // var treatCostSelfTotal float64 = 0 //治疗费用
  10959. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10960. //
  10961. // var zhenChaCostTotal float64 = 0 //其他费用
  10962. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10963. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10964. //
  10965. // decimal.DivisionPrecision = 2
  10966. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10967. //
  10968. // var balanceAccountsType int64
  10969. // if his.ID > 0 {
  10970. // balanceAccountsType = his.BalanceAccountsType
  10971. // } else {
  10972. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10973. // }
  10974. // if balanceAccountsType == 2 {
  10975. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10976. // for _, item := range orderInfos_two {
  10977. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10978. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10979. // item.MedChrgitmType = "09"
  10980. // }
  10981. //
  10982. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10983. // if item.HisPrescriptionProject.Type == 2 {
  10984. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10985. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10986. // case 0:
  10987. // item.MedChrgitmType = "0"
  10988. // break
  10989. // case 1:
  10990. // item.MedChrgitmType = "14"
  10991. // break
  10992. // case 2:
  10993. // item.MedChrgitmType = "05"
  10994. //
  10995. // break
  10996. // case 3:
  10997. // item.MedChrgitmType = "03"
  10998. //
  10999. // break
  11000. // case 4:
  11001. // item.MedChrgitmType = "03"
  11002. //
  11003. // break
  11004. // case 5:
  11005. // item.MedChrgitmType = "08"
  11006. //
  11007. // break
  11008. // case 6:
  11009. // item.MedChrgitmType = "14"
  11010. //
  11011. // break
  11012. // case 7:
  11013. // item.MedChrgitmType = "14"
  11014. //
  11015. // break
  11016. // case 8:
  11017. // item.MedChrgitmType = "03"
  11018. // break
  11019. // case 9:
  11020. // item.MedChrgitmType = "14"
  11021. // break
  11022. // case 10:
  11023. // item.MedChrgitmType = "14"
  11024. // break
  11025. // case 11:
  11026. // item.MedChrgitmType = "06"
  11027. // break
  11028. // case 12:
  11029. // item.MedChrgitmType = "12"
  11030. // break
  11031. // case 13:
  11032. // item.MedChrgitmType = "01"
  11033. // break
  11034. // case 14:
  11035. // item.MedChrgitmType = "04"
  11036. // break
  11037. // case 15:
  11038. // item.MedChrgitmType = "02"
  11039. // break
  11040. //
  11041. // }
  11042. //
  11043. // } else {
  11044. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11045. //
  11046. // case 1:
  11047. // item.MedChrgitmType = "14"
  11048. // break
  11049. // case 2:
  11050. // item.MedChrgitmType = "05"
  11051. //
  11052. // break
  11053. // case 3:
  11054. // item.MedChrgitmType = "03"
  11055. //
  11056. // break
  11057. // case 4:
  11058. // item.MedChrgitmType = "03"
  11059. //
  11060. // break
  11061. // case 5:
  11062. // item.MedChrgitmType = "08"
  11063. //
  11064. // break
  11065. // case 6:
  11066. // item.MedChrgitmType = "14"
  11067. //
  11068. // break
  11069. // case 7:
  11070. // item.MedChrgitmType = "14"
  11071. //
  11072. // break
  11073. // case 8:
  11074. // item.MedChrgitmType = "03"
  11075. // break
  11076. // case 9:
  11077. // item.MedChrgitmType = "14"
  11078. // break
  11079. //
  11080. // }
  11081. //
  11082. // }
  11083. //
  11084. // } else if item.HisPrescriptionProject.Type == 3 {
  11085. // item.MedChrgitmType = "08"
  11086. // }
  11087. // }
  11088. // }
  11089. //
  11090. // for _, item := range orderInfos_two {
  11091. // fmt.Println(item.MedChrgitmType)
  11092. // if item.MedChrgitmType == "01" { //床位费
  11093. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11094. // bedCostSelfTotal = bedCostTotal
  11095. // }
  11096. //
  11097. // if item.MedChrgitmType == "02" { //诊察费
  11098. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11099. // zhenChaCostSelfTotal = zhenChaCostTotal
  11100. // }
  11101. //
  11102. // if item.MedChrgitmType == "03" { //检查费
  11103. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11104. // checkCostSelfTotal = checkCostTotal
  11105. // }
  11106. //
  11107. // if item.MedChrgitmType == "04" { //化验费
  11108. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11109. // laboratoryCostSelfTotal = laboratoryCostTotal
  11110. // }
  11111. //
  11112. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11113. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11114. // treatCostSelfTotal = treatCostTotal
  11115. // }
  11116. //
  11117. // if item.MedChrgitmType == "06" { //手术费
  11118. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11119. // operationCostSelfTotal = treatCostTotal
  11120. // }
  11121. //
  11122. // if item.MedChrgitmType == "08" { //材料费
  11123. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11124. // materialCostSelfTotal = materialCostTotal
  11125. // }
  11126. //
  11127. // if item.MedChrgitmType == "09" { //西药费
  11128. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11129. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11130. // }
  11131. //
  11132. // if item.MedChrgitmType == "11" { //中成费
  11133. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11134. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11135. // }
  11136. //
  11137. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11138. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11139. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11140. // otherCostSelfTotal = otherCostTotal
  11141. // }
  11142. // } else {
  11143. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11144. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11145. // otherCostSelfTotal = otherCostTotal
  11146. // }
  11147. //
  11148. // }
  11149. //
  11150. // }
  11151. //
  11152. // } else {
  11153. // for _, item := range orderInfos {
  11154. // if item.MedChrgitmType == "01" { //床位费
  11155. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11156. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11157. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11158. // }
  11159. //
  11160. // if item.MedChrgitmType == "02" { //诊察费
  11161. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11162. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11163. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11164. // }
  11165. //
  11166. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11167. // if item.MedChrgitmType == "03" { //检查费
  11168. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11169. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11170. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11171. //
  11172. // }
  11173. // } else {
  11174. // if item.MedChrgitmType == "03" { //检查费
  11175. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11176. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11177. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11178. // }
  11179. //
  11180. // }
  11181. //
  11182. // if item.MedChrgitmType == "04" { //化验费
  11183. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11184. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11185. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11186. //
  11187. // }
  11188. //
  11189. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11190. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11191. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11192. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11193. //
  11194. // }
  11195. //
  11196. // if item.MedChrgitmType == "06" { //手术费
  11197. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11198. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11199. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11200. // }
  11201. //
  11202. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11203. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11204. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11205. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11206. // }
  11207. //
  11208. // if item.MedChrgitmType == "09" { //西药费
  11209. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11210. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11211. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11212. // }
  11213. //
  11214. // if item.MedChrgitmType == "11" { //中成费
  11215. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11216. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11217. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11218. // }
  11219. //
  11220. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11221. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11222. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11223. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11224. // }
  11225. //
  11226. // }
  11227. // }
  11228. // timeLayout := "2006-01-02"
  11229. // loc, _ := time.LoadLocation("Local")
  11230. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11231. // if err != nil {
  11232. // }
  11233. // startRecordDateTime := startTime.Unix()
  11234. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11235. // if err != nil {
  11236. // }
  11237. // endRecordDateTime := endTime.Unix()
  11238. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11239. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11240. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11241. //
  11242. // c.ServeSuccessJSON(map[string]interface{}{
  11243. // "order_number": order.Number, //业务流水号
  11244. // "id_card_no": his.IdCardNo, //社会保障号
  11245. // "department_name": department.Name, //科室
  11246. // "number": his.Number, //门诊号
  11247. // "date": order.SettleAccountsDate, //结算日期
  11248. // "name": order.PsnName, //姓名
  11249. // "gender": patient.Gender, //性别
  11250. // "psn_cash_money": order.PsnCashPay, //个人支付
  11251. // "pay_way": "门诊", //结算方式
  11252. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11253. // "admin_user_name": admin.UserName, //收款员
  11254. // "order": order,
  11255. // "order_info": orderInfos_two,
  11256. // "his": his,
  11257. // "bedCostTotal": bedCostTotal,
  11258. // "bedCostSelfTotal": bedCostSelfTotal,
  11259. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11260. // "operationCostTotal": operationCostTotal,
  11261. // "operationCostSelfTotal": operationCostSelfTotal,
  11262. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11263. // "otherCostTotal": otherCostTotal,
  11264. // "otherCostSelfTotal": otherCostSelfTotal,
  11265. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11266. // "materialCostTotal": materialCostTotal,
  11267. // "materialCostSelfTotal": materialCostSelfTotal,
  11268. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11269. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11270. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11271. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11272. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11273. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11274. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11275. // "checkCostTotal": checkCostTotal,
  11276. // "checkCostSelfTotal": checkCostSelfTotal,
  11277. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11278. // "laboratoryCostTotal": laboratoryCostTotal,
  11279. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11280. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11281. // "treatCostTotal": treatCostTotal,
  11282. // "treatCostSelfTotal": treatCostSelfTotal,
  11283. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11284. // "zhenChaCostTotal": zhenChaCostTotal,
  11285. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11286. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11287. // "his_hospital_record": his_hospital_record,
  11288. // "pre_pay_money": pre_pay_money,
  11289. // "refund_sum": sum,
  11290. // })
  11291. //
  11292. //}
  11293. func (this *HisApiController) GetIncomeStatisticsData() {
  11294. start_time := this.GetString("start_time")
  11295. end_time := this.GetString("end_time")
  11296. key_words := this.GetString("key_words")
  11297. limit, _ := this.GetInt64("limit")
  11298. page, _ := this.GetInt64("page")
  11299. if page <= 0 {
  11300. page = 1
  11301. }
  11302. if limit <= 0 {
  11303. limit = 10
  11304. }
  11305. statistics_type, _ := this.GetInt64("statistics_type")
  11306. admin := this.GetAdminUserInfo()
  11307. timeLayout := "2006-01-02"
  11308. loc, _ := time.LoadLocation("Local")
  11309. var theStartTIme int64
  11310. if len(start_time) > 0 {
  11311. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11312. if err != nil {
  11313. theStartTIme = 0
  11314. }
  11315. theStartTIme = theTime.Unix()
  11316. }
  11317. var theEndtTIme int64
  11318. if len(end_time) > 0 {
  11319. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11320. if err != nil {
  11321. theEndtTIme = 0
  11322. }
  11323. theEndtTIme = theTime.Unix()
  11324. }
  11325. if statistics_type == 1 {
  11326. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11327. this.ServeSuccessJSON(map[string]interface{}{
  11328. "list": list,
  11329. "total": total,
  11330. })
  11331. } else {
  11332. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11333. this.ServeSuccessJSON(map[string]interface{}{
  11334. "list": list,
  11335. "total": total,
  11336. })
  11337. }
  11338. }
  11339. func (c *HisApiController) PostProjectInformation() {
  11340. adminUser := c.GetAdminUserInfo()
  11341. orgId := adminUser.CurrentOrgId
  11342. dataBody := make(map[string]interface{}, 0)
  11343. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11344. if err != nil {
  11345. utils.ErrorLog(err.Error())
  11346. return
  11347. }
  11348. utils.ErrorLog("%v", dataBody)
  11349. var projectList []*models.HisProject
  11350. var total_goods []interface{}
  11351. tempProjects := dataBody["projects"].([]interface{})
  11352. total_goods = tempProjects
  11353. for index, projectMap := range tempProjects {
  11354. projectM := projectMap.(map[string]interface{})
  11355. var project models.HisProject
  11356. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11357. utils.ErrorLog("project_name")
  11358. return
  11359. }
  11360. project_name, _ := projectM["project_name"].(string)
  11361. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11362. err_log := models.ExportErrLog{
  11363. LogType: 6,
  11364. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11365. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11366. Status: 1,
  11367. CreateTime: time.Now().Unix(),
  11368. UpdateTime: time.Now().Unix(),
  11369. ExportTime: time.Now().Unix(),
  11370. }
  11371. service.CreateExportErrLog(&err_log)
  11372. continue
  11373. }
  11374. project.ProjectName = project_name
  11375. prices := projectM["price"].(string)
  11376. price, _ := strconv.ParseFloat(prices, 64)
  11377. if price <= 0 { //名字为空则生成一条导入错误日志
  11378. err_log := models.ExportErrLog{
  11379. LogType: 6,
  11380. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11381. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11382. Status: 1,
  11383. CreateTime: time.Now().Unix(),
  11384. UpdateTime: time.Now().Unix(),
  11385. ExportTime: time.Now().Unix(),
  11386. }
  11387. service.CreateExportErrLog(&err_log)
  11388. continue
  11389. }
  11390. project.Price = price
  11391. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11392. utils.ErrorLog("unit_id")
  11393. return
  11394. }
  11395. unit := projectM["unit"].(string)
  11396. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11397. err_log := models.ExportErrLog{
  11398. LogType: 6,
  11399. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11400. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11401. Status: 1,
  11402. CreateTime: time.Now().Unix(),
  11403. UpdateTime: time.Now().Unix(),
  11404. ExportTime: time.Now().Unix(),
  11405. }
  11406. service.CreateExportErrLog(&err_log)
  11407. continue
  11408. }
  11409. project.Unit = unit
  11410. cost_classify := projectM["cost_classify"].(string)
  11411. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11412. err_log := models.ExportErrLog{
  11413. LogType: 6,
  11414. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11415. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11416. Status: 1,
  11417. CreateTime: time.Now().Unix(),
  11418. UpdateTime: time.Now().Unix(),
  11419. ExportTime: time.Now().Unix(),
  11420. }
  11421. service.CreateExportErrLog(&err_log)
  11422. continue
  11423. }
  11424. var costClassify = "费用类别"
  11425. var cost_classify_id int64
  11426. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11427. if len(cost_classify) != 0 {
  11428. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11429. if errcode == gorm.ErrRecordNotFound {
  11430. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11431. dataconfig := models.DictDataconfig{
  11432. ParentId: costClassifyConfig.ID,
  11433. Module: "system",
  11434. OrgId: orgId,
  11435. Name: cost_classify,
  11436. FieldName: "",
  11437. Value: costConfig.Value + 1,
  11438. CreatedTime: "",
  11439. UpdatedTime: "",
  11440. CreateUserId: adminUser.AdminUser.Id,
  11441. Status: 1,
  11442. Remark: "",
  11443. DeleteIdSystem: 0,
  11444. Title: "",
  11445. Content: "",
  11446. Order: 0,
  11447. Code: "",
  11448. }
  11449. service.CreatedDicConfig(&dataconfig)
  11450. }
  11451. }
  11452. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11453. for _, it := range costClassList {
  11454. if cost_classify == it.Name {
  11455. cost_classify_id = int64(it.Value)
  11456. }
  11457. }
  11458. project.CostClassify = cost_classify_id
  11459. executive_section := projectM["executive_section"].(string)
  11460. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11461. err_log := models.ExportErrLog{
  11462. LogType: 6,
  11463. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11464. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11465. Status: 1,
  11466. CreateTime: time.Now().Unix(),
  11467. UpdateTime: time.Now().Unix(),
  11468. ExportTime: time.Now().Unix(),
  11469. }
  11470. service.CreateExportErrLog(&err_log)
  11471. continue
  11472. }
  11473. if len(executive_section) != 0 {
  11474. //查找科室是否有内容
  11475. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11476. if errcodedepart == gorm.ErrRecordNotFound {
  11477. department := models.XtHisDepartment{
  11478. Name: executive_section,
  11479. Status: 1,
  11480. UserOrgId: adminUser.CurrentOrgId,
  11481. CreatedTime: time.Now().Unix(),
  11482. }
  11483. service.CreateDePartment(&department)
  11484. }
  11485. }
  11486. var executive_section_id int64
  11487. departMentList, _ := service.GetAllDepartMent(orgId)
  11488. for _, it := range departMentList {
  11489. if executive_section == it.Name {
  11490. executive_section_id = it.ID
  11491. }
  11492. }
  11493. project.ExecutiveSection = executive_section_id
  11494. medical_coverage := projectM["medical_coverage"].(string)
  11495. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11496. err_log := models.ExportErrLog{
  11497. LogType: 6,
  11498. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11499. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11500. Status: 1,
  11501. CreateTime: time.Now().Unix(),
  11502. UpdateTime: time.Now().Unix(),
  11503. ExportTime: time.Now().Unix(),
  11504. }
  11505. service.CreateExportErrLog(&err_log)
  11506. continue
  11507. }
  11508. var medicalCoverage = "医保等级"
  11509. var medical_coverage_id int64
  11510. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11511. if len(medical_coverage) != 0 {
  11512. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11513. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11514. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11515. dataconfig := models.DictDataconfig{
  11516. ParentId: medicalCoverageConfig.ID,
  11517. Module: "system",
  11518. OrgId: orgId,
  11519. Name: medical_coverage,
  11520. FieldName: "",
  11521. Value: medicalCoverageConfig.Value + 1,
  11522. CreatedTime: "",
  11523. UpdatedTime: "",
  11524. CreateUserId: adminUser.AdminUser.Id,
  11525. Status: 1,
  11526. Remark: "",
  11527. DeleteIdSystem: 0,
  11528. Title: "",
  11529. Content: "",
  11530. Order: 0,
  11531. Code: "",
  11532. }
  11533. service.CreatedDicConfig(&dataconfig)
  11534. }
  11535. }
  11536. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11537. for _, it := range medicalCoverageList {
  11538. if medical_coverage == it.Name {
  11539. medical_coverage_id = int64(it.Value)
  11540. }
  11541. }
  11542. project.MedicalCoverage = medical_coverage_id
  11543. pinyin := projectM["pinyin"].(string)
  11544. project.Pinyin = pinyin
  11545. wubi := projectM["wubi"].(string)
  11546. project.Wubi = wubi
  11547. statistical_classification := projectM["statistical_classification"].(string)
  11548. var statisticalClassification = "统计分类"
  11549. var statistical_classification_id int64
  11550. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11551. if len(statistical_classification) != 0 {
  11552. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11553. if classificationerrcodes == gorm.ErrRecordNotFound {
  11554. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11555. dataconfig := models.DictDataconfig{
  11556. ParentId: classiFication.ID,
  11557. Module: "system",
  11558. OrgId: orgId,
  11559. Name: statistical_classification,
  11560. FieldName: "",
  11561. Value: classiFicationConfig.Value + 1,
  11562. CreatedTime: "",
  11563. UpdatedTime: "",
  11564. CreateUserId: adminUser.AdminUser.Id,
  11565. Status: 1,
  11566. Remark: "",
  11567. DeleteIdSystem: 0,
  11568. Title: "",
  11569. Content: "",
  11570. Order: 0,
  11571. Code: "",
  11572. }
  11573. service.CreatedDicConfig(&dataconfig)
  11574. }
  11575. }
  11576. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11577. for _, it := range classiFicationList {
  11578. if statistical_classification == it.Name {
  11579. statistical_classification_id = int64(it.Value)
  11580. }
  11581. }
  11582. project.StatisticalClassification = statistical_classification_id
  11583. disease_directory := int64(projectM["disease_directory"].(float64))
  11584. project.DiseaseDirectory = disease_directory
  11585. is_record := int64(projectM["is_record"].(float64))
  11586. project.IsRecord = is_record
  11587. medical_code := projectM["medical_code"].(string)
  11588. project.MedicalCode = medical_code
  11589. tube_color := projectM["tube_color"].(string)
  11590. var tubeColor = "试管颜色"
  11591. var tube_color_id int64
  11592. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11593. if len(tube_color) != 0 {
  11594. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11595. if errcodetube == gorm.ErrRecordNotFound {
  11596. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11597. dataconfig := models.DictDataconfig{
  11598. ParentId: tubeColorConfig.ID,
  11599. Module: "system",
  11600. OrgId: orgId,
  11601. Name: tube_color,
  11602. FieldName: "",
  11603. Value: tubeConfig.Value + 1,
  11604. CreatedTime: "",
  11605. UpdatedTime: "",
  11606. CreateUserId: adminUser.AdminUser.Id,
  11607. Status: 1,
  11608. Remark: "",
  11609. DeleteIdSystem: 0,
  11610. Title: "",
  11611. Content: "",
  11612. Order: 0,
  11613. Code: "",
  11614. }
  11615. service.CreatedDicConfig(&dataconfig)
  11616. }
  11617. }
  11618. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11619. for _, it := range tubeColorList {
  11620. if tube_color == it.Name {
  11621. tube_color_id = int64(it.Value)
  11622. }
  11623. }
  11624. project.TubeColor = tube_color_id
  11625. single_dose := projectM["single_dose"].(string)
  11626. project.SingleDose = single_dose
  11627. execution_frequency := projectM["execution_frequency"].(string)
  11628. project.ExecutionFrequency = execution_frequency
  11629. delivery_way := projectM["delivery_way"].(string)
  11630. project.DeliveryWay = delivery_way
  11631. number_days := projectM["number_days"].(string)
  11632. project.NumberDays = number_days
  11633. total := projectM["total"].(string)
  11634. project.Total = total
  11635. medical_status := int64(projectM["medical_status"].(float64))
  11636. project.MedicalStatus = medical_status
  11637. category := int64(projectM["category"].(float64))
  11638. project.Category = category
  11639. specail_project := int64(projectM["specail_project"].(float64))
  11640. project.SpecailProject = specail_project
  11641. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11642. project.SocialSecurityDirectoryCode = social_security_directory_code
  11643. remark := projectM["remark"].(string)
  11644. project.Remark = remark
  11645. record_date := projectM["record_date"].(string)
  11646. timeLayout := "2006-01-02"
  11647. loc, _ := time.LoadLocation("Local")
  11648. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11649. project.RecordDate = theTime.Unix()
  11650. projectList = append(projectList, &project)
  11651. }
  11652. export_time := time.Now().Unix()
  11653. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11654. if len(projectList) > 0 {
  11655. for _, item := range projectList {
  11656. hans := item.ProjectName // 要转换的汉字字符串
  11657. // 创建一个拼音转换器
  11658. p := pinyin.NewArgs()
  11659. // 将汉字转为拼音
  11660. pinyinSlice := pinyin.Pinyin(hans, p)
  11661. // 输出拼音
  11662. fmt.Println("Pinyin:", pinyinSlice)
  11663. // 获取首字母
  11664. firstLetter := ""
  11665. for _, py := range pinyinSlice {
  11666. if len(py) > 0 {
  11667. firstLetter += string(py[0][0])
  11668. }
  11669. }
  11670. item.FirstLetter = firstLetter
  11671. project := models.HisProject{
  11672. ProjectName: item.ProjectName,
  11673. Price: item.Price,
  11674. Unit: item.Unit,
  11675. CostClassify: item.CostClassify,
  11676. ExecutiveSection: item.ExecutiveSection,
  11677. MedicalCoverage: item.MedicalCoverage,
  11678. UserOrgId: orgId,
  11679. Status: 1,
  11680. CreatedTime: time.Now().Unix(),
  11681. Pinyin: item.Pinyin,
  11682. Wubi: item.Wubi,
  11683. StatisticalClassification: item.StatisticalClassification,
  11684. DiseaseDirectory: item.DiseaseDirectory,
  11685. IsRecord: item.IsRecord,
  11686. MedicalCode: item.MedicalCode,
  11687. TubeColor: item.TubeColor,
  11688. SingleDose: item.SingleDose,
  11689. DeliveryWay: item.DeliveryWay,
  11690. NumberDays: item.NumberDays,
  11691. Total: item.Total,
  11692. Category: item.Category,
  11693. MedicalStatus: item.MedicalStatus,
  11694. SpecailProject: item.SpecailProject,
  11695. RecordDate: item.RecordDate,
  11696. Remark: item.Remark,
  11697. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11698. ExecutionFrequency: item.ExecutionFrequency,
  11699. FirstLetter: item.FirstLetter,
  11700. }
  11701. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11702. if errcodeproject == gorm.ErrRecordNotFound {
  11703. service.CreateProjectInfomation(&project)
  11704. } else if errcodeproject == nil {
  11705. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11706. }
  11707. log := models.ExportLog{
  11708. LogType: 6,
  11709. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11710. TotalNum: int64(len(total_goods)),
  11711. FailNum: int64(len(errLogs)),
  11712. SuccessNum: int64(len(projectList)),
  11713. CreateTime: time.Now().Unix(),
  11714. UpdateTime: time.Now().Unix(),
  11715. ExportTime: export_time,
  11716. Status: 1,
  11717. }
  11718. service.CreateExportLog(&log)
  11719. c.ServeSuccessJSON(map[string]interface{}{
  11720. "msg": "导入成功",
  11721. "total_num": len(total_goods),
  11722. "success_num": len(projectList),
  11723. "fail_num": int64(len(errLogs)),
  11724. })
  11725. }
  11726. } else {
  11727. log := models.ExportLog{
  11728. LogType: 6,
  11729. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11730. TotalNum: int64(len(total_goods)),
  11731. FailNum: int64(len(errLogs)),
  11732. SuccessNum: int64(len(projectList)),
  11733. CreateTime: time.Now().Unix(),
  11734. UpdateTime: time.Now().Unix(),
  11735. ExportTime: export_time,
  11736. Status: 1,
  11737. }
  11738. service.CreateExportLog(&log)
  11739. c.ServeSuccessJSON(map[string]interface{}{
  11740. "msg": "导入成功",
  11741. "total_num": len(total_goods),
  11742. "success_num": len(projectList),
  11743. "fail_num": int64(len(errLogs)),
  11744. })
  11745. }
  11746. }
  11747. //func (this *HisApiController) EditProjectInformation(){
  11748. //
  11749. // id, _ := this.GetInt64("id")
  11750. // project_team := this.GetString("project_team")
  11751. // price := this.GetString("price")
  11752. // price_float, _ := strconv.ParseFloat(price, 64)
  11753. // pinyin := this.GetString("pinyin")
  11754. // wubi := this.GetString("wubi")
  11755. // tube_color, _ := this.GetInt64("tube_color")
  11756. // team_type, _ := this.GetInt64("team_type")
  11757. // remark := this.GetString("remark")
  11758. // ids := this.GetString("ids")
  11759. // item_id := this.GetString("item_id")
  11760. // projectTeam := models.XtHisProjectTeam{
  11761. // ProjectTeam: project_team,
  11762. // Price: price_float,
  11763. // Pinyin: pinyin,
  11764. // Wubi: wubi,
  11765. // TubeColor: tube_color,
  11766. // TeamType: team_type,
  11767. // Remark: remark,
  11768. // ProjectId: ids,
  11769. // ItemId: item_id,
  11770. // }
  11771. //
  11772. //
  11773. // dataBody := make(map[string]interface{}, 0)
  11774. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11775. // if err != nil {
  11776. // utils.ErrorLog(err.Error())
  11777. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11778. // return
  11779. // }
  11780. //
  11781. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11782. //
  11783. //
  11784. // if err != nil {
  11785. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11786. // return
  11787. // }
  11788. //
  11789. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11790. // infos, _ := dataBody["info"].([]interface{})
  11791. // if len(infos) > 0 {
  11792. // var ids []string
  11793. //
  11794. // for _, item := range infos {
  11795. // items := item.(map[string]interface{})
  11796. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11797. // utils.ErrorLog("id")
  11798. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11799. // return
  11800. // }
  11801. // id := int64(items["id"].(float64))
  11802. //
  11803. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11804. // utils.ErrorLog("type")
  11805. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11806. // return
  11807. // }
  11808. // types := int64(items["type"].(float64))
  11809. //
  11810. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11811. // utils.ErrorLog("number")
  11812. // }
  11813. //
  11814. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11815. //
  11816. // projectList := models.XtHisProjectList{
  11817. // Number: number,
  11818. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11819. // ProjectId: id,
  11820. // Status: 1,
  11821. // CreatedTime: time.Now().Unix(),
  11822. // UpdatedTime: time.Now().Unix(),
  11823. // TeamId: projectTeam.ID,
  11824. // Type: types,
  11825. // }
  11826. // list := projectList
  11827. //
  11828. // service.CreateProjectList(&list)
  11829. //
  11830. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11831. //
  11832. // }
  11833. // ids_str := strings.Join(ids, ",")
  11834. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11835. // service.SaveProjectTeam(&projectTeam)
  11836. // this.ServeSuccessJSON(map[string]interface{}{
  11837. // "projectTeam": projectTeam,
  11838. // })
  11839. // }
  11840. // }
  11841. //}
  11842. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11843. name := c.GetString("name")
  11844. mode_id, _ := c.GetInt64("mode", 0)
  11845. types, _ := c.GetInt64("type", 0)
  11846. patient_id, _ := c.GetInt64("patient_id", 0)
  11847. types = 1
  11848. adminInfo := c.GetAdminUserInfo()
  11849. template := &models.HisPrescriptionTemplate{
  11850. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11851. PatientId: patient_id,
  11852. Type: types,
  11853. Status: 1,
  11854. Ctime: time.Now().Unix(),
  11855. Mtime: time.Now().Unix(),
  11856. Name: name,
  11857. Mode: mode_id,
  11858. }
  11859. dataBody := make(map[string]interface{}, 0)
  11860. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11861. if err != nil {
  11862. utils.ErrorLog(err.Error())
  11863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11864. return
  11865. }
  11866. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11867. //如果已经存在记录则删除处方
  11868. if template_one.ID > 0 {
  11869. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11870. var ids []int64
  11871. var org_id int64
  11872. for _, item := range ps {
  11873. org_id = c.GetAdminUserInfo().CurrentOrgId
  11874. ids = append(ids, item.ID)
  11875. }
  11876. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11877. if err2 == nil {
  11878. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11879. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11880. if len(prescriptions) > 0 {
  11881. for _, item := range prescriptions {
  11882. items := item.(map[string]interface{})
  11883. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11884. utils.ErrorLog("type")
  11885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11886. return
  11887. }
  11888. types := int64(items["type"].(float64))
  11889. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11890. utils.ErrorLog("med_type")
  11891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11892. return
  11893. }
  11894. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11895. ctime := time.Now().Unix()
  11896. prescription := &models.HisPrescriptionInfoTemplate{
  11897. PatientId: patient_id,
  11898. UserOrgId: adminInfo.CurrentOrgId,
  11899. Ctime: ctime,
  11900. Mtime: ctime,
  11901. Type: types,
  11902. Modifier: adminInfo.AdminUser.Id,
  11903. Creator: adminInfo.AdminUser.Id,
  11904. Status: 1,
  11905. PTemplateId: template_one.ID,
  11906. MedType: med_type,
  11907. }
  11908. service.CreateHisPrescriptionInfoTemplate(prescription)
  11909. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11910. advices := items["advices"].([]interface{})
  11911. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11912. ctime := time.Now().Unix()
  11913. mtime := ctime
  11914. if len(advices) > 0 {
  11915. for _, advice := range advices {
  11916. var s models.HisPrescriptionAdviceTemplate
  11917. s.PrescriptionId = prescription.ID
  11918. s.AdviceType = 2
  11919. s.StopState = 2
  11920. s.ExecutionState = 2
  11921. s.Status = 1
  11922. s.UserOrgId = adminInfo.CurrentOrgId
  11923. s.CreatedTime = ctime
  11924. s.UpdatedTime = mtime
  11925. s.PatientId = patient_id
  11926. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11927. if errcode > 0 {
  11928. c.ServeFailJSONWithSGJErrorCode(errcode)
  11929. return
  11930. }
  11931. service.CreateHisPrescriptionAdviceTemplate(&s)
  11932. }
  11933. }
  11934. }
  11935. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11936. projects := items["project"].([]interface{})
  11937. if len(projects) > 0 {
  11938. for _, project := range projects {
  11939. var p models.HisPrescriptionProjectTemplate
  11940. p.PrescriptionId = prescription.ID
  11941. p.Ctime = time.Now().Unix()
  11942. p.Mtime = time.Now().Unix()
  11943. p.PatientId = patient_id
  11944. p.UserOrgId = adminInfo.CurrentOrgId
  11945. p.Status = 1
  11946. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11947. if errcode > 0 {
  11948. c.ServeFailJSONWithSGJErrorCode(errcode)
  11949. return
  11950. }
  11951. service.CreateHisPrescriptionProjectTemplate(&p)
  11952. }
  11953. }
  11954. }
  11955. }
  11956. c.ServeSuccessJSON(map[string]interface{}{
  11957. "msg": "创建成功",
  11958. })
  11959. }
  11960. }
  11961. } else {
  11962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11963. return
  11964. }
  11965. } else {
  11966. err3 := service.CreateHisPrescriptionTemplate(template)
  11967. if err3 == nil {
  11968. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11969. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11970. if len(prescriptions) > 0 {
  11971. for _, item := range prescriptions {
  11972. items := item.(map[string]interface{})
  11973. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11974. utils.ErrorLog("type")
  11975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11976. return
  11977. }
  11978. types := int64(items["type"].(float64))
  11979. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11980. utils.ErrorLog("med_type")
  11981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11982. return
  11983. }
  11984. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11985. ctime := time.Now().Unix()
  11986. prescription := &models.HisPrescriptionInfoTemplate{
  11987. PatientId: patient_id,
  11988. UserOrgId: adminInfo.CurrentOrgId,
  11989. Ctime: ctime,
  11990. Mtime: ctime,
  11991. Type: types,
  11992. Modifier: adminInfo.AdminUser.Id,
  11993. Creator: adminInfo.AdminUser.Id,
  11994. Status: 1,
  11995. PTemplateId: template.ID,
  11996. MedType: med_type,
  11997. }
  11998. service.CreateHisPrescriptionInfoTemplate(prescription)
  11999. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12000. advices := items["advices"].([]interface{})
  12001. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12002. ctime := time.Now().Unix()
  12003. mtime := ctime
  12004. if len(advices) > 0 {
  12005. for _, advice := range advices {
  12006. var s models.HisPrescriptionAdviceTemplate
  12007. s.PrescriptionId = prescription.ID
  12008. s.AdviceType = 2
  12009. s.StopState = 2
  12010. s.ExecutionState = 2
  12011. s.Status = 1
  12012. s.UserOrgId = adminInfo.CurrentOrgId
  12013. s.CreatedTime = ctime
  12014. s.UpdatedTime = mtime
  12015. s.PatientId = patient_id
  12016. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12017. if errcode > 0 {
  12018. c.ServeFailJSONWithSGJErrorCode(errcode)
  12019. return
  12020. }
  12021. service.CreateHisPrescriptionAdviceTemplate(&s)
  12022. }
  12023. }
  12024. }
  12025. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12026. projects := items["project"].([]interface{})
  12027. if len(projects) > 0 {
  12028. for _, project := range projects {
  12029. var p models.HisPrescriptionProjectTemplate
  12030. p.PrescriptionId = prescription.ID
  12031. p.Ctime = time.Now().Unix()
  12032. p.Mtime = time.Now().Unix()
  12033. p.PatientId = patient_id
  12034. p.UserOrgId = adminInfo.CurrentOrgId
  12035. p.Status = 1
  12036. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12037. if errcode > 0 {
  12038. c.ServeFailJSONWithSGJErrorCode(errcode)
  12039. return
  12040. }
  12041. service.CreateHisPrescriptionProjectTemplate(&p)
  12042. }
  12043. }
  12044. }
  12045. }
  12046. c.ServeSuccessJSON(map[string]interface{}{
  12047. "msg": "创建成功",
  12048. })
  12049. }
  12050. }
  12051. } else {
  12052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12053. return
  12054. }
  12055. }
  12056. }
  12057. func (c *HisApiController) PreSettle() {
  12058. id, _ := c.GetInt64("id")
  12059. record_time := c.GetString("record_time")
  12060. his_patient_id, _ := c.GetInt64("his_patient_id")
  12061. timeLayout := "2006-01-02"
  12062. loc, _ := time.LoadLocation("Local")
  12063. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12064. diagnosis_id := c.GetString("diagnosis")
  12065. sick_type, _ := c.GetInt64("sick_type")
  12066. reg_type, _ := c.GetInt64("p_type")
  12067. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12069. if err != nil {
  12070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12071. return
  12072. }
  12073. recordDateTime := theTime.Unix()
  12074. adminUser := c.GetAdminUserInfo()
  12075. var prescriptions []*models.HisPrescription
  12076. var start_time int64
  12077. var end_time int64
  12078. ids_str := c.GetString("ids")
  12079. ids_arr := strings.Split(ids_str, ",")
  12080. fmt.Println(reg_type)
  12081. if settle_accounts_type == 1 { //日结
  12082. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12083. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12084. } else {
  12085. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12086. }
  12087. fmt.Println(prescriptions)
  12088. } else { //月结
  12089. start_time_str := c.GetString("start_time")
  12090. end_time_str := c.GetString("end_time")
  12091. timeLayout := "2006-01-02"
  12092. loc, _ := time.LoadLocation("Local")
  12093. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12094. if err != nil {
  12095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12096. return
  12097. }
  12098. recordStartTime := theStartTime.Unix()
  12099. start_time = recordStartTime
  12100. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12101. if err != nil {
  12102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12103. return
  12104. }
  12105. recordEndTime := theEndTime.Unix()
  12106. end_time = recordEndTime
  12107. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12108. }
  12109. if reg_type == 1111 || reg_type == 1112 {
  12110. reg_type = 11
  12111. }
  12112. timestamp := time.Now().Unix()
  12113. tempTime := time.Unix(timestamp, 0)
  12114. timeFormat := tempTime.Format("20060102150405")
  12115. chrgBchno := rand.Intn(100000) + 10000
  12116. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12117. strconv.FormatInt(his.PatientId, 10)
  12118. var ids []int64
  12119. for _, item := range prescriptions {
  12120. ids = append(ids, item.ID)
  12121. }
  12122. fmt.Println(ids)
  12123. var total float64
  12124. for _, item := range prescriptions {
  12125. fmt.Println(item)
  12126. if item.Type == 1 { //药品
  12127. for _, subItem := range item.HisDoctorAdviceInfo {
  12128. total = total + (subItem.Price * subItem.PrescribingNumber)
  12129. }
  12130. }
  12131. if item.Type == 2 { //项目
  12132. for _, subItem := range item.HisPrescriptionProject {
  12133. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12134. total = total + (subItem.Price * cnt)
  12135. }
  12136. }
  12137. for _, subItem := range item.HisAdditionalCharge {
  12138. total = total + (subItem.Price * float64(subItem.Count))
  12139. }
  12140. }
  12141. allTotal := fmt.Sprintf("%.2f", total)
  12142. totals, _ := strconv.ParseFloat(allTotal, 64)
  12143. order := &models.HisOrder{
  12144. UserOrgId: adminUser.CurrentOrgId,
  12145. HisPatientId: his.ID,
  12146. PatientId: id,
  12147. SettleAccountsDate: recordDateTime,
  12148. Ctime: time.Now().Unix(),
  12149. Mtime: time.Now().Unix(),
  12150. Status: 1,
  12151. OrderStatus: 1,
  12152. MdtrtId: his.Number,
  12153. Number: chrg_bchno,
  12154. MedfeeSumamt: totals,
  12155. SettleEndTime: end_time,
  12156. SettleStartTime: start_time,
  12157. SettleType: settle_accounts_type,
  12158. PsnPartAmt: totals,
  12159. PsnCashPay: totals,
  12160. PType: 2,
  12161. IsPre: 1,
  12162. MedType: strconv.Itoa(int(reg_type)),
  12163. Diagnosis: diagnosis_id,
  12164. }
  12165. err = service.CreateOrder(order)
  12166. if err != nil {
  12167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12168. return
  12169. }
  12170. var customs []*Custom
  12171. for _, item := range prescriptions {
  12172. fmt.Println(item.Type)
  12173. if item.Type == 1 { //药品
  12174. for _, subItem := range item.HisDoctorAdviceInfo {
  12175. cus := &Custom{
  12176. AdviceId: subItem.ID,
  12177. ProjectId: 0,
  12178. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12179. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12180. FeedetlSn: subItem.FeedetlSn,
  12181. Price: fmt.Sprintf("%.2f", subItem.Price),
  12182. MedListCodg: subItem.MedListCodg,
  12183. Type: 1,
  12184. }
  12185. customs = append(customs, cus)
  12186. }
  12187. }
  12188. if item.Type == 2 { //项目
  12189. for _, subItem := range item.HisPrescriptionProject {
  12190. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12191. cus := &Custom{
  12192. AdviceId: 0,
  12193. ProjectId: subItem.ID,
  12194. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12195. Cut: fmt.Sprintf("%.2f", cnt),
  12196. FeedetlSn: subItem.FeedetlSn,
  12197. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12198. MedListCodg: subItem.MedListCodg,
  12199. Type: 2,
  12200. }
  12201. customs = append(customs, cus)
  12202. }
  12203. }
  12204. for _, item := range item.HisAdditionalCharge {
  12205. cus := &Custom{
  12206. ItemId: item.ID,
  12207. AdviceId: 0,
  12208. ProjectId: 0,
  12209. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12210. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12211. FeedetlSn: item.FeedetlSn,
  12212. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12213. MedListCodg: item.XtHisAddtionConfig.Code,
  12214. Type: 3,
  12215. }
  12216. customs = append(customs, cus)
  12217. }
  12218. }
  12219. fmt.Println(customs)
  12220. for _, item := range customs {
  12221. var advice_id int64 = 0
  12222. var project_id int64 = 0
  12223. var item_id int64 = 0
  12224. var types int64 = 0
  12225. if item.Type == 1 {
  12226. advice_id = item.AdviceId
  12227. project_id = 0
  12228. item_id = 0
  12229. } else if item.Type == 2 {
  12230. advice_id = 0
  12231. item_id = 0
  12232. project_id = item.ProjectId
  12233. } else if item.Type == 3 {
  12234. advice_id = 0
  12235. item_id = item.ItemId
  12236. project_id = 0
  12237. }
  12238. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12239. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12240. pric, _ := strconv.ParseFloat(item.Price, 32)
  12241. info := &models.HisOrderInfo{
  12242. OrderNumber: order.Number,
  12243. UploadDate: time.Now().Unix(),
  12244. AdviceId: advice_id,
  12245. DetItemFeeSumamt: detItemFeeSumamt,
  12246. Cnt: cut,
  12247. Pric: pric,
  12248. PatientId: id,
  12249. Status: 1,
  12250. Mtime: time.Now().Unix(),
  12251. Ctime: time.Now().Unix(),
  12252. UserOrgId: adminUser.CurrentOrgId,
  12253. HisPatientId: his.ID,
  12254. OrderId: order.ID,
  12255. ProjectId: project_id,
  12256. Type: types,
  12257. ItemId: item_id,
  12258. }
  12259. service.CreateOrderInfo(info)
  12260. }
  12261. his.SickType = sick_type
  12262. service.UpdataHisPateint(&his)
  12263. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12264. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12265. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12266. if err == nil {
  12267. c.ServeSuccessJSON(map[string]interface{}{
  12268. "msg": "结算成功",
  12269. })
  12270. }
  12271. }
  12272. type CustomOrderInfo struct {
  12273. Name string
  12274. Spec string
  12275. Unit string
  12276. Count float64
  12277. Price float64
  12278. Total float64
  12279. }
  12280. func (c *HisApiController) GetPrivateExpensesInfo() {
  12281. order_id, _ := c.GetInt64("id", 0)
  12282. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12283. order, _ := service.GetHisOrderByID(order_id)
  12284. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12285. if order.ID == 0 {
  12286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12287. return
  12288. }
  12289. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12290. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12291. org_id := c.GetAdminUserInfo().CurrentOrgId
  12292. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12293. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12294. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12295. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12296. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12297. //var orderInfos_four []*models.HisOrderInfoTwo
  12298. //for _, item := range orderInfos_three {
  12299. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12300. // item.HisPrescriptionProject.IsCheckTeam = 1
  12301. // orderInfos_four = append(orderInfos_four, item)
  12302. //
  12303. // }
  12304. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12305. // item.HisPrescriptionProject.IsCheckTeam = 2
  12306. // orderInfos_two = append(orderInfos_two, item)
  12307. // }
  12308. //}
  12309. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12310. //var cus_slice []CustomOrderInfo
  12311. //for _, item := range new_order_info {
  12312. // var cus CustomOrderInfo
  12313. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12314. // cus.Unit = ""
  12315. // cus.Spec = ""
  12316. // var total float64
  12317. // for _, subItem := range orderInfos_four {
  12318. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12319. // total = total + subItem.DetItemFeeSumamt
  12320. // fmt.Println(subItem.DetItemFeeSumamt)
  12321. // }
  12322. // }
  12323. // cus.Count = 1
  12324. // cus.Total = total
  12325. // cus_slice = append(cus_slice, cus)
  12326. //}
  12327. orderInfos = append(orderInfos, orderInfos_two...)
  12328. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12329. //orderInfos = append(orderInfos, orderInfos_three...)
  12330. //}/**/
  12331. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12332. c.ServeSuccessJSON(map[string]interface{}{
  12333. "order": order,
  12334. "order_info": orderInfos,
  12335. "patient": patient,
  12336. "admin_info": adminInfo,
  12337. "his": his,
  12338. "current_admin": role,
  12339. "org_config": miConfig,
  12340. //"new_order_info": cus_slice,
  12341. })
  12342. }
  12343. func (this *HisApiController) ChangeMedType() {
  12344. med_type := this.GetString("med_type")
  12345. old_med_type := this.GetString("old_med_type")
  12346. ids := this.GetString("ids")
  12347. settle_type, _ := this.GetInt64("settle_type")
  12348. start_time := this.GetString("start_time")
  12349. end_time := this.GetString("end_time")
  12350. ids_arr := strings.Split(ids, ",")
  12351. if settle_type == 1 { //日结
  12352. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12353. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12354. prescription.MedType = med_type
  12355. err := service.SaveHisPrescriptionTwo(&prescription)
  12356. if err == nil {
  12357. this.ServeSuccessJSON(map[string]interface{}{
  12358. "msg": "修改成功",
  12359. })
  12360. } else {
  12361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12362. return
  12363. }
  12364. } else if settle_type == 2 {
  12365. timeLayout := "2006-01-02"
  12366. loc, _ := time.LoadLocation("Local")
  12367. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12368. if err != nil {
  12369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12370. return
  12371. }
  12372. recordStartTime := theStartTime.Unix()
  12373. start_time_timestamp := recordStartTime
  12374. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12375. if err != nil {
  12376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12377. return
  12378. }
  12379. recordEndTime := theEndTime.Unix()
  12380. end_time_timestamp := recordEndTime
  12381. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12382. if updateErr == nil {
  12383. this.ServeSuccessJSON(map[string]interface{}{
  12384. "msg": "修改成功",
  12385. })
  12386. } else {
  12387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12388. return
  12389. }
  12390. }
  12391. }
  12392. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12393. patient_id, _ := c.GetInt64("patient_id")
  12394. his_patient_id, _ := c.GetInt64("his_patient_id")
  12395. record_date := c.GetString("record_date")
  12396. start_time := c.GetString("start_time")
  12397. end_time := c.GetString("end_time")
  12398. order_status, _ := c.GetInt64("type", 0)
  12399. p_type, _ := c.GetInt64("p_type", 0)
  12400. order_id, _ := c.GetInt64("order_id", 0)
  12401. timeLayout := "2006-01-02"
  12402. loc, _ := time.LoadLocation("Local")
  12403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12404. if err != nil {
  12405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12406. return
  12407. }
  12408. recordDateTime := theTime.Unix()
  12409. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12410. if err != nil {
  12411. }
  12412. startRecordDateTime := startTime.Unix()
  12413. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12414. if err != nil {
  12415. }
  12416. endRecordDateTime := endTime.Unix()
  12417. admin := c.GetAdminUserInfo()
  12418. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12419. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12420. order, _ := service.GetHisOrderByID(order_id)
  12421. var monthPrescriptions []*models.HisPrescription
  12422. if order_status == 1 || order_status == 0 {
  12423. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12424. } else if order_status == 2 {
  12425. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12426. }
  12427. var settle_total float64
  12428. for _, item := range monthPrescriptions {
  12429. if len(item.HisPrescriptionProject) > 0 {
  12430. for _, subItem := range item.HisPrescriptionProject {
  12431. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12432. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12433. settle_total = settle_total + total
  12434. }
  12435. }
  12436. if len(item.HisDoctorAdviceInfo) > 0 {
  12437. for _, subItem := range item.HisDoctorAdviceInfo {
  12438. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12439. settle_total = settle_total + total
  12440. }
  12441. }
  12442. }
  12443. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12444. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12445. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12446. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12447. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12448. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12449. //获取所有科室信息
  12450. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12451. var dia string
  12452. for _, item := range month_p_info {
  12453. if len(dia) == 0 {
  12454. dia = item.Diagnosis
  12455. } else {
  12456. dia = dia + "," + item.Diagnosis
  12457. }
  12458. }
  12459. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12460. dia_arr = removeEmptyStrings(dia_arr)
  12461. c.ServeSuccessJSON(map[string]interface{}{
  12462. "his_info": his_patient_info,
  12463. "xt_info": xt_patient_info,
  12464. "case_history": case_history,
  12465. "info": patientPrescriptionInfo,
  12466. "last_info": lastPatientPrescriptionInfo,
  12467. "month_prescriptions": monthPrescriptions,
  12468. "order": order,
  12469. "doctors": doctors,
  12470. "department": department,
  12471. "settle_total": settle_total,
  12472. "dia_arr": dia_arr,
  12473. })
  12474. return
  12475. }
  12476. func removeEmptyStrings(input []string) []string {
  12477. var output []string
  12478. for _, s := range input {
  12479. if s != "" {
  12480. output = append(output, s)
  12481. }
  12482. }
  12483. return output
  12484. }
  12485. func removeDuplicates(input []string) []string {
  12486. seen := make(map[string]bool)
  12487. output := []string{}
  12488. for _, s := range input {
  12489. if _, exists := seen[s]; !exists {
  12490. seen[s] = true
  12491. output = append(output, s)
  12492. }
  12493. }
  12494. return output
  12495. }
  12496. func (c *HisApiController) GetHisMonthPatientInfo() {
  12497. patient_id, _ := c.GetInt64("patient_id")
  12498. his_patient_id, _ := c.GetInt64("his_patient_id")
  12499. record_date := c.GetString("record_date")
  12500. number := c.GetString("number")
  12501. start_time := c.GetString("start_time")
  12502. end_time := c.GetString("end_time")
  12503. p_type, _ := c.GetInt64("p_type")
  12504. timeLayout := "2006-01-02"
  12505. loc, _ := time.LoadLocation("Local")
  12506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12507. if err != nil {
  12508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12509. return
  12510. }
  12511. recordDateTime := theTime.Unix()
  12512. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12513. if err != nil {
  12514. }
  12515. startRecordDateTime := startTime.Unix()
  12516. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12517. if err != nil {
  12518. }
  12519. endRecordDateTime := endTime.Unix()
  12520. admin := c.GetAdminUserInfo()
  12521. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12522. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12523. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12524. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12525. var settle_total float64
  12526. for _, item := range monthPrescriptions {
  12527. if len(item.HisPrescriptionProject) > 0 {
  12528. for _, subItem := range item.HisPrescriptionProject {
  12529. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12530. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12531. settle_total = settle_total + total
  12532. }
  12533. }
  12534. if len(item.HisDoctorAdviceInfo) > 0 {
  12535. for _, subItem := range item.HisDoctorAdviceInfo {
  12536. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12537. settle_total = settle_total + total
  12538. }
  12539. }
  12540. }
  12541. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12542. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12543. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12544. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12545. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12546. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12547. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12548. //获取所有科室信息
  12549. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12550. c.ServeSuccessJSON(map[string]interface{}{
  12551. "his_info": his_patient_info,
  12552. "xt_info": xt_patient_info,
  12553. "case_history": case_history,
  12554. "info": patientPrescriptionInfo,
  12555. "month_prescriptions": monthPrescriptions,
  12556. "order": order,
  12557. "doctors": doctors,
  12558. "department": department,
  12559. "count": count,
  12560. "drugStockConfig": drugStockConfig,
  12561. "last_info": lastPatientPrescriptionInfo,
  12562. "settle_total": settle_total,
  12563. })
  12564. return
  12565. }
  12566. func (c *HisApiController) GetAllOrder() {
  12567. org_id := c.GetAdminUserInfo().CurrentOrgId
  12568. orders, _ := service.GetNewHisOrderList(org_id)
  12569. c.ServeSuccessJSON(map[string]interface{}{
  12570. "order": orders,
  12571. })
  12572. return
  12573. }
  12574. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12575. newArr = make([]*models.HisOrderInfoTwo, 0)
  12576. for i := 0; i < len(arr); i++ {
  12577. repeat := false
  12578. for j := i + 1; j < len(arr); j++ {
  12579. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12580. repeat = true
  12581. break
  12582. }
  12583. }
  12584. if !repeat {
  12585. newArr = append(newArr, arr[i])
  12586. }
  12587. }
  12588. return
  12589. }
  12590. // 修改处方退库操作 参数传修改之前的处方数据
  12591. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12592. if advice.ExecutionState == 1 {
  12593. //查询该病人该药品是否有库存记录
  12594. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12595. if errcode == gorm.ErrRecordNotFound {
  12596. } else {
  12597. //退库
  12598. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12599. if advice.PrescribingNumberUnit == drug.MinUnit {
  12600. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12601. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12602. //退库
  12603. warehouseInfo := models.DrugWarehouseInfo{
  12604. StockMinNumber: prescribingNumber,
  12605. }
  12606. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12607. operation_time := time.Now().Unix()
  12608. creater := advice.AdviceDoctor
  12609. ctime := time.Now().Unix()
  12610. timeStr := time.Now().Format("2006-01-02")
  12611. timeArr := strings.Split(timeStr, "-")
  12612. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12613. total = total + 1
  12614. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12615. cancelStock := models.DrugCancelStock{
  12616. OrderNumber: orderNumber,
  12617. OperaTime: operation_time,
  12618. OrgId: advice.UserOrgId,
  12619. Creater: creater,
  12620. Ctime: ctime,
  12621. Status: 1,
  12622. ReturnTime: advice.AdviceDate,
  12623. Dealer: info.Dealer,
  12624. Manufacturer: info.Manufacturer,
  12625. Type: 1,
  12626. }
  12627. service.AddSigleDrugCancelStock(&cancelStock)
  12628. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12629. dealer, _ := service.GetDealerById(info.Dealer)
  12630. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12631. cancelStockInfo := models.DrugCancelStockInfo{
  12632. OrderNumber: cancelInfo.OrderNumber,
  12633. CancelStockId: cancelInfo.ID,
  12634. DrugId: info.DrugId,
  12635. Count: info.Count,
  12636. Status: 1,
  12637. Ctime: ctime,
  12638. OrgId: advice.UserOrgId,
  12639. Type: 1,
  12640. Manufacturer: manufactureName.ManufacturerName,
  12641. Dealer: dealer.DealerName,
  12642. Total: 0,
  12643. RetailPrice: info.RetailPrice,
  12644. RetailTotalPrice: info.RetailTotalPrice,
  12645. Price: info.Price,
  12646. RegisterAccount: "",
  12647. Remark: info.Remark,
  12648. BatchNumber: info.BatchNumber,
  12649. MaxUnit: info.CountUnit,
  12650. ProductDate: info.ProductDate,
  12651. ExpiryDate: info.ExpiryDate,
  12652. BatchNumberId: info.WarehouseInfoId,
  12653. }
  12654. flow := models.DrugFlow{
  12655. WarehousingId: 0,
  12656. DrugId: info.DrugId,
  12657. Number: "",
  12658. BatchNumber: info.BatchNumber,
  12659. Count: info.Count,
  12660. UserOrgId: advice.UserOrgId,
  12661. PatientId: 0,
  12662. SystemTime: ctime,
  12663. ConsumableType: 4,
  12664. IsSys: 0,
  12665. WarehousingOrder: "",
  12666. WarehouseOutId: 0,
  12667. WarehouseOutOrderNumber: "",
  12668. IsEdit: 0,
  12669. CancelStockId: cancelStock.ID,
  12670. CancelOrderNumber: cancelStock.OrderNumber,
  12671. Manufacturer: info.Manufacturer,
  12672. Dealer: info.Dealer,
  12673. Creator: advice.UserOrgId,
  12674. UpdateCreator: 0,
  12675. Status: 1,
  12676. Ctime: time.Now().Unix(),
  12677. Mtime: 0,
  12678. Price: info.Price,
  12679. WarehousingDetailId: 0,
  12680. WarehouseOutDetailId: 0,
  12681. CancelOutDetailId: 0,
  12682. ExpireDate: info.ExpiryDate,
  12683. ProductDate: info.ProductDate,
  12684. MaxUnit: info.CountUnit,
  12685. MinUnit: "",
  12686. }
  12687. service.CreatedCancelStock(cancelStockInfo)
  12688. service.CreateDrugFlowOne(flow)
  12689. } else {
  12690. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12691. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12692. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12693. warehouseInfo := models.DrugWarehouseInfo{
  12694. StockMinNumber: prescribingNumber,
  12695. }
  12696. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12697. }
  12698. operation_time := time.Now().Unix()
  12699. creater := advice.AdviceDoctor
  12700. ctime := time.Now().Unix()
  12701. timeStr := time.Now().Format("2006-01-02")
  12702. timeArr := strings.Split(timeStr, "-")
  12703. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12704. total = total + 1
  12705. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12706. cancelStock := models.DrugCancelStock{
  12707. OrderNumber: orderNumber,
  12708. OperaTime: operation_time,
  12709. OrgId: advice.UserOrgId,
  12710. Creater: creater,
  12711. Ctime: ctime,
  12712. Status: 1,
  12713. ReturnTime: advice.AdviceDate,
  12714. Dealer: info.Dealer,
  12715. Manufacturer: info.Manufacturer,
  12716. Type: 1,
  12717. }
  12718. service.AddSigleDrugCancelStock(&cancelStock)
  12719. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12720. dealer, _ := service.GetDealerById(info.Dealer)
  12721. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12722. cancelStockInfo := models.DrugCancelStockInfo{
  12723. OrderNumber: cancelInfo.OrderNumber,
  12724. CancelStockId: cancelInfo.ID,
  12725. DrugId: info.DrugId,
  12726. Count: info.Count,
  12727. Status: 1,
  12728. Ctime: ctime,
  12729. OrgId: advice.UserOrgId,
  12730. Type: 1,
  12731. Manufacturer: manufactureName.ManufacturerName,
  12732. Dealer: dealer.DealerName,
  12733. Total: 0,
  12734. RetailPrice: info.RetailPrice,
  12735. RetailTotalPrice: info.RetailTotalPrice,
  12736. Price: info.Price,
  12737. RegisterAccount: "",
  12738. Remark: info.Remark,
  12739. BatchNumber: info.BatchNumber,
  12740. MaxUnit: info.CountUnit,
  12741. ProductDate: info.ProductDate,
  12742. ExpiryDate: info.ExpiryDate,
  12743. BatchNumberId: info.WarehouseInfoId,
  12744. }
  12745. flow := models.DrugFlow{
  12746. WarehousingId: 0,
  12747. DrugId: info.DrugId,
  12748. Number: "",
  12749. BatchNumber: info.BatchNumber,
  12750. Count: info.Count,
  12751. UserOrgId: advice.UserOrgId,
  12752. PatientId: 0,
  12753. SystemTime: ctime,
  12754. ConsumableType: 4,
  12755. IsSys: 0,
  12756. WarehousingOrder: "",
  12757. WarehouseOutId: 0,
  12758. WarehouseOutOrderNumber: "",
  12759. IsEdit: 0,
  12760. CancelStockId: cancelStock.ID,
  12761. CancelOrderNumber: cancelStock.OrderNumber,
  12762. Manufacturer: info.Manufacturer,
  12763. Dealer: info.Dealer,
  12764. Creator: advice.AdviceDoctor,
  12765. UpdateCreator: 0,
  12766. Status: 1,
  12767. Ctime: time.Now().Unix(),
  12768. Mtime: 0,
  12769. Price: info.Price,
  12770. WarehousingDetailId: 0,
  12771. WarehouseOutDetailId: 0,
  12772. CancelOutDetailId: 0,
  12773. ExpireDate: info.ExpiryDate,
  12774. ProductDate: info.ProductDate,
  12775. MaxUnit: info.CountUnit,
  12776. MinUnit: "",
  12777. }
  12778. service.CreatedCancelStock(cancelStockInfo)
  12779. service.CreateDrugFlowOne(flow)
  12780. }
  12781. }
  12782. }
  12783. return err
  12784. }
  12785. func (this *HisApiController) DeleteNCDS() {
  12786. id, _ := this.GetInt64("id", 0)
  12787. if id > 0 {
  12788. service.DeletePsnNCDSRecordById(id)
  12789. this.ServeSuccessJSON(map[string]interface{}{
  12790. "msg": "删除成功",
  12791. })
  12792. } else {
  12793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12794. return
  12795. }
  12796. }
  12797. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12798. id, _ := c.GetInt64("id")
  12799. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12800. c.ServeSuccessJSON(map[string]interface{}{
  12801. "advice": advice,
  12802. })
  12803. return
  12804. }
  12805. func (c *HisApiController) GetHisMonthChargePatientList() {
  12806. record_date := c.GetString("record_date")
  12807. start_time := c.GetString("start_time")
  12808. end_time := c.GetString("end_time")
  12809. timeLayout := "2006-01-02"
  12810. loc, _ := time.LoadLocation("Local")
  12811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12812. if err != nil {
  12813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12814. return
  12815. }
  12816. if err != nil {
  12817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12818. return
  12819. }
  12820. recordDateTime := theTime.Unix()
  12821. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12822. if err != nil {
  12823. }
  12824. startRecordDateTime := startTime.Unix()
  12825. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12826. if err != nil {
  12827. }
  12828. endRecordDateTime := endTime.Unix()
  12829. adminInfo := c.GetAdminUserInfo()
  12830. var tempMonthChargePatients []*service.MonthChargePatients
  12831. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12832. for _, item := range tempPatients {
  12833. //过滤没有处方的
  12834. if len(item.HisPrescription) == 0 {
  12835. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12836. }
  12837. }
  12838. c.ServeSuccessJSON(map[string]interface{}{
  12839. "list": tempMonthChargePatients,
  12840. })
  12841. }
  12842. // PrescriptionDifference 医嘱数量差值结构体
  12843. type PrescriptionDrugDifference struct {
  12844. DrugID int64 //基础库药品id
  12845. ID int64 //医嘱id
  12846. Difference float64 //差值
  12847. Unit string //单位
  12848. }
  12849. type PrescriptionGoodDifference struct {
  12850. GoodID int64 //基础库项目耗材id
  12851. ID int64 //医嘱id
  12852. Difference int64 //差值
  12853. Unit string //单位
  12854. Type int64 //类型
  12855. }
  12856. type EditCustomData struct {
  12857. adviceList []*models.HisDoctorAdviceInfo
  12858. projectList []*models.HisPrescriptionProject
  12859. }
  12860. type SrcCustomData struct {
  12861. adviceList []*models.HisDoctorAdviceInfo
  12862. projectList []*models.HisPrescriptionProject
  12863. }
  12864. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12865. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12866. differences := make([]*PrescriptionDrugDifference, 0)
  12867. // 创建一个 map 来存储第一个切片中的药品信息
  12868. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12869. for _, advice := range firstPrescription {
  12870. firstMap[advice.DrugId] = advice
  12871. }
  12872. // 遍历第二个切片中的药品信息,并比较数量差值
  12873. for _, advice := range secondPrescription {
  12874. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12875. diff := &PrescriptionDrugDifference{
  12876. DrugID: advice.DrugId,
  12877. ID: firstAdvice.ID,
  12878. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12879. Unit: firstAdvice.PrescribingNumberUnit,
  12880. }
  12881. differences = append(differences, diff)
  12882. }
  12883. }
  12884. return differences
  12885. }
  12886. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12887. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12888. differences := make([]*PrescriptionGoodDifference, 0)
  12889. // 创建一个 map 来存储第一个切片中的耗材信息
  12890. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12891. for _, good := range firstPrescription {
  12892. firstMap[good.ProjectId] = good
  12893. }
  12894. // 遍历第二个切片中的耗材信息,并比较数量差值
  12895. for _, good := range secondPrescription {
  12896. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12897. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12898. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12899. diff := &PrescriptionGoodDifference{
  12900. GoodID: good.ProjectId,
  12901. ID: firstGood.ID,
  12902. Difference: count - firstCount,
  12903. Unit: firstGood.Unit,
  12904. Type: firstGood.Type,
  12905. }
  12906. differences = append(differences, diff)
  12907. }
  12908. }
  12909. return differences
  12910. }
  12911. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12912. var adviceList []*models.HisDoctorAdviceInfo
  12913. var projectList []*models.HisPrescriptionProject
  12914. var advice_ids []int64
  12915. var project_ids []int64
  12916. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12917. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12918. //var tempPrescription *models.HisPrescriptionProjectscription
  12919. if len(prescriptions) > 0 {
  12920. for _, item := range prescriptions {
  12921. items := item.(map[string]interface{})
  12922. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12923. advices := items["advices"].([]interface{})
  12924. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12925. groupNo := int64(0)
  12926. ctime := time.Now().Unix()
  12927. mtime := ctime
  12928. if len(advices) > 0 {
  12929. for _, advice := range advices {
  12930. var s models.HisDoctorAdviceInfo
  12931. s.AdviceType = 2
  12932. s.StopState = 2
  12933. s.ExecutionState = 2
  12934. s.Status = 1
  12935. s.Groupno = groupNo
  12936. s.CreatedTime = ctime
  12937. s.UpdatedTime = mtime
  12938. s.IsSettle = 2
  12939. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12940. //存储切片中
  12941. if s.ID > 0 {
  12942. advice_ids = append(advice_ids, s.ID)
  12943. adviceList = append(adviceList, &s)
  12944. }
  12945. }
  12946. }
  12947. }
  12948. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12949. projects := items["project"].([]interface{})
  12950. if len(projects) > 0 {
  12951. for _, project := range projects {
  12952. var p models.HisPrescriptionProject
  12953. p.Ctime = time.Now().Unix()
  12954. p.Mtime = time.Now().Unix()
  12955. p.Status = 1
  12956. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12957. if p.ID > 0 {
  12958. project_ids = append(project_ids, p.ID)
  12959. projectList = append(projectList, &p)
  12960. }
  12961. }
  12962. }
  12963. }
  12964. }
  12965. }
  12966. }
  12967. editCustomData.projectList = projectList
  12968. editCustomData.adviceList = adviceList
  12969. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12970. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12971. srcCustomData.adviceList = list
  12972. srcCustomData.projectList = list2
  12973. return
  12974. }
  12975. func (c *HisApiController) GetAllGoodInforList() {
  12976. orgId := c.GetAdminUserInfo().CurrentOrgId
  12977. goodList, _ := service.GetAllGoodList(orgId)
  12978. c.ServeSuccessJSON(map[string]interface{}{
  12979. "goodList": goodList,
  12980. })
  12981. return
  12982. }
  12983. func (this *HisApiController) SaveGoodList() {
  12984. project_name := this.GetString("project_name")
  12985. sort, _ := this.GetInt64("sort")
  12986. orgId := this.GetAdminUserInfo().CurrentOrgId
  12987. dataBody := make(map[string]interface{}, 0)
  12988. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12989. if err != nil {
  12990. utils.ErrorLog(err.Error())
  12991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12992. return
  12993. }
  12994. goodTeam := models.XtGoodTeam{
  12995. ProjectName: project_name,
  12996. Sort: sort,
  12997. UserOrgId: orgId,
  12998. Status: 1,
  12999. Ctime: time.Now().Unix(),
  13000. Mtime: time.Now().Unix(),
  13001. }
  13002. service.CreateGoodTeam(goodTeam)
  13003. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13004. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13005. infos, _ := dataBody["info"].([]interface{})
  13006. if len(infos) > 0 {
  13007. for _, item := range infos {
  13008. items := item.(map[string]interface{})
  13009. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13010. utils.ErrorLog("good_id")
  13011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13012. return
  13013. }
  13014. good_id := int64(items["good_id"].(float64))
  13015. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13016. utils.ErrorLog("number")
  13017. }
  13018. number := int64(items["number"].(float64))
  13019. xtGoodTeamList := models.XtGoodTeamList{
  13020. GoodId: good_id,
  13021. Count: number,
  13022. TeamId: lastGoodTeam.ID,
  13023. UserOrgId: orgId,
  13024. Status: 1,
  13025. Ctime: time.Now().Unix(),
  13026. Mtime: time.Now().Unix(),
  13027. }
  13028. service.CreateGoodList(xtGoodTeamList)
  13029. }
  13030. this.ServeSuccessJSON(map[string]interface{}{
  13031. "lastGoodTeam": lastGoodTeam,
  13032. })
  13033. }
  13034. }
  13035. return
  13036. }
  13037. func (this *HisApiController) GetGoodList() {
  13038. orgId := this.GetAdminUserInfo().CurrentOrgId
  13039. limit, _ := this.GetInt64("limit")
  13040. page, _ := this.GetInt64("page")
  13041. keyword := this.GetString("keyword")
  13042. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13043. this.ServeSuccessJSON(map[string]interface{}{
  13044. "list": list,
  13045. "total": total,
  13046. })
  13047. }
  13048. func (this *HisApiController) GetGoodNameDetail() {
  13049. id, _ := this.GetInt64("id")
  13050. orgId := this.GetAdminUserInfo().CurrentOrgId
  13051. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13052. goodList, _ := service.GetAllGoodList(orgId)
  13053. this.ServeSuccessJSON(map[string]interface{}{
  13054. "goodNameDetail": goodNameDetail,
  13055. "goodList": goodList,
  13056. })
  13057. }
  13058. func (this *HisApiController) UpdateGoodList() {
  13059. project_name := this.GetString("project_name")
  13060. sort, _ := this.GetInt64("sort")
  13061. id, _ := this.GetInt64("id")
  13062. orgId := this.GetAdminUserInfo().CurrentOrgId
  13063. dataBody := make(map[string]interface{}, 0)
  13064. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13065. if err != nil {
  13066. utils.ErrorLog(err.Error())
  13067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13068. return
  13069. }
  13070. goodTeam := models.XtGoodTeam{
  13071. ProjectName: project_name,
  13072. Sort: sort,
  13073. UserOrgId: orgId,
  13074. Status: 1,
  13075. Ctime: time.Now().Unix(),
  13076. Mtime: time.Now().Unix(),
  13077. ID: id,
  13078. }
  13079. service.SaveGoodTeam(goodTeam)
  13080. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13081. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13082. infos, _ := dataBody["info"].([]interface{})
  13083. if len(infos) > 0 {
  13084. for _, item := range infos {
  13085. items := item.(map[string]interface{})
  13086. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13087. utils.ErrorLog("good_id")
  13088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13089. return
  13090. }
  13091. good_id := int64(items["good_id"].(float64))
  13092. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13093. utils.ErrorLog("id")
  13094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13095. return
  13096. }
  13097. id := int64(items["id"].(float64))
  13098. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13099. utils.ErrorLog("number")
  13100. }
  13101. number := int64(items["number"].(float64))
  13102. xtGoodTeamList := models.XtGoodTeamList{
  13103. ID: id,
  13104. GoodId: good_id,
  13105. Count: number,
  13106. TeamId: lastGoodTeam.ID,
  13107. UserOrgId: orgId,
  13108. Status: 1,
  13109. Ctime: time.Now().Unix(),
  13110. Mtime: time.Now().Unix(),
  13111. }
  13112. service.SaveGoodList(xtGoodTeamList)
  13113. }
  13114. this.ServeSuccessJSON(map[string]interface{}{
  13115. "lastGoodTeam": lastGoodTeam,
  13116. })
  13117. }
  13118. }
  13119. return
  13120. }
  13121. func (this *HisApiController) DeleteGoodTeam() {
  13122. id, _ := this.GetInt64("id")
  13123. team, _ := service.DeleteGoodTeam(id)
  13124. this.ServeSuccessJSON(map[string]interface{}{
  13125. "team": team,
  13126. })
  13127. }
  13128. func (this *HisApiController) DeleteGood() {
  13129. id, _ := this.GetInt64("id")
  13130. good, _ := service.DeleteGood(id)
  13131. this.ServeSuccessJSON(map[string]interface{}{
  13132. "good": good,
  13133. })
  13134. }