his_api_controller.go 551KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177
  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. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. "prescriptionInfo": prescriptionInfo,
  1485. })
  1486. return
  1487. }
  1488. func (c *HisApiController) GetHisPrescriptionConfig() {
  1489. adminInfo := c.GetAdminUserInfo()
  1490. //获取医嘱模版
  1491. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1492. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1493. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1494. //获取所有基础药
  1495. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1496. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1497. if config.ID > 0 && config.IsOpen == 1 {
  1498. for _, item := range drugs {
  1499. var index = 0
  1500. for _, subItem := range item.OtherDrugWarehouseInfo {
  1501. if index == 0 {
  1502. index = index + 1
  1503. if subItem.RetailPrice > 0 {
  1504. item.MinPrice = subItem.RetailPrice
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1511. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1512. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1513. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1514. //获取所有科室信息
  1515. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1516. //获取诊断信息
  1517. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1518. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1519. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1520. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "drugs": drugs,
  1525. "advices_template": advices,
  1526. "drugways": drugways,
  1527. "efs": efs,
  1528. "doctors": doctors,
  1529. "department": department,
  1530. "sick": sick,
  1531. "additions": additions,
  1532. "diagnose": diagnose,
  1533. "manufacturers": manufacturers,
  1534. "goodOutOpen": goodOutOpen,
  1535. "patientDiagnose": patientDiagnose,
  1536. })
  1537. }
  1538. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1539. //获取所有基础药
  1540. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1541. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1542. if config.ID > 0 && config.IsOpen == 1 {
  1543. for _, item := range drugs {
  1544. var index = 0
  1545. for _, subItem := range item.OtherDrugWarehouseInfo {
  1546. if index == 0 {
  1547. index = index + 1
  1548. if subItem.RetailPrice > 0 {
  1549. item.MinPrice = subItem.RetailPrice
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1556. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1557. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1558. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1559. //获取所有科室信息
  1560. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1561. //获取诊断信息
  1562. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1563. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1564. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1565. //获取是否开启保存耗材出库的开关
  1566. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1567. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1568. c.ServeSuccessJSON(map[string]interface{}{
  1569. "drugs": drugs,
  1570. "advices_template": advices,
  1571. "drugways": drugways,
  1572. "efs": efs,
  1573. "doctors": doctors,
  1574. "department": department,
  1575. "sick": sick,
  1576. "additions": additions,
  1577. "diagnose": diagnose,
  1578. "manufacturers": manufacturers,
  1579. "goodOutOpen": goodOutOpen,
  1580. "patientDiagnose": patientDiagnose,
  1581. })
  1582. }
  1583. }
  1584. func (c *HisApiController) CreateHisPrescription() {
  1585. record_date := c.GetString("record_date")
  1586. patient_id, _ := c.GetInt64("patient_id")
  1587. reg_type, _ := c.GetInt64("reg_type")
  1588. diagnose := c.GetString("diagnose")
  1589. sick_type, _ := c.GetInt64("sick_type")
  1590. sick_history := c.GetString("sick_history")
  1591. doctor_id, _ := c.GetInt64("doctor", 0)
  1592. department, _ := c.GetInt64("department", 0)
  1593. his_patient_id, _ := c.GetInt64("his_patient_id")
  1594. p_type, _ := c.GetInt64("p_type")
  1595. patient_diagnose := c.GetString("patient_diagnose")
  1596. dataBody := make(map[string]interface{}, 0)
  1597. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1598. if err != nil {
  1599. utils.ErrorLog(err.Error())
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1601. return
  1602. }
  1603. //edit, src := GetCompareData(dataBody)
  1604. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1605. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1606. //fmt.Println(drugResult)
  1607. //fmt.Println(goodResult)
  1608. timeLayout := "2006-01-02"
  1609. loc, _ := time.LoadLocation("Local")
  1610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1611. if err != nil {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. adminInfo := c.GetAdminUserInfo()
  1616. recordDateTime := theTime.Unix()
  1617. //查询默认出库仓库库存
  1618. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1619. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1620. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1621. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1622. if len(lists) == 1 {
  1623. his_patient_id = lists[0].ID
  1624. }
  1625. }
  1626. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1627. //自动出库的开关开启
  1628. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //自动出库
  1630. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1631. //耗材保存处方出库
  1632. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1634. //已发药和已收费限制逻辑
  1635. isMidicine := false
  1636. isCharge := false
  1637. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1638. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1639. if len(prescriptions) > 0 {
  1640. for _, item := range prescriptions {
  1641. items := item.(map[string]interface{})
  1642. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1643. utils.ErrorLog("id")
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. id := int64(items["id"].(float64))
  1648. if id > 0 {
  1649. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1650. if err != nil {
  1651. if new_prescription.OrderStatus == 4 {
  1652. isCharge = true
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. if isMidicine == true {
  1660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1661. return
  1662. }
  1663. if isCharge == true {
  1664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1665. return
  1666. }
  1667. // 开始主事务
  1668. db := service.XTWriteDB()
  1669. tx := db.Begin()
  1670. // 在函数结束时处理事务回滚
  1671. defer func() {
  1672. if r := recover(); r != nil {
  1673. tx.Rollback()
  1674. }
  1675. }()
  1676. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1677. //药品发药出库
  1678. if pharmacyConfig.IsOpen == 1 {
  1679. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1680. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1681. if len(prescriptions) > 0 {
  1682. for _, item := range prescriptions {
  1683. items := item.(map[string]interface{})
  1684. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1685. advices := items["advices"].([]interface{})
  1686. if len(advices) > 0 {
  1687. for _, advice := range advices {
  1688. var drug_id int64
  1689. var prescribing_number float64
  1690. var prescribingNumberUnit string
  1691. var adviceId int64
  1692. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1693. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1694. }
  1695. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1696. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1697. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1698. }
  1699. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1700. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1701. }
  1702. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1703. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1704. }
  1705. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1706. if drug.ID == 0 {
  1707. tx.Rollback()
  1708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1709. return
  1710. }
  1711. //查询药品的所有库存
  1712. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1713. var total_count int64
  1714. for _, it := range list {
  1715. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1716. }
  1717. totals := strconv.FormatInt(total_count, 10)
  1718. //查询该药品是否存在开药记录
  1719. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1720. //新增处方盘点库存是否充足
  1721. if advicelist.ID == 0 {
  1722. all_count, _ := strconv.ParseFloat(totals, 64)
  1723. if prescribingNumberUnit == drug.MinUnit {
  1724. if drug.IsUse != 1 {
  1725. if drug.IsProject == 0 || drug.IsProject == 2 {
  1726. if all_count == 0 {
  1727. tx.Rollback()
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1729. return
  1730. }
  1731. if prescribing_number > all_count {
  1732. tx.Rollback()
  1733. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1734. return
  1735. }
  1736. }
  1737. }
  1738. }
  1739. if prescribingNumberUnit == drug.MaxUnit {
  1740. num := prescribing_number * float64(drug.MinNumber)
  1741. if drug.IsUse != 1 {
  1742. if drug.IsProject == 0 || drug.IsProject == 2 {
  1743. if all_count == 0 {
  1744. tx.Rollback()
  1745. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1746. return
  1747. }
  1748. if num > all_count {
  1749. tx.Rollback()
  1750. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1751. return
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1758. //不使用保存处方出库
  1759. if drugOutConfig.IsOpen != 1 {
  1760. //修改处方
  1761. for _, advice := range advices {
  1762. var drug_id int64
  1763. var prescribing_number float64
  1764. var prescribingNumberUnit string
  1765. var prescribingNumber string
  1766. var adviceId int64
  1767. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1768. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1769. }
  1770. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1771. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1772. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1773. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1774. }
  1775. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1776. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1777. }
  1778. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1779. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1780. }
  1781. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1782. if drug.ID == 0 {
  1783. tx.Rollback()
  1784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1785. return
  1786. }
  1787. //查询药品的所有库存
  1788. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1789. var total_count int64
  1790. for _, it := range list {
  1791. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1792. }
  1793. totals := strconv.FormatInt(total_count, 10)
  1794. //查询该药品是否存在开药记录
  1795. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1796. //新增处方
  1797. if advicelist.ID == 0 {
  1798. all_count, _ := strconv.ParseFloat(totals, 64)
  1799. if prescribingNumberUnit == drug.MinUnit {
  1800. if drug.IsUse != 1 {
  1801. if drug.IsProject == 0 || drug.IsProject == 2 {
  1802. if all_count == 0 {
  1803. tx.Rollback()
  1804. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1805. return
  1806. }
  1807. if prescribing_number > all_count {
  1808. tx.Rollback()
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1810. return
  1811. }
  1812. }
  1813. }
  1814. } else {
  1815. if prescribingNumberUnit == drug.MaxUnit {
  1816. num := prescribing_number * float64(drug.MinNumber)
  1817. if drug.IsUse != 1 {
  1818. if drug.IsProject == 0 || drug.IsProject == 2 {
  1819. if all_count == 0 {
  1820. tx.Rollback()
  1821. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1822. return
  1823. }
  1824. if num > all_count {
  1825. tx.Rollback()
  1826. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. //修改处方
  1835. if advicelist.ID > 0 {
  1836. var device_number int64
  1837. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt * drug.MinNumber
  1841. }
  1842. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1843. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1845. device_number = prescribingNumberInt
  1846. }
  1847. var number_count int64
  1848. if prescribingNumberUnit == drug.MaxUnit {
  1849. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1850. number_count = prescribingNumberInt * drug.MinNumber
  1851. }
  1852. if prescribingNumberUnit == drug.MinUnit {
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1854. number_count = prescribingNumberInt
  1855. }
  1856. //如果修改的数量大于之前修改的数量
  1857. if (number_count - device_number) > 0 {
  1858. //如果修改的差数量 大于库存数量
  1859. if drug.IsUse != 1 {
  1860. if (number_count - device_number) > total_count {
  1861. tx.Rollback()
  1862. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1863. return
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. //已发药和已收费限制逻辑
  1878. //执行出库的逻辑
  1879. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1880. //校验库存总量
  1881. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1882. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1883. if len(prescriptions) > 0 {
  1884. for _, item := range prescriptions {
  1885. items := item.(map[string]interface{})
  1886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1887. advices := items["advices"].([]interface{})
  1888. if len(advices) > 0 {
  1889. for _, advice := range advices {
  1890. var drug_id int64
  1891. var prescribing_number float64
  1892. var prescribingNumberUnit string
  1893. var adviceId int64
  1894. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1895. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1896. }
  1897. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1898. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1899. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1900. }
  1901. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1902. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1903. }
  1904. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1905. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1906. }
  1907. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1908. if drug.ID == 0 {
  1909. tx.Rollback()
  1910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1911. return
  1912. }
  1913. //查询药品的所有库存
  1914. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1915. var total_count int64
  1916. for _, it := range list {
  1917. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1918. }
  1919. totals := strconv.FormatInt(total_count, 10)
  1920. //查询该药品是否存在开药记录
  1921. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1922. //查询最新批次库存
  1923. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1924. var batch_number_count int64
  1925. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1926. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1927. //新增处方
  1928. if advicelist.ID == 0 {
  1929. all_count, _ := strconv.ParseFloat(totals, 64)
  1930. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1931. if prescribingNumberUnit == drug.MinUnit {
  1932. if drug.IsUse != 1 {
  1933. if drug.IsProject == 0 || drug.IsProject == 2 {
  1934. if all_count == 0 {
  1935. tx.Rollback()
  1936. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1937. return
  1938. }
  1939. if prescribing_number > all_count {
  1940. tx.Rollback()
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. }
  1945. if adminInfo.CurrentOrgId == 10215 {
  1946. if prescribing_number > batch_number_all_count {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1949. return
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if prescribingNumberUnit == drug.MaxUnit {
  1955. num := prescribing_number * float64(drug.MinNumber)
  1956. if drug.IsUse != 1 {
  1957. if drug.IsProject == 0 || drug.IsProject == 2 {
  1958. if all_count == 0 {
  1959. tx.Rollback()
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1961. return
  1962. }
  1963. if num > all_count {
  1964. tx.Rollback()
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1966. return
  1967. }
  1968. }
  1969. if adminInfo.CurrentOrgId == 10215 {
  1970. if num > batch_number_all_count {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1973. return
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. //不是保存处方出库
  1980. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1981. if drugOutConfig.IsOpen != 1 {
  1982. //修改处方
  1983. for _, advice := range advices {
  1984. var drug_id int64
  1985. var prescribing_number float64
  1986. var prescribingNumberUnit string
  1987. var prescribingNumber string
  1988. var adviceId int64
  1989. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1990. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1991. }
  1992. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1993. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1994. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1995. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1996. }
  1997. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1998. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1999. }
  2000. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2001. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2002. }
  2003. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2004. if drug.ID == 0 {
  2005. tx.Rollback()
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2007. return
  2008. }
  2009. //查询药品的所有库存
  2010. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2011. var total_count int64
  2012. for _, it := range list {
  2013. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2014. }
  2015. totals := strconv.FormatInt(total_count, 10)
  2016. //查询该药品是否存在开药记录
  2017. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2018. //新增处方
  2019. if advicelist.ID == 0 {
  2020. //查询最新批次库存
  2021. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2022. var batch_number_count int64
  2023. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2024. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2025. all_count, _ := strconv.ParseFloat(totals, 64)
  2026. if all_count == 0 {
  2027. tx.Rollback()
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2029. return
  2030. }
  2031. if prescribingNumberUnit == drug.MinUnit {
  2032. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2033. if drug.IsUse != 1 {
  2034. if drug.IsProject == 0 || drug.IsProject == 2 {
  2035. if all_count == 0 {
  2036. tx.Rollback()
  2037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2038. return
  2039. }
  2040. if prescribing_number > all_count {
  2041. tx.Rollback()
  2042. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2043. return
  2044. }
  2045. }
  2046. if adminInfo.CurrentOrgId == 10215 {
  2047. if prescribing_number > batch_number_all_count {
  2048. tx.Rollback()
  2049. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2050. return
  2051. }
  2052. }
  2053. }
  2054. } else {
  2055. if prescribingNumberUnit == drug.MaxUnit {
  2056. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2057. num := prescribing_number * float64(drug.MinNumber)
  2058. if drug.IsUse != 1 {
  2059. if drug.IsProject == 0 || drug.IsProject == 2 {
  2060. if all_count == 0 {
  2061. tx.Rollback()
  2062. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2063. return
  2064. }
  2065. if num > all_count {
  2066. tx.Rollback()
  2067. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2068. return
  2069. }
  2070. }
  2071. if adminInfo.CurrentOrgId == 10215 {
  2072. if prescribing_number > batch_number_all_count {
  2073. tx.Rollback()
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2075. return
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. //修改处方
  2083. if advicelist.ID > 0 {
  2084. //查询最新批次库存
  2085. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2086. var batch_number_count int64
  2087. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2088. var device_number int64
  2089. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2090. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2091. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2092. device_number = prescribingNumberInt * drug.MinNumber
  2093. }
  2094. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2095. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2096. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2097. device_number = prescribingNumberInt
  2098. //回退库存
  2099. }
  2100. var number_count int64
  2101. if prescribingNumberUnit == drug.MaxUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt * drug.MinNumber
  2104. //回退库存
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  2109. //回退库存
  2110. }
  2111. //如果修改的数量大于之前修改的数量
  2112. if (number_count - device_number) > 0 {
  2113. //如果修改的差数量 大于库存数量
  2114. if drug.IsUse != 1 {
  2115. if drug.IsProject == 0 || drug.IsProject == 2 {
  2116. if total_count == 0 {
  2117. tx.Rollback()
  2118. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2119. return
  2120. }
  2121. if (number_count - device_number) > total_count {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. if (number_count - device_number) > batch_number_count {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2129. return
  2130. }
  2131. }
  2132. if adminInfo.CurrentOrgId == 10215 {
  2133. // 查询该药品最后一次出库记录
  2134. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2135. var out_count int64
  2136. var in_count int64
  2137. var stock_max_number int64
  2138. var stock_min_number int64
  2139. for _, it := range outInfo {
  2140. if it.CountUnit == drug.MaxUnit {
  2141. it.Count = it.Count * drug.MinNumber
  2142. }
  2143. out_count += it.Count
  2144. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2145. stock_max_number = warehouseInfoList.StockMaxNumber
  2146. stock_min_number = warehouseInfoList.StockMinNumber
  2147. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2148. }
  2149. if out_count > 0 {
  2150. if (number_count - device_number) > in_count {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2153. return
  2154. }
  2155. }
  2156. // 未出库
  2157. if out_count == 0 {
  2158. var sum_in_count int64
  2159. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2160. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //药品发药
  2172. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2173. //不使用药品发药的功能
  2174. //if pharmacyConfig.IsOpen != 1 {
  2175. // if device_number != number_count {
  2176. //
  2177. // //查询该药品的出库记录
  2178. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2179. // if len(outListExport) > 0 {
  2180. // //
  2181. // for _, item := range outListExport {
  2182. // //回退库存
  2183. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2184. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2185. // }
  2186. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2187. // var stock_max_number int64
  2188. // var stock_min_number int64
  2189. //
  2190. // if number_count >= drug.MinNumber {
  2191. //
  2192. // stock_max_number = device_number / drug.MinNumber
  2193. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2194. //
  2195. // stock_min_number = device_number % drug.MinNumber
  2196. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2197. //
  2198. // } else {
  2199. //
  2200. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2201. //
  2202. // }
  2203. // }
  2204. //
  2205. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2206. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2207. // }
  2208. // }
  2209. // }
  2210. //
  2211. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2212. // var sum_count int64
  2213. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2214. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2215. // for _, its := range stockInfo {
  2216. // if its.MaxUnit == drug.MaxUnit {
  2217. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2218. // }
  2219. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2220. // }
  2221. // //更新字典里面的库存
  2222. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2223. //
  2224. // //剩余库存
  2225. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2226. //
  2227. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2228. // //减少出库数量
  2229. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2230. //
  2231. // }
  2232. //}
  2233. }
  2234. }
  2235. }
  2236. //保存处方开药
  2237. if drugOutConfig.IsOpen == 1 {
  2238. //修改处方
  2239. for _, advice := range advices {
  2240. var drug_id int64
  2241. var prescribing_number float64
  2242. var prescribingNumberUnit string
  2243. var prescribingNumber string
  2244. var adviceId int64
  2245. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2246. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2247. }
  2248. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2249. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2250. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2251. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2252. }
  2253. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2254. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2255. }
  2256. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2257. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2258. }
  2259. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2260. if drug.ID == 0 {
  2261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2262. return
  2263. }
  2264. //查询药品的所有库存
  2265. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2266. var total_count int64
  2267. for _, it := range list {
  2268. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2269. }
  2270. totals := strconv.FormatInt(total_count, 10)
  2271. //查询该药品是否存在开药记录
  2272. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2273. //新增处方
  2274. if advicelist.ID == 0 {
  2275. //查询最新批次库存
  2276. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2277. var batch_number_count int64
  2278. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2279. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2280. all_count, _ := strconv.ParseFloat(totals, 64)
  2281. if prescribingNumberUnit == drug.MinUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. if drug.IsUse != 1 {
  2284. if drug.IsProject == 0 || drug.IsProject == 2 {
  2285. if all_count == 0 {
  2286. tx.Rollback()
  2287. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2288. return
  2289. }
  2290. if prescribing_number > all_count {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. }
  2296. if adminInfo.CurrentOrgId == 10215 {
  2297. if prescribing_number > batch_number_all_count {
  2298. tx.Rollback()
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2300. return
  2301. }
  2302. }
  2303. }
  2304. } else {
  2305. if prescribingNumberUnit == drug.MaxUnit {
  2306. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2307. num := prescribing_number * float64(drug.MinNumber)
  2308. if drug.IsUse != 1 {
  2309. if drug.IsProject == 0 || drug.IsProject == 2 {
  2310. if all_count == 0 {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if num > all_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. if prescribing_number > batch_number_all_count {
  2323. tx.Rollback()
  2324. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2325. return
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. //修改处方
  2333. if advicelist.ID > 0 {
  2334. //查询最新批次库存
  2335. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2336. var batch_number_count int64
  2337. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2338. var device_number int64
  2339. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2340. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2341. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2342. device_number = prescribingNumberInt * drug.MinNumber
  2343. }
  2344. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2345. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2346. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2347. device_number = prescribingNumberInt
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. }
  2354. if prescribingNumberUnit == drug.MinUnit {
  2355. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2356. number_count = prescribingNumberInt
  2357. }
  2358. //如果修改的数量大于之前修改的数量
  2359. if (number_count - device_number) > 0 {
  2360. //如果修改的差数量 大于库存数量
  2361. if drug.IsUse != 1 {
  2362. if drug.IsProject == 0 || drug.IsProject == 2 {
  2363. if total_count == 0 {
  2364. tx.Rollback()
  2365. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2366. return
  2367. }
  2368. if (number_count - device_number) > total_count {
  2369. tx.Rollback()
  2370. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2371. return
  2372. }
  2373. }
  2374. if adminInfo.CurrentOrgId == 10215 {
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2382. //查询历史出库数据总批次
  2383. // 查询该药品最后一次出库记录
  2384. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2385. var out_count int64
  2386. var in_count int64
  2387. var stock_max_number int64
  2388. var stock_min_number int64
  2389. for _, it := range outInfo {
  2390. if it.CountUnit == drug.MaxUnit {
  2391. it.Count = it.Count * drug.MinNumber
  2392. }
  2393. out_count += it.Count
  2394. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2395. stock_max_number = warehouseInfoList.StockMaxNumber
  2396. stock_min_number = warehouseInfoList.StockMinNumber
  2397. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2398. }
  2399. if out_count > 0 {
  2400. if (number_count - device_number) > in_count {
  2401. tx.Rollback()
  2402. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2403. return
  2404. }
  2405. }
  2406. // 未出库
  2407. if out_count == 0 {
  2408. var sum_in_count int64
  2409. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2410. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2411. if sum_in_count == 0 {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. //如果修改的数量大于有库存的第一个批次
  2417. if number_count > sum_in_count {
  2418. tx.Rollback()
  2419. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2420. return
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. //校验耗材库存
  2437. if goodOutConfig.IsOpen == 1 {
  2438. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2439. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2440. if len(prescriptions) > 0 {
  2441. for _, item := range prescriptions {
  2442. items := item.(map[string]interface{})
  2443. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2444. projects := items["project"].([]interface{})
  2445. if len(projects) > 0 {
  2446. for _, project := range projects {
  2447. var project_id int64
  2448. var project_type int64
  2449. var totals float64
  2450. var project_name string
  2451. var parsetotal int64
  2452. var id int64
  2453. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2454. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2455. }
  2456. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2457. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2458. }
  2459. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2460. total, _ := project.(map[string]interface{})["total"].(string)
  2461. totals, _ = strconv.ParseFloat(total, 64)
  2462. }
  2463. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2464. project_name = project.(map[string]interface{})["project_name"].(string)
  2465. }
  2466. if project_type == 3 {
  2467. //查找该耗材的出库记录
  2468. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2469. if len(goodWarehouseInfo) == 0 {
  2470. //查询耗材库存
  2471. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2472. var stock_count int64
  2473. for _, it := range list {
  2474. stock_count += it.StockCount
  2475. }
  2476. stock_counts := strconv.FormatInt(stock_count, 10)
  2477. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2478. if stock_total_count == 0 {
  2479. tx.Rollback()
  2480. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2481. return
  2482. }
  2483. if totals > stock_total_count {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. }
  2489. if len(goodWarehouseInfo) > 0 {
  2490. //查询该患者耗材的历史数据
  2491. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2492. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2493. //数量发生改变
  2494. if parsetotal != count {
  2495. //如果现在的数量大于历史数量,就要看库存是否足够
  2496. if parsetotal > count {
  2497. //查询耗材所有库存
  2498. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2499. var stock_count int64
  2500. for _, it := range list {
  2501. stock_count += it.StockCount
  2502. }
  2503. //库存不足
  2504. if stock_count == 0 {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2507. return
  2508. }
  2509. if (parsetotal - count) > stock_count {
  2510. tx.Rollback()
  2511. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2512. return
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. //不使用耗材保存处方出库
  2526. if goodOutConfig.IsOpen != 1 {
  2527. if stockConfig.IsOpen == 1 {
  2528. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2529. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2530. if len(prescriptions) > 0 {
  2531. for _, item := range prescriptions {
  2532. items := item.(map[string]interface{})
  2533. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2534. projects := items["project"].([]interface{})
  2535. if len(projects) > 0 {
  2536. for _, project := range projects {
  2537. var project_id int64
  2538. var project_type int64
  2539. var totals float64
  2540. var project_name string
  2541. var parsetotal int64
  2542. var id int64
  2543. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2544. id = int64(project.(map[string]interface{})["id"].(float64))
  2545. }
  2546. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2547. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2548. }
  2549. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2550. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2551. }
  2552. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2553. total, _ := project.(map[string]interface{})["total"].(string)
  2554. totals, _ = strconv.ParseFloat(total, 64)
  2555. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2556. }
  2557. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2558. project_name = project.(map[string]interface{})["project_name"].(string)
  2559. }
  2560. if project_type == 3 {
  2561. //查找该耗材的出库记录
  2562. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2563. //没有出库记录
  2564. if len(goodWarehouseInfo) == 0 {
  2565. //查询耗材库存
  2566. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2567. var stock_count int64
  2568. for _, it := range list {
  2569. stock_count += it.StockCount
  2570. }
  2571. stock_counts := strconv.FormatInt(stock_count, 10)
  2572. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2573. if stock_total_count == 0 {
  2574. tx.Rollback()
  2575. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2576. return
  2577. }
  2578. if totals > stock_total_count {
  2579. tx.Rollback()
  2580. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2581. return
  2582. }
  2583. //查找今日该患者已经出库的所有耗材
  2584. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2585. for _, item := range goodList {
  2586. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2587. var flush_count int64
  2588. for _, it := range goodListSix {
  2589. flush_count += it.StockCount
  2590. }
  2591. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2592. creater := adminInfo.AdminUser.Id
  2593. if errs != nil {
  2594. goodErrcode := models.XtGoodErrcode{
  2595. UserOrgId: item.OrgId,
  2596. Errcode: "手动出库更新剩余出库失败",
  2597. GoodId: item.GoodId,
  2598. Status: 1,
  2599. Ctime: time.Now().Unix(),
  2600. Mtime: 0,
  2601. Count: 0,
  2602. StockCount: 0,
  2603. Creater: creater,
  2604. BatchNumberId: 0,
  2605. WarehouseOutId: 0,
  2606. }
  2607. service.CreateGoodErrcode(goodErrcode)
  2608. }
  2609. }
  2610. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2611. }
  2612. //有出库记录
  2613. if len(goodWarehouseInfo) > 0 {
  2614. //查询该患者耗材的历史数据
  2615. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2616. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2617. //数量发生改变
  2618. if parsetotal != count {
  2619. //查找今日该患者已经出库的所有耗材
  2620. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2621. for _, item := range goodList {
  2622. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2623. var flush_count int64
  2624. for _, it := range goodListSix {
  2625. flush_count += it.StockCount
  2626. }
  2627. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2628. //减少出库数量
  2629. creater := adminInfo.AdminUser.Id
  2630. if errs != nil {
  2631. goodErrcode := models.XtGoodErrcode{
  2632. UserOrgId: item.OrgId,
  2633. Errcode: "手动出库更新剩余出库失败",
  2634. GoodId: item.GoodId,
  2635. Status: 1,
  2636. Ctime: time.Now().Unix(),
  2637. Mtime: 0,
  2638. Count: 0,
  2639. StockCount: 0,
  2640. Creater: creater,
  2641. BatchNumberId: 0,
  2642. WarehouseOutId: 0,
  2643. }
  2644. service.CreateGoodErrcode(goodErrcode)
  2645. }
  2646. //查询默认仓库
  2647. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2648. var total_count int64
  2649. for _, it := range stockList {
  2650. total_count += it.StockCount
  2651. }
  2652. //基础库插入数据
  2653. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2654. }
  2655. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. }
  2667. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2668. var hpInfo models.HisPrescriptionInfo
  2669. if info.ID == 0 {
  2670. var randNum int
  2671. randNum = rand.Intn(10000) + 1000
  2672. timestamp := time.Now().Unix()
  2673. tempTime := time.Unix(timestamp, 0)
  2674. timeFormat := tempTime.Format("20060102150405")
  2675. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2676. hpInfo = models.HisPrescriptionInfo{
  2677. HisPatientId: his_patient_id,
  2678. UserOrgId: adminInfo.CurrentOrgId,
  2679. RecordDate: theTime.Unix(),
  2680. PatientId: patient_id,
  2681. Status: 1,
  2682. Ctime: time.Now().Unix(),
  2683. Mtime: time.Now().Unix(),
  2684. Creator: adminInfo.AdminUser.Id,
  2685. Modifier: adminInfo.AdminUser.Id,
  2686. Diagnosis: diagnose,
  2687. SickHistory: sick_history,
  2688. Departments: department,
  2689. RegisterType: reg_type,
  2690. PrescriptionNumber: p_number,
  2691. PrescriptionStatus: 1,
  2692. Doctor: role.UserName,
  2693. DoctorId: doctor_id,
  2694. SickType: sick_type,
  2695. PType: p_type,
  2696. PatientDiagnosis: patient_diagnose,
  2697. }
  2698. service.SavePatientPrescriptionInfo(hpInfo)
  2699. //创建步骤表
  2700. finish := models.XtDialysisFinish{
  2701. IsFinish: 1,
  2702. UserOrgId: adminInfo.CurrentOrgId,
  2703. Status: 1,
  2704. Ctime: time.Now().Unix(),
  2705. Mtime: 0,
  2706. Module: 4,
  2707. RecordDate: theTime.Unix(),
  2708. Sourse: 1,
  2709. PatientId: patient_id,
  2710. }
  2711. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2712. if dialysisFinish.ID == 0 {
  2713. service.CreateDialysisFinish(finish)
  2714. }
  2715. redis := service.RedisClient()
  2716. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2719. redis.Set(keyOne, "", time.Second)
  2720. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2721. redis.Set(keySeven, "", time.Second)
  2722. defer redis.Close()
  2723. } else {
  2724. hpInfo = models.HisPrescriptionInfo{
  2725. ID: info.ID,
  2726. UserOrgId: adminInfo.CurrentOrgId,
  2727. RecordDate: info.RecordDate,
  2728. PatientId: info.PatientId,
  2729. Status: 1,
  2730. Ctime: info.Ctime,
  2731. Mtime: time.Now().Unix(),
  2732. Creator: info.Creator,
  2733. Modifier: adminInfo.AdminUser.Id,
  2734. Diagnosis: diagnose,
  2735. SickHistory: sick_history,
  2736. Departments: department,
  2737. RegisterType: reg_type,
  2738. PrescriptionNumber: info.PrescriptionNumber,
  2739. Doctor: role.UserName,
  2740. PrescriptionStatus: info.PrescriptionStatus,
  2741. DoctorId: doctor_id,
  2742. SickType: sick_type,
  2743. PType: info.PType,
  2744. HisPatientId: info.HisPatientId,
  2745. PatientDiagnosis: patient_diagnose,
  2746. }
  2747. service.SavePatientPrescriptionInfo(hpInfo)
  2748. //创建步骤表
  2749. finish := models.XtDialysisFinish{
  2750. IsFinish: 1,
  2751. UserOrgId: adminInfo.CurrentOrgId,
  2752. Status: 1,
  2753. Ctime: time.Now().Unix(),
  2754. Mtime: 0,
  2755. Module: 4,
  2756. RecordDate: info.RecordDate,
  2757. Sourse: 1,
  2758. PatientId: info.PatientId,
  2759. }
  2760. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2761. if dialysisFinish.ID == 0 {
  2762. service.CreateDialysisFinish(finish)
  2763. }
  2764. redis := service.RedisClient()
  2765. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2766. redis.Set(key, "", time.Second)
  2767. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2768. redis.Set(keyOne, "", time.Second)
  2769. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2770. redis.Set(keySeven, "", time.Second)
  2771. defer redis.Close()
  2772. }
  2773. //定义切片
  2774. var adviceList []models.HisDoctorAdviceInfo
  2775. var projectList []models.HisPrescriptionProject
  2776. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. var tempPrescription *models.HisPrescription
  2780. if len(prescriptions) > 0 {
  2781. for _, item := range prescriptions {
  2782. // 开始外部循环的事务
  2783. tx := db.Begin()
  2784. // 在函数结束时处理事务回滚
  2785. defer func() {
  2786. if r := recover(); r != nil {
  2787. tx.Rollback()
  2788. }
  2789. }()
  2790. items := item.(map[string]interface{})
  2791. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2792. utils.ErrorLog("id")
  2793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2794. return
  2795. }
  2796. id := int64(items["id"].(float64))
  2797. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2798. tempPrescription = &new_prescription
  2799. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2800. utils.ErrorLog("type")
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. types := int64(items["type"].(float64))
  2805. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2806. utils.ErrorLog("med_type")
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2811. if med_type == "0" {
  2812. med_type = "14"
  2813. }
  2814. //if order_status == 0 {
  2815. // order_status = 1
  2816. //}
  2817. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2818. utils.ErrorLog("pre_time")
  2819. }
  2820. preTime, _ := items["pre_time"].(string)
  2821. fmt.Println("preTime", preTime)
  2822. timeLayout := "2006-01-02"
  2823. loc, _ := time.LoadLocation("Local")
  2824. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2825. //result := strings.Split(preTime, " ")
  2826. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2827. if err != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2829. return
  2830. }
  2831. pTime := theTime2.Unix()
  2832. ctime := time.Now().Unix()
  2833. if tempPrescription.ID == 0 {
  2834. prescription := &models.HisPrescription{
  2835. ID: 0,
  2836. PatientId: patient_id,
  2837. UserOrgId: adminInfo.CurrentOrgId,
  2838. RecordDate: recordDateTime,
  2839. Ctime: ctime,
  2840. Mtime: ctime,
  2841. Type: types,
  2842. Modifier: adminInfo.AdminUser.Id,
  2843. Creator: adminInfo.AdminUser.Id,
  2844. Status: 1,
  2845. Doctor: role.UserName,
  2846. HisPatientId: his_patient_id,
  2847. OrderStatus: 1,
  2848. BatchNumber: "",
  2849. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2850. PreTime: pTime,
  2851. PType: p_type,
  2852. MedType: med_type,
  2853. }
  2854. tempPrescription = prescription
  2855. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2856. redis := service.RedisClient()
  2857. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2858. redis.Set(key, "", time.Second)
  2859. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2860. redis.Set(keyOne, "", time.Second)
  2861. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2862. redis.Set(keySeven, "", time.Second)
  2863. defer redis.Close()
  2864. } else {
  2865. tempPrescription.ID = id
  2866. tempPrescription.Type = types
  2867. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2868. tempPrescription.Mtime = time.Now().Unix()
  2869. tempPrescription.Doctor = role.UserName
  2870. //tempPrescription.OrderStatus = order_status
  2871. tempPrescription.PreTime = pTime
  2872. tempPrescription.MedType = med_type
  2873. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2874. redis := service.RedisClient()
  2875. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2876. redis.Set(key, "", time.Second)
  2877. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2878. redis.Set(keyOne, "", time.Second)
  2879. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2880. redis.Set(keySeven, "", time.Second)
  2881. defer redis.Close()
  2882. }
  2883. //service.SaveHisPrescription(prescription)
  2884. //更改患者挂号状态
  2885. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2886. fmt.Println("更改失败", err2)
  2887. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2888. advices := items["advices"].([]interface{})
  2889. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2890. groupNo := int64(0)
  2891. if len(advices) > 0 {
  2892. for _, advice := range advices {
  2893. tx := db.Begin()
  2894. // 在函数结束时处理事务回滚
  2895. defer func() {
  2896. if r := recover(); r != nil {
  2897. tx.Rollback()
  2898. }
  2899. }()
  2900. var s models.HisDoctorAdviceInfo
  2901. s.PrescriptionId = tempPrescription.ID
  2902. s.AdviceType = 2
  2903. s.AdviceDoctor = doctor_id
  2904. s.StopState = 2
  2905. s.ExecutionState = 2
  2906. s.AdviceDate = theTime3.Unix()
  2907. s.Status = 1
  2908. s.UserOrgId = adminInfo.CurrentOrgId
  2909. s.RecordDate = theTime3.Unix()
  2910. s.StartTime = tempPrescription.PreTime
  2911. s.Groupno = groupNo
  2912. s.PatientId = patient_id
  2913. s.HisPatientId = his_patient_id
  2914. s.StartTime = pTime
  2915. s.IsSettle = 2
  2916. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2917. if errcode > 0 {
  2918. c.ServeFailJSONWithSGJErrorCode(errcode)
  2919. return
  2920. }
  2921. s.StartTime = pTime
  2922. var total_count int64 //处方总库存
  2923. //查询改药品信息
  2924. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2925. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2926. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2927. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2928. total_count += prescribingNumberSeven * medical.MinNumber
  2929. }
  2930. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2931. total_count += prescribingNumberSeven
  2932. }
  2933. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2934. total_count += prescribingNumberSeven
  2935. }
  2936. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2937. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2938. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2939. if s.Price != lastWarehouse.RetailPrice {
  2940. s.Price = lastWarehouse.RetailPrice
  2941. }
  2942. if s.Price == 0 {
  2943. if lastWarehouse.ID == 0 {
  2944. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2945. s.Price = lastWarehouseTwo.RetailPrice
  2946. }
  2947. }
  2948. }
  2949. //查询保存处方出库开关是否打开
  2950. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2951. if s.PatientId != 30038 {
  2952. if drugOutConfig.IsOpen == 1 {
  2953. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2954. // 查询该药品最后一次出库记录
  2955. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2956. var is_user_total int64
  2957. var no_user_total int64
  2958. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2959. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2960. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2961. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2962. }
  2963. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2964. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2965. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2966. no_user_total += prescribingNumberSevenTy
  2967. }
  2968. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2969. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2970. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2971. no_user_total += prescribingNumberSevenTy
  2972. }
  2973. if len(druginfo) > 0 {
  2974. for _, it := range druginfo {
  2975. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2976. it.Count = it.Count * drug.MinNumber
  2977. is_user_total += it.Count
  2978. }
  2979. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2980. is_user_total += it.Count
  2981. }
  2982. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2983. is_user_total += it.Count
  2984. }
  2985. }
  2986. }
  2987. //fmt.Println("药品名称----------------------", drug.DrugName)
  2988. //fmt.Println("药品名称----------------------", drug.IsUse)
  2989. //fmt.Println("is_user_total-------------------------", is_user_total)
  2990. //fmt.Println("no_user_total-------------------------", no_user_total)
  2991. if is_user_total != no_user_total {
  2992. //出库
  2993. if drug.IsUse == 2 {
  2994. creater := adminInfo.AdminUser.Id
  2995. newadviceInfo := &models.HisDoctorAdviceInfo{
  2996. ID: s.ID,
  2997. UserOrgId: s.UserOrgId,
  2998. PatientId: s.PatientId,
  2999. HisPatientId: s.HisPatientId,
  3000. AdviceType: s.AdviceType,
  3001. AdviceDate: s.AdviceDate,
  3002. StartTime: s.StartTime,
  3003. AdviceName: s.AdviceName,
  3004. AdviceDesc: s.AdviceDesc,
  3005. ReminderDate: s.ReminderDate,
  3006. SingleDose: s.SingleDose,
  3007. SingleDoseUnit: s.SingleDoseUnit,
  3008. PrescribingNumber: s.PrescribingNumber,
  3009. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3010. DeliveryWay: s.DeliveryWay,
  3011. ExecutionFrequency: s.ExecutionFrequency,
  3012. AdviceDoctor: s.AdviceDoctor,
  3013. Status: s.Status,
  3014. CreatedTime: s.CreatedTime,
  3015. UpdatedTime: s.UpdatedTime,
  3016. AdviceAffirm: s.AdviceAffirm,
  3017. Remark: s.Remark,
  3018. StopTime: s.StopTime,
  3019. StopReason: s.StopReason,
  3020. StopDoctor: s.StopDoctor,
  3021. StopState: s.StopState,
  3022. ParentId: s.ParentId,
  3023. ExecutionTime: s.ExecutionTime,
  3024. ExecutionStaff: s.ExecutionStaff,
  3025. ExecutionState: s.ExecutionState,
  3026. Checker: s.Checker,
  3027. RecordDate: s.RecordDate,
  3028. DialysisOrderId: s.DialysisOrderId,
  3029. CheckTime: s.CheckTime,
  3030. CheckState: s.CheckState,
  3031. DrugSpec: s.DrugSpec,
  3032. DrugSpecUnit: s.DrugSpecUnit,
  3033. Groupno: s.Groupno,
  3034. RemindType: s.RemindType,
  3035. FrequencyType: s.FrequencyType,
  3036. DayCount: s.DayCount,
  3037. WeekDay: s.WeekDay,
  3038. TemplateId: s.TemplateId,
  3039. Modifier: s.Modifier,
  3040. DrugId: s.DrugId,
  3041. Price: s.Price,
  3042. PrescriptionId: s.PrescriptionId,
  3043. MedListCodg: s.MedListCodg,
  3044. FeedetlSn: s.FeedetlSn,
  3045. Day: s.DayCount,
  3046. ChildDoctorAdvice: nil,
  3047. Drug: models.Drug{},
  3048. Diagnosis: s.Diagnosis,
  3049. Way: s.Way,
  3050. HospApprFlag: s.HospApprFlag,
  3051. LmtUsedFlag: s.LmtUsedFlag,
  3052. HisOrderInfo: models.HisOrderInfo{},
  3053. IsMedicine: s.IsMedicine,
  3054. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3055. Child: nil,
  3056. IsSettle: s.IsSettle,
  3057. IsMobile: s.IsMobile,
  3058. IsSelfDrug: s.IsSelfDrug,
  3059. DrugWayCount: s.DrugWayCount,
  3060. }
  3061. var history_count int64
  3062. var local_count int64
  3063. //查找已经开过的医嘱信息
  3064. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3065. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3066. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3067. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3068. local_count += prescribingNumberSevenTy * drug.MinNumber
  3069. }
  3070. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3071. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3072. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3073. local_count += prescribingNumberSevenTy
  3074. }
  3075. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3076. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3077. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3078. local_count += prescribingNumberSevenTy
  3079. }
  3080. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3081. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3082. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3083. history_count += prescribingNumberSevenTy * drug.MinNumber
  3084. }
  3085. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3086. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3087. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3088. history_count += prescribingNumberSevenTy
  3089. }
  3090. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3091. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3092. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3093. history_count += prescribingNumberSevenTy
  3094. }
  3095. //如果当前出库数量大于历史出库数量则需要出库
  3096. if local_count > history_count {
  3097. //按最小单位出库
  3098. var cha_count = local_count - history_count
  3099. newadviceInfo.PrescribingNumber = float64(cha_count)
  3100. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3101. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3102. }
  3103. //如果当前出库数量小于历史出库数量则需要退库
  3104. if local_count < history_count {
  3105. var cha_count = history_count - local_count
  3106. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3108. }
  3109. if local_count == history_count {
  3110. if is_user_total == 0 {
  3111. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3112. }
  3113. }
  3114. }
  3115. //更新字典里面的库存
  3116. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3117. var sum_count int64
  3118. for _, its := range stockInfo {
  3119. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3120. if its.MaxUnit == baseDrug.MaxUnit {
  3121. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3122. }
  3123. sum_count += its.StockMaxNumber + its.StockMinNumber
  3124. }
  3125. //更新基础库存
  3126. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3127. //剩余库存
  3128. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3129. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3130. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3131. //创建医嘱
  3132. service.CreateHisDoctorAdviceOne(&s, tx)
  3133. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3135. if len(outInfoTwo) > 0 {
  3136. for _, item := range outInfoTwo {
  3137. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3138. }
  3139. }
  3140. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3141. if len(drugAutoDetail) > 0 {
  3142. for _, item := range drugAutoDetail {
  3143. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3144. }
  3145. }
  3146. }
  3147. }
  3148. }
  3149. //记录日志
  3150. byterequest, _ := json.Marshal(s)
  3151. adviceLog := models.XtDoctorAdviceLog{
  3152. UserOrgId: s.UserOrgId,
  3153. PatientId: s.PatientId,
  3154. AdminUserId: adminInfo.AdminUser.Id,
  3155. Module: 1,
  3156. ErrLog: string(byterequest),
  3157. Status: 1,
  3158. Ctime: time.Now().Unix(),
  3159. Mtime: 0,
  3160. Source: "电脑端新建his医嘱",
  3161. RecordDate: s.AdviceDate,
  3162. }
  3163. service.CreateDoctorAdviceLog(adviceLog)
  3164. //存储切片中
  3165. adviceList = append(adviceList, s)
  3166. redis := service.RedisClient()
  3167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3168. redis.Set(key, "", time.Second)
  3169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3170. redis.Set(keyOne, "", time.Second)
  3171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3172. redis.Set(keySeven, "", time.Second)
  3173. var randNum int
  3174. randNum = rand.Intn(10000) + 1000
  3175. timestamp := time.Now().Unix()
  3176. tempTime := time.Unix(timestamp, 0)
  3177. timeFormat := tempTime.Format("20060102150405")
  3178. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3179. if s.UserOrgId != 10206 {
  3180. if s.ID == 0 {
  3181. //查询改药品是否已经停用
  3182. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3183. if base.ID > 0 {
  3184. tx.Rollback()
  3185. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3186. return
  3187. }
  3188. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3189. if drugMedical.SumCount == 0 {
  3190. tx.Rollback()
  3191. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3192. return
  3193. }
  3194. }
  3195. }
  3196. //赤峰
  3197. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3198. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3199. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3200. if info.RetailPrice > 0 {
  3201. if s.DeliveryWay == "口服" {
  3202. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3203. s.Price = drug.RetailPrice
  3204. }
  3205. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3206. s.Price = info.RetailPrice
  3207. }
  3208. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3209. s.Price = info.RetailPrice
  3210. }
  3211. }
  3212. }
  3213. }
  3214. service.CreateHisDoctorAdviceOne(&s, tx)
  3215. tx.Commit()
  3216. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3217. redis.Set(keySix, "", time.Second)
  3218. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3219. redis.Set(keyFive, "", time.Second)
  3220. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3221. redis.Set(keyEight, "", time.Second)
  3222. defer redis.Close()
  3223. }
  3224. }
  3225. }
  3226. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3227. projects := items["project"].([]interface{})
  3228. if len(projects) > 0 {
  3229. for _, project := range projects {
  3230. tx := db.Begin()
  3231. // 在函数结束时处理事务回滚
  3232. defer func() {
  3233. if r := recover(); r != nil {
  3234. tx.Rollback()
  3235. }
  3236. }()
  3237. var p models.HisPrescriptionProject
  3238. p.PrescriptionId = tempPrescription.ID
  3239. p.PatientId = patient_id
  3240. p.RecordDate = theTime3.Unix()
  3241. p.Doctor = doctor_id
  3242. p.UserOrgId = adminInfo.CurrentOrgId
  3243. p.HisPatientId = his_patient_id
  3244. p.Status = 1
  3245. p.StartTime = pTime
  3246. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3247. if errcode > 0 {
  3248. tx.Rollback()
  3249. c.ServeFailJSONWithSGJErrorCode(errcode)
  3250. return
  3251. }
  3252. if p.ID == 0 {
  3253. p.IsOut = 2
  3254. }
  3255. if p.ID > 0 {
  3256. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3257. p.IsOut = projectDetail.IsOut
  3258. }
  3259. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3260. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3261. if p.Type == 3 {
  3262. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3263. if p.Price != lastWarehouse.PackingPrice {
  3264. p.Price = lastWarehouse.PackingPrice
  3265. }
  3266. if p.Price == 0 {
  3267. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3268. p.Price = lastWarehouseTwo.PackingPrice
  3269. }
  3270. if p.Unit == "" {
  3271. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3272. p.Unit = goodInfoOne.PackingUnit
  3273. }
  3274. }
  3275. }
  3276. if adminInfo.CurrentOrgId != 10206 {
  3277. if p.Type == 3 {
  3278. if p.ID == 0 {
  3279. //查询该耗材是否停用
  3280. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3281. //表示该耗材已经停用,不能保存
  3282. if goodInfoSeven.ID == 0 {
  3283. tx.Rollback()
  3284. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3285. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3286. return
  3287. }
  3288. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3289. if goodInfoOne.SumCount == 0 {
  3290. tx.Rollback()
  3291. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3292. return
  3293. }
  3294. }
  3295. }
  3296. }
  3297. //查询保存耗材出库开关是否打开
  3298. if p.PatientId != 30038 {
  3299. if goodOutConfig.IsOpen == 1 {
  3300. //耗材出库
  3301. if p.Type == 3 {
  3302. //对比当前数据和历史出库数据
  3303. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3304. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3305. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3306. //fmt.Println("p----------------------------------------------------", p.ProjectId)
  3307. //fmt.Println("p----------------------------------------------------", nowCount)
  3308. //fmt.Println("p----------------------------------------------------", historyCount)
  3309. //如果当前处方数量大于历史数据,则需要出库
  3310. if nowCount > historyCount {
  3311. var cha_count int64
  3312. cha_count = nowCount - historyCount
  3313. timeStr := time.Now().Format("2006-01-02")
  3314. timeArr := strings.Split(timeStr, "-")
  3315. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3316. total = total + 1
  3317. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3318. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3319. number = number + total
  3320. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3321. operation_time := time.Now().Unix()
  3322. creater := c.GetAdminUserInfo().AdminUser.Id
  3323. recordDateStr := time.Now().Format("2006-01-02")
  3324. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3325. nowtime := recordDate.Unix()
  3326. warehouseOut := models.WarehouseOut{
  3327. WarehouseOutOrderNumber: warehousing_out_order,
  3328. OperationTime: operation_time,
  3329. OrgId: adminInfo.CurrentOrgId,
  3330. Creater: creater,
  3331. Ctime: time.Now().Unix(),
  3332. Status: 1,
  3333. WarehouseOutTime: nowtime,
  3334. Type: 1,
  3335. StorehouseId: storeConfig.StorehouseOutInfo,
  3336. IsCheck: 1,
  3337. IsSys: 1,
  3338. }
  3339. //查询是否生成出库单
  3340. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3341. if out.ID == 0 {
  3342. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3343. }
  3344. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3345. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3346. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3347. dialyPrepareOne := models.DialysisBeforePrepare{
  3348. GoodTypeId: goodObj.GoodTypeId,
  3349. GoodId: p.ProjectId,
  3350. PatientId: p.PatientId,
  3351. RecordDate: p.RecordDate,
  3352. UserOrgId: adminInfo.CurrentOrgId,
  3353. Count: cha_count,
  3354. Ctime: time.Now().Unix(),
  3355. Creater: creater,
  3356. Status: 1,
  3357. StorehouseId: houseConfig.StorehouseOutInfo,
  3358. ProjectId: p.ID,
  3359. }
  3360. //出库
  3361. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3362. }
  3363. //如果当前处方数量小于历史数据,怎需要退库
  3364. if nowCount < historyCount {
  3365. var cha_count int64
  3366. cha_count = historyCount - nowCount
  3367. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3368. creater := c.GetAdminUserInfo().AdminUser.Id
  3369. newPrescriptionProject := &models.HisPrescriptionProject{
  3370. ID: p.ID,
  3371. ProjectId: p.ProjectId,
  3372. Price: p.Price,
  3373. UserOrgId: p.UserOrgId,
  3374. Status: 1,
  3375. Ctime: time.Now().Unix(),
  3376. Mtime: time.Now().Unix(),
  3377. PatientId: p.PatientId,
  3378. HisPatientId: p.HisPatientId,
  3379. RecordDate: p.RecordDate,
  3380. PrescriptionId: p.PrescriptionId,
  3381. Count: p.Count,
  3382. FeedetlSn: p.FeedetlSn,
  3383. MedListCodg: p.MedListCodg,
  3384. SingleDose: p.SingleDose,
  3385. DeliveryWay: p.DeliveryWay,
  3386. ExecutionFrequency: p.ExecutionFrequency,
  3387. Day: p.Day,
  3388. HisProject: models.HisProject{},
  3389. GoodInfo: models.GoodInfo{},
  3390. Remark: p.Remark,
  3391. Unit: p.Unit,
  3392. Type: p.Type,
  3393. Doctor: p.Doctor,
  3394. ExecutionTime: p.ExecutionTime,
  3395. ExecutionStaff: p.ExecutionStaff,
  3396. ExecutionState: p.ExecutionState,
  3397. CheckTime: p.CheckTime,
  3398. CheckState: p.CheckState,
  3399. Checker: p.Checker,
  3400. StartTime: p.StartTime,
  3401. TeamId: p.TeamId,
  3402. XtHisProjectTeam: models.XtHisProjectTeam{},
  3403. FrequencyType: p.FrequencyType,
  3404. DayCount: p.DayCount,
  3405. WeekDay: p.WeekDay,
  3406. IsCheckTeam: p.IsCheckTeam,
  3407. HisOrderInfo: models.HisOrderInfo{},
  3408. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3409. IsOut: p.IsOut,
  3410. YbSyncStatus: p.YbSyncStatus,
  3411. }
  3412. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3413. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3414. }
  3415. if nowCount == historyCount {
  3416. if historyCount == 0 {
  3417. recordDateStr := time.Now().Format("2006-01-02")
  3418. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3419. nowtime := recordDate.Unix()
  3420. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3421. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3422. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3423. creater := c.GetAdminUserInfo().AdminUser.Id
  3424. dialyPrepareOne := models.DialysisBeforePrepare{
  3425. GoodTypeId: goodObj.GoodTypeId,
  3426. GoodId: p.ProjectId,
  3427. PatientId: p.PatientId,
  3428. RecordDate: p.RecordDate,
  3429. UserOrgId: adminInfo.CurrentOrgId,
  3430. Count: nowCount,
  3431. Ctime: time.Now().Unix(),
  3432. Creater: creater,
  3433. Status: 1,
  3434. StorehouseId: houseConfig.StorehouseOutInfo,
  3435. ProjectId: p.ID,
  3436. }
  3437. //出库
  3438. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3439. }
  3440. }
  3441. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3442. //查询历史出库数据
  3443. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3444. var out_count_five int64
  3445. for _, item := range flowGood {
  3446. out_count_five += item.Count
  3447. }
  3448. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3449. //fmt.Println("p.ProjectId-----------------", p.ProjectId)
  3450. //fmt.Println("out_count_five===============", out_count_five)
  3451. //fmt.Println("parseIntCount===============", parseIntCount)
  3452. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3453. if out_count_five != parseIntCount {
  3454. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3455. detail := models.AutomaticReduceDetail{
  3456. WarehouseOutId: 0,
  3457. WarehouseOutOrderNumber: "",
  3458. PatientId: p.PatientId,
  3459. Ctime: time.Now().Unix(),
  3460. Mtime: 0,
  3461. Status: 1,
  3462. RecordTime: p.RecordDate,
  3463. OrgId: p.UserOrgId,
  3464. GoodId: p.ProjectId,
  3465. GoodTypeId: 0,
  3466. Count: parseIntCount,
  3467. Type: 0,
  3468. ProjectId: lastHisProject.ID,
  3469. StorehouseId: 0,
  3470. }
  3471. service.CreateNewAutoDetail(detail, tx)
  3472. }
  3473. // //查询耗材最后一次出库记录
  3474. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3475. // //查询默认出库仓库库存
  3476. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3477. // if len(wareOut) > 0 {
  3478. //
  3479. // for _, it := range wareOut {
  3480. // //回退库存
  3481. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3482. //
  3483. // //删除出库记录
  3484. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3485. //
  3486. // }
  3487. // }
  3488. //
  3489. // timeStr := time.Now().Format("2006-01-02")
  3490. // timeArr := strings.Split(timeStr, "-")
  3491. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3492. //
  3493. // total = total + 1
  3494. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3495. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3496. // number = number + total
  3497. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3498. //
  3499. // operation_time := time.Now().Unix()
  3500. // creater := c.GetAdminUserInfo().AdminUser.Id
  3501. //
  3502. // recordDateStr := time.Now().Format("2006-01-02")
  3503. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3504. // nowtime := recordDate.Unix()
  3505. // warehouseOut := models.WarehouseOut{
  3506. // WarehouseOutOrderNumber: warehousing_out_order,
  3507. // OperationTime: operation_time,
  3508. // OrgId: adminInfo.CurrentOrgId,
  3509. // Creater: creater,
  3510. // Ctime: time.Now().Unix(),
  3511. // Status: 1,
  3512. // WarehouseOutTime: nowtime,
  3513. // Type: 1,
  3514. // StorehouseId: storeConfig.StorehouseOutInfo,
  3515. // IsCheck: 1,
  3516. // IsSys: 1,
  3517. // }
  3518. // //查询是否生成出库单
  3519. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3520. // if out.ID == 0 {
  3521. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3522. // }
  3523. //
  3524. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3525. //
  3526. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3527. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3528. //
  3529. // dialyPrepareOne := models.DialysisBeforePrepare{
  3530. // GoodTypeId: goodObj.GoodTypeId,
  3531. // GoodId: p.ProjectId,
  3532. // PatientId: p.PatientId,
  3533. // RecordDate: p.RecordDate,
  3534. // UserOrgId: adminInfo.CurrentOrgId,
  3535. // Count: parseIntCount,
  3536. // Ctime: time.Now().Unix(),
  3537. // Creater: creater,
  3538. // Status: 1,
  3539. // StorehouseId: houseConfig.StorehouseOutInfo,
  3540. // ProjectId: lastHisProject.ID,
  3541. // }
  3542. // //判断是否是零用耗材(非零用)
  3543. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3544. //
  3545. // //查询历史出库数据
  3546. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3547. // var out_count int64
  3548. // for _, item := range flowGood {
  3549. // out_count += item.Count
  3550. // }
  3551. // //如果历史数和当前数据不想等才进行退库出库
  3552. // if out_count != parseIntCount {
  3553. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3554. //
  3555. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3556. // detail := models.AutomaticReduceDetail{
  3557. // WarehouseOutId: 0,
  3558. // WarehouseOutOrderNumber: "",
  3559. // PatientId: p.PatientId,
  3560. // Ctime: time.Now().Unix(),
  3561. // Mtime: 0,
  3562. // Status: 1,
  3563. // RecordTime: p.RecordDate,
  3564. // OrgId: p.UserOrgId,
  3565. // GoodId: p.ProjectId,
  3566. // GoodTypeId: 0,
  3567. // Count: parseIntCount,
  3568. // Type: 0,
  3569. // ProjectId: lastHisProject.ID,
  3570. // StorehouseId: 0,
  3571. // }
  3572. //
  3573. // service.CreateNewAutoDetail(detail, tx)
  3574. //
  3575. // //查询剩余库存
  3576. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3577. // var sum_count int64
  3578. // for _, item := range goodList {
  3579. // sum_count += item.StockCount
  3580. // }
  3581. //
  3582. // //更新剩余库存
  3583. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3584. //
  3585. // //耗材
  3586. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3587. //
  3588. // }
  3589. // //判断是否是零用耗材(零用但是是出库耗材)
  3590. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3591. //
  3592. // //查询历史出库数据
  3593. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3594. // var out_count int64
  3595. // for _, item := range flowGood {
  3596. // out_count += item.Count
  3597. // }
  3598. // //如果历史数和当前数据不想等才进行退库出库
  3599. // if out_count != parseIntCount {
  3600. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3601. //
  3602. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3603. // detail := models.AutomaticReduceDetail{
  3604. // WarehouseOutId: 0,
  3605. // WarehouseOutOrderNumber: "",
  3606. // PatientId: p.PatientId,
  3607. // Ctime: time.Now().Unix(),
  3608. // Mtime: 0,
  3609. // Status: 1,
  3610. // RecordTime: p.RecordDate,
  3611. // OrgId: p.UserOrgId,
  3612. // GoodId: p.ProjectId,
  3613. // GoodTypeId: 0,
  3614. // Count: parseIntCount,
  3615. // Type: 0,
  3616. // ProjectId: p.ID,
  3617. // StorehouseId: 0,
  3618. // }
  3619. //
  3620. // service.CreateNewAutoDetail(detail, tx)
  3621. //
  3622. // //查询剩余库存
  3623. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3624. // var sum_count int64
  3625. // for _, item := range goodList {
  3626. // sum_count += item.StockCount
  3627. // }
  3628. //
  3629. // //更新剩余库存
  3630. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3631. //
  3632. // //耗材
  3633. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3634. // }
  3635. //
  3636. // }
  3637. //
  3638. // }
  3639. //
  3640. //}
  3641. //记录日志
  3642. byterequest, _ := json.Marshal(p)
  3643. adviceLog := models.XtDoctorAdviceLog{
  3644. UserOrgId: p.UserOrgId,
  3645. PatientId: p.PatientId,
  3646. AdminUserId: adminInfo.AdminUser.Id,
  3647. Module: 1,
  3648. ErrLog: string(byterequest),
  3649. Status: 1,
  3650. Ctime: time.Now().Unix(),
  3651. Mtime: 0,
  3652. Source: "电脑端新建his项目",
  3653. RecordDate: p.RecordDate,
  3654. }
  3655. service.CreateDoctorAdviceLog(adviceLog)
  3656. projectList = append(projectList, p)
  3657. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3658. //新增或者编辑项目,修改对应的标签数据
  3659. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3660. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3661. var label models.HisLabelPrintInfo
  3662. project, _ := service.GetProjectDetail(p.ProjectId)
  3663. if project.CostClassify == 3 { //类别为检验检查
  3664. if p.TeamId > 0 { //检验检查组套
  3665. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3666. if tempLabel.ID == 0 {
  3667. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3668. label.Number = tempPrescription.PrescriptionNumber
  3669. label.ProjectId = project.ID
  3670. label.Status = 1
  3671. label.IsPrint = 2
  3672. label.DoctorId = info.DoctorId
  3673. label.UserOrgId = p.UserOrgId
  3674. label.PatientId = patient_id
  3675. label.RecordDate = recordDateTime
  3676. label.Ctime = time.Now().Unix()
  3677. label.Mtime = time.Now().Unix()
  3678. label.ItemId = p.TeamId
  3679. label.FeedetlSn = p.FeedetlSn
  3680. label.PProjectId = p.ID
  3681. label.ProjectName = team.ProjectTeam
  3682. label.PatientName = patient.Name
  3683. service.CreateNewHisLabelRecord(&label, tx)
  3684. }
  3685. } else { //单条检验检查项目
  3686. label.Number = tempPrescription.PrescriptionNumber
  3687. label.ProjectId = project.ID
  3688. label.Status = 1
  3689. label.DoctorId = info.DoctorId
  3690. label.UserOrgId = p.UserOrgId
  3691. label.PatientId = patient_id
  3692. label.RecordDate = recordDateTime
  3693. label.IsPrint = 2
  3694. label.Ctime = time.Now().Unix()
  3695. label.Mtime = time.Now().Unix()
  3696. label.FeedetlSn = p.FeedetlSn
  3697. label.PProjectId = p.ID
  3698. label.ItemId = p.TeamId
  3699. label.ProjectName = project.ProjectName
  3700. label.PatientName = patient.Name
  3701. service.CreateNewHisLabelRecord(&label, tx)
  3702. }
  3703. }
  3704. }
  3705. }
  3706. }
  3707. }
  3708. }
  3709. //插入检验数据
  3710. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3711. //新增或者编辑项目,修改对应的标签数据
  3712. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3713. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3714. var label models.HisLabelPrintInfo
  3715. project, _ := service.GetProjectDetail(p.ProjectId)
  3716. if project.CostClassify == 3 { //类别为检验检查
  3717. if p.TeamId > 0 { //检验检查组套
  3718. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3719. if tempLabel.ID == 0 {
  3720. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3721. label.Number = tempPrescription.PrescriptionNumber
  3722. label.ProjectId = project.ID
  3723. label.Status = 1
  3724. label.IsPrint = 2
  3725. label.DoctorId = info.DoctorId
  3726. label.UserOrgId = p.UserOrgId
  3727. label.PatientId = patient_id
  3728. label.RecordDate = recordDateTime
  3729. label.Ctime = time.Now().Unix()
  3730. label.Mtime = time.Now().Unix()
  3731. label.ItemId = p.TeamId
  3732. label.FeedetlSn = p.FeedetlSn
  3733. label.PProjectId = p.ID
  3734. label.ProjectName = team.ProjectTeam
  3735. label.PatientName = patient.Name
  3736. service.CreateHisLabelRecord(&label)
  3737. }
  3738. } else { //单条检验检查项目
  3739. label.Number = tempPrescription.PrescriptionNumber
  3740. label.ProjectId = project.ID
  3741. label.Status = 1
  3742. label.DoctorId = info.DoctorId
  3743. label.UserOrgId = p.UserOrgId
  3744. label.PatientId = patient_id
  3745. label.RecordDate = recordDateTime
  3746. label.IsPrint = 2
  3747. label.Ctime = time.Now().Unix()
  3748. label.Mtime = time.Now().Unix()
  3749. label.FeedetlSn = p.FeedetlSn
  3750. label.PProjectId = p.ID
  3751. label.ItemId = p.TeamId
  3752. label.ProjectName = project.ProjectName
  3753. label.PatientName = patient.Name
  3754. service.CreateHisLabelRecord(&label)
  3755. }
  3756. }
  3757. }
  3758. }
  3759. service.CreateNewHisProjectTwo(&p, tx)
  3760. var randNum int
  3761. randNum = rand.Intn(10000) + 1000
  3762. timestamp := time.Now().Unix()
  3763. tempTime := time.Unix(timestamp, 0)
  3764. timeFormat := tempTime.Format("20060102150405")
  3765. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3766. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3767. if goodBase.ID > 0 {
  3768. tx.Rollback()
  3769. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3770. return
  3771. }
  3772. service.CreateNewHisProjectTwo(&p, tx)
  3773. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3774. //查询剩余库存
  3775. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3776. var sum_count int64
  3777. for _, item := range goodList {
  3778. sum_count += item.StockCount
  3779. }
  3780. //更新剩余库存
  3781. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3782. //耗材
  3783. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3784. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3785. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3786. if len(outInfoTwo) > 0 {
  3787. for _, item := range outInfoTwo {
  3788. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3789. }
  3790. }
  3791. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3792. if len(drugAutoDetail) > 0 {
  3793. for _, item := range drugAutoDetail {
  3794. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3795. }
  3796. }
  3797. tx.Commit()
  3798. }
  3799. }
  3800. }
  3801. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3802. // addition := items["addition"].([]interface{})
  3803. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3804. // ctime := time.Now().Unix()
  3805. // mtime := ctime
  3806. // if len(addition) > 0 {
  3807. // for _, item := range addition {
  3808. // var s models.HisAdditionalCharge
  3809. // s.PrescriptionId = tempPrescription.ID
  3810. // s.Status = 1
  3811. // s.UserOrgId = adminInfo.CurrentOrgId
  3812. // s.RecordDate = recordDateTime
  3813. // s.CreatedTime = ctime
  3814. // s.UpdatedTime = mtime
  3815. // s.PatientId = patient_id
  3816. // s.HisPatientId = his_patient_id
  3817. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3818. // if errcode > 0 {
  3819. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3820. // return
  3821. // }
  3822. // service.CreateAdditionalCharge(&s)
  3823. // var randNum int
  3824. // randNum = rand.Intn(10000) + 1000
  3825. // timestamp := time.Now().Unix()
  3826. // tempTime := time.Unix(timestamp, 0)
  3827. // timeFormat := tempTime.Format("20060102150405")
  3828. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3829. // service.CreateAdditionalCharge(&s)
  3830. //
  3831. // }
  3832. // }
  3833. //}
  3834. }
  3835. }
  3836. }
  3837. tx.Commit()
  3838. if err == nil {
  3839. c.ServeSuccessJSON(map[string]interface{}{
  3840. "msg": "保存成功",
  3841. })
  3842. return
  3843. } else {
  3844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3845. return
  3846. }
  3847. } else {
  3848. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3849. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3850. var tempPrescription *models.HisPrescription
  3851. if len(prescriptions) > 0 {
  3852. for _, item := range prescriptions {
  3853. items := item.(map[string]interface{})
  3854. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3855. utils.ErrorLog("id")
  3856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3857. return
  3858. }
  3859. id := int64(items["id"].(float64))
  3860. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3861. tempPrescription = &new_prescription
  3862. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3863. utils.ErrorLog("type")
  3864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3865. return
  3866. }
  3867. types := int64(items["type"].(float64))
  3868. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3869. utils.ErrorLog("med_type")
  3870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3871. return
  3872. }
  3873. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3874. if med_type == "0" {
  3875. med_type = "14"
  3876. }
  3877. //if order_status == 0 {
  3878. // order_status = 1
  3879. //}
  3880. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3881. utils.ErrorLog("pre_time")
  3882. }
  3883. preTime, _ := items["pre_time"].(string)
  3884. timeLayout := "2006-01-02"
  3885. loc, _ := time.LoadLocation("Local")
  3886. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3887. //result := strings.Split(preTime, " ")
  3888. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3889. if err != nil {
  3890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3891. return
  3892. }
  3893. pTime := theTime2.Unix()
  3894. ctime := time.Now().Unix()
  3895. if tempPrescription.ID == 0 {
  3896. prescription := &models.HisPrescription{
  3897. ID: 0,
  3898. PatientId: patient_id,
  3899. UserOrgId: adminInfo.CurrentOrgId,
  3900. RecordDate: recordDateTime,
  3901. Ctime: ctime,
  3902. Mtime: ctime,
  3903. Type: types,
  3904. Modifier: adminInfo.AdminUser.Id,
  3905. Creator: adminInfo.AdminUser.Id,
  3906. Status: 1,
  3907. Doctor: role.UserName,
  3908. HisPatientId: his_patient_id,
  3909. OrderStatus: 1,
  3910. BatchNumber: "",
  3911. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3912. PreTime: pTime,
  3913. PType: p_type,
  3914. MedType: med_type,
  3915. }
  3916. tempPrescription = prescription
  3917. service.SaveHisPrescription(tempPrescription)
  3918. redis := service.RedisClient()
  3919. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3920. redis.Set(key, "", time.Second)
  3921. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3922. redis.Set(keyOne, "", time.Second)
  3923. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3924. redis.Set(keySeven, "", time.Second)
  3925. defer redis.Close()
  3926. } else {
  3927. tempPrescription.ID = id
  3928. tempPrescription.Type = types
  3929. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3930. tempPrescription.Mtime = time.Now().Unix()
  3931. tempPrescription.Doctor = role.UserName
  3932. //tempPrescription.OrderStatus = order_status
  3933. tempPrescription.PreTime = pTime
  3934. tempPrescription.MedType = med_type
  3935. service.SaveHisPrescription(tempPrescription)
  3936. redis := service.RedisClient()
  3937. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3938. redis.Set(key, "", time.Second)
  3939. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3940. redis.Set(keyOne, "", time.Second)
  3941. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3942. redis.Set(keySeven, "", time.Second)
  3943. defer redis.Close()
  3944. }
  3945. //service.SaveHisPrescription(prescription)
  3946. //更改患者挂号状态
  3947. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3948. fmt.Println("更改失败", err2)
  3949. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3950. advices := items["advices"].([]interface{})
  3951. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3952. groupNo := int64(0)
  3953. if len(advices) > 0 {
  3954. for _, advice := range advices {
  3955. var s models.HisDoctorAdviceInfo
  3956. s.PrescriptionId = tempPrescription.ID
  3957. s.AdviceType = 2
  3958. s.AdviceDoctor = doctor_id
  3959. s.StopState = 2
  3960. s.ExecutionState = 2
  3961. s.AdviceDate = theTime3.Unix()
  3962. s.Status = 1
  3963. s.UserOrgId = adminInfo.CurrentOrgId
  3964. s.RecordDate = theTime3.Unix()
  3965. s.StartTime = tempPrescription.PreTime
  3966. s.Groupno = groupNo
  3967. s.PatientId = patient_id
  3968. s.HisPatientId = his_patient_id
  3969. s.StartTime = pTime
  3970. s.IsSettle = 2
  3971. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3972. if errcode > 0 {
  3973. c.ServeFailJSONWithSGJErrorCode(errcode)
  3974. return
  3975. }
  3976. s.StartTime = pTime
  3977. var total_count int64 //处方总库存
  3978. //查询改药品信息
  3979. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3980. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3981. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3982. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3983. total_count += prescribingNumberSeven * medical.MinNumber
  3984. }
  3985. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3986. total_count += prescribingNumberSeven
  3987. }
  3988. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3989. total_count += prescribingNumberSeven
  3990. }
  3991. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3992. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3993. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3994. if s.Price != lastWarehouse.RetailPrice {
  3995. s.Price = lastWarehouse.RetailPrice
  3996. }
  3997. if s.Price == 0 {
  3998. if lastWarehouse.ID == 0 {
  3999. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4000. s.Price = lastWarehouseTwo.RetailPrice
  4001. }
  4002. }
  4003. }
  4004. if adminInfo.CurrentOrgId != 10206 {
  4005. if s.ID == 0 {
  4006. //查询改药品是否已经停用
  4007. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4008. if base.ID > 0 {
  4009. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4010. return
  4011. }
  4012. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4013. if drugMedical.SumCount == 0 {
  4014. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4015. return
  4016. }
  4017. }
  4018. }
  4019. //赤峰
  4020. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4021. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4022. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4023. if info.RetailPrice > 0 {
  4024. if s.DeliveryWay == "口服" {
  4025. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4026. s.Price = drug.RetailPrice
  4027. }
  4028. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4029. s.Price = info.RetailPrice
  4030. }
  4031. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4032. s.Price = info.RetailPrice
  4033. }
  4034. }
  4035. }
  4036. }
  4037. service.CreateHisDoctorAdvice(&s)
  4038. //记录日志
  4039. byterequest, _ := json.Marshal(s)
  4040. adviceLog := models.XtDoctorAdviceLog{
  4041. UserOrgId: s.UserOrgId,
  4042. PatientId: s.PatientId,
  4043. AdminUserId: adminInfo.AdminUser.Id,
  4044. Module: 1,
  4045. ErrLog: string(byterequest),
  4046. Status: 1,
  4047. Ctime: time.Now().Unix(),
  4048. Mtime: 0,
  4049. Source: "电脑端新建his医嘱",
  4050. RecordDate: s.AdviceDate,
  4051. }
  4052. service.CreateDoctorAdviceLog(adviceLog)
  4053. //存储切片中
  4054. adviceList = append(adviceList, s)
  4055. redis := service.RedisClient()
  4056. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4057. redis.Set(key, "", time.Second)
  4058. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4059. redis.Set(keyOne, "", time.Second)
  4060. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4061. redis.Set(keySeven, "", time.Second)
  4062. var randNum int
  4063. randNum = rand.Intn(10000) + 1000
  4064. timestamp := time.Now().Unix()
  4065. tempTime := time.Unix(timestamp, 0)
  4066. timeFormat := tempTime.Format("20060102150405")
  4067. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4068. service.CreateHisDoctorAdvice(&s)
  4069. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4070. redis.Set(keySix, "", time.Second)
  4071. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4072. redis.Set(keyFive, "", time.Second)
  4073. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4074. redis.Set(keyEight, "", time.Second)
  4075. defer redis.Close()
  4076. }
  4077. }
  4078. }
  4079. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4080. projects := items["project"].([]interface{})
  4081. if len(projects) > 0 {
  4082. for _, project := range projects {
  4083. var p models.HisPrescriptionProject
  4084. p.PrescriptionId = tempPrescription.ID
  4085. p.PatientId = patient_id
  4086. p.RecordDate = theTime3.Unix()
  4087. p.Doctor = doctor_id
  4088. p.UserOrgId = adminInfo.CurrentOrgId
  4089. p.HisPatientId = his_patient_id
  4090. p.Status = 1
  4091. p.StartTime = pTime
  4092. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4093. if errcode > 0 {
  4094. c.ServeFailJSONWithSGJErrorCode(errcode)
  4095. return
  4096. }
  4097. if p.ID == 0 {
  4098. p.IsOut = 2
  4099. }
  4100. if p.ID > 0 {
  4101. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4102. p.IsOut = projectDetail.IsOut
  4103. }
  4104. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4105. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4106. if p.Type == 3 {
  4107. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4108. if p.Price != lastWarehouse.PackingPrice {
  4109. p.Price = lastWarehouse.PackingPrice
  4110. }
  4111. if p.Price == 0 {
  4112. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4113. p.Price = lastWarehouseTwo.PackingPrice
  4114. }
  4115. if p.Unit == "" {
  4116. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4117. p.Unit = goodInfoOne.PackingUnit
  4118. }
  4119. }
  4120. }
  4121. if adminInfo.CurrentOrgId != 10206 {
  4122. if p.Type == 3 {
  4123. if p.ID == 0 {
  4124. //查询该耗材是否停用
  4125. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4126. //表示该耗材已经停用,不能保存
  4127. if goodInfoSeven.ID == 0 {
  4128. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4129. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4130. return
  4131. }
  4132. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4133. if goodInfoOne.SumCount == 0 {
  4134. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4135. return
  4136. }
  4137. }
  4138. }
  4139. }
  4140. service.CreateHisProjectTwo(&p)
  4141. //记录日志
  4142. byterequest, _ := json.Marshal(p)
  4143. adviceLog := models.XtDoctorAdviceLog{
  4144. UserOrgId: p.UserOrgId,
  4145. PatientId: p.PatientId,
  4146. AdminUserId: adminInfo.AdminUser.Id,
  4147. Module: 1,
  4148. ErrLog: string(byterequest),
  4149. Status: 1,
  4150. Ctime: time.Now().Unix(),
  4151. Mtime: 0,
  4152. Source: "电脑端新建his项目",
  4153. RecordDate: p.RecordDate,
  4154. }
  4155. service.CreateDoctorAdviceLog(adviceLog)
  4156. projectList = append(projectList, p)
  4157. var randNum int
  4158. randNum = rand.Intn(10000) + 1000
  4159. timestamp := time.Now().Unix()
  4160. tempTime := time.Unix(timestamp, 0)
  4161. timeFormat := tempTime.Format("20060102150405")
  4162. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4163. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4164. //新增或者编辑项目,修改对应的标签数据
  4165. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4166. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4167. var label models.HisLabelPrintInfo
  4168. project, _ := service.GetProjectDetail(p.ProjectId)
  4169. if project.CostClassify == 3 { //类别为检验检查
  4170. if p.TeamId > 0 { //检验检查组套
  4171. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4172. if tempLabel.ID == 0 {
  4173. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4174. label.Number = tempPrescription.PrescriptionNumber
  4175. label.ProjectId = project.ID
  4176. label.Status = 1
  4177. label.IsPrint = 2
  4178. label.DoctorId = info.DoctorId
  4179. label.UserOrgId = p.UserOrgId
  4180. label.PatientId = patient_id
  4181. label.RecordDate = recordDateTime
  4182. label.Ctime = time.Now().Unix()
  4183. label.Mtime = time.Now().Unix()
  4184. label.ItemId = p.TeamId
  4185. label.FeedetlSn = p.FeedetlSn
  4186. label.PProjectId = p.ID
  4187. label.ProjectName = team.ProjectTeam
  4188. label.PatientName = patient.Name
  4189. service.CreateHisLabelRecord(&label)
  4190. }
  4191. } else { //单条检验检查项目
  4192. label.Number = tempPrescription.PrescriptionNumber
  4193. label.ProjectId = project.ID
  4194. label.Status = 1
  4195. label.DoctorId = info.DoctorId
  4196. label.UserOrgId = p.UserOrgId
  4197. label.PatientId = patient_id
  4198. label.RecordDate = recordDateTime
  4199. label.IsPrint = 2
  4200. label.Ctime = time.Now().Unix()
  4201. label.Mtime = time.Now().Unix()
  4202. label.FeedetlSn = p.FeedetlSn
  4203. label.PProjectId = p.ID
  4204. label.ItemId = p.TeamId
  4205. label.ProjectName = project.ProjectName
  4206. label.PatientName = patient.Name
  4207. service.CreateHisLabelRecord(&label)
  4208. }
  4209. }
  4210. }
  4211. }
  4212. service.SaveHisProjectTwo(&p)
  4213. }
  4214. }
  4215. }
  4216. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4217. // addition := items["addition"].([]interface{})
  4218. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4219. // ctime := time.Now().Unix()
  4220. // mtime := ctime
  4221. // if len(addition) > 0 {
  4222. // for _, item := range addition {
  4223. // var s models.HisAdditionalCharge
  4224. // s.PrescriptionId = tempPrescription.ID
  4225. // s.Status = 1
  4226. // s.UserOrgId = adminInfo.CurrentOrgId
  4227. // s.RecordDate = recordDateTime
  4228. // s.CreatedTime = ctime
  4229. // s.UpdatedTime = mtime
  4230. // s.PatientId = patient_id
  4231. // s.HisPatientId = his_patient_id
  4232. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4233. // if errcode > 0 {
  4234. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4235. // return
  4236. // }
  4237. // service.CreateAdditionalCharge(&s)
  4238. // var randNum int
  4239. // randNum = rand.Intn(10000) + 1000
  4240. // timestamp := time.Now().Unix()
  4241. // tempTime := time.Unix(timestamp, 0)
  4242. // timeFormat := tempTime.Format("20060102150405")
  4243. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4244. // service.CreateAdditionalCharge(&s)
  4245. //
  4246. // }
  4247. // }
  4248. //}
  4249. }
  4250. }
  4251. //查询今日该患者开的药品处方
  4252. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4253. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4254. //药品出库
  4255. if drugOutConfig.IsOpen == 1 {
  4256. for _, item := range hisdoctorlist {
  4257. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4258. // 查询该药品最后一次出库记录
  4259. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4260. if len(druginfo) > 0 {
  4261. //回退库存
  4262. for _, it := range druginfo {
  4263. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4264. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4265. }
  4266. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4267. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4268. }
  4269. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4270. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4271. }
  4272. }
  4273. }
  4274. //删除记录
  4275. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4276. //查询最后一次数据
  4277. if drugOutConfig.IsOpen == 1 {
  4278. //出库
  4279. if drug.IsUse == 2 {
  4280. creater := adminInfo.AdminUser.Id
  4281. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4282. }
  4283. //更新字典里面的库存
  4284. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4285. var sum_count int64
  4286. for _, its := range stockInfo {
  4287. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4288. if its.MaxUnit == baseDrug.MaxUnit {
  4289. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4290. }
  4291. sum_count += its.StockMaxNumber + its.StockMinNumber
  4292. }
  4293. //更新基础库存
  4294. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4295. //剩余库存
  4296. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4297. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4298. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4299. }
  4300. }
  4301. }
  4302. //耗材保存处方出库
  4303. if goodOutConfig.IsOpen == 1 {
  4304. //查询今日耗材出库数量
  4305. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4306. for _, item := range hisgoodlist {
  4307. //查询历史出库数据
  4308. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4309. var out_count_five int64
  4310. for _, item := range flowGood {
  4311. out_count_five += item.Count
  4312. }
  4313. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4314. if out_count_five != parseIntCount {
  4315. //查询耗材最后一次出库记录
  4316. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4317. //查询默认出库仓库库存
  4318. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4319. if len(wareOut) > 0 {
  4320. for _, it := range wareOut {
  4321. //回退库存
  4322. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4323. //删除出库记录
  4324. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4325. }
  4326. }
  4327. timeStr := time.Now().Format("2006-01-02")
  4328. timeArr := strings.Split(timeStr, "-")
  4329. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4330. total = total + 1
  4331. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4332. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4333. number = number + total
  4334. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4335. operation_time := time.Now().Unix()
  4336. creater := c.GetAdminUserInfo().AdminUser.Id
  4337. recordDateStr := time.Now().Format("2006-01-02")
  4338. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4339. nowtime := recordDate.Unix()
  4340. warehouseOut := models.WarehouseOut{
  4341. WarehouseOutOrderNumber: warehousing_out_order,
  4342. OperationTime: operation_time,
  4343. OrgId: adminInfo.CurrentOrgId,
  4344. Creater: creater,
  4345. Ctime: time.Now().Unix(),
  4346. Status: 1,
  4347. WarehouseOutTime: nowtime,
  4348. Type: 1,
  4349. StorehouseId: storeConfig.StorehouseOutInfo,
  4350. IsCheck: 1,
  4351. IsSys: 1,
  4352. }
  4353. //查询是否生成出库单
  4354. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4355. if out.ID == 0 {
  4356. service.AddSigleWarehouseOut(&warehouseOut)
  4357. }
  4358. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4359. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4360. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4361. dialyPrepareOne := models.DialysisBeforePrepare{
  4362. GoodTypeId: goodObj.GoodTypeId,
  4363. GoodId: item.ProjectId,
  4364. PatientId: item.PatientId,
  4365. RecordDate: item.RecordDate,
  4366. UserOrgId: adminInfo.CurrentOrgId,
  4367. Count: parseIntCount,
  4368. Ctime: time.Now().Unix(),
  4369. Creater: creater,
  4370. Status: 1,
  4371. StorehouseId: houseConfig.StorehouseOutInfo,
  4372. ProjectId: item.ID,
  4373. }
  4374. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4375. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4376. //查询历史出库数据
  4377. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4378. var out_count int64
  4379. for _, item := range flowGood {
  4380. out_count += item.Count
  4381. }
  4382. //如果历史数和当前数据不想等才进行退库出库
  4383. if out_count != parseIntCount {
  4384. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4385. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4386. detail := models.AutomaticReduceDetail{
  4387. WarehouseOutId: 0,
  4388. WarehouseOutOrderNumber: "",
  4389. PatientId: item.PatientId,
  4390. Ctime: time.Now().Unix(),
  4391. Mtime: 0,
  4392. Status: 1,
  4393. RecordTime: item.RecordDate,
  4394. OrgId: item.UserOrgId,
  4395. GoodId: item.ProjectId,
  4396. GoodTypeId: 0,
  4397. Count: parseIntCount,
  4398. Type: 0,
  4399. ProjectId: item.ID,
  4400. StorehouseId: 0,
  4401. }
  4402. service.CreateAutoDetail(detail)
  4403. //查询剩余库存
  4404. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4405. var sum_count int64
  4406. for _, item := range goodList {
  4407. sum_count += item.StockCount
  4408. }
  4409. //更新剩余库存
  4410. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4411. //耗材
  4412. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4413. }
  4414. }
  4415. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4416. //查询历史出库数据
  4417. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4418. var out_count int64
  4419. for _, item := range flowGood {
  4420. out_count += item.Count
  4421. }
  4422. //如果历史数和当前数据不想等才进行退库出库
  4423. if out_count != parseIntCount {
  4424. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4425. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4426. detail := models.AutomaticReduceDetail{
  4427. WarehouseOutId: 0,
  4428. WarehouseOutOrderNumber: "",
  4429. PatientId: item.PatientId,
  4430. Ctime: time.Now().Unix(),
  4431. Mtime: 0,
  4432. Status: 1,
  4433. RecordTime: item.RecordDate,
  4434. OrgId: item.UserOrgId,
  4435. GoodId: item.ProjectId,
  4436. GoodTypeId: 0,
  4437. Count: parseIntCount,
  4438. Type: 0,
  4439. ProjectId: item.ID,
  4440. StorehouseId: 0,
  4441. }
  4442. service.CreateAutoDetail(detail)
  4443. //查询剩余库存
  4444. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4445. var sum_count int64
  4446. for _, item := range goodList {
  4447. sum_count += item.StockCount
  4448. }
  4449. //更新剩余库存
  4450. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4451. //耗材
  4452. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4453. }
  4454. }
  4455. }
  4456. }
  4457. }
  4458. ////同步到自备药
  4459. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4460. if selfPrescriptionOpen.IsOpen == 1 {
  4461. timeStr := time.Now().Format("2006-01-02")
  4462. timeArr := strings.Split(timeStr, "-")
  4463. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4464. total = total + 1
  4465. operation_time := time.Now().Unix()
  4466. creater := adminInfo.AdminUser.Id
  4467. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4468. warehousing := models.XtSelfDrugWarehouse{
  4469. WarehousingOrder: warehousing_order,
  4470. OperationTime: operation_time,
  4471. OrgId: adminInfo.CurrentOrgId,
  4472. Creater: creater,
  4473. Ctime: time.Now().Unix(),
  4474. Status: 1,
  4475. WarehousingTime: recordDateTime,
  4476. Type: 0,
  4477. StorehouseId: 0,
  4478. IsCheck: 1,
  4479. PatientId: patient_id,
  4480. IsSys: 1,
  4481. }
  4482. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4483. if selfDrugWarehouse.ID == 0 {
  4484. service.AddSelfDrugWarehouse(&warehousing, tx)
  4485. }
  4486. if selfDrugWarehouse.ID > 0 {
  4487. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4488. }
  4489. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4490. fmt.Println(info)
  4491. for _, item := range hisdoctorlist {
  4492. //查询该病人的该药品是否已经入库
  4493. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4494. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4495. var in_count int64
  4496. if len(selfdruginfo) > 0 {
  4497. for _, item := range selfdruginfo {
  4498. var in_count_one int64
  4499. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4500. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4501. }
  4502. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4503. in_count_one = item.WarehousingCount
  4504. }
  4505. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4506. in_count_one = item.WarehousingCount
  4507. }
  4508. in_count += in_count_one
  4509. }
  4510. }
  4511. if selfBasedrug.IsSelfDrug == 1 {
  4512. var total_count int64
  4513. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4514. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4515. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4516. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4517. }
  4518. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4519. total_count += prescribingNumberSeven
  4520. }
  4521. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4522. total_count += prescribingNumberSeven
  4523. }
  4524. //入库
  4525. if total_count > in_count {
  4526. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4527. WarehousingOrder: warehousing_order,
  4528. WarehousingId: info.ID,
  4529. DrugId: item.DrugId,
  4530. Number: "",
  4531. ProductDate: 0,
  4532. ExpiryDate: 0,
  4533. WarehousingCount: total_count - in_count,
  4534. WarehouseingUnit: selfBasedrug.MinUnit,
  4535. Price: 0,
  4536. TotalPrice: 0,
  4537. Status: 1,
  4538. Ctime: time.Now().Unix(),
  4539. Remark: "",
  4540. OrgId: adminInfo.CurrentOrgId,
  4541. Type: 0,
  4542. Manufacturer: selfBasedrug.Manufacturer,
  4543. Dealer: selfBasedrug.Dealer,
  4544. StockMaxNumber: total_count - in_count,
  4545. RetailTotalPrice: 0,
  4546. BatchNumber: "",
  4547. MaxUnit: selfBasedrug.MinUnit,
  4548. MinUnit: selfBasedrug.MinUnit,
  4549. RetailPrice: 0,
  4550. StorehouseId: 0,
  4551. IsCheck: 1,
  4552. StockMinNumber: 0,
  4553. PatientId: patient_id,
  4554. IsSys: 1,
  4555. RecordDate: item.RecordDate,
  4556. AdviceId: item.ID,
  4557. }
  4558. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4559. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4560. Creator := adminInfo.AdminUser.Id
  4561. //查询默认仓库剩余多少库存
  4562. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4563. var sum_count int64
  4564. for _, it := range list {
  4565. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4566. if it.MaxUnit == baseDrug.MaxUnit {
  4567. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4568. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4569. }
  4570. sum_count += it.StockMaxNumber + it.StockMinNumber
  4571. }
  4572. flow := &models.XtSelfDrugFlow{
  4573. WarehousingId: info.ID,
  4574. DrugId: item.DrugId,
  4575. Number: "",
  4576. BatchNumber: "",
  4577. Count: total_count - in_count,
  4578. UserOrgId: adminInfo.CurrentOrgId,
  4579. PatientId: item.PatientId,
  4580. SystemTime: time.Now().Unix(),
  4581. ConsumableType: 1,
  4582. IsSys: 1,
  4583. WarehousingOrder: warehousing_order,
  4584. WarehouseOutId: 0,
  4585. WarehouseOutOrderNumber: "",
  4586. IsEdit: 0,
  4587. CancelStockId: 0,
  4588. CancelOrderNumber: "",
  4589. Manufacturer: selfBasedrug.Manufacturer,
  4590. Dealer: selfBasedrug.Dealer,
  4591. Creator: Creator,
  4592. UpdateCreator: Creator,
  4593. Status: 1,
  4594. Ctime: item.AdviceDate,
  4595. Mtime: 0,
  4596. Price: item.Price,
  4597. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4598. WarehouseOutDetailId: 0,
  4599. CancelOutDetailId: 0,
  4600. ExpireDate: 0,
  4601. ProductDate: 0,
  4602. MaxUnit: selfBasedrug.MinUnit,
  4603. MinUnit: selfBasedrug.MinUnit,
  4604. StorehouseId: 0,
  4605. OverCount: sum_count,
  4606. OperateTime: time.Now().Unix(),
  4607. AdviceId: item.ID,
  4608. }
  4609. service.CreateSelfDrugFlow(flow, tx)
  4610. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4611. var total_count int64 // 入库总数量
  4612. var over_count int64 //剩余库存
  4613. for _, it := range drugInfolist {
  4614. if it.MaxUnit == selfBasedrug.MaxUnit {
  4615. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4616. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4617. }
  4618. }
  4619. for _, it := range drugInfolist {
  4620. total_count += it.WarehousingCount
  4621. over_count += it.StockMaxNumber + it.StockMinNumber
  4622. }
  4623. //查询该仓库是否有默认数据
  4624. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4625. if selfDrugStock.ID == 0 {
  4626. drugStock := models.XtSelfDrugStockCount{
  4627. UserOrgId: item.UserOrgId,
  4628. PatientId: item.PatientId,
  4629. SumInCount: total_count,
  4630. SumOutCount: 0,
  4631. SumCancelCount: 0,
  4632. DrugId: item.DrugId,
  4633. Ctime: time.Now().Unix(),
  4634. Mtime: 0,
  4635. Status: 1,
  4636. FlushCount: over_count,
  4637. SumActOutCount: 0,
  4638. }
  4639. service.CreateSelfDrugStockSum(drugStock, tx)
  4640. }
  4641. if selfDrugStock.ID > 0 {
  4642. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4643. }
  4644. }
  4645. //查询这个单据的出库数量
  4646. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4647. var his_out_count int64
  4648. for _, item := range drugFlowList {
  4649. his_out_count += item.Count
  4650. }
  4651. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4652. if (total_count + his_out_count) <= in_count {
  4653. // 出库
  4654. if total_count < in_count {
  4655. var cha_count int64
  4656. cha_count = in_count - total_count
  4657. var stock_number int64 = 0
  4658. //查询库存是否充足
  4659. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4660. // 将该批次的剩余库存数量转换为拆零数量
  4661. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4662. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4663. }
  4664. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4665. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4666. }
  4667. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4668. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4669. }
  4670. if stock_number >= cha_count {
  4671. var maxNumber int64 = 0
  4672. var minNumber int64 = 0
  4673. maxNumber = cha_count / selfBasedrug.MinNumber
  4674. minNumber = cha_count % selfBasedrug.MinNumber
  4675. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4676. minNumber = maxNumber
  4677. }
  4678. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4679. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4681. return
  4682. }
  4683. }
  4684. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4685. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4686. }
  4687. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4688. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4689. }
  4690. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4691. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4692. }
  4693. if warehouse.StockMaxNumber < 0 {
  4694. warehouse.StockMaxNumber = 0
  4695. }
  4696. if warehouse.StockMinNumber < 0 {
  4697. warehouse.StockMinNumber = 0
  4698. }
  4699. warehouse.Mtime = time.Now().Unix()
  4700. if warehouse.StockMinNumber < minNumber {
  4701. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4702. if warehouse.MaxUnit != warehouse.MinUnit {
  4703. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4704. }
  4705. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4706. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4707. }
  4708. } else {
  4709. if minNumber > 0 {
  4710. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4711. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4712. }
  4713. }
  4714. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4715. if warehouse.StockMinNumber > 0 {
  4716. if warehouse.StockMinNumber-cha_count >= 0 {
  4717. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4718. }
  4719. }
  4720. }
  4721. }
  4722. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4723. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4724. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4725. }
  4726. }
  4727. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4728. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4730. return
  4731. }
  4732. }
  4733. if warehouse.StockMinNumber <= 0 {
  4734. warehouse.StockMinNumber = 0
  4735. }
  4736. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4737. //查询该药品剩余库存
  4738. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4739. var over_count int64
  4740. for _, its := range infolist {
  4741. if its.MaxUnit == selfBasedrug.MaxUnit {
  4742. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4743. }
  4744. over_count += its.StockMaxNumber + its.StockMinNumber
  4745. }
  4746. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4747. drugflow := models.XtSelfDrugFlow{
  4748. WarehouseOutId: 0,
  4749. WarehouseOutOrderNumber: warehousing_order,
  4750. WarehousingOrder: warehousing_order,
  4751. DrugId: item.DrugId,
  4752. Number: warehouse.Number,
  4753. ProductDate: warehouse.ProductDate,
  4754. ExpireDate: warehouse.ExpiryDate,
  4755. Count: cha_count,
  4756. Price: warehouse.RetailPrice,
  4757. Status: 1,
  4758. Ctime: item.AdviceDate,
  4759. Mtime: time.Now().Unix(),
  4760. UserOrgId: item.UserOrgId,
  4761. Manufacturer: warehouse.Manufacturer,
  4762. Dealer: warehouse.Dealer,
  4763. BatchNumber: warehouse.BatchNumber,
  4764. MaxUnit: selfBasedrug.MinUnit,
  4765. ConsumableType: 20,
  4766. IsEdit: 1,
  4767. Creator: 0,
  4768. IsSys: 3,
  4769. WarehouseOutDetailId: drugWareInfo.ID,
  4770. AdviceId: item.ID,
  4771. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4772. StorehouseId: 0,
  4773. AdminUserId: creater,
  4774. LastPrice: warehouse.Price,
  4775. StockCount: "",
  4776. WarehousingDetailId: 0,
  4777. OverCount: over_count,
  4778. RetailPrice: item.Price, //手动出库出库价格
  4779. WarehousingId: warehouse.ID,
  4780. SystemTime: item.AdviceDate,
  4781. PatientId: item.PatientId,
  4782. Remark: "保存处方入库数据差",
  4783. OperateTime: time.Now().Unix(),
  4784. }
  4785. if warehouse.RetailPrice == 0 {
  4786. drugflow.Price = item.Price
  4787. }
  4788. service.CreateSelfDrugFlowOne(drugflow, tx)
  4789. var out_count int64
  4790. out_count = in_count - total_count
  4791. //
  4792. //fmt.Println("in_count------------------", in_count)
  4793. //fmt.Println("total_count------------------", total_count)
  4794. //添加出库数量
  4795. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4796. //查询剩余库存
  4797. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4798. var sum_count int64
  4799. for _, its := range stockInfo {
  4800. if its.MaxUnit == selfBasedrug.MaxUnit {
  4801. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4802. }
  4803. sum_count += its.StockMaxNumber + its.StockMinNumber
  4804. }
  4805. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4806. } else {
  4807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4808. return
  4809. }
  4810. }
  4811. }
  4812. }
  4813. }
  4814. }
  4815. }
  4816. tx.Commit()
  4817. if err == nil {
  4818. c.ServeSuccessJSON(map[string]interface{}{
  4819. "msg": "保存成功",
  4820. })
  4821. return
  4822. } else {
  4823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4824. return
  4825. }
  4826. }
  4827. }
  4828. //func (c *HisApiController) EditHisPrescription() {
  4829. // record_date := c.GetString("record_date")
  4830. // patient_id, _ := c.GetInt64("patient_id")
  4831. // reg_type, _ := c.GetInt64("reg_type")
  4832. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4833. // diagnose := c.GetString("diagnose")
  4834. // sick_type, _ := c.GetInt64("sick_type")
  4835. // sick_history := c.GetString("sick_history")
  4836. // doctor_id, _ := c.GetInt64("doctor", 0)
  4837. // department, _ := c.GetInt64("department", 0)
  4838. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4839. // p_type, _ := c.GetInt64("p_type")
  4840. //
  4841. // dataBody := make(map[string]interface{}, 0)
  4842. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4843. // if err != nil {
  4844. // utils.ErrorLog(err.Error())
  4845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4846. // return
  4847. // }
  4848. //
  4849. // timeLayout := "2006-01-02"
  4850. // loc, _ := time.LoadLocation("Local")
  4851. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4852. // if err != nil {
  4853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4854. // return
  4855. // }
  4856. // adminInfo := c.GetAdminUserInfo()
  4857. // recordDateTime := theTime.Unix()
  4858. //
  4859. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4860. //
  4861. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4862. // var hpInfo models.HisPrescriptionInfo
  4863. // if info.ID == 0 {
  4864. // var randNum int
  4865. // randNum = rand.Intn(10000) + 1000
  4866. // timestamp := time.Now().Unix()
  4867. // tempTime := time.Unix(timestamp, 0)
  4868. // timeFormat := tempTime.Format("20060102150405")
  4869. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4870. //
  4871. // hpInfo = models.HisPrescriptionInfo{
  4872. // UserOrgId: adminInfo.CurrentOrgId,
  4873. // RecordDate: theTime.Unix(),
  4874. // PatientId: patient_id,
  4875. // Status: 1,
  4876. // Ctime: time.Now().Unix(),
  4877. // Mtime: time.Now().Unix(),
  4878. // Creator: adminInfo.AdminUser.Id,
  4879. // Modifier: adminInfo.AdminUser.Id,
  4880. // Diagnosis: diagnose,
  4881. // SickHistory: sick_history,
  4882. // Departments: department,
  4883. // RegisterType: reg_type,
  4884. // PrescriptionNumber: p_number,
  4885. // PrescriptionStatus: 1,
  4886. // Doctor: role.UserName,
  4887. // DoctorId: doctor_id,
  4888. // SickType: sick_type,
  4889. // PType: p_type,
  4890. // }
  4891. // service.SavePatientPrescriptionInfo(hpInfo)
  4892. //
  4893. // } else {
  4894. // hpInfo = models.HisPrescriptionInfo{
  4895. // ID: info.ID,
  4896. // UserOrgId: adminInfo.CurrentOrgId,
  4897. // RecordDate: info.RecordDate,
  4898. // PatientId: info.PatientId,
  4899. // Status: 1,
  4900. // Ctime: info.Ctime,
  4901. // Mtime: time.Now().Unix(),
  4902. // Creator: info.Creator,
  4903. // Modifier: adminInfo.AdminUser.Id,
  4904. // Diagnosis: diagnose,
  4905. // SickHistory: sick_history,
  4906. // Departments: department,
  4907. // RegisterType: reg_type,
  4908. // PrescriptionNumber: info.PrescriptionNumber,
  4909. // Doctor: role.UserName,
  4910. // PrescriptionStatus: info.PrescriptionStatus,
  4911. // DoctorId: doctor_id,
  4912. // SickType: sick_type,
  4913. // PType: info.PType,
  4914. // }
  4915. // service.SavePatientPrescriptionInfo(hpInfo)
  4916. // }
  4917. //
  4918. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4919. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4920. //
  4921. // if len(prescriptions) > 0 {
  4922. // for _, item := range prescriptions {
  4923. // items := item.(map[string]interface{})
  4924. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4925. // utils.ErrorLog("id")
  4926. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4927. // return
  4928. // }
  4929. // id := int64(items["id"].(float64))
  4930. //
  4931. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4932. // utils.ErrorLog("type")
  4933. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4934. // return
  4935. // }
  4936. // types := int64(items["type"].(float64))
  4937. //
  4938. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4939. // utils.ErrorLog("med_type")
  4940. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4941. // return
  4942. // }
  4943. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4944. //
  4945. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4946. //
  4947. // ctime := time.Now().Unix()
  4948. //
  4949. // prescription := &models.HisPrescription{
  4950. // ID: id,
  4951. // PatientId: patient_id,
  4952. // UserOrgId: adminInfo.CurrentOrgId,
  4953. // RecordDate: recordDateTime,
  4954. // Ctime: ctime,
  4955. // Mtime: ctime,
  4956. // Type: types,
  4957. // Modifier: adminInfo.AdminUser.Id,
  4958. // Creator: adminInfo.AdminUser.Id,
  4959. // Status: 1,
  4960. // Doctor: role.UserName,
  4961. // HisPatientId: his_patient_id,
  4962. // OrderStatus: 1,
  4963. // BatchNumber: "",
  4964. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4965. // PType: hpInfo.PType,
  4966. // MedType: med_type,
  4967. // }
  4968. //
  4969. // if historyPrescription.ID > 0 {
  4970. // prescription.PreTime = historyPrescription.PreTime
  4971. //
  4972. // }
  4973. //
  4974. // service.SaveHisPrescription(prescription)
  4975. //
  4976. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4977. // advices := items["advices"].([]interface{})
  4978. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4979. // groupNo := int64(0)
  4980. // ctime := time.Now().Unix()
  4981. // mtime := ctime
  4982. // if len(advices) > 0 {
  4983. // for _, advice := range advices {
  4984. // var s models.HisDoctorAdviceInfo
  4985. // s.PrescriptionId = prescription.ID
  4986. // s.AdviceType = 2
  4987. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4988. // s.StopState = 2
  4989. // s.ExecutionState = 2
  4990. // s.AdviceDate = recordDateTime
  4991. // s.Status = 1
  4992. // s.UserOrgId = adminInfo.CurrentOrgId
  4993. // s.RecordDate = recordDateTime
  4994. // s.StartTime = prescription.PreTime
  4995. // s.Groupno = groupNo
  4996. // s.CreatedTime = ctime
  4997. // s.UpdatedTime = mtime
  4998. // s.PatientId = patient_id
  4999. // s.HisPatientId = his_patient_id
  5000. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5001. // if errcode > 0 {
  5002. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5003. // return
  5004. // }
  5005. //
  5006. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5007. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5008. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5009. // if s.Price == 0 {
  5010. // s.Price = lastWarehouse.RetailPrice
  5011. // }
  5012. // }
  5013. //
  5014. // service.CreateHisDoctorAdvice(&s)
  5015. // //记录日志
  5016. // byterequest, _ := json.Marshal(s)
  5017. // adviceLog := models.XtDoctorAdviceLog{
  5018. // UserOrgId: s.UserOrgId,
  5019. // PatientId: s.PatientId,
  5020. // AdminUserId: adminInfo.AdminUser.Id,
  5021. // Module: 1,
  5022. // ErrLog: string(byterequest),
  5023. // Status: 1,
  5024. // Ctime: time.Now().Unix(),
  5025. // Mtime: 0,
  5026. // Source: "电脑端his医嘱修改",
  5027. // RecordDate: s.AdviceDate,
  5028. // }
  5029. // service.CreateDoctorAdviceLog(adviceLog)
  5030. // redis := service.RedisClient()
  5031. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5032. // redis.Set(key, "", time.Second)
  5033. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5034. // fmt.Println("keyOne", keyOne)
  5035. // redis.Set(keyOne, "", time.Second)
  5036. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5037. // redis.Set(keySeven, "", time.Second)
  5038. // redis.Close()
  5039. //
  5040. // }
  5041. // }
  5042. // }
  5043. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5044. // projects := items["project"].([]interface{})
  5045. // if len(projects) > 0 {
  5046. // for _, project := range projects {
  5047. // var p models.HisPrescriptionProject
  5048. // p.PrescriptionId = prescription.ID
  5049. // p.Ctime = time.Now().Unix()
  5050. // p.Mtime = time.Now().Unix()
  5051. // p.PatientId = patient_id
  5052. // p.RecordDate = recordDateTime
  5053. // p.UserOrgId = adminInfo.CurrentOrgId
  5054. // p.HisPatientId = his_patient_id
  5055. // p.Status = 1
  5056. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5057. // if errcode > 0 {
  5058. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5059. // return
  5060. // }
  5061. // service.CreateHisProjectTwo(&p)
  5062. //
  5063. // //记录日志
  5064. // byterequest, _ := json.Marshal(p)
  5065. // adviceLog := models.XtDoctorAdviceLog{
  5066. // UserOrgId: p.UserOrgId,
  5067. // PatientId: p.PatientId,
  5068. // AdminUserId: adminInfo.AdminUser.Id,
  5069. // Module: 1,
  5070. // ErrLog: string(byterequest),
  5071. // Status: 1,
  5072. // Ctime: time.Now().Unix(),
  5073. // Mtime: 0,
  5074. // Source: "电脑端his项目修改",
  5075. // RecordDate: p.RecordDate,
  5076. // }
  5077. // service.CreateDoctorAdviceLog(adviceLog)
  5078. // }
  5079. // }
  5080. // }
  5081. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5082. // addition := items["addition"].([]interface{})
  5083. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5084. // ctime := time.Now().Unix()
  5085. // mtime := ctime
  5086. // if len(addition) > 0 {
  5087. // for _, item := range addition {
  5088. // var s models.HisAdditionalCharge
  5089. // s.PrescriptionId = prescription.ID
  5090. // s.Status = 1
  5091. // s.UserOrgId = adminInfo.CurrentOrgId
  5092. // s.RecordDate = recordDateTime
  5093. // s.CreatedTime = ctime
  5094. // s.UpdatedTime = mtime
  5095. // s.PatientId = patient_id
  5096. // s.HisPatientId = his_patient_id
  5097. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5098. // if errcode > 0 {
  5099. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5100. // return
  5101. // }
  5102. // service.CreateAdditionalCharge(&s)
  5103. // }
  5104. // }
  5105. // }
  5106. //
  5107. // }
  5108. // }
  5109. // }
  5110. // if err == nil {
  5111. // c.ServeSuccessJSON(map[string]interface{}{
  5112. // "msg": "保存成功",
  5113. // })
  5114. // return
  5115. //
  5116. // } else {
  5117. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5118. // return
  5119. // }
  5120. //}
  5121. func (c *HisApiController) DeletePrescription() {
  5122. prescription_id, _ := c.GetInt64("id")
  5123. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5124. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5125. ////同步到自备药
  5126. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5127. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5128. if selfPrescriptionOpen.IsOpen == 1 {
  5129. // 在函数结束时处理事务回滚
  5130. db := service.XTWriteDB()
  5131. tx := db.Begin()
  5132. defer func() {
  5133. if r := recover(); r != nil {
  5134. tx.Rollback()
  5135. } else {
  5136. tx.Commit()
  5137. }
  5138. }()
  5139. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5140. for _, item := range advicesList {
  5141. timeStr := time.Now().Format("2006-01-02")
  5142. timeArr := strings.Split(timeStr, "-")
  5143. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5144. total = total + 1
  5145. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5146. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5147. number = number + total
  5148. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5149. operation_time := time.Now().Unix()
  5150. creater := c.GetAdminUserInfo().AdminUser.Id
  5151. //创建一个出库单
  5152. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5153. WarehouseOutOrderNumber: warehousing_out_order,
  5154. OperationTime: operation_time,
  5155. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5156. Creater: creater,
  5157. Ctime: time.Now().Unix(),
  5158. Status: 1,
  5159. WarehouseOutTime: item.AdviceDate,
  5160. Type: 0,
  5161. PatientId: item.PatientId,
  5162. IsCheck: 1,
  5163. }
  5164. //查询今日是否有出库数据
  5165. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5166. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5167. if lastWarehouseOut.ID == 0 {
  5168. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5169. }
  5170. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5171. var total_count int64
  5172. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5173. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5174. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5175. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5176. }
  5177. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5178. total_count += prescribingNumberSeven
  5179. }
  5180. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5181. total_count += prescribingNumberSeven
  5182. }
  5183. //出库
  5184. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5185. WarehouseOutOrderNumber: warehousing_out_order,
  5186. WarehouseOutId: lastWarehouseOut.ID,
  5187. DrugId: item.DrugId,
  5188. Count: total_count,
  5189. Price: 0,
  5190. TotalPrice: 0,
  5191. Status: 1,
  5192. Ctime: item.AdviceDate,
  5193. Mtime: item.AdviceDate,
  5194. Remark: "",
  5195. OrgId: item.UserOrgId,
  5196. Type: 0,
  5197. Manufacturer: selfBasedrug.Manufacturer,
  5198. Dealer: selfBasedrug.Dealer,
  5199. RetailPrice: 0,
  5200. RetailTotalPrice: 0,
  5201. CountUnit: selfBasedrug.MinUnit,
  5202. ExpiryDate: 0,
  5203. ProductDate: 0,
  5204. Number: "",
  5205. BatchNumber: "",
  5206. IsSys: 1,
  5207. WarehouseInfoId: 0,
  5208. AdminUserId: 0,
  5209. StockCount: "",
  5210. IsCheck: 1,
  5211. SysRecordTime: item.AdviceDate,
  5212. PatientId: item.PatientId,
  5213. ClassType: "",
  5214. AdviceId: item.ID,
  5215. }
  5216. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5217. }
  5218. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5219. for _, it := range warehousingOutInfo {
  5220. //查询今日是否有出库数据
  5221. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5222. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5223. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5224. //出库逻辑
  5225. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5226. //查询剩余库存
  5227. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5228. var sum_count int64
  5229. for _, its := range stockInfo {
  5230. if its.MaxUnit == medical.MaxUnit {
  5231. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5232. }
  5233. sum_count += its.StockMaxNumber + its.StockMinNumber
  5234. }
  5235. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5236. }
  5237. }
  5238. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5239. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5240. //耗材保存处方出库
  5241. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5242. //已收费和已发药限制逻辑
  5243. isCharge := false
  5244. isMedicine := false
  5245. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5246. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5247. if new_prescription.IsMedicine == 1 {
  5248. isMedicine = true
  5249. }
  5250. for _, item := range new_prescriptions {
  5251. if item.OrderStatus == 4 {
  5252. isCharge = true
  5253. }
  5254. }
  5255. if p_err != nil {
  5256. if new_prescription.ID > 0 {
  5257. if new_prescription.OrderStatus == 2 {
  5258. isCharge = true
  5259. }
  5260. }
  5261. }
  5262. for _, item := range advices {
  5263. if item.IsMedicine == 1 {
  5264. isMedicine = true
  5265. }
  5266. }
  5267. if isCharge {
  5268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5269. return
  5270. }
  5271. if isMedicine {
  5272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5273. return
  5274. }
  5275. //已收费和已发药限制逻辑
  5276. if len(projects) > 0 {
  5277. for _, item := range projects {
  5278. service.DeletePrintInfo(item.ID) //删除打印信息
  5279. if goodOutConfig.IsOpen != 1 {
  5280. if stockConfig.IsOpen == 1 {
  5281. if item.Type == 3 && item.IsOut == 1 {
  5282. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5283. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5284. good.Total = good.Total + f_count
  5285. service.UpdateGoodInfo(&good)
  5286. operation_time := time.Now().Unix()
  5287. creater := c.GetAdminUserInfo().AdminUser.Id
  5288. //创建退库单
  5289. timeStr := time.Now().Format("2006-01-02")
  5290. timeArr := strings.Split(timeStr, "-")
  5291. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5292. total = total + 1
  5293. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5294. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5295. cancelStock := models.CancelStock{
  5296. OrderNumber: orderNumber,
  5297. OperaTime: operation_time,
  5298. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5299. Creater: creater,
  5300. Ctime: time.Now().Unix(),
  5301. Status: 1,
  5302. ReturnTime: item.RecordDate,
  5303. Type: 1,
  5304. StorehouseId: houseConfig.StorehouseOutInfo,
  5305. IsCheck: 1,
  5306. }
  5307. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5308. if msgerrkonde == gorm.ErrRecordNotFound {
  5309. service.AddSigleCancelStock(&cancelStock)
  5310. }
  5311. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5312. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5313. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5314. //查询该耗材是否出库
  5315. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5316. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5317. deaerler, _ := service.GetDealerById(info.Dealer)
  5318. var total_count int64
  5319. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5320. total_count += count
  5321. if info.ID > 0 {
  5322. if info.Count >= total_count {
  5323. //回退库存
  5324. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5325. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5326. var flush_count int64
  5327. for _, it := range goodList {
  5328. flush_count += it.StockCount
  5329. }
  5330. cancelStockInfo := models.CancelStockInfo{
  5331. GoodId: item.ProjectId,
  5332. CancelStockId: cancel.ID,
  5333. GoodTypeId: good.GoodTypeId,
  5334. Count: prescribingNumber,
  5335. Price: info.Price,
  5336. Total: 0,
  5337. ProductDate: info.ProductDate,
  5338. ExpiryDate: info.ExpiryDate,
  5339. Ctime: time.Now().Unix(),
  5340. Status: 1,
  5341. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5342. OrderNumber: cancel.OrderNumber,
  5343. Type: 0,
  5344. Dealer: deaerler.DealerName,
  5345. Manufacturer: manufacturer.ManufacturerName,
  5346. Number: info.Number,
  5347. RegisterAccount: "",
  5348. Remark: "",
  5349. WarehouseInfoId: info.WarehouseInfotId,
  5350. PatientId: info.PatientId,
  5351. RecordDate: info.SysRecordTime,
  5352. StorehouseId: houseConfig.StorehouseOutInfo,
  5353. IsCheck: 1,
  5354. }
  5355. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5356. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5357. flow := models.VmStockFlow{
  5358. WarehousingId: info.WarehouseInfotId,
  5359. GoodId: item.ProjectId,
  5360. Number: info.Number,
  5361. LicenseNumber: info.LicenseNumber,
  5362. Count: prescribingNumber,
  5363. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5364. PatientId: item.PatientId,
  5365. SystemTime: info.SysRecordTime,
  5366. ConsumableType: 7,
  5367. IsSys: 0,
  5368. WarehousingOrder: "",
  5369. WarehouseOutId: info.WarehouseOutId,
  5370. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5371. IsEdit: 0,
  5372. CancelStockId: cancel.ID,
  5373. CancelOrderNumber: cancel.OrderNumber,
  5374. Manufacturer: manufacturer.ID,
  5375. Dealer: 0,
  5376. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5377. UpdateCreator: 0,
  5378. Status: 1,
  5379. Ctime: time.Now().Unix(),
  5380. Mtime: 0,
  5381. Price: info.Price,
  5382. WarehousingDetailId: info.WarehouseInfotId,
  5383. WarehouseOutDetailId: info.ID,
  5384. CancelOutDetailId: cancelInfo.ID,
  5385. ProductDate: info.ProductDate,
  5386. ExpireDate: info.ExpiryDate,
  5387. StorehouseId: houseConfig.StorehouseOutInfo,
  5388. OverCount: flush_count,
  5389. OperateTime: time.Now().Unix(),
  5390. }
  5391. service.CreateStockFlowOne(flow)
  5392. //退库数量增加
  5393. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5394. //出库数量减少
  5395. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5396. }
  5397. if info.Count < total_count {
  5398. //回退库存
  5399. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5400. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5401. var flush_count int64
  5402. for _, it := range goodList {
  5403. flush_count += it.StockCount
  5404. }
  5405. cancelStockInfo := models.CancelStockInfo{
  5406. GoodId: item.ProjectId,
  5407. CancelStockId: cancel.ID,
  5408. GoodTypeId: good.GoodTypeId,
  5409. Count: info.Count,
  5410. Price: info.Price,
  5411. Total: 0,
  5412. ProductDate: info.ProductDate,
  5413. ExpiryDate: info.ExpiryDate,
  5414. Ctime: time.Now().Unix(),
  5415. Status: 1,
  5416. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5417. OrderNumber: cancel.OrderNumber,
  5418. Type: 0,
  5419. Dealer: deaerler.DealerName,
  5420. Manufacturer: manufacturer.ManufacturerName,
  5421. Number: info.Number,
  5422. RegisterAccount: "",
  5423. Remark: "",
  5424. WarehouseInfoId: info.WarehouseInfotId,
  5425. PatientId: info.PatientId,
  5426. RecordDate: info.SysRecordTime,
  5427. StorehouseId: houseConfig.StorehouseOutInfo,
  5428. IsCheck: 1,
  5429. }
  5430. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5431. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5432. flow := models.VmStockFlow{
  5433. WarehousingId: info.WarehouseInfotId,
  5434. GoodId: item.ProjectId,
  5435. Number: info.Number,
  5436. LicenseNumber: info.LicenseNumber,
  5437. Count: info.Count,
  5438. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5439. PatientId: item.PatientId,
  5440. SystemTime: info.SysRecordTime,
  5441. ConsumableType: 7,
  5442. IsSys: 0,
  5443. WarehousingOrder: "",
  5444. WarehouseOutId: info.WarehouseOutId,
  5445. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5446. IsEdit: 0,
  5447. CancelStockId: cancel.ID,
  5448. CancelOrderNumber: cancel.OrderNumber,
  5449. Manufacturer: manufacturer.ID,
  5450. Dealer: 0,
  5451. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5452. UpdateCreator: 0,
  5453. Status: 1,
  5454. Ctime: time.Now().Unix(),
  5455. Mtime: 0,
  5456. Price: info.Price,
  5457. WarehousingDetailId: info.WarehouseInfotId,
  5458. WarehouseOutDetailId: info.ID,
  5459. CancelOutDetailId: cancelInfo.ID,
  5460. ProductDate: info.ProductDate,
  5461. ExpireDate: info.ExpiryDate,
  5462. StorehouseId: houseConfig.StorehouseOutInfo,
  5463. OverCount: flush_count,
  5464. OperateTime: time.Now().Unix(),
  5465. }
  5466. service.CreateStockFlowOne(flow)
  5467. //退库数量增加
  5468. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5469. //出库数量减少
  5470. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5471. }
  5472. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5473. var flush_count int64
  5474. for _, it := range goodList {
  5475. flush_count += it.StockCount
  5476. }
  5477. //查询已出库数量
  5478. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5479. if prescribingNumber < dialysisInfo.Count {
  5480. //改变数量
  5481. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5482. }
  5483. if prescribingNumber >= dialysisInfo.Count {
  5484. //删除出库表
  5485. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5486. }
  5487. //更新库存
  5488. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5489. //更新基础库库存
  5490. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5491. }
  5492. }
  5493. }
  5494. }
  5495. //保存耗材出库
  5496. if goodOutConfig.IsOpen == 1 {
  5497. if item.Type == 3 {
  5498. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5499. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5500. good.Total = good.Total + f_count
  5501. service.UpdateGoodInfo(&good)
  5502. operation_time := time.Now().Unix()
  5503. creater := c.GetAdminUserInfo().AdminUser.Id
  5504. //创建退库单
  5505. timeStr := time.Now().Format("2006-01-02")
  5506. timeArr := strings.Split(timeStr, "-")
  5507. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5508. total = total + 1
  5509. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5510. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5511. cancelStock := models.CancelStock{
  5512. OrderNumber: orderNumber,
  5513. OperaTime: operation_time,
  5514. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5515. Creater: creater,
  5516. Ctime: time.Now().Unix(),
  5517. Status: 1,
  5518. ReturnTime: item.RecordDate,
  5519. Type: 1,
  5520. StorehouseId: houseConfig.StorehouseOutInfo,
  5521. IsCheck: 1,
  5522. }
  5523. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5524. if msgerrkonde == gorm.ErrRecordNotFound {
  5525. service.AddSigleCancelStock(&cancelStock)
  5526. }
  5527. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5528. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5529. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5530. //查询该耗材是否出库
  5531. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5532. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5533. deaerler, _ := service.GetDealerById(info.Dealer)
  5534. var total_count int64
  5535. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5536. total_count += count
  5537. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5538. var flush_count int64
  5539. for _, it := range goodList {
  5540. flush_count += it.StockCount
  5541. }
  5542. fmt.Println("历史出库数据", info.Count)
  5543. fmt.Println("出库数量", total_count)
  5544. if info.ID > 0 {
  5545. cancelStockInfo := models.CancelStockInfo{
  5546. GoodId: item.ProjectId,
  5547. CancelStockId: cancel.ID,
  5548. GoodTypeId: good.GoodTypeId,
  5549. Count: prescribingNumber,
  5550. Price: info.Price,
  5551. Total: 0,
  5552. ProductDate: info.ProductDate,
  5553. ExpiryDate: info.ExpiryDate,
  5554. Ctime: time.Now().Unix(),
  5555. Status: 1,
  5556. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5557. OrderNumber: cancel.OrderNumber,
  5558. Type: 0,
  5559. Dealer: deaerler.DealerName,
  5560. Manufacturer: manufacturer.ManufacturerName,
  5561. Number: info.Number,
  5562. RegisterAccount: "",
  5563. Remark: "",
  5564. WarehouseInfoId: info.WarehouseInfotId,
  5565. PatientId: info.PatientId,
  5566. RecordDate: info.SysRecordTime,
  5567. StorehouseId: houseConfig.StorehouseOutInfo,
  5568. IsCheck: 1,
  5569. }
  5570. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5571. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5572. //查询出库数量
  5573. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5574. //出库数据 大于 退库数量
  5575. if len(list) > 0 {
  5576. for _, it := range list {
  5577. //回退库存
  5578. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5579. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5580. var flush_count_one int64
  5581. for _, it := range goodList {
  5582. flush_count_one += it.StockCount
  5583. }
  5584. //查询该批次是否有退库数据
  5585. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5586. creater := c.GetAdminUserInfo().AdminUser.Id
  5587. flow := models.VmStockFlow{
  5588. WarehousingId: it.WarehouseInfotId,
  5589. GoodId: it.GoodId,
  5590. Number: it.Number,
  5591. LicenseNumber: it.LicenseNumber,
  5592. Count: it.Count,
  5593. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5594. PatientId: it.PatientId,
  5595. SystemTime: it.SysRecordTime,
  5596. ConsumableType: 7,
  5597. IsSys: 0,
  5598. WarehousingOrder: "",
  5599. WarehouseOutId: it.WarehouseOutId,
  5600. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5601. IsEdit: 0,
  5602. CancelStockId: cancel.ID,
  5603. CancelOrderNumber: cancel.OrderNumber,
  5604. Manufacturer: manufacturer.ID,
  5605. Dealer: 0,
  5606. Creator: creater,
  5607. UpdateCreator: 0,
  5608. Status: 1,
  5609. Ctime: time.Now().Unix(),
  5610. Mtime: 0,
  5611. Price: it.Price,
  5612. WarehousingDetailId: it.WarehouseInfotId,
  5613. WarehouseOutDetailId: it.ID,
  5614. CancelOutDetailId: cancelInfo.ID,
  5615. ProductDate: it.ProductDate,
  5616. ExpireDate: it.ExpiryDate,
  5617. StorehouseId: houseConfig.StorehouseOutInfo,
  5618. OverCount: flush_count_one,
  5619. }
  5620. service.CreateStockFlowOne(flow)
  5621. //if flow.ID > 0 {
  5622. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5623. //}
  5624. }
  5625. }
  5626. //flow := models.VmStockFlow{
  5627. // WarehousingId: info.WarehouseInfotId,
  5628. // GoodId: item.ProjectId,
  5629. // Number: info.Number,
  5630. // LicenseNumber: info.LicenseNumber,
  5631. // Count: prescribingNumber,
  5632. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5633. // PatientId: item.PatientId,
  5634. // SystemTime: info.SysRecordTime,
  5635. // ConsumableType: 7,
  5636. // IsSys: 0,
  5637. // WarehousingOrder: "",
  5638. // WarehouseOutId: info.WarehouseOutId,
  5639. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5640. // IsEdit: 0,
  5641. // CancelStockId: cancel.ID,
  5642. // CancelOrderNumber: cancel.OrderNumber,
  5643. // Manufacturer: manufacturer.ID,
  5644. // Dealer: 0,
  5645. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5646. // UpdateCreator: 0,
  5647. // Status: 1,
  5648. // Ctime: time.Now().Unix(),
  5649. // Mtime: 0,
  5650. // Price: info.Price,
  5651. // WarehousingDetailId: info.WarehouseInfotId,
  5652. // WarehouseOutDetailId: info.ID,
  5653. // CancelOutDetailId: cancelInfo.ID,
  5654. // ProductDate: info.ProductDate,
  5655. // ExpireDate: info.ExpiryDate,
  5656. // StorehouseId: houseConfig.StorehouseOutInfo,
  5657. // OverCount: flush_count,
  5658. //}
  5659. //service.CreateStockFlowOne(flow)
  5660. //退库数量增加
  5661. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5662. //出库数量减少
  5663. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5664. //查询已出库数量
  5665. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5666. if prescribingNumber < dialysisInfo.Count {
  5667. //改变数量
  5668. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5669. }
  5670. if prescribingNumber >= dialysisInfo.Count {
  5671. //删除出库表
  5672. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5673. }
  5674. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5675. var flush_count_one int64
  5676. for _, it := range goodList {
  5677. flush_count_one += it.StockCount
  5678. }
  5679. //更新库存
  5680. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5681. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5682. //更新基础库库存
  5683. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5684. }
  5685. }
  5686. }
  5687. }
  5688. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5689. fmt.Println(err)
  5690. }
  5691. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5692. fmt.Println(err)
  5693. if len(advices) > 0 {
  5694. for _, item := range advices {
  5695. redis := service.RedisClient()
  5696. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5697. redis.Set(keyFive, "", time.Second)
  5698. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5699. redis.Set(keyOne, "", time.Second)
  5700. redis.Close()
  5701. }
  5702. }
  5703. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5704. if len(advices) > 0 {
  5705. for _, item := range advices {
  5706. creater := c.GetAdminUserInfo().AdminUser.Id
  5707. service.DrugAutoAddCancelInfo(item, creater)
  5708. }
  5709. }
  5710. } else {
  5711. if drugOutConfig.IsOpen == 1 {
  5712. if len(advices) > 0 {
  5713. for _, item := range advices {
  5714. creater := c.GetAdminUserInfo().AdminUser.Id
  5715. service.DrugAutoAddCancelInfo(item, creater)
  5716. }
  5717. }
  5718. } else {
  5719. if len(advices) > 0 {
  5720. for _, item := range advices {
  5721. creater := c.GetAdminUserInfo().AdminUser.Id
  5722. service.DrugAutoAddCancelInfo(item, creater)
  5723. }
  5724. }
  5725. }
  5726. }
  5727. c.ServeSuccessJSON(map[string]interface{}{
  5728. "msg": "删除成功",
  5729. })
  5730. return
  5731. }
  5732. func (c *HisApiController) DeleteDoctorAdvice() {
  5733. id, _ := c.GetInt64("id")
  5734. advice, _ := service.GetHisDoctorAdvicesById(id)
  5735. ////同步到自备药
  5736. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5737. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5738. if selfPrescriptionOpen.IsOpen == 1 {
  5739. db := service.XTWriteDB()
  5740. tx := db.Begin()
  5741. defer func() {
  5742. if r := recover(); r != nil {
  5743. tx.Rollback()
  5744. } else {
  5745. tx.Commit()
  5746. }
  5747. }()
  5748. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5749. var total_count int64
  5750. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5751. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5752. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5753. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5754. }
  5755. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5756. total_count += prescribingNumberSeven
  5757. }
  5758. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5759. total_count += prescribingNumberSeven
  5760. }
  5761. timeStr := time.Now().Format("2006-01-02")
  5762. timeArr := strings.Split(timeStr, "-")
  5763. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5764. total = total + 1
  5765. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5766. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5767. number = number + total
  5768. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5769. operation_time := time.Now().Unix()
  5770. creater := c.GetAdminUserInfo().AdminUser.Id
  5771. //创建一个出库单
  5772. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5773. WarehouseOutOrderNumber: warehousing_out_order,
  5774. OperationTime: operation_time,
  5775. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5776. Creater: creater,
  5777. Ctime: time.Now().Unix(),
  5778. Status: 1,
  5779. WarehouseOutTime: advice.AdviceDate,
  5780. Type: 0,
  5781. PatientId: advice.PatientId,
  5782. IsCheck: 1,
  5783. }
  5784. //查询今日是否有出库数据
  5785. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5786. if lastWarehouseOut.ID == 0 {
  5787. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5788. }
  5789. //出库
  5790. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5791. WarehouseOutId: lastWarehouseOut.ID,
  5792. WarehouseOutOrderNumber: warehousing_out_order,
  5793. DrugId: advice.DrugId,
  5794. Count: total_count,
  5795. Price: 0,
  5796. TotalPrice: 0,
  5797. Status: 1,
  5798. Ctime: advice.AdviceDate,
  5799. Mtime: advice.AdviceDate,
  5800. Remark: "",
  5801. OrgId: advice.UserOrgId,
  5802. Type: 0,
  5803. Manufacturer: selfBasedrug.Manufacturer,
  5804. Dealer: selfBasedrug.Dealer,
  5805. RetailPrice: 0,
  5806. RetailTotalPrice: 0,
  5807. CountUnit: advice.PrescribingNumberUnit,
  5808. ExpiryDate: 0,
  5809. ProductDate: 0,
  5810. Number: "",
  5811. BatchNumber: "",
  5812. IsSys: 0,
  5813. WarehouseInfoId: 0,
  5814. AdminUserId: 0,
  5815. StockCount: "",
  5816. IsCheck: 1,
  5817. SysRecordTime: advice.AdviceDate,
  5818. PatientId: advice.PatientId,
  5819. AdviceId: advice.ID,
  5820. ClassType: "",
  5821. }
  5822. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5823. for _, it := range warehousingOutInfo {
  5824. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5825. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5826. //出库逻辑
  5827. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5828. //查询剩余库存
  5829. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5830. var sum_count int64
  5831. for _, its := range stockInfo {
  5832. if its.MaxUnit == medical.MaxUnit {
  5833. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5834. }
  5835. sum_count += its.StockMaxNumber + its.StockMinNumber
  5836. }
  5837. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5838. }
  5839. }
  5840. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5841. //已收费和已发药的限制逻辑
  5842. isCharge := false
  5843. isMedicine := false
  5844. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5845. //获取今天该患者所有处方,判断是否发药或者收费
  5846. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5847. //for _, item := range new_prescriptions {
  5848. if new_prescription.IsMedicine == 1 {
  5849. isMedicine = true
  5850. }
  5851. //}
  5852. for _, item := range new_prescriptions {
  5853. if item.OrderStatus == 4 {
  5854. isCharge = true
  5855. }
  5856. }
  5857. if isMedicine {
  5858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5859. return
  5860. }
  5861. if isCharge {
  5862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5863. return
  5864. }
  5865. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5866. for _, item := range advices {
  5867. if item.IsMedicine == 1 {
  5868. isMedicine = true
  5869. }
  5870. }
  5871. if isMedicine {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5873. return
  5874. }
  5875. if new_prescription.ID > 0 {
  5876. if new_prescription.OrderStatus == 2 {
  5877. isCharge = true
  5878. }
  5879. }
  5880. if isCharge {
  5881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5882. return
  5883. }
  5884. //已收费和已发药的限制逻辑
  5885. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5886. redis := service.RedisClient()
  5887. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5888. redis.Set(keyFive, "", time.Second)
  5889. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5890. redis.Set(keyOne, "", time.Second)
  5891. defer redis.Close()
  5892. if err == nil {
  5893. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5894. //查询是否在处方中出库
  5895. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5896. if openConfig.IsOpen != 1 {
  5897. //判断该医嘱是否执行了
  5898. if advice.ExecutionState == 1 {
  5899. creater := c.GetAdminUserInfo().AdminUser.Id
  5900. service.DrugAutoAddCancelInfo(&advice, creater)
  5901. }
  5902. }
  5903. //开启保存处方扣减功能
  5904. if openConfig.IsOpen == 1 {
  5905. creater := c.GetAdminUserInfo().AdminUser.Id
  5906. service.DrugAutoAddCancelInfo(&advice, creater)
  5907. }
  5908. } else {
  5909. if drugOutConfig.IsOpen == 1 {
  5910. //查询是否在处方中出库
  5911. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5912. if openConfig.IsOpen != 1 {
  5913. //判断该医嘱是否执行了
  5914. if advice.ExecutionState == 1 {
  5915. creater := c.GetAdminUserInfo().AdminUser.Id
  5916. service.DrugAutoAddCancelInfo(&advice, creater)
  5917. }
  5918. }
  5919. //开启保存处方扣减功能
  5920. if openConfig.IsOpen == 1 {
  5921. creater := c.GetAdminUserInfo().AdminUser.Id
  5922. service.DrugAutoAddCancelInfo(&advice, creater)
  5923. }
  5924. } else {
  5925. //判断该医嘱是否执行了
  5926. if advice.ExecutionState == 1 {
  5927. creater := c.GetAdminUserInfo().AdminUser.Id
  5928. service.DrugAutoAddCancelInfo(&advice, creater)
  5929. }
  5930. }
  5931. }
  5932. c.ServeSuccessJSON(map[string]interface{}{
  5933. "msg": "删除成功",
  5934. })
  5935. return
  5936. } else {
  5937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5938. return
  5939. }
  5940. }
  5941. func (c *HisApiController) DeleteProject() {
  5942. id, _ := c.GetInt64("id")
  5943. adminInfo := c.GetAdminUserInfo()
  5944. project, _ := service.GetHisProjectByID(id)
  5945. // var consumable models.DialysisBeforePrepare
  5946. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5947. //耗材保存处方出库
  5948. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5949. isCharge := false
  5950. isMedicine := false
  5951. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5952. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5953. for _, item := range new_prescriptions {
  5954. if item.IsMedicine == 1 {
  5955. isMedicine = true
  5956. }
  5957. }
  5958. for _, item := range new_prescriptions {
  5959. if item.OrderStatus == 4 {
  5960. isCharge = true
  5961. }
  5962. }
  5963. if isMedicine {
  5964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5965. return
  5966. }
  5967. if isCharge {
  5968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5969. return
  5970. }
  5971. if new_prescription.ID > 0 {
  5972. if new_prescription.OrderStatus == 2 {
  5973. isCharge = true
  5974. }
  5975. }
  5976. if isCharge {
  5977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5978. return
  5979. }
  5980. service.DeletePrintInfo(id)
  5981. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5982. label.Status = 0
  5983. service.CreateHisLabelRecordTwo(&label)
  5984. fmt.Println(goodOutConfig.IsOpen)
  5985. if goodOutConfig.IsOpen != 1 {
  5986. if stockConfig.IsOpen == 1 {
  5987. if project.Type == 2 {
  5988. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5989. fmt.Println(err)
  5990. }
  5991. if project.Type == 3 && project.IsOut == 1 {
  5992. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5993. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5994. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5995. operation_time := time.Now().Unix()
  5996. creater := adminInfo.AdminUser.Id
  5997. //创建退库单
  5998. timeStr := time.Now().Format("2006-01-02")
  5999. timeArr := strings.Split(timeStr, "-")
  6000. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6001. total = total + 1
  6002. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6003. cancelStock := models.CancelStock{
  6004. OrderNumber: orderNumber,
  6005. OperaTime: operation_time,
  6006. OrgId: adminInfo.CurrentOrgId,
  6007. Creater: creater,
  6008. Ctime: time.Now().Unix(),
  6009. Status: 1,
  6010. ReturnTime: project.RecordDate,
  6011. Type: 1,
  6012. StorehouseId: houseConfig.StorehouseOutInfo,
  6013. IsCheck: 1,
  6014. }
  6015. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6016. if msgerrkonde == gorm.ErrRecordNotFound {
  6017. service.AddSigleCancelStock(&cancelStock)
  6018. }
  6019. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6020. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6021. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6022. //查询是否有出库
  6023. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6024. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6025. deaerler, _ := service.GetDealerById(info.Dealer)
  6026. if info.ID > 0 {
  6027. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6028. if info.Count >= prescribingNumber {
  6029. cancelStockInfo := models.CancelStockInfo{
  6030. GoodId: project.ProjectId,
  6031. CancelStockId: cancel.ID,
  6032. GoodTypeId: good.GoodTypeId,
  6033. Count: prescribingNumber,
  6034. Price: info.Price,
  6035. Total: 0,
  6036. ProductDate: info.ProductDate,
  6037. ExpiryDate: info.ExpiryDate,
  6038. Ctime: time.Now().Unix(),
  6039. Status: 1,
  6040. OrgId: adminInfo.CurrentOrgId,
  6041. OrderNumber: cancel.OrderNumber,
  6042. Type: 0,
  6043. Dealer: deaerler.DealerName,
  6044. Manufacturer: manufacturer.ManufacturerName,
  6045. Number: info.Number,
  6046. RegisterAccount: "",
  6047. Remark: "",
  6048. WarehouseInfoId: info.WarehouseInfotId,
  6049. PatientId: info.PatientId,
  6050. RecordDate: info.SysRecordTime,
  6051. StorehouseId: houseConfig.StorehouseOutInfo,
  6052. IsCheck: 1,
  6053. }
  6054. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6055. //回退库存
  6056. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6057. //退库数量增加
  6058. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6059. //出库数量减少
  6060. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6061. }
  6062. if info.Count < prescribingNumber {
  6063. cancelStockInfo := models.CancelStockInfo{
  6064. GoodId: project.ProjectId,
  6065. CancelStockId: cancel.ID,
  6066. GoodTypeId: good.GoodTypeId,
  6067. Count: info.Count,
  6068. Price: info.Price,
  6069. Total: 0,
  6070. ProductDate: info.ProductDate,
  6071. ExpiryDate: info.ExpiryDate,
  6072. Ctime: time.Now().Unix(),
  6073. Status: 1,
  6074. OrgId: adminInfo.CurrentOrgId,
  6075. OrderNumber: cancel.OrderNumber,
  6076. Type: 0,
  6077. Dealer: deaerler.DealerName,
  6078. Manufacturer: manufacturer.ManufacturerName,
  6079. Number: info.Number,
  6080. RegisterAccount: "",
  6081. Remark: "",
  6082. WarehouseInfoId: info.WarehouseInfotId,
  6083. PatientId: info.PatientId,
  6084. RecordDate: info.SysRecordTime,
  6085. StorehouseId: houseConfig.StorehouseOutInfo,
  6086. IsCheck: 1,
  6087. }
  6088. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6089. //回退库存
  6090. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6091. //退库数量增加
  6092. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6093. //出库数量减少
  6094. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6095. }
  6096. //查询剩余库存
  6097. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6098. var over_count int64
  6099. for _, it := range goodList {
  6100. over_count += it.StockCount
  6101. }
  6102. //出库数据 大于 退库数量
  6103. if info.Count >= prescribingNumber {
  6104. flow := models.VmStockFlow{
  6105. WarehousingId: info.WarehouseInfotId,
  6106. GoodId: project.ProjectId,
  6107. Number: info.Number,
  6108. LicenseNumber: info.LicenseNumber,
  6109. Count: prescribingNumber,
  6110. UserOrgId: adminInfo.CurrentOrgId,
  6111. PatientId: project.PatientId,
  6112. SystemTime: info.SysRecordTime,
  6113. ConsumableType: 7,
  6114. IsSys: 0,
  6115. WarehousingOrder: "",
  6116. WarehouseOutId: info.WarehouseOutId,
  6117. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6118. IsEdit: 0,
  6119. CancelStockId: cancel.ID,
  6120. CancelOrderNumber: cancel.OrderNumber,
  6121. Manufacturer: manufacturer.ID,
  6122. Dealer: 0,
  6123. Creator: adminInfo.AdminUser.Id,
  6124. UpdateCreator: 0,
  6125. Status: 1,
  6126. Ctime: time.Now().Unix(),
  6127. Mtime: 0,
  6128. Price: info.Price,
  6129. WarehousingDetailId: info.WarehouseInfotId,
  6130. WarehouseOutDetailId: info.ID,
  6131. CancelOutDetailId: cancelInfo.ID,
  6132. ProductDate: info.ProductDate,
  6133. ExpireDate: info.ExpiryDate,
  6134. StorehouseId: houseConfig.StorehouseOutInfo,
  6135. OverCount: over_count,
  6136. OperateTime: time.Now().Unix(),
  6137. }
  6138. service.CreateStockFlowOne(flow)
  6139. }
  6140. //出库数据小于退库数据
  6141. if info.Count < prescribingNumber {
  6142. flow := models.VmStockFlow{
  6143. WarehousingId: info.WarehouseInfotId,
  6144. GoodId: project.ProjectId,
  6145. Number: info.Number,
  6146. LicenseNumber: info.LicenseNumber,
  6147. Count: info.Count,
  6148. UserOrgId: adminInfo.CurrentOrgId,
  6149. PatientId: project.PatientId,
  6150. SystemTime: info.SysRecordTime,
  6151. ConsumableType: 7,
  6152. IsSys: 0,
  6153. WarehousingOrder: "",
  6154. WarehouseOutId: info.WarehouseOutId,
  6155. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6156. IsEdit: 0,
  6157. CancelStockId: cancel.ID,
  6158. CancelOrderNumber: cancel.OrderNumber,
  6159. Manufacturer: manufacturer.ID,
  6160. Dealer: 0,
  6161. Creator: adminInfo.AdminUser.Id,
  6162. UpdateCreator: 0,
  6163. Status: 1,
  6164. Ctime: time.Now().Unix(),
  6165. Mtime: 0,
  6166. Price: info.Price,
  6167. WarehousingDetailId: info.WarehouseInfotId,
  6168. WarehouseOutDetailId: info.ID,
  6169. CancelOutDetailId: cancelInfo.ID,
  6170. ProductDate: info.ProductDate,
  6171. ExpireDate: info.ExpiryDate,
  6172. StorehouseId: houseConfig.StorehouseOutInfo,
  6173. OverCount: over_count,
  6174. OperateTime: time.Now().Unix(),
  6175. }
  6176. service.CreateStockFlowOne(flow)
  6177. }
  6178. //查询已出库数量
  6179. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6180. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6181. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6182. if prescribingNumber < dialysisInfo.Count {
  6183. //改变数量
  6184. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6185. }
  6186. if prescribingNumber >= dialysisInfo.Count {
  6187. //删除出库表
  6188. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6189. }
  6190. //更新剩余库存
  6191. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6192. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6193. var total_count_one int64
  6194. for _, it := range stockList {
  6195. total_count_one += it.StockCount
  6196. }
  6197. //基础库插入数据
  6198. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6199. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6200. var flush_count int64
  6201. for _, it := range goodListOne {
  6202. flush_count += it.StockCount
  6203. }
  6204. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6205. if errs != nil {
  6206. goodErrcode := models.XtGoodErrcode{
  6207. UserOrgId: project.UserOrgId,
  6208. Errcode: "手动出库更新剩余出库失败",
  6209. GoodId: project.ProjectId,
  6210. Status: 1,
  6211. Ctime: time.Now().Unix(),
  6212. Mtime: 0,
  6213. Count: 0,
  6214. StockCount: 0,
  6215. Creater: creater,
  6216. BatchNumberId: 0,
  6217. WarehouseOutId: 0,
  6218. }
  6219. service.CreateGoodErrcode(goodErrcode)
  6220. }
  6221. }
  6222. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6223. fmt.Println(err)
  6224. } else {
  6225. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6226. fmt.Println(err)
  6227. }
  6228. } else {
  6229. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6230. fmt.Println(err)
  6231. }
  6232. }
  6233. //保存处方出库
  6234. if goodOutConfig.IsOpen == 1 {
  6235. if project.Type == 3 {
  6236. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6237. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6238. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6239. operation_time := time.Now().Unix()
  6240. creater := adminInfo.AdminUser.Id
  6241. //创建退库单
  6242. timeStr := time.Now().Format("2006-01-02")
  6243. timeArr := strings.Split(timeStr, "-")
  6244. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6245. total = total + 1
  6246. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6247. cancelStock := models.CancelStock{
  6248. OrderNumber: orderNumber,
  6249. OperaTime: operation_time,
  6250. OrgId: adminInfo.CurrentOrgId,
  6251. Creater: creater,
  6252. Ctime: time.Now().Unix(),
  6253. Status: 1,
  6254. ReturnTime: project.RecordDate,
  6255. Type: 1,
  6256. StorehouseId: houseConfig.StorehouseOutInfo,
  6257. IsCheck: 1,
  6258. }
  6259. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6260. if msgerrkonde == gorm.ErrRecordNotFound {
  6261. service.AddSigleCancelStock(&cancelStock)
  6262. }
  6263. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6264. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6265. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6266. //获取出库数据
  6267. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6268. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6269. deaerler, _ := service.GetDealerById(info.Dealer)
  6270. if info.ID > 0 {
  6271. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6272. if info.Count >= prescribingNumber {
  6273. cancelStockInfo := models.CancelStockInfo{
  6274. GoodId: project.ProjectId,
  6275. CancelStockId: cancel.ID,
  6276. GoodTypeId: good.GoodTypeId,
  6277. Count: prescribingNumber,
  6278. Price: info.Price,
  6279. Total: 0,
  6280. ProductDate: info.ProductDate,
  6281. ExpiryDate: info.ExpiryDate,
  6282. Ctime: time.Now().Unix(),
  6283. Status: 1,
  6284. OrgId: adminInfo.CurrentOrgId,
  6285. OrderNumber: cancel.OrderNumber,
  6286. Type: 0,
  6287. Dealer: deaerler.DealerName,
  6288. Manufacturer: manufacturer.ManufacturerName,
  6289. Number: info.Number,
  6290. RegisterAccount: "",
  6291. Remark: "",
  6292. WarehouseInfoId: info.WarehouseInfotId,
  6293. PatientId: info.PatientId,
  6294. RecordDate: info.SysRecordTime,
  6295. StorehouseId: houseConfig.StorehouseOutInfo,
  6296. IsCheck: 1,
  6297. }
  6298. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6299. //退库数量增加
  6300. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6301. //出库数量减少
  6302. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6303. }
  6304. if info.Count < prescribingNumber {
  6305. cancelStockInfo := models.CancelStockInfo{
  6306. GoodId: project.ProjectId,
  6307. CancelStockId: cancel.ID,
  6308. GoodTypeId: good.GoodTypeId,
  6309. Count: prescribingNumber,
  6310. Price: info.Price,
  6311. Total: 0,
  6312. ProductDate: info.ProductDate,
  6313. ExpiryDate: info.ExpiryDate,
  6314. Ctime: time.Now().Unix(),
  6315. Status: 1,
  6316. OrgId: adminInfo.CurrentOrgId,
  6317. OrderNumber: cancel.OrderNumber,
  6318. Type: 0,
  6319. Dealer: deaerler.DealerName,
  6320. Manufacturer: manufacturer.ManufacturerName,
  6321. Number: info.Number,
  6322. RegisterAccount: "",
  6323. Remark: "",
  6324. WarehouseInfoId: info.WarehouseInfotId,
  6325. PatientId: info.PatientId,
  6326. RecordDate: info.SysRecordTime,
  6327. StorehouseId: houseConfig.StorehouseOutInfo,
  6328. IsCheck: 1,
  6329. }
  6330. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6331. //回退库存
  6332. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6333. }
  6334. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6335. var over_count int64
  6336. for _, it := range goodList {
  6337. over_count += it.StockCount
  6338. }
  6339. //查询出库数量
  6340. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6341. //出库数据 大于 退库数量
  6342. if len(list) > 0 {
  6343. for _, it := range list {
  6344. //回退库存
  6345. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6346. //退库数量增加
  6347. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6348. //出库数量减少
  6349. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6350. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6351. var over_count_one int64
  6352. for _, it := range goodList {
  6353. over_count_one += it.StockCount
  6354. }
  6355. //查询该批次是否有退库数据
  6356. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6357. flow := models.VmStockFlow{
  6358. WarehousingId: it.WarehouseInfotId,
  6359. GoodId: it.GoodId,
  6360. Number: it.Number,
  6361. LicenseNumber: it.LicenseNumber,
  6362. Count: it.Count,
  6363. UserOrgId: adminInfo.CurrentOrgId,
  6364. PatientId: it.PatientId,
  6365. SystemTime: it.SysRecordTime,
  6366. ConsumableType: 7,
  6367. IsSys: 0,
  6368. WarehousingOrder: "",
  6369. WarehouseOutId: it.WarehouseOutId,
  6370. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6371. IsEdit: 0,
  6372. CancelStockId: cancel.ID,
  6373. CancelOrderNumber: cancel.OrderNumber,
  6374. Manufacturer: manufacturer.ID,
  6375. Dealer: 0,
  6376. Creator: adminInfo.AdminUser.Id,
  6377. UpdateCreator: 0,
  6378. Status: 1,
  6379. Ctime: time.Now().Unix(),
  6380. Mtime: 0,
  6381. Price: it.Price,
  6382. WarehousingDetailId: it.WarehouseInfotId,
  6383. WarehouseOutDetailId: it.ID,
  6384. CancelOutDetailId: cancelInfo.ID,
  6385. ProductDate: it.ProductDate,
  6386. ExpireDate: it.ExpiryDate,
  6387. StorehouseId: houseConfig.StorehouseOutInfo,
  6388. OverCount: over_count_one,
  6389. OperateTime: time.Now().Unix(),
  6390. }
  6391. service.CreateStockFlowOne(flow)
  6392. }
  6393. }
  6394. //查询已出库数量
  6395. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6396. if prescribingNumber < dialysisInfo.Count {
  6397. //改变数量
  6398. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6399. }
  6400. if prescribingNumber >= dialysisInfo.Count {
  6401. //删除出库表
  6402. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6403. }
  6404. //更新剩余库存
  6405. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6406. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6407. var total_count_one int64
  6408. for _, it := range stockList {
  6409. total_count_one += it.StockCount
  6410. }
  6411. //基础库插入数据
  6412. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6413. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6414. var flush_count int64
  6415. for _, it := range goodListOne {
  6416. flush_count += it.StockCount
  6417. }
  6418. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6419. if errs != nil {
  6420. goodErrcode := models.XtGoodErrcode{
  6421. UserOrgId: project.UserOrgId,
  6422. Errcode: "手动出库更新剩余出库失败",
  6423. GoodId: project.ProjectId,
  6424. Status: 1,
  6425. Ctime: time.Now().Unix(),
  6426. Mtime: 0,
  6427. Count: 0,
  6428. StockCount: 0,
  6429. Creater: creater,
  6430. BatchNumberId: 0,
  6431. WarehouseOutId: 0,
  6432. }
  6433. service.CreateGoodErrcode(goodErrcode)
  6434. }
  6435. }
  6436. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6437. fmt.Println(err)
  6438. } else {
  6439. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6440. fmt.Println(err)
  6441. }
  6442. }
  6443. c.ServeSuccessJSON(map[string]interface{}{
  6444. "msg": "删除成功",
  6445. })
  6446. return
  6447. }
  6448. func (c *HisApiController) CreateHisAdditionalCharge() {
  6449. his_patient_id, _ := c.GetInt64("his_patient_id")
  6450. patient_id, _ := c.GetInt64("patient_id")
  6451. record_date := c.GetString("record_date")
  6452. timeLayout := "2006-01-02"
  6453. loc, _ := time.LoadLocation("Local")
  6454. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6455. if err != nil {
  6456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6457. return
  6458. }
  6459. adminInfo := c.GetAdminUserInfo()
  6460. recordDateTime := theTime.Unix()
  6461. dataBody := make(map[string]interface{}, 0)
  6462. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6463. if err != nil {
  6464. utils.ErrorLog(err.Error())
  6465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6466. return
  6467. }
  6468. var additions []*models.HisAdditionalCharge
  6469. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6470. additions, _ := dataBody["addition"].([]interface{})
  6471. if len(additions) > 0 {
  6472. for _, item := range additions {
  6473. items := item.(map[string]interface{})
  6474. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6475. utils.ErrorLog("item_id")
  6476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6477. return
  6478. }
  6479. item_id := int64(items["item_id"].(float64))
  6480. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6481. utils.ErrorLog("item_name")
  6482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6483. return
  6484. }
  6485. item_name := items["item_name"].(string)
  6486. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6487. utils.ErrorLog("price")
  6488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6489. return
  6490. }
  6491. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6492. ctime := time.Now().Unix()
  6493. additional := &models.HisAdditionalCharge{
  6494. PatientId: patient_id,
  6495. HisPatientId: his_patient_id,
  6496. UserOrgId: adminInfo.CurrentOrgId,
  6497. RecordDate: recordDateTime,
  6498. CreatedTime: ctime,
  6499. UpdatedTime: ctime,
  6500. Modifier: adminInfo.AdminUser.Id,
  6501. Creator: adminInfo.AdminUser.Id,
  6502. Price: price,
  6503. ItemName: item_name,
  6504. ItemId: item_id,
  6505. Status: 1,
  6506. }
  6507. additions = append(additions, additional)
  6508. }
  6509. }
  6510. }
  6511. for _, item := range additions {
  6512. service.CreateAddtionalCharge(item)
  6513. }
  6514. c.ServeSuccessJSON(map[string]interface{}{
  6515. "msg": "创建成功",
  6516. })
  6517. }
  6518. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6519. blood_fat := c.GetString("blood_fat")
  6520. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6521. blood_sugar := c.GetString("blood_sugar")
  6522. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6523. chief_conplaint := c.GetString("chief_conplaint")
  6524. dbp := c.GetString("dbp")
  6525. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6526. delivery_way, _ := c.GetInt64("delivery_way")
  6527. diagnostic := c.GetString("diagnostic")
  6528. family_history := c.GetString("family_history")
  6529. height := c.GetString("height")
  6530. history_of_present_illness := c.GetString("history_of_present_illness")
  6531. is_infect, _ := c.GetInt64("is_infect")
  6532. past_history := c.GetString("past_history")
  6533. patient_id, _ := c.GetInt64("patient_id")
  6534. his_patient_id, _ := c.GetInt64("his_patient_id")
  6535. personal_history := c.GetString("personal_history")
  6536. pulse := c.GetString("pulse")
  6537. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6538. sbp := c.GetString("sbp")
  6539. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6540. heightfloat, _ := strconv.ParseFloat(height, 64)
  6541. sicktype := c.GetString("sick_type")
  6542. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6543. symptom := c.GetString("symptom")
  6544. sick_date := c.GetString("sick_date")
  6545. temperatures := c.GetString("temperature")
  6546. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6547. record_date := c.GetString("record_date")
  6548. breathing := c.GetString("breathing")
  6549. doctor_advice := c.GetString("doctor_advice")
  6550. remark := c.GetString("remark")
  6551. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6552. sick, _ := c.GetInt64("sick")
  6553. diagnose, _ := c.GetInt64("diagnose")
  6554. //id, _ := c.GetInt64("id")
  6555. timeLayout := "2006-01-02"
  6556. loc, _ := time.LoadLocation("Local")
  6557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6558. allergic_history := c.GetString("allergic_history")
  6559. if err != nil {
  6560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6561. return
  6562. }
  6563. recordDateTime := theTime.Unix()
  6564. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6565. if err != nil {
  6566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6567. return
  6568. }
  6569. sickTimes := sickTime.Unix()
  6570. ctime := time.Now().Unix()
  6571. primary_disease := c.GetString("primary_disease")
  6572. confirm_failure_date := c.GetString("confirm_failure_date")
  6573. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6574. drug_allergy_history := c.GetString("drug_allergy_history")
  6575. physical_examination := c.GetString("physical_examination")
  6576. special_inspection := c.GetString("special_inspection")
  6577. lab_apparatus := c.GetString("lab_apparatus")
  6578. caseHistory := models.HisPatientCaseHistory{
  6579. HisPatientId: his_patient_id,
  6580. PatientId: patient_id,
  6581. Temperature: temperature,
  6582. BloodSugar: bloodsugarfloat,
  6583. Pulse: pulsefloat,
  6584. Sbp: sbpfloat,
  6585. Dbp: dbpfloat,
  6586. Height: heightfloat,
  6587. BloodFat: bloodfatfloat,
  6588. SickType: sick_type,
  6589. Symptom: symptom,
  6590. SickDate: sickTimes,
  6591. IsInfect: is_infect,
  6592. HistoryOfPresentIllness: history_of_present_illness,
  6593. PastHistory: past_history,
  6594. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6595. ChiefConplaint: chief_conplaint,
  6596. PersonalHistory: personal_history,
  6597. FamilyHistory: family_history,
  6598. Diagnostic: diagnostic,
  6599. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6600. Status: 1,
  6601. Ctime: ctime,
  6602. Mtime: ctime,
  6603. RecordDate: recordDateTime,
  6604. DeliveryWay: delivery_way,
  6605. Breathing: breathingfloat,
  6606. DoctorAdvice: doctor_advice,
  6607. Remark: remark,
  6608. Sick: sick,
  6609. Diagnose: diagnose,
  6610. AllergicHistory: allergic_history,
  6611. PrimaryDisease: primary_disease,
  6612. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6613. DrugAllergyHistory: drug_allergy_history,
  6614. PhysicalExamination: physical_examination,
  6615. SpecialInspection: special_inspection,
  6616. LabApparatus: lab_apparatus,
  6617. }
  6618. //查询该患者是否有病历
  6619. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6620. if errcodes == gorm.ErrRecordNotFound {
  6621. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6622. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6623. if err != nil {
  6624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6625. return
  6626. }
  6627. c.ServeSuccessJSON(map[string]interface{}{
  6628. "caseHistory": caseHistory,
  6629. "historyInfo": historyInfo,
  6630. })
  6631. return
  6632. } else if errcodes == nil {
  6633. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6634. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6635. if err != nil {
  6636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6637. return
  6638. }
  6639. c.ServeSuccessJSON(map[string]interface{}{
  6640. "caseHistory": caseHistory,
  6641. "historyInfo": historyInfo,
  6642. })
  6643. }
  6644. //查询该患者是否有病历
  6645. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6646. //if errcode == gorm.ErrRecordNotFound {
  6647. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6648. // if err != nil {
  6649. // c.ServeSuccessJSON(map[string]interface{}{
  6650. // "msg": "保存成功",
  6651. // })
  6652. // }
  6653. //} else if errcode == nil {
  6654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6655. // return
  6656. //}
  6657. }
  6658. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6659. patient_id, _ := c.GetInt64("patient_id", 0)
  6660. adminUser := c.GetAdminUserInfo()
  6661. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6662. c.ServeSuccessJSON(map[string]interface{}{
  6663. "list": caseHistorys,
  6664. })
  6665. }
  6666. func (c *HisApiController) GetHisPatientCaseHistory() {
  6667. record_date, _ := c.GetInt64("record_date", 0)
  6668. patient_id, _ := c.GetInt64("patient_id", 0)
  6669. admin := c.GetAdminUserInfo()
  6670. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6671. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6672. c.ServeSuccessJSON(map[string]interface{}{
  6673. "info": info,
  6674. "case_history": case_history,
  6675. })
  6676. }
  6677. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6678. template_name := c.GetString("template_name")
  6679. template_remark := c.GetString("template_remark")
  6680. doctor := c.GetAdminUserInfo().AdminUser.Id
  6681. diagnostic := c.GetString("diagnostic")
  6682. chief_conplaint := c.GetString("chief_conplain")
  6683. history_of_present_illness := c.GetString("history_of_present_illness")
  6684. past_history := c.GetString("past_history")
  6685. personal_history := c.GetString("personal_history")
  6686. family_history := c.GetString("family_history")
  6687. user_name := c.GetString("user_name")
  6688. doctor_advice := c.GetString("doctor_advice")
  6689. remark := c.GetString("remark")
  6690. //record_date := c.GetString("record_date")
  6691. //fmt.Println("record_date--------",record_date)
  6692. //timeLayout := "2006-01-02"
  6693. //loc, _ := time.LoadLocation("Local")
  6694. //
  6695. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6696. //if err != nil {
  6697. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6698. // return
  6699. //}
  6700. //recordDateTime := theTime.Unix()
  6701. ctime := time.Now().Unix()
  6702. template := models.HisCaseHistoryTemplate{
  6703. HistoryOfPresentIllness: history_of_present_illness,
  6704. PastHistory: past_history,
  6705. ChiefConplaint: chief_conplaint,
  6706. PersonalHistory: personal_history,
  6707. FamilyHistory: family_history,
  6708. Diagnostic: diagnostic,
  6709. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6710. Status: 1,
  6711. Ctime: ctime,
  6712. Mtime: ctime,
  6713. RecordDate: time.Now().Unix(),
  6714. TemplateName: template_name,
  6715. TemplateRemark: template_remark,
  6716. Creator: doctor,
  6717. Modifier: doctor,
  6718. UserName: user_name,
  6719. DoctorAdvice: doctor_advice,
  6720. Remark: remark,
  6721. }
  6722. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6723. if err == nil {
  6724. c.ServeSuccessJSON(map[string]interface{}{
  6725. "msg": "保存成功",
  6726. })
  6727. } else {
  6728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6729. return
  6730. }
  6731. }
  6732. func (c *HisApiController) GetCaseHistoryTemplate() {
  6733. timeLayout := "2006-01-02"
  6734. loc, _ := time.LoadLocation("Local")
  6735. keyword := c.GetString("keyword")
  6736. start_time := c.GetString("start_time")
  6737. end_time := c.GetString("end_time")
  6738. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6739. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6740. admin := c.GetAdminUserInfo()
  6741. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6742. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6743. c.ServeSuccessJSON(map[string]interface{}{
  6744. "template": template,
  6745. //"history": history,
  6746. })
  6747. }
  6748. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6749. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6750. utils.ErrorLog("drug_name")
  6751. return enums.ErrorCodeParamWrong
  6752. }
  6753. adviceName, _ := json["drug_name"].(string)
  6754. if len(adviceName) == 0 {
  6755. utils.ErrorLog("len(advice_name) == 0")
  6756. return enums.ErrorCodeParamWrong
  6757. }
  6758. advice.AdviceName = adviceName
  6759. adviceDesc, _ := json["advice_desc"].(string)
  6760. advice.AdviceDesc = adviceDesc
  6761. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6762. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6763. advice.DrugSpec = drugSpec
  6764. }
  6765. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6766. remark, _ := json["remark"].(string)
  6767. advice.Remark = remark
  6768. }
  6769. if json["id"] == nil {
  6770. advice.DrugId = 0
  6771. } else {
  6772. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6773. drug_id := int64(json["id"].(float64))
  6774. advice.DrugId = drug_id
  6775. }
  6776. }
  6777. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6778. advice_id := int64(json["advice_id"].(float64))
  6779. advice.ID = advice_id
  6780. if advice.ID > 0 {
  6781. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6782. if err == nil {
  6783. if hisAdvice.ID > 0 {
  6784. advice.ExecutionTime = hisAdvice.ExecutionTime
  6785. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6786. advice.ExecutionState = hisAdvice.ExecutionState
  6787. advice.CheckTime = hisAdvice.CheckTime
  6788. advice.Checker = hisAdvice.Checker
  6789. advice.CheckState = hisAdvice.CheckState
  6790. advice.StartTime = hisAdvice.StartTime
  6791. advice.FeedetlSn = hisAdvice.FeedetlSn
  6792. }
  6793. }
  6794. }
  6795. }
  6796. //
  6797. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6798. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6799. // advice.ExecutionTime = execution_time
  6800. //}
  6801. //
  6802. //
  6803. //
  6804. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6805. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6806. // advice.ExecutionStaff = execution_staff
  6807. //}
  6808. //
  6809. //
  6810. //
  6811. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6812. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6813. // advice.ExecutionState = execution_state
  6814. //}
  6815. //
  6816. //
  6817. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6818. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6819. // advice.CheckTime = check_time
  6820. //}
  6821. //
  6822. //
  6823. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6824. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6825. // advice.CheckState = check_state
  6826. //}
  6827. //
  6828. //
  6829. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6830. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6831. // advice.Checker = checker
  6832. //}
  6833. //
  6834. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6835. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6836. // advice.StartTime = start_time
  6837. //}
  6838. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6839. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6840. advice.IsSelfDrug = is_self_drug
  6841. }
  6842. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6843. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6844. drug_way_count, _ := json["drug_way_count"].(string)
  6845. advice.DrugWayCount = drug_way_count
  6846. }
  6847. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6848. drugSpecUnit, _ := json["min_unit"].(string)
  6849. advice.DrugSpecUnit = drugSpecUnit
  6850. }
  6851. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6852. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6853. advice.SingleDose = singleDose
  6854. }
  6855. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6856. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6857. advice.SingleDoseUnit = singleDoseUnit
  6858. }
  6859. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6860. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6861. advice.PrescribingNumber = prescribingNumber
  6862. }
  6863. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6864. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6865. advice.PrescribingNumberUnit = prescribingNumberUnit
  6866. }
  6867. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6868. deliveryWay, _ := json["delivery_way"].(string)
  6869. advice.DeliveryWay = deliveryWay
  6870. }
  6871. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6872. executionFrequency, _ := json["execution_frequency"].(string)
  6873. advice.ExecutionFrequency = executionFrequency
  6874. }
  6875. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6876. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6877. advice.Price = price
  6878. }
  6879. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6880. med_list_codg, _ := json["medical_insurance_number"].(string)
  6881. advice.MedListCodg = med_list_codg
  6882. }
  6883. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6884. day := int64(json["day"].(float64))
  6885. advice.Day = day
  6886. }
  6887. return 0
  6888. }
  6889. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6890. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6891. id := int64(json["id"].(float64))
  6892. project.ID = id
  6893. historyProject, _ := service.GetHisProjectByID(id)
  6894. project.FeedetlSn = historyProject.FeedetlSn
  6895. }
  6896. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6897. project_id := int64(json["project_id"].(float64))
  6898. project.ProjectId = project_id
  6899. }
  6900. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6901. // price := int64(json["price"].(float64))
  6902. // formatInt_price := strconv.FormatInt(price, 10)
  6903. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6904. // project.Price = float_price
  6905. // }
  6906. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6907. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6908. project.Price = price
  6909. }
  6910. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6911. total, _ := json["total"].(string)
  6912. project.Count = total
  6913. }
  6914. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6915. medical_code, _ := json["medical_code"].(string)
  6916. project.MedListCodg = medical_code
  6917. }
  6918. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6919. single_dose, _ := json["single_dose"].(string)
  6920. project.SingleDose = single_dose
  6921. }
  6922. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6923. delivery_way, _ := json["delivery_way"].(string)
  6924. project.DeliveryWay = delivery_way
  6925. }
  6926. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6927. execution_frequency, _ := json["execution_frequency"].(string)
  6928. project.ExecutionFrequency = execution_frequency
  6929. }
  6930. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6931. remark, _ := json["remark"].(string)
  6932. project.Remark = remark
  6933. }
  6934. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6935. day, _ := json["number_days"].(string)
  6936. project.Day = day
  6937. }
  6938. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6939. unit, _ := json["unit"].(string)
  6940. project.Unit = unit
  6941. }
  6942. return 0
  6943. }
  6944. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6945. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6946. id := int64(json["id"].(float64))
  6947. historyAddtions, _ := service.GetHisAdditionByID(id)
  6948. additionalCharge.ID = id
  6949. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6950. }
  6951. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6952. item_id := int64(json["item_id"].(float64))
  6953. additionalCharge.ItemId = item_id
  6954. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6955. if config.ID > 0 {
  6956. if len(config.Code) > 0 {
  6957. additionalCharge.MedListCodg = config.Code
  6958. }
  6959. }
  6960. }
  6961. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6962. // price := int64(json["price"].(float64))
  6963. // formatInt_price := strconv.FormatInt(price, 10)
  6964. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6965. // additionalCharge.Price = float_price
  6966. // }
  6967. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6968. // price := int64(json["price"].(float64))
  6969. // formatInt_price := strconv.FormatInt(price, 10)
  6970. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6971. // additionalCharge.Price = float_price
  6972. //}
  6973. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6974. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6975. additionalCharge.Price = price
  6976. }
  6977. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6978. count, _ := json["count"].(string)
  6979. counts, _ := strconv.ParseInt(count, 10, 64)
  6980. additionalCharge.Count = counts
  6981. }
  6982. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6983. item_name, _ := json["item_name"].(string)
  6984. additionalCharge.ItemName = item_name
  6985. }
  6986. return 0
  6987. }
  6988. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6989. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6990. utils.ErrorLog("drug_name")
  6991. return enums.ErrorCodeParamWrong
  6992. }
  6993. adviceName, _ := json["drug_name"].(string)
  6994. if len(adviceName) == 0 {
  6995. utils.ErrorLog("len(advice_name) == 0")
  6996. return enums.ErrorCodeParamWrong
  6997. }
  6998. advice.AdviceName = adviceName
  6999. adviceDesc, _ := json["advice_desc"].(string)
  7000. advice.AdviceDesc = adviceDesc
  7001. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7002. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7003. advice.DrugSpec = drugSpec
  7004. }
  7005. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7006. remark, _ := json["remark"].(string)
  7007. advice.Remark = remark
  7008. }
  7009. if json["id"] == nil {
  7010. advice.DrugId = 0
  7011. } else {
  7012. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7013. drug_id := int64(json["id"].(float64))
  7014. advice.DrugId = drug_id
  7015. }
  7016. }
  7017. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7018. groupno := int64(json["groupno"].(float64))
  7019. advice.Groupno = groupno
  7020. }
  7021. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7022. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7023. advice.IsSelfDrug = is_self_drug
  7024. }
  7025. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7026. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7027. drug_way_count, _ := json["drug_way_count"].(string)
  7028. advice.DrugWayCount = drug_way_count
  7029. }
  7030. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7031. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7032. advice.HospApprFlag = hosp_appr_flag
  7033. }
  7034. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7035. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7036. advice.PrescribingNumber = prescribingNumber
  7037. }
  7038. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7039. // frequency_type := int64(json["frequency_type"].(float64))
  7040. // advice.FrequencyType = frequency_type
  7041. //}
  7042. //
  7043. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7044. // day_count := int64(json["day_count"].(float64))
  7045. // advice.DayCount = day_count
  7046. //}
  7047. //
  7048. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7049. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7050. // week_day, _ := json["week_day"].(string)
  7051. // advice.WeekDay = week_day
  7052. //}
  7053. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7054. drugSpecUnit, _ := json["min_unit"].(string)
  7055. advice.DrugSpecUnit = drugSpecUnit
  7056. }
  7057. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7058. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7059. advice.SingleDose = singleDose
  7060. }
  7061. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7062. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7063. advice.SingleDoseUnit = singleDoseUnit
  7064. }
  7065. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7066. deliveryWay, _ := json["delivery_way"].(string)
  7067. advice.DeliveryWay = deliveryWay
  7068. }
  7069. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7070. executionFrequency, _ := json["execution_frequency"].(string)
  7071. advice.ExecutionFrequency = executionFrequency
  7072. }
  7073. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7074. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7075. advice.Price = price
  7076. }
  7077. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7078. med_list_codg, _ := json["medical_insurance_number"].(string)
  7079. advice.MedListCodg = med_list_codg
  7080. }
  7081. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7082. day := int64(json["day"].(float64))
  7083. advice.Day = day
  7084. }
  7085. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7086. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7087. advice.PrescribingNumberUnit = prescribingNumberUnit
  7088. }
  7089. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7090. advice_id := int64(json["advice_id"].(float64))
  7091. advice.ID = advice_id
  7092. if advice.ID > 0 {
  7093. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7094. if err == nil {
  7095. if hisAdvice.ID > 0 {
  7096. advice.ExecutionTime = hisAdvice.ExecutionTime
  7097. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7098. advice.ExecutionState = hisAdvice.ExecutionState
  7099. advice.CheckTime = hisAdvice.CheckTime
  7100. advice.Checker = hisAdvice.Checker
  7101. advice.CheckState = hisAdvice.CheckState
  7102. advice.StartTime = hisAdvice.StartTime
  7103. advice.HospApprFlag = hisAdvice.HospApprFlag
  7104. advice.IsMedicine = hisAdvice.IsMedicine
  7105. if hisAdvice.UserOrgId == 10028 {
  7106. 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 {
  7107. advice.ExecutionTime = 0
  7108. advice.ExecutionStaff = 0
  7109. advice.ExecutionState = 2
  7110. advice.CheckTime = 0
  7111. advice.Checker = 0
  7112. advice.CheckState = 2
  7113. }
  7114. } else {
  7115. 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 {
  7116. advice.ExecutionTime = 0
  7117. advice.ExecutionStaff = 0
  7118. advice.ExecutionState = 2
  7119. advice.CheckTime = 0
  7120. advice.Checker = 0
  7121. advice.CheckState = 2
  7122. advice.UpdatedTime = time.Now().Unix()
  7123. }
  7124. }
  7125. //advice.Groupno = hisAdvice.Groupno
  7126. }
  7127. }
  7128. }
  7129. }
  7130. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7131. //
  7132. //if drugStockConfig.IsOpen == 1 {
  7133. //
  7134. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7135. // if advice.ID == 0 { //医嘱不存在
  7136. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7137. // drug.Total = drug.Total - advice.PrescribingNumber
  7138. // service.UpdateBaseDrugLib(&drug)
  7139. //
  7140. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7141. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7142. // drug.Total = drug.Total - num
  7143. // service.UpdateBaseDrugLib(&drug)
  7144. // }
  7145. //
  7146. // } else if advice.ID > 0 { //医嘱存在
  7147. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7148. // var num float64
  7149. //
  7150. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7151. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7152. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7153. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7154. // drug.Total = drug.Total + num
  7155. // service.UpdateBaseDrugLib(&drug)
  7156. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7157. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7158. // drug.Total = drug.Total - num
  7159. // service.UpdateBaseDrugLib(&drug)
  7160. // }
  7161. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7162. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7163. // if num2 > advice.PrescribingNumber {
  7164. // num = num2 - advice.PrescribingNumber
  7165. // drug.Total = drug.Total + num
  7166. // service.UpdateBaseDrugLib(&drug)
  7167. // } else if num2 < advice.PrescribingNumber {
  7168. // num = advice.PrescribingNumber - num2
  7169. // drug.Total = drug.Total - num
  7170. // service.UpdateBaseDrugLib(&drug)
  7171. // }
  7172. //
  7173. // }
  7174. //
  7175. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7176. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7177. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7178. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7179. // if num1 > num2 {
  7180. // num = num1 - num2
  7181. // drug.Total = drug.Total + num
  7182. // service.UpdateBaseDrugLib(&drug)
  7183. // } else if num1 < num2 {
  7184. // num = num2 - num1
  7185. // drug.Total = drug.Total - num
  7186. // service.UpdateBaseDrugLib(&drug)
  7187. // }
  7188. //
  7189. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7190. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7191. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7192. // if hisAdvice.PrescribingNumber > num2 {
  7193. // num = hisAdvice.PrescribingNumber - num2
  7194. // drug.Total = drug.Total + num
  7195. // service.UpdateBaseDrugLib(&drug)
  7196. // } else if num2 < advice.PrescribingNumber {
  7197. // num = num2 - hisAdvice.PrescribingNumber
  7198. // drug.Total = drug.Total - num
  7199. // service.UpdateBaseDrugLib(&drug)
  7200. // }
  7201. //
  7202. // }
  7203. // }
  7204. // }
  7205. //}
  7206. //
  7207. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7208. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7209. // advice.ExecutionTime = execution_time
  7210. //}
  7211. //
  7212. //
  7213. //
  7214. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7215. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7216. // advice.ExecutionStaff = execution_staff
  7217. //}
  7218. //
  7219. //
  7220. //
  7221. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7222. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7223. // advice.ExecutionState = execution_state
  7224. //}
  7225. //
  7226. //
  7227. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7228. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7229. // advice.CheckTime = check_time
  7230. //}
  7231. //
  7232. //
  7233. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7234. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7235. // advice.CheckState = check_state
  7236. //}
  7237. //
  7238. //
  7239. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7240. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7241. // advice.Checker = checker
  7242. //}
  7243. //
  7244. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7245. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7246. // advice.StartTime = start_time
  7247. //}
  7248. return 0
  7249. }
  7250. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7251. project.ExecutionStaff = 0
  7252. project.ExecutionState = 2
  7253. project.ExecutionTime = 0
  7254. project.Checker = 0
  7255. project.CheckState = 2
  7256. project.CheckTime = 0
  7257. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7258. id := int64(json["id"].(float64))
  7259. project.ID = id
  7260. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7261. project.ExecutionStaff = temp_project.ExecutionStaff
  7262. project.ExecutionState = temp_project.ExecutionState
  7263. project.ExecutionTime = temp_project.ExecutionTime
  7264. project.Checker = temp_project.Checker
  7265. project.CheckState = temp_project.CheckState
  7266. project.CheckTime = temp_project.CheckTime
  7267. project.TeamId = temp_project.TeamId
  7268. }
  7269. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7270. types := int64(json["type"].(float64))
  7271. project.Type = types
  7272. }
  7273. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7274. project_id := int64(json["project_id"].(float64))
  7275. project.ProjectId = project_id
  7276. }
  7277. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7278. team_id := int64(json["team_id"].(float64))
  7279. project.TeamId = team_id
  7280. }
  7281. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7282. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7283. project.Price = price
  7284. }
  7285. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7286. total, _ := json["total"].(string)
  7287. //totals, _ := strconv.ParseInt(total, 10, 64)
  7288. project.Count = total
  7289. }
  7290. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7291. medical_code, _ := json["medical_code"].(string)
  7292. project.MedListCodg = medical_code
  7293. }
  7294. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7295. single_dose, _ := json["single_dose"].(string)
  7296. project.SingleDose = single_dose
  7297. }
  7298. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7299. delivery_way, _ := json["delivery_way"].(string)
  7300. project.DeliveryWay = delivery_way
  7301. }
  7302. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7303. execution_frequency, _ := json["execution_frequency"].(string)
  7304. project.ExecutionFrequency = execution_frequency
  7305. }
  7306. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7307. remark, _ := json["remark"].(string)
  7308. project.Remark = remark
  7309. }
  7310. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7311. day, _ := json["number_days"].(string)
  7312. project.Day = day
  7313. }
  7314. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7315. unit, _ := json["unit"].(string)
  7316. project.Unit = unit
  7317. }
  7318. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7319. // frequency_type := int64(json["frequency_type"].(float64))
  7320. // project.FrequencyType = frequency_type
  7321. //}
  7322. //
  7323. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7324. // day_count := int64(json["day_count"].(float64))
  7325. // project.DayCount = day_count
  7326. //}
  7327. //
  7328. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7329. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7330. // week_day, _ := json["week_day"].(string)
  7331. // project.WeekDay = week_day
  7332. //}
  7333. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7334. //
  7335. //if project.ID == 0 {
  7336. // if stockConfig.IsOpen == 1 {
  7337. // if project.Type == 3 {
  7338. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7339. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7340. // good.Total = good.Total - f_count
  7341. // service.UpdateGoodInfo(&good)
  7342. // }
  7343. // }
  7344. //
  7345. //} else {
  7346. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7347. //
  7348. // if stockConfig.IsOpen == 1 {
  7349. // if project.Type == 3 {
  7350. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7351. // if project.Count < temp_project.Count {
  7352. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7353. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7354. //
  7355. // other_count := f_count_two - f_count_one
  7356. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7357. // good.Total = good.Total + other_count_two
  7358. // service.UpdateGoodInfo(&good)
  7359. // } else if project.Count > temp_project.Count {
  7360. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7361. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7362. //
  7363. // other_count := f_count_one - f_count_two
  7364. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7365. // good.Total = good.Total - other_count_two
  7366. // service.UpdateGoodInfo(&good)
  7367. // }
  7368. //
  7369. // }
  7370. // }
  7371. //
  7372. //}
  7373. return 0
  7374. }
  7375. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7376. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7377. utils.ErrorLog("drug_name")
  7378. return enums.ErrorCodeParamWrong
  7379. }
  7380. adviceName, _ := json["drug_name"].(string)
  7381. if len(adviceName) == 0 {
  7382. utils.ErrorLog("len(advice_name) == 0")
  7383. return enums.ErrorCodeParamWrong
  7384. }
  7385. advice.AdviceName = adviceName
  7386. adviceDesc, _ := json["advice_desc"].(string)
  7387. advice.AdviceDesc = adviceDesc
  7388. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7389. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7390. advice.DrugSpec = drugSpec
  7391. }
  7392. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7393. remark, _ := json["remark"].(string)
  7394. advice.Remark = remark
  7395. }
  7396. if json["id"] == nil {
  7397. advice.DrugId = 0
  7398. } else {
  7399. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7400. drug_id := int64(json["id"].(float64))
  7401. advice.DrugId = drug_id
  7402. }
  7403. }
  7404. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7405. groupno := int64(json["groupno"].(float64))
  7406. advice.Groupno = groupno
  7407. }
  7408. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7409. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7410. advice.IsSelfDrug = is_self_drug
  7411. }
  7412. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7413. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7414. drug_way_count, _ := json["drug_way_count"].(string)
  7415. advice.DrugWayCount = drug_way_count
  7416. }
  7417. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7418. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7419. advice.HospApprFlag = hosp_appr_flag
  7420. }
  7421. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7422. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7423. advice.PrescribingNumber = prescribingNumber
  7424. }
  7425. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7426. // frequency_type := int64(json["frequency_type"].(float64))
  7427. // advice.FrequencyType = frequency_type
  7428. //}
  7429. //
  7430. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7431. // day_count := int64(json["day_count"].(float64))
  7432. // advice.DayCount = day_count
  7433. //}
  7434. //
  7435. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7436. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7437. // week_day, _ := json["week_day"].(string)
  7438. // advice.WeekDay = week_day
  7439. //}
  7440. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7441. drugSpecUnit, _ := json["min_unit"].(string)
  7442. advice.DrugSpecUnit = drugSpecUnit
  7443. }
  7444. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7445. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7446. advice.SingleDose = singleDose
  7447. }
  7448. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7449. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7450. advice.SingleDoseUnit = singleDoseUnit
  7451. }
  7452. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7453. deliveryWay, _ := json["delivery_way"].(string)
  7454. advice.DeliveryWay = deliveryWay
  7455. }
  7456. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7457. executionFrequency, _ := json["execution_frequency"].(string)
  7458. advice.ExecutionFrequency = executionFrequency
  7459. }
  7460. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7461. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7462. advice.Price = price
  7463. }
  7464. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7465. med_list_codg, _ := json["medical_insurance_number"].(string)
  7466. advice.MedListCodg = med_list_codg
  7467. }
  7468. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7469. day := int64(json["day"].(float64))
  7470. advice.Day = day
  7471. }
  7472. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7473. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7474. advice.PrescribingNumberUnit = prescribingNumberUnit
  7475. }
  7476. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7477. advice_id := int64(json["advice_id"].(float64))
  7478. advice.ID = advice_id
  7479. if advice.ID > 0 {
  7480. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7481. if err == nil {
  7482. if hisAdvice.ID > 0 {
  7483. advice.ExecutionTime = hisAdvice.ExecutionTime
  7484. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7485. advice.ExecutionState = hisAdvice.ExecutionState
  7486. advice.CheckTime = hisAdvice.CheckTime
  7487. advice.Checker = hisAdvice.Checker
  7488. advice.DrugCode = hisAdvice.DrugCode
  7489. advice.CheckState = hisAdvice.CheckState
  7490. advice.StartTime = hisAdvice.StartTime
  7491. advice.HospApprFlag = hisAdvice.HospApprFlag
  7492. advice.IsMedicine = hisAdvice.IsMedicine
  7493. if hisAdvice.UserOrgId == 10028 {
  7494. 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 {
  7495. advice.ExecutionTime = 0
  7496. advice.ExecutionStaff = 0
  7497. advice.ExecutionState = 2
  7498. advice.CheckTime = 0
  7499. advice.Checker = 0
  7500. advice.CheckState = 2
  7501. }
  7502. } else {
  7503. 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 {
  7504. advice.ExecutionTime = 0
  7505. advice.ExecutionStaff = 0
  7506. advice.ExecutionState = 2
  7507. advice.CheckTime = 0
  7508. advice.Checker = 0
  7509. advice.CheckState = 2
  7510. //advice.UpdatedTime = time.Now().Unix()
  7511. advice.CreatedTime = hisAdvice.CreatedTime
  7512. advice.UpdatedTime = time.Now().Unix()
  7513. } else {
  7514. advice.CreatedTime = hisAdvice.CreatedTime
  7515. advice.UpdatedTime = hisAdvice.UpdatedTime
  7516. }
  7517. }
  7518. //advice.Groupno = hisAdvice.Groupno
  7519. } else {
  7520. advice.IsMedicine = 0
  7521. ctime := time.Now().Unix()
  7522. advice.CreatedTime = ctime
  7523. advice.UpdatedTime = ctime
  7524. }
  7525. }
  7526. } else {
  7527. advice.IsMedicine = 0
  7528. ctime := time.Now().Unix()
  7529. advice.CreatedTime = ctime
  7530. advice.UpdatedTime = ctime
  7531. }
  7532. }
  7533. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7534. //
  7535. //if drugStockConfig.IsOpen == 1 {
  7536. //
  7537. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7538. // if advice.ID == 0 { //医嘱不存在
  7539. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7540. // drug.Total = drug.Total - advice.PrescribingNumber
  7541. // service.UpdateBaseDrugLib(&drug)
  7542. //
  7543. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7544. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7545. // drug.Total = drug.Total - num
  7546. // service.UpdateBaseDrugLib(&drug)
  7547. // }
  7548. //
  7549. // } else if advice.ID > 0 { //医嘱存在
  7550. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7551. // var num float64
  7552. //
  7553. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7554. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7555. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7556. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7557. // drug.Total = drug.Total + num
  7558. // service.UpdateBaseDrugLib(&drug)
  7559. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7560. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7561. // drug.Total = drug.Total - num
  7562. // service.UpdateBaseDrugLib(&drug)
  7563. // }
  7564. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7565. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7566. // if num2 > advice.PrescribingNumber {
  7567. // num = num2 - advice.PrescribingNumber
  7568. // drug.Total = drug.Total + num
  7569. // service.UpdateBaseDrugLib(&drug)
  7570. // } else if num2 < advice.PrescribingNumber {
  7571. // num = advice.PrescribingNumber - num2
  7572. // drug.Total = drug.Total - num
  7573. // service.UpdateBaseDrugLib(&drug)
  7574. // }
  7575. //
  7576. // }
  7577. //
  7578. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7579. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7580. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7581. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7582. // if num1 > num2 {
  7583. // num = num1 - num2
  7584. // drug.Total = drug.Total + num
  7585. // service.UpdateBaseDrugLib(&drug)
  7586. // } else if num1 < num2 {
  7587. // num = num2 - num1
  7588. // drug.Total = drug.Total - num
  7589. // service.UpdateBaseDrugLib(&drug)
  7590. // }
  7591. //
  7592. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7593. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7594. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7595. // if hisAdvice.PrescribingNumber > num2 {
  7596. // num = hisAdvice.PrescribingNumber - num2
  7597. // drug.Total = drug.Total + num
  7598. // service.UpdateBaseDrugLib(&drug)
  7599. // } else if num2 < advice.PrescribingNumber {
  7600. // num = num2 - hisAdvice.PrescribingNumber
  7601. // drug.Total = drug.Total - num
  7602. // service.UpdateBaseDrugLib(&drug)
  7603. // }
  7604. //
  7605. // }
  7606. // }
  7607. // }
  7608. //}
  7609. //
  7610. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7611. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7612. // advice.ExecutionTime = execution_time
  7613. //}
  7614. //
  7615. //
  7616. //
  7617. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7618. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7619. // advice.ExecutionStaff = execution_staff
  7620. //}
  7621. //
  7622. //
  7623. //
  7624. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7625. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7626. // advice.ExecutionState = execution_state
  7627. //}
  7628. //
  7629. //
  7630. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7631. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7632. // advice.CheckTime = check_time
  7633. //}
  7634. //
  7635. //
  7636. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7637. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7638. // advice.CheckState = check_state
  7639. //}
  7640. //
  7641. //
  7642. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7643. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7644. // advice.Checker = checker
  7645. //}
  7646. //
  7647. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7648. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7649. // advice.StartTime = start_time
  7650. //}
  7651. return 0
  7652. }
  7653. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7654. project.ExecutionStaff = 0
  7655. project.ExecutionState = 2
  7656. project.ExecutionTime = 0
  7657. project.Checker = 0
  7658. project.CheckState = 2
  7659. project.CheckTime = 0
  7660. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7661. id := int64(json["id"].(float64))
  7662. project.ID = id
  7663. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7664. project.ExecutionStaff = temp_project.ExecutionStaff
  7665. project.ExecutionState = temp_project.ExecutionState
  7666. project.ExecutionTime = temp_project.ExecutionTime
  7667. project.Checker = temp_project.Checker
  7668. project.CheckState = temp_project.CheckState
  7669. project.CheckTime = temp_project.CheckTime
  7670. project.TeamId = temp_project.TeamId
  7671. }
  7672. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7673. types := int64(json["type"].(float64))
  7674. project.Type = types
  7675. }
  7676. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7677. project_id := int64(json["project_id"].(float64))
  7678. project.ProjectId = project_id
  7679. }
  7680. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7681. team_id := int64(json["team_id"].(float64))
  7682. project.TeamId = team_id
  7683. }
  7684. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7685. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7686. project.Price = price
  7687. }
  7688. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7689. total, _ := json["total"].(string)
  7690. //totals, _ := strconv.ParseInt(total, 10, 64)
  7691. project.Count = total
  7692. }
  7693. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7694. medical_code, _ := json["medical_code"].(string)
  7695. project.MedListCodg = medical_code
  7696. }
  7697. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7698. single_dose, _ := json["single_dose"].(string)
  7699. project.SingleDose = single_dose
  7700. }
  7701. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7702. delivery_way, _ := json["delivery_way"].(string)
  7703. project.DeliveryWay = delivery_way
  7704. }
  7705. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7706. execution_frequency, _ := json["execution_frequency"].(string)
  7707. project.ExecutionFrequency = execution_frequency
  7708. }
  7709. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7710. remark, _ := json["remark"].(string)
  7711. project.Remark = remark
  7712. }
  7713. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7714. day, _ := json["number_days"].(string)
  7715. project.Day = day
  7716. }
  7717. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7718. unit, _ := json["unit"].(string)
  7719. project.Unit = unit
  7720. }
  7721. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7722. // frequency_type := int64(json["frequency_type"].(float64))
  7723. // project.FrequencyType = frequency_type
  7724. //}
  7725. //
  7726. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7727. // day_count := int64(json["day_count"].(float64))
  7728. // project.DayCount = day_count
  7729. //}
  7730. //
  7731. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7732. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7733. // week_day, _ := json["week_day"].(string)
  7734. // project.WeekDay = week_day
  7735. //}
  7736. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7737. //
  7738. //if project.ID == 0 {
  7739. // if stockConfig.IsOpen == 1 {
  7740. // if project.Type == 3 {
  7741. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7742. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7743. // good.Total = good.Total - f_count
  7744. // service.UpdateGoodInfo(&good)
  7745. // }
  7746. // }
  7747. //
  7748. //} else {
  7749. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7750. //
  7751. // if stockConfig.IsOpen == 1 {
  7752. // if project.Type == 3 {
  7753. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7754. // if project.Count < temp_project.Count {
  7755. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7756. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7757. //
  7758. // other_count := f_count_two - f_count_one
  7759. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7760. // good.Total = good.Total + other_count_two
  7761. // service.UpdateGoodInfo(&good)
  7762. // } else if project.Count > temp_project.Count {
  7763. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7764. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7765. //
  7766. // other_count := f_count_one - f_count_two
  7767. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7768. // good.Total = good.Total - other_count_two
  7769. // service.UpdateGoodInfo(&good)
  7770. // }
  7771. //
  7772. // }
  7773. // }
  7774. //
  7775. //}
  7776. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7777. id := int64(json["id"].(float64))
  7778. if id > 0 {
  7779. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7780. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7781. fmt.Println("666666")
  7782. project.Mtime = time.Now().Unix()
  7783. project.Ctime = temp_project.Ctime
  7784. } else {
  7785. project.Mtime = temp_project.Mtime
  7786. project.Ctime = temp_project.Ctime
  7787. }
  7788. } else {
  7789. ctime := time.Now().Unix()
  7790. project.Mtime = ctime
  7791. project.Ctime = ctime
  7792. }
  7793. }
  7794. return 0
  7795. }
  7796. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7797. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7798. id := int64(json["id"].(float64))
  7799. additionalCharge.ID = id
  7800. }
  7801. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7802. item_id := int64(json["item_id"].(float64))
  7803. additionalCharge.ItemId = item_id
  7804. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7805. if config.ID > 0 {
  7806. if len(config.Code) > 0 {
  7807. additionalCharge.MedListCodg = config.Code
  7808. }
  7809. }
  7810. }
  7811. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7812. // price := int64(json["price"].(float64))
  7813. // formatInt_price := strconv.FormatInt(price, 10)
  7814. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7815. // additionalCharge.Price = float_price
  7816. // }
  7817. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7818. // price := int64(json["price"].(float64))
  7819. // formatInt_price := strconv.FormatInt(price, 10)
  7820. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7821. // additionalCharge.Price = float_price
  7822. //}
  7823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7824. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7825. additionalCharge.Price = price
  7826. }
  7827. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7828. count, _ := json["count"].(string)
  7829. counts, _ := strconv.ParseInt(count, 10, 64)
  7830. additionalCharge.Count = counts
  7831. }
  7832. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7833. item_name, _ := json["item_name"].(string)
  7834. additionalCharge.ItemName = item_name
  7835. }
  7836. return 0
  7837. }
  7838. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7839. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7840. utils.ErrorLog("drug_name")
  7841. return enums.ErrorCodeParamWrong
  7842. }
  7843. adviceName, _ := json["drug_name"].(string)
  7844. if len(adviceName) == 0 {
  7845. utils.ErrorLog("len(advice_name) == 0")
  7846. return enums.ErrorCodeParamWrong
  7847. }
  7848. advice.AdviceName = adviceName
  7849. adviceDesc, _ := json["advice_desc"].(string)
  7850. advice.AdviceDesc = adviceDesc
  7851. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7852. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7853. advice.DrugSpec = drugSpec
  7854. }
  7855. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7856. remark, _ := json["remark"].(string)
  7857. advice.Remark = remark
  7858. }
  7859. if json["id"] == nil {
  7860. advice.DrugId = 0
  7861. } else {
  7862. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7863. drug_id := int64(json["id"].(float64))
  7864. advice.DrugId = drug_id
  7865. }
  7866. }
  7867. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7868. groupno := int64(json["groupno"].(float64))
  7869. advice.Groupno = groupno
  7870. }
  7871. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7872. drugSpecUnit, _ := json["min_unit"].(string)
  7873. advice.DrugSpecUnit = drugSpecUnit
  7874. }
  7875. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7876. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7877. advice.SingleDose = singleDose
  7878. }
  7879. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7880. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7881. advice.SingleDoseUnit = singleDoseUnit
  7882. }
  7883. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7884. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7885. advice.PrescribingNumber = prescribingNumber
  7886. }
  7887. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7888. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7889. advice.PrescribingNumberUnit = prescribingNumberUnit
  7890. }
  7891. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7892. deliveryWay, _ := json["delivery_way"].(string)
  7893. advice.DeliveryWay = deliveryWay
  7894. }
  7895. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7896. executionFrequency, _ := json["execution_frequency"].(string)
  7897. advice.ExecutionFrequency = executionFrequency
  7898. }
  7899. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7900. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7901. advice.Price = price
  7902. }
  7903. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7904. med_list_codg, _ := json["medical_insurance_number"].(string)
  7905. advice.MedListCodg = med_list_codg
  7906. }
  7907. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7908. day := int64(json["day"].(float64))
  7909. advice.Day = day
  7910. }
  7911. advice.FrequencyType = 1
  7912. return 0
  7913. }
  7914. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7915. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7916. types := int64(json["type"].(float64))
  7917. project.Type = types
  7918. }
  7919. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7920. project_id := int64(json["project_id"].(float64))
  7921. project.ProjectId = project_id
  7922. }
  7923. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7924. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7925. project.Price = price
  7926. }
  7927. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7928. total, _ := json["total"].(string)
  7929. //totals, _ := strconv.ParseInt(total, 10, 64)
  7930. project.Count = total
  7931. }
  7932. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7933. medical_code, _ := json["medical_code"].(string)
  7934. project.MedListCodg = medical_code
  7935. }
  7936. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7937. single_dose, _ := json["single_dose"].(string)
  7938. project.SingleDose = single_dose
  7939. }
  7940. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7941. delivery_way, _ := json["delivery_way"].(string)
  7942. project.DeliveryWay = delivery_way
  7943. }
  7944. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7945. execution_frequency, _ := json["execution_frequency"].(string)
  7946. project.ExecutionFrequency = execution_frequency
  7947. }
  7948. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7949. remark, _ := json["remark"].(string)
  7950. project.Remark = remark
  7951. }
  7952. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7953. day, _ := json["number_days"].(string)
  7954. project.Day = day
  7955. }
  7956. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7957. unit, _ := json["unit"].(string)
  7958. project.Unit = unit
  7959. }
  7960. project.FrequencyType = 1
  7961. return 0
  7962. }
  7963. func (c *HisApiController) GetHisOrderListTwo() {
  7964. start_time := c.GetString("start_time")
  7965. end_time := c.GetString("end_time")
  7966. timeLayout := "2006-01-02"
  7967. loc, _ := time.LoadLocation("Local")
  7968. var startTime int64
  7969. if len(start_time) > 0 {
  7970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7971. if err != nil {
  7972. //fmt.Println(err)
  7973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7974. return
  7975. }
  7976. startTime = theTime.Unix()
  7977. }
  7978. var endTime int64
  7979. if len(end_time) > 0 {
  7980. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7981. if err != nil {
  7982. utils.ErrorLog(err.Error())
  7983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7984. return
  7985. }
  7986. endTime = theTime.Unix()
  7987. }
  7988. adminUser := c.GetAdminUserInfo()
  7989. org_id := adminUser.CurrentOrgId
  7990. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7991. if err == nil {
  7992. c.ServeSuccessJSON(map[string]interface{}{
  7993. "order2": order,
  7994. })
  7995. } else {
  7996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7997. return
  7998. }
  7999. }
  8000. func (c *HisApiController) GetHisOrderList() {
  8001. page, _ := c.GetInt64("page", -1)
  8002. limit, _ := c.GetInt64("limit", -1)
  8003. start_time := c.GetString("start_time")
  8004. end_time := c.GetString("end_time")
  8005. types, _ := c.GetInt64("type", 0)
  8006. keywords := c.GetString("keywords")
  8007. p_type, _ := c.GetInt64("p_type", 0)
  8008. sort_type, _ := c.GetInt64("sort_type", 0)
  8009. charge_type, _ := c.GetInt64("charge_type", 0)
  8010. sch_type, _ := c.GetInt64("sch_type", 0)
  8011. zone_type, _ := c.GetInt64("zone_type", 0)
  8012. med_type, _ := c.GetInt64("med_type", 0)
  8013. timeLayout := "2006-01-02"
  8014. loc, _ := time.LoadLocation("Local")
  8015. var startTime int64
  8016. if len(start_time) > 0 {
  8017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8018. if err != nil {
  8019. //fmt.Println(err)
  8020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8021. return
  8022. }
  8023. startTime = theTime.Unix()
  8024. }
  8025. var endTime int64
  8026. if len(end_time) > 0 {
  8027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8028. if err != nil {
  8029. utils.ErrorLog(err.Error())
  8030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8031. return
  8032. }
  8033. endTime = theTime.Unix()
  8034. }
  8035. adminUser := c.GetAdminUserInfo()
  8036. org_id := adminUser.CurrentOrgId
  8037. 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)
  8038. for _, item := range order {
  8039. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8040. item.DoctorName = info.Doctor
  8041. item.DepartmentName = info.XtHisDepartment.Name
  8042. }
  8043. if err == nil {
  8044. c.ServeSuccessJSON(map[string]interface{}{
  8045. "order": order,
  8046. "total": total,
  8047. })
  8048. } else {
  8049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8050. return
  8051. }
  8052. }
  8053. func (c *HisApiController) GetHisOrder() {
  8054. patient_id, _ := c.GetInt64("patient_id", 0)
  8055. number := c.GetString("number")
  8056. adminInfo := c.GetAdminUserInfo()
  8057. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8058. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8059. if err == nil {
  8060. c.ServeSuccessJSON(map[string]interface{}{
  8061. "order": order,
  8062. "prescription": prescriptions,
  8063. })
  8064. } else {
  8065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8066. return
  8067. }
  8068. }
  8069. func (c *HisApiController) GetHisPrescriptionList() {
  8070. record_date := c.GetString("record_date")
  8071. keywords := c.GetString("keywords")
  8072. page, _ := c.GetInt64("page")
  8073. limit, _ := c.GetInt64("limit")
  8074. sch_type, _ := c.GetInt64("sch_type")
  8075. timeLayout := "2006-01-02"
  8076. loc, _ := time.LoadLocation("Local")
  8077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8078. if err != nil {
  8079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8080. return
  8081. }
  8082. recordDateTime := theTime.Unix()
  8083. adminInfo := c.GetAdminUserInfo()
  8084. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8085. //adminInfo := c.GetAdminUserInfo()
  8086. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8087. //fmt.Println(prescriptionOrder)
  8088. if err == nil {
  8089. c.ServeSuccessJSON(map[string]interface{}{
  8090. "order": prescriptionOrder,
  8091. "total": total,
  8092. })
  8093. } else {
  8094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8095. return
  8096. }
  8097. }
  8098. func (c *HisApiController) GetHisPrescriptionInfo() {
  8099. id, _ := c.GetInt64("id")
  8100. adminInfo := c.GetAdminUserInfo()
  8101. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8102. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8103. if err == nil {
  8104. c.ServeSuccessJSON(map[string]interface{}{
  8105. "order": prescriptionOrder,
  8106. "prescription": prescription,
  8107. })
  8108. } else {
  8109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8110. return
  8111. }
  8112. }
  8113. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8114. adminUser := c.GetAdminUserInfo()
  8115. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8116. c.ServeSuccessJSON(map[string]interface{}{
  8117. "config": config,
  8118. })
  8119. }
  8120. type ResultTwo struct {
  8121. ErrMsg interface{} `json:"err_msg"`
  8122. InfRefmsgid string `json:"inf_refmsgid"`
  8123. Infcode int64 `json:"infcode"`
  8124. Output struct {
  8125. Baseinfo struct {
  8126. Age float64 `json:"age"`
  8127. Brdy string `json:"brdy"`
  8128. Certno string `json:"certno"`
  8129. Gend string `json:"gend"`
  8130. Naty string `json:"naty"`
  8131. PsnCertType string `json:"psn_cert_type"`
  8132. PsnName string `json:"psn_name"`
  8133. PsnNo string `json:"psn_no"`
  8134. } `json:"baseinfo"`
  8135. Idetinfo []interface{} `json:"idetinfo"`
  8136. Iinfo []struct {
  8137. Balc float64 `json:"balc"`
  8138. CvlservFlag string `json:"cvlserv_flag"`
  8139. EmpName string `json:"emp_name"`
  8140. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8141. Insutype string `json:"insutype"`
  8142. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8143. PausInsuDate interface{} `json:"paus_insu_date"`
  8144. PsnInsuDate string `json:"psn_insu_date"`
  8145. PsnInsuStas string `json:"psn_insu_stas"`
  8146. PsnType string `json:"psn_type"`
  8147. } `json:"insuinfo"`
  8148. } `json:"output"`
  8149. RefmsgTime string `json:"refmsg_time"`
  8150. RespondTime string `json:"respond_time"`
  8151. Signtype interface{} `json:"signtype"`
  8152. WarnInfo interface{} `json:"warn_info"`
  8153. }
  8154. type ResultThree struct {
  8155. Cainfo interface{} `json:"cainfo"`
  8156. ErrMsg interface{} `json:"err_msg"`
  8157. InfRefmsgid string `json:"inf_refmsgid"`
  8158. Infcode int64 `json:"infcode"`
  8159. Output struct {
  8160. Data struct {
  8161. IptOtpNo string `json:"ipt_otp_no"`
  8162. MdtrtID string `json:"mdtrt_id"`
  8163. PsnNo string `json:"psn_no"`
  8164. } `json:"data"`
  8165. } `json:"output"`
  8166. RefmsgTime string `json:"refmsg_time"`
  8167. RespondTime string `json:"respond_time"`
  8168. Signtype interface{} `json:"signtype"`
  8169. WarnMsg interface{} `json:"warn_msg"`
  8170. }
  8171. type ResultFour struct {
  8172. Cainfo string `json:"cainfo"`
  8173. ErrMsg string `json:"err_msg"`
  8174. InfRefmsgid string `json:"inf_refmsgid"`
  8175. Infcode int64 `json:"infcode"`
  8176. Output struct {
  8177. Result []struct {
  8178. BasMednFlag string `json:"bas_medn_flag"`
  8179. ChldMedcFlag string `json:"chld_medc_flag"`
  8180. ChrgitmLv string `json:"chrgitm_lv"`
  8181. Cnt float64 `json:"cnt"`
  8182. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8183. DrtReimFlag string `json:"drt_reim_flag"`
  8184. FeedetlSn string `json:"feedetl_sn"`
  8185. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8186. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8187. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8188. ListSpItemFlag string `json:"list_sp_item_flag"`
  8189. LmtUsedFlag string `json:"lmt_used_flag"`
  8190. MedChrgitmType string `json:"med_chrgitm_type"`
  8191. Memo string `json:"memo"`
  8192. OverlmtAmt float64 `json:"overlmt_amt"`
  8193. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8194. Pric float64 `json:"pric"`
  8195. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8196. SelfpayProp float64 `json:"selfpay_prop"`
  8197. } `json:"result"`
  8198. } `json:"output"`
  8199. RefmsgTime string `json:"refmsg_time"`
  8200. RespondTime string `json:"respond_time"`
  8201. Signtype string `json:"signtype"`
  8202. WarnMsg string `json:"warn_msg"`
  8203. }
  8204. type ResultFive struct {
  8205. Insutype string `json:"insutype"`
  8206. }
  8207. type ResultSix struct {
  8208. Cainfo interface{} `json:"cainfo"`
  8209. ErrMsg interface{} `json:"err_msg"`
  8210. InfRefmsgid string `json:"inf_refmsgid"`
  8211. Infcode int64 `json:"infcode"`
  8212. Output struct {
  8213. } `json:"output"`
  8214. RefmsgTime string `json:"refmsg_time"`
  8215. RespondTime string `json:"respond_time"`
  8216. Signtype interface{} `json:"signtype"`
  8217. WarnMsg interface{} `json:"warn_msg"`
  8218. }
  8219. type ResultSeven struct {
  8220. Cainfo string `json:"cainfo"`
  8221. ErrMsg string `json:"err_msg"`
  8222. InfRefmsgid string `json:"inf_refmsgid"`
  8223. Infcode int64 `json:"infcode"`
  8224. Output struct {
  8225. Setldetail []interface{} `json:"setldetail"`
  8226. Setlinfo struct {
  8227. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8228. AcctPay float64 `json:"acct_pay"`
  8229. ActPayDedc float64 `json:"act_pay_dedc"`
  8230. Age float64 `json:"age"`
  8231. Balc float64 `json:"balc"`
  8232. Brdy string `json:"brdy"`
  8233. Certno string `json:"certno"`
  8234. ClrOptins string `json:"clr_optins"`
  8235. ClrType string `json:"clr_type"`
  8236. ClrWay string `json:"clr_way"`
  8237. CvlservFlag string `json:"cvlserv_flag"`
  8238. CvlservPay float64 `json:"cvlserv_pay"`
  8239. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8240. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8241. Gend string `json:"gend"`
  8242. HifesPay float64 `json:"hifes_pay"`
  8243. HifmiPay float64 `json:"hifmi_pay"`
  8244. HifobPay float64 `json:"hifob_pay"`
  8245. HifpPay float64 `json:"hifp_pay"`
  8246. HospPartAmt float64 `json:"hosp_part_amt"`
  8247. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8248. Insutype string `json:"insutype"`
  8249. MafPay float64 `json:"maf_pay"`
  8250. MdtrtCertType string `json:"mdtrt_cert_type"`
  8251. MdtrtID string `json:"mdtrt_id"`
  8252. MedType string `json:"med_type"`
  8253. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8254. MedinsSetlID string `json:"medins_setl_id"`
  8255. Naty string `json:"naty"`
  8256. OthPay float64 `json:"oth_pay"`
  8257. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8258. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8259. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8260. PsnCashPay float64 `json:"psn_cash_pay"`
  8261. PsnCertType string `json:"psn_cert_type"`
  8262. PsnName string `json:"psn_name"`
  8263. PsnNo string `json:"psn_no"`
  8264. PsnPartAmt float64 `json:"psn_part_amt"`
  8265. PsnType string `json:"psn_type"`
  8266. SetlID string `json:"setl_id"`
  8267. SetlTime string `json:"setl_time"`
  8268. } `json:"setlinfo"`
  8269. } `json:"output"`
  8270. RefmsgTime string `json:"refmsg_time"`
  8271. RespondTime string `json:"respond_time"`
  8272. Signtype interface{} `json:"signtype"`
  8273. WarnMsg interface{} `json:"warn_msg"`
  8274. }
  8275. type ResultEight struct {
  8276. Cainfo string `json:"cainfo"`
  8277. ErrMsg string `json:"err_msg"`
  8278. InfRefmsgid string `json:"inf_refmsgid"`
  8279. Infcode int64 `json:"infcode"`
  8280. Output struct {
  8281. Stmtinfo struct {
  8282. SetlOptins string `json:"setl_optins"`
  8283. StmtRslt string `json:"stmt_rslt"`
  8284. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8285. } `json:"stmtinfo"`
  8286. } `json:"output"`
  8287. RefmsgTime string `json:"refmsg_time"`
  8288. RespondTime string `json:"respond_time"`
  8289. Signtype interface{} `json:"signtype"`
  8290. WarnMsg interface{} `json:"warn_msg"`
  8291. }
  8292. type ResultNine struct {
  8293. Cainfo string `json:"cainfo"`
  8294. ErrMsg string `json:"err_msg"`
  8295. InfRefmsgid string `json:"inf_refmsgid"`
  8296. Infcode int64 `json:"infcode"`
  8297. Output struct {
  8298. FileQuryNo string `json:"file_qury_no"`
  8299. } `json:"output"`
  8300. RefmsgTime string `json:"refmsg_time"`
  8301. RespondTime string `json:"respond_time"`
  8302. Signtype interface{} `json:"signtype"`
  8303. WarnMsg interface{} `json:"warn_msg"`
  8304. }
  8305. type ResultTen struct {
  8306. Cainfo string `json:"cainfo"`
  8307. ErrMsg string `json:"err_msg"`
  8308. InfRefmsgid string `json:"inf_refmsgid"`
  8309. Infcode int64 `json:"infcode"`
  8310. Output struct {
  8311. DldEndtime string `json:"dld_endtime"`
  8312. FileQuryNo string `json:"file_qury_no"`
  8313. Filename string `json:"filename"`
  8314. } `json:"output"`
  8315. RefmsgTime string `json:"refmsg_time"`
  8316. RespondTime string `json:"respond_time"`
  8317. Signtype interface{} `json:"signtype"`
  8318. WarnMsg interface{} `json:"warn_msg"`
  8319. }
  8320. type ResultEleven struct {
  8321. Cainfo string `json:"cainfo"`
  8322. ErrMsg string `json:"err_msg"`
  8323. InfRefmsgid string `json:"inf_refmsgid"`
  8324. Infcode int64 `json:"infcode"`
  8325. Output struct {
  8326. Setlinfo struct {
  8327. FixmedinsName string `json:"fixmedins_name"`
  8328. FixmedinsCode string `json:"fixmedins_code"`
  8329. PsnNo string `json:"psn_no"`
  8330. PsnName string `json:"psn_name"`
  8331. HifobPay float64 `json:"hifob_pay"`
  8332. Gend string `json:"gend"`
  8333. Brdy string `json:"brdy"`
  8334. PsnCertType string `json:"psn_cert_type"`
  8335. PsnType string `json:"psn_type"`
  8336. EmpName string `json:"emp_name"`
  8337. Certno string `json:"certno"`
  8338. Insutype string `json:"insutype"`
  8339. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8340. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8341. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8342. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8343. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8344. ActPayDedc float64 `json:"act_pay_dedc"`
  8345. HifpPay float64 `json:"hifp_pay"`
  8346. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8347. CvlservPay float64 `json:"cvlserv_pay"`
  8348. HifesPay float64 `json:"hifes_pay"`
  8349. HifmiPay float64 `json:"hifmi_pay"`
  8350. MafPay float64 `json:"maf_pay"`
  8351. OthPay float64 `json:"oth_pay"`
  8352. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8353. PsnPay float64 `json:"psn_pay"`
  8354. AcctPay float64 `json:"acct_pay"`
  8355. CashPayamt float64 `json:"cash_payamt"`
  8356. Balc float64 `json:"balc"`
  8357. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8358. MedinsSetlId string `json:"medins_setl_id"`
  8359. RefdSetlFlag string `json:"refd_setl_flag"`
  8360. SetlTime string `json:"setl_time"`
  8361. MedType string `json:"med_type"`
  8362. } `json:"setlinfo"`
  8363. } `json:"output"`
  8364. RefmsgTime string `json:"refmsg_time"`
  8365. RespondTime string `json:"respond_time"`
  8366. Signtype interface{} `json:"signtype"`
  8367. WarnMsg interface{} `json:"warn_msg"`
  8368. }
  8369. type Custom struct {
  8370. DetItemFeeSumamt string
  8371. Cut string
  8372. FeedetlSn string
  8373. Price string
  8374. MedListCodg string
  8375. Type int64
  8376. AdviceId int64
  8377. ProjectId int64
  8378. ItemId int64
  8379. CostType int64
  8380. }
  8381. // 获取个人信息----挂号-----上传就诊信息
  8382. func (c *HisApiController) GetRegisterInfo() {
  8383. id, _ := c.GetInt64("id")
  8384. record_time := c.GetString("record_time")
  8385. settlementValue, _ := c.GetInt64("settlement_value")
  8386. medical_insurance_card := c.GetString("medical_insurance_card")
  8387. name := c.GetString("name")
  8388. id_card_type, _ := c.GetInt64("id_card_type")
  8389. certificates, _ := c.GetInt64("certificates")
  8390. medical_care, _ := c.GetInt64("medical_care")
  8391. birthday := c.GetString("birthday")
  8392. age, _ := c.GetInt64("age")
  8393. id_card := c.GetString("id_card")
  8394. register_type, _ := c.GetInt64("register")
  8395. doctor, _ := c.GetInt64("doctor")
  8396. department, _ := c.GetInt64("department")
  8397. gender, _ := c.GetInt64("sex")
  8398. phone := c.GetString("phone")
  8399. registration_fee, _ := c.GetFloat("registration_fee")
  8400. medical_expenses, _ := c.GetFloat("medical_expenses")
  8401. social_type, _ := c.GetInt64("social_type")
  8402. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8403. diagnosis_ids := c.GetString("diagnosis")
  8404. sick_type, _ := c.GetInt64("sick_type")
  8405. reg_type := c.GetString("p_type")
  8406. timeLayout := "2006-01-02"
  8407. loc, _ := time.LoadLocation("Local")
  8408. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8409. birthUnix := birthdays.Unix()
  8410. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8411. if err != nil {
  8412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8413. return
  8414. }
  8415. recordDateTime := theTime.Unix()
  8416. adminInfo := c.GetAdminUserInfo()
  8417. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8418. if tempPatient.ID == 0 {
  8419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8420. return
  8421. }
  8422. var patient service.Patients
  8423. if id == 0 {
  8424. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8425. } else {
  8426. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8427. }
  8428. if patient.ID == 0 {
  8429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8430. return
  8431. }
  8432. if len(patient.IdCardNo) == 0 {
  8433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8434. return
  8435. }
  8436. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8437. if len(his) >= 1 {
  8438. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8439. if len(his) >= 1 && order.ID == 0 {
  8440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8441. return
  8442. }
  8443. }
  8444. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8445. fmt.Println(timeStr)
  8446. timeArr := strings.Split(timeStr, " ")
  8447. fmt.Println(timeArr)
  8448. timeArrTwo := strings.Split(timeArr[0], "-")
  8449. timeArrThree := strings.Split(timeArr[1], ":")
  8450. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8451. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8452. if len(lists) == 0 {
  8453. var hisPatient models.XtHisPatient
  8454. hisPatient = models.XtHisPatient{
  8455. Name: name,
  8456. Age: age,
  8457. Gender: gender,
  8458. Birthday: birthUnix,
  8459. Phone: phone,
  8460. MedicalTreatmentType: medical_care,
  8461. IdType: certificates,
  8462. IdCardNo: id_card,
  8463. BalanceAccountsType: settlementValue,
  8464. SocialType: social_type,
  8465. MedicalInsuranceNumber: medical_insurance_card,
  8466. RegisterType: register_type,
  8467. RegisterCost: registration_fee,
  8468. TreatmentCost: medical_expenses,
  8469. AdminUserId: adminInfo.AdminUser.Id,
  8470. UserOrgId: adminInfo.CurrentOrgId,
  8471. Status: 1,
  8472. RecordDate: recordDateTime,
  8473. IsReturn: 1,
  8474. PatientId: patient.ID,
  8475. Ctime: time.Now().Unix(),
  8476. Mtime: time.Now().Unix(),
  8477. Number: str,
  8478. IdCardType: id_card_type,
  8479. Departments: department,
  8480. Doctor: doctor,
  8481. PType: reg_type,
  8482. Diagnosis: diagnosis_ids,
  8483. SickType: sick_type,
  8484. }
  8485. service.CreateHisPatient(&hisPatient)
  8486. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8487. c.ServeSuccessJSON(map[string]interface{}{
  8488. "his_info": hisPatient,
  8489. })
  8490. } else {
  8491. //chrgBchno := rand.Intn(1000000) + 10000
  8492. var hisPatient models.XtHisPatient
  8493. hisPatient = models.XtHisPatient{
  8494. Name: name,
  8495. Age: age,
  8496. Gender: gender,
  8497. Birthday: birthUnix,
  8498. Phone: phone,
  8499. MedicalTreatmentType: medical_care,
  8500. IdType: certificates,
  8501. IdCardNo: id_card,
  8502. BalanceAccountsType: settlementValue,
  8503. SocialType: social_type,
  8504. MedicalInsuranceNumber: medical_insurance_card,
  8505. RegisterType: register_type,
  8506. RegisterCost: registration_fee,
  8507. TreatmentCost: medical_expenses,
  8508. AdminUserId: adminInfo.AdminUser.Id,
  8509. UserOrgId: adminInfo.CurrentOrgId,
  8510. Status: 1,
  8511. RecordDate: recordDateTime,
  8512. IsReturn: 1,
  8513. PatientId: patient.ID,
  8514. Ctime: time.Now().Unix(),
  8515. Mtime: time.Now().Unix(),
  8516. Number: str,
  8517. IdCardType: id_card_type,
  8518. Departments: department,
  8519. Doctor: doctor,
  8520. PType: reg_type,
  8521. Diagnosis: diagnosis_ids,
  8522. SickType: sick_type,
  8523. }
  8524. service.CreateHisPatient(&hisPatient)
  8525. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8526. c.ServeSuccessJSON(map[string]interface{}{
  8527. "his_info": hisPatient,
  8528. })
  8529. }
  8530. }
  8531. // 上传明细----结算
  8532. func (c *HisApiController) GetUploadInfo() {
  8533. id, _ := c.GetInt64("id")
  8534. record_time := c.GetString("record_time")
  8535. his_patient_id, _ := c.GetInt64("his_patient_id")
  8536. oth_desc := c.GetString("oth_desc")
  8537. pay_way, _ := c.GetInt64("pay_way")
  8538. pay_ways := c.GetString("pay_ways")
  8539. pay_price, _ := c.GetFloat("pay_price")
  8540. pay_card_no := c.GetString("pay_card_no")
  8541. discount_price, _ := c.GetFloat("discount_price")
  8542. preferential_price, _ := c.GetFloat("preferential_price")
  8543. reality_price, _ := c.GetFloat("reality_price")
  8544. found_price, _ := c.GetFloat("found_price")
  8545. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8546. private_price, _ := c.GetFloat("private_price")
  8547. timeLayout := "2006-01-02"
  8548. loc, _ := time.LoadLocation("Local")
  8549. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8550. fapiao_code := c.GetString("fapiao_code")
  8551. fapiao_number := c.GetString("fapiao_number")
  8552. diagnosis_id := c.GetString("diagnosis")
  8553. sick_type, _ := c.GetInt64("sick_type")
  8554. reg_type, _ := c.GetInt64("p_type")
  8555. order_id, _ := c.GetInt64("order_id")
  8556. cash_pay := c.GetString("cash_pay")
  8557. wechat_pay := c.GetString("wechat_pay")
  8558. ali_pay := c.GetString("ali_pay")
  8559. jifen_pay := c.GetString("jifen_pay")
  8560. band_card_pay := c.GetString("band_card_pay")
  8561. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8562. tmp_decimal := c.GetString("tmp_decimal")
  8563. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8564. var decimal float64 //本次使用的押金
  8565. var errmsg error
  8566. tx := service.XTWriteDB().Begin() //开了事务
  8567. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8568. defer func() {
  8569. if errmsg != nil {
  8570. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8571. tx.Rollback()
  8572. } else {
  8573. tx.Commit()
  8574. }
  8575. }()
  8576. fmt.Println("dec_way", dec_way)
  8577. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8578. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8579. return
  8580. }
  8581. if len(tmp_decimal) > 0 {
  8582. if tmp_decimal[0] == 45 {
  8583. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8584. return
  8585. }
  8586. }
  8587. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8588. fmt.Println(errs)
  8589. decimal = tt
  8590. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8591. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8593. if err != nil {
  8594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8595. return
  8596. }
  8597. recordDateTime := theTime.Unix()
  8598. adminUser := c.GetAdminUserInfo()
  8599. var prescriptions []*models.HisPrescription
  8600. var prescriptionsOne []*models.HisPrescription
  8601. var start_time int64
  8602. var end_time int64
  8603. ids_str := c.GetString("ids")
  8604. ids_arr := strings.Split(ids_str, ",")
  8605. if tempOrder.ID == 0 {
  8606. if settle_accounts_type == 1 { //日结
  8607. fmt.Println(reg_type)
  8608. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8609. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8610. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8611. } else {
  8612. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8613. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8614. }
  8615. } else { //月结
  8616. start_time_str := c.GetString("start_time")
  8617. end_time_str := c.GetString("end_time")
  8618. timeLayout := "2006-01-02"
  8619. loc, _ := time.LoadLocation("Local")
  8620. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8621. if err != nil {
  8622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8623. return
  8624. }
  8625. recordStartTime := theStartTime.Unix()
  8626. start_time = recordStartTime
  8627. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8628. if err != nil {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8630. return
  8631. }
  8632. recordEndTime := theEndTime.Unix()
  8633. end_time = recordEndTime
  8634. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8635. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8636. }
  8637. var goods []*models.DialysisBeforePrepareGoods
  8638. var newGoods []*models.NewDialysisBeforePrepareGoods
  8639. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8640. var infos []*models.HisDoctorAdviceInfo
  8641. var infoList []*models.HisDoctorAdviceInfo
  8642. var hisAdvice []*models.HisDoctorAdviceInfo
  8643. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8644. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8645. //判断库存不足
  8646. //结算出库开关
  8647. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8648. if settConfig.IsOpen == 1 {
  8649. //判断库存的地方
  8650. for _, info := range prescriptions {
  8651. if info.Type == 1 {
  8652. infos = append(infos, info.HisDoctorAdviceInfo...)
  8653. }
  8654. if info.Type == 2 {
  8655. for _, sumItem := range info.HisPrescriptionProject {
  8656. if sumItem.Type == 3 {
  8657. var good models.DialysisBeforePrepareGoods
  8658. var newGood models.NewDialysisBeforePrepareGoods
  8659. good.GoodId = sumItem.GoodInfo.ID
  8660. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8661. count, _ := strconv.Atoi(sumItem.Count)
  8662. good.Count = int64(count)
  8663. good.StorehouseId = houseConfig.StorehouseOutInfo
  8664. good.ProjectId = sumItem.ID
  8665. goods = append(goods, &good)
  8666. newGood.GoodId = sumItem.GoodInfo.ID
  8667. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8668. count2, _ := strconv.Atoi(sumItem.Count)
  8669. newGood.Count = int64(count2)
  8670. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8671. newGood.ProjectId = sumItem.ID
  8672. newGoods = append(newGoods, &newGood)
  8673. }
  8674. }
  8675. }
  8676. }
  8677. for _, info := range prescriptionsOne {
  8678. if info.Type == 1 {
  8679. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8680. }
  8681. if info.Type == 2 {
  8682. for _, sumItem := range info.HisPrescriptionProject {
  8683. if sumItem.Type == 3 {
  8684. var newGood models.NewDialysisBeforePrepareGoods
  8685. newGood.GoodId = sumItem.GoodInfo.ID
  8686. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8687. count2, _ := strconv.Atoi(sumItem.Count)
  8688. newGood.Count = int64(count2)
  8689. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8690. newGood.ProjectId = sumItem.ID
  8691. newGoodOne = append(newGoodOne, &newGood)
  8692. }
  8693. }
  8694. }
  8695. }
  8696. //判断
  8697. for _, itemOne := range infos {
  8698. for _, itemTwo := range hisAdvice {
  8699. if itemOne.DrugId == itemTwo.DrugId {
  8700. itemTwo.Child = append(itemTwo.Child, itemOne)
  8701. }
  8702. }
  8703. }
  8704. for _, itemTwo := range hisAdvice {
  8705. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8706. var sum_out_count int64
  8707. for _, itemThree := range itemTwo.Child {
  8708. var prescribing_number int64
  8709. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8710. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8711. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8712. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8713. }
  8714. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8715. prescribing_number = parseIntPrescribingNumber
  8716. }
  8717. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8718. prescribing_number = parseIntPrescribingNumber
  8719. }
  8720. sum_out_count += prescribing_number
  8721. }
  8722. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8723. if sum_out_count > drugStockOut.FlushCount {
  8724. c.ServeSuccessJSON(map[string]interface{}{
  8725. "msg": "2",
  8726. "drug": medical,
  8727. })
  8728. return
  8729. }
  8730. }
  8731. for _, itemOne := range newGoods {
  8732. for _, item := range newGoodOne {
  8733. if itemOne.GoodId == item.GoodId {
  8734. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8735. }
  8736. }
  8737. }
  8738. for _, item := range newGoodOne {
  8739. var sum_out_count_one int64
  8740. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8741. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8742. sum_out_count_one += itemOne.Count
  8743. }
  8744. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8745. fmt.Println("sum_out_count_one", sum_out_count_one)
  8746. fmt.Println("list.FlushCount", list.FlushCount)
  8747. if sum_out_count_one > list.FlushCount {
  8748. c.ServeSuccessJSON(map[string]interface{}{
  8749. "msg": "3",
  8750. "good": good,
  8751. })
  8752. return
  8753. }
  8754. }
  8755. }
  8756. timestamp := time.Now().Unix()
  8757. tempTime := time.Unix(timestamp, 0)
  8758. timeFormat := tempTime.Format("20060102150405")
  8759. chrgBchno := rand.Intn(100000) + 10000
  8760. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8761. strconv.FormatInt(his.PatientId, 10)
  8762. var ids []int64
  8763. for _, item := range prescriptions {
  8764. ids = append(ids, item.ID)
  8765. }
  8766. var total float64
  8767. for _, item := range prescriptions {
  8768. fmt.Println(item)
  8769. if item.Type == 1 { //药品
  8770. for _, subItem := range item.HisDoctorAdviceInfo {
  8771. total = total + (subItem.Price * subItem.PrescribingNumber)
  8772. }
  8773. }
  8774. if item.Type == 2 { //项目
  8775. for _, subItem := range item.HisPrescriptionProject {
  8776. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8777. total = total + (subItem.Price * cnt)
  8778. }
  8779. }
  8780. for _, subItem := range item.HisAdditionalCharge {
  8781. total = total + (subItem.Price * float64(subItem.Count))
  8782. }
  8783. }
  8784. if reg_type == 1111 || reg_type == 1112 {
  8785. reg_type = 11
  8786. }
  8787. tm := time.Unix(time.Now().Unix(), 0)
  8788. allTotal := fmt.Sprintf("%.4f", total)
  8789. totals, _ := strconv.ParseFloat(allTotal, 64)
  8790. order := &models.HisOrder{
  8791. UserOrgId: adminUser.CurrentOrgId,
  8792. HisPatientId: his.ID,
  8793. PatientId: id,
  8794. SettleAccountsDate: recordDateTime,
  8795. Ctime: time.Now().Unix(),
  8796. Mtime: time.Now().Unix(),
  8797. Status: 1,
  8798. OrderStatus: 2,
  8799. MdtrtId: his.Number,
  8800. Number: chrg_bchno,
  8801. MedfeeSumamt: totals,
  8802. PayWay: pay_way,
  8803. PayWays: pay_ways,
  8804. PayPrice: pay_price,
  8805. MedType: strconv.Itoa(int(reg_type)),
  8806. PayCardNo: pay_card_no,
  8807. DiscountPrice: discount_price,
  8808. PreferentialPrice: preferential_price,
  8809. RealityPrice: reality_price,
  8810. FoundPrice: found_price,
  8811. MedicalInsurancePrice: medical_insurance_price,
  8812. PrivatePrice: private_price,
  8813. SettleEndTime: end_time,
  8814. SettleStartTime: start_time,
  8815. PsnPartAmt: totals,
  8816. PsnCashPay: totals,
  8817. SettleType: settle_accounts_type,
  8818. FaPiaoCode: fapiao_code,
  8819. FaPiaoNumber: fapiao_number,
  8820. Diagnosis: diagnosis_id,
  8821. PType: 2,
  8822. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8823. Decimal: decimal,
  8824. OthDesc: oth_desc,
  8825. CashPay: cash_pay,
  8826. WechatPay: wechat_pay,
  8827. AliPay: ali_pay,
  8828. JifenPay: jifen_pay,
  8829. BandCardPay: band_card_pay,
  8830. Creator: adminUser.AdminUser.Id,
  8831. }
  8832. err = service.CreateOrderTX(order, tx)
  8833. if err != nil {
  8834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8835. return
  8836. }
  8837. var customs []*Custom
  8838. for _, item := range prescriptions {
  8839. if item.Type == 1 { //药品a
  8840. for _, subItem := range item.HisDoctorAdviceInfo {
  8841. cus := &Custom{
  8842. AdviceId: subItem.ID,
  8843. ProjectId: 0,
  8844. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8845. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8846. FeedetlSn: subItem.FeedetlSn,
  8847. Price: fmt.Sprintf("%.4f", subItem.Price),
  8848. MedListCodg: subItem.MedListCodg,
  8849. Type: 1,
  8850. CostType: 9,
  8851. }
  8852. customs = append(customs, cus)
  8853. }
  8854. }
  8855. if item.Type == 2 { //项目
  8856. for _, subItem := range item.HisPrescriptionProject {
  8857. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8858. cus := &Custom{
  8859. AdviceId: 0,
  8860. ProjectId: subItem.ID,
  8861. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8862. Cut: fmt.Sprintf("%.4f", cnt),
  8863. FeedetlSn: subItem.FeedetlSn,
  8864. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8865. MedListCodg: subItem.MedListCodg,
  8866. Type: 2,
  8867. CostType: subItem.HisProject.CostClassify,
  8868. }
  8869. customs = append(customs, cus)
  8870. }
  8871. }
  8872. for _, item := range item.HisAdditionalCharge {
  8873. cus := &Custom{
  8874. ItemId: item.ID,
  8875. AdviceId: 0,
  8876. ProjectId: 0,
  8877. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8878. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8879. FeedetlSn: item.FeedetlSn,
  8880. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8881. MedListCodg: item.XtHisAddtionConfig.Code,
  8882. Type: 3,
  8883. CostType: 5,
  8884. }
  8885. customs = append(customs, cus)
  8886. }
  8887. }
  8888. for _, item := range customs {
  8889. var advice_id int64 = 0
  8890. var project_id int64 = 0
  8891. var item_id int64 = 0
  8892. var types int64 = 0
  8893. var med_chrgitm_type string
  8894. if item.Type == 1 {
  8895. advice_id = item.AdviceId
  8896. project_id = 0
  8897. item_id = 0
  8898. med_chrgitm_type = "09"
  8899. } else if item.Type == 2 {
  8900. med_chrgitm_type = "05"
  8901. if item.CostType == 3 {
  8902. med_chrgitm_type = "04"
  8903. }
  8904. if item.CostType == 8 {
  8905. med_chrgitm_type = "03"
  8906. }
  8907. advice_id = 0
  8908. item_id = 0
  8909. project_id = item.ProjectId
  8910. } else if item.Type == 3 {
  8911. advice_id = 0
  8912. item_id = item.ItemId
  8913. project_id = 0
  8914. med_chrgitm_type = "08"
  8915. }
  8916. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8917. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8918. pric, _ := strconv.ParseFloat(item.Price, 32)
  8919. info := &models.HisOrderInfo{
  8920. OrderNumber: order.Number,
  8921. UploadDate: time.Now().Unix(),
  8922. AdviceId: advice_id,
  8923. DetItemFeeSumamt: detItemFeeSumamt,
  8924. MedChrgitmType: med_chrgitm_type,
  8925. Cnt: cut,
  8926. Pric: pric,
  8927. PatientId: id,
  8928. Status: 1,
  8929. Mtime: time.Now().Unix(),
  8930. Ctime: time.Now().Unix(),
  8931. UserOrgId: adminUser.CurrentOrgId,
  8932. HisPatientId: his.ID,
  8933. OrderId: order.ID,
  8934. ProjectId: project_id,
  8935. Type: types,
  8936. ItemId: item_id,
  8937. }
  8938. service.CreateOrderInfoTX(info, tx)
  8939. }
  8940. his.Diagnosis = diagnosis_id
  8941. his.SickType = sick_type
  8942. his.RegisterType = reg_type
  8943. his.MedicalTreatmentType = reg_type
  8944. service.UpdataHisPateintTX(&his, tx)
  8945. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8946. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8947. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8948. //判断是否使用了押金
  8949. if dec_way == "true" {
  8950. tmpstring := strconv.FormatInt(order.ID, 10)
  8951. //扣押金
  8952. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8953. order.Decimal = decimal
  8954. service.UpDateOrderTwo(order, tx)
  8955. if errmsg != nil {
  8956. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8957. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8958. return
  8959. }
  8960. }
  8961. if err == nil {
  8962. for _, info := range prescriptions {
  8963. if info.Type == 1 {
  8964. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8965. }
  8966. if info.Type == 2 {
  8967. for _, sumItem := range info.HisPrescriptionProject {
  8968. if sumItem.Type == 3 {
  8969. var good models.DialysisBeforePrepareGoods
  8970. var newGood models.NewDialysisBeforePrepareGoods
  8971. var oldGood models.OldDialysisBeforePrepareGoods
  8972. good.GoodId = sumItem.GoodInfo.ID
  8973. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8974. count, _ := strconv.Atoi(sumItem.Count)
  8975. good.Count = int64(count)
  8976. good.StorehouseId = houseConfig.StorehouseOutInfo
  8977. good.ProjectId = sumItem.ID
  8978. good.PatientId = sumItem.PatientId
  8979. goods = append(goods, &good)
  8980. newGood.GoodId = sumItem.GoodInfo.ID
  8981. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8982. count2, _ := strconv.Atoi(sumItem.Count)
  8983. newGood.Count = int64(count2)
  8984. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8985. newGood.ProjectId = sumItem.ID
  8986. newGood.PatientId = sumItem.HisPatientId
  8987. newGoods = append(newGoods, &newGood)
  8988. oldGood.GoodId = sumItem.GoodInfo.ID
  8989. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8990. count3, _ := strconv.Atoi(sumItem.Count)
  8991. oldGood.Count = int64(count3)
  8992. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8993. oldGood.ProjectId = sumItem.ID
  8994. oldGood.RecordDate = sumItem.RecordDate
  8995. oldGood.PatientId = sumItem.HisPatientId
  8996. oldGoods = append(oldGoods, &oldGood)
  8997. }
  8998. }
  8999. }
  9000. }
  9001. if settConfig.IsOpen == 1 {
  9002. for _, item := range infoList {
  9003. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9004. if medical.IsUse == 2 {
  9005. //药品出库
  9006. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9007. //查询默认仓库
  9008. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9009. //查询默认仓库剩余多少库存
  9010. var sum_count int64
  9011. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9012. for _, its := range stockInfo {
  9013. if its.MaxUnit == medical.MaxUnit {
  9014. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9015. }
  9016. sum_count += its.StockMaxNumber + its.StockMinNumber
  9017. }
  9018. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9019. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9020. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9021. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9022. }
  9023. }
  9024. orgId := c.GetAdminUserInfo().CurrentOrgId
  9025. if len(oldGoods) > 0 {
  9026. timeStr := time.Now().Format("2006-01-02")
  9027. timeArr := strings.Split(timeStr, "-")
  9028. total, _ := service.FindAllWarehouseOut(orgId)
  9029. total = total + 1
  9030. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9031. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9032. number = number + total
  9033. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9034. operation_time := time.Now().Unix()
  9035. creater := c.GetAdminUserInfo().AdminUser.Id
  9036. //查询默认出库仓库库存
  9037. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9038. recordDateStr := time.Now().Format("2006-01-02")
  9039. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9040. nowtime := recordDate.Unix()
  9041. warehouseOut := models.WarehouseOut{
  9042. WarehouseOutOrderNumber: warehousing_out_order,
  9043. OperationTime: operation_time,
  9044. OrgId: orgId,
  9045. Creater: creater,
  9046. Ctime: time.Now().Unix(),
  9047. Status: 1,
  9048. WarehouseOutTime: nowtime,
  9049. Type: 1,
  9050. StorehouseId: storeConfig.StorehouseOutInfo,
  9051. IsCheck: 1,
  9052. OrderId: order.ID,
  9053. IsSys: 5,
  9054. }
  9055. //查询是否生成出库单
  9056. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9057. if out.ID == 0 {
  9058. service.AddSigleWarehouseOut(&warehouseOut)
  9059. }
  9060. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9061. for _, item := range oldGoods {
  9062. dialyPrepareOne := models.DialysisBeforePrepare{
  9063. GoodTypeId: item.GoodTypeId,
  9064. GoodId: item.GoodId,
  9065. PatientId: his.PatientId,
  9066. RecordDate: item.RecordDate,
  9067. UserOrgId: adminUser.CurrentOrgId,
  9068. Count: item.Count,
  9069. Ctime: time.Now().Unix(),
  9070. Creater: adminUser.AdminUser.Id,
  9071. CommdityCode: item.CommdityCode,
  9072. Status: 1,
  9073. StorehouseId: houseConfig.StorehouseOutInfo,
  9074. }
  9075. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9076. //非零用
  9077. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9078. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9079. //查询剩余库存
  9080. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9081. var sum_count int64
  9082. for _, item := range goodList {
  9083. sum_count += item.StockCount
  9084. }
  9085. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9086. //耗材
  9087. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9088. }
  9089. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9090. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9091. //查询剩余库存
  9092. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9093. var sum_count int64
  9094. for _, item := range goodList {
  9095. sum_count += item.StockCount
  9096. }
  9097. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9098. //耗材
  9099. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9100. }
  9101. }
  9102. }
  9103. }
  9104. c.ServeSuccessJSON(map[string]interface{}{
  9105. "msg": "结算成功",
  9106. })
  9107. }
  9108. }
  9109. }
  9110. // 退款
  9111. func (c *HisApiController) Refund() {
  9112. order_id, _ := c.GetInt64("order_id")
  9113. order, _ := service.GetHisOrderByID(order_id)
  9114. adminUser := c.GetAdminUserInfo()
  9115. orgid := c.GetAdminUserInfo().CurrentOrgId
  9116. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9117. if err != nil {
  9118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9119. return
  9120. }
  9121. tmp := strconv.FormatInt(order.ID, 10)
  9122. //当押金不为零时产生退费记录
  9123. if order.Decimal != 0 {
  9124. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9125. if err != nil {
  9126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9127. return
  9128. }
  9129. }
  9130. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9131. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9132. var goods []*models.DialysisBeforePrepareGoods
  9133. var newGoods []*models.NewDialysisBeforePrepareGoods
  9134. var infos []*models.HisDoctorAdviceInfo
  9135. for _, info := range orders {
  9136. if info.AdviceId > 0 && info.ProjectId == 0 {
  9137. infos = append(infos, &info.HisDoctorAdviceInfo)
  9138. }
  9139. if info.ProjectId > 0 && info.AdviceId == 0 {
  9140. if info.HisPrescriptionProject.Type == 3 {
  9141. var good models.DialysisBeforePrepareGoods
  9142. var newGood models.NewDialysisBeforePrepareGoods
  9143. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9144. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9145. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9146. good.Count = int64(count)
  9147. good.StorehouseId = houseConfig.StorehouseOutInfo
  9148. good.ProjectId = info.HisPrescriptionProject.ID
  9149. good.PatientId = info.PatientId
  9150. good.OrderId = order_id
  9151. goods = append(goods, &good)
  9152. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9153. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9154. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9155. newGood.Count = int64(count2)
  9156. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9157. newGood.ProjectId = info.HisPrescriptionProject.ID
  9158. newGood.RecordDate = order.SettleAccountsDate
  9159. newGood.UserOrgId = order.UserOrgId
  9160. newGood.PatientId = info.PatientId
  9161. newGood.OrderId = order_id
  9162. newGoods = append(newGoods, &newGood)
  9163. }
  9164. }
  9165. }
  9166. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9167. if settConfig.IsOpen == 1 {
  9168. for _, item := range infos {
  9169. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9170. }
  9171. for _, item := range newGoods {
  9172. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9173. }
  9174. }
  9175. c.ServeSuccessJSON(map[string]interface{}{
  9176. "msg": "退费成功",
  9177. })
  9178. }
  9179. func (c *HisApiController) RefundNumber() {
  9180. his_patient_id, _ := c.GetInt64("id")
  9181. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9182. info.Status = 0
  9183. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9184. if count > 0 {
  9185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9186. return
  9187. }
  9188. err := service.SaveHisPatient(info)
  9189. if err == nil {
  9190. c.ServeSuccessJSON(map[string]interface{}{
  9191. "msg": "退号成功",
  9192. })
  9193. } else {
  9194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9195. return
  9196. }
  9197. }
  9198. func (this *HisApiController) AdditionalCharge() {
  9199. dataBody := make(map[string]interface{}, 0)
  9200. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9201. fmt.Println(err)
  9202. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9203. patient_id := int64(dataBody["patient_id"].(float64))
  9204. medicineData, _ := dataBody["medicineData"].([]interface{})
  9205. adminUserInfo := this.GetAdminUserInfo()
  9206. orgId := adminUserInfo.CurrentOrgId
  9207. admin_user_id := adminUserInfo.AdminUser.Id
  9208. timeStr := time.Now().Format("2006-01-02")
  9209. timeLayout := "2006-01-02 15:04:05"
  9210. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9211. timenow := timeStringToTime.Unix()
  9212. var additionalCharges []*models.HisAdditionalCharge
  9213. for _, item := range medicineData {
  9214. var randNum int
  9215. randNum = rand.Intn(10000) + 1000
  9216. timestamp := time.Now().Unix()
  9217. tempTime := time.Unix(timestamp, 0)
  9218. timeFormat := tempTime.Format("20060102150405")
  9219. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9220. items := item.(map[string]interface{})
  9221. money := items["price"].(string)
  9222. item_id_str := items["item_id"].(string)
  9223. name := items["name"].(string)
  9224. id_str := items["id"].(string)
  9225. moneys, _ := strconv.ParseInt(money, 10, 64)
  9226. monStr := strconv.FormatInt(moneys, 10)
  9227. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9228. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9229. id, _ := strconv.ParseInt(id_str, 10, 64)
  9230. additionalCharge := &models.HisAdditionalCharge{
  9231. ID: id,
  9232. HisPatientId: his_patient_id,
  9233. UserOrgId: orgId,
  9234. PatientId: patient_id,
  9235. RecordDate: timenow,
  9236. Price: monneyStr,
  9237. Status: 1,
  9238. ItemName: name,
  9239. ItemId: item_id,
  9240. AdminUserId: admin_user_id,
  9241. CreatedTime: time.Now().Unix(),
  9242. OrderStatus: 0,
  9243. PrescriptionNumber: "",
  9244. BatchNumber: "",
  9245. FeedetlSn: p_number,
  9246. }
  9247. service.CreateAdditionalCharge(additionalCharge)
  9248. additionalCharges = append(additionalCharges, additionalCharge)
  9249. }
  9250. this.ServeSuccessJSON(map[string]interface{}{
  9251. "msg": "添加成功",
  9252. "additional_charges": additionalCharges,
  9253. })
  9254. }
  9255. func (this *HisApiController) DeleteAddition() {
  9256. id, _ := this.GetInt64("id")
  9257. //TODO 需要判断是否已经结算
  9258. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9259. if err == nil {
  9260. this.ServeSuccessJSON(map[string]interface{}{
  9261. "msg": "删除成功",
  9262. })
  9263. return
  9264. } else {
  9265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9266. return
  9267. }
  9268. }
  9269. func (this *HisApiController) GetAdminUsers() {
  9270. adminUser := this.GetAdminUserInfo()
  9271. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9272. this.ServeSuccessJSON(map[string]interface{}{
  9273. "doctors": doctors,
  9274. })
  9275. }
  9276. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9277. change_type, _ := this.GetInt64("type", 0)
  9278. record_date := this.GetString("record_time")
  9279. patient_id, _ := this.GetInt64("patient_id", 0)
  9280. p_type, _ := this.GetInt64("p_type", 0)
  9281. timeLayout := "2006-01-02"
  9282. loc, _ := time.LoadLocation("Local")
  9283. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9284. record_time := theAdviceRecordTime.Unix()
  9285. adminUserInfo := this.GetAdminUserInfo()
  9286. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9287. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9288. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9289. if config.ID > 0 && config.IsOpen == 1 {
  9290. for _, subitems := range prescriptions {
  9291. for _, item := range subitems.VMHisPrescription {
  9292. for _, subItem := range item.HisDoctorAdviceInfo {
  9293. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9294. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9295. if info.RetailPrice > 0 {
  9296. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9297. subItem.Drug.RetailPrice = drug.RetailPrice
  9298. }
  9299. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9300. subItem.Drug.MinPrice = info.RetailPrice
  9301. subItem.Drug.RetailPrice = info.RetailPrice
  9302. }
  9303. }
  9304. }
  9305. }
  9306. }
  9307. }
  9308. if config.ID > 0 && config.IsOpen == 1 {
  9309. for _, subitems := range prescriptions {
  9310. for _, item := range subitems.VMHisPrescription {
  9311. for _, subItem := range item.HisPrescriptionProject {
  9312. if subItem.Type == 3 {
  9313. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9314. if info.Price > 0 {
  9315. subItem.GoodInfo.PackingPrice = info.Price
  9316. }
  9317. }
  9318. }
  9319. }
  9320. }
  9321. }
  9322. }
  9323. if err == nil {
  9324. if len(prescriptions) == 0 {
  9325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9326. return
  9327. } else {
  9328. this.ServeSuccessJSON(map[string]interface{}{
  9329. "prescriptions": prescriptions,
  9330. })
  9331. return
  9332. }
  9333. } else {
  9334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9335. return
  9336. }
  9337. }
  9338. func (this *HisApiController) GetCallHisPrescription() {
  9339. patient_id, _ := this.GetInt64("patient_id", 0)
  9340. timeLayout := "2006-01-02"
  9341. loc, _ := time.LoadLocation("Local")
  9342. start_time := this.GetString("start_time")
  9343. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9344. end_time := this.GetString("end_time")
  9345. p_type, _ := this.GetInt64("p_type")
  9346. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9347. adminUserInfo := this.GetAdminUserInfo()
  9348. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9349. //if
  9350. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9351. //
  9352. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9353. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9354. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9355. if config.ID > 0 && config.IsOpen == 1 {
  9356. for _, subitems := range prescriptions {
  9357. for _, item := range subitems.VMHisPrescription {
  9358. for _, subItem := range item.HisDoctorAdviceInfo {
  9359. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9360. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9361. if info.RetailPrice > 0 {
  9362. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9363. subItem.Drug.RetailPrice = drug.RetailPrice
  9364. }
  9365. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9366. subItem.Drug.MinPrice = info.RetailPrice
  9367. subItem.Drug.RetailPrice = info.RetailPrice
  9368. }
  9369. }
  9370. }
  9371. }
  9372. }
  9373. }
  9374. if config.ID > 0 && config.IsOpen == 1 {
  9375. for _, subitems := range prescriptions {
  9376. for _, item := range subitems.VMHisPrescription {
  9377. for _, subItem := range item.HisPrescriptionProject {
  9378. if subItem.Type == 3 {
  9379. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9380. if info.Price > 0 {
  9381. subItem.GoodInfo.PackingPrice = info.Price
  9382. }
  9383. }
  9384. }
  9385. }
  9386. }
  9387. }
  9388. }
  9389. if err == nil {
  9390. this.ServeSuccessJSON(map[string]interface{}{
  9391. "prescriptions": prescriptions,
  9392. })
  9393. return
  9394. } else {
  9395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9396. return
  9397. }
  9398. }
  9399. func (this *HisApiController) GetHisDayPrescription() {
  9400. timeLayout := "2006-01-02"
  9401. loc, _ := time.LoadLocation("Local")
  9402. start_time := this.GetString("start_time")
  9403. patient_id, _ := this.GetInt64("patient_id", 0)
  9404. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9405. end_time := this.GetString("end_time")
  9406. p_type, _ := this.GetInt64("p_type")
  9407. order_status, _ := this.GetInt64("type")
  9408. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9409. adminUserInfo := this.GetAdminUserInfo()
  9410. var dayHisPrescription []*models.HisPrescription
  9411. var err error
  9412. if order_status == 1 || order_status == 0 {
  9413. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9414. } else if order_status == 2 {
  9415. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9416. }
  9417. var settle_total float64
  9418. for _, item := range dayHisPrescription {
  9419. if len(item.HisPrescriptionProject) > 0 {
  9420. for _, subItem := range item.HisPrescriptionProject {
  9421. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9422. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9423. settle_total = settle_total + total
  9424. }
  9425. }
  9426. if len(item.HisDoctorAdviceInfo) > 0 {
  9427. for _, subItem := range item.HisDoctorAdviceInfo {
  9428. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9429. settle_total = settle_total + total
  9430. }
  9431. }
  9432. }
  9433. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9434. if err == nil {
  9435. this.ServeSuccessJSON(map[string]interface{}{
  9436. "day_prescription": dayHisPrescription,
  9437. "settle_total": settle_total,
  9438. })
  9439. return
  9440. } else {
  9441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9442. return
  9443. }
  9444. }
  9445. func (c *HisApiController) GetHisChargePatientList() {
  9446. record_date := c.GetString("record_date")
  9447. order_status, _ := c.GetInt64("type")
  9448. sch_type, _ := c.GetInt64("sch_type")
  9449. timeLayout := "2006-01-02"
  9450. loc, _ := time.LoadLocation("Local")
  9451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9452. if err != nil {
  9453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9454. return
  9455. }
  9456. recordDateTime := theTime.Unix()
  9457. adminInfo := c.GetAdminUserInfo()
  9458. var tempPatients []*service.NewTempPatients
  9459. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9460. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9461. if order_status != 2 {
  9462. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9463. } else {
  9464. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9465. }
  9466. } else {
  9467. if order_status != 2 {
  9468. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9469. } else {
  9470. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9471. }
  9472. }
  9473. var patients []*service.NewTempPatients
  9474. var patients_two []*service.NewTempPatients
  9475. for _, item := range tempPatients {
  9476. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9477. //过滤掉没挂号的和没开处方的
  9478. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9479. patients = append(patients, item)
  9480. }
  9481. //过滤掉没挂号的
  9482. if len(item.HisPatient) > 0 {
  9483. patients_two = append(patients_two, item)
  9484. }
  9485. } else {
  9486. if len(item.HisPrescription) > 0 {
  9487. patients = append(patients, item)
  9488. }
  9489. }
  9490. }
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "list": patients,
  9493. "list_two": patients_two,
  9494. })
  9495. }
  9496. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9497. record_date := c.GetString("record_date")
  9498. timeLayout := "2006-01-02"
  9499. loc, _ := time.LoadLocation("Local")
  9500. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9501. if err != nil {
  9502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9503. return
  9504. }
  9505. recordDateTime := theTime.Unix()
  9506. adminUser := c.GetAdminUserInfo()
  9507. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9508. var patients []*service.Patients
  9509. for _, item := range tempPatients {
  9510. if item.HisPatient.ID == 0 {
  9511. patients = append(patients, item)
  9512. }
  9513. }
  9514. c.ServeSuccessJSON(map[string]interface{}{
  9515. "list": patients,
  9516. //"list_two": patients_two,
  9517. })
  9518. }
  9519. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9520. newArr = make([]*service.Patients, 0)
  9521. for i := 0; i < len(patient); i++ {
  9522. repeat := false
  9523. for j := i + 1; j < len(patient); j++ {
  9524. if patient[i].ID == patient[j].ID {
  9525. repeat = true
  9526. break
  9527. }
  9528. }
  9529. if !repeat {
  9530. newArr = append(newArr, patient[i])
  9531. }
  9532. }
  9533. return
  9534. }
  9535. func (c *HisApiController) GetHisChargePatientInfo() {
  9536. patient_id, _ := c.GetInt64("patient_id")
  9537. his_patient_id, _ := c.GetInt64("his_patient_id")
  9538. record_date := c.GetString("record_date")
  9539. //start_time := c.GetString("start_time")
  9540. //end_time := c.GetString("end_time")
  9541. order_status, _ := c.GetInt64("type", 0)
  9542. p_type, _ := c.GetInt64("p_type", 0)
  9543. order_id, _ := c.GetInt64("order_id", 0)
  9544. timeLayout := "2006-01-02"
  9545. loc, _ := time.LoadLocation("Local")
  9546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9547. if err != nil {
  9548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9549. return
  9550. }
  9551. recordDateTime := theTime.Unix()
  9552. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9553. //if err != nil {
  9554. //
  9555. //}
  9556. //startRecordDateTime := startTime.Unix()
  9557. //
  9558. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9559. //if err != nil {
  9560. //
  9561. //}
  9562. //endRecordDateTime := endTime.Unix()
  9563. admin := c.GetAdminUserInfo()
  9564. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9565. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9566. var prescriptions []*models.HisPrescription
  9567. //var unChargeMonthPrescriptions []*models.HisPrescription
  9568. order, _ := service.GetHisOrderByID(order_id)
  9569. if order_status == 1 || order_status == 0 {
  9570. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9571. } else if order_status == 2 {
  9572. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9573. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9574. }
  9575. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9576. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9577. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9578. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9579. //获取所有科室信息
  9580. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9581. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9582. c.ServeSuccessJSON(map[string]interface{}{
  9583. "his_info": his_patient_info,
  9584. "xt_info": xt_patient_info,
  9585. "prescription": prescriptions,
  9586. "case_history": case_history,
  9587. "info": patientPrescriptionInfo,
  9588. "last_info": lastPatientPrescriptionInfo,
  9589. "order": order,
  9590. "doctors": doctors,
  9591. "department": department,
  9592. "sch": sch,
  9593. })
  9594. return
  9595. }
  9596. func (c *HisApiController) GetAllOrderDetail() {
  9597. order_id, _ := c.GetInt64("id", 0)
  9598. order, _ := service.GetHisOrderByID(order_id)
  9599. if order.ID == 0 {
  9600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9601. return
  9602. }
  9603. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9604. org_id := c.GetAdminUserInfo().CurrentOrgId
  9605. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9606. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9607. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9608. c.ServeSuccessJSON(map[string]interface{}{
  9609. "order": order,
  9610. "order_info": order_info,
  9611. "patient": patient,
  9612. "admin_info": adminInfo,
  9613. "hospital_record": record,
  9614. })
  9615. return
  9616. }
  9617. func (c *HisApiController) GetAllOrderDetailCollect() {
  9618. order_id, _ := c.GetInt64("id", 0)
  9619. order, _ := service.GetHisOrderByID(order_id)
  9620. if order.ID == 0 {
  9621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9622. return
  9623. }
  9624. org_id := c.GetAdminUserInfo().CurrentOrgId
  9625. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9626. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9627. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9628. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9629. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9630. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9631. var bedCostTotal float64 = 0 //床位总费
  9632. //var bedCostSelfTotal float64 = 0 //床位自费
  9633. var operationCostTotal float64 = 0 //手术费
  9634. //var operationCostSelfTotal float64 = 0 //手术费
  9635. var otherCostTotal float64 = 0 //其他费用
  9636. //var otherCostSelfTotal float64 = 0 //其他费用
  9637. var materialCostTotal float64 = 0 //材料费
  9638. //var materialCostSelfTotal float64 = 0 //材料费
  9639. var westernMedicineCostTotal float64 = 0 //西药费
  9640. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9641. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9642. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9643. var checkCostTotal float64 = 0 //检查费
  9644. //var checkCostSelfTotal float64 = 0 //检查费
  9645. var laboratoryCostTotal float64 = 0 //化验费
  9646. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9647. var treatCostTotal float64 = 0 //治疗费用
  9648. //var treatCostSelfTotal float64 = 0 //治疗费用
  9649. var zhenChaCostTotal float64 = 0 //其他费用
  9650. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9651. decimal.DivisionPrecision = 2
  9652. var BalanceAccountsType int64
  9653. if his.ID > 0 {
  9654. BalanceAccountsType = his.BalanceAccountsType
  9655. } else {
  9656. BalanceAccountsType = record.BalanceAccountsType
  9657. }
  9658. if BalanceAccountsType != 2 {
  9659. for _, item := range order_info {
  9660. if org_id == 10215 {
  9661. if item.MedChrgitmType == "01" { //床位费
  9662. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9663. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9664. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9665. }
  9666. if item.MedChrgitmType == "02" { //诊察费
  9667. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9668. //zhenChaCostSelfTotal = zhenChaCostTotal
  9669. }
  9670. if item.MedChrgitmType == "03" { //检查费
  9671. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9672. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9673. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9674. }
  9675. //if item.MedChrgitmType == "02" { //检查费
  9676. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9677. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9678. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9679. //}
  9680. if item.MedChrgitmType == "04" { //化验费
  9681. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9682. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9683. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9684. }
  9685. if item.MedChrgitmType == "05" { //治疗费
  9686. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9687. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9688. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9689. }
  9690. if item.MedChrgitmType == "06" { //手术费
  9691. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9692. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9693. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9694. }
  9695. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9696. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9697. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9698. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9699. }
  9700. if item.MedChrgitmType == "09" { //西药费
  9701. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9702. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9703. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9704. }
  9705. if item.MedChrgitmType == "11" { //中成费
  9706. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9707. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9708. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9709. }
  9710. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9711. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9712. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9713. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9714. }
  9715. } else if org_id == 10188 || org_id == 10217 {
  9716. if item.MedChrgitmType == "01" { //床位费
  9717. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9718. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9719. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9720. }
  9721. if item.MedChrgitmType == "02" { //诊察费
  9722. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9723. //zhenChaCostSelfTotal = zhenChaCostTotal
  9724. }
  9725. if item.MedChrgitmType == "03" { //检查费
  9726. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9727. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9728. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9729. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9730. }
  9731. //if item.MedChrgitmType == "02" { //检查费
  9732. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9733. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9734. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9735. //}
  9736. if item.MedChrgitmType == "04" { //化验费
  9737. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9738. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9739. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9740. }
  9741. if item.MedChrgitmType == "05" { //治疗费
  9742. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9743. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9744. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9745. }
  9746. if item.MedChrgitmType == "06" { //手术费
  9747. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9748. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9749. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9750. }
  9751. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9752. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9753. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9754. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9755. }
  9756. if item.MedChrgitmType == "09" { //西药费
  9757. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9758. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9759. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9760. }
  9761. if item.MedChrgitmType == "11" { //中成费
  9762. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9763. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9764. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9765. }
  9766. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9767. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9768. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9769. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9770. }
  9771. } else {
  9772. if item.MedChrgitmType == "01" { //床位费
  9773. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9774. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9775. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9776. }
  9777. //if item.MedChrgitmType == "02" { //诊察费
  9778. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9779. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9780. //}
  9781. if item.MedChrgitmType == "03" { //检查费
  9782. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9783. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9784. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9785. }
  9786. //if item.MedChrgitmType == "02" { //检查费
  9787. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9788. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9789. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9790. //}
  9791. if item.MedChrgitmType == "04" { //化验费
  9792. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9793. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9794. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9795. }
  9796. if item.MedChrgitmType == "05" { //治疗费
  9797. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9798. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9799. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9800. }
  9801. if item.MedChrgitmType == "06" { //手术费
  9802. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9803. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9804. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9805. }
  9806. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9807. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9808. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9809. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9810. }
  9811. if item.MedChrgitmType == "09" { //西药费
  9812. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9813. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9814. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9815. }
  9816. if item.MedChrgitmType == "11" { //中成费
  9817. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9818. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9819. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9820. }
  9821. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9822. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9823. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9824. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9825. }
  9826. }
  9827. }
  9828. c.ServeSuccessJSON(map[string]interface{}{
  9829. "order": order,
  9830. "order_info": order_info,
  9831. "patient": patient,
  9832. "admin_info": adminInfo,
  9833. "his_hospital": record,
  9834. "bedCostTotal": bedCostTotal,
  9835. "operationCostTotal": operationCostTotal,
  9836. "otherCostTotal": otherCostTotal,
  9837. "materialCostTotal": materialCostTotal,
  9838. "westernMedicineCostTotal": westernMedicineCostTotal,
  9839. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9840. "checkCostTotal": checkCostTotal,
  9841. "zhenChaCostTotal": zhenChaCostTotal,
  9842. "laboratoryCostTotal": laboratoryCostTotal,
  9843. "treatCostTotal": treatCostTotal,
  9844. })
  9845. } else {
  9846. for _, item := range order_info {
  9847. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9848. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9849. item.MedChrgitmType = "09"
  9850. }
  9851. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9852. if item.HisPrescriptionProject.Type == 2 {
  9853. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9854. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9855. case 0:
  9856. item.MedChrgitmType = "0"
  9857. break
  9858. case 1:
  9859. item.MedChrgitmType = "14"
  9860. break
  9861. case 2:
  9862. item.MedChrgitmType = "05"
  9863. break
  9864. case 3:
  9865. item.MedChrgitmType = "03"
  9866. break
  9867. case 4:
  9868. item.MedChrgitmType = "03"
  9869. break
  9870. case 5:
  9871. item.MedChrgitmType = "08"
  9872. break
  9873. case 6:
  9874. item.MedChrgitmType = "14"
  9875. break
  9876. case 7:
  9877. item.MedChrgitmType = "14"
  9878. break
  9879. case 8:
  9880. item.MedChrgitmType = "03"
  9881. break
  9882. case 9:
  9883. item.MedChrgitmType = "14"
  9884. break
  9885. case 10:
  9886. item.MedChrgitmType = "14"
  9887. break
  9888. case 11:
  9889. item.MedChrgitmType = "06"
  9890. break
  9891. case 12:
  9892. item.MedChrgitmType = "12"
  9893. break
  9894. case 13:
  9895. item.MedChrgitmType = "01"
  9896. break
  9897. case 14:
  9898. item.MedChrgitmType = "04"
  9899. break
  9900. case 15:
  9901. item.MedChrgitmType = "14"
  9902. break
  9903. }
  9904. } else {
  9905. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9906. case 1:
  9907. item.MedChrgitmType = "14"
  9908. break
  9909. case 2:
  9910. item.MedChrgitmType = "05"
  9911. break
  9912. case 3:
  9913. item.MedChrgitmType = "04"
  9914. break
  9915. case 4:
  9916. item.MedChrgitmType = "14"
  9917. break
  9918. case 5:
  9919. item.MedChrgitmType = "08"
  9920. break
  9921. case 6:
  9922. item.MedChrgitmType = "14"
  9923. break
  9924. case 7:
  9925. item.MedChrgitmType = "14"
  9926. break
  9927. case 8:
  9928. item.MedChrgitmType = "03"
  9929. break
  9930. case 9:
  9931. item.MedChrgitmType = "14"
  9932. break
  9933. }
  9934. }
  9935. } else if item.HisPrescriptionProject.Type == 3 {
  9936. item.MedChrgitmType = "08"
  9937. }
  9938. }
  9939. }
  9940. for _, item := range order_info {
  9941. if org_id == 10215 {
  9942. if item.MedChrgitmType == "01" { //床位费
  9943. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9944. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9945. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9946. }
  9947. if item.MedChrgitmType == "02" { //诊察费
  9948. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9949. //zhenChaCostSelfTotal = zhenChaCostTotal
  9950. }
  9951. if item.MedChrgitmType == "03" { //检查费
  9952. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9953. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9954. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9955. }
  9956. //if item.MedChrgitmType == "02" { //检查费
  9957. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9958. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9959. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9960. //}
  9961. if item.MedChrgitmType == "04" { //化验费
  9962. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9963. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9964. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9965. }
  9966. if item.MedChrgitmType == "05" { //治疗费
  9967. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9968. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9969. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9970. }
  9971. if item.MedChrgitmType == "06" { //手术费
  9972. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9973. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9974. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9975. }
  9976. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9977. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9978. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9979. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9980. }
  9981. if item.MedChrgitmType == "09" { //西药费
  9982. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9983. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9984. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9985. }
  9986. if item.MedChrgitmType == "11" { //中成费
  9987. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9988. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9989. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9990. }
  9991. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9992. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9993. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9994. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9995. }
  9996. } else {
  9997. if item.MedChrgitmType == "01" { //床位费
  9998. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9999. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10000. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10001. }
  10002. //if item.MedChrgitmType == "02" { //诊察费
  10003. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10004. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10005. //}
  10006. if item.MedChrgitmType == "03" { //检查费
  10007. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10008. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10009. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10010. }
  10011. //if item.MedChrgitmType == "02" { //检查费
  10012. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10013. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10014. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10015. //}
  10016. if item.MedChrgitmType == "04" { //化验费
  10017. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10018. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10019. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10020. }
  10021. if item.MedChrgitmType == "05" { //治疗费
  10022. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10023. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10024. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10025. }
  10026. if item.MedChrgitmType == "06" { //手术费
  10027. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10028. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10029. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10030. }
  10031. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10032. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10033. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10034. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10035. }
  10036. if item.MedChrgitmType == "09" { //西药费
  10037. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10038. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10039. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10040. }
  10041. if item.MedChrgitmType == "11" { //中成费
  10042. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10043. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10044. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10045. }
  10046. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10047. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10048. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10049. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10050. }
  10051. }
  10052. }
  10053. c.ServeSuccessJSON(map[string]interface{}{
  10054. "order": order,
  10055. "order_info": order_info,
  10056. "patient": patient,
  10057. "admin_info": adminInfo,
  10058. "his_hospital": record,
  10059. "bedCostTotal": bedCostTotal,
  10060. "operationCostTotal": operationCostTotal,
  10061. "otherCostTotal": otherCostTotal,
  10062. "materialCostTotal": materialCostTotal,
  10063. "westernMedicineCostTotal": westernMedicineCostTotal,
  10064. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10065. "checkCostTotal": checkCostTotal,
  10066. "zhenChaCostTotal": zhenChaCostTotal,
  10067. "laboratoryCostTotal": laboratoryCostTotal,
  10068. "treatCostTotal": treatCostTotal,
  10069. })
  10070. }
  10071. }
  10072. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10073. page, _ := c.GetInt64("page")
  10074. limit, _ := c.GetInt64("limit")
  10075. keywords := c.GetString("keywords")
  10076. start_time := c.GetString("start_time")
  10077. end_time := c.GetString("end_time")
  10078. //clr_type := c.GetString("clr_type")
  10079. insutype := c.GetString("insutype")
  10080. timeLayout := "2006-01-02"
  10081. loc, _ := time.LoadLocation("Local")
  10082. var theStartTIme int64
  10083. if len(start_time) > 0 {
  10084. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10085. theStartTIme = theTime.Unix()
  10086. }
  10087. var theEndtTIme int64
  10088. if len(end_time) > 0 {
  10089. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10090. theEndtTIme = theTime.Unix()
  10091. }
  10092. if page <= 0 {
  10093. page = 1
  10094. }
  10095. if limit <= 0 {
  10096. limit = 10
  10097. }
  10098. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10099. c.ServeSuccessJSON(map[string]interface{}{
  10100. "total": total,
  10101. "list": list,
  10102. })
  10103. return
  10104. }
  10105. func (c *HisApiController) GetPutOnRecordList() {
  10106. page, _ := c.GetInt64("page")
  10107. limit, _ := c.GetInt64("limit")
  10108. keywords := c.GetString("keywords")
  10109. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10110. if page <= 0 {
  10111. page = 1
  10112. }
  10113. if limit <= 0 {
  10114. limit = 10
  10115. }
  10116. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10117. c.ServeSuccessJSON(map[string]interface{}{
  10118. "total": total,
  10119. "list": list,
  10120. })
  10121. return
  10122. }
  10123. func (c *HisApiController) GetCompareData() {
  10124. start_time := c.GetString("start_time")
  10125. end_time := c.GetString("end_time")
  10126. insutype := c.GetString("insutype")
  10127. clr_type := c.GetString("clr_type")
  10128. timeLayout := "2006-01-02"
  10129. loc, _ := time.LoadLocation("Local")
  10130. var theStartTIme int64
  10131. if len(start_time) > 0 {
  10132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10133. if err != nil {
  10134. theStartTIme = 0
  10135. }
  10136. theStartTIme = theTime.Unix()
  10137. }
  10138. var theEndtTIme int64
  10139. if len(end_time) > 0 {
  10140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10141. if err != nil {
  10142. theEndtTIme = 0
  10143. }
  10144. theEndtTIme = theTime.Unix()
  10145. }
  10146. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10147. fmt.Println(err)
  10148. if err == nil {
  10149. c.ServeSuccessJSON(map[string]interface{}{
  10150. "list": formData,
  10151. })
  10152. } else {
  10153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10154. return
  10155. }
  10156. }
  10157. func (c *HisApiController) GetFaPiaoData() {
  10158. order_id, _ := c.GetInt64("order_id")
  10159. patient_id, _ := c.GetInt64("patient_id")
  10160. //number := c.GetString("number")
  10161. adminUser := c.GetAdminUserInfo()
  10162. order, _ := service.GetHisOrderByID(order_id)
  10163. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10164. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10165. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10166. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10167. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10168. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10169. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10170. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10171. var bedCostTotal float64 = 0 //床位总费
  10172. var bedCostSelfTotal float64 = 0 //床位自费
  10173. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10174. var operationCostTotal float64 = 0 //手术费
  10175. var operationCostSelfTotal float64 = 0 //手术费
  10176. var operationCostPartSelfTotal float64 = 0 //手术费
  10177. var otherCostTotal float64 = 0 //其他费用
  10178. var otherCostSelfTotal float64 = 0 //其他费用
  10179. var otherCostPartSelfTotal float64 = 0 //其他费用
  10180. var materialCostTotal float64 = 0 //材料费
  10181. var materialCostSelfTotal float64 = 0 //材料费
  10182. var materialCostPartSelfTotal float64 = 0 //材料费
  10183. var westernMedicineCostTotal float64 = 0 //西药费
  10184. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10185. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10186. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10187. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10188. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10189. var checkCostTotal float64 = 0 //检查费
  10190. var checkCostSelfTotal float64 = 0 //检查费
  10191. var checkCostPartSelfTotal float64 = 0 //检查费
  10192. var hiliCostTotal float64 = 0 //护理费
  10193. var hiliCostSelfTotal float64 = 0 //护理费
  10194. var hiliCostPartSelfTotal float64 = 0 //护理费
  10195. var laboratoryCostTotal float64 = 0 //化验费
  10196. var laboratoryCostSelfTotal float64 = 0 //化验费
  10197. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10198. var treatCostTotal float64 = 0 //治疗费用
  10199. var treatCostSelfTotal float64 = 0 //治疗费用
  10200. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10201. var zhenChaCostTotal float64 = 0 //其他费用
  10202. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10203. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10204. decimal.DivisionPrecision = 2
  10205. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10206. var balanceAccountsType int64
  10207. if his.ID > 0 {
  10208. balanceAccountsType = his.BalanceAccountsType
  10209. } else {
  10210. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10211. }
  10212. if balanceAccountsType == 2 {
  10213. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10214. for _, item := range orderInfos_two {
  10215. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10216. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10217. item.MedChrgitmType = "09"
  10218. }
  10219. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10220. if item.HisPrescriptionProject.Type == 2 {
  10221. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10222. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10223. case 0:
  10224. item.MedChrgitmType = "0"
  10225. break
  10226. case 1:
  10227. item.MedChrgitmType = "14"
  10228. break
  10229. case 2:
  10230. item.MedChrgitmType = "05"
  10231. break
  10232. case 3:
  10233. item.MedChrgitmType = "03"
  10234. break
  10235. case 4:
  10236. item.MedChrgitmType = "03"
  10237. break
  10238. case 5:
  10239. item.MedChrgitmType = "08"
  10240. break
  10241. case 6:
  10242. item.MedChrgitmType = "14"
  10243. break
  10244. case 7:
  10245. item.MedChrgitmType = "14"
  10246. break
  10247. case 8:
  10248. item.MedChrgitmType = "03"
  10249. break
  10250. case 9:
  10251. item.MedChrgitmType = "14"
  10252. break
  10253. case 10:
  10254. item.MedChrgitmType = "14"
  10255. break
  10256. case 11:
  10257. item.MedChrgitmType = "06"
  10258. break
  10259. case 12:
  10260. item.MedChrgitmType = "12"
  10261. break
  10262. case 13:
  10263. item.MedChrgitmType = "01"
  10264. break
  10265. case 14:
  10266. item.MedChrgitmType = "04"
  10267. break
  10268. case 15:
  10269. item.MedChrgitmType = "02"
  10270. break
  10271. }
  10272. } else {
  10273. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10274. case 1:
  10275. item.MedChrgitmType = "14"
  10276. break
  10277. case 2:
  10278. item.MedChrgitmType = "05"
  10279. break
  10280. case 3:
  10281. item.MedChrgitmType = "04"
  10282. break
  10283. case 4:
  10284. item.MedChrgitmType = "03"
  10285. break
  10286. case 5:
  10287. item.MedChrgitmType = "08"
  10288. break
  10289. case 6:
  10290. item.MedChrgitmType = "14"
  10291. break
  10292. case 7:
  10293. item.MedChrgitmType = "14"
  10294. break
  10295. case 8:
  10296. item.MedChrgitmType = "03"
  10297. break
  10298. case 9:
  10299. item.MedChrgitmType = "14"
  10300. break
  10301. }
  10302. }
  10303. } else if item.HisPrescriptionProject.Type == 3 {
  10304. item.MedChrgitmType = "08"
  10305. }
  10306. }
  10307. }
  10308. for _, item := range orderInfos_two {
  10309. fmt.Println(item.MedChrgitmType)
  10310. if item.MedChrgitmType == "07" { //床位费
  10311. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. hiliCostSelfTotal = hiliCostTotal
  10313. }
  10314. if item.MedChrgitmType == "01" { //床位费
  10315. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. bedCostSelfTotal = bedCostTotal
  10317. }
  10318. if item.MedChrgitmType == "02" { //诊察费
  10319. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10320. zhenChaCostSelfTotal = zhenChaCostTotal
  10321. }
  10322. if item.MedChrgitmType == "03" { //检查费
  10323. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10324. checkCostSelfTotal = checkCostTotal
  10325. }
  10326. if item.MedChrgitmType == "04" { //化验费
  10327. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10328. laboratoryCostSelfTotal = laboratoryCostTotal
  10329. }
  10330. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10331. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. treatCostSelfTotal = treatCostTotal
  10333. }
  10334. if item.MedChrgitmType == "06" { //手术费
  10335. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10336. operationCostSelfTotal = treatCostTotal
  10337. }
  10338. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10339. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10340. materialCostSelfTotal = materialCostTotal
  10341. }
  10342. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10343. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10344. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10345. }
  10346. if item.MedChrgitmType == "11" { //中成费
  10347. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10348. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10349. }
  10350. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10351. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10352. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10353. otherCostSelfTotal = otherCostTotal
  10354. }
  10355. } else {
  10356. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10357. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10358. otherCostSelfTotal = otherCostTotal
  10359. }
  10360. }
  10361. }
  10362. } else {
  10363. for _, item := range orderInfos {
  10364. if item.MedChrgitmType == "01" { //床位费
  10365. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10366. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10367. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10368. }
  10369. if item.MedChrgitmType == "02" { //诊察费
  10370. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10371. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10372. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10373. }
  10374. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10375. if item.MedChrgitmType == "03" { //检查费
  10376. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10377. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10378. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10379. }
  10380. } else {
  10381. if item.MedChrgitmType == "03" { //检查费
  10382. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10383. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10384. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10385. }
  10386. }
  10387. if item.MedChrgitmType == "04" { //化验费
  10388. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10389. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10390. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10391. }
  10392. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10393. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10394. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10395. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10396. }
  10397. if item.MedChrgitmType == "06" { //手术费
  10398. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10399. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10400. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10401. }
  10402. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10403. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10404. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10405. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10406. }
  10407. if item.MedChrgitmType == "07" { //护理
  10408. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10409. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10410. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10411. }
  10412. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10413. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10414. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10415. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10416. }
  10417. if item.MedChrgitmType == "11" { //中成费
  10418. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10419. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10420. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10421. }
  10422. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10423. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10424. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10425. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10426. }
  10427. }
  10428. }
  10429. timeLayout := "2006-01-02"
  10430. loc, _ := time.LoadLocation("Local")
  10431. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10432. if err != nil {
  10433. }
  10434. startRecordDateTime := startTime.Unix()
  10435. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10436. if err != nil {
  10437. }
  10438. endRecordDateTime := endTime.Unix()
  10439. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10440. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10441. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10442. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10443. c.ServeSuccessJSON(map[string]interface{}{
  10444. "charge_admin_name": charge_admin.UserName,
  10445. "order_number": order.Number, //业务流水号
  10446. "id_card_no": his.IdCardNo, //社会保障号
  10447. "patient": patient,
  10448. "department_name": department.Name, //科室
  10449. "number": his.Number, //门诊号
  10450. "date": order.SettleAccountsDate, //结算日期
  10451. "name": order.PsnName, //姓名
  10452. "gender": patient.Gender, //性别
  10453. "psn_cash_money": order.PsnCashPay, //个人支付
  10454. "pay_way": "门诊", //结算方式
  10455. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10456. "admin_user_name": admin.UserName, //收款员
  10457. "order": order,
  10458. "order_info": orderInfos_two,
  10459. "his": his,
  10460. "bedCostTotal": bedCostTotal,
  10461. "bedCostSelfTotal": bedCostSelfTotal,
  10462. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10463. "operationCostTotal": operationCostTotal,
  10464. "operationCostSelfTotal": operationCostSelfTotal,
  10465. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10466. "otherCostTotal": otherCostTotal,
  10467. "otherCostSelfTotal": otherCostSelfTotal,
  10468. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10469. "materialCostTotal": materialCostTotal,
  10470. "materialCostSelfTotal": materialCostSelfTotal,
  10471. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10472. "westernMedicineCostTotal": westernMedicineCostTotal,
  10473. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10474. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10475. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10476. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10477. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10478. "checkCostTotal": checkCostTotal,
  10479. "checkCostSelfTotal": checkCostSelfTotal,
  10480. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10481. "laboratoryCostTotal": laboratoryCostTotal,
  10482. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10483. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10484. "treatCostTotal": treatCostTotal,
  10485. "treatCostSelfTotal": treatCostSelfTotal,
  10486. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10487. "zhenChaCostTotal": zhenChaCostTotal,
  10488. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10489. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10490. "his_hospital_record": his_hospital_record,
  10491. "pre_pay_money": pre_pay_money,
  10492. "refund_sum": sum,
  10493. "doctor_info": doctor_info,
  10494. "hiliCostTotal": hiliCostTotal,
  10495. "hiliCostSelfTotal": hiliCostSelfTotal,
  10496. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10497. })
  10498. }
  10499. //func (c *HisApiController) GetFaPiaoDatas() {
  10500. // order_ids := c.GetString("order_ids")
  10501. // patient_id, _ := c.GetInt64("patient_id")
  10502. // adminUser := c.GetAdminUserInfo()
  10503. //
  10504. // orders := strings.Split(order_ids, ",")
  10505. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10506. //
  10507. // for _, item := range orders {
  10508. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10509. // order, _ := service.GetHisOrderByID(order_id)
  10510. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10511. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10512. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10513. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10514. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10515. //
  10516. // }
  10517. //
  10518. // var bedCostTotal float64 = 0 //床位总费
  10519. // var bedCostSelfTotal float64 = 0 //床位自费
  10520. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10521. //
  10522. // var operationCostTotal float64 = 0 //手术费
  10523. // var operationCostSelfTotal float64 = 0 //手术费
  10524. // var operationCostPartSelfTotal float64 = 0 //手术费
  10525. //
  10526. // var otherCostTotal float64 = 0 //其他费用
  10527. // var otherCostSelfTotal float64 = 0 //其他费用
  10528. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10529. //
  10530. // var materialCostTotal float64 = 0 //材料费
  10531. // var materialCostSelfTotal float64 = 0 //材料费
  10532. // var materialCostPartSelfTotal float64 = 0 //材料费
  10533. //
  10534. // var westernMedicineCostTotal float64 = 0 //西药费
  10535. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10536. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10537. //
  10538. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10539. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10540. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10541. //
  10542. // var checkCostTotal float64 = 0 //检查费
  10543. // var checkCostSelfTotal float64 = 0 //检查费
  10544. // var checkCostPartSelfTotal float64 = 0 //检查费
  10545. //
  10546. // var laboratoryCostTotal float64 = 0 //化验费
  10547. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10548. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10549. //
  10550. // var treatCostTotal float64 = 0 //治疗费用
  10551. // var treatCostSelfTotal float64 = 0 //治疗费用
  10552. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10553. //
  10554. // var zhenChaCostTotal float64 = 0 //其他费用
  10555. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10556. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10557. //
  10558. // decimal.DivisionPrecision = 2
  10559. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10560. //
  10561. // var balanceAccountsType int64
  10562. // if his.ID > 0 {
  10563. // balanceAccountsType = his.BalanceAccountsType
  10564. // } else {
  10565. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10566. // }
  10567. // if balanceAccountsType == 2 {
  10568. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10569. // for _, item := range orderInfos_two {
  10570. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10571. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10572. // item.MedChrgitmType = "09"
  10573. // }
  10574. //
  10575. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10576. // if item.HisPrescriptionProject.Type == 2 {
  10577. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10578. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10579. // case 0:
  10580. // item.MedChrgitmType = "0"
  10581. // break
  10582. // case 1:
  10583. // item.MedChrgitmType = "14"
  10584. // break
  10585. // case 2:
  10586. // item.MedChrgitmType = "05"
  10587. //
  10588. // break
  10589. // case 3:
  10590. // item.MedChrgitmType = "03"
  10591. //
  10592. // break
  10593. // case 4:
  10594. // item.MedChrgitmType = "03"
  10595. //
  10596. // break
  10597. // case 5:
  10598. // item.MedChrgitmType = "08"
  10599. //
  10600. // break
  10601. // case 6:
  10602. // item.MedChrgitmType = "14"
  10603. //
  10604. // break
  10605. // case 7:
  10606. // item.MedChrgitmType = "14"
  10607. //
  10608. // break
  10609. // case 8:
  10610. // item.MedChrgitmType = "03"
  10611. // break
  10612. // case 9:
  10613. // item.MedChrgitmType = "14"
  10614. // break
  10615. // case 10:
  10616. // item.MedChrgitmType = "14"
  10617. // break
  10618. // case 11:
  10619. // item.MedChrgitmType = "06"
  10620. // break
  10621. // case 12:
  10622. // item.MedChrgitmType = "12"
  10623. // break
  10624. // case 13:
  10625. // item.MedChrgitmType = "01"
  10626. // break
  10627. // case 14:
  10628. // item.MedChrgitmType = "04"
  10629. // break
  10630. // case 15:
  10631. // item.MedChrgitmType = "02"
  10632. // break
  10633. //
  10634. // }
  10635. //
  10636. // } else {
  10637. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10638. //
  10639. // case 1:
  10640. // item.MedChrgitmType = "14"
  10641. // break
  10642. // case 2:
  10643. // item.MedChrgitmType = "05"
  10644. //
  10645. // break
  10646. // case 3:
  10647. // item.MedChrgitmType = "03"
  10648. //
  10649. // break
  10650. // case 4:
  10651. // item.MedChrgitmType = "03"
  10652. //
  10653. // break
  10654. // case 5:
  10655. // item.MedChrgitmType = "08"
  10656. //
  10657. // break
  10658. // case 6:
  10659. // item.MedChrgitmType = "14"
  10660. //
  10661. // break
  10662. // case 7:
  10663. // item.MedChrgitmType = "14"
  10664. //
  10665. // break
  10666. // case 8:
  10667. // item.MedChrgitmType = "03"
  10668. // break
  10669. // case 9:
  10670. // item.MedChrgitmType = "14"
  10671. // break
  10672. //
  10673. // }
  10674. //
  10675. // }
  10676. //
  10677. // } else if item.HisPrescriptionProject.Type == 3 {
  10678. // item.MedChrgitmType = "08"
  10679. // }
  10680. // }
  10681. // }
  10682. //
  10683. // for _, item := range orderInfos_two {
  10684. // fmt.Println(item.MedChrgitmType)
  10685. // if item.MedChrgitmType == "01" { //床位费
  10686. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10687. // bedCostSelfTotal = bedCostTotal
  10688. // }
  10689. //
  10690. // if item.MedChrgitmType == "02" { //诊察费
  10691. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10692. // zhenChaCostSelfTotal = zhenChaCostTotal
  10693. // }
  10694. //
  10695. // if item.MedChrgitmType == "03" { //检查费
  10696. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10697. // checkCostSelfTotal = checkCostTotal
  10698. // }
  10699. //
  10700. // if item.MedChrgitmType == "04" { //化验费
  10701. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10702. // laboratoryCostSelfTotal = laboratoryCostTotal
  10703. // }
  10704. //
  10705. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10706. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10707. // treatCostSelfTotal = treatCostTotal
  10708. // }
  10709. //
  10710. // if item.MedChrgitmType == "06" { //手术费
  10711. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10712. // operationCostSelfTotal = treatCostTotal
  10713. // }
  10714. //
  10715. // if item.MedChrgitmType == "08" { //材料费
  10716. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10717. // materialCostSelfTotal = materialCostTotal
  10718. // }
  10719. //
  10720. // if item.MedChrgitmType == "09" { //西药费
  10721. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10722. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10723. // }
  10724. //
  10725. // if item.MedChrgitmType == "11" { //中成费
  10726. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10727. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10728. // }
  10729. //
  10730. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10731. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10732. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10733. // otherCostSelfTotal = otherCostTotal
  10734. // }
  10735. // } else {
  10736. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10737. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10738. // otherCostSelfTotal = otherCostTotal
  10739. // }
  10740. //
  10741. // }
  10742. //
  10743. // }
  10744. //
  10745. // } else {
  10746. // for _, item := range orderInfos {
  10747. // if item.MedChrgitmType == "01" { //床位费
  10748. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10749. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10750. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10751. // }
  10752. //
  10753. // if item.MedChrgitmType == "02" { //诊察费
  10754. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10755. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10756. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10757. // }
  10758. //
  10759. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10760. // if item.MedChrgitmType == "03" { //检查费
  10761. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10762. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10763. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10764. //
  10765. // }
  10766. // } else {
  10767. // if item.MedChrgitmType == "03" { //检查费
  10768. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10769. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10770. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10771. // }
  10772. //
  10773. // }
  10774. //
  10775. // if item.MedChrgitmType == "04" { //化验费
  10776. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10777. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10778. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10779. //
  10780. // }
  10781. //
  10782. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10783. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10784. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10785. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10786. //
  10787. // }
  10788. //
  10789. // if item.MedChrgitmType == "06" { //手术费
  10790. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10791. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10792. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10793. // }
  10794. //
  10795. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10796. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10797. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10798. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10799. // }
  10800. //
  10801. // if item.MedChrgitmType == "09" { //西药费
  10802. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10803. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10804. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10805. // }
  10806. //
  10807. // if item.MedChrgitmType == "11" { //中成费
  10808. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10809. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10810. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10811. // }
  10812. //
  10813. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10814. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10816. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10817. // }
  10818. //
  10819. // }
  10820. // }
  10821. // timeLayout := "2006-01-02"
  10822. // loc, _ := time.LoadLocation("Local")
  10823. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10824. // if err != nil {
  10825. // }
  10826. // startRecordDateTime := startTime.Unix()
  10827. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10828. // if err != nil {
  10829. // }
  10830. // endRecordDateTime := endTime.Unix()
  10831. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10832. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10833. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10834. //
  10835. // c.ServeSuccessJSON(map[string]interface{}{
  10836. // "order_number": order.Number, //业务流水号
  10837. // "id_card_no": his.IdCardNo, //社会保障号
  10838. // "department_name": department.Name, //科室
  10839. // "number": his.Number, //门诊号
  10840. // "date": order.SettleAccountsDate, //结算日期
  10841. // "name": order.PsnName, //姓名
  10842. // "gender": patient.Gender, //性别
  10843. // "psn_cash_money": order.PsnCashPay, //个人支付
  10844. // "pay_way": "门诊", //结算方式
  10845. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10846. // "admin_user_name": admin.UserName, //收款员
  10847. // "order": order,
  10848. // "order_info": orderInfos_two,
  10849. // "his": his,
  10850. // "bedCostTotal": bedCostTotal,
  10851. // "bedCostSelfTotal": bedCostSelfTotal,
  10852. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10853. // "operationCostTotal": operationCostTotal,
  10854. // "operationCostSelfTotal": operationCostSelfTotal,
  10855. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10856. // "otherCostTotal": otherCostTotal,
  10857. // "otherCostSelfTotal": otherCostSelfTotal,
  10858. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10859. // "materialCostTotal": materialCostTotal,
  10860. // "materialCostSelfTotal": materialCostSelfTotal,
  10861. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10862. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10863. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10864. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10865. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10866. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10867. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10868. // "checkCostTotal": checkCostTotal,
  10869. // "checkCostSelfTotal": checkCostSelfTotal,
  10870. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10871. // "laboratoryCostTotal": laboratoryCostTotal,
  10872. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10873. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10874. // "treatCostTotal": treatCostTotal,
  10875. // "treatCostSelfTotal": treatCostSelfTotal,
  10876. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10877. // "zhenChaCostTotal": zhenChaCostTotal,
  10878. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10879. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10880. // "his_hospital_record": his_hospital_record,
  10881. // "pre_pay_money": pre_pay_money,
  10882. // "refund_sum": sum,
  10883. // })
  10884. //
  10885. //}
  10886. func (this *HisApiController) GetIncomeStatisticsData() {
  10887. start_time := this.GetString("start_time")
  10888. end_time := this.GetString("end_time")
  10889. key_words := this.GetString("key_words")
  10890. limit, _ := this.GetInt64("limit")
  10891. page, _ := this.GetInt64("page")
  10892. if page <= 0 {
  10893. page = 1
  10894. }
  10895. if limit <= 0 {
  10896. limit = 10
  10897. }
  10898. statistics_type, _ := this.GetInt64("statistics_type")
  10899. admin := this.GetAdminUserInfo()
  10900. timeLayout := "2006-01-02"
  10901. loc, _ := time.LoadLocation("Local")
  10902. var theStartTIme int64
  10903. if len(start_time) > 0 {
  10904. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10905. if err != nil {
  10906. theStartTIme = 0
  10907. }
  10908. theStartTIme = theTime.Unix()
  10909. }
  10910. var theEndtTIme int64
  10911. if len(end_time) > 0 {
  10912. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10913. if err != nil {
  10914. theEndtTIme = 0
  10915. }
  10916. theEndtTIme = theTime.Unix()
  10917. }
  10918. if statistics_type == 1 {
  10919. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10920. this.ServeSuccessJSON(map[string]interface{}{
  10921. "list": list,
  10922. "total": total,
  10923. })
  10924. } else {
  10925. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10926. this.ServeSuccessJSON(map[string]interface{}{
  10927. "list": list,
  10928. "total": total,
  10929. })
  10930. }
  10931. }
  10932. func (c *HisApiController) PostProjectInformation() {
  10933. adminUser := c.GetAdminUserInfo()
  10934. orgId := adminUser.CurrentOrgId
  10935. dataBody := make(map[string]interface{}, 0)
  10936. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10937. if err != nil {
  10938. utils.ErrorLog(err.Error())
  10939. return
  10940. }
  10941. utils.ErrorLog("%v", dataBody)
  10942. var projectList []*models.HisProject
  10943. var total_goods []interface{}
  10944. tempProjects := dataBody["projects"].([]interface{})
  10945. total_goods = tempProjects
  10946. for index, projectMap := range tempProjects {
  10947. projectM := projectMap.(map[string]interface{})
  10948. var project models.HisProject
  10949. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10950. utils.ErrorLog("project_name")
  10951. return
  10952. }
  10953. project_name, _ := projectM["project_name"].(string)
  10954. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10955. err_log := models.ExportErrLog{
  10956. LogType: 6,
  10957. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10958. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10959. Status: 1,
  10960. CreateTime: time.Now().Unix(),
  10961. UpdateTime: time.Now().Unix(),
  10962. ExportTime: time.Now().Unix(),
  10963. }
  10964. service.CreateExportErrLog(&err_log)
  10965. continue
  10966. }
  10967. project.ProjectName = project_name
  10968. prices := projectM["price"].(string)
  10969. price, _ := strconv.ParseFloat(prices, 64)
  10970. if price <= 0 { //名字为空则生成一条导入错误日志
  10971. err_log := models.ExportErrLog{
  10972. LogType: 6,
  10973. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10974. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10975. Status: 1,
  10976. CreateTime: time.Now().Unix(),
  10977. UpdateTime: time.Now().Unix(),
  10978. ExportTime: time.Now().Unix(),
  10979. }
  10980. service.CreateExportErrLog(&err_log)
  10981. continue
  10982. }
  10983. project.Price = price
  10984. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10985. utils.ErrorLog("unit_id")
  10986. return
  10987. }
  10988. unit := projectM["unit"].(string)
  10989. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10990. err_log := models.ExportErrLog{
  10991. LogType: 6,
  10992. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10993. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10994. Status: 1,
  10995. CreateTime: time.Now().Unix(),
  10996. UpdateTime: time.Now().Unix(),
  10997. ExportTime: time.Now().Unix(),
  10998. }
  10999. service.CreateExportErrLog(&err_log)
  11000. continue
  11001. }
  11002. project.Unit = unit
  11003. cost_classify := projectM["cost_classify"].(string)
  11004. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11005. err_log := models.ExportErrLog{
  11006. LogType: 6,
  11007. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11008. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11009. Status: 1,
  11010. CreateTime: time.Now().Unix(),
  11011. UpdateTime: time.Now().Unix(),
  11012. ExportTime: time.Now().Unix(),
  11013. }
  11014. service.CreateExportErrLog(&err_log)
  11015. continue
  11016. }
  11017. var costClassify = "费用类别"
  11018. var cost_classify_id int64
  11019. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11020. if len(cost_classify) != 0 {
  11021. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11022. if errcode == gorm.ErrRecordNotFound {
  11023. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11024. dataconfig := models.DictDataconfig{
  11025. ParentId: costClassifyConfig.ID,
  11026. Module: "system",
  11027. OrgId: orgId,
  11028. Name: cost_classify,
  11029. FieldName: "",
  11030. Value: costConfig.Value + 1,
  11031. CreatedTime: "",
  11032. UpdatedTime: "",
  11033. CreateUserId: adminUser.AdminUser.Id,
  11034. Status: 1,
  11035. Remark: "",
  11036. DeleteIdSystem: 0,
  11037. Title: "",
  11038. Content: "",
  11039. Order: 0,
  11040. Code: "",
  11041. }
  11042. service.CreatedDicConfig(&dataconfig)
  11043. }
  11044. }
  11045. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11046. for _, it := range costClassList {
  11047. if cost_classify == it.Name {
  11048. cost_classify_id = int64(it.Value)
  11049. }
  11050. }
  11051. project.CostClassify = cost_classify_id
  11052. executive_section := projectM["executive_section"].(string)
  11053. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11054. err_log := models.ExportErrLog{
  11055. LogType: 6,
  11056. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11057. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11058. Status: 1,
  11059. CreateTime: time.Now().Unix(),
  11060. UpdateTime: time.Now().Unix(),
  11061. ExportTime: time.Now().Unix(),
  11062. }
  11063. service.CreateExportErrLog(&err_log)
  11064. continue
  11065. }
  11066. if len(executive_section) != 0 {
  11067. //查找科室是否有内容
  11068. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11069. if errcodedepart == gorm.ErrRecordNotFound {
  11070. department := models.XtHisDepartment{
  11071. Name: executive_section,
  11072. Status: 1,
  11073. UserOrgId: adminUser.CurrentOrgId,
  11074. CreatedTime: time.Now().Unix(),
  11075. }
  11076. service.CreateDePartment(&department)
  11077. }
  11078. }
  11079. var executive_section_id int64
  11080. departMentList, _ := service.GetAllDepartMent(orgId)
  11081. for _, it := range departMentList {
  11082. if executive_section == it.Name {
  11083. executive_section_id = it.ID
  11084. }
  11085. }
  11086. project.ExecutiveSection = executive_section_id
  11087. medical_coverage := projectM["medical_coverage"].(string)
  11088. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11089. err_log := models.ExportErrLog{
  11090. LogType: 6,
  11091. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11092. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11093. Status: 1,
  11094. CreateTime: time.Now().Unix(),
  11095. UpdateTime: time.Now().Unix(),
  11096. ExportTime: time.Now().Unix(),
  11097. }
  11098. service.CreateExportErrLog(&err_log)
  11099. continue
  11100. }
  11101. var medicalCoverage = "医保等级"
  11102. var medical_coverage_id int64
  11103. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11104. if len(medical_coverage) != 0 {
  11105. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11106. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11107. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11108. dataconfig := models.DictDataconfig{
  11109. ParentId: medicalCoverageConfig.ID,
  11110. Module: "system",
  11111. OrgId: orgId,
  11112. Name: medical_coverage,
  11113. FieldName: "",
  11114. Value: medicalCoverageConfig.Value + 1,
  11115. CreatedTime: "",
  11116. UpdatedTime: "",
  11117. CreateUserId: adminUser.AdminUser.Id,
  11118. Status: 1,
  11119. Remark: "",
  11120. DeleteIdSystem: 0,
  11121. Title: "",
  11122. Content: "",
  11123. Order: 0,
  11124. Code: "",
  11125. }
  11126. service.CreatedDicConfig(&dataconfig)
  11127. }
  11128. }
  11129. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11130. for _, it := range medicalCoverageList {
  11131. if medical_coverage == it.Name {
  11132. medical_coverage_id = int64(it.Value)
  11133. }
  11134. }
  11135. project.MedicalCoverage = medical_coverage_id
  11136. pinyin := projectM["pinyin"].(string)
  11137. project.Pinyin = pinyin
  11138. wubi := projectM["wubi"].(string)
  11139. project.Wubi = wubi
  11140. statistical_classification := projectM["statistical_classification"].(string)
  11141. var statisticalClassification = "统计分类"
  11142. var statistical_classification_id int64
  11143. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11144. if len(statistical_classification) != 0 {
  11145. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11146. if classificationerrcodes == gorm.ErrRecordNotFound {
  11147. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11148. dataconfig := models.DictDataconfig{
  11149. ParentId: classiFication.ID,
  11150. Module: "system",
  11151. OrgId: orgId,
  11152. Name: statistical_classification,
  11153. FieldName: "",
  11154. Value: classiFicationConfig.Value + 1,
  11155. CreatedTime: "",
  11156. UpdatedTime: "",
  11157. CreateUserId: adminUser.AdminUser.Id,
  11158. Status: 1,
  11159. Remark: "",
  11160. DeleteIdSystem: 0,
  11161. Title: "",
  11162. Content: "",
  11163. Order: 0,
  11164. Code: "",
  11165. }
  11166. service.CreatedDicConfig(&dataconfig)
  11167. }
  11168. }
  11169. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11170. for _, it := range classiFicationList {
  11171. if statistical_classification == it.Name {
  11172. statistical_classification_id = int64(it.Value)
  11173. }
  11174. }
  11175. project.StatisticalClassification = statistical_classification_id
  11176. disease_directory := int64(projectM["disease_directory"].(float64))
  11177. project.DiseaseDirectory = disease_directory
  11178. is_record := int64(projectM["is_record"].(float64))
  11179. project.IsRecord = is_record
  11180. medical_code := projectM["medical_code"].(string)
  11181. project.MedicalCode = medical_code
  11182. tube_color := projectM["tube_color"].(string)
  11183. var tubeColor = "试管颜色"
  11184. var tube_color_id int64
  11185. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11186. if len(tube_color) != 0 {
  11187. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11188. if errcodetube == gorm.ErrRecordNotFound {
  11189. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11190. dataconfig := models.DictDataconfig{
  11191. ParentId: tubeColorConfig.ID,
  11192. Module: "system",
  11193. OrgId: orgId,
  11194. Name: tube_color,
  11195. FieldName: "",
  11196. Value: tubeConfig.Value + 1,
  11197. CreatedTime: "",
  11198. UpdatedTime: "",
  11199. CreateUserId: adminUser.AdminUser.Id,
  11200. Status: 1,
  11201. Remark: "",
  11202. DeleteIdSystem: 0,
  11203. Title: "",
  11204. Content: "",
  11205. Order: 0,
  11206. Code: "",
  11207. }
  11208. service.CreatedDicConfig(&dataconfig)
  11209. }
  11210. }
  11211. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11212. for _, it := range tubeColorList {
  11213. if tube_color == it.Name {
  11214. tube_color_id = int64(it.Value)
  11215. }
  11216. }
  11217. project.TubeColor = tube_color_id
  11218. single_dose := projectM["single_dose"].(string)
  11219. project.SingleDose = single_dose
  11220. execution_frequency := projectM["execution_frequency"].(string)
  11221. project.ExecutionFrequency = execution_frequency
  11222. delivery_way := projectM["delivery_way"].(string)
  11223. project.DeliveryWay = delivery_way
  11224. number_days := projectM["number_days"].(string)
  11225. project.NumberDays = number_days
  11226. total := projectM["total"].(string)
  11227. project.Total = total
  11228. medical_status := int64(projectM["medical_status"].(float64))
  11229. project.MedicalStatus = medical_status
  11230. category := int64(projectM["category"].(float64))
  11231. project.Category = category
  11232. specail_project := int64(projectM["specail_project"].(float64))
  11233. project.SpecailProject = specail_project
  11234. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11235. project.SocialSecurityDirectoryCode = social_security_directory_code
  11236. remark := projectM["remark"].(string)
  11237. project.Remark = remark
  11238. record_date := projectM["record_date"].(string)
  11239. timeLayout := "2006-01-02"
  11240. loc, _ := time.LoadLocation("Local")
  11241. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11242. project.RecordDate = theTime.Unix()
  11243. projectList = append(projectList, &project)
  11244. }
  11245. export_time := time.Now().Unix()
  11246. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11247. if len(projectList) > 0 {
  11248. for _, item := range projectList {
  11249. hans := item.ProjectName // 要转换的汉字字符串
  11250. // 创建一个拼音转换器
  11251. p := pinyin.NewArgs()
  11252. // 将汉字转为拼音
  11253. pinyinSlice := pinyin.Pinyin(hans, p)
  11254. // 输出拼音
  11255. fmt.Println("Pinyin:", pinyinSlice)
  11256. // 获取首字母
  11257. firstLetter := ""
  11258. for _, py := range pinyinSlice {
  11259. if len(py) > 0 {
  11260. firstLetter += string(py[0][0])
  11261. }
  11262. }
  11263. item.FirstLetter = firstLetter
  11264. project := models.HisProject{
  11265. ProjectName: item.ProjectName,
  11266. Price: item.Price,
  11267. Unit: item.Unit,
  11268. CostClassify: item.CostClassify,
  11269. ExecutiveSection: item.ExecutiveSection,
  11270. MedicalCoverage: item.MedicalCoverage,
  11271. UserOrgId: orgId,
  11272. Status: 1,
  11273. CreatedTime: time.Now().Unix(),
  11274. Pinyin: item.Pinyin,
  11275. Wubi: item.Wubi,
  11276. StatisticalClassification: item.StatisticalClassification,
  11277. DiseaseDirectory: item.DiseaseDirectory,
  11278. IsRecord: item.IsRecord,
  11279. MedicalCode: item.MedicalCode,
  11280. TubeColor: item.TubeColor,
  11281. SingleDose: item.SingleDose,
  11282. DeliveryWay: item.DeliveryWay,
  11283. NumberDays: item.NumberDays,
  11284. Total: item.Total,
  11285. Category: item.Category,
  11286. MedicalStatus: item.MedicalStatus,
  11287. SpecailProject: item.SpecailProject,
  11288. RecordDate: item.RecordDate,
  11289. Remark: item.Remark,
  11290. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11291. ExecutionFrequency: item.ExecutionFrequency,
  11292. FirstLetter: item.FirstLetter,
  11293. }
  11294. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11295. if errcodeproject == gorm.ErrRecordNotFound {
  11296. service.CreateProjectInfomation(&project)
  11297. } else if errcodeproject == nil {
  11298. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11299. }
  11300. log := models.ExportLog{
  11301. LogType: 6,
  11302. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11303. TotalNum: int64(len(total_goods)),
  11304. FailNum: int64(len(errLogs)),
  11305. SuccessNum: int64(len(projectList)),
  11306. CreateTime: time.Now().Unix(),
  11307. UpdateTime: time.Now().Unix(),
  11308. ExportTime: export_time,
  11309. Status: 1,
  11310. }
  11311. service.CreateExportLog(&log)
  11312. c.ServeSuccessJSON(map[string]interface{}{
  11313. "msg": "导入成功",
  11314. "total_num": len(total_goods),
  11315. "success_num": len(projectList),
  11316. "fail_num": int64(len(errLogs)),
  11317. })
  11318. }
  11319. } else {
  11320. log := models.ExportLog{
  11321. LogType: 6,
  11322. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11323. TotalNum: int64(len(total_goods)),
  11324. FailNum: int64(len(errLogs)),
  11325. SuccessNum: int64(len(projectList)),
  11326. CreateTime: time.Now().Unix(),
  11327. UpdateTime: time.Now().Unix(),
  11328. ExportTime: export_time,
  11329. Status: 1,
  11330. }
  11331. service.CreateExportLog(&log)
  11332. c.ServeSuccessJSON(map[string]interface{}{
  11333. "msg": "导入成功",
  11334. "total_num": len(total_goods),
  11335. "success_num": len(projectList),
  11336. "fail_num": int64(len(errLogs)),
  11337. })
  11338. }
  11339. }
  11340. //func (this *HisApiController) EditProjectInformation(){
  11341. //
  11342. // id, _ := this.GetInt64("id")
  11343. // project_team := this.GetString("project_team")
  11344. // price := this.GetString("price")
  11345. // price_float, _ := strconv.ParseFloat(price, 64)
  11346. // pinyin := this.GetString("pinyin")
  11347. // wubi := this.GetString("wubi")
  11348. // tube_color, _ := this.GetInt64("tube_color")
  11349. // team_type, _ := this.GetInt64("team_type")
  11350. // remark := this.GetString("remark")
  11351. // ids := this.GetString("ids")
  11352. // item_id := this.GetString("item_id")
  11353. // projectTeam := models.XtHisProjectTeam{
  11354. // ProjectTeam: project_team,
  11355. // Price: price_float,
  11356. // Pinyin: pinyin,
  11357. // Wubi: wubi,
  11358. // TubeColor: tube_color,
  11359. // TeamType: team_type,
  11360. // Remark: remark,
  11361. // ProjectId: ids,
  11362. // ItemId: item_id,
  11363. // }
  11364. //
  11365. //
  11366. // dataBody := make(map[string]interface{}, 0)
  11367. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11368. // if err != nil {
  11369. // utils.ErrorLog(err.Error())
  11370. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11371. // return
  11372. // }
  11373. //
  11374. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11375. //
  11376. //
  11377. // if err != nil {
  11378. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11379. // return
  11380. // }
  11381. //
  11382. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11383. // infos, _ := dataBody["info"].([]interface{})
  11384. // if len(infos) > 0 {
  11385. // var ids []string
  11386. //
  11387. // for _, item := range infos {
  11388. // items := item.(map[string]interface{})
  11389. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11390. // utils.ErrorLog("id")
  11391. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11392. // return
  11393. // }
  11394. // id := int64(items["id"].(float64))
  11395. //
  11396. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11397. // utils.ErrorLog("type")
  11398. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11399. // return
  11400. // }
  11401. // types := int64(items["type"].(float64))
  11402. //
  11403. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11404. // utils.ErrorLog("number")
  11405. // }
  11406. //
  11407. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11408. //
  11409. // projectList := models.XtHisProjectList{
  11410. // Number: number,
  11411. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11412. // ProjectId: id,
  11413. // Status: 1,
  11414. // CreatedTime: time.Now().Unix(),
  11415. // UpdatedTime: time.Now().Unix(),
  11416. // TeamId: projectTeam.ID,
  11417. // Type: types,
  11418. // }
  11419. // list := projectList
  11420. //
  11421. // service.CreateProjectList(&list)
  11422. //
  11423. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11424. //
  11425. // }
  11426. // ids_str := strings.Join(ids, ",")
  11427. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11428. // service.SaveProjectTeam(&projectTeam)
  11429. // this.ServeSuccessJSON(map[string]interface{}{
  11430. // "projectTeam": projectTeam,
  11431. // })
  11432. // }
  11433. // }
  11434. //}
  11435. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11436. name := c.GetString("name")
  11437. mode_id, _ := c.GetInt64("mode", 0)
  11438. types, _ := c.GetInt64("type", 0)
  11439. patient_id, _ := c.GetInt64("patient_id", 0)
  11440. types = 1
  11441. adminInfo := c.GetAdminUserInfo()
  11442. template := &models.HisPrescriptionTemplate{
  11443. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11444. PatientId: patient_id,
  11445. Type: types,
  11446. Status: 1,
  11447. Ctime: time.Now().Unix(),
  11448. Mtime: time.Now().Unix(),
  11449. Name: name,
  11450. Mode: mode_id,
  11451. }
  11452. dataBody := make(map[string]interface{}, 0)
  11453. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11454. if err != nil {
  11455. utils.ErrorLog(err.Error())
  11456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11457. return
  11458. }
  11459. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11460. //如果已经存在记录则删除处方
  11461. if template_one.ID > 0 {
  11462. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11463. var ids []int64
  11464. var org_id int64
  11465. for _, item := range ps {
  11466. org_id = c.GetAdminUserInfo().CurrentOrgId
  11467. ids = append(ids, item.ID)
  11468. }
  11469. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11470. if err2 == nil {
  11471. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11472. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11473. if len(prescriptions) > 0 {
  11474. for _, item := range prescriptions {
  11475. items := item.(map[string]interface{})
  11476. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11477. utils.ErrorLog("type")
  11478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11479. return
  11480. }
  11481. types := int64(items["type"].(float64))
  11482. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11483. utils.ErrorLog("med_type")
  11484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11485. return
  11486. }
  11487. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11488. ctime := time.Now().Unix()
  11489. prescription := &models.HisPrescriptionInfoTemplate{
  11490. PatientId: patient_id,
  11491. UserOrgId: adminInfo.CurrentOrgId,
  11492. Ctime: ctime,
  11493. Mtime: ctime,
  11494. Type: types,
  11495. Modifier: adminInfo.AdminUser.Id,
  11496. Creator: adminInfo.AdminUser.Id,
  11497. Status: 1,
  11498. PTemplateId: template_one.ID,
  11499. MedType: med_type,
  11500. }
  11501. service.CreateHisPrescriptionInfoTemplate(prescription)
  11502. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11503. advices := items["advices"].([]interface{})
  11504. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11505. ctime := time.Now().Unix()
  11506. mtime := ctime
  11507. if len(advices) > 0 {
  11508. for _, advice := range advices {
  11509. var s models.HisPrescriptionAdviceTemplate
  11510. s.PrescriptionId = prescription.ID
  11511. s.AdviceType = 2
  11512. s.StopState = 2
  11513. s.ExecutionState = 2
  11514. s.Status = 1
  11515. s.UserOrgId = adminInfo.CurrentOrgId
  11516. s.CreatedTime = ctime
  11517. s.UpdatedTime = mtime
  11518. s.PatientId = patient_id
  11519. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11520. if errcode > 0 {
  11521. c.ServeFailJSONWithSGJErrorCode(errcode)
  11522. return
  11523. }
  11524. service.CreateHisPrescriptionAdviceTemplate(&s)
  11525. }
  11526. }
  11527. }
  11528. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11529. projects := items["project"].([]interface{})
  11530. if len(projects) > 0 {
  11531. for _, project := range projects {
  11532. var p models.HisPrescriptionProjectTemplate
  11533. p.PrescriptionId = prescription.ID
  11534. p.Ctime = time.Now().Unix()
  11535. p.Mtime = time.Now().Unix()
  11536. p.PatientId = patient_id
  11537. p.UserOrgId = adminInfo.CurrentOrgId
  11538. p.Status = 1
  11539. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11540. if errcode > 0 {
  11541. c.ServeFailJSONWithSGJErrorCode(errcode)
  11542. return
  11543. }
  11544. service.CreateHisPrescriptionProjectTemplate(&p)
  11545. }
  11546. }
  11547. }
  11548. }
  11549. c.ServeSuccessJSON(map[string]interface{}{
  11550. "msg": "创建成功",
  11551. })
  11552. }
  11553. }
  11554. } else {
  11555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11556. return
  11557. }
  11558. } else {
  11559. err3 := service.CreateHisPrescriptionTemplate(template)
  11560. if err3 == nil {
  11561. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11562. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11563. if len(prescriptions) > 0 {
  11564. for _, item := range prescriptions {
  11565. items := item.(map[string]interface{})
  11566. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11567. utils.ErrorLog("type")
  11568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11569. return
  11570. }
  11571. types := int64(items["type"].(float64))
  11572. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11573. utils.ErrorLog("med_type")
  11574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11575. return
  11576. }
  11577. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11578. ctime := time.Now().Unix()
  11579. prescription := &models.HisPrescriptionInfoTemplate{
  11580. PatientId: patient_id,
  11581. UserOrgId: adminInfo.CurrentOrgId,
  11582. Ctime: ctime,
  11583. Mtime: ctime,
  11584. Type: types,
  11585. Modifier: adminInfo.AdminUser.Id,
  11586. Creator: adminInfo.AdminUser.Id,
  11587. Status: 1,
  11588. PTemplateId: template.ID,
  11589. MedType: med_type,
  11590. }
  11591. service.CreateHisPrescriptionInfoTemplate(prescription)
  11592. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11593. advices := items["advices"].([]interface{})
  11594. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11595. ctime := time.Now().Unix()
  11596. mtime := ctime
  11597. if len(advices) > 0 {
  11598. for _, advice := range advices {
  11599. var s models.HisPrescriptionAdviceTemplate
  11600. s.PrescriptionId = prescription.ID
  11601. s.AdviceType = 2
  11602. s.StopState = 2
  11603. s.ExecutionState = 2
  11604. s.Status = 1
  11605. s.UserOrgId = adminInfo.CurrentOrgId
  11606. s.CreatedTime = ctime
  11607. s.UpdatedTime = mtime
  11608. s.PatientId = patient_id
  11609. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11610. if errcode > 0 {
  11611. c.ServeFailJSONWithSGJErrorCode(errcode)
  11612. return
  11613. }
  11614. service.CreateHisPrescriptionAdviceTemplate(&s)
  11615. }
  11616. }
  11617. }
  11618. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11619. projects := items["project"].([]interface{})
  11620. if len(projects) > 0 {
  11621. for _, project := range projects {
  11622. var p models.HisPrescriptionProjectTemplate
  11623. p.PrescriptionId = prescription.ID
  11624. p.Ctime = time.Now().Unix()
  11625. p.Mtime = time.Now().Unix()
  11626. p.PatientId = patient_id
  11627. p.UserOrgId = adminInfo.CurrentOrgId
  11628. p.Status = 1
  11629. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11630. if errcode > 0 {
  11631. c.ServeFailJSONWithSGJErrorCode(errcode)
  11632. return
  11633. }
  11634. service.CreateHisPrescriptionProjectTemplate(&p)
  11635. }
  11636. }
  11637. }
  11638. }
  11639. c.ServeSuccessJSON(map[string]interface{}{
  11640. "msg": "创建成功",
  11641. })
  11642. }
  11643. }
  11644. } else {
  11645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11646. return
  11647. }
  11648. }
  11649. }
  11650. func (c *HisApiController) PreSettle() {
  11651. id, _ := c.GetInt64("id")
  11652. record_time := c.GetString("record_time")
  11653. his_patient_id, _ := c.GetInt64("his_patient_id")
  11654. timeLayout := "2006-01-02"
  11655. loc, _ := time.LoadLocation("Local")
  11656. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11657. diagnosis_id := c.GetString("diagnosis")
  11658. sick_type, _ := c.GetInt64("sick_type")
  11659. reg_type, _ := c.GetInt64("p_type")
  11660. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11662. if err != nil {
  11663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11664. return
  11665. }
  11666. recordDateTime := theTime.Unix()
  11667. adminUser := c.GetAdminUserInfo()
  11668. var prescriptions []*models.HisPrescription
  11669. var start_time int64
  11670. var end_time int64
  11671. ids_str := c.GetString("ids")
  11672. ids_arr := strings.Split(ids_str, ",")
  11673. fmt.Println(reg_type)
  11674. if settle_accounts_type == 1 { //日结
  11675. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11676. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11677. } else {
  11678. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11679. }
  11680. fmt.Println(prescriptions)
  11681. } else { //月结
  11682. start_time_str := c.GetString("start_time")
  11683. end_time_str := c.GetString("end_time")
  11684. timeLayout := "2006-01-02"
  11685. loc, _ := time.LoadLocation("Local")
  11686. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11687. if err != nil {
  11688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11689. return
  11690. }
  11691. recordStartTime := theStartTime.Unix()
  11692. start_time = recordStartTime
  11693. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11694. if err != nil {
  11695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11696. return
  11697. }
  11698. recordEndTime := theEndTime.Unix()
  11699. end_time = recordEndTime
  11700. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11701. }
  11702. if reg_type == 1111 || reg_type == 1112 {
  11703. reg_type = 11
  11704. }
  11705. timestamp := time.Now().Unix()
  11706. tempTime := time.Unix(timestamp, 0)
  11707. timeFormat := tempTime.Format("20060102150405")
  11708. chrgBchno := rand.Intn(100000) + 10000
  11709. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11710. strconv.FormatInt(his.PatientId, 10)
  11711. var ids []int64
  11712. for _, item := range prescriptions {
  11713. ids = append(ids, item.ID)
  11714. }
  11715. fmt.Println(ids)
  11716. var total float64
  11717. for _, item := range prescriptions {
  11718. fmt.Println(item)
  11719. if item.Type == 1 { //药品
  11720. for _, subItem := range item.HisDoctorAdviceInfo {
  11721. total = total + (subItem.Price * subItem.PrescribingNumber)
  11722. }
  11723. }
  11724. if item.Type == 2 { //项目
  11725. for _, subItem := range item.HisPrescriptionProject {
  11726. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11727. total = total + (subItem.Price * cnt)
  11728. }
  11729. }
  11730. for _, subItem := range item.HisAdditionalCharge {
  11731. total = total + (subItem.Price * float64(subItem.Count))
  11732. }
  11733. }
  11734. allTotal := fmt.Sprintf("%.2f", total)
  11735. totals, _ := strconv.ParseFloat(allTotal, 64)
  11736. order := &models.HisOrder{
  11737. UserOrgId: adminUser.CurrentOrgId,
  11738. HisPatientId: his.ID,
  11739. PatientId: id,
  11740. SettleAccountsDate: recordDateTime,
  11741. Ctime: time.Now().Unix(),
  11742. Mtime: time.Now().Unix(),
  11743. Status: 1,
  11744. OrderStatus: 1,
  11745. MdtrtId: his.Number,
  11746. Number: chrg_bchno,
  11747. MedfeeSumamt: totals,
  11748. SettleEndTime: end_time,
  11749. SettleStartTime: start_time,
  11750. SettleType: settle_accounts_type,
  11751. PsnPartAmt: totals,
  11752. PsnCashPay: totals,
  11753. PType: 2,
  11754. IsPre: 1,
  11755. MedType: strconv.Itoa(int(reg_type)),
  11756. Diagnosis: diagnosis_id,
  11757. }
  11758. err = service.CreateOrder(order)
  11759. if err != nil {
  11760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11761. return
  11762. }
  11763. var customs []*Custom
  11764. for _, item := range prescriptions {
  11765. fmt.Println(item.Type)
  11766. if item.Type == 1 { //药品
  11767. for _, subItem := range item.HisDoctorAdviceInfo {
  11768. cus := &Custom{
  11769. AdviceId: subItem.ID,
  11770. ProjectId: 0,
  11771. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11772. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11773. FeedetlSn: subItem.FeedetlSn,
  11774. Price: fmt.Sprintf("%.2f", subItem.Price),
  11775. MedListCodg: subItem.MedListCodg,
  11776. Type: 1,
  11777. }
  11778. customs = append(customs, cus)
  11779. }
  11780. }
  11781. if item.Type == 2 { //项目
  11782. for _, subItem := range item.HisPrescriptionProject {
  11783. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11784. cus := &Custom{
  11785. AdviceId: 0,
  11786. ProjectId: subItem.ID,
  11787. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11788. Cut: fmt.Sprintf("%.2f", cnt),
  11789. FeedetlSn: subItem.FeedetlSn,
  11790. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11791. MedListCodg: subItem.MedListCodg,
  11792. Type: 2,
  11793. }
  11794. customs = append(customs, cus)
  11795. }
  11796. }
  11797. for _, item := range item.HisAdditionalCharge {
  11798. cus := &Custom{
  11799. ItemId: item.ID,
  11800. AdviceId: 0,
  11801. ProjectId: 0,
  11802. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11803. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11804. FeedetlSn: item.FeedetlSn,
  11805. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11806. MedListCodg: item.XtHisAddtionConfig.Code,
  11807. Type: 3,
  11808. }
  11809. customs = append(customs, cus)
  11810. }
  11811. }
  11812. fmt.Println(customs)
  11813. for _, item := range customs {
  11814. var advice_id int64 = 0
  11815. var project_id int64 = 0
  11816. var item_id int64 = 0
  11817. var types int64 = 0
  11818. if item.Type == 1 {
  11819. advice_id = item.AdviceId
  11820. project_id = 0
  11821. item_id = 0
  11822. } else if item.Type == 2 {
  11823. advice_id = 0
  11824. item_id = 0
  11825. project_id = item.ProjectId
  11826. } else if item.Type == 3 {
  11827. advice_id = 0
  11828. item_id = item.ItemId
  11829. project_id = 0
  11830. }
  11831. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11832. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11833. pric, _ := strconv.ParseFloat(item.Price, 32)
  11834. info := &models.HisOrderInfo{
  11835. OrderNumber: order.Number,
  11836. UploadDate: time.Now().Unix(),
  11837. AdviceId: advice_id,
  11838. DetItemFeeSumamt: detItemFeeSumamt,
  11839. Cnt: cut,
  11840. Pric: pric,
  11841. PatientId: id,
  11842. Status: 1,
  11843. Mtime: time.Now().Unix(),
  11844. Ctime: time.Now().Unix(),
  11845. UserOrgId: adminUser.CurrentOrgId,
  11846. HisPatientId: his.ID,
  11847. OrderId: order.ID,
  11848. ProjectId: project_id,
  11849. Type: types,
  11850. ItemId: item_id,
  11851. }
  11852. service.CreateOrderInfo(info)
  11853. }
  11854. his.SickType = sick_type
  11855. service.UpdataHisPateint(&his)
  11856. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11857. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11858. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11859. if err == nil {
  11860. c.ServeSuccessJSON(map[string]interface{}{
  11861. "msg": "结算成功",
  11862. })
  11863. }
  11864. }
  11865. type CustomOrderInfo struct {
  11866. Name string
  11867. Spec string
  11868. Unit string
  11869. Count float64
  11870. Price float64
  11871. Total float64
  11872. }
  11873. func (c *HisApiController) GetPrivateExpensesInfo() {
  11874. order_id, _ := c.GetInt64("id", 0)
  11875. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11876. order, _ := service.GetHisOrderByID(order_id)
  11877. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11878. if order.ID == 0 {
  11879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11880. return
  11881. }
  11882. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11883. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11884. org_id := c.GetAdminUserInfo().CurrentOrgId
  11885. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11886. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11887. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11888. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11889. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11890. //var orderInfos_four []*models.HisOrderInfoTwo
  11891. //for _, item := range orderInfos_three {
  11892. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11893. // item.HisPrescriptionProject.IsCheckTeam = 1
  11894. // orderInfos_four = append(orderInfos_four, item)
  11895. //
  11896. // }
  11897. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11898. // item.HisPrescriptionProject.IsCheckTeam = 2
  11899. // orderInfos_two = append(orderInfos_two, item)
  11900. // }
  11901. //}
  11902. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11903. //var cus_slice []CustomOrderInfo
  11904. //for _, item := range new_order_info {
  11905. // var cus CustomOrderInfo
  11906. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11907. // cus.Unit = ""
  11908. // cus.Spec = ""
  11909. // var total float64
  11910. // for _, subItem := range orderInfos_four {
  11911. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11912. // total = total + subItem.DetItemFeeSumamt
  11913. // fmt.Println(subItem.DetItemFeeSumamt)
  11914. // }
  11915. // }
  11916. // cus.Count = 1
  11917. // cus.Total = total
  11918. // cus_slice = append(cus_slice, cus)
  11919. //}
  11920. orderInfos = append(orderInfos, orderInfos_two...)
  11921. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11922. //orderInfos = append(orderInfos, orderInfos_three...)
  11923. //}/**/
  11924. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11925. c.ServeSuccessJSON(map[string]interface{}{
  11926. "order": order,
  11927. "order_info": orderInfos,
  11928. "patient": patient,
  11929. "admin_info": adminInfo,
  11930. "his": his,
  11931. "current_admin": role,
  11932. "org_config": miConfig,
  11933. //"new_order_info": cus_slice,
  11934. })
  11935. }
  11936. func (this *HisApiController) ChangeMedType() {
  11937. med_type := this.GetString("med_type")
  11938. old_med_type := this.GetString("old_med_type")
  11939. ids := this.GetString("ids")
  11940. settle_type, _ := this.GetInt64("settle_type")
  11941. start_time := this.GetString("start_time")
  11942. end_time := this.GetString("end_time")
  11943. ids_arr := strings.Split(ids, ",")
  11944. if settle_type == 1 { //日结
  11945. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11946. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11947. prescription.MedType = med_type
  11948. err := service.SaveHisPrescriptionTwo(&prescription)
  11949. if err == nil {
  11950. this.ServeSuccessJSON(map[string]interface{}{
  11951. "msg": "修改成功",
  11952. })
  11953. } else {
  11954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11955. return
  11956. }
  11957. } else if settle_type == 2 {
  11958. timeLayout := "2006-01-02"
  11959. loc, _ := time.LoadLocation("Local")
  11960. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11961. if err != nil {
  11962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11963. return
  11964. }
  11965. recordStartTime := theStartTime.Unix()
  11966. start_time_timestamp := recordStartTime
  11967. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11968. if err != nil {
  11969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11970. return
  11971. }
  11972. recordEndTime := theEndTime.Unix()
  11973. end_time_timestamp := recordEndTime
  11974. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11975. if updateErr == nil {
  11976. this.ServeSuccessJSON(map[string]interface{}{
  11977. "msg": "修改成功",
  11978. })
  11979. } else {
  11980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11981. return
  11982. }
  11983. }
  11984. }
  11985. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11986. patient_id, _ := c.GetInt64("patient_id")
  11987. his_patient_id, _ := c.GetInt64("his_patient_id")
  11988. record_date := c.GetString("record_date")
  11989. start_time := c.GetString("start_time")
  11990. end_time := c.GetString("end_time")
  11991. order_status, _ := c.GetInt64("type", 0)
  11992. p_type, _ := c.GetInt64("p_type", 0)
  11993. order_id, _ := c.GetInt64("order_id", 0)
  11994. timeLayout := "2006-01-02"
  11995. loc, _ := time.LoadLocation("Local")
  11996. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11997. if err != nil {
  11998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11999. return
  12000. }
  12001. recordDateTime := theTime.Unix()
  12002. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12003. if err != nil {
  12004. }
  12005. startRecordDateTime := startTime.Unix()
  12006. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12007. if err != nil {
  12008. }
  12009. endRecordDateTime := endTime.Unix()
  12010. admin := c.GetAdminUserInfo()
  12011. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12012. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12013. order, _ := service.GetHisOrderByID(order_id)
  12014. var monthPrescriptions []*models.HisPrescription
  12015. if order_status == 1 || order_status == 0 {
  12016. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12017. } else if order_status == 2 {
  12018. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12019. }
  12020. var settle_total float64
  12021. for _, item := range monthPrescriptions {
  12022. if len(item.HisPrescriptionProject) > 0 {
  12023. for _, subItem := range item.HisPrescriptionProject {
  12024. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12025. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12026. settle_total = settle_total + total
  12027. }
  12028. }
  12029. if len(item.HisDoctorAdviceInfo) > 0 {
  12030. for _, subItem := range item.HisDoctorAdviceInfo {
  12031. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12032. settle_total = settle_total + total
  12033. }
  12034. }
  12035. }
  12036. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12037. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12038. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12039. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12040. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12041. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12042. //获取所有科室信息
  12043. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12044. var dia string
  12045. for _, item := range month_p_info {
  12046. if len(dia) == 0 {
  12047. dia = item.Diagnosis
  12048. } else {
  12049. dia = dia + "," + item.Diagnosis
  12050. }
  12051. }
  12052. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12053. dia_arr = removeEmptyStrings(dia_arr)
  12054. c.ServeSuccessJSON(map[string]interface{}{
  12055. "his_info": his_patient_info,
  12056. "xt_info": xt_patient_info,
  12057. "case_history": case_history,
  12058. "info": patientPrescriptionInfo,
  12059. "last_info": lastPatientPrescriptionInfo,
  12060. "month_prescriptions": monthPrescriptions,
  12061. "order": order,
  12062. "doctors": doctors,
  12063. "department": department,
  12064. "settle_total": settle_total,
  12065. "dia_arr": dia_arr,
  12066. })
  12067. return
  12068. }
  12069. func removeEmptyStrings(input []string) []string {
  12070. var output []string
  12071. for _, s := range input {
  12072. if s != "" {
  12073. output = append(output, s)
  12074. }
  12075. }
  12076. return output
  12077. }
  12078. func removeDuplicates(input []string) []string {
  12079. seen := make(map[string]bool)
  12080. output := []string{}
  12081. for _, s := range input {
  12082. if _, exists := seen[s]; !exists {
  12083. seen[s] = true
  12084. output = append(output, s)
  12085. }
  12086. }
  12087. return output
  12088. }
  12089. func (c *HisApiController) GetHisMonthPatientInfo() {
  12090. patient_id, _ := c.GetInt64("patient_id")
  12091. his_patient_id, _ := c.GetInt64("his_patient_id")
  12092. record_date := c.GetString("record_date")
  12093. number := c.GetString("number")
  12094. start_time := c.GetString("start_time")
  12095. end_time := c.GetString("end_time")
  12096. p_type, _ := c.GetInt64("p_type")
  12097. timeLayout := "2006-01-02"
  12098. loc, _ := time.LoadLocation("Local")
  12099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12100. if err != nil {
  12101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12102. return
  12103. }
  12104. recordDateTime := theTime.Unix()
  12105. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12106. if err != nil {
  12107. }
  12108. startRecordDateTime := startTime.Unix()
  12109. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12110. if err != nil {
  12111. }
  12112. endRecordDateTime := endTime.Unix()
  12113. admin := c.GetAdminUserInfo()
  12114. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12115. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12116. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12117. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12118. var settle_total float64
  12119. for _, item := range monthPrescriptions {
  12120. if len(item.HisPrescriptionProject) > 0 {
  12121. for _, subItem := range item.HisPrescriptionProject {
  12122. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12123. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12124. settle_total = settle_total + total
  12125. }
  12126. }
  12127. if len(item.HisDoctorAdviceInfo) > 0 {
  12128. for _, subItem := range item.HisDoctorAdviceInfo {
  12129. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12130. settle_total = settle_total + total
  12131. }
  12132. }
  12133. }
  12134. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12135. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12136. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12137. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12138. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12139. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12140. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12141. //获取所有科室信息
  12142. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12143. c.ServeSuccessJSON(map[string]interface{}{
  12144. "his_info": his_patient_info,
  12145. "xt_info": xt_patient_info,
  12146. "case_history": case_history,
  12147. "info": patientPrescriptionInfo,
  12148. "month_prescriptions": monthPrescriptions,
  12149. "order": order,
  12150. "doctors": doctors,
  12151. "department": department,
  12152. "count": count,
  12153. "drugStockConfig": drugStockConfig,
  12154. "last_info": lastPatientPrescriptionInfo,
  12155. "settle_total": settle_total,
  12156. })
  12157. return
  12158. }
  12159. func (c *HisApiController) GetAllOrder() {
  12160. org_id := c.GetAdminUserInfo().CurrentOrgId
  12161. orders, _ := service.GetNewHisOrderList(org_id)
  12162. c.ServeSuccessJSON(map[string]interface{}{
  12163. "order": orders,
  12164. })
  12165. return
  12166. }
  12167. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12168. newArr = make([]*models.HisOrderInfoTwo, 0)
  12169. for i := 0; i < len(arr); i++ {
  12170. repeat := false
  12171. for j := i + 1; j < len(arr); j++ {
  12172. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12173. repeat = true
  12174. break
  12175. }
  12176. }
  12177. if !repeat {
  12178. newArr = append(newArr, arr[i])
  12179. }
  12180. }
  12181. return
  12182. }
  12183. // 修改处方退库操作 参数传修改之前的处方数据
  12184. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12185. if advice.ExecutionState == 1 {
  12186. //查询该病人该药品是否有库存记录
  12187. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12188. if errcode == gorm.ErrRecordNotFound {
  12189. } else {
  12190. //退库
  12191. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12192. if advice.PrescribingNumberUnit == drug.MinUnit {
  12193. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12194. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12195. //退库
  12196. warehouseInfo := models.DrugWarehouseInfo{
  12197. StockMinNumber: prescribingNumber,
  12198. }
  12199. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12200. operation_time := time.Now().Unix()
  12201. creater := advice.AdviceDoctor
  12202. ctime := time.Now().Unix()
  12203. timeStr := time.Now().Format("2006-01-02")
  12204. timeArr := strings.Split(timeStr, "-")
  12205. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12206. total = total + 1
  12207. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12208. cancelStock := models.DrugCancelStock{
  12209. OrderNumber: orderNumber,
  12210. OperaTime: operation_time,
  12211. OrgId: advice.UserOrgId,
  12212. Creater: creater,
  12213. Ctime: ctime,
  12214. Status: 1,
  12215. ReturnTime: advice.AdviceDate,
  12216. Dealer: info.Dealer,
  12217. Manufacturer: info.Manufacturer,
  12218. Type: 1,
  12219. }
  12220. service.AddSigleDrugCancelStock(&cancelStock)
  12221. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12222. dealer, _ := service.GetDealerById(info.Dealer)
  12223. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12224. cancelStockInfo := models.DrugCancelStockInfo{
  12225. OrderNumber: cancelInfo.OrderNumber,
  12226. CancelStockId: cancelInfo.ID,
  12227. DrugId: info.DrugId,
  12228. Count: info.Count,
  12229. Status: 1,
  12230. Ctime: ctime,
  12231. OrgId: advice.UserOrgId,
  12232. Type: 1,
  12233. Manufacturer: manufactureName.ManufacturerName,
  12234. Dealer: dealer.DealerName,
  12235. Total: 0,
  12236. RetailPrice: info.RetailPrice,
  12237. RetailTotalPrice: info.RetailTotalPrice,
  12238. Price: info.Price,
  12239. RegisterAccount: "",
  12240. Remark: info.Remark,
  12241. BatchNumber: info.BatchNumber,
  12242. MaxUnit: info.CountUnit,
  12243. ProductDate: info.ProductDate,
  12244. ExpiryDate: info.ExpiryDate,
  12245. BatchNumberId: info.WarehouseInfoId,
  12246. }
  12247. flow := models.DrugFlow{
  12248. WarehousingId: 0,
  12249. DrugId: info.DrugId,
  12250. Number: "",
  12251. BatchNumber: info.BatchNumber,
  12252. Count: info.Count,
  12253. UserOrgId: advice.UserOrgId,
  12254. PatientId: 0,
  12255. SystemTime: ctime,
  12256. ConsumableType: 4,
  12257. IsSys: 0,
  12258. WarehousingOrder: "",
  12259. WarehouseOutId: 0,
  12260. WarehouseOutOrderNumber: "",
  12261. IsEdit: 0,
  12262. CancelStockId: cancelStock.ID,
  12263. CancelOrderNumber: cancelStock.OrderNumber,
  12264. Manufacturer: info.Manufacturer,
  12265. Dealer: info.Dealer,
  12266. Creator: advice.UserOrgId,
  12267. UpdateCreator: 0,
  12268. Status: 1,
  12269. Ctime: time.Now().Unix(),
  12270. Mtime: 0,
  12271. Price: info.Price,
  12272. WarehousingDetailId: 0,
  12273. WarehouseOutDetailId: 0,
  12274. CancelOutDetailId: 0,
  12275. ExpireDate: info.ExpiryDate,
  12276. ProductDate: info.ProductDate,
  12277. MaxUnit: info.CountUnit,
  12278. MinUnit: "",
  12279. }
  12280. service.CreatedCancelStock(cancelStockInfo)
  12281. service.CreateDrugFlowOne(flow)
  12282. } else {
  12283. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12284. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12285. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12286. warehouseInfo := models.DrugWarehouseInfo{
  12287. StockMinNumber: prescribingNumber,
  12288. }
  12289. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12290. }
  12291. operation_time := time.Now().Unix()
  12292. creater := advice.AdviceDoctor
  12293. ctime := time.Now().Unix()
  12294. timeStr := time.Now().Format("2006-01-02")
  12295. timeArr := strings.Split(timeStr, "-")
  12296. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12297. total = total + 1
  12298. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12299. cancelStock := models.DrugCancelStock{
  12300. OrderNumber: orderNumber,
  12301. OperaTime: operation_time,
  12302. OrgId: advice.UserOrgId,
  12303. Creater: creater,
  12304. Ctime: ctime,
  12305. Status: 1,
  12306. ReturnTime: advice.AdviceDate,
  12307. Dealer: info.Dealer,
  12308. Manufacturer: info.Manufacturer,
  12309. Type: 1,
  12310. }
  12311. service.AddSigleDrugCancelStock(&cancelStock)
  12312. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12313. dealer, _ := service.GetDealerById(info.Dealer)
  12314. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12315. cancelStockInfo := models.DrugCancelStockInfo{
  12316. OrderNumber: cancelInfo.OrderNumber,
  12317. CancelStockId: cancelInfo.ID,
  12318. DrugId: info.DrugId,
  12319. Count: info.Count,
  12320. Status: 1,
  12321. Ctime: ctime,
  12322. OrgId: advice.UserOrgId,
  12323. Type: 1,
  12324. Manufacturer: manufactureName.ManufacturerName,
  12325. Dealer: dealer.DealerName,
  12326. Total: 0,
  12327. RetailPrice: info.RetailPrice,
  12328. RetailTotalPrice: info.RetailTotalPrice,
  12329. Price: info.Price,
  12330. RegisterAccount: "",
  12331. Remark: info.Remark,
  12332. BatchNumber: info.BatchNumber,
  12333. MaxUnit: info.CountUnit,
  12334. ProductDate: info.ProductDate,
  12335. ExpiryDate: info.ExpiryDate,
  12336. BatchNumberId: info.WarehouseInfoId,
  12337. }
  12338. flow := models.DrugFlow{
  12339. WarehousingId: 0,
  12340. DrugId: info.DrugId,
  12341. Number: "",
  12342. BatchNumber: info.BatchNumber,
  12343. Count: info.Count,
  12344. UserOrgId: advice.UserOrgId,
  12345. PatientId: 0,
  12346. SystemTime: ctime,
  12347. ConsumableType: 4,
  12348. IsSys: 0,
  12349. WarehousingOrder: "",
  12350. WarehouseOutId: 0,
  12351. WarehouseOutOrderNumber: "",
  12352. IsEdit: 0,
  12353. CancelStockId: cancelStock.ID,
  12354. CancelOrderNumber: cancelStock.OrderNumber,
  12355. Manufacturer: info.Manufacturer,
  12356. Dealer: info.Dealer,
  12357. Creator: advice.AdviceDoctor,
  12358. UpdateCreator: 0,
  12359. Status: 1,
  12360. Ctime: time.Now().Unix(),
  12361. Mtime: 0,
  12362. Price: info.Price,
  12363. WarehousingDetailId: 0,
  12364. WarehouseOutDetailId: 0,
  12365. CancelOutDetailId: 0,
  12366. ExpireDate: info.ExpiryDate,
  12367. ProductDate: info.ProductDate,
  12368. MaxUnit: info.CountUnit,
  12369. MinUnit: "",
  12370. }
  12371. service.CreatedCancelStock(cancelStockInfo)
  12372. service.CreateDrugFlowOne(flow)
  12373. }
  12374. }
  12375. }
  12376. return err
  12377. }
  12378. func (this *HisApiController) DeleteNCDS() {
  12379. id, _ := this.GetInt64("id", 0)
  12380. if id > 0 {
  12381. service.DeletePsnNCDSRecordById(id)
  12382. this.ServeSuccessJSON(map[string]interface{}{
  12383. "msg": "删除成功",
  12384. })
  12385. } else {
  12386. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12387. return
  12388. }
  12389. }
  12390. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12391. id, _ := c.GetInt64("id")
  12392. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12393. c.ServeSuccessJSON(map[string]interface{}{
  12394. "advice": advice,
  12395. })
  12396. return
  12397. }
  12398. func (c *HisApiController) GetHisMonthChargePatientList() {
  12399. record_date := c.GetString("record_date")
  12400. start_time := c.GetString("start_time")
  12401. end_time := c.GetString("end_time")
  12402. timeLayout := "2006-01-02"
  12403. loc, _ := time.LoadLocation("Local")
  12404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12405. if err != nil {
  12406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12407. return
  12408. }
  12409. if err != nil {
  12410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12411. return
  12412. }
  12413. recordDateTime := theTime.Unix()
  12414. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12415. if err != nil {
  12416. }
  12417. startRecordDateTime := startTime.Unix()
  12418. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12419. if err != nil {
  12420. }
  12421. endRecordDateTime := endTime.Unix()
  12422. adminInfo := c.GetAdminUserInfo()
  12423. var tempMonthChargePatients []*service.MonthChargePatients
  12424. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12425. for _, item := range tempPatients {
  12426. //过滤没有处方的
  12427. if len(item.HisPrescription) == 0 {
  12428. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12429. }
  12430. }
  12431. c.ServeSuccessJSON(map[string]interface{}{
  12432. "list": tempMonthChargePatients,
  12433. })
  12434. }
  12435. // PrescriptionDifference 医嘱数量差值结构体
  12436. type PrescriptionDrugDifference struct {
  12437. DrugID int64 //基础库药品id
  12438. ID int64 //医嘱id
  12439. Difference float64 //差值
  12440. Unit string //单位
  12441. }
  12442. type PrescriptionGoodDifference struct {
  12443. GoodID int64 //基础库项目耗材id
  12444. ID int64 //医嘱id
  12445. Difference int64 //差值
  12446. Unit string //单位
  12447. Type int64 //类型
  12448. }
  12449. type EditCustomData struct {
  12450. adviceList []*models.HisDoctorAdviceInfo
  12451. projectList []*models.HisPrescriptionProject
  12452. }
  12453. type SrcCustomData struct {
  12454. adviceList []*models.HisDoctorAdviceInfo
  12455. projectList []*models.HisPrescriptionProject
  12456. }
  12457. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12458. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12459. differences := make([]*PrescriptionDrugDifference, 0)
  12460. // 创建一个 map 来存储第一个切片中的药品信息
  12461. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12462. for _, advice := range firstPrescription {
  12463. firstMap[advice.DrugId] = advice
  12464. }
  12465. // 遍历第二个切片中的药品信息,并比较数量差值
  12466. for _, advice := range secondPrescription {
  12467. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12468. diff := &PrescriptionDrugDifference{
  12469. DrugID: advice.DrugId,
  12470. ID: firstAdvice.ID,
  12471. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12472. Unit: firstAdvice.PrescribingNumberUnit,
  12473. }
  12474. differences = append(differences, diff)
  12475. }
  12476. }
  12477. return differences
  12478. }
  12479. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12480. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12481. differences := make([]*PrescriptionGoodDifference, 0)
  12482. // 创建一个 map 来存储第一个切片中的耗材信息
  12483. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12484. for _, good := range firstPrescription {
  12485. firstMap[good.ProjectId] = good
  12486. }
  12487. // 遍历第二个切片中的耗材信息,并比较数量差值
  12488. for _, good := range secondPrescription {
  12489. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12490. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12491. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12492. diff := &PrescriptionGoodDifference{
  12493. GoodID: good.ProjectId,
  12494. ID: firstGood.ID,
  12495. Difference: count - firstCount,
  12496. Unit: firstGood.Unit,
  12497. Type: firstGood.Type,
  12498. }
  12499. differences = append(differences, diff)
  12500. }
  12501. }
  12502. return differences
  12503. }
  12504. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12505. var adviceList []*models.HisDoctorAdviceInfo
  12506. var projectList []*models.HisPrescriptionProject
  12507. var advice_ids []int64
  12508. var project_ids []int64
  12509. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12510. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12511. //var tempPrescription *models.HisPrescriptionProjectscription
  12512. if len(prescriptions) > 0 {
  12513. for _, item := range prescriptions {
  12514. items := item.(map[string]interface{})
  12515. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12516. advices := items["advices"].([]interface{})
  12517. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12518. groupNo := int64(0)
  12519. ctime := time.Now().Unix()
  12520. mtime := ctime
  12521. if len(advices) > 0 {
  12522. for _, advice := range advices {
  12523. var s models.HisDoctorAdviceInfo
  12524. s.AdviceType = 2
  12525. s.StopState = 2
  12526. s.ExecutionState = 2
  12527. s.Status = 1
  12528. s.Groupno = groupNo
  12529. s.CreatedTime = ctime
  12530. s.UpdatedTime = mtime
  12531. s.IsSettle = 2
  12532. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12533. //存储切片中
  12534. if s.ID > 0 {
  12535. advice_ids = append(advice_ids, s.ID)
  12536. adviceList = append(adviceList, &s)
  12537. }
  12538. }
  12539. }
  12540. }
  12541. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12542. projects := items["project"].([]interface{})
  12543. if len(projects) > 0 {
  12544. for _, project := range projects {
  12545. var p models.HisPrescriptionProject
  12546. p.Ctime = time.Now().Unix()
  12547. p.Mtime = time.Now().Unix()
  12548. p.Status = 1
  12549. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12550. if p.ID > 0 {
  12551. project_ids = append(project_ids, p.ID)
  12552. projectList = append(projectList, &p)
  12553. }
  12554. }
  12555. }
  12556. }
  12557. }
  12558. }
  12559. }
  12560. editCustomData.projectList = projectList
  12561. editCustomData.adviceList = adviceList
  12562. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12563. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12564. srcCustomData.adviceList = list
  12565. srcCustomData.projectList = list2
  12566. return
  12567. }