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.CheckState = hisAdvice.CheckState
  7489. advice.StartTime = hisAdvice.StartTime
  7490. advice.HospApprFlag = hisAdvice.HospApprFlag
  7491. advice.IsMedicine = hisAdvice.IsMedicine
  7492. if hisAdvice.UserOrgId == 10028 {
  7493. 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 {
  7494. advice.ExecutionTime = 0
  7495. advice.ExecutionStaff = 0
  7496. advice.ExecutionState = 2
  7497. advice.CheckTime = 0
  7498. advice.Checker = 0
  7499. advice.CheckState = 2
  7500. }
  7501. } else {
  7502. 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 {
  7503. advice.ExecutionTime = 0
  7504. advice.ExecutionStaff = 0
  7505. advice.ExecutionState = 2
  7506. advice.CheckTime = 0
  7507. advice.Checker = 0
  7508. advice.CheckState = 2
  7509. //advice.UpdatedTime = time.Now().Unix()
  7510. advice.CreatedTime = hisAdvice.CreatedTime
  7511. advice.UpdatedTime = time.Now().Unix()
  7512. } else {
  7513. advice.CreatedTime = hisAdvice.CreatedTime
  7514. advice.UpdatedTime = hisAdvice.UpdatedTime
  7515. }
  7516. }
  7517. //advice.Groupno = hisAdvice.Groupno
  7518. } else {
  7519. advice.IsMedicine = 0
  7520. ctime := time.Now().Unix()
  7521. advice.CreatedTime = ctime
  7522. advice.UpdatedTime = ctime
  7523. }
  7524. }
  7525. } else {
  7526. advice.IsMedicine = 0
  7527. ctime := time.Now().Unix()
  7528. advice.CreatedTime = ctime
  7529. advice.UpdatedTime = ctime
  7530. }
  7531. }
  7532. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7533. //
  7534. //if drugStockConfig.IsOpen == 1 {
  7535. //
  7536. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7537. // if advice.ID == 0 { //医嘱不存在
  7538. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7539. // drug.Total = drug.Total - advice.PrescribingNumber
  7540. // service.UpdateBaseDrugLib(&drug)
  7541. //
  7542. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7543. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7544. // drug.Total = drug.Total - num
  7545. // service.UpdateBaseDrugLib(&drug)
  7546. // }
  7547. //
  7548. // } else if advice.ID > 0 { //医嘱存在
  7549. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7550. // var num float64
  7551. //
  7552. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7553. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7554. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7555. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7556. // drug.Total = drug.Total + num
  7557. // service.UpdateBaseDrugLib(&drug)
  7558. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7559. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7560. // drug.Total = drug.Total - num
  7561. // service.UpdateBaseDrugLib(&drug)
  7562. // }
  7563. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7564. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7565. // if num2 > advice.PrescribingNumber {
  7566. // num = num2 - advice.PrescribingNumber
  7567. // drug.Total = drug.Total + num
  7568. // service.UpdateBaseDrugLib(&drug)
  7569. // } else if num2 < advice.PrescribingNumber {
  7570. // num = advice.PrescribingNumber - num2
  7571. // drug.Total = drug.Total - num
  7572. // service.UpdateBaseDrugLib(&drug)
  7573. // }
  7574. //
  7575. // }
  7576. //
  7577. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7578. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7579. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7580. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7581. // if num1 > num2 {
  7582. // num = num1 - num2
  7583. // drug.Total = drug.Total + num
  7584. // service.UpdateBaseDrugLib(&drug)
  7585. // } else if num1 < num2 {
  7586. // num = num2 - num1
  7587. // drug.Total = drug.Total - num
  7588. // service.UpdateBaseDrugLib(&drug)
  7589. // }
  7590. //
  7591. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7592. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7593. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7594. // if hisAdvice.PrescribingNumber > num2 {
  7595. // num = hisAdvice.PrescribingNumber - num2
  7596. // drug.Total = drug.Total + num
  7597. // service.UpdateBaseDrugLib(&drug)
  7598. // } else if num2 < advice.PrescribingNumber {
  7599. // num = num2 - hisAdvice.PrescribingNumber
  7600. // drug.Total = drug.Total - num
  7601. // service.UpdateBaseDrugLib(&drug)
  7602. // }
  7603. //
  7604. // }
  7605. // }
  7606. // }
  7607. //}
  7608. //
  7609. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7610. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7611. // advice.ExecutionTime = execution_time
  7612. //}
  7613. //
  7614. //
  7615. //
  7616. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7617. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7618. // advice.ExecutionStaff = execution_staff
  7619. //}
  7620. //
  7621. //
  7622. //
  7623. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7624. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7625. // advice.ExecutionState = execution_state
  7626. //}
  7627. //
  7628. //
  7629. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7630. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7631. // advice.CheckTime = check_time
  7632. //}
  7633. //
  7634. //
  7635. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7636. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7637. // advice.CheckState = check_state
  7638. //}
  7639. //
  7640. //
  7641. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7642. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7643. // advice.Checker = checker
  7644. //}
  7645. //
  7646. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7647. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7648. // advice.StartTime = start_time
  7649. //}
  7650. return 0
  7651. }
  7652. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7653. project.ExecutionStaff = 0
  7654. project.ExecutionState = 2
  7655. project.ExecutionTime = 0
  7656. project.Checker = 0
  7657. project.CheckState = 2
  7658. project.CheckTime = 0
  7659. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7660. id := int64(json["id"].(float64))
  7661. project.ID = id
  7662. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7663. project.ExecutionStaff = temp_project.ExecutionStaff
  7664. project.ExecutionState = temp_project.ExecutionState
  7665. project.ExecutionTime = temp_project.ExecutionTime
  7666. project.Checker = temp_project.Checker
  7667. project.CheckState = temp_project.CheckState
  7668. project.CheckTime = temp_project.CheckTime
  7669. project.TeamId = temp_project.TeamId
  7670. }
  7671. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7672. types := int64(json["type"].(float64))
  7673. project.Type = types
  7674. }
  7675. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7676. project_id := int64(json["project_id"].(float64))
  7677. project.ProjectId = project_id
  7678. }
  7679. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7680. team_id := int64(json["team_id"].(float64))
  7681. project.TeamId = team_id
  7682. }
  7683. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7684. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7685. project.Price = price
  7686. }
  7687. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7688. total, _ := json["total"].(string)
  7689. //totals, _ := strconv.ParseInt(total, 10, 64)
  7690. project.Count = total
  7691. }
  7692. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7693. medical_code, _ := json["medical_code"].(string)
  7694. project.MedListCodg = medical_code
  7695. }
  7696. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7697. single_dose, _ := json["single_dose"].(string)
  7698. project.SingleDose = single_dose
  7699. }
  7700. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7701. delivery_way, _ := json["delivery_way"].(string)
  7702. project.DeliveryWay = delivery_way
  7703. }
  7704. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7705. execution_frequency, _ := json["execution_frequency"].(string)
  7706. project.ExecutionFrequency = execution_frequency
  7707. }
  7708. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7709. remark, _ := json["remark"].(string)
  7710. project.Remark = remark
  7711. }
  7712. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7713. day, _ := json["number_days"].(string)
  7714. project.Day = day
  7715. }
  7716. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7717. unit, _ := json["unit"].(string)
  7718. project.Unit = unit
  7719. }
  7720. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7721. // frequency_type := int64(json["frequency_type"].(float64))
  7722. // project.FrequencyType = frequency_type
  7723. //}
  7724. //
  7725. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7726. // day_count := int64(json["day_count"].(float64))
  7727. // project.DayCount = day_count
  7728. //}
  7729. //
  7730. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7731. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7732. // week_day, _ := json["week_day"].(string)
  7733. // project.WeekDay = week_day
  7734. //}
  7735. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7736. //
  7737. //if project.ID == 0 {
  7738. // if stockConfig.IsOpen == 1 {
  7739. // if project.Type == 3 {
  7740. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7741. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7742. // good.Total = good.Total - f_count
  7743. // service.UpdateGoodInfo(&good)
  7744. // }
  7745. // }
  7746. //
  7747. //} else {
  7748. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7749. //
  7750. // if stockConfig.IsOpen == 1 {
  7751. // if project.Type == 3 {
  7752. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7753. // if project.Count < temp_project.Count {
  7754. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7755. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7756. //
  7757. // other_count := f_count_two - f_count_one
  7758. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7759. // good.Total = good.Total + other_count_two
  7760. // service.UpdateGoodInfo(&good)
  7761. // } else if project.Count > temp_project.Count {
  7762. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7763. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7764. //
  7765. // other_count := f_count_one - f_count_two
  7766. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7767. // good.Total = good.Total - other_count_two
  7768. // service.UpdateGoodInfo(&good)
  7769. // }
  7770. //
  7771. // }
  7772. // }
  7773. //
  7774. //}
  7775. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7776. id := int64(json["id"].(float64))
  7777. if id > 0 {
  7778. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7779. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7780. fmt.Println("666666")
  7781. project.Mtime = time.Now().Unix()
  7782. project.Ctime = temp_project.Ctime
  7783. } else {
  7784. project.Mtime = temp_project.Mtime
  7785. project.Ctime = temp_project.Ctime
  7786. }
  7787. } else {
  7788. ctime := time.Now().Unix()
  7789. project.Mtime = ctime
  7790. project.Ctime = ctime
  7791. }
  7792. }
  7793. return 0
  7794. }
  7795. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7796. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7797. id := int64(json["id"].(float64))
  7798. additionalCharge.ID = id
  7799. }
  7800. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7801. item_id := int64(json["item_id"].(float64))
  7802. additionalCharge.ItemId = item_id
  7803. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7804. if config.ID > 0 {
  7805. if len(config.Code) > 0 {
  7806. additionalCharge.MedListCodg = config.Code
  7807. }
  7808. }
  7809. }
  7810. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7811. // price := int64(json["price"].(float64))
  7812. // formatInt_price := strconv.FormatInt(price, 10)
  7813. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7814. // additionalCharge.Price = float_price
  7815. // }
  7816. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7817. // price := int64(json["price"].(float64))
  7818. // formatInt_price := strconv.FormatInt(price, 10)
  7819. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7820. // additionalCharge.Price = float_price
  7821. //}
  7822. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7823. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7824. additionalCharge.Price = price
  7825. }
  7826. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7827. count, _ := json["count"].(string)
  7828. counts, _ := strconv.ParseInt(count, 10, 64)
  7829. additionalCharge.Count = counts
  7830. }
  7831. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7832. item_name, _ := json["item_name"].(string)
  7833. additionalCharge.ItemName = item_name
  7834. }
  7835. return 0
  7836. }
  7837. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7838. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7839. utils.ErrorLog("drug_name")
  7840. return enums.ErrorCodeParamWrong
  7841. }
  7842. adviceName, _ := json["drug_name"].(string)
  7843. if len(adviceName) == 0 {
  7844. utils.ErrorLog("len(advice_name) == 0")
  7845. return enums.ErrorCodeParamWrong
  7846. }
  7847. advice.AdviceName = adviceName
  7848. adviceDesc, _ := json["advice_desc"].(string)
  7849. advice.AdviceDesc = adviceDesc
  7850. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7851. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7852. advice.DrugSpec = drugSpec
  7853. }
  7854. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7855. remark, _ := json["remark"].(string)
  7856. advice.Remark = remark
  7857. }
  7858. if json["id"] == nil {
  7859. advice.DrugId = 0
  7860. } else {
  7861. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7862. drug_id := int64(json["id"].(float64))
  7863. advice.DrugId = drug_id
  7864. }
  7865. }
  7866. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7867. groupno := int64(json["groupno"].(float64))
  7868. advice.Groupno = groupno
  7869. }
  7870. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7871. drugSpecUnit, _ := json["min_unit"].(string)
  7872. advice.DrugSpecUnit = drugSpecUnit
  7873. }
  7874. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7875. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7876. advice.SingleDose = singleDose
  7877. }
  7878. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7879. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7880. advice.SingleDoseUnit = singleDoseUnit
  7881. }
  7882. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7883. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7884. advice.PrescribingNumber = prescribingNumber
  7885. }
  7886. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7887. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7888. advice.PrescribingNumberUnit = prescribingNumberUnit
  7889. }
  7890. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7891. deliveryWay, _ := json["delivery_way"].(string)
  7892. advice.DeliveryWay = deliveryWay
  7893. }
  7894. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7895. executionFrequency, _ := json["execution_frequency"].(string)
  7896. advice.ExecutionFrequency = executionFrequency
  7897. }
  7898. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7899. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7900. advice.Price = price
  7901. }
  7902. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7903. med_list_codg, _ := json["medical_insurance_number"].(string)
  7904. advice.MedListCodg = med_list_codg
  7905. }
  7906. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7907. day := int64(json["day"].(float64))
  7908. advice.Day = day
  7909. }
  7910. advice.FrequencyType = 1
  7911. return 0
  7912. }
  7913. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7914. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7915. types := int64(json["type"].(float64))
  7916. project.Type = types
  7917. }
  7918. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7919. project_id := int64(json["project_id"].(float64))
  7920. project.ProjectId = project_id
  7921. }
  7922. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7923. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7924. project.Price = price
  7925. }
  7926. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7927. total, _ := json["total"].(string)
  7928. //totals, _ := strconv.ParseInt(total, 10, 64)
  7929. project.Count = total
  7930. }
  7931. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7932. medical_code, _ := json["medical_code"].(string)
  7933. project.MedListCodg = medical_code
  7934. }
  7935. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7936. single_dose, _ := json["single_dose"].(string)
  7937. project.SingleDose = single_dose
  7938. }
  7939. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7940. delivery_way, _ := json["delivery_way"].(string)
  7941. project.DeliveryWay = delivery_way
  7942. }
  7943. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7944. execution_frequency, _ := json["execution_frequency"].(string)
  7945. project.ExecutionFrequency = execution_frequency
  7946. }
  7947. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7948. remark, _ := json["remark"].(string)
  7949. project.Remark = remark
  7950. }
  7951. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7952. day, _ := json["number_days"].(string)
  7953. project.Day = day
  7954. }
  7955. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7956. unit, _ := json["unit"].(string)
  7957. project.Unit = unit
  7958. }
  7959. project.FrequencyType = 1
  7960. return 0
  7961. }
  7962. func (c *HisApiController) GetHisOrderListTwo() {
  7963. start_time := c.GetString("start_time")
  7964. end_time := c.GetString("end_time")
  7965. timeLayout := "2006-01-02"
  7966. loc, _ := time.LoadLocation("Local")
  7967. var startTime int64
  7968. if len(start_time) > 0 {
  7969. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7970. if err != nil {
  7971. //fmt.Println(err)
  7972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7973. return
  7974. }
  7975. startTime = theTime.Unix()
  7976. }
  7977. var endTime int64
  7978. if len(end_time) > 0 {
  7979. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7980. if err != nil {
  7981. utils.ErrorLog(err.Error())
  7982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7983. return
  7984. }
  7985. endTime = theTime.Unix()
  7986. }
  7987. adminUser := c.GetAdminUserInfo()
  7988. org_id := adminUser.CurrentOrgId
  7989. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7990. if err == nil {
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "order2": order,
  7993. })
  7994. } else {
  7995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7996. return
  7997. }
  7998. }
  7999. func (c *HisApiController) GetHisOrderList() {
  8000. page, _ := c.GetInt64("page", -1)
  8001. limit, _ := c.GetInt64("limit", -1)
  8002. start_time := c.GetString("start_time")
  8003. end_time := c.GetString("end_time")
  8004. types, _ := c.GetInt64("type", 0)
  8005. keywords := c.GetString("keywords")
  8006. p_type, _ := c.GetInt64("p_type", 0)
  8007. sort_type, _ := c.GetInt64("sort_type", 0)
  8008. charge_type, _ := c.GetInt64("charge_type", 0)
  8009. sch_type, _ := c.GetInt64("sch_type", 0)
  8010. zone_type, _ := c.GetInt64("zone_type", 0)
  8011. med_type, _ := c.GetInt64("med_type", 0)
  8012. timeLayout := "2006-01-02"
  8013. loc, _ := time.LoadLocation("Local")
  8014. var startTime int64
  8015. if len(start_time) > 0 {
  8016. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8017. if err != nil {
  8018. //fmt.Println(err)
  8019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8020. return
  8021. }
  8022. startTime = theTime.Unix()
  8023. }
  8024. var endTime int64
  8025. if len(end_time) > 0 {
  8026. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8027. if err != nil {
  8028. utils.ErrorLog(err.Error())
  8029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8030. return
  8031. }
  8032. endTime = theTime.Unix()
  8033. }
  8034. adminUser := c.GetAdminUserInfo()
  8035. org_id := adminUser.CurrentOrgId
  8036. 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)
  8037. for _, item := range order {
  8038. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8039. item.DoctorName = info.Doctor
  8040. item.DepartmentName = info.XtHisDepartment.Name
  8041. }
  8042. if err == nil {
  8043. c.ServeSuccessJSON(map[string]interface{}{
  8044. "order": order,
  8045. "total": total,
  8046. })
  8047. } else {
  8048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8049. return
  8050. }
  8051. }
  8052. func (c *HisApiController) GetHisOrder() {
  8053. patient_id, _ := c.GetInt64("patient_id", 0)
  8054. number := c.GetString("number")
  8055. adminInfo := c.GetAdminUserInfo()
  8056. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8057. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8058. if err == nil {
  8059. c.ServeSuccessJSON(map[string]interface{}{
  8060. "order": order,
  8061. "prescription": prescriptions,
  8062. })
  8063. } else {
  8064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8065. return
  8066. }
  8067. }
  8068. func (c *HisApiController) GetHisPrescriptionList() {
  8069. record_date := c.GetString("record_date")
  8070. keywords := c.GetString("keywords")
  8071. page, _ := c.GetInt64("page")
  8072. limit, _ := c.GetInt64("limit")
  8073. sch_type, _ := c.GetInt64("sch_type")
  8074. timeLayout := "2006-01-02"
  8075. loc, _ := time.LoadLocation("Local")
  8076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8077. if err != nil {
  8078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8079. return
  8080. }
  8081. recordDateTime := theTime.Unix()
  8082. adminInfo := c.GetAdminUserInfo()
  8083. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8084. //adminInfo := c.GetAdminUserInfo()
  8085. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8086. //fmt.Println(prescriptionOrder)
  8087. if err == nil {
  8088. c.ServeSuccessJSON(map[string]interface{}{
  8089. "order": prescriptionOrder,
  8090. "total": total,
  8091. })
  8092. } else {
  8093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8094. return
  8095. }
  8096. }
  8097. func (c *HisApiController) GetHisPrescriptionInfo() {
  8098. id, _ := c.GetInt64("id")
  8099. adminInfo := c.GetAdminUserInfo()
  8100. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8101. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8102. if err == nil {
  8103. c.ServeSuccessJSON(map[string]interface{}{
  8104. "order": prescriptionOrder,
  8105. "prescription": prescription,
  8106. })
  8107. } else {
  8108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8109. return
  8110. }
  8111. }
  8112. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8113. adminUser := c.GetAdminUserInfo()
  8114. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8115. c.ServeSuccessJSON(map[string]interface{}{
  8116. "config": config,
  8117. })
  8118. }
  8119. type ResultTwo struct {
  8120. ErrMsg interface{} `json:"err_msg"`
  8121. InfRefmsgid string `json:"inf_refmsgid"`
  8122. Infcode int64 `json:"infcode"`
  8123. Output struct {
  8124. Baseinfo struct {
  8125. Age float64 `json:"age"`
  8126. Brdy string `json:"brdy"`
  8127. Certno string `json:"certno"`
  8128. Gend string `json:"gend"`
  8129. Naty string `json:"naty"`
  8130. PsnCertType string `json:"psn_cert_type"`
  8131. PsnName string `json:"psn_name"`
  8132. PsnNo string `json:"psn_no"`
  8133. } `json:"baseinfo"`
  8134. Idetinfo []interface{} `json:"idetinfo"`
  8135. Iinfo []struct {
  8136. Balc float64 `json:"balc"`
  8137. CvlservFlag string `json:"cvlserv_flag"`
  8138. EmpName string `json:"emp_name"`
  8139. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8140. Insutype string `json:"insutype"`
  8141. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8142. PausInsuDate interface{} `json:"paus_insu_date"`
  8143. PsnInsuDate string `json:"psn_insu_date"`
  8144. PsnInsuStas string `json:"psn_insu_stas"`
  8145. PsnType string `json:"psn_type"`
  8146. } `json:"insuinfo"`
  8147. } `json:"output"`
  8148. RefmsgTime string `json:"refmsg_time"`
  8149. RespondTime string `json:"respond_time"`
  8150. Signtype interface{} `json:"signtype"`
  8151. WarnInfo interface{} `json:"warn_info"`
  8152. }
  8153. type ResultThree struct {
  8154. Cainfo interface{} `json:"cainfo"`
  8155. ErrMsg interface{} `json:"err_msg"`
  8156. InfRefmsgid string `json:"inf_refmsgid"`
  8157. Infcode int64 `json:"infcode"`
  8158. Output struct {
  8159. Data struct {
  8160. IptOtpNo string `json:"ipt_otp_no"`
  8161. MdtrtID string `json:"mdtrt_id"`
  8162. PsnNo string `json:"psn_no"`
  8163. } `json:"data"`
  8164. } `json:"output"`
  8165. RefmsgTime string `json:"refmsg_time"`
  8166. RespondTime string `json:"respond_time"`
  8167. Signtype interface{} `json:"signtype"`
  8168. WarnMsg interface{} `json:"warn_msg"`
  8169. }
  8170. type ResultFour struct {
  8171. Cainfo string `json:"cainfo"`
  8172. ErrMsg string `json:"err_msg"`
  8173. InfRefmsgid string `json:"inf_refmsgid"`
  8174. Infcode int64 `json:"infcode"`
  8175. Output struct {
  8176. Result []struct {
  8177. BasMednFlag string `json:"bas_medn_flag"`
  8178. ChldMedcFlag string `json:"chld_medc_flag"`
  8179. ChrgitmLv string `json:"chrgitm_lv"`
  8180. Cnt float64 `json:"cnt"`
  8181. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8182. DrtReimFlag string `json:"drt_reim_flag"`
  8183. FeedetlSn string `json:"feedetl_sn"`
  8184. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8185. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8186. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8187. ListSpItemFlag string `json:"list_sp_item_flag"`
  8188. LmtUsedFlag string `json:"lmt_used_flag"`
  8189. MedChrgitmType string `json:"med_chrgitm_type"`
  8190. Memo string `json:"memo"`
  8191. OverlmtAmt float64 `json:"overlmt_amt"`
  8192. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8193. Pric float64 `json:"pric"`
  8194. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8195. SelfpayProp float64 `json:"selfpay_prop"`
  8196. } `json:"result"`
  8197. } `json:"output"`
  8198. RefmsgTime string `json:"refmsg_time"`
  8199. RespondTime string `json:"respond_time"`
  8200. Signtype string `json:"signtype"`
  8201. WarnMsg string `json:"warn_msg"`
  8202. }
  8203. type ResultFive struct {
  8204. Insutype string `json:"insutype"`
  8205. }
  8206. type ResultSix struct {
  8207. Cainfo interface{} `json:"cainfo"`
  8208. ErrMsg interface{} `json:"err_msg"`
  8209. InfRefmsgid string `json:"inf_refmsgid"`
  8210. Infcode int64 `json:"infcode"`
  8211. Output struct {
  8212. } `json:"output"`
  8213. RefmsgTime string `json:"refmsg_time"`
  8214. RespondTime string `json:"respond_time"`
  8215. Signtype interface{} `json:"signtype"`
  8216. WarnMsg interface{} `json:"warn_msg"`
  8217. }
  8218. type ResultSeven struct {
  8219. Cainfo string `json:"cainfo"`
  8220. ErrMsg string `json:"err_msg"`
  8221. InfRefmsgid string `json:"inf_refmsgid"`
  8222. Infcode int64 `json:"infcode"`
  8223. Output struct {
  8224. Setldetail []interface{} `json:"setldetail"`
  8225. Setlinfo struct {
  8226. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8227. AcctPay float64 `json:"acct_pay"`
  8228. ActPayDedc float64 `json:"act_pay_dedc"`
  8229. Age float64 `json:"age"`
  8230. Balc float64 `json:"balc"`
  8231. Brdy string `json:"brdy"`
  8232. Certno string `json:"certno"`
  8233. ClrOptins string `json:"clr_optins"`
  8234. ClrType string `json:"clr_type"`
  8235. ClrWay string `json:"clr_way"`
  8236. CvlservFlag string `json:"cvlserv_flag"`
  8237. CvlservPay float64 `json:"cvlserv_pay"`
  8238. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8239. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8240. Gend string `json:"gend"`
  8241. HifesPay float64 `json:"hifes_pay"`
  8242. HifmiPay float64 `json:"hifmi_pay"`
  8243. HifobPay float64 `json:"hifob_pay"`
  8244. HifpPay float64 `json:"hifp_pay"`
  8245. HospPartAmt float64 `json:"hosp_part_amt"`
  8246. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8247. Insutype string `json:"insutype"`
  8248. MafPay float64 `json:"maf_pay"`
  8249. MdtrtCertType string `json:"mdtrt_cert_type"`
  8250. MdtrtID string `json:"mdtrt_id"`
  8251. MedType string `json:"med_type"`
  8252. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8253. MedinsSetlID string `json:"medins_setl_id"`
  8254. Naty string `json:"naty"`
  8255. OthPay float64 `json:"oth_pay"`
  8256. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8257. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8258. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8259. PsnCashPay float64 `json:"psn_cash_pay"`
  8260. PsnCertType string `json:"psn_cert_type"`
  8261. PsnName string `json:"psn_name"`
  8262. PsnNo string `json:"psn_no"`
  8263. PsnPartAmt float64 `json:"psn_part_amt"`
  8264. PsnType string `json:"psn_type"`
  8265. SetlID string `json:"setl_id"`
  8266. SetlTime string `json:"setl_time"`
  8267. } `json:"setlinfo"`
  8268. } `json:"output"`
  8269. RefmsgTime string `json:"refmsg_time"`
  8270. RespondTime string `json:"respond_time"`
  8271. Signtype interface{} `json:"signtype"`
  8272. WarnMsg interface{} `json:"warn_msg"`
  8273. }
  8274. type ResultEight struct {
  8275. Cainfo string `json:"cainfo"`
  8276. ErrMsg string `json:"err_msg"`
  8277. InfRefmsgid string `json:"inf_refmsgid"`
  8278. Infcode int64 `json:"infcode"`
  8279. Output struct {
  8280. Stmtinfo struct {
  8281. SetlOptins string `json:"setl_optins"`
  8282. StmtRslt string `json:"stmt_rslt"`
  8283. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8284. } `json:"stmtinfo"`
  8285. } `json:"output"`
  8286. RefmsgTime string `json:"refmsg_time"`
  8287. RespondTime string `json:"respond_time"`
  8288. Signtype interface{} `json:"signtype"`
  8289. WarnMsg interface{} `json:"warn_msg"`
  8290. }
  8291. type ResultNine struct {
  8292. Cainfo string `json:"cainfo"`
  8293. ErrMsg string `json:"err_msg"`
  8294. InfRefmsgid string `json:"inf_refmsgid"`
  8295. Infcode int64 `json:"infcode"`
  8296. Output struct {
  8297. FileQuryNo string `json:"file_qury_no"`
  8298. } `json:"output"`
  8299. RefmsgTime string `json:"refmsg_time"`
  8300. RespondTime string `json:"respond_time"`
  8301. Signtype interface{} `json:"signtype"`
  8302. WarnMsg interface{} `json:"warn_msg"`
  8303. }
  8304. type ResultTen struct {
  8305. Cainfo string `json:"cainfo"`
  8306. ErrMsg string `json:"err_msg"`
  8307. InfRefmsgid string `json:"inf_refmsgid"`
  8308. Infcode int64 `json:"infcode"`
  8309. Output struct {
  8310. DldEndtime string `json:"dld_endtime"`
  8311. FileQuryNo string `json:"file_qury_no"`
  8312. Filename string `json:"filename"`
  8313. } `json:"output"`
  8314. RefmsgTime string `json:"refmsg_time"`
  8315. RespondTime string `json:"respond_time"`
  8316. Signtype interface{} `json:"signtype"`
  8317. WarnMsg interface{} `json:"warn_msg"`
  8318. }
  8319. type ResultEleven struct {
  8320. Cainfo string `json:"cainfo"`
  8321. ErrMsg string `json:"err_msg"`
  8322. InfRefmsgid string `json:"inf_refmsgid"`
  8323. Infcode int64 `json:"infcode"`
  8324. Output struct {
  8325. Setlinfo struct {
  8326. FixmedinsName string `json:"fixmedins_name"`
  8327. FixmedinsCode string `json:"fixmedins_code"`
  8328. PsnNo string `json:"psn_no"`
  8329. PsnName string `json:"psn_name"`
  8330. HifobPay float64 `json:"hifob_pay"`
  8331. Gend string `json:"gend"`
  8332. Brdy string `json:"brdy"`
  8333. PsnCertType string `json:"psn_cert_type"`
  8334. PsnType string `json:"psn_type"`
  8335. EmpName string `json:"emp_name"`
  8336. Certno string `json:"certno"`
  8337. Insutype string `json:"insutype"`
  8338. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8339. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8340. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8341. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8342. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8343. ActPayDedc float64 `json:"act_pay_dedc"`
  8344. HifpPay float64 `json:"hifp_pay"`
  8345. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8346. CvlservPay float64 `json:"cvlserv_pay"`
  8347. HifesPay float64 `json:"hifes_pay"`
  8348. HifmiPay float64 `json:"hifmi_pay"`
  8349. MafPay float64 `json:"maf_pay"`
  8350. OthPay float64 `json:"oth_pay"`
  8351. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8352. PsnPay float64 `json:"psn_pay"`
  8353. AcctPay float64 `json:"acct_pay"`
  8354. CashPayamt float64 `json:"cash_payamt"`
  8355. Balc float64 `json:"balc"`
  8356. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8357. MedinsSetlId string `json:"medins_setl_id"`
  8358. RefdSetlFlag string `json:"refd_setl_flag"`
  8359. SetlTime string `json:"setl_time"`
  8360. MedType string `json:"med_type"`
  8361. } `json:"setlinfo"`
  8362. } `json:"output"`
  8363. RefmsgTime string `json:"refmsg_time"`
  8364. RespondTime string `json:"respond_time"`
  8365. Signtype interface{} `json:"signtype"`
  8366. WarnMsg interface{} `json:"warn_msg"`
  8367. }
  8368. type Custom struct {
  8369. DetItemFeeSumamt string
  8370. Cut string
  8371. FeedetlSn string
  8372. Price string
  8373. MedListCodg string
  8374. Type int64
  8375. AdviceId int64
  8376. ProjectId int64
  8377. ItemId int64
  8378. CostType int64
  8379. }
  8380. // 获取个人信息----挂号-----上传就诊信息
  8381. func (c *HisApiController) GetRegisterInfo() {
  8382. id, _ := c.GetInt64("id")
  8383. record_time := c.GetString("record_time")
  8384. settlementValue, _ := c.GetInt64("settlement_value")
  8385. medical_insurance_card := c.GetString("medical_insurance_card")
  8386. name := c.GetString("name")
  8387. id_card_type, _ := c.GetInt64("id_card_type")
  8388. certificates, _ := c.GetInt64("certificates")
  8389. medical_care, _ := c.GetInt64("medical_care")
  8390. birthday := c.GetString("birthday")
  8391. age, _ := c.GetInt64("age")
  8392. id_card := c.GetString("id_card")
  8393. register_type, _ := c.GetInt64("register")
  8394. doctor, _ := c.GetInt64("doctor")
  8395. department, _ := c.GetInt64("department")
  8396. gender, _ := c.GetInt64("sex")
  8397. phone := c.GetString("phone")
  8398. registration_fee, _ := c.GetFloat("registration_fee")
  8399. medical_expenses, _ := c.GetFloat("medical_expenses")
  8400. social_type, _ := c.GetInt64("social_type")
  8401. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8402. diagnosis_ids := c.GetString("diagnosis")
  8403. sick_type, _ := c.GetInt64("sick_type")
  8404. reg_type := c.GetString("p_type")
  8405. timeLayout := "2006-01-02"
  8406. loc, _ := time.LoadLocation("Local")
  8407. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8408. birthUnix := birthdays.Unix()
  8409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8410. if err != nil {
  8411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8412. return
  8413. }
  8414. recordDateTime := theTime.Unix()
  8415. adminInfo := c.GetAdminUserInfo()
  8416. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8417. if tempPatient.ID == 0 {
  8418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8419. return
  8420. }
  8421. var patient service.Patients
  8422. if id == 0 {
  8423. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8424. } else {
  8425. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8426. }
  8427. if patient.ID == 0 {
  8428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8429. return
  8430. }
  8431. if len(patient.IdCardNo) == 0 {
  8432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8433. return
  8434. }
  8435. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8436. if len(his) >= 1 {
  8437. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8438. if len(his) >= 1 && order.ID == 0 {
  8439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8440. return
  8441. }
  8442. }
  8443. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8444. fmt.Println(timeStr)
  8445. timeArr := strings.Split(timeStr, " ")
  8446. fmt.Println(timeArr)
  8447. timeArrTwo := strings.Split(timeArr[0], "-")
  8448. timeArrThree := strings.Split(timeArr[1], ":")
  8449. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8450. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8451. if len(lists) == 0 {
  8452. var hisPatient models.XtHisPatient
  8453. hisPatient = models.XtHisPatient{
  8454. Name: name,
  8455. Age: age,
  8456. Gender: gender,
  8457. Birthday: birthUnix,
  8458. Phone: phone,
  8459. MedicalTreatmentType: medical_care,
  8460. IdType: certificates,
  8461. IdCardNo: id_card,
  8462. BalanceAccountsType: settlementValue,
  8463. SocialType: social_type,
  8464. MedicalInsuranceNumber: medical_insurance_card,
  8465. RegisterType: register_type,
  8466. RegisterCost: registration_fee,
  8467. TreatmentCost: medical_expenses,
  8468. AdminUserId: adminInfo.AdminUser.Id,
  8469. UserOrgId: adminInfo.CurrentOrgId,
  8470. Status: 1,
  8471. RecordDate: recordDateTime,
  8472. IsReturn: 1,
  8473. PatientId: patient.ID,
  8474. Ctime: time.Now().Unix(),
  8475. Mtime: time.Now().Unix(),
  8476. Number: str,
  8477. IdCardType: id_card_type,
  8478. Departments: department,
  8479. Doctor: doctor,
  8480. PType: reg_type,
  8481. Diagnosis: diagnosis_ids,
  8482. SickType: sick_type,
  8483. }
  8484. service.CreateHisPatient(&hisPatient)
  8485. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8486. c.ServeSuccessJSON(map[string]interface{}{
  8487. "his_info": hisPatient,
  8488. })
  8489. } else {
  8490. //chrgBchno := rand.Intn(1000000) + 10000
  8491. var hisPatient models.XtHisPatient
  8492. hisPatient = models.XtHisPatient{
  8493. Name: name,
  8494. Age: age,
  8495. Gender: gender,
  8496. Birthday: birthUnix,
  8497. Phone: phone,
  8498. MedicalTreatmentType: medical_care,
  8499. IdType: certificates,
  8500. IdCardNo: id_card,
  8501. BalanceAccountsType: settlementValue,
  8502. SocialType: social_type,
  8503. MedicalInsuranceNumber: medical_insurance_card,
  8504. RegisterType: register_type,
  8505. RegisterCost: registration_fee,
  8506. TreatmentCost: medical_expenses,
  8507. AdminUserId: adminInfo.AdminUser.Id,
  8508. UserOrgId: adminInfo.CurrentOrgId,
  8509. Status: 1,
  8510. RecordDate: recordDateTime,
  8511. IsReturn: 1,
  8512. PatientId: patient.ID,
  8513. Ctime: time.Now().Unix(),
  8514. Mtime: time.Now().Unix(),
  8515. Number: str,
  8516. IdCardType: id_card_type,
  8517. Departments: department,
  8518. Doctor: doctor,
  8519. PType: reg_type,
  8520. Diagnosis: diagnosis_ids,
  8521. SickType: sick_type,
  8522. }
  8523. service.CreateHisPatient(&hisPatient)
  8524. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8525. c.ServeSuccessJSON(map[string]interface{}{
  8526. "his_info": hisPatient,
  8527. })
  8528. }
  8529. }
  8530. // 上传明细----结算
  8531. func (c *HisApiController) GetUploadInfo() {
  8532. id, _ := c.GetInt64("id")
  8533. record_time := c.GetString("record_time")
  8534. his_patient_id, _ := c.GetInt64("his_patient_id")
  8535. oth_desc := c.GetString("oth_desc")
  8536. pay_way, _ := c.GetInt64("pay_way")
  8537. pay_ways := c.GetString("pay_ways")
  8538. pay_price, _ := c.GetFloat("pay_price")
  8539. pay_card_no := c.GetString("pay_card_no")
  8540. discount_price, _ := c.GetFloat("discount_price")
  8541. preferential_price, _ := c.GetFloat("preferential_price")
  8542. reality_price, _ := c.GetFloat("reality_price")
  8543. found_price, _ := c.GetFloat("found_price")
  8544. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8545. private_price, _ := c.GetFloat("private_price")
  8546. timeLayout := "2006-01-02"
  8547. loc, _ := time.LoadLocation("Local")
  8548. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8549. fapiao_code := c.GetString("fapiao_code")
  8550. fapiao_number := c.GetString("fapiao_number")
  8551. diagnosis_id := c.GetString("diagnosis")
  8552. sick_type, _ := c.GetInt64("sick_type")
  8553. reg_type, _ := c.GetInt64("p_type")
  8554. order_id, _ := c.GetInt64("order_id")
  8555. cash_pay := c.GetString("cash_pay")
  8556. wechat_pay := c.GetString("wechat_pay")
  8557. ali_pay := c.GetString("ali_pay")
  8558. jifen_pay := c.GetString("jifen_pay")
  8559. band_card_pay := c.GetString("band_card_pay")
  8560. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8561. tmp_decimal := c.GetString("tmp_decimal")
  8562. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8563. var decimal float64 //本次使用的押金
  8564. var errmsg error
  8565. tx := service.XTWriteDB().Begin() //开了事务
  8566. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8567. defer func() {
  8568. if errmsg != nil {
  8569. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8570. tx.Rollback()
  8571. } else {
  8572. tx.Commit()
  8573. }
  8574. }()
  8575. fmt.Println("dec_way", dec_way)
  8576. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8577. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8578. return
  8579. }
  8580. if len(tmp_decimal) > 0 {
  8581. if tmp_decimal[0] == 45 {
  8582. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8583. return
  8584. }
  8585. }
  8586. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8587. fmt.Println(errs)
  8588. decimal = tt
  8589. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8590. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8591. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8592. if err != nil {
  8593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8594. return
  8595. }
  8596. recordDateTime := theTime.Unix()
  8597. adminUser := c.GetAdminUserInfo()
  8598. var prescriptions []*models.HisPrescription
  8599. var prescriptionsOne []*models.HisPrescription
  8600. var start_time int64
  8601. var end_time int64
  8602. ids_str := c.GetString("ids")
  8603. ids_arr := strings.Split(ids_str, ",")
  8604. if tempOrder.ID == 0 {
  8605. if settle_accounts_type == 1 { //日结
  8606. fmt.Println(reg_type)
  8607. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8608. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8609. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8610. } else {
  8611. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8612. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8613. }
  8614. } else { //月结
  8615. start_time_str := c.GetString("start_time")
  8616. end_time_str := c.GetString("end_time")
  8617. timeLayout := "2006-01-02"
  8618. loc, _ := time.LoadLocation("Local")
  8619. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8620. if err != nil {
  8621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8622. return
  8623. }
  8624. recordStartTime := theStartTime.Unix()
  8625. start_time = recordStartTime
  8626. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8627. if err != nil {
  8628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8629. return
  8630. }
  8631. recordEndTime := theEndTime.Unix()
  8632. end_time = recordEndTime
  8633. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8634. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8635. }
  8636. var goods []*models.DialysisBeforePrepareGoods
  8637. var newGoods []*models.NewDialysisBeforePrepareGoods
  8638. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8639. var infos []*models.HisDoctorAdviceInfo
  8640. var infoList []*models.HisDoctorAdviceInfo
  8641. var hisAdvice []*models.HisDoctorAdviceInfo
  8642. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8643. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8644. //判断库存不足
  8645. //结算出库开关
  8646. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8647. if settConfig.IsOpen == 1 {
  8648. //判断库存的地方
  8649. for _, info := range prescriptions {
  8650. if info.Type == 1 {
  8651. infos = append(infos, info.HisDoctorAdviceInfo...)
  8652. }
  8653. if info.Type == 2 {
  8654. for _, sumItem := range info.HisPrescriptionProject {
  8655. if sumItem.Type == 3 {
  8656. var good models.DialysisBeforePrepareGoods
  8657. var newGood models.NewDialysisBeforePrepareGoods
  8658. good.GoodId = sumItem.GoodInfo.ID
  8659. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8660. count, _ := strconv.Atoi(sumItem.Count)
  8661. good.Count = int64(count)
  8662. good.StorehouseId = houseConfig.StorehouseOutInfo
  8663. good.ProjectId = sumItem.ID
  8664. goods = append(goods, &good)
  8665. newGood.GoodId = sumItem.GoodInfo.ID
  8666. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8667. count2, _ := strconv.Atoi(sumItem.Count)
  8668. newGood.Count = int64(count2)
  8669. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8670. newGood.ProjectId = sumItem.ID
  8671. newGoods = append(newGoods, &newGood)
  8672. }
  8673. }
  8674. }
  8675. }
  8676. for _, info := range prescriptionsOne {
  8677. if info.Type == 1 {
  8678. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8679. }
  8680. if info.Type == 2 {
  8681. for _, sumItem := range info.HisPrescriptionProject {
  8682. if sumItem.Type == 3 {
  8683. var newGood models.NewDialysisBeforePrepareGoods
  8684. newGood.GoodId = sumItem.GoodInfo.ID
  8685. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8686. count2, _ := strconv.Atoi(sumItem.Count)
  8687. newGood.Count = int64(count2)
  8688. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8689. newGood.ProjectId = sumItem.ID
  8690. newGoodOne = append(newGoodOne, &newGood)
  8691. }
  8692. }
  8693. }
  8694. }
  8695. //判断
  8696. for _, itemOne := range infos {
  8697. for _, itemTwo := range hisAdvice {
  8698. if itemOne.DrugId == itemTwo.DrugId {
  8699. itemTwo.Child = append(itemTwo.Child, itemOne)
  8700. }
  8701. }
  8702. }
  8703. for _, itemTwo := range hisAdvice {
  8704. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8705. var sum_out_count int64
  8706. for _, itemThree := range itemTwo.Child {
  8707. var prescribing_number int64
  8708. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8709. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8710. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8711. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8712. }
  8713. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8714. prescribing_number = parseIntPrescribingNumber
  8715. }
  8716. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8717. prescribing_number = parseIntPrescribingNumber
  8718. }
  8719. sum_out_count += prescribing_number
  8720. }
  8721. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8722. if sum_out_count > drugStockOut.FlushCount {
  8723. c.ServeSuccessJSON(map[string]interface{}{
  8724. "msg": "2",
  8725. "drug": medical,
  8726. })
  8727. return
  8728. }
  8729. }
  8730. for _, itemOne := range newGoods {
  8731. for _, item := range newGoodOne {
  8732. if itemOne.GoodId == item.GoodId {
  8733. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8734. }
  8735. }
  8736. }
  8737. for _, item := range newGoodOne {
  8738. var sum_out_count_one int64
  8739. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8740. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8741. sum_out_count_one += itemOne.Count
  8742. }
  8743. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8744. fmt.Println("sum_out_count_one", sum_out_count_one)
  8745. fmt.Println("list.FlushCount", list.FlushCount)
  8746. if sum_out_count_one > list.FlushCount {
  8747. c.ServeSuccessJSON(map[string]interface{}{
  8748. "msg": "3",
  8749. "good": good,
  8750. })
  8751. return
  8752. }
  8753. }
  8754. }
  8755. timestamp := time.Now().Unix()
  8756. tempTime := time.Unix(timestamp, 0)
  8757. timeFormat := tempTime.Format("20060102150405")
  8758. chrgBchno := rand.Intn(100000) + 10000
  8759. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8760. strconv.FormatInt(his.PatientId, 10)
  8761. var ids []int64
  8762. for _, item := range prescriptions {
  8763. ids = append(ids, item.ID)
  8764. }
  8765. var total float64
  8766. for _, item := range prescriptions {
  8767. fmt.Println(item)
  8768. if item.Type == 1 { //药品
  8769. for _, subItem := range item.HisDoctorAdviceInfo {
  8770. total = total + (subItem.Price * subItem.PrescribingNumber)
  8771. }
  8772. }
  8773. if item.Type == 2 { //项目
  8774. for _, subItem := range item.HisPrescriptionProject {
  8775. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8776. total = total + (subItem.Price * cnt)
  8777. }
  8778. }
  8779. for _, subItem := range item.HisAdditionalCharge {
  8780. total = total + (subItem.Price * float64(subItem.Count))
  8781. }
  8782. }
  8783. if reg_type == 1111 || reg_type == 1112 {
  8784. reg_type = 11
  8785. }
  8786. tm := time.Unix(time.Now().Unix(), 0)
  8787. allTotal := fmt.Sprintf("%.4f", total)
  8788. totals, _ := strconv.ParseFloat(allTotal, 64)
  8789. order := &models.HisOrder{
  8790. UserOrgId: adminUser.CurrentOrgId,
  8791. HisPatientId: his.ID,
  8792. PatientId: id,
  8793. SettleAccountsDate: recordDateTime,
  8794. Ctime: time.Now().Unix(),
  8795. Mtime: time.Now().Unix(),
  8796. Status: 1,
  8797. OrderStatus: 2,
  8798. MdtrtId: his.Number,
  8799. Number: chrg_bchno,
  8800. MedfeeSumamt: totals,
  8801. PayWay: pay_way,
  8802. PayWays: pay_ways,
  8803. PayPrice: pay_price,
  8804. MedType: strconv.Itoa(int(reg_type)),
  8805. PayCardNo: pay_card_no,
  8806. DiscountPrice: discount_price,
  8807. PreferentialPrice: preferential_price,
  8808. RealityPrice: reality_price,
  8809. FoundPrice: found_price,
  8810. MedicalInsurancePrice: medical_insurance_price,
  8811. PrivatePrice: private_price,
  8812. SettleEndTime: end_time,
  8813. SettleStartTime: start_time,
  8814. PsnPartAmt: totals,
  8815. PsnCashPay: totals,
  8816. SettleType: settle_accounts_type,
  8817. FaPiaoCode: fapiao_code,
  8818. FaPiaoNumber: fapiao_number,
  8819. Diagnosis: diagnosis_id,
  8820. PType: 2,
  8821. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8822. Decimal: decimal,
  8823. OthDesc: oth_desc,
  8824. CashPay: cash_pay,
  8825. WechatPay: wechat_pay,
  8826. AliPay: ali_pay,
  8827. JifenPay: jifen_pay,
  8828. BandCardPay: band_card_pay,
  8829. Creator: adminUser.AdminUser.Id,
  8830. }
  8831. err = service.CreateOrderTX(order, tx)
  8832. if err != nil {
  8833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8834. return
  8835. }
  8836. var customs []*Custom
  8837. for _, item := range prescriptions {
  8838. if item.Type == 1 { //药品a
  8839. for _, subItem := range item.HisDoctorAdviceInfo {
  8840. cus := &Custom{
  8841. AdviceId: subItem.ID,
  8842. ProjectId: 0,
  8843. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8844. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8845. FeedetlSn: subItem.FeedetlSn,
  8846. Price: fmt.Sprintf("%.4f", subItem.Price),
  8847. MedListCodg: subItem.MedListCodg,
  8848. Type: 1,
  8849. CostType: 9,
  8850. }
  8851. customs = append(customs, cus)
  8852. }
  8853. }
  8854. if item.Type == 2 { //项目
  8855. for _, subItem := range item.HisPrescriptionProject {
  8856. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8857. cus := &Custom{
  8858. AdviceId: 0,
  8859. ProjectId: subItem.ID,
  8860. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8861. Cut: fmt.Sprintf("%.4f", cnt),
  8862. FeedetlSn: subItem.FeedetlSn,
  8863. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8864. MedListCodg: subItem.MedListCodg,
  8865. Type: 2,
  8866. CostType: subItem.HisProject.CostClassify,
  8867. }
  8868. customs = append(customs, cus)
  8869. }
  8870. }
  8871. for _, item := range item.HisAdditionalCharge {
  8872. cus := &Custom{
  8873. ItemId: item.ID,
  8874. AdviceId: 0,
  8875. ProjectId: 0,
  8876. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8877. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8878. FeedetlSn: item.FeedetlSn,
  8879. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8880. MedListCodg: item.XtHisAddtionConfig.Code,
  8881. Type: 3,
  8882. CostType: 5,
  8883. }
  8884. customs = append(customs, cus)
  8885. }
  8886. }
  8887. for _, item := range customs {
  8888. var advice_id int64 = 0
  8889. var project_id int64 = 0
  8890. var item_id int64 = 0
  8891. var types int64 = 0
  8892. var med_chrgitm_type string
  8893. if item.Type == 1 {
  8894. advice_id = item.AdviceId
  8895. project_id = 0
  8896. item_id = 0
  8897. med_chrgitm_type = "09"
  8898. } else if item.Type == 2 {
  8899. med_chrgitm_type = "05"
  8900. if item.CostType == 3 {
  8901. med_chrgitm_type = "04"
  8902. }
  8903. if item.CostType == 8 {
  8904. med_chrgitm_type = "03"
  8905. }
  8906. advice_id = 0
  8907. item_id = 0
  8908. project_id = item.ProjectId
  8909. } else if item.Type == 3 {
  8910. advice_id = 0
  8911. item_id = item.ItemId
  8912. project_id = 0
  8913. med_chrgitm_type = "08"
  8914. }
  8915. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8916. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8917. pric, _ := strconv.ParseFloat(item.Price, 32)
  8918. info := &models.HisOrderInfo{
  8919. OrderNumber: order.Number,
  8920. UploadDate: time.Now().Unix(),
  8921. AdviceId: advice_id,
  8922. DetItemFeeSumamt: detItemFeeSumamt,
  8923. MedChrgitmType: med_chrgitm_type,
  8924. Cnt: cut,
  8925. Pric: pric,
  8926. PatientId: id,
  8927. Status: 1,
  8928. Mtime: time.Now().Unix(),
  8929. Ctime: time.Now().Unix(),
  8930. UserOrgId: adminUser.CurrentOrgId,
  8931. HisPatientId: his.ID,
  8932. OrderId: order.ID,
  8933. ProjectId: project_id,
  8934. Type: types,
  8935. ItemId: item_id,
  8936. }
  8937. service.CreateOrderInfoTX(info, tx)
  8938. }
  8939. his.Diagnosis = diagnosis_id
  8940. his.SickType = sick_type
  8941. his.RegisterType = reg_type
  8942. his.MedicalTreatmentType = reg_type
  8943. service.UpdataHisPateintTX(&his, tx)
  8944. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8945. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8946. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8947. //判断是否使用了押金
  8948. if dec_way == "true" {
  8949. tmpstring := strconv.FormatInt(order.ID, 10)
  8950. //扣押金
  8951. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8952. order.Decimal = decimal
  8953. service.UpDateOrderTwo(order, tx)
  8954. if errmsg != nil {
  8955. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8956. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8957. return
  8958. }
  8959. }
  8960. if err == nil {
  8961. for _, info := range prescriptions {
  8962. if info.Type == 1 {
  8963. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8964. }
  8965. if info.Type == 2 {
  8966. for _, sumItem := range info.HisPrescriptionProject {
  8967. if sumItem.Type == 3 {
  8968. var good models.DialysisBeforePrepareGoods
  8969. var newGood models.NewDialysisBeforePrepareGoods
  8970. var oldGood models.OldDialysisBeforePrepareGoods
  8971. good.GoodId = sumItem.GoodInfo.ID
  8972. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8973. count, _ := strconv.Atoi(sumItem.Count)
  8974. good.Count = int64(count)
  8975. good.StorehouseId = houseConfig.StorehouseOutInfo
  8976. good.ProjectId = sumItem.ID
  8977. good.PatientId = sumItem.PatientId
  8978. goods = append(goods, &good)
  8979. newGood.GoodId = sumItem.GoodInfo.ID
  8980. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8981. count2, _ := strconv.Atoi(sumItem.Count)
  8982. newGood.Count = int64(count2)
  8983. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8984. newGood.ProjectId = sumItem.ID
  8985. newGood.PatientId = sumItem.HisPatientId
  8986. newGoods = append(newGoods, &newGood)
  8987. oldGood.GoodId = sumItem.GoodInfo.ID
  8988. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8989. count3, _ := strconv.Atoi(sumItem.Count)
  8990. oldGood.Count = int64(count3)
  8991. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8992. oldGood.ProjectId = sumItem.ID
  8993. oldGood.RecordDate = sumItem.RecordDate
  8994. oldGood.PatientId = sumItem.HisPatientId
  8995. oldGoods = append(oldGoods, &oldGood)
  8996. }
  8997. }
  8998. }
  8999. }
  9000. if settConfig.IsOpen == 1 {
  9001. for _, item := range infoList {
  9002. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9003. if medical.IsUse == 2 {
  9004. //药品出库
  9005. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9006. //查询默认仓库
  9007. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9008. //查询默认仓库剩余多少库存
  9009. var sum_count int64
  9010. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9011. for _, its := range stockInfo {
  9012. if its.MaxUnit == medical.MaxUnit {
  9013. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9014. }
  9015. sum_count += its.StockMaxNumber + its.StockMinNumber
  9016. }
  9017. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9018. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9019. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9020. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9021. }
  9022. }
  9023. orgId := c.GetAdminUserInfo().CurrentOrgId
  9024. if len(oldGoods) > 0 {
  9025. timeStr := time.Now().Format("2006-01-02")
  9026. timeArr := strings.Split(timeStr, "-")
  9027. total, _ := service.FindAllWarehouseOut(orgId)
  9028. total = total + 1
  9029. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9030. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9031. number = number + total
  9032. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9033. operation_time := time.Now().Unix()
  9034. creater := c.GetAdminUserInfo().AdminUser.Id
  9035. //查询默认出库仓库库存
  9036. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9037. recordDateStr := time.Now().Format("2006-01-02")
  9038. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9039. nowtime := recordDate.Unix()
  9040. warehouseOut := models.WarehouseOut{
  9041. WarehouseOutOrderNumber: warehousing_out_order,
  9042. OperationTime: operation_time,
  9043. OrgId: orgId,
  9044. Creater: creater,
  9045. Ctime: time.Now().Unix(),
  9046. Status: 1,
  9047. WarehouseOutTime: nowtime,
  9048. Type: 1,
  9049. StorehouseId: storeConfig.StorehouseOutInfo,
  9050. IsCheck: 1,
  9051. OrderId: order.ID,
  9052. IsSys: 5,
  9053. }
  9054. //查询是否生成出库单
  9055. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9056. if out.ID == 0 {
  9057. service.AddSigleWarehouseOut(&warehouseOut)
  9058. }
  9059. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9060. for _, item := range oldGoods {
  9061. dialyPrepareOne := models.DialysisBeforePrepare{
  9062. GoodTypeId: item.GoodTypeId,
  9063. GoodId: item.GoodId,
  9064. PatientId: his.PatientId,
  9065. RecordDate: item.RecordDate,
  9066. UserOrgId: adminUser.CurrentOrgId,
  9067. Count: item.Count,
  9068. Ctime: time.Now().Unix(),
  9069. Creater: adminUser.AdminUser.Id,
  9070. CommdityCode: item.CommdityCode,
  9071. Status: 1,
  9072. StorehouseId: houseConfig.StorehouseOutInfo,
  9073. }
  9074. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9075. //非零用
  9076. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9077. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9078. //查询剩余库存
  9079. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9080. var sum_count int64
  9081. for _, item := range goodList {
  9082. sum_count += item.StockCount
  9083. }
  9084. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9085. //耗材
  9086. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9087. }
  9088. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9089. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9090. //查询剩余库存
  9091. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9092. var sum_count int64
  9093. for _, item := range goodList {
  9094. sum_count += item.StockCount
  9095. }
  9096. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9097. //耗材
  9098. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9099. }
  9100. }
  9101. }
  9102. }
  9103. c.ServeSuccessJSON(map[string]interface{}{
  9104. "msg": "结算成功",
  9105. })
  9106. }
  9107. }
  9108. }
  9109. // 退款
  9110. func (c *HisApiController) Refund() {
  9111. order_id, _ := c.GetInt64("order_id")
  9112. order, _ := service.GetHisOrderByID(order_id)
  9113. adminUser := c.GetAdminUserInfo()
  9114. orgid := c.GetAdminUserInfo().CurrentOrgId
  9115. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9116. if err != nil {
  9117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9118. return
  9119. }
  9120. tmp := strconv.FormatInt(order.ID, 10)
  9121. //当押金不为零时产生退费记录
  9122. if order.Decimal != 0 {
  9123. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9124. if err != nil {
  9125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9126. return
  9127. }
  9128. }
  9129. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9130. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9131. var goods []*models.DialysisBeforePrepareGoods
  9132. var newGoods []*models.NewDialysisBeforePrepareGoods
  9133. var infos []*models.HisDoctorAdviceInfo
  9134. for _, info := range orders {
  9135. if info.AdviceId > 0 && info.ProjectId == 0 {
  9136. infos = append(infos, &info.HisDoctorAdviceInfo)
  9137. }
  9138. if info.ProjectId > 0 && info.AdviceId == 0 {
  9139. if info.HisPrescriptionProject.Type == 3 {
  9140. var good models.DialysisBeforePrepareGoods
  9141. var newGood models.NewDialysisBeforePrepareGoods
  9142. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9143. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9144. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9145. good.Count = int64(count)
  9146. good.StorehouseId = houseConfig.StorehouseOutInfo
  9147. good.ProjectId = info.HisPrescriptionProject.ID
  9148. good.PatientId = info.PatientId
  9149. good.OrderId = order_id
  9150. goods = append(goods, &good)
  9151. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9152. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9153. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9154. newGood.Count = int64(count2)
  9155. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9156. newGood.ProjectId = info.HisPrescriptionProject.ID
  9157. newGood.RecordDate = order.SettleAccountsDate
  9158. newGood.UserOrgId = order.UserOrgId
  9159. newGood.PatientId = info.PatientId
  9160. newGood.OrderId = order_id
  9161. newGoods = append(newGoods, &newGood)
  9162. }
  9163. }
  9164. }
  9165. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9166. if settConfig.IsOpen == 1 {
  9167. for _, item := range infos {
  9168. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9169. }
  9170. for _, item := range newGoods {
  9171. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9172. }
  9173. }
  9174. c.ServeSuccessJSON(map[string]interface{}{
  9175. "msg": "退费成功",
  9176. })
  9177. }
  9178. func (c *HisApiController) RefundNumber() {
  9179. his_patient_id, _ := c.GetInt64("id")
  9180. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9181. info.Status = 0
  9182. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9183. if count > 0 {
  9184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9185. return
  9186. }
  9187. err := service.SaveHisPatient(info)
  9188. if err == nil {
  9189. c.ServeSuccessJSON(map[string]interface{}{
  9190. "msg": "退号成功",
  9191. })
  9192. } else {
  9193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9194. return
  9195. }
  9196. }
  9197. func (this *HisApiController) AdditionalCharge() {
  9198. dataBody := make(map[string]interface{}, 0)
  9199. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9200. fmt.Println(err)
  9201. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9202. patient_id := int64(dataBody["patient_id"].(float64))
  9203. medicineData, _ := dataBody["medicineData"].([]interface{})
  9204. adminUserInfo := this.GetAdminUserInfo()
  9205. orgId := adminUserInfo.CurrentOrgId
  9206. admin_user_id := adminUserInfo.AdminUser.Id
  9207. timeStr := time.Now().Format("2006-01-02")
  9208. timeLayout := "2006-01-02 15:04:05"
  9209. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9210. timenow := timeStringToTime.Unix()
  9211. var additionalCharges []*models.HisAdditionalCharge
  9212. for _, item := range medicineData {
  9213. var randNum int
  9214. randNum = rand.Intn(10000) + 1000
  9215. timestamp := time.Now().Unix()
  9216. tempTime := time.Unix(timestamp, 0)
  9217. timeFormat := tempTime.Format("20060102150405")
  9218. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9219. items := item.(map[string]interface{})
  9220. money := items["price"].(string)
  9221. item_id_str := items["item_id"].(string)
  9222. name := items["name"].(string)
  9223. id_str := items["id"].(string)
  9224. moneys, _ := strconv.ParseInt(money, 10, 64)
  9225. monStr := strconv.FormatInt(moneys, 10)
  9226. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9227. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9228. id, _ := strconv.ParseInt(id_str, 10, 64)
  9229. additionalCharge := &models.HisAdditionalCharge{
  9230. ID: id,
  9231. HisPatientId: his_patient_id,
  9232. UserOrgId: orgId,
  9233. PatientId: patient_id,
  9234. RecordDate: timenow,
  9235. Price: monneyStr,
  9236. Status: 1,
  9237. ItemName: name,
  9238. ItemId: item_id,
  9239. AdminUserId: admin_user_id,
  9240. CreatedTime: time.Now().Unix(),
  9241. OrderStatus: 0,
  9242. PrescriptionNumber: "",
  9243. BatchNumber: "",
  9244. FeedetlSn: p_number,
  9245. }
  9246. service.CreateAdditionalCharge(additionalCharge)
  9247. additionalCharges = append(additionalCharges, additionalCharge)
  9248. }
  9249. this.ServeSuccessJSON(map[string]interface{}{
  9250. "msg": "添加成功",
  9251. "additional_charges": additionalCharges,
  9252. })
  9253. }
  9254. func (this *HisApiController) DeleteAddition() {
  9255. id, _ := this.GetInt64("id")
  9256. //TODO 需要判断是否已经结算
  9257. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9258. if err == nil {
  9259. this.ServeSuccessJSON(map[string]interface{}{
  9260. "msg": "删除成功",
  9261. })
  9262. return
  9263. } else {
  9264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9265. return
  9266. }
  9267. }
  9268. func (this *HisApiController) GetAdminUsers() {
  9269. adminUser := this.GetAdminUserInfo()
  9270. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9271. this.ServeSuccessJSON(map[string]interface{}{
  9272. "doctors": doctors,
  9273. })
  9274. }
  9275. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9276. change_type, _ := this.GetInt64("type", 0)
  9277. record_date := this.GetString("record_time")
  9278. patient_id, _ := this.GetInt64("patient_id", 0)
  9279. p_type, _ := this.GetInt64("p_type", 0)
  9280. timeLayout := "2006-01-02"
  9281. loc, _ := time.LoadLocation("Local")
  9282. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9283. record_time := theAdviceRecordTime.Unix()
  9284. adminUserInfo := this.GetAdminUserInfo()
  9285. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9286. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9287. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9288. if config.ID > 0 && config.IsOpen == 1 {
  9289. for _, subitems := range prescriptions {
  9290. for _, item := range subitems.VMHisPrescription {
  9291. for _, subItem := range item.HisDoctorAdviceInfo {
  9292. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9294. if info.RetailPrice > 0 {
  9295. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9296. subItem.Drug.RetailPrice = drug.RetailPrice
  9297. }
  9298. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9299. subItem.Drug.MinPrice = info.RetailPrice
  9300. subItem.Drug.RetailPrice = info.RetailPrice
  9301. }
  9302. }
  9303. }
  9304. }
  9305. }
  9306. }
  9307. if config.ID > 0 && config.IsOpen == 1 {
  9308. for _, subitems := range prescriptions {
  9309. for _, item := range subitems.VMHisPrescription {
  9310. for _, subItem := range item.HisPrescriptionProject {
  9311. if subItem.Type == 3 {
  9312. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9313. if info.Price > 0 {
  9314. subItem.GoodInfo.PackingPrice = info.Price
  9315. }
  9316. }
  9317. }
  9318. }
  9319. }
  9320. }
  9321. }
  9322. if err == nil {
  9323. if len(prescriptions) == 0 {
  9324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9325. return
  9326. } else {
  9327. this.ServeSuccessJSON(map[string]interface{}{
  9328. "prescriptions": prescriptions,
  9329. })
  9330. return
  9331. }
  9332. } else {
  9333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9334. return
  9335. }
  9336. }
  9337. func (this *HisApiController) GetCallHisPrescription() {
  9338. patient_id, _ := this.GetInt64("patient_id", 0)
  9339. timeLayout := "2006-01-02"
  9340. loc, _ := time.LoadLocation("Local")
  9341. start_time := this.GetString("start_time")
  9342. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9343. end_time := this.GetString("end_time")
  9344. p_type, _ := this.GetInt64("p_type")
  9345. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9346. adminUserInfo := this.GetAdminUserInfo()
  9347. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9348. //if
  9349. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9350. //
  9351. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9352. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9353. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9354. if config.ID > 0 && config.IsOpen == 1 {
  9355. for _, subitems := range prescriptions {
  9356. for _, item := range subitems.VMHisPrescription {
  9357. for _, subItem := range item.HisDoctorAdviceInfo {
  9358. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9359. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9360. if info.RetailPrice > 0 {
  9361. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9362. subItem.Drug.RetailPrice = drug.RetailPrice
  9363. }
  9364. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9365. subItem.Drug.MinPrice = info.RetailPrice
  9366. subItem.Drug.RetailPrice = info.RetailPrice
  9367. }
  9368. }
  9369. }
  9370. }
  9371. }
  9372. }
  9373. if config.ID > 0 && config.IsOpen == 1 {
  9374. for _, subitems := range prescriptions {
  9375. for _, item := range subitems.VMHisPrescription {
  9376. for _, subItem := range item.HisPrescriptionProject {
  9377. if subItem.Type == 3 {
  9378. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9379. if info.Price > 0 {
  9380. subItem.GoodInfo.PackingPrice = info.Price
  9381. }
  9382. }
  9383. }
  9384. }
  9385. }
  9386. }
  9387. }
  9388. if err == nil {
  9389. this.ServeSuccessJSON(map[string]interface{}{
  9390. "prescriptions": prescriptions,
  9391. })
  9392. return
  9393. } else {
  9394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9395. return
  9396. }
  9397. }
  9398. func (this *HisApiController) GetHisDayPrescription() {
  9399. timeLayout := "2006-01-02"
  9400. loc, _ := time.LoadLocation("Local")
  9401. start_time := this.GetString("start_time")
  9402. patient_id, _ := this.GetInt64("patient_id", 0)
  9403. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9404. end_time := this.GetString("end_time")
  9405. p_type, _ := this.GetInt64("p_type")
  9406. order_status, _ := this.GetInt64("type")
  9407. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9408. adminUserInfo := this.GetAdminUserInfo()
  9409. var dayHisPrescription []*models.HisPrescription
  9410. var err error
  9411. if order_status == 1 || order_status == 0 {
  9412. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9413. } else if order_status == 2 {
  9414. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9415. }
  9416. var settle_total float64
  9417. for _, item := range dayHisPrescription {
  9418. if len(item.HisPrescriptionProject) > 0 {
  9419. for _, subItem := range item.HisPrescriptionProject {
  9420. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9421. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9422. settle_total = settle_total + total
  9423. }
  9424. }
  9425. if len(item.HisDoctorAdviceInfo) > 0 {
  9426. for _, subItem := range item.HisDoctorAdviceInfo {
  9427. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9428. settle_total = settle_total + total
  9429. }
  9430. }
  9431. }
  9432. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9433. if err == nil {
  9434. this.ServeSuccessJSON(map[string]interface{}{
  9435. "day_prescription": dayHisPrescription,
  9436. "settle_total": settle_total,
  9437. })
  9438. return
  9439. } else {
  9440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9441. return
  9442. }
  9443. }
  9444. func (c *HisApiController) GetHisChargePatientList() {
  9445. record_date := c.GetString("record_date")
  9446. order_status, _ := c.GetInt64("type")
  9447. sch_type, _ := c.GetInt64("sch_type")
  9448. timeLayout := "2006-01-02"
  9449. loc, _ := time.LoadLocation("Local")
  9450. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9451. if err != nil {
  9452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9453. return
  9454. }
  9455. recordDateTime := theTime.Unix()
  9456. adminInfo := c.GetAdminUserInfo()
  9457. var tempPatients []*service.NewTempPatients
  9458. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9459. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9460. if order_status != 2 {
  9461. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9462. } else {
  9463. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9464. }
  9465. } else {
  9466. if order_status != 2 {
  9467. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9468. } else {
  9469. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9470. }
  9471. }
  9472. var patients []*service.NewTempPatients
  9473. var patients_two []*service.NewTempPatients
  9474. for _, item := range tempPatients {
  9475. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9476. //过滤掉没挂号的和没开处方的
  9477. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9478. patients = append(patients, item)
  9479. }
  9480. //过滤掉没挂号的
  9481. if len(item.HisPatient) > 0 {
  9482. patients_two = append(patients_two, item)
  9483. }
  9484. } else {
  9485. if len(item.HisPrescription) > 0 {
  9486. patients = append(patients, item)
  9487. }
  9488. }
  9489. }
  9490. c.ServeSuccessJSON(map[string]interface{}{
  9491. "list": patients,
  9492. "list_two": patients_two,
  9493. })
  9494. }
  9495. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9496. record_date := c.GetString("record_date")
  9497. timeLayout := "2006-01-02"
  9498. loc, _ := time.LoadLocation("Local")
  9499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9500. if err != nil {
  9501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9502. return
  9503. }
  9504. recordDateTime := theTime.Unix()
  9505. adminUser := c.GetAdminUserInfo()
  9506. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9507. var patients []*service.Patients
  9508. for _, item := range tempPatients {
  9509. if item.HisPatient.ID == 0 {
  9510. patients = append(patients, item)
  9511. }
  9512. }
  9513. c.ServeSuccessJSON(map[string]interface{}{
  9514. "list": patients,
  9515. //"list_two": patients_two,
  9516. })
  9517. }
  9518. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9519. newArr = make([]*service.Patients, 0)
  9520. for i := 0; i < len(patient); i++ {
  9521. repeat := false
  9522. for j := i + 1; j < len(patient); j++ {
  9523. if patient[i].ID == patient[j].ID {
  9524. repeat = true
  9525. break
  9526. }
  9527. }
  9528. if !repeat {
  9529. newArr = append(newArr, patient[i])
  9530. }
  9531. }
  9532. return
  9533. }
  9534. func (c *HisApiController) GetHisChargePatientInfo() {
  9535. patient_id, _ := c.GetInt64("patient_id")
  9536. his_patient_id, _ := c.GetInt64("his_patient_id")
  9537. record_date := c.GetString("record_date")
  9538. //start_time := c.GetString("start_time")
  9539. //end_time := c.GetString("end_time")
  9540. order_status, _ := c.GetInt64("type", 0)
  9541. p_type, _ := c.GetInt64("p_type", 0)
  9542. order_id, _ := c.GetInt64("order_id", 0)
  9543. timeLayout := "2006-01-02"
  9544. loc, _ := time.LoadLocation("Local")
  9545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9546. if err != nil {
  9547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9548. return
  9549. }
  9550. recordDateTime := theTime.Unix()
  9551. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9552. //if err != nil {
  9553. //
  9554. //}
  9555. //startRecordDateTime := startTime.Unix()
  9556. //
  9557. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9558. //if err != nil {
  9559. //
  9560. //}
  9561. //endRecordDateTime := endTime.Unix()
  9562. admin := c.GetAdminUserInfo()
  9563. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9564. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9565. var prescriptions []*models.HisPrescription
  9566. //var unChargeMonthPrescriptions []*models.HisPrescription
  9567. order, _ := service.GetHisOrderByID(order_id)
  9568. if order_status == 1 || order_status == 0 {
  9569. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9570. } else if order_status == 2 {
  9571. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9572. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9573. }
  9574. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9575. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9576. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9577. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9578. //获取所有科室信息
  9579. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9580. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9581. c.ServeSuccessJSON(map[string]interface{}{
  9582. "his_info": his_patient_info,
  9583. "xt_info": xt_patient_info,
  9584. "prescription": prescriptions,
  9585. "case_history": case_history,
  9586. "info": patientPrescriptionInfo,
  9587. "last_info": lastPatientPrescriptionInfo,
  9588. "order": order,
  9589. "doctors": doctors,
  9590. "department": department,
  9591. "sch": sch,
  9592. })
  9593. return
  9594. }
  9595. func (c *HisApiController) GetAllOrderDetail() {
  9596. order_id, _ := c.GetInt64("id", 0)
  9597. order, _ := service.GetHisOrderByID(order_id)
  9598. if order.ID == 0 {
  9599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9600. return
  9601. }
  9602. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9603. org_id := c.GetAdminUserInfo().CurrentOrgId
  9604. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9605. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9606. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9607. c.ServeSuccessJSON(map[string]interface{}{
  9608. "order": order,
  9609. "order_info": order_info,
  9610. "patient": patient,
  9611. "admin_info": adminInfo,
  9612. "hospital_record": record,
  9613. })
  9614. return
  9615. }
  9616. func (c *HisApiController) GetAllOrderDetailCollect() {
  9617. order_id, _ := c.GetInt64("id", 0)
  9618. order, _ := service.GetHisOrderByID(order_id)
  9619. if order.ID == 0 {
  9620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9621. return
  9622. }
  9623. org_id := c.GetAdminUserInfo().CurrentOrgId
  9624. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9625. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9626. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9627. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9628. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9629. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9630. var bedCostTotal float64 = 0 //床位总费
  9631. //var bedCostSelfTotal float64 = 0 //床位自费
  9632. var operationCostTotal float64 = 0 //手术费
  9633. //var operationCostSelfTotal float64 = 0 //手术费
  9634. var otherCostTotal float64 = 0 //其他费用
  9635. //var otherCostSelfTotal float64 = 0 //其他费用
  9636. var materialCostTotal float64 = 0 //材料费
  9637. //var materialCostSelfTotal float64 = 0 //材料费
  9638. var westernMedicineCostTotal float64 = 0 //西药费
  9639. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9640. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9641. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9642. var checkCostTotal float64 = 0 //检查费
  9643. //var checkCostSelfTotal float64 = 0 //检查费
  9644. var laboratoryCostTotal float64 = 0 //化验费
  9645. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9646. var treatCostTotal float64 = 0 //治疗费用
  9647. //var treatCostSelfTotal float64 = 0 //治疗费用
  9648. var zhenChaCostTotal float64 = 0 //其他费用
  9649. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9650. decimal.DivisionPrecision = 2
  9651. var BalanceAccountsType int64
  9652. if his.ID > 0 {
  9653. BalanceAccountsType = his.BalanceAccountsType
  9654. } else {
  9655. BalanceAccountsType = record.BalanceAccountsType
  9656. }
  9657. if BalanceAccountsType != 2 {
  9658. for _, item := range order_info {
  9659. if org_id == 10215 {
  9660. if item.MedChrgitmType == "01" { //床位费
  9661. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9662. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9663. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9664. }
  9665. if item.MedChrgitmType == "02" { //诊察费
  9666. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9667. //zhenChaCostSelfTotal = zhenChaCostTotal
  9668. }
  9669. if item.MedChrgitmType == "03" { //检查费
  9670. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9671. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9672. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9673. }
  9674. //if item.MedChrgitmType == "02" { //检查费
  9675. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9677. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9678. //}
  9679. if item.MedChrgitmType == "04" { //化验费
  9680. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9681. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9682. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9683. }
  9684. if item.MedChrgitmType == "05" { //治疗费
  9685. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9686. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9687. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9688. }
  9689. if item.MedChrgitmType == "06" { //手术费
  9690. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9691. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9692. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9693. }
  9694. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9695. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9696. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9697. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9698. }
  9699. if item.MedChrgitmType == "09" { //西药费
  9700. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9701. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9702. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9703. }
  9704. if item.MedChrgitmType == "11" { //中成费
  9705. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9706. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9707. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9708. }
  9709. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9710. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9711. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9712. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9713. }
  9714. } else if org_id == 10188 || org_id == 10217 {
  9715. if item.MedChrgitmType == "01" { //床位费
  9716. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9717. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9718. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9719. }
  9720. if item.MedChrgitmType == "02" { //诊察费
  9721. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9722. //zhenChaCostSelfTotal = zhenChaCostTotal
  9723. }
  9724. if item.MedChrgitmType == "03" { //检查费
  9725. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9726. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9727. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9728. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9729. }
  9730. //if item.MedChrgitmType == "02" { //检查费
  9731. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9732. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9733. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9734. //}
  9735. if item.MedChrgitmType == "04" { //化验费
  9736. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9737. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9738. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9739. }
  9740. if item.MedChrgitmType == "05" { //治疗费
  9741. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9742. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9743. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9744. }
  9745. if item.MedChrgitmType == "06" { //手术费
  9746. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9747. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9748. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9749. }
  9750. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9751. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9752. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9753. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9754. }
  9755. if item.MedChrgitmType == "09" { //西药费
  9756. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9757. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9758. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9759. }
  9760. if item.MedChrgitmType == "11" { //中成费
  9761. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9762. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9763. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9764. }
  9765. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9766. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9767. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9768. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9769. }
  9770. } else {
  9771. if item.MedChrgitmType == "01" { //床位费
  9772. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9773. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9774. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9775. }
  9776. //if item.MedChrgitmType == "02" { //诊察费
  9777. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9778. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9779. //}
  9780. if item.MedChrgitmType == "03" { //检查费
  9781. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9782. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9783. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9784. }
  9785. //if item.MedChrgitmType == "02" { //检查费
  9786. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9787. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9788. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9789. //}
  9790. if item.MedChrgitmType == "04" { //化验费
  9791. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9792. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9793. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9794. }
  9795. if item.MedChrgitmType == "05" { //治疗费
  9796. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9797. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9798. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9799. }
  9800. if item.MedChrgitmType == "06" { //手术费
  9801. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9802. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9803. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9804. }
  9805. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9806. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9807. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9808. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9809. }
  9810. if item.MedChrgitmType == "09" { //西药费
  9811. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9812. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9813. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9814. }
  9815. if item.MedChrgitmType == "11" { //中成费
  9816. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. }
  9820. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9821. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9822. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9823. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9824. }
  9825. }
  9826. }
  9827. c.ServeSuccessJSON(map[string]interface{}{
  9828. "order": order,
  9829. "order_info": order_info,
  9830. "patient": patient,
  9831. "admin_info": adminInfo,
  9832. "his_hospital": record,
  9833. "bedCostTotal": bedCostTotal,
  9834. "operationCostTotal": operationCostTotal,
  9835. "otherCostTotal": otherCostTotal,
  9836. "materialCostTotal": materialCostTotal,
  9837. "westernMedicineCostTotal": westernMedicineCostTotal,
  9838. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9839. "checkCostTotal": checkCostTotal,
  9840. "zhenChaCostTotal": zhenChaCostTotal,
  9841. "laboratoryCostTotal": laboratoryCostTotal,
  9842. "treatCostTotal": treatCostTotal,
  9843. })
  9844. } else {
  9845. for _, item := range order_info {
  9846. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9847. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9848. item.MedChrgitmType = "09"
  9849. }
  9850. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9851. if item.HisPrescriptionProject.Type == 2 {
  9852. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9853. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9854. case 0:
  9855. item.MedChrgitmType = "0"
  9856. break
  9857. case 1:
  9858. item.MedChrgitmType = "14"
  9859. break
  9860. case 2:
  9861. item.MedChrgitmType = "05"
  9862. break
  9863. case 3:
  9864. item.MedChrgitmType = "03"
  9865. break
  9866. case 4:
  9867. item.MedChrgitmType = "03"
  9868. break
  9869. case 5:
  9870. item.MedChrgitmType = "08"
  9871. break
  9872. case 6:
  9873. item.MedChrgitmType = "14"
  9874. break
  9875. case 7:
  9876. item.MedChrgitmType = "14"
  9877. break
  9878. case 8:
  9879. item.MedChrgitmType = "03"
  9880. break
  9881. case 9:
  9882. item.MedChrgitmType = "14"
  9883. break
  9884. case 10:
  9885. item.MedChrgitmType = "14"
  9886. break
  9887. case 11:
  9888. item.MedChrgitmType = "06"
  9889. break
  9890. case 12:
  9891. item.MedChrgitmType = "12"
  9892. break
  9893. case 13:
  9894. item.MedChrgitmType = "01"
  9895. break
  9896. case 14:
  9897. item.MedChrgitmType = "04"
  9898. break
  9899. case 15:
  9900. item.MedChrgitmType = "14"
  9901. break
  9902. }
  9903. } else {
  9904. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9905. case 1:
  9906. item.MedChrgitmType = "14"
  9907. break
  9908. case 2:
  9909. item.MedChrgitmType = "05"
  9910. break
  9911. case 3:
  9912. item.MedChrgitmType = "04"
  9913. break
  9914. case 4:
  9915. item.MedChrgitmType = "14"
  9916. break
  9917. case 5:
  9918. item.MedChrgitmType = "08"
  9919. break
  9920. case 6:
  9921. item.MedChrgitmType = "14"
  9922. break
  9923. case 7:
  9924. item.MedChrgitmType = "14"
  9925. break
  9926. case 8:
  9927. item.MedChrgitmType = "03"
  9928. break
  9929. case 9:
  9930. item.MedChrgitmType = "14"
  9931. break
  9932. }
  9933. }
  9934. } else if item.HisPrescriptionProject.Type == 3 {
  9935. item.MedChrgitmType = "08"
  9936. }
  9937. }
  9938. }
  9939. for _, item := range order_info {
  9940. if org_id == 10215 {
  9941. if item.MedChrgitmType == "01" { //床位费
  9942. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9943. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9944. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9945. }
  9946. if item.MedChrgitmType == "02" { //诊察费
  9947. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9948. //zhenChaCostSelfTotal = zhenChaCostTotal
  9949. }
  9950. if item.MedChrgitmType == "03" { //检查费
  9951. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9952. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9953. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9954. }
  9955. //if item.MedChrgitmType == "02" { //检查费
  9956. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9957. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9958. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9959. //}
  9960. if item.MedChrgitmType == "04" { //化验费
  9961. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9962. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9963. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9964. }
  9965. if item.MedChrgitmType == "05" { //治疗费
  9966. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9967. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9968. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9969. }
  9970. if item.MedChrgitmType == "06" { //手术费
  9971. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9972. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9973. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9974. }
  9975. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9976. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9977. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9978. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9979. }
  9980. if item.MedChrgitmType == "09" { //西药费
  9981. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9982. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9983. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9984. }
  9985. if item.MedChrgitmType == "11" { //中成费
  9986. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9987. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9988. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9989. }
  9990. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9991. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9992. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9993. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9994. }
  9995. } else {
  9996. if item.MedChrgitmType == "01" { //床位费
  9997. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9998. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9999. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10000. }
  10001. //if item.MedChrgitmType == "02" { //诊察费
  10002. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10003. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10004. //}
  10005. if item.MedChrgitmType == "03" { //检查费
  10006. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10007. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10008. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10009. }
  10010. //if item.MedChrgitmType == "02" { //检查费
  10011. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10012. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10013. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10014. //}
  10015. if item.MedChrgitmType == "04" { //化验费
  10016. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10017. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10018. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10019. }
  10020. if item.MedChrgitmType == "05" { //治疗费
  10021. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10022. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10023. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10024. }
  10025. if item.MedChrgitmType == "06" { //手术费
  10026. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10027. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10028. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10029. }
  10030. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10031. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10032. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10033. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10034. }
  10035. if item.MedChrgitmType == "09" { //西药费
  10036. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10037. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10038. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10039. }
  10040. if item.MedChrgitmType == "11" { //中成费
  10041. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10042. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10043. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10044. }
  10045. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10046. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10047. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10048. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10049. }
  10050. }
  10051. }
  10052. c.ServeSuccessJSON(map[string]interface{}{
  10053. "order": order,
  10054. "order_info": order_info,
  10055. "patient": patient,
  10056. "admin_info": adminInfo,
  10057. "his_hospital": record,
  10058. "bedCostTotal": bedCostTotal,
  10059. "operationCostTotal": operationCostTotal,
  10060. "otherCostTotal": otherCostTotal,
  10061. "materialCostTotal": materialCostTotal,
  10062. "westernMedicineCostTotal": westernMedicineCostTotal,
  10063. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10064. "checkCostTotal": checkCostTotal,
  10065. "zhenChaCostTotal": zhenChaCostTotal,
  10066. "laboratoryCostTotal": laboratoryCostTotal,
  10067. "treatCostTotal": treatCostTotal,
  10068. })
  10069. }
  10070. }
  10071. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10072. page, _ := c.GetInt64("page")
  10073. limit, _ := c.GetInt64("limit")
  10074. keywords := c.GetString("keywords")
  10075. start_time := c.GetString("start_time")
  10076. end_time := c.GetString("end_time")
  10077. //clr_type := c.GetString("clr_type")
  10078. insutype := c.GetString("insutype")
  10079. timeLayout := "2006-01-02"
  10080. loc, _ := time.LoadLocation("Local")
  10081. var theStartTIme int64
  10082. if len(start_time) > 0 {
  10083. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10084. theStartTIme = theTime.Unix()
  10085. }
  10086. var theEndtTIme int64
  10087. if len(end_time) > 0 {
  10088. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10089. theEndtTIme = theTime.Unix()
  10090. }
  10091. if page <= 0 {
  10092. page = 1
  10093. }
  10094. if limit <= 0 {
  10095. limit = 10
  10096. }
  10097. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10098. c.ServeSuccessJSON(map[string]interface{}{
  10099. "total": total,
  10100. "list": list,
  10101. })
  10102. return
  10103. }
  10104. func (c *HisApiController) GetPutOnRecordList() {
  10105. page, _ := c.GetInt64("page")
  10106. limit, _ := c.GetInt64("limit")
  10107. keywords := c.GetString("keywords")
  10108. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10109. if page <= 0 {
  10110. page = 1
  10111. }
  10112. if limit <= 0 {
  10113. limit = 10
  10114. }
  10115. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10116. c.ServeSuccessJSON(map[string]interface{}{
  10117. "total": total,
  10118. "list": list,
  10119. })
  10120. return
  10121. }
  10122. func (c *HisApiController) GetCompareData() {
  10123. start_time := c.GetString("start_time")
  10124. end_time := c.GetString("end_time")
  10125. insutype := c.GetString("insutype")
  10126. clr_type := c.GetString("clr_type")
  10127. timeLayout := "2006-01-02"
  10128. loc, _ := time.LoadLocation("Local")
  10129. var theStartTIme int64
  10130. if len(start_time) > 0 {
  10131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10132. if err != nil {
  10133. theStartTIme = 0
  10134. }
  10135. theStartTIme = theTime.Unix()
  10136. }
  10137. var theEndtTIme int64
  10138. if len(end_time) > 0 {
  10139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10140. if err != nil {
  10141. theEndtTIme = 0
  10142. }
  10143. theEndtTIme = theTime.Unix()
  10144. }
  10145. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10146. fmt.Println(err)
  10147. if err == nil {
  10148. c.ServeSuccessJSON(map[string]interface{}{
  10149. "list": formData,
  10150. })
  10151. } else {
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10153. return
  10154. }
  10155. }
  10156. func (c *HisApiController) GetFaPiaoData() {
  10157. order_id, _ := c.GetInt64("order_id")
  10158. patient_id, _ := c.GetInt64("patient_id")
  10159. //number := c.GetString("number")
  10160. adminUser := c.GetAdminUserInfo()
  10161. order, _ := service.GetHisOrderByID(order_id)
  10162. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10163. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10164. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10165. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10166. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10167. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10168. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10169. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10170. var bedCostTotal float64 = 0 //床位总费
  10171. var bedCostSelfTotal float64 = 0 //床位自费
  10172. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10173. var operationCostTotal float64 = 0 //手术费
  10174. var operationCostSelfTotal float64 = 0 //手术费
  10175. var operationCostPartSelfTotal float64 = 0 //手术费
  10176. var otherCostTotal float64 = 0 //其他费用
  10177. var otherCostSelfTotal float64 = 0 //其他费用
  10178. var otherCostPartSelfTotal float64 = 0 //其他费用
  10179. var materialCostTotal float64 = 0 //材料费
  10180. var materialCostSelfTotal float64 = 0 //材料费
  10181. var materialCostPartSelfTotal float64 = 0 //材料费
  10182. var westernMedicineCostTotal float64 = 0 //西药费
  10183. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10184. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10185. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10186. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10187. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10188. var checkCostTotal float64 = 0 //检查费
  10189. var checkCostSelfTotal float64 = 0 //检查费
  10190. var checkCostPartSelfTotal float64 = 0 //检查费
  10191. var hiliCostTotal float64 = 0 //护理费
  10192. var hiliCostSelfTotal float64 = 0 //护理费
  10193. var hiliCostPartSelfTotal float64 = 0 //护理费
  10194. var laboratoryCostTotal float64 = 0 //化验费
  10195. var laboratoryCostSelfTotal float64 = 0 //化验费
  10196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10197. var treatCostTotal float64 = 0 //治疗费用
  10198. var treatCostSelfTotal float64 = 0 //治疗费用
  10199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10200. var zhenChaCostTotal float64 = 0 //其他费用
  10201. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10202. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10203. decimal.DivisionPrecision = 2
  10204. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10205. var balanceAccountsType int64
  10206. if his.ID > 0 {
  10207. balanceAccountsType = his.BalanceAccountsType
  10208. } else {
  10209. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10210. }
  10211. if balanceAccountsType == 2 {
  10212. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10213. for _, item := range orderInfos_two {
  10214. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10215. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10216. item.MedChrgitmType = "09"
  10217. }
  10218. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10219. if item.HisPrescriptionProject.Type == 2 {
  10220. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10221. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10222. case 0:
  10223. item.MedChrgitmType = "0"
  10224. break
  10225. case 1:
  10226. item.MedChrgitmType = "14"
  10227. break
  10228. case 2:
  10229. item.MedChrgitmType = "05"
  10230. break
  10231. case 3:
  10232. item.MedChrgitmType = "03"
  10233. break
  10234. case 4:
  10235. item.MedChrgitmType = "03"
  10236. break
  10237. case 5:
  10238. item.MedChrgitmType = "08"
  10239. break
  10240. case 6:
  10241. item.MedChrgitmType = "14"
  10242. break
  10243. case 7:
  10244. item.MedChrgitmType = "14"
  10245. break
  10246. case 8:
  10247. item.MedChrgitmType = "03"
  10248. break
  10249. case 9:
  10250. item.MedChrgitmType = "14"
  10251. break
  10252. case 10:
  10253. item.MedChrgitmType = "14"
  10254. break
  10255. case 11:
  10256. item.MedChrgitmType = "06"
  10257. break
  10258. case 12:
  10259. item.MedChrgitmType = "12"
  10260. break
  10261. case 13:
  10262. item.MedChrgitmType = "01"
  10263. break
  10264. case 14:
  10265. item.MedChrgitmType = "04"
  10266. break
  10267. case 15:
  10268. item.MedChrgitmType = "02"
  10269. break
  10270. }
  10271. } else {
  10272. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10273. case 1:
  10274. item.MedChrgitmType = "14"
  10275. break
  10276. case 2:
  10277. item.MedChrgitmType = "05"
  10278. break
  10279. case 3:
  10280. item.MedChrgitmType = "04"
  10281. break
  10282. case 4:
  10283. item.MedChrgitmType = "03"
  10284. break
  10285. case 5:
  10286. item.MedChrgitmType = "08"
  10287. break
  10288. case 6:
  10289. item.MedChrgitmType = "14"
  10290. break
  10291. case 7:
  10292. item.MedChrgitmType = "14"
  10293. break
  10294. case 8:
  10295. item.MedChrgitmType = "03"
  10296. break
  10297. case 9:
  10298. item.MedChrgitmType = "14"
  10299. break
  10300. }
  10301. }
  10302. } else if item.HisPrescriptionProject.Type == 3 {
  10303. item.MedChrgitmType = "08"
  10304. }
  10305. }
  10306. }
  10307. for _, item := range orderInfos_two {
  10308. fmt.Println(item.MedChrgitmType)
  10309. if item.MedChrgitmType == "07" { //床位费
  10310. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10311. hiliCostSelfTotal = hiliCostTotal
  10312. }
  10313. if item.MedChrgitmType == "01" { //床位费
  10314. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10315. bedCostSelfTotal = bedCostTotal
  10316. }
  10317. if item.MedChrgitmType == "02" { //诊察费
  10318. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10319. zhenChaCostSelfTotal = zhenChaCostTotal
  10320. }
  10321. if item.MedChrgitmType == "03" { //检查费
  10322. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10323. checkCostSelfTotal = checkCostTotal
  10324. }
  10325. if item.MedChrgitmType == "04" { //化验费
  10326. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. laboratoryCostSelfTotal = laboratoryCostTotal
  10328. }
  10329. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10330. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10331. treatCostSelfTotal = treatCostTotal
  10332. }
  10333. if item.MedChrgitmType == "06" { //手术费
  10334. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10335. operationCostSelfTotal = treatCostTotal
  10336. }
  10337. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10338. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10339. materialCostSelfTotal = materialCostTotal
  10340. }
  10341. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10342. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10343. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10344. }
  10345. if item.MedChrgitmType == "11" { //中成费
  10346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10348. }
  10349. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10350. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. otherCostSelfTotal = otherCostTotal
  10353. }
  10354. } else {
  10355. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10356. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. otherCostSelfTotal = otherCostTotal
  10358. }
  10359. }
  10360. }
  10361. } else {
  10362. for _, item := range orderInfos {
  10363. if item.MedChrgitmType == "01" { //床位费
  10364. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10365. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10366. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10367. }
  10368. if item.MedChrgitmType == "02" { //诊察费
  10369. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10370. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10371. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10372. }
  10373. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10374. if item.MedChrgitmType == "03" { //检查费
  10375. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10376. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10377. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10378. }
  10379. } else {
  10380. if item.MedChrgitmType == "03" { //检查费
  10381. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10382. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10383. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10384. }
  10385. }
  10386. if item.MedChrgitmType == "04" { //化验费
  10387. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10388. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10389. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10390. }
  10391. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10392. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10393. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10394. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10395. }
  10396. if item.MedChrgitmType == "06" { //手术费
  10397. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10398. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10399. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10400. }
  10401. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10402. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10403. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10404. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10405. }
  10406. if item.MedChrgitmType == "07" { //护理
  10407. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10408. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10409. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10410. }
  10411. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10412. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10413. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10414. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10415. }
  10416. if item.MedChrgitmType == "11" { //中成费
  10417. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10418. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10419. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10420. }
  10421. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10422. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10423. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10424. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10425. }
  10426. }
  10427. }
  10428. timeLayout := "2006-01-02"
  10429. loc, _ := time.LoadLocation("Local")
  10430. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10431. if err != nil {
  10432. }
  10433. startRecordDateTime := startTime.Unix()
  10434. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10435. if err != nil {
  10436. }
  10437. endRecordDateTime := endTime.Unix()
  10438. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10439. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10440. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10441. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10442. c.ServeSuccessJSON(map[string]interface{}{
  10443. "charge_admin_name": charge_admin.UserName,
  10444. "order_number": order.Number, //业务流水号
  10445. "id_card_no": his.IdCardNo, //社会保障号
  10446. "patient": patient,
  10447. "department_name": department.Name, //科室
  10448. "number": his.Number, //门诊号
  10449. "date": order.SettleAccountsDate, //结算日期
  10450. "name": order.PsnName, //姓名
  10451. "gender": patient.Gender, //性别
  10452. "psn_cash_money": order.PsnCashPay, //个人支付
  10453. "pay_way": "门诊", //结算方式
  10454. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10455. "admin_user_name": admin.UserName, //收款员
  10456. "order": order,
  10457. "order_info": orderInfos_two,
  10458. "his": his,
  10459. "bedCostTotal": bedCostTotal,
  10460. "bedCostSelfTotal": bedCostSelfTotal,
  10461. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10462. "operationCostTotal": operationCostTotal,
  10463. "operationCostSelfTotal": operationCostSelfTotal,
  10464. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10465. "otherCostTotal": otherCostTotal,
  10466. "otherCostSelfTotal": otherCostSelfTotal,
  10467. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10468. "materialCostTotal": materialCostTotal,
  10469. "materialCostSelfTotal": materialCostSelfTotal,
  10470. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10471. "westernMedicineCostTotal": westernMedicineCostTotal,
  10472. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10473. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10474. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10475. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10476. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10477. "checkCostTotal": checkCostTotal,
  10478. "checkCostSelfTotal": checkCostSelfTotal,
  10479. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10480. "laboratoryCostTotal": laboratoryCostTotal,
  10481. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10482. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10483. "treatCostTotal": treatCostTotal,
  10484. "treatCostSelfTotal": treatCostSelfTotal,
  10485. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10486. "zhenChaCostTotal": zhenChaCostTotal,
  10487. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10488. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10489. "his_hospital_record": his_hospital_record,
  10490. "pre_pay_money": pre_pay_money,
  10491. "refund_sum": sum,
  10492. "doctor_info": doctor_info,
  10493. "hiliCostTotal": hiliCostTotal,
  10494. "hiliCostSelfTotal": hiliCostSelfTotal,
  10495. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10496. })
  10497. }
  10498. //func (c *HisApiController) GetFaPiaoDatas() {
  10499. // order_ids := c.GetString("order_ids")
  10500. // patient_id, _ := c.GetInt64("patient_id")
  10501. // adminUser := c.GetAdminUserInfo()
  10502. //
  10503. // orders := strings.Split(order_ids, ",")
  10504. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10505. //
  10506. // for _, item := range orders {
  10507. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10508. // order, _ := service.GetHisOrderByID(order_id)
  10509. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10510. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10511. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10512. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10513. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10514. //
  10515. // }
  10516. //
  10517. // var bedCostTotal float64 = 0 //床位总费
  10518. // var bedCostSelfTotal float64 = 0 //床位自费
  10519. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10520. //
  10521. // var operationCostTotal float64 = 0 //手术费
  10522. // var operationCostSelfTotal float64 = 0 //手术费
  10523. // var operationCostPartSelfTotal float64 = 0 //手术费
  10524. //
  10525. // var otherCostTotal float64 = 0 //其他费用
  10526. // var otherCostSelfTotal float64 = 0 //其他费用
  10527. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10528. //
  10529. // var materialCostTotal float64 = 0 //材料费
  10530. // var materialCostSelfTotal float64 = 0 //材料费
  10531. // var materialCostPartSelfTotal float64 = 0 //材料费
  10532. //
  10533. // var westernMedicineCostTotal float64 = 0 //西药费
  10534. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10535. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10536. //
  10537. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10538. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10539. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10540. //
  10541. // var checkCostTotal float64 = 0 //检查费
  10542. // var checkCostSelfTotal float64 = 0 //检查费
  10543. // var checkCostPartSelfTotal float64 = 0 //检查费
  10544. //
  10545. // var laboratoryCostTotal float64 = 0 //化验费
  10546. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10547. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10548. //
  10549. // var treatCostTotal float64 = 0 //治疗费用
  10550. // var treatCostSelfTotal float64 = 0 //治疗费用
  10551. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10552. //
  10553. // var zhenChaCostTotal float64 = 0 //其他费用
  10554. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10555. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10556. //
  10557. // decimal.DivisionPrecision = 2
  10558. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10559. //
  10560. // var balanceAccountsType int64
  10561. // if his.ID > 0 {
  10562. // balanceAccountsType = his.BalanceAccountsType
  10563. // } else {
  10564. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10565. // }
  10566. // if balanceAccountsType == 2 {
  10567. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10568. // for _, item := range orderInfos_two {
  10569. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10570. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10571. // item.MedChrgitmType = "09"
  10572. // }
  10573. //
  10574. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10575. // if item.HisPrescriptionProject.Type == 2 {
  10576. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10577. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10578. // case 0:
  10579. // item.MedChrgitmType = "0"
  10580. // break
  10581. // case 1:
  10582. // item.MedChrgitmType = "14"
  10583. // break
  10584. // case 2:
  10585. // item.MedChrgitmType = "05"
  10586. //
  10587. // break
  10588. // case 3:
  10589. // item.MedChrgitmType = "03"
  10590. //
  10591. // break
  10592. // case 4:
  10593. // item.MedChrgitmType = "03"
  10594. //
  10595. // break
  10596. // case 5:
  10597. // item.MedChrgitmType = "08"
  10598. //
  10599. // break
  10600. // case 6:
  10601. // item.MedChrgitmType = "14"
  10602. //
  10603. // break
  10604. // case 7:
  10605. // item.MedChrgitmType = "14"
  10606. //
  10607. // break
  10608. // case 8:
  10609. // item.MedChrgitmType = "03"
  10610. // break
  10611. // case 9:
  10612. // item.MedChrgitmType = "14"
  10613. // break
  10614. // case 10:
  10615. // item.MedChrgitmType = "14"
  10616. // break
  10617. // case 11:
  10618. // item.MedChrgitmType = "06"
  10619. // break
  10620. // case 12:
  10621. // item.MedChrgitmType = "12"
  10622. // break
  10623. // case 13:
  10624. // item.MedChrgitmType = "01"
  10625. // break
  10626. // case 14:
  10627. // item.MedChrgitmType = "04"
  10628. // break
  10629. // case 15:
  10630. // item.MedChrgitmType = "02"
  10631. // break
  10632. //
  10633. // }
  10634. //
  10635. // } else {
  10636. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10637. //
  10638. // case 1:
  10639. // item.MedChrgitmType = "14"
  10640. // break
  10641. // case 2:
  10642. // item.MedChrgitmType = "05"
  10643. //
  10644. // break
  10645. // case 3:
  10646. // item.MedChrgitmType = "03"
  10647. //
  10648. // break
  10649. // case 4:
  10650. // item.MedChrgitmType = "03"
  10651. //
  10652. // break
  10653. // case 5:
  10654. // item.MedChrgitmType = "08"
  10655. //
  10656. // break
  10657. // case 6:
  10658. // item.MedChrgitmType = "14"
  10659. //
  10660. // break
  10661. // case 7:
  10662. // item.MedChrgitmType = "14"
  10663. //
  10664. // break
  10665. // case 8:
  10666. // item.MedChrgitmType = "03"
  10667. // break
  10668. // case 9:
  10669. // item.MedChrgitmType = "14"
  10670. // break
  10671. //
  10672. // }
  10673. //
  10674. // }
  10675. //
  10676. // } else if item.HisPrescriptionProject.Type == 3 {
  10677. // item.MedChrgitmType = "08"
  10678. // }
  10679. // }
  10680. // }
  10681. //
  10682. // for _, item := range orderInfos_two {
  10683. // fmt.Println(item.MedChrgitmType)
  10684. // if item.MedChrgitmType == "01" { //床位费
  10685. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10686. // bedCostSelfTotal = bedCostTotal
  10687. // }
  10688. //
  10689. // if item.MedChrgitmType == "02" { //诊察费
  10690. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10691. // zhenChaCostSelfTotal = zhenChaCostTotal
  10692. // }
  10693. //
  10694. // if item.MedChrgitmType == "03" { //检查费
  10695. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10696. // checkCostSelfTotal = checkCostTotal
  10697. // }
  10698. //
  10699. // if item.MedChrgitmType == "04" { //化验费
  10700. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10701. // laboratoryCostSelfTotal = laboratoryCostTotal
  10702. // }
  10703. //
  10704. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10705. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10706. // treatCostSelfTotal = treatCostTotal
  10707. // }
  10708. //
  10709. // if item.MedChrgitmType == "06" { //手术费
  10710. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10711. // operationCostSelfTotal = treatCostTotal
  10712. // }
  10713. //
  10714. // if item.MedChrgitmType == "08" { //材料费
  10715. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10716. // materialCostSelfTotal = materialCostTotal
  10717. // }
  10718. //
  10719. // if item.MedChrgitmType == "09" { //西药费
  10720. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10721. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10722. // }
  10723. //
  10724. // if item.MedChrgitmType == "11" { //中成费
  10725. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10726. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10727. // }
  10728. //
  10729. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10730. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10731. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10732. // otherCostSelfTotal = otherCostTotal
  10733. // }
  10734. // } else {
  10735. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10736. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10737. // otherCostSelfTotal = otherCostTotal
  10738. // }
  10739. //
  10740. // }
  10741. //
  10742. // }
  10743. //
  10744. // } else {
  10745. // for _, item := range orderInfos {
  10746. // if item.MedChrgitmType == "01" { //床位费
  10747. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10748. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10749. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10750. // }
  10751. //
  10752. // if item.MedChrgitmType == "02" { //诊察费
  10753. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10754. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10755. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10756. // }
  10757. //
  10758. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10759. // if item.MedChrgitmType == "03" { //检查费
  10760. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10761. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10762. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10763. //
  10764. // }
  10765. // } else {
  10766. // if item.MedChrgitmType == "03" { //检查费
  10767. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10768. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10769. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10770. // }
  10771. //
  10772. // }
  10773. //
  10774. // if item.MedChrgitmType == "04" { //化验费
  10775. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. //
  10779. // }
  10780. //
  10781. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10782. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10783. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10784. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10785. //
  10786. // }
  10787. //
  10788. // if item.MedChrgitmType == "06" { //手术费
  10789. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. // }
  10793. //
  10794. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10795. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10796. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10797. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10798. // }
  10799. //
  10800. // if item.MedChrgitmType == "09" { //西药费
  10801. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10802. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10803. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10804. // }
  10805. //
  10806. // if item.MedChrgitmType == "11" { //中成费
  10807. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10808. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10809. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10810. // }
  10811. //
  10812. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10813. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10814. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10815. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10816. // }
  10817. //
  10818. // }
  10819. // }
  10820. // timeLayout := "2006-01-02"
  10821. // loc, _ := time.LoadLocation("Local")
  10822. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10823. // if err != nil {
  10824. // }
  10825. // startRecordDateTime := startTime.Unix()
  10826. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10827. // if err != nil {
  10828. // }
  10829. // endRecordDateTime := endTime.Unix()
  10830. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10831. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10832. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10833. //
  10834. // c.ServeSuccessJSON(map[string]interface{}{
  10835. // "order_number": order.Number, //业务流水号
  10836. // "id_card_no": his.IdCardNo, //社会保障号
  10837. // "department_name": department.Name, //科室
  10838. // "number": his.Number, //门诊号
  10839. // "date": order.SettleAccountsDate, //结算日期
  10840. // "name": order.PsnName, //姓名
  10841. // "gender": patient.Gender, //性别
  10842. // "psn_cash_money": order.PsnCashPay, //个人支付
  10843. // "pay_way": "门诊", //结算方式
  10844. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10845. // "admin_user_name": admin.UserName, //收款员
  10846. // "order": order,
  10847. // "order_info": orderInfos_two,
  10848. // "his": his,
  10849. // "bedCostTotal": bedCostTotal,
  10850. // "bedCostSelfTotal": bedCostSelfTotal,
  10851. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10852. // "operationCostTotal": operationCostTotal,
  10853. // "operationCostSelfTotal": operationCostSelfTotal,
  10854. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10855. // "otherCostTotal": otherCostTotal,
  10856. // "otherCostSelfTotal": otherCostSelfTotal,
  10857. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10858. // "materialCostTotal": materialCostTotal,
  10859. // "materialCostSelfTotal": materialCostSelfTotal,
  10860. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10861. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10862. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10863. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10864. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10865. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10866. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10867. // "checkCostTotal": checkCostTotal,
  10868. // "checkCostSelfTotal": checkCostSelfTotal,
  10869. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10870. // "laboratoryCostTotal": laboratoryCostTotal,
  10871. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10872. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10873. // "treatCostTotal": treatCostTotal,
  10874. // "treatCostSelfTotal": treatCostSelfTotal,
  10875. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10876. // "zhenChaCostTotal": zhenChaCostTotal,
  10877. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10878. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10879. // "his_hospital_record": his_hospital_record,
  10880. // "pre_pay_money": pre_pay_money,
  10881. // "refund_sum": sum,
  10882. // })
  10883. //
  10884. //}
  10885. func (this *HisApiController) GetIncomeStatisticsData() {
  10886. start_time := this.GetString("start_time")
  10887. end_time := this.GetString("end_time")
  10888. key_words := this.GetString("key_words")
  10889. limit, _ := this.GetInt64("limit")
  10890. page, _ := this.GetInt64("page")
  10891. if page <= 0 {
  10892. page = 1
  10893. }
  10894. if limit <= 0 {
  10895. limit = 10
  10896. }
  10897. statistics_type, _ := this.GetInt64("statistics_type")
  10898. admin := this.GetAdminUserInfo()
  10899. timeLayout := "2006-01-02"
  10900. loc, _ := time.LoadLocation("Local")
  10901. var theStartTIme int64
  10902. if len(start_time) > 0 {
  10903. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10904. if err != nil {
  10905. theStartTIme = 0
  10906. }
  10907. theStartTIme = theTime.Unix()
  10908. }
  10909. var theEndtTIme int64
  10910. if len(end_time) > 0 {
  10911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10912. if err != nil {
  10913. theEndtTIme = 0
  10914. }
  10915. theEndtTIme = theTime.Unix()
  10916. }
  10917. if statistics_type == 1 {
  10918. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10919. this.ServeSuccessJSON(map[string]interface{}{
  10920. "list": list,
  10921. "total": total,
  10922. })
  10923. } else {
  10924. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10925. this.ServeSuccessJSON(map[string]interface{}{
  10926. "list": list,
  10927. "total": total,
  10928. })
  10929. }
  10930. }
  10931. func (c *HisApiController) PostProjectInformation() {
  10932. adminUser := c.GetAdminUserInfo()
  10933. orgId := adminUser.CurrentOrgId
  10934. dataBody := make(map[string]interface{}, 0)
  10935. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10936. if err != nil {
  10937. utils.ErrorLog(err.Error())
  10938. return
  10939. }
  10940. utils.ErrorLog("%v", dataBody)
  10941. var projectList []*models.HisProject
  10942. var total_goods []interface{}
  10943. tempProjects := dataBody["projects"].([]interface{})
  10944. total_goods = tempProjects
  10945. for index, projectMap := range tempProjects {
  10946. projectM := projectMap.(map[string]interface{})
  10947. var project models.HisProject
  10948. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10949. utils.ErrorLog("project_name")
  10950. return
  10951. }
  10952. project_name, _ := projectM["project_name"].(string)
  10953. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10954. err_log := models.ExportErrLog{
  10955. LogType: 6,
  10956. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10957. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10958. Status: 1,
  10959. CreateTime: time.Now().Unix(),
  10960. UpdateTime: time.Now().Unix(),
  10961. ExportTime: time.Now().Unix(),
  10962. }
  10963. service.CreateExportErrLog(&err_log)
  10964. continue
  10965. }
  10966. project.ProjectName = project_name
  10967. prices := projectM["price"].(string)
  10968. price, _ := strconv.ParseFloat(prices, 64)
  10969. if price <= 0 { //名字为空则生成一条导入错误日志
  10970. err_log := models.ExportErrLog{
  10971. LogType: 6,
  10972. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10973. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10974. Status: 1,
  10975. CreateTime: time.Now().Unix(),
  10976. UpdateTime: time.Now().Unix(),
  10977. ExportTime: time.Now().Unix(),
  10978. }
  10979. service.CreateExportErrLog(&err_log)
  10980. continue
  10981. }
  10982. project.Price = price
  10983. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10984. utils.ErrorLog("unit_id")
  10985. return
  10986. }
  10987. unit := projectM["unit"].(string)
  10988. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10989. err_log := models.ExportErrLog{
  10990. LogType: 6,
  10991. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10992. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10993. Status: 1,
  10994. CreateTime: time.Now().Unix(),
  10995. UpdateTime: time.Now().Unix(),
  10996. ExportTime: time.Now().Unix(),
  10997. }
  10998. service.CreateExportErrLog(&err_log)
  10999. continue
  11000. }
  11001. project.Unit = unit
  11002. cost_classify := projectM["cost_classify"].(string)
  11003. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11004. err_log := models.ExportErrLog{
  11005. LogType: 6,
  11006. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11007. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11008. Status: 1,
  11009. CreateTime: time.Now().Unix(),
  11010. UpdateTime: time.Now().Unix(),
  11011. ExportTime: time.Now().Unix(),
  11012. }
  11013. service.CreateExportErrLog(&err_log)
  11014. continue
  11015. }
  11016. var costClassify = "费用类别"
  11017. var cost_classify_id int64
  11018. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11019. if len(cost_classify) != 0 {
  11020. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11021. if errcode == gorm.ErrRecordNotFound {
  11022. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11023. dataconfig := models.DictDataconfig{
  11024. ParentId: costClassifyConfig.ID,
  11025. Module: "system",
  11026. OrgId: orgId,
  11027. Name: cost_classify,
  11028. FieldName: "",
  11029. Value: costConfig.Value + 1,
  11030. CreatedTime: "",
  11031. UpdatedTime: "",
  11032. CreateUserId: adminUser.AdminUser.Id,
  11033. Status: 1,
  11034. Remark: "",
  11035. DeleteIdSystem: 0,
  11036. Title: "",
  11037. Content: "",
  11038. Order: 0,
  11039. Code: "",
  11040. }
  11041. service.CreatedDicConfig(&dataconfig)
  11042. }
  11043. }
  11044. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11045. for _, it := range costClassList {
  11046. if cost_classify == it.Name {
  11047. cost_classify_id = int64(it.Value)
  11048. }
  11049. }
  11050. project.CostClassify = cost_classify_id
  11051. executive_section := projectM["executive_section"].(string)
  11052. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11053. err_log := models.ExportErrLog{
  11054. LogType: 6,
  11055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11056. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11057. Status: 1,
  11058. CreateTime: time.Now().Unix(),
  11059. UpdateTime: time.Now().Unix(),
  11060. ExportTime: time.Now().Unix(),
  11061. }
  11062. service.CreateExportErrLog(&err_log)
  11063. continue
  11064. }
  11065. if len(executive_section) != 0 {
  11066. //查找科室是否有内容
  11067. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11068. if errcodedepart == gorm.ErrRecordNotFound {
  11069. department := models.XtHisDepartment{
  11070. Name: executive_section,
  11071. Status: 1,
  11072. UserOrgId: adminUser.CurrentOrgId,
  11073. CreatedTime: time.Now().Unix(),
  11074. }
  11075. service.CreateDePartment(&department)
  11076. }
  11077. }
  11078. var executive_section_id int64
  11079. departMentList, _ := service.GetAllDepartMent(orgId)
  11080. for _, it := range departMentList {
  11081. if executive_section == it.Name {
  11082. executive_section_id = it.ID
  11083. }
  11084. }
  11085. project.ExecutiveSection = executive_section_id
  11086. medical_coverage := projectM["medical_coverage"].(string)
  11087. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11088. err_log := models.ExportErrLog{
  11089. LogType: 6,
  11090. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11091. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11092. Status: 1,
  11093. CreateTime: time.Now().Unix(),
  11094. UpdateTime: time.Now().Unix(),
  11095. ExportTime: time.Now().Unix(),
  11096. }
  11097. service.CreateExportErrLog(&err_log)
  11098. continue
  11099. }
  11100. var medicalCoverage = "医保等级"
  11101. var medical_coverage_id int64
  11102. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11103. if len(medical_coverage) != 0 {
  11104. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11105. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11106. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11107. dataconfig := models.DictDataconfig{
  11108. ParentId: medicalCoverageConfig.ID,
  11109. Module: "system",
  11110. OrgId: orgId,
  11111. Name: medical_coverage,
  11112. FieldName: "",
  11113. Value: medicalCoverageConfig.Value + 1,
  11114. CreatedTime: "",
  11115. UpdatedTime: "",
  11116. CreateUserId: adminUser.AdminUser.Id,
  11117. Status: 1,
  11118. Remark: "",
  11119. DeleteIdSystem: 0,
  11120. Title: "",
  11121. Content: "",
  11122. Order: 0,
  11123. Code: "",
  11124. }
  11125. service.CreatedDicConfig(&dataconfig)
  11126. }
  11127. }
  11128. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11129. for _, it := range medicalCoverageList {
  11130. if medical_coverage == it.Name {
  11131. medical_coverage_id = int64(it.Value)
  11132. }
  11133. }
  11134. project.MedicalCoverage = medical_coverage_id
  11135. pinyin := projectM["pinyin"].(string)
  11136. project.Pinyin = pinyin
  11137. wubi := projectM["wubi"].(string)
  11138. project.Wubi = wubi
  11139. statistical_classification := projectM["statistical_classification"].(string)
  11140. var statisticalClassification = "统计分类"
  11141. var statistical_classification_id int64
  11142. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11143. if len(statistical_classification) != 0 {
  11144. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11145. if classificationerrcodes == gorm.ErrRecordNotFound {
  11146. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11147. dataconfig := models.DictDataconfig{
  11148. ParentId: classiFication.ID,
  11149. Module: "system",
  11150. OrgId: orgId,
  11151. Name: statistical_classification,
  11152. FieldName: "",
  11153. Value: classiFicationConfig.Value + 1,
  11154. CreatedTime: "",
  11155. UpdatedTime: "",
  11156. CreateUserId: adminUser.AdminUser.Id,
  11157. Status: 1,
  11158. Remark: "",
  11159. DeleteIdSystem: 0,
  11160. Title: "",
  11161. Content: "",
  11162. Order: 0,
  11163. Code: "",
  11164. }
  11165. service.CreatedDicConfig(&dataconfig)
  11166. }
  11167. }
  11168. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11169. for _, it := range classiFicationList {
  11170. if statistical_classification == it.Name {
  11171. statistical_classification_id = int64(it.Value)
  11172. }
  11173. }
  11174. project.StatisticalClassification = statistical_classification_id
  11175. disease_directory := int64(projectM["disease_directory"].(float64))
  11176. project.DiseaseDirectory = disease_directory
  11177. is_record := int64(projectM["is_record"].(float64))
  11178. project.IsRecord = is_record
  11179. medical_code := projectM["medical_code"].(string)
  11180. project.MedicalCode = medical_code
  11181. tube_color := projectM["tube_color"].(string)
  11182. var tubeColor = "试管颜色"
  11183. var tube_color_id int64
  11184. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11185. if len(tube_color) != 0 {
  11186. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11187. if errcodetube == gorm.ErrRecordNotFound {
  11188. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11189. dataconfig := models.DictDataconfig{
  11190. ParentId: tubeColorConfig.ID,
  11191. Module: "system",
  11192. OrgId: orgId,
  11193. Name: tube_color,
  11194. FieldName: "",
  11195. Value: tubeConfig.Value + 1,
  11196. CreatedTime: "",
  11197. UpdatedTime: "",
  11198. CreateUserId: adminUser.AdminUser.Id,
  11199. Status: 1,
  11200. Remark: "",
  11201. DeleteIdSystem: 0,
  11202. Title: "",
  11203. Content: "",
  11204. Order: 0,
  11205. Code: "",
  11206. }
  11207. service.CreatedDicConfig(&dataconfig)
  11208. }
  11209. }
  11210. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11211. for _, it := range tubeColorList {
  11212. if tube_color == it.Name {
  11213. tube_color_id = int64(it.Value)
  11214. }
  11215. }
  11216. project.TubeColor = tube_color_id
  11217. single_dose := projectM["single_dose"].(string)
  11218. project.SingleDose = single_dose
  11219. execution_frequency := projectM["execution_frequency"].(string)
  11220. project.ExecutionFrequency = execution_frequency
  11221. delivery_way := projectM["delivery_way"].(string)
  11222. project.DeliveryWay = delivery_way
  11223. number_days := projectM["number_days"].(string)
  11224. project.NumberDays = number_days
  11225. total := projectM["total"].(string)
  11226. project.Total = total
  11227. medical_status := int64(projectM["medical_status"].(float64))
  11228. project.MedicalStatus = medical_status
  11229. category := int64(projectM["category"].(float64))
  11230. project.Category = category
  11231. specail_project := int64(projectM["specail_project"].(float64))
  11232. project.SpecailProject = specail_project
  11233. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11234. project.SocialSecurityDirectoryCode = social_security_directory_code
  11235. remark := projectM["remark"].(string)
  11236. project.Remark = remark
  11237. record_date := projectM["record_date"].(string)
  11238. timeLayout := "2006-01-02"
  11239. loc, _ := time.LoadLocation("Local")
  11240. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11241. project.RecordDate = theTime.Unix()
  11242. projectList = append(projectList, &project)
  11243. }
  11244. export_time := time.Now().Unix()
  11245. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11246. if len(projectList) > 0 {
  11247. for _, item := range projectList {
  11248. hans := item.ProjectName // 要转换的汉字字符串
  11249. // 创建一个拼音转换器
  11250. p := pinyin.NewArgs()
  11251. // 将汉字转为拼音
  11252. pinyinSlice := pinyin.Pinyin(hans, p)
  11253. // 输出拼音
  11254. fmt.Println("Pinyin:", pinyinSlice)
  11255. // 获取首字母
  11256. firstLetter := ""
  11257. for _, py := range pinyinSlice {
  11258. if len(py) > 0 {
  11259. firstLetter += string(py[0][0])
  11260. }
  11261. }
  11262. item.FirstLetter = firstLetter
  11263. project := models.HisProject{
  11264. ProjectName: item.ProjectName,
  11265. Price: item.Price,
  11266. Unit: item.Unit,
  11267. CostClassify: item.CostClassify,
  11268. ExecutiveSection: item.ExecutiveSection,
  11269. MedicalCoverage: item.MedicalCoverage,
  11270. UserOrgId: orgId,
  11271. Status: 1,
  11272. CreatedTime: time.Now().Unix(),
  11273. Pinyin: item.Pinyin,
  11274. Wubi: item.Wubi,
  11275. StatisticalClassification: item.StatisticalClassification,
  11276. DiseaseDirectory: item.DiseaseDirectory,
  11277. IsRecord: item.IsRecord,
  11278. MedicalCode: item.MedicalCode,
  11279. TubeColor: item.TubeColor,
  11280. SingleDose: item.SingleDose,
  11281. DeliveryWay: item.DeliveryWay,
  11282. NumberDays: item.NumberDays,
  11283. Total: item.Total,
  11284. Category: item.Category,
  11285. MedicalStatus: item.MedicalStatus,
  11286. SpecailProject: item.SpecailProject,
  11287. RecordDate: item.RecordDate,
  11288. Remark: item.Remark,
  11289. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11290. ExecutionFrequency: item.ExecutionFrequency,
  11291. FirstLetter: item.FirstLetter,
  11292. }
  11293. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11294. if errcodeproject == gorm.ErrRecordNotFound {
  11295. service.CreateProjectInfomation(&project)
  11296. } else if errcodeproject == nil {
  11297. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11298. }
  11299. log := models.ExportLog{
  11300. LogType: 6,
  11301. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11302. TotalNum: int64(len(total_goods)),
  11303. FailNum: int64(len(errLogs)),
  11304. SuccessNum: int64(len(projectList)),
  11305. CreateTime: time.Now().Unix(),
  11306. UpdateTime: time.Now().Unix(),
  11307. ExportTime: export_time,
  11308. Status: 1,
  11309. }
  11310. service.CreateExportLog(&log)
  11311. c.ServeSuccessJSON(map[string]interface{}{
  11312. "msg": "导入成功",
  11313. "total_num": len(total_goods),
  11314. "success_num": len(projectList),
  11315. "fail_num": int64(len(errLogs)),
  11316. })
  11317. }
  11318. } else {
  11319. log := models.ExportLog{
  11320. LogType: 6,
  11321. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11322. TotalNum: int64(len(total_goods)),
  11323. FailNum: int64(len(errLogs)),
  11324. SuccessNum: int64(len(projectList)),
  11325. CreateTime: time.Now().Unix(),
  11326. UpdateTime: time.Now().Unix(),
  11327. ExportTime: export_time,
  11328. Status: 1,
  11329. }
  11330. service.CreateExportLog(&log)
  11331. c.ServeSuccessJSON(map[string]interface{}{
  11332. "msg": "导入成功",
  11333. "total_num": len(total_goods),
  11334. "success_num": len(projectList),
  11335. "fail_num": int64(len(errLogs)),
  11336. })
  11337. }
  11338. }
  11339. //func (this *HisApiController) EditProjectInformation(){
  11340. //
  11341. // id, _ := this.GetInt64("id")
  11342. // project_team := this.GetString("project_team")
  11343. // price := this.GetString("price")
  11344. // price_float, _ := strconv.ParseFloat(price, 64)
  11345. // pinyin := this.GetString("pinyin")
  11346. // wubi := this.GetString("wubi")
  11347. // tube_color, _ := this.GetInt64("tube_color")
  11348. // team_type, _ := this.GetInt64("team_type")
  11349. // remark := this.GetString("remark")
  11350. // ids := this.GetString("ids")
  11351. // item_id := this.GetString("item_id")
  11352. // projectTeam := models.XtHisProjectTeam{
  11353. // ProjectTeam: project_team,
  11354. // Price: price_float,
  11355. // Pinyin: pinyin,
  11356. // Wubi: wubi,
  11357. // TubeColor: tube_color,
  11358. // TeamType: team_type,
  11359. // Remark: remark,
  11360. // ProjectId: ids,
  11361. // ItemId: item_id,
  11362. // }
  11363. //
  11364. //
  11365. // dataBody := make(map[string]interface{}, 0)
  11366. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11367. // if err != nil {
  11368. // utils.ErrorLog(err.Error())
  11369. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11370. // return
  11371. // }
  11372. //
  11373. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11374. //
  11375. //
  11376. // if err != nil {
  11377. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11378. // return
  11379. // }
  11380. //
  11381. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11382. // infos, _ := dataBody["info"].([]interface{})
  11383. // if len(infos) > 0 {
  11384. // var ids []string
  11385. //
  11386. // for _, item := range infos {
  11387. // items := item.(map[string]interface{})
  11388. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11389. // utils.ErrorLog("id")
  11390. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11391. // return
  11392. // }
  11393. // id := int64(items["id"].(float64))
  11394. //
  11395. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11396. // utils.ErrorLog("type")
  11397. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11398. // return
  11399. // }
  11400. // types := int64(items["type"].(float64))
  11401. //
  11402. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11403. // utils.ErrorLog("number")
  11404. // }
  11405. //
  11406. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11407. //
  11408. // projectList := models.XtHisProjectList{
  11409. // Number: number,
  11410. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11411. // ProjectId: id,
  11412. // Status: 1,
  11413. // CreatedTime: time.Now().Unix(),
  11414. // UpdatedTime: time.Now().Unix(),
  11415. // TeamId: projectTeam.ID,
  11416. // Type: types,
  11417. // }
  11418. // list := projectList
  11419. //
  11420. // service.CreateProjectList(&list)
  11421. //
  11422. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11423. //
  11424. // }
  11425. // ids_str := strings.Join(ids, ",")
  11426. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11427. // service.SaveProjectTeam(&projectTeam)
  11428. // this.ServeSuccessJSON(map[string]interface{}{
  11429. // "projectTeam": projectTeam,
  11430. // })
  11431. // }
  11432. // }
  11433. //}
  11434. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11435. name := c.GetString("name")
  11436. mode_id, _ := c.GetInt64("mode", 0)
  11437. types, _ := c.GetInt64("type", 0)
  11438. patient_id, _ := c.GetInt64("patient_id", 0)
  11439. types = 1
  11440. adminInfo := c.GetAdminUserInfo()
  11441. template := &models.HisPrescriptionTemplate{
  11442. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11443. PatientId: patient_id,
  11444. Type: types,
  11445. Status: 1,
  11446. Ctime: time.Now().Unix(),
  11447. Mtime: time.Now().Unix(),
  11448. Name: name,
  11449. Mode: mode_id,
  11450. }
  11451. dataBody := make(map[string]interface{}, 0)
  11452. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11453. if err != nil {
  11454. utils.ErrorLog(err.Error())
  11455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11456. return
  11457. }
  11458. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11459. //如果已经存在记录则删除处方
  11460. if template_one.ID > 0 {
  11461. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11462. var ids []int64
  11463. var org_id int64
  11464. for _, item := range ps {
  11465. org_id = c.GetAdminUserInfo().CurrentOrgId
  11466. ids = append(ids, item.ID)
  11467. }
  11468. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11469. if err2 == nil {
  11470. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11471. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11472. if len(prescriptions) > 0 {
  11473. for _, item := range prescriptions {
  11474. items := item.(map[string]interface{})
  11475. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11476. utils.ErrorLog("type")
  11477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11478. return
  11479. }
  11480. types := int64(items["type"].(float64))
  11481. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11482. utils.ErrorLog("med_type")
  11483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11484. return
  11485. }
  11486. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11487. ctime := time.Now().Unix()
  11488. prescription := &models.HisPrescriptionInfoTemplate{
  11489. PatientId: patient_id,
  11490. UserOrgId: adminInfo.CurrentOrgId,
  11491. Ctime: ctime,
  11492. Mtime: ctime,
  11493. Type: types,
  11494. Modifier: adminInfo.AdminUser.Id,
  11495. Creator: adminInfo.AdminUser.Id,
  11496. Status: 1,
  11497. PTemplateId: template_one.ID,
  11498. MedType: med_type,
  11499. }
  11500. service.CreateHisPrescriptionInfoTemplate(prescription)
  11501. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11502. advices := items["advices"].([]interface{})
  11503. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11504. ctime := time.Now().Unix()
  11505. mtime := ctime
  11506. if len(advices) > 0 {
  11507. for _, advice := range advices {
  11508. var s models.HisPrescriptionAdviceTemplate
  11509. s.PrescriptionId = prescription.ID
  11510. s.AdviceType = 2
  11511. s.StopState = 2
  11512. s.ExecutionState = 2
  11513. s.Status = 1
  11514. s.UserOrgId = adminInfo.CurrentOrgId
  11515. s.CreatedTime = ctime
  11516. s.UpdatedTime = mtime
  11517. s.PatientId = patient_id
  11518. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11519. if errcode > 0 {
  11520. c.ServeFailJSONWithSGJErrorCode(errcode)
  11521. return
  11522. }
  11523. service.CreateHisPrescriptionAdviceTemplate(&s)
  11524. }
  11525. }
  11526. }
  11527. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11528. projects := items["project"].([]interface{})
  11529. if len(projects) > 0 {
  11530. for _, project := range projects {
  11531. var p models.HisPrescriptionProjectTemplate
  11532. p.PrescriptionId = prescription.ID
  11533. p.Ctime = time.Now().Unix()
  11534. p.Mtime = time.Now().Unix()
  11535. p.PatientId = patient_id
  11536. p.UserOrgId = adminInfo.CurrentOrgId
  11537. p.Status = 1
  11538. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11539. if errcode > 0 {
  11540. c.ServeFailJSONWithSGJErrorCode(errcode)
  11541. return
  11542. }
  11543. service.CreateHisPrescriptionProjectTemplate(&p)
  11544. }
  11545. }
  11546. }
  11547. }
  11548. c.ServeSuccessJSON(map[string]interface{}{
  11549. "msg": "创建成功",
  11550. })
  11551. }
  11552. }
  11553. } else {
  11554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11555. return
  11556. }
  11557. } else {
  11558. err3 := service.CreateHisPrescriptionTemplate(template)
  11559. if err3 == nil {
  11560. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11561. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11562. if len(prescriptions) > 0 {
  11563. for _, item := range prescriptions {
  11564. items := item.(map[string]interface{})
  11565. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11566. utils.ErrorLog("type")
  11567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11568. return
  11569. }
  11570. types := int64(items["type"].(float64))
  11571. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11572. utils.ErrorLog("med_type")
  11573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11574. return
  11575. }
  11576. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11577. ctime := time.Now().Unix()
  11578. prescription := &models.HisPrescriptionInfoTemplate{
  11579. PatientId: patient_id,
  11580. UserOrgId: adminInfo.CurrentOrgId,
  11581. Ctime: ctime,
  11582. Mtime: ctime,
  11583. Type: types,
  11584. Modifier: adminInfo.AdminUser.Id,
  11585. Creator: adminInfo.AdminUser.Id,
  11586. Status: 1,
  11587. PTemplateId: template.ID,
  11588. MedType: med_type,
  11589. }
  11590. service.CreateHisPrescriptionInfoTemplate(prescription)
  11591. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11592. advices := items["advices"].([]interface{})
  11593. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11594. ctime := time.Now().Unix()
  11595. mtime := ctime
  11596. if len(advices) > 0 {
  11597. for _, advice := range advices {
  11598. var s models.HisPrescriptionAdviceTemplate
  11599. s.PrescriptionId = prescription.ID
  11600. s.AdviceType = 2
  11601. s.StopState = 2
  11602. s.ExecutionState = 2
  11603. s.Status = 1
  11604. s.UserOrgId = adminInfo.CurrentOrgId
  11605. s.CreatedTime = ctime
  11606. s.UpdatedTime = mtime
  11607. s.PatientId = patient_id
  11608. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11609. if errcode > 0 {
  11610. c.ServeFailJSONWithSGJErrorCode(errcode)
  11611. return
  11612. }
  11613. service.CreateHisPrescriptionAdviceTemplate(&s)
  11614. }
  11615. }
  11616. }
  11617. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11618. projects := items["project"].([]interface{})
  11619. if len(projects) > 0 {
  11620. for _, project := range projects {
  11621. var p models.HisPrescriptionProjectTemplate
  11622. p.PrescriptionId = prescription.ID
  11623. p.Ctime = time.Now().Unix()
  11624. p.Mtime = time.Now().Unix()
  11625. p.PatientId = patient_id
  11626. p.UserOrgId = adminInfo.CurrentOrgId
  11627. p.Status = 1
  11628. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11629. if errcode > 0 {
  11630. c.ServeFailJSONWithSGJErrorCode(errcode)
  11631. return
  11632. }
  11633. service.CreateHisPrescriptionProjectTemplate(&p)
  11634. }
  11635. }
  11636. }
  11637. }
  11638. c.ServeSuccessJSON(map[string]interface{}{
  11639. "msg": "创建成功",
  11640. })
  11641. }
  11642. }
  11643. } else {
  11644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11645. return
  11646. }
  11647. }
  11648. }
  11649. func (c *HisApiController) PreSettle() {
  11650. id, _ := c.GetInt64("id")
  11651. record_time := c.GetString("record_time")
  11652. his_patient_id, _ := c.GetInt64("his_patient_id")
  11653. timeLayout := "2006-01-02"
  11654. loc, _ := time.LoadLocation("Local")
  11655. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11656. diagnosis_id := c.GetString("diagnosis")
  11657. sick_type, _ := c.GetInt64("sick_type")
  11658. reg_type, _ := c.GetInt64("p_type")
  11659. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11661. if err != nil {
  11662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11663. return
  11664. }
  11665. recordDateTime := theTime.Unix()
  11666. adminUser := c.GetAdminUserInfo()
  11667. var prescriptions []*models.HisPrescription
  11668. var start_time int64
  11669. var end_time int64
  11670. ids_str := c.GetString("ids")
  11671. ids_arr := strings.Split(ids_str, ",")
  11672. fmt.Println(reg_type)
  11673. if settle_accounts_type == 1 { //日结
  11674. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11675. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11676. } else {
  11677. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11678. }
  11679. fmt.Println(prescriptions)
  11680. } else { //月结
  11681. start_time_str := c.GetString("start_time")
  11682. end_time_str := c.GetString("end_time")
  11683. timeLayout := "2006-01-02"
  11684. loc, _ := time.LoadLocation("Local")
  11685. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11686. if err != nil {
  11687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11688. return
  11689. }
  11690. recordStartTime := theStartTime.Unix()
  11691. start_time = recordStartTime
  11692. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11693. if err != nil {
  11694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11695. return
  11696. }
  11697. recordEndTime := theEndTime.Unix()
  11698. end_time = recordEndTime
  11699. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11700. }
  11701. if reg_type == 1111 || reg_type == 1112 {
  11702. reg_type = 11
  11703. }
  11704. timestamp := time.Now().Unix()
  11705. tempTime := time.Unix(timestamp, 0)
  11706. timeFormat := tempTime.Format("20060102150405")
  11707. chrgBchno := rand.Intn(100000) + 10000
  11708. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11709. strconv.FormatInt(his.PatientId, 10)
  11710. var ids []int64
  11711. for _, item := range prescriptions {
  11712. ids = append(ids, item.ID)
  11713. }
  11714. fmt.Println(ids)
  11715. var total float64
  11716. for _, item := range prescriptions {
  11717. fmt.Println(item)
  11718. if item.Type == 1 { //药品
  11719. for _, subItem := range item.HisDoctorAdviceInfo {
  11720. total = total + (subItem.Price * subItem.PrescribingNumber)
  11721. }
  11722. }
  11723. if item.Type == 2 { //项目
  11724. for _, subItem := range item.HisPrescriptionProject {
  11725. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11726. total = total + (subItem.Price * cnt)
  11727. }
  11728. }
  11729. for _, subItem := range item.HisAdditionalCharge {
  11730. total = total + (subItem.Price * float64(subItem.Count))
  11731. }
  11732. }
  11733. allTotal := fmt.Sprintf("%.2f", total)
  11734. totals, _ := strconv.ParseFloat(allTotal, 64)
  11735. order := &models.HisOrder{
  11736. UserOrgId: adminUser.CurrentOrgId,
  11737. HisPatientId: his.ID,
  11738. PatientId: id,
  11739. SettleAccountsDate: recordDateTime,
  11740. Ctime: time.Now().Unix(),
  11741. Mtime: time.Now().Unix(),
  11742. Status: 1,
  11743. OrderStatus: 1,
  11744. MdtrtId: his.Number,
  11745. Number: chrg_bchno,
  11746. MedfeeSumamt: totals,
  11747. SettleEndTime: end_time,
  11748. SettleStartTime: start_time,
  11749. SettleType: settle_accounts_type,
  11750. PsnPartAmt: totals,
  11751. PsnCashPay: totals,
  11752. PType: 2,
  11753. IsPre: 1,
  11754. MedType: strconv.Itoa(int(reg_type)),
  11755. Diagnosis: diagnosis_id,
  11756. }
  11757. err = service.CreateOrder(order)
  11758. if err != nil {
  11759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11760. return
  11761. }
  11762. var customs []*Custom
  11763. for _, item := range prescriptions {
  11764. fmt.Println(item.Type)
  11765. if item.Type == 1 { //药品
  11766. for _, subItem := range item.HisDoctorAdviceInfo {
  11767. cus := &Custom{
  11768. AdviceId: subItem.ID,
  11769. ProjectId: 0,
  11770. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11771. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11772. FeedetlSn: subItem.FeedetlSn,
  11773. Price: fmt.Sprintf("%.2f", subItem.Price),
  11774. MedListCodg: subItem.MedListCodg,
  11775. Type: 1,
  11776. }
  11777. customs = append(customs, cus)
  11778. }
  11779. }
  11780. if item.Type == 2 { //项目
  11781. for _, subItem := range item.HisPrescriptionProject {
  11782. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11783. cus := &Custom{
  11784. AdviceId: 0,
  11785. ProjectId: subItem.ID,
  11786. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11787. Cut: fmt.Sprintf("%.2f", cnt),
  11788. FeedetlSn: subItem.FeedetlSn,
  11789. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11790. MedListCodg: subItem.MedListCodg,
  11791. Type: 2,
  11792. }
  11793. customs = append(customs, cus)
  11794. }
  11795. }
  11796. for _, item := range item.HisAdditionalCharge {
  11797. cus := &Custom{
  11798. ItemId: item.ID,
  11799. AdviceId: 0,
  11800. ProjectId: 0,
  11801. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11802. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11803. FeedetlSn: item.FeedetlSn,
  11804. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11805. MedListCodg: item.XtHisAddtionConfig.Code,
  11806. Type: 3,
  11807. }
  11808. customs = append(customs, cus)
  11809. }
  11810. }
  11811. fmt.Println(customs)
  11812. for _, item := range customs {
  11813. var advice_id int64 = 0
  11814. var project_id int64 = 0
  11815. var item_id int64 = 0
  11816. var types int64 = 0
  11817. if item.Type == 1 {
  11818. advice_id = item.AdviceId
  11819. project_id = 0
  11820. item_id = 0
  11821. } else if item.Type == 2 {
  11822. advice_id = 0
  11823. item_id = 0
  11824. project_id = item.ProjectId
  11825. } else if item.Type == 3 {
  11826. advice_id = 0
  11827. item_id = item.ItemId
  11828. project_id = 0
  11829. }
  11830. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11831. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11832. pric, _ := strconv.ParseFloat(item.Price, 32)
  11833. info := &models.HisOrderInfo{
  11834. OrderNumber: order.Number,
  11835. UploadDate: time.Now().Unix(),
  11836. AdviceId: advice_id,
  11837. DetItemFeeSumamt: detItemFeeSumamt,
  11838. Cnt: cut,
  11839. Pric: pric,
  11840. PatientId: id,
  11841. Status: 1,
  11842. Mtime: time.Now().Unix(),
  11843. Ctime: time.Now().Unix(),
  11844. UserOrgId: adminUser.CurrentOrgId,
  11845. HisPatientId: his.ID,
  11846. OrderId: order.ID,
  11847. ProjectId: project_id,
  11848. Type: types,
  11849. ItemId: item_id,
  11850. }
  11851. service.CreateOrderInfo(info)
  11852. }
  11853. his.SickType = sick_type
  11854. service.UpdataHisPateint(&his)
  11855. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11856. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11857. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11858. if err == nil {
  11859. c.ServeSuccessJSON(map[string]interface{}{
  11860. "msg": "结算成功",
  11861. })
  11862. }
  11863. }
  11864. type CustomOrderInfo struct {
  11865. Name string
  11866. Spec string
  11867. Unit string
  11868. Count float64
  11869. Price float64
  11870. Total float64
  11871. }
  11872. func (c *HisApiController) GetPrivateExpensesInfo() {
  11873. order_id, _ := c.GetInt64("id", 0)
  11874. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11875. order, _ := service.GetHisOrderByID(order_id)
  11876. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11877. if order.ID == 0 {
  11878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11879. return
  11880. }
  11881. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11882. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11883. org_id := c.GetAdminUserInfo().CurrentOrgId
  11884. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11885. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11886. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11887. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11888. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11889. //var orderInfos_four []*models.HisOrderInfoTwo
  11890. //for _, item := range orderInfos_three {
  11891. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11892. // item.HisPrescriptionProject.IsCheckTeam = 1
  11893. // orderInfos_four = append(orderInfos_four, item)
  11894. //
  11895. // }
  11896. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11897. // item.HisPrescriptionProject.IsCheckTeam = 2
  11898. // orderInfos_two = append(orderInfos_two, item)
  11899. // }
  11900. //}
  11901. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11902. //var cus_slice []CustomOrderInfo
  11903. //for _, item := range new_order_info {
  11904. // var cus CustomOrderInfo
  11905. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11906. // cus.Unit = ""
  11907. // cus.Spec = ""
  11908. // var total float64
  11909. // for _, subItem := range orderInfos_four {
  11910. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11911. // total = total + subItem.DetItemFeeSumamt
  11912. // fmt.Println(subItem.DetItemFeeSumamt)
  11913. // }
  11914. // }
  11915. // cus.Count = 1
  11916. // cus.Total = total
  11917. // cus_slice = append(cus_slice, cus)
  11918. //}
  11919. orderInfos = append(orderInfos, orderInfos_two...)
  11920. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11921. //orderInfos = append(orderInfos, orderInfos_three...)
  11922. //}/**/
  11923. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11924. c.ServeSuccessJSON(map[string]interface{}{
  11925. "order": order,
  11926. "order_info": orderInfos,
  11927. "patient": patient,
  11928. "admin_info": adminInfo,
  11929. "his": his,
  11930. "current_admin": role,
  11931. "org_config": miConfig,
  11932. //"new_order_info": cus_slice,
  11933. })
  11934. }
  11935. func (this *HisApiController) ChangeMedType() {
  11936. med_type := this.GetString("med_type")
  11937. old_med_type := this.GetString("old_med_type")
  11938. ids := this.GetString("ids")
  11939. settle_type, _ := this.GetInt64("settle_type")
  11940. start_time := this.GetString("start_time")
  11941. end_time := this.GetString("end_time")
  11942. ids_arr := strings.Split(ids, ",")
  11943. if settle_type == 1 { //日结
  11944. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11945. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11946. prescription.MedType = med_type
  11947. err := service.SaveHisPrescriptionTwo(&prescription)
  11948. if err == nil {
  11949. this.ServeSuccessJSON(map[string]interface{}{
  11950. "msg": "修改成功",
  11951. })
  11952. } else {
  11953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11954. return
  11955. }
  11956. } else if settle_type == 2 {
  11957. timeLayout := "2006-01-02"
  11958. loc, _ := time.LoadLocation("Local")
  11959. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11960. if err != nil {
  11961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11962. return
  11963. }
  11964. recordStartTime := theStartTime.Unix()
  11965. start_time_timestamp := recordStartTime
  11966. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11967. if err != nil {
  11968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11969. return
  11970. }
  11971. recordEndTime := theEndTime.Unix()
  11972. end_time_timestamp := recordEndTime
  11973. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11974. if updateErr == nil {
  11975. this.ServeSuccessJSON(map[string]interface{}{
  11976. "msg": "修改成功",
  11977. })
  11978. } else {
  11979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11980. return
  11981. }
  11982. }
  11983. }
  11984. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11985. patient_id, _ := c.GetInt64("patient_id")
  11986. his_patient_id, _ := c.GetInt64("his_patient_id")
  11987. record_date := c.GetString("record_date")
  11988. start_time := c.GetString("start_time")
  11989. end_time := c.GetString("end_time")
  11990. order_status, _ := c.GetInt64("type", 0)
  11991. p_type, _ := c.GetInt64("p_type", 0)
  11992. order_id, _ := c.GetInt64("order_id", 0)
  11993. timeLayout := "2006-01-02"
  11994. loc, _ := time.LoadLocation("Local")
  11995. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11996. if err != nil {
  11997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11998. return
  11999. }
  12000. recordDateTime := theTime.Unix()
  12001. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12002. if err != nil {
  12003. }
  12004. startRecordDateTime := startTime.Unix()
  12005. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12006. if err != nil {
  12007. }
  12008. endRecordDateTime := endTime.Unix()
  12009. admin := c.GetAdminUserInfo()
  12010. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12011. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12012. order, _ := service.GetHisOrderByID(order_id)
  12013. var monthPrescriptions []*models.HisPrescription
  12014. if order_status == 1 || order_status == 0 {
  12015. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12016. } else if order_status == 2 {
  12017. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12018. }
  12019. var settle_total float64
  12020. for _, item := range monthPrescriptions {
  12021. if len(item.HisPrescriptionProject) > 0 {
  12022. for _, subItem := range item.HisPrescriptionProject {
  12023. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12024. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12025. settle_total = settle_total + total
  12026. }
  12027. }
  12028. if len(item.HisDoctorAdviceInfo) > 0 {
  12029. for _, subItem := range item.HisDoctorAdviceInfo {
  12030. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12031. settle_total = settle_total + total
  12032. }
  12033. }
  12034. }
  12035. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12036. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12037. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12038. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12039. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12040. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12041. //获取所有科室信息
  12042. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12043. var dia string
  12044. for _, item := range month_p_info {
  12045. if len(dia) == 0 {
  12046. dia = item.Diagnosis
  12047. } else {
  12048. dia = dia + "," + item.Diagnosis
  12049. }
  12050. }
  12051. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12052. dia_arr = removeEmptyStrings(dia_arr)
  12053. c.ServeSuccessJSON(map[string]interface{}{
  12054. "his_info": his_patient_info,
  12055. "xt_info": xt_patient_info,
  12056. "case_history": case_history,
  12057. "info": patientPrescriptionInfo,
  12058. "last_info": lastPatientPrescriptionInfo,
  12059. "month_prescriptions": monthPrescriptions,
  12060. "order": order,
  12061. "doctors": doctors,
  12062. "department": department,
  12063. "settle_total": settle_total,
  12064. "dia_arr": dia_arr,
  12065. })
  12066. return
  12067. }
  12068. func removeEmptyStrings(input []string) []string {
  12069. var output []string
  12070. for _, s := range input {
  12071. if s != "" {
  12072. output = append(output, s)
  12073. }
  12074. }
  12075. return output
  12076. }
  12077. func removeDuplicates(input []string) []string {
  12078. seen := make(map[string]bool)
  12079. output := []string{}
  12080. for _, s := range input {
  12081. if _, exists := seen[s]; !exists {
  12082. seen[s] = true
  12083. output = append(output, s)
  12084. }
  12085. }
  12086. return output
  12087. }
  12088. func (c *HisApiController) GetHisMonthPatientInfo() {
  12089. patient_id, _ := c.GetInt64("patient_id")
  12090. his_patient_id, _ := c.GetInt64("his_patient_id")
  12091. record_date := c.GetString("record_date")
  12092. number := c.GetString("number")
  12093. start_time := c.GetString("start_time")
  12094. end_time := c.GetString("end_time")
  12095. p_type, _ := c.GetInt64("p_type")
  12096. timeLayout := "2006-01-02"
  12097. loc, _ := time.LoadLocation("Local")
  12098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12099. if err != nil {
  12100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12101. return
  12102. }
  12103. recordDateTime := theTime.Unix()
  12104. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12105. if err != nil {
  12106. }
  12107. startRecordDateTime := startTime.Unix()
  12108. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12109. if err != nil {
  12110. }
  12111. endRecordDateTime := endTime.Unix()
  12112. admin := c.GetAdminUserInfo()
  12113. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12114. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12115. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12116. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12117. var settle_total float64
  12118. for _, item := range monthPrescriptions {
  12119. if len(item.HisPrescriptionProject) > 0 {
  12120. for _, subItem := range item.HisPrescriptionProject {
  12121. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12122. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12123. settle_total = settle_total + total
  12124. }
  12125. }
  12126. if len(item.HisDoctorAdviceInfo) > 0 {
  12127. for _, subItem := range item.HisDoctorAdviceInfo {
  12128. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12129. settle_total = settle_total + total
  12130. }
  12131. }
  12132. }
  12133. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12134. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12135. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12136. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12137. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12138. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12139. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12140. //获取所有科室信息
  12141. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12142. c.ServeSuccessJSON(map[string]interface{}{
  12143. "his_info": his_patient_info,
  12144. "xt_info": xt_patient_info,
  12145. "case_history": case_history,
  12146. "info": patientPrescriptionInfo,
  12147. "month_prescriptions": monthPrescriptions,
  12148. "order": order,
  12149. "doctors": doctors,
  12150. "department": department,
  12151. "count": count,
  12152. "drugStockConfig": drugStockConfig,
  12153. "last_info": lastPatientPrescriptionInfo,
  12154. "settle_total": settle_total,
  12155. })
  12156. return
  12157. }
  12158. func (c *HisApiController) GetAllOrder() {
  12159. org_id := c.GetAdminUserInfo().CurrentOrgId
  12160. orders, _ := service.GetNewHisOrderList(org_id)
  12161. c.ServeSuccessJSON(map[string]interface{}{
  12162. "order": orders,
  12163. })
  12164. return
  12165. }
  12166. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12167. newArr = make([]*models.HisOrderInfoTwo, 0)
  12168. for i := 0; i < len(arr); i++ {
  12169. repeat := false
  12170. for j := i + 1; j < len(arr); j++ {
  12171. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12172. repeat = true
  12173. break
  12174. }
  12175. }
  12176. if !repeat {
  12177. newArr = append(newArr, arr[i])
  12178. }
  12179. }
  12180. return
  12181. }
  12182. // 修改处方退库操作 参数传修改之前的处方数据
  12183. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12184. if advice.ExecutionState == 1 {
  12185. //查询该病人该药品是否有库存记录
  12186. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12187. if errcode == gorm.ErrRecordNotFound {
  12188. } else {
  12189. //退库
  12190. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12191. if advice.PrescribingNumberUnit == drug.MinUnit {
  12192. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12193. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12194. //退库
  12195. warehouseInfo := models.DrugWarehouseInfo{
  12196. StockMinNumber: prescribingNumber,
  12197. }
  12198. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12199. operation_time := time.Now().Unix()
  12200. creater := advice.AdviceDoctor
  12201. ctime := time.Now().Unix()
  12202. timeStr := time.Now().Format("2006-01-02")
  12203. timeArr := strings.Split(timeStr, "-")
  12204. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12205. total = total + 1
  12206. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12207. cancelStock := models.DrugCancelStock{
  12208. OrderNumber: orderNumber,
  12209. OperaTime: operation_time,
  12210. OrgId: advice.UserOrgId,
  12211. Creater: creater,
  12212. Ctime: ctime,
  12213. Status: 1,
  12214. ReturnTime: advice.AdviceDate,
  12215. Dealer: info.Dealer,
  12216. Manufacturer: info.Manufacturer,
  12217. Type: 1,
  12218. }
  12219. service.AddSigleDrugCancelStock(&cancelStock)
  12220. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12221. dealer, _ := service.GetDealerById(info.Dealer)
  12222. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12223. cancelStockInfo := models.DrugCancelStockInfo{
  12224. OrderNumber: cancelInfo.OrderNumber,
  12225. CancelStockId: cancelInfo.ID,
  12226. DrugId: info.DrugId,
  12227. Count: info.Count,
  12228. Status: 1,
  12229. Ctime: ctime,
  12230. OrgId: advice.UserOrgId,
  12231. Type: 1,
  12232. Manufacturer: manufactureName.ManufacturerName,
  12233. Dealer: dealer.DealerName,
  12234. Total: 0,
  12235. RetailPrice: info.RetailPrice,
  12236. RetailTotalPrice: info.RetailTotalPrice,
  12237. Price: info.Price,
  12238. RegisterAccount: "",
  12239. Remark: info.Remark,
  12240. BatchNumber: info.BatchNumber,
  12241. MaxUnit: info.CountUnit,
  12242. ProductDate: info.ProductDate,
  12243. ExpiryDate: info.ExpiryDate,
  12244. BatchNumberId: info.WarehouseInfoId,
  12245. }
  12246. flow := models.DrugFlow{
  12247. WarehousingId: 0,
  12248. DrugId: info.DrugId,
  12249. Number: "",
  12250. BatchNumber: info.BatchNumber,
  12251. Count: info.Count,
  12252. UserOrgId: advice.UserOrgId,
  12253. PatientId: 0,
  12254. SystemTime: ctime,
  12255. ConsumableType: 4,
  12256. IsSys: 0,
  12257. WarehousingOrder: "",
  12258. WarehouseOutId: 0,
  12259. WarehouseOutOrderNumber: "",
  12260. IsEdit: 0,
  12261. CancelStockId: cancelStock.ID,
  12262. CancelOrderNumber: cancelStock.OrderNumber,
  12263. Manufacturer: info.Manufacturer,
  12264. Dealer: info.Dealer,
  12265. Creator: advice.UserOrgId,
  12266. UpdateCreator: 0,
  12267. Status: 1,
  12268. Ctime: time.Now().Unix(),
  12269. Mtime: 0,
  12270. Price: info.Price,
  12271. WarehousingDetailId: 0,
  12272. WarehouseOutDetailId: 0,
  12273. CancelOutDetailId: 0,
  12274. ExpireDate: info.ExpiryDate,
  12275. ProductDate: info.ProductDate,
  12276. MaxUnit: info.CountUnit,
  12277. MinUnit: "",
  12278. }
  12279. service.CreatedCancelStock(cancelStockInfo)
  12280. service.CreateDrugFlowOne(flow)
  12281. } else {
  12282. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12283. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12284. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12285. warehouseInfo := models.DrugWarehouseInfo{
  12286. StockMinNumber: prescribingNumber,
  12287. }
  12288. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12289. }
  12290. operation_time := time.Now().Unix()
  12291. creater := advice.AdviceDoctor
  12292. ctime := time.Now().Unix()
  12293. timeStr := time.Now().Format("2006-01-02")
  12294. timeArr := strings.Split(timeStr, "-")
  12295. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12296. total = total + 1
  12297. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12298. cancelStock := models.DrugCancelStock{
  12299. OrderNumber: orderNumber,
  12300. OperaTime: operation_time,
  12301. OrgId: advice.UserOrgId,
  12302. Creater: creater,
  12303. Ctime: ctime,
  12304. Status: 1,
  12305. ReturnTime: advice.AdviceDate,
  12306. Dealer: info.Dealer,
  12307. Manufacturer: info.Manufacturer,
  12308. Type: 1,
  12309. }
  12310. service.AddSigleDrugCancelStock(&cancelStock)
  12311. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12312. dealer, _ := service.GetDealerById(info.Dealer)
  12313. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12314. cancelStockInfo := models.DrugCancelStockInfo{
  12315. OrderNumber: cancelInfo.OrderNumber,
  12316. CancelStockId: cancelInfo.ID,
  12317. DrugId: info.DrugId,
  12318. Count: info.Count,
  12319. Status: 1,
  12320. Ctime: ctime,
  12321. OrgId: advice.UserOrgId,
  12322. Type: 1,
  12323. Manufacturer: manufactureName.ManufacturerName,
  12324. Dealer: dealer.DealerName,
  12325. Total: 0,
  12326. RetailPrice: info.RetailPrice,
  12327. RetailTotalPrice: info.RetailTotalPrice,
  12328. Price: info.Price,
  12329. RegisterAccount: "",
  12330. Remark: info.Remark,
  12331. BatchNumber: info.BatchNumber,
  12332. MaxUnit: info.CountUnit,
  12333. ProductDate: info.ProductDate,
  12334. ExpiryDate: info.ExpiryDate,
  12335. BatchNumberId: info.WarehouseInfoId,
  12336. }
  12337. flow := models.DrugFlow{
  12338. WarehousingId: 0,
  12339. DrugId: info.DrugId,
  12340. Number: "",
  12341. BatchNumber: info.BatchNumber,
  12342. Count: info.Count,
  12343. UserOrgId: advice.UserOrgId,
  12344. PatientId: 0,
  12345. SystemTime: ctime,
  12346. ConsumableType: 4,
  12347. IsSys: 0,
  12348. WarehousingOrder: "",
  12349. WarehouseOutId: 0,
  12350. WarehouseOutOrderNumber: "",
  12351. IsEdit: 0,
  12352. CancelStockId: cancelStock.ID,
  12353. CancelOrderNumber: cancelStock.OrderNumber,
  12354. Manufacturer: info.Manufacturer,
  12355. Dealer: info.Dealer,
  12356. Creator: advice.AdviceDoctor,
  12357. UpdateCreator: 0,
  12358. Status: 1,
  12359. Ctime: time.Now().Unix(),
  12360. Mtime: 0,
  12361. Price: info.Price,
  12362. WarehousingDetailId: 0,
  12363. WarehouseOutDetailId: 0,
  12364. CancelOutDetailId: 0,
  12365. ExpireDate: info.ExpiryDate,
  12366. ProductDate: info.ProductDate,
  12367. MaxUnit: info.CountUnit,
  12368. MinUnit: "",
  12369. }
  12370. service.CreatedCancelStock(cancelStockInfo)
  12371. service.CreateDrugFlowOne(flow)
  12372. }
  12373. }
  12374. }
  12375. return err
  12376. }
  12377. func (this *HisApiController) DeleteNCDS() {
  12378. id, _ := this.GetInt64("id", 0)
  12379. if id > 0 {
  12380. service.DeletePsnNCDSRecordById(id)
  12381. this.ServeSuccessJSON(map[string]interface{}{
  12382. "msg": "删除成功",
  12383. })
  12384. } else {
  12385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12386. return
  12387. }
  12388. }
  12389. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12390. id, _ := c.GetInt64("id")
  12391. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12392. c.ServeSuccessJSON(map[string]interface{}{
  12393. "advice": advice,
  12394. })
  12395. return
  12396. }
  12397. func (c *HisApiController) GetHisMonthChargePatientList() {
  12398. record_date := c.GetString("record_date")
  12399. start_time := c.GetString("start_time")
  12400. end_time := c.GetString("end_time")
  12401. timeLayout := "2006-01-02"
  12402. loc, _ := time.LoadLocation("Local")
  12403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12404. if err != nil {
  12405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12406. return
  12407. }
  12408. if err != nil {
  12409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12410. return
  12411. }
  12412. recordDateTime := theTime.Unix()
  12413. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12414. if err != nil {
  12415. }
  12416. startRecordDateTime := startTime.Unix()
  12417. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12418. if err != nil {
  12419. }
  12420. endRecordDateTime := endTime.Unix()
  12421. adminInfo := c.GetAdminUserInfo()
  12422. var tempMonthChargePatients []*service.MonthChargePatients
  12423. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12424. for _, item := range tempPatients {
  12425. //过滤没有处方的
  12426. if len(item.HisPrescription) == 0 {
  12427. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12428. }
  12429. }
  12430. c.ServeSuccessJSON(map[string]interface{}{
  12431. "list": tempMonthChargePatients,
  12432. })
  12433. }
  12434. // PrescriptionDifference 医嘱数量差值结构体
  12435. type PrescriptionDrugDifference struct {
  12436. DrugID int64 //基础库药品id
  12437. ID int64 //医嘱id
  12438. Difference float64 //差值
  12439. Unit string //单位
  12440. }
  12441. type PrescriptionGoodDifference struct {
  12442. GoodID int64 //基础库项目耗材id
  12443. ID int64 //医嘱id
  12444. Difference int64 //差值
  12445. Unit string //单位
  12446. Type int64 //类型
  12447. }
  12448. type EditCustomData struct {
  12449. adviceList []*models.HisDoctorAdviceInfo
  12450. projectList []*models.HisPrescriptionProject
  12451. }
  12452. type SrcCustomData struct {
  12453. adviceList []*models.HisDoctorAdviceInfo
  12454. projectList []*models.HisPrescriptionProject
  12455. }
  12456. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12457. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12458. differences := make([]*PrescriptionDrugDifference, 0)
  12459. // 创建一个 map 来存储第一个切片中的药品信息
  12460. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12461. for _, advice := range firstPrescription {
  12462. firstMap[advice.DrugId] = advice
  12463. }
  12464. // 遍历第二个切片中的药品信息,并比较数量差值
  12465. for _, advice := range secondPrescription {
  12466. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12467. diff := &PrescriptionDrugDifference{
  12468. DrugID: advice.DrugId,
  12469. ID: firstAdvice.ID,
  12470. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12471. Unit: firstAdvice.PrescribingNumberUnit,
  12472. }
  12473. differences = append(differences, diff)
  12474. }
  12475. }
  12476. return differences
  12477. }
  12478. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12479. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12480. differences := make([]*PrescriptionGoodDifference, 0)
  12481. // 创建一个 map 来存储第一个切片中的耗材信息
  12482. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12483. for _, good := range firstPrescription {
  12484. firstMap[good.ProjectId] = good
  12485. }
  12486. // 遍历第二个切片中的耗材信息,并比较数量差值
  12487. for _, good := range secondPrescription {
  12488. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12489. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12490. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12491. diff := &PrescriptionGoodDifference{
  12492. GoodID: good.ProjectId,
  12493. ID: firstGood.ID,
  12494. Difference: count - firstCount,
  12495. Unit: firstGood.Unit,
  12496. Type: firstGood.Type,
  12497. }
  12498. differences = append(differences, diff)
  12499. }
  12500. }
  12501. return differences
  12502. }
  12503. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12504. var adviceList []*models.HisDoctorAdviceInfo
  12505. var projectList []*models.HisPrescriptionProject
  12506. var advice_ids []int64
  12507. var project_ids []int64
  12508. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12509. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12510. //var tempPrescription *models.HisPrescriptionProjectscription
  12511. if len(prescriptions) > 0 {
  12512. for _, item := range prescriptions {
  12513. items := item.(map[string]interface{})
  12514. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12515. advices := items["advices"].([]interface{})
  12516. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12517. groupNo := int64(0)
  12518. ctime := time.Now().Unix()
  12519. mtime := ctime
  12520. if len(advices) > 0 {
  12521. for _, advice := range advices {
  12522. var s models.HisDoctorAdviceInfo
  12523. s.AdviceType = 2
  12524. s.StopState = 2
  12525. s.ExecutionState = 2
  12526. s.Status = 1
  12527. s.Groupno = groupNo
  12528. s.CreatedTime = ctime
  12529. s.UpdatedTime = mtime
  12530. s.IsSettle = 2
  12531. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12532. //存储切片中
  12533. if s.ID > 0 {
  12534. advice_ids = append(advice_ids, s.ID)
  12535. adviceList = append(adviceList, &s)
  12536. }
  12537. }
  12538. }
  12539. }
  12540. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12541. projects := items["project"].([]interface{})
  12542. if len(projects) > 0 {
  12543. for _, project := range projects {
  12544. var p models.HisPrescriptionProject
  12545. p.Ctime = time.Now().Unix()
  12546. p.Mtime = time.Now().Unix()
  12547. p.Status = 1
  12548. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12549. if p.ID > 0 {
  12550. project_ids = append(project_ids, p.ID)
  12551. projectList = append(projectList, &p)
  12552. }
  12553. }
  12554. }
  12555. }
  12556. }
  12557. }
  12558. }
  12559. editCustomData.projectList = projectList
  12560. editCustomData.adviceList = adviceList
  12561. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12562. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12563. srcCustomData.adviceList = list
  12564. srcCustomData.projectList = list2
  12565. return
  12566. }