his_api_controller.go 551KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171
  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. c.ServeFailJSONWithSGJErrorCode(errcode)
  3249. return
  3250. }
  3251. if p.ID == 0 {
  3252. p.IsOut = 2
  3253. }
  3254. if p.ID > 0 {
  3255. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3256. p.IsOut = projectDetail.IsOut
  3257. }
  3258. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3259. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3260. if p.Type == 3 {
  3261. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3262. if p.Price != lastWarehouse.PackingPrice {
  3263. p.Price = lastWarehouse.PackingPrice
  3264. }
  3265. if p.Price == 0 {
  3266. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3267. p.Price = lastWarehouseTwo.PackingPrice
  3268. }
  3269. if p.Unit == "" {
  3270. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3271. p.Unit = goodInfoOne.PackingUnit
  3272. }
  3273. }
  3274. }
  3275. if adminInfo.CurrentOrgId != 10206 {
  3276. if p.Type == 3 {
  3277. if p.ID == 0 {
  3278. //查询该耗材是否停用
  3279. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3280. //表示该耗材已经停用,不能保存
  3281. if goodInfoSeven.ID == 0 {
  3282. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3283. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3284. return
  3285. }
  3286. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3287. if goodInfoOne.SumCount == 0 {
  3288. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3289. return
  3290. }
  3291. }
  3292. }
  3293. }
  3294. //查询保存耗材出库开关是否打开
  3295. if p.PatientId != 30038 {
  3296. if goodOutConfig.IsOpen == 1 {
  3297. //耗材出库
  3298. if p.Type == 3 {
  3299. //对比当前数据和历史出库数据
  3300. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3301. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3302. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3303. //fmt.Println("p----------------------------------------------------", p.ProjectId)
  3304. //fmt.Println("p----------------------------------------------------", nowCount)
  3305. //fmt.Println("p----------------------------------------------------", historyCount)
  3306. //如果当前处方数量大于历史数据,则需要出库
  3307. if nowCount > historyCount {
  3308. var cha_count int64
  3309. cha_count = nowCount - historyCount
  3310. timeStr := time.Now().Format("2006-01-02")
  3311. timeArr := strings.Split(timeStr, "-")
  3312. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3313. total = total + 1
  3314. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3315. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3316. number = number + total
  3317. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3318. operation_time := time.Now().Unix()
  3319. creater := c.GetAdminUserInfo().AdminUser.Id
  3320. recordDateStr := time.Now().Format("2006-01-02")
  3321. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3322. nowtime := recordDate.Unix()
  3323. warehouseOut := models.WarehouseOut{
  3324. WarehouseOutOrderNumber: warehousing_out_order,
  3325. OperationTime: operation_time,
  3326. OrgId: adminInfo.CurrentOrgId,
  3327. Creater: creater,
  3328. Ctime: time.Now().Unix(),
  3329. Status: 1,
  3330. WarehouseOutTime: nowtime,
  3331. Type: 1,
  3332. StorehouseId: storeConfig.StorehouseOutInfo,
  3333. IsCheck: 1,
  3334. IsSys: 1,
  3335. }
  3336. //查询是否生成出库单
  3337. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3338. if out.ID == 0 {
  3339. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3340. }
  3341. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3342. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3343. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3344. dialyPrepareOne := models.DialysisBeforePrepare{
  3345. GoodTypeId: goodObj.GoodTypeId,
  3346. GoodId: p.ProjectId,
  3347. PatientId: p.PatientId,
  3348. RecordDate: p.RecordDate,
  3349. UserOrgId: adminInfo.CurrentOrgId,
  3350. Count: cha_count,
  3351. Ctime: time.Now().Unix(),
  3352. Creater: creater,
  3353. Status: 1,
  3354. StorehouseId: houseConfig.StorehouseOutInfo,
  3355. ProjectId: p.ID,
  3356. }
  3357. //出库
  3358. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3359. }
  3360. //如果当前处方数量小于历史数据,怎需要退库
  3361. if nowCount < historyCount {
  3362. var cha_count int64
  3363. cha_count = historyCount - nowCount
  3364. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3365. creater := c.GetAdminUserInfo().AdminUser.Id
  3366. newPrescriptionProject := &models.HisPrescriptionProject{
  3367. ID: p.ID,
  3368. ProjectId: p.ProjectId,
  3369. Price: p.Price,
  3370. UserOrgId: p.UserOrgId,
  3371. Status: 1,
  3372. Ctime: time.Now().Unix(),
  3373. Mtime: time.Now().Unix(),
  3374. PatientId: p.PatientId,
  3375. HisPatientId: p.HisPatientId,
  3376. RecordDate: p.RecordDate,
  3377. PrescriptionId: p.PrescriptionId,
  3378. Count: p.Count,
  3379. FeedetlSn: p.FeedetlSn,
  3380. MedListCodg: p.MedListCodg,
  3381. SingleDose: p.SingleDose,
  3382. DeliveryWay: p.DeliveryWay,
  3383. ExecutionFrequency: p.ExecutionFrequency,
  3384. Day: p.Day,
  3385. HisProject: models.HisProject{},
  3386. GoodInfo: models.GoodInfo{},
  3387. Remark: p.Remark,
  3388. Unit: p.Unit,
  3389. Type: p.Type,
  3390. Doctor: p.Doctor,
  3391. ExecutionTime: p.ExecutionTime,
  3392. ExecutionStaff: p.ExecutionStaff,
  3393. ExecutionState: p.ExecutionState,
  3394. CheckTime: p.CheckTime,
  3395. CheckState: p.CheckState,
  3396. Checker: p.Checker,
  3397. StartTime: p.StartTime,
  3398. TeamId: p.TeamId,
  3399. XtHisProjectTeam: models.XtHisProjectTeam{},
  3400. FrequencyType: p.FrequencyType,
  3401. DayCount: p.DayCount,
  3402. WeekDay: p.WeekDay,
  3403. IsCheckTeam: p.IsCheckTeam,
  3404. HisOrderInfo: models.HisOrderInfo{},
  3405. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3406. IsOut: p.IsOut,
  3407. YbSyncStatus: p.YbSyncStatus,
  3408. }
  3409. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3410. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3411. }
  3412. if nowCount == historyCount {
  3413. if historyCount == 0 {
  3414. recordDateStr := time.Now().Format("2006-01-02")
  3415. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3416. nowtime := recordDate.Unix()
  3417. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3418. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3419. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3420. creater := c.GetAdminUserInfo().AdminUser.Id
  3421. dialyPrepareOne := models.DialysisBeforePrepare{
  3422. GoodTypeId: goodObj.GoodTypeId,
  3423. GoodId: p.ProjectId,
  3424. PatientId: p.PatientId,
  3425. RecordDate: p.RecordDate,
  3426. UserOrgId: adminInfo.CurrentOrgId,
  3427. Count: nowCount,
  3428. Ctime: time.Now().Unix(),
  3429. Creater: creater,
  3430. Status: 1,
  3431. StorehouseId: houseConfig.StorehouseOutInfo,
  3432. ProjectId: p.ID,
  3433. }
  3434. //出库
  3435. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3436. }
  3437. }
  3438. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3439. //查询历史出库数据
  3440. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3441. var out_count_five int64
  3442. for _, item := range flowGood {
  3443. out_count_five += item.Count
  3444. }
  3445. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3446. //fmt.Println("p.ProjectId-----------------", p.ProjectId)
  3447. //fmt.Println("out_count_five===============", out_count_five)
  3448. //fmt.Println("parseIntCount===============", parseIntCount)
  3449. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3450. if out_count_five != parseIntCount {
  3451. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3452. detail := models.AutomaticReduceDetail{
  3453. WarehouseOutId: 0,
  3454. WarehouseOutOrderNumber: "",
  3455. PatientId: p.PatientId,
  3456. Ctime: time.Now().Unix(),
  3457. Mtime: 0,
  3458. Status: 1,
  3459. RecordTime: p.RecordDate,
  3460. OrgId: p.UserOrgId,
  3461. GoodId: p.ProjectId,
  3462. GoodTypeId: 0,
  3463. Count: parseIntCount,
  3464. Type: 0,
  3465. ProjectId: lastHisProject.ID,
  3466. StorehouseId: 0,
  3467. }
  3468. service.CreateNewAutoDetail(detail, tx)
  3469. }
  3470. // //查询耗材最后一次出库记录
  3471. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3472. // //查询默认出库仓库库存
  3473. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3474. // if len(wareOut) > 0 {
  3475. //
  3476. // for _, it := range wareOut {
  3477. // //回退库存
  3478. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3479. //
  3480. // //删除出库记录
  3481. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3482. //
  3483. // }
  3484. // }
  3485. //
  3486. // timeStr := time.Now().Format("2006-01-02")
  3487. // timeArr := strings.Split(timeStr, "-")
  3488. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3489. //
  3490. // total = total + 1
  3491. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3492. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3493. // number = number + total
  3494. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3495. //
  3496. // operation_time := time.Now().Unix()
  3497. // creater := c.GetAdminUserInfo().AdminUser.Id
  3498. //
  3499. // recordDateStr := time.Now().Format("2006-01-02")
  3500. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3501. // nowtime := recordDate.Unix()
  3502. // warehouseOut := models.WarehouseOut{
  3503. // WarehouseOutOrderNumber: warehousing_out_order,
  3504. // OperationTime: operation_time,
  3505. // OrgId: adminInfo.CurrentOrgId,
  3506. // Creater: creater,
  3507. // Ctime: time.Now().Unix(),
  3508. // Status: 1,
  3509. // WarehouseOutTime: nowtime,
  3510. // Type: 1,
  3511. // StorehouseId: storeConfig.StorehouseOutInfo,
  3512. // IsCheck: 1,
  3513. // IsSys: 1,
  3514. // }
  3515. // //查询是否生成出库单
  3516. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3517. // if out.ID == 0 {
  3518. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3519. // }
  3520. //
  3521. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3522. //
  3523. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3524. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3525. //
  3526. // dialyPrepareOne := models.DialysisBeforePrepare{
  3527. // GoodTypeId: goodObj.GoodTypeId,
  3528. // GoodId: p.ProjectId,
  3529. // PatientId: p.PatientId,
  3530. // RecordDate: p.RecordDate,
  3531. // UserOrgId: adminInfo.CurrentOrgId,
  3532. // Count: parseIntCount,
  3533. // Ctime: time.Now().Unix(),
  3534. // Creater: creater,
  3535. // Status: 1,
  3536. // StorehouseId: houseConfig.StorehouseOutInfo,
  3537. // ProjectId: lastHisProject.ID,
  3538. // }
  3539. // //判断是否是零用耗材(非零用)
  3540. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3541. //
  3542. // //查询历史出库数据
  3543. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3544. // var out_count int64
  3545. // for _, item := range flowGood {
  3546. // out_count += item.Count
  3547. // }
  3548. // //如果历史数和当前数据不想等才进行退库出库
  3549. // if out_count != parseIntCount {
  3550. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3551. //
  3552. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3553. // detail := models.AutomaticReduceDetail{
  3554. // WarehouseOutId: 0,
  3555. // WarehouseOutOrderNumber: "",
  3556. // PatientId: p.PatientId,
  3557. // Ctime: time.Now().Unix(),
  3558. // Mtime: 0,
  3559. // Status: 1,
  3560. // RecordTime: p.RecordDate,
  3561. // OrgId: p.UserOrgId,
  3562. // GoodId: p.ProjectId,
  3563. // GoodTypeId: 0,
  3564. // Count: parseIntCount,
  3565. // Type: 0,
  3566. // ProjectId: lastHisProject.ID,
  3567. // StorehouseId: 0,
  3568. // }
  3569. //
  3570. // service.CreateNewAutoDetail(detail, tx)
  3571. //
  3572. // //查询剩余库存
  3573. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3574. // var sum_count int64
  3575. // for _, item := range goodList {
  3576. // sum_count += item.StockCount
  3577. // }
  3578. //
  3579. // //更新剩余库存
  3580. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3581. //
  3582. // //耗材
  3583. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3584. //
  3585. // }
  3586. // //判断是否是零用耗材(零用但是是出库耗材)
  3587. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3588. //
  3589. // //查询历史出库数据
  3590. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3591. // var out_count int64
  3592. // for _, item := range flowGood {
  3593. // out_count += item.Count
  3594. // }
  3595. // //如果历史数和当前数据不想等才进行退库出库
  3596. // if out_count != parseIntCount {
  3597. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3598. //
  3599. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3600. // detail := models.AutomaticReduceDetail{
  3601. // WarehouseOutId: 0,
  3602. // WarehouseOutOrderNumber: "",
  3603. // PatientId: p.PatientId,
  3604. // Ctime: time.Now().Unix(),
  3605. // Mtime: 0,
  3606. // Status: 1,
  3607. // RecordTime: p.RecordDate,
  3608. // OrgId: p.UserOrgId,
  3609. // GoodId: p.ProjectId,
  3610. // GoodTypeId: 0,
  3611. // Count: parseIntCount,
  3612. // Type: 0,
  3613. // ProjectId: p.ID,
  3614. // StorehouseId: 0,
  3615. // }
  3616. //
  3617. // service.CreateNewAutoDetail(detail, tx)
  3618. //
  3619. // //查询剩余库存
  3620. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3621. // var sum_count int64
  3622. // for _, item := range goodList {
  3623. // sum_count += item.StockCount
  3624. // }
  3625. //
  3626. // //更新剩余库存
  3627. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3628. //
  3629. // //耗材
  3630. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3631. // }
  3632. //
  3633. // }
  3634. //
  3635. // }
  3636. //
  3637. //}
  3638. //记录日志
  3639. byterequest, _ := json.Marshal(p)
  3640. adviceLog := models.XtDoctorAdviceLog{
  3641. UserOrgId: p.UserOrgId,
  3642. PatientId: p.PatientId,
  3643. AdminUserId: adminInfo.AdminUser.Id,
  3644. Module: 1,
  3645. ErrLog: string(byterequest),
  3646. Status: 1,
  3647. Ctime: time.Now().Unix(),
  3648. Mtime: 0,
  3649. Source: "电脑端新建his项目",
  3650. RecordDate: p.RecordDate,
  3651. }
  3652. service.CreateDoctorAdviceLog(adviceLog)
  3653. projectList = append(projectList, p)
  3654. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3655. //新增或者编辑项目,修改对应的标签数据
  3656. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3657. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3658. var label models.HisLabelPrintInfo
  3659. project, _ := service.GetProjectDetail(p.ProjectId)
  3660. if project.CostClassify == 3 { //类别为检验检查
  3661. if p.TeamId > 0 { //检验检查组套
  3662. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3663. if tempLabel.ID == 0 {
  3664. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3665. label.Number = tempPrescription.PrescriptionNumber
  3666. label.ProjectId = project.ID
  3667. label.Status = 1
  3668. label.IsPrint = 2
  3669. label.DoctorId = info.DoctorId
  3670. label.UserOrgId = p.UserOrgId
  3671. label.PatientId = patient_id
  3672. label.RecordDate = recordDateTime
  3673. label.Ctime = time.Now().Unix()
  3674. label.Mtime = time.Now().Unix()
  3675. label.ItemId = p.TeamId
  3676. label.FeedetlSn = p.FeedetlSn
  3677. label.PProjectId = p.ID
  3678. label.ProjectName = team.ProjectTeam
  3679. label.PatientName = patient.Name
  3680. service.CreateNewHisLabelRecord(&label, tx)
  3681. }
  3682. } else { //单条检验检查项目
  3683. label.Number = tempPrescription.PrescriptionNumber
  3684. label.ProjectId = project.ID
  3685. label.Status = 1
  3686. label.DoctorId = info.DoctorId
  3687. label.UserOrgId = p.UserOrgId
  3688. label.PatientId = patient_id
  3689. label.RecordDate = recordDateTime
  3690. label.IsPrint = 2
  3691. label.Ctime = time.Now().Unix()
  3692. label.Mtime = time.Now().Unix()
  3693. label.FeedetlSn = p.FeedetlSn
  3694. label.PProjectId = p.ID
  3695. label.ItemId = p.TeamId
  3696. label.ProjectName = project.ProjectName
  3697. label.PatientName = patient.Name
  3698. service.CreateNewHisLabelRecord(&label, tx)
  3699. }
  3700. }
  3701. }
  3702. }
  3703. }
  3704. }
  3705. }
  3706. //插入检验数据
  3707. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3708. //新增或者编辑项目,修改对应的标签数据
  3709. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3710. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3711. var label models.HisLabelPrintInfo
  3712. project, _ := service.GetProjectDetail(p.ProjectId)
  3713. if project.CostClassify == 3 { //类别为检验检查
  3714. if p.TeamId > 0 { //检验检查组套
  3715. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3716. if tempLabel.ID == 0 {
  3717. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3718. label.Number = tempPrescription.PrescriptionNumber
  3719. label.ProjectId = project.ID
  3720. label.Status = 1
  3721. label.IsPrint = 2
  3722. label.DoctorId = info.DoctorId
  3723. label.UserOrgId = p.UserOrgId
  3724. label.PatientId = patient_id
  3725. label.RecordDate = recordDateTime
  3726. label.Ctime = time.Now().Unix()
  3727. label.Mtime = time.Now().Unix()
  3728. label.ItemId = p.TeamId
  3729. label.FeedetlSn = p.FeedetlSn
  3730. label.PProjectId = p.ID
  3731. label.ProjectName = team.ProjectTeam
  3732. label.PatientName = patient.Name
  3733. service.CreateHisLabelRecord(&label)
  3734. }
  3735. } else { //单条检验检查项目
  3736. label.Number = tempPrescription.PrescriptionNumber
  3737. label.ProjectId = project.ID
  3738. label.Status = 1
  3739. label.DoctorId = info.DoctorId
  3740. label.UserOrgId = p.UserOrgId
  3741. label.PatientId = patient_id
  3742. label.RecordDate = recordDateTime
  3743. label.IsPrint = 2
  3744. label.Ctime = time.Now().Unix()
  3745. label.Mtime = time.Now().Unix()
  3746. label.FeedetlSn = p.FeedetlSn
  3747. label.PProjectId = p.ID
  3748. label.ItemId = p.TeamId
  3749. label.ProjectName = project.ProjectName
  3750. label.PatientName = patient.Name
  3751. service.CreateHisLabelRecord(&label)
  3752. }
  3753. }
  3754. }
  3755. }
  3756. service.CreateNewHisProjectTwo(&p, tx)
  3757. var randNum int
  3758. randNum = rand.Intn(10000) + 1000
  3759. timestamp := time.Now().Unix()
  3760. tempTime := time.Unix(timestamp, 0)
  3761. timeFormat := tempTime.Format("20060102150405")
  3762. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3763. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3764. if goodBase.ID > 0 {
  3765. tx.Rollback()
  3766. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3767. return
  3768. }
  3769. service.CreateNewHisProjectTwo(&p, tx)
  3770. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3771. //查询剩余库存
  3772. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3773. var sum_count int64
  3774. for _, item := range goodList {
  3775. sum_count += item.StockCount
  3776. }
  3777. //更新剩余库存
  3778. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3779. //耗材
  3780. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3781. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3782. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3783. if len(outInfoTwo) > 0 {
  3784. for _, item := range outInfoTwo {
  3785. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3786. }
  3787. }
  3788. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3789. if len(drugAutoDetail) > 0 {
  3790. for _, item := range drugAutoDetail {
  3791. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3792. }
  3793. }
  3794. tx.Commit()
  3795. }
  3796. }
  3797. }
  3798. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3799. // addition := items["addition"].([]interface{})
  3800. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3801. // ctime := time.Now().Unix()
  3802. // mtime := ctime
  3803. // if len(addition) > 0 {
  3804. // for _, item := range addition {
  3805. // var s models.HisAdditionalCharge
  3806. // s.PrescriptionId = tempPrescription.ID
  3807. // s.Status = 1
  3808. // s.UserOrgId = adminInfo.CurrentOrgId
  3809. // s.RecordDate = recordDateTime
  3810. // s.CreatedTime = ctime
  3811. // s.UpdatedTime = mtime
  3812. // s.PatientId = patient_id
  3813. // s.HisPatientId = his_patient_id
  3814. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3815. // if errcode > 0 {
  3816. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3817. // return
  3818. // }
  3819. // service.CreateAdditionalCharge(&s)
  3820. // var randNum int
  3821. // randNum = rand.Intn(10000) + 1000
  3822. // timestamp := time.Now().Unix()
  3823. // tempTime := time.Unix(timestamp, 0)
  3824. // timeFormat := tempTime.Format("20060102150405")
  3825. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3826. // service.CreateAdditionalCharge(&s)
  3827. //
  3828. // }
  3829. // }
  3830. //}
  3831. }
  3832. }
  3833. }
  3834. tx.Commit()
  3835. if err == nil {
  3836. c.ServeSuccessJSON(map[string]interface{}{
  3837. "msg": "保存成功",
  3838. })
  3839. return
  3840. } else {
  3841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3842. return
  3843. }
  3844. } else {
  3845. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3846. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3847. var tempPrescription *models.HisPrescription
  3848. if len(prescriptions) > 0 {
  3849. for _, item := range prescriptions {
  3850. items := item.(map[string]interface{})
  3851. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3852. utils.ErrorLog("id")
  3853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3854. return
  3855. }
  3856. id := int64(items["id"].(float64))
  3857. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3858. tempPrescription = &new_prescription
  3859. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3860. utils.ErrorLog("type")
  3861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3862. return
  3863. }
  3864. types := int64(items["type"].(float64))
  3865. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3866. utils.ErrorLog("med_type")
  3867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3868. return
  3869. }
  3870. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3871. if med_type == "0" {
  3872. med_type = "14"
  3873. }
  3874. //if order_status == 0 {
  3875. // order_status = 1
  3876. //}
  3877. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3878. utils.ErrorLog("pre_time")
  3879. }
  3880. preTime, _ := items["pre_time"].(string)
  3881. timeLayout := "2006-01-02"
  3882. loc, _ := time.LoadLocation("Local")
  3883. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3884. //result := strings.Split(preTime, " ")
  3885. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3886. if err != nil {
  3887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3888. return
  3889. }
  3890. pTime := theTime2.Unix()
  3891. ctime := time.Now().Unix()
  3892. if tempPrescription.ID == 0 {
  3893. prescription := &models.HisPrescription{
  3894. ID: 0,
  3895. PatientId: patient_id,
  3896. UserOrgId: adminInfo.CurrentOrgId,
  3897. RecordDate: recordDateTime,
  3898. Ctime: ctime,
  3899. Mtime: ctime,
  3900. Type: types,
  3901. Modifier: adminInfo.AdminUser.Id,
  3902. Creator: adminInfo.AdminUser.Id,
  3903. Status: 1,
  3904. Doctor: role.UserName,
  3905. HisPatientId: his_patient_id,
  3906. OrderStatus: 1,
  3907. BatchNumber: "",
  3908. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3909. PreTime: pTime,
  3910. PType: p_type,
  3911. MedType: med_type,
  3912. }
  3913. tempPrescription = prescription
  3914. service.SaveHisPrescription(tempPrescription)
  3915. redis := service.RedisClient()
  3916. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3917. redis.Set(key, "", time.Second)
  3918. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3919. redis.Set(keyOne, "", time.Second)
  3920. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3921. redis.Set(keySeven, "", time.Second)
  3922. defer redis.Close()
  3923. } else {
  3924. tempPrescription.ID = id
  3925. tempPrescription.Type = types
  3926. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3927. tempPrescription.Mtime = time.Now().Unix()
  3928. tempPrescription.Doctor = role.UserName
  3929. //tempPrescription.OrderStatus = order_status
  3930. tempPrescription.PreTime = pTime
  3931. tempPrescription.MedType = med_type
  3932. service.SaveHisPrescription(tempPrescription)
  3933. redis := service.RedisClient()
  3934. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3935. redis.Set(key, "", time.Second)
  3936. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3937. redis.Set(keyOne, "", time.Second)
  3938. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3939. redis.Set(keySeven, "", time.Second)
  3940. defer redis.Close()
  3941. }
  3942. //service.SaveHisPrescription(prescription)
  3943. //更改患者挂号状态
  3944. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3945. fmt.Println("更改失败", err2)
  3946. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3947. advices := items["advices"].([]interface{})
  3948. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3949. groupNo := int64(0)
  3950. if len(advices) > 0 {
  3951. for _, advice := range advices {
  3952. var s models.HisDoctorAdviceInfo
  3953. s.PrescriptionId = tempPrescription.ID
  3954. s.AdviceType = 2
  3955. s.AdviceDoctor = doctor_id
  3956. s.StopState = 2
  3957. s.ExecutionState = 2
  3958. s.AdviceDate = theTime3.Unix()
  3959. s.Status = 1
  3960. s.UserOrgId = adminInfo.CurrentOrgId
  3961. s.RecordDate = theTime3.Unix()
  3962. s.StartTime = tempPrescription.PreTime
  3963. s.Groupno = groupNo
  3964. s.PatientId = patient_id
  3965. s.HisPatientId = his_patient_id
  3966. s.StartTime = pTime
  3967. s.IsSettle = 2
  3968. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3969. if errcode > 0 {
  3970. c.ServeFailJSONWithSGJErrorCode(errcode)
  3971. return
  3972. }
  3973. s.StartTime = pTime
  3974. var total_count int64 //处方总库存
  3975. //查询改药品信息
  3976. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3977. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3978. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3979. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3980. total_count += prescribingNumberSeven * medical.MinNumber
  3981. }
  3982. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3983. total_count += prescribingNumberSeven
  3984. }
  3985. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3986. total_count += prescribingNumberSeven
  3987. }
  3988. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3989. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3990. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3991. if s.Price != lastWarehouse.RetailPrice {
  3992. s.Price = lastWarehouse.RetailPrice
  3993. }
  3994. if s.Price == 0 {
  3995. if lastWarehouse.ID == 0 {
  3996. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3997. s.Price = lastWarehouseTwo.RetailPrice
  3998. }
  3999. }
  4000. }
  4001. if adminInfo.CurrentOrgId != 10206 {
  4002. if s.ID == 0 {
  4003. //查询改药品是否已经停用
  4004. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4005. if base.ID > 0 {
  4006. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4007. return
  4008. }
  4009. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4010. if drugMedical.SumCount == 0 {
  4011. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4012. return
  4013. }
  4014. }
  4015. }
  4016. //赤峰
  4017. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4018. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4019. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4020. if info.RetailPrice > 0 {
  4021. if s.DeliveryWay == "口服" {
  4022. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4023. s.Price = drug.RetailPrice
  4024. }
  4025. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4026. s.Price = info.RetailPrice
  4027. }
  4028. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4029. s.Price = info.RetailPrice
  4030. }
  4031. }
  4032. }
  4033. }
  4034. service.CreateHisDoctorAdvice(&s)
  4035. //记录日志
  4036. byterequest, _ := json.Marshal(s)
  4037. adviceLog := models.XtDoctorAdviceLog{
  4038. UserOrgId: s.UserOrgId,
  4039. PatientId: s.PatientId,
  4040. AdminUserId: adminInfo.AdminUser.Id,
  4041. Module: 1,
  4042. ErrLog: string(byterequest),
  4043. Status: 1,
  4044. Ctime: time.Now().Unix(),
  4045. Mtime: 0,
  4046. Source: "电脑端新建his医嘱",
  4047. RecordDate: s.AdviceDate,
  4048. }
  4049. service.CreateDoctorAdviceLog(adviceLog)
  4050. //存储切片中
  4051. adviceList = append(adviceList, s)
  4052. redis := service.RedisClient()
  4053. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4054. redis.Set(key, "", time.Second)
  4055. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4056. redis.Set(keyOne, "", time.Second)
  4057. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4058. redis.Set(keySeven, "", time.Second)
  4059. var randNum int
  4060. randNum = rand.Intn(10000) + 1000
  4061. timestamp := time.Now().Unix()
  4062. tempTime := time.Unix(timestamp, 0)
  4063. timeFormat := tempTime.Format("20060102150405")
  4064. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4065. service.CreateHisDoctorAdvice(&s)
  4066. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4067. redis.Set(keySix, "", time.Second)
  4068. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4069. redis.Set(keyFive, "", time.Second)
  4070. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4071. redis.Set(keyEight, "", time.Second)
  4072. defer redis.Close()
  4073. }
  4074. }
  4075. }
  4076. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4077. projects := items["project"].([]interface{})
  4078. if len(projects) > 0 {
  4079. for _, project := range projects {
  4080. var p models.HisPrescriptionProject
  4081. p.PrescriptionId = tempPrescription.ID
  4082. p.PatientId = patient_id
  4083. p.RecordDate = theTime3.Unix()
  4084. p.Doctor = doctor_id
  4085. p.UserOrgId = adminInfo.CurrentOrgId
  4086. p.HisPatientId = his_patient_id
  4087. p.Status = 1
  4088. p.StartTime = pTime
  4089. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4090. if errcode > 0 {
  4091. c.ServeFailJSONWithSGJErrorCode(errcode)
  4092. return
  4093. }
  4094. if p.ID == 0 {
  4095. p.IsOut = 2
  4096. }
  4097. if p.ID > 0 {
  4098. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4099. p.IsOut = projectDetail.IsOut
  4100. }
  4101. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4102. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4103. if p.Type == 3 {
  4104. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4105. if p.Price != lastWarehouse.PackingPrice {
  4106. p.Price = lastWarehouse.PackingPrice
  4107. }
  4108. if p.Price == 0 {
  4109. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4110. p.Price = lastWarehouseTwo.PackingPrice
  4111. }
  4112. if p.Unit == "" {
  4113. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4114. p.Unit = goodInfoOne.PackingUnit
  4115. }
  4116. }
  4117. }
  4118. if adminInfo.CurrentOrgId != 10206 {
  4119. if p.Type == 3 {
  4120. if p.ID == 0 {
  4121. //查询该耗材是否停用
  4122. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4123. //表示该耗材已经停用,不能保存
  4124. if goodInfoSeven.ID == 0 {
  4125. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4126. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4127. return
  4128. }
  4129. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4130. if goodInfoOne.SumCount == 0 {
  4131. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4132. return
  4133. }
  4134. }
  4135. }
  4136. }
  4137. service.CreateHisProjectTwo(&p)
  4138. //记录日志
  4139. byterequest, _ := json.Marshal(p)
  4140. adviceLog := models.XtDoctorAdviceLog{
  4141. UserOrgId: p.UserOrgId,
  4142. PatientId: p.PatientId,
  4143. AdminUserId: adminInfo.AdminUser.Id,
  4144. Module: 1,
  4145. ErrLog: string(byterequest),
  4146. Status: 1,
  4147. Ctime: time.Now().Unix(),
  4148. Mtime: 0,
  4149. Source: "电脑端新建his项目",
  4150. RecordDate: p.RecordDate,
  4151. }
  4152. service.CreateDoctorAdviceLog(adviceLog)
  4153. projectList = append(projectList, p)
  4154. var randNum int
  4155. randNum = rand.Intn(10000) + 1000
  4156. timestamp := time.Now().Unix()
  4157. tempTime := time.Unix(timestamp, 0)
  4158. timeFormat := tempTime.Format("20060102150405")
  4159. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4160. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4161. //新增或者编辑项目,修改对应的标签数据
  4162. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4163. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4164. var label models.HisLabelPrintInfo
  4165. project, _ := service.GetProjectDetail(p.ProjectId)
  4166. if project.CostClassify == 3 { //类别为检验检查
  4167. if p.TeamId > 0 { //检验检查组套
  4168. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4169. if tempLabel.ID == 0 {
  4170. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4171. label.Number = tempPrescription.PrescriptionNumber
  4172. label.ProjectId = project.ID
  4173. label.Status = 1
  4174. label.IsPrint = 2
  4175. label.DoctorId = info.DoctorId
  4176. label.UserOrgId = p.UserOrgId
  4177. label.PatientId = patient_id
  4178. label.RecordDate = recordDateTime
  4179. label.Ctime = time.Now().Unix()
  4180. label.Mtime = time.Now().Unix()
  4181. label.ItemId = p.TeamId
  4182. label.FeedetlSn = p.FeedetlSn
  4183. label.PProjectId = p.ID
  4184. label.ProjectName = team.ProjectTeam
  4185. label.PatientName = patient.Name
  4186. service.CreateHisLabelRecord(&label)
  4187. }
  4188. } else { //单条检验检查项目
  4189. label.Number = tempPrescription.PrescriptionNumber
  4190. label.ProjectId = project.ID
  4191. label.Status = 1
  4192. label.DoctorId = info.DoctorId
  4193. label.UserOrgId = p.UserOrgId
  4194. label.PatientId = patient_id
  4195. label.RecordDate = recordDateTime
  4196. label.IsPrint = 2
  4197. label.Ctime = time.Now().Unix()
  4198. label.Mtime = time.Now().Unix()
  4199. label.FeedetlSn = p.FeedetlSn
  4200. label.PProjectId = p.ID
  4201. label.ItemId = p.TeamId
  4202. label.ProjectName = project.ProjectName
  4203. label.PatientName = patient.Name
  4204. service.CreateHisLabelRecord(&label)
  4205. }
  4206. }
  4207. }
  4208. }
  4209. service.SaveHisProjectTwo(&p)
  4210. }
  4211. }
  4212. }
  4213. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4214. // addition := items["addition"].([]interface{})
  4215. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4216. // ctime := time.Now().Unix()
  4217. // mtime := ctime
  4218. // if len(addition) > 0 {
  4219. // for _, item := range addition {
  4220. // var s models.HisAdditionalCharge
  4221. // s.PrescriptionId = tempPrescription.ID
  4222. // s.Status = 1
  4223. // s.UserOrgId = adminInfo.CurrentOrgId
  4224. // s.RecordDate = recordDateTime
  4225. // s.CreatedTime = ctime
  4226. // s.UpdatedTime = mtime
  4227. // s.PatientId = patient_id
  4228. // s.HisPatientId = his_patient_id
  4229. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4230. // if errcode > 0 {
  4231. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4232. // return
  4233. // }
  4234. // service.CreateAdditionalCharge(&s)
  4235. // var randNum int
  4236. // randNum = rand.Intn(10000) + 1000
  4237. // timestamp := time.Now().Unix()
  4238. // tempTime := time.Unix(timestamp, 0)
  4239. // timeFormat := tempTime.Format("20060102150405")
  4240. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4241. // service.CreateAdditionalCharge(&s)
  4242. //
  4243. // }
  4244. // }
  4245. //}
  4246. }
  4247. }
  4248. //查询今日该患者开的药品处方
  4249. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4250. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4251. //药品出库
  4252. if drugOutConfig.IsOpen == 1 {
  4253. for _, item := range hisdoctorlist {
  4254. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4255. // 查询该药品最后一次出库记录
  4256. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4257. if len(druginfo) > 0 {
  4258. //回退库存
  4259. for _, it := range druginfo {
  4260. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4261. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4262. }
  4263. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4264. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4265. }
  4266. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4267. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4268. }
  4269. }
  4270. }
  4271. //删除记录
  4272. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4273. //查询最后一次数据
  4274. if drugOutConfig.IsOpen == 1 {
  4275. //出库
  4276. if drug.IsUse == 2 {
  4277. creater := adminInfo.AdminUser.Id
  4278. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4279. }
  4280. //更新字典里面的库存
  4281. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4282. var sum_count int64
  4283. for _, its := range stockInfo {
  4284. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4285. if its.MaxUnit == baseDrug.MaxUnit {
  4286. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4287. }
  4288. sum_count += its.StockMaxNumber + its.StockMinNumber
  4289. }
  4290. //更新基础库存
  4291. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4292. //剩余库存
  4293. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4294. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4295. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4296. }
  4297. }
  4298. }
  4299. //耗材保存处方出库
  4300. if goodOutConfig.IsOpen == 1 {
  4301. //查询今日耗材出库数量
  4302. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4303. for _, item := range hisgoodlist {
  4304. //查询历史出库数据
  4305. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4306. var out_count_five int64
  4307. for _, item := range flowGood {
  4308. out_count_five += item.Count
  4309. }
  4310. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4311. if out_count_five != parseIntCount {
  4312. //查询耗材最后一次出库记录
  4313. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4314. //查询默认出库仓库库存
  4315. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4316. if len(wareOut) > 0 {
  4317. for _, it := range wareOut {
  4318. //回退库存
  4319. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4320. //删除出库记录
  4321. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4322. }
  4323. }
  4324. timeStr := time.Now().Format("2006-01-02")
  4325. timeArr := strings.Split(timeStr, "-")
  4326. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4327. total = total + 1
  4328. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4329. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4330. number = number + total
  4331. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4332. operation_time := time.Now().Unix()
  4333. creater := c.GetAdminUserInfo().AdminUser.Id
  4334. recordDateStr := time.Now().Format("2006-01-02")
  4335. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4336. nowtime := recordDate.Unix()
  4337. warehouseOut := models.WarehouseOut{
  4338. WarehouseOutOrderNumber: warehousing_out_order,
  4339. OperationTime: operation_time,
  4340. OrgId: adminInfo.CurrentOrgId,
  4341. Creater: creater,
  4342. Ctime: time.Now().Unix(),
  4343. Status: 1,
  4344. WarehouseOutTime: nowtime,
  4345. Type: 1,
  4346. StorehouseId: storeConfig.StorehouseOutInfo,
  4347. IsCheck: 1,
  4348. IsSys: 1,
  4349. }
  4350. //查询是否生成出库单
  4351. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4352. if out.ID == 0 {
  4353. service.AddSigleWarehouseOut(&warehouseOut)
  4354. }
  4355. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4356. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4357. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4358. dialyPrepareOne := models.DialysisBeforePrepare{
  4359. GoodTypeId: goodObj.GoodTypeId,
  4360. GoodId: item.ProjectId,
  4361. PatientId: item.PatientId,
  4362. RecordDate: item.RecordDate,
  4363. UserOrgId: adminInfo.CurrentOrgId,
  4364. Count: parseIntCount,
  4365. Ctime: time.Now().Unix(),
  4366. Creater: creater,
  4367. Status: 1,
  4368. StorehouseId: houseConfig.StorehouseOutInfo,
  4369. ProjectId: item.ID,
  4370. }
  4371. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4372. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4373. //查询历史出库数据
  4374. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4375. var out_count int64
  4376. for _, item := range flowGood {
  4377. out_count += item.Count
  4378. }
  4379. //如果历史数和当前数据不想等才进行退库出库
  4380. if out_count != parseIntCount {
  4381. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4382. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4383. detail := models.AutomaticReduceDetail{
  4384. WarehouseOutId: 0,
  4385. WarehouseOutOrderNumber: "",
  4386. PatientId: item.PatientId,
  4387. Ctime: time.Now().Unix(),
  4388. Mtime: 0,
  4389. Status: 1,
  4390. RecordTime: item.RecordDate,
  4391. OrgId: item.UserOrgId,
  4392. GoodId: item.ProjectId,
  4393. GoodTypeId: 0,
  4394. Count: parseIntCount,
  4395. Type: 0,
  4396. ProjectId: item.ID,
  4397. StorehouseId: 0,
  4398. }
  4399. service.CreateAutoDetail(detail)
  4400. //查询剩余库存
  4401. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4402. var sum_count int64
  4403. for _, item := range goodList {
  4404. sum_count += item.StockCount
  4405. }
  4406. //更新剩余库存
  4407. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4408. //耗材
  4409. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4410. }
  4411. }
  4412. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4413. //查询历史出库数据
  4414. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4415. var out_count int64
  4416. for _, item := range flowGood {
  4417. out_count += item.Count
  4418. }
  4419. //如果历史数和当前数据不想等才进行退库出库
  4420. if out_count != parseIntCount {
  4421. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4422. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4423. detail := models.AutomaticReduceDetail{
  4424. WarehouseOutId: 0,
  4425. WarehouseOutOrderNumber: "",
  4426. PatientId: item.PatientId,
  4427. Ctime: time.Now().Unix(),
  4428. Mtime: 0,
  4429. Status: 1,
  4430. RecordTime: item.RecordDate,
  4431. OrgId: item.UserOrgId,
  4432. GoodId: item.ProjectId,
  4433. GoodTypeId: 0,
  4434. Count: parseIntCount,
  4435. Type: 0,
  4436. ProjectId: item.ID,
  4437. StorehouseId: 0,
  4438. }
  4439. service.CreateAutoDetail(detail)
  4440. //查询剩余库存
  4441. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4442. var sum_count int64
  4443. for _, item := range goodList {
  4444. sum_count += item.StockCount
  4445. }
  4446. //更新剩余库存
  4447. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4448. //耗材
  4449. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4450. }
  4451. }
  4452. }
  4453. }
  4454. }
  4455. ////同步到自备药
  4456. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4457. if selfPrescriptionOpen.IsOpen == 1 {
  4458. timeStr := time.Now().Format("2006-01-02")
  4459. timeArr := strings.Split(timeStr, "-")
  4460. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4461. total = total + 1
  4462. operation_time := time.Now().Unix()
  4463. creater := adminInfo.AdminUser.Id
  4464. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4465. warehousing := models.XtSelfDrugWarehouse{
  4466. WarehousingOrder: warehousing_order,
  4467. OperationTime: operation_time,
  4468. OrgId: adminInfo.CurrentOrgId,
  4469. Creater: creater,
  4470. Ctime: time.Now().Unix(),
  4471. Status: 1,
  4472. WarehousingTime: recordDateTime,
  4473. Type: 0,
  4474. StorehouseId: 0,
  4475. IsCheck: 1,
  4476. PatientId: patient_id,
  4477. IsSys: 1,
  4478. }
  4479. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4480. if selfDrugWarehouse.ID == 0 {
  4481. service.AddSelfDrugWarehouse(&warehousing, tx)
  4482. }
  4483. if selfDrugWarehouse.ID > 0 {
  4484. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4485. }
  4486. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4487. fmt.Println(info)
  4488. for _, item := range hisdoctorlist {
  4489. //查询该病人的该药品是否已经入库
  4490. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4491. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4492. var in_count int64
  4493. if len(selfdruginfo) > 0 {
  4494. for _, item := range selfdruginfo {
  4495. var in_count_one int64
  4496. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4497. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4498. }
  4499. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4500. in_count_one = item.WarehousingCount
  4501. }
  4502. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4503. in_count_one = item.WarehousingCount
  4504. }
  4505. in_count += in_count_one
  4506. }
  4507. }
  4508. if selfBasedrug.IsSelfDrug == 1 {
  4509. var total_count int64
  4510. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4511. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4512. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4513. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4514. }
  4515. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4516. total_count += prescribingNumberSeven
  4517. }
  4518. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4519. total_count += prescribingNumberSeven
  4520. }
  4521. //入库
  4522. if total_count > in_count {
  4523. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4524. WarehousingOrder: warehousing_order,
  4525. WarehousingId: info.ID,
  4526. DrugId: item.DrugId,
  4527. Number: "",
  4528. ProductDate: 0,
  4529. ExpiryDate: 0,
  4530. WarehousingCount: total_count - in_count,
  4531. WarehouseingUnit: selfBasedrug.MinUnit,
  4532. Price: 0,
  4533. TotalPrice: 0,
  4534. Status: 1,
  4535. Ctime: time.Now().Unix(),
  4536. Remark: "",
  4537. OrgId: adminInfo.CurrentOrgId,
  4538. Type: 0,
  4539. Manufacturer: selfBasedrug.Manufacturer,
  4540. Dealer: selfBasedrug.Dealer,
  4541. StockMaxNumber: total_count - in_count,
  4542. RetailTotalPrice: 0,
  4543. BatchNumber: "",
  4544. MaxUnit: selfBasedrug.MinUnit,
  4545. MinUnit: selfBasedrug.MinUnit,
  4546. RetailPrice: 0,
  4547. StorehouseId: 0,
  4548. IsCheck: 1,
  4549. StockMinNumber: 0,
  4550. PatientId: patient_id,
  4551. IsSys: 1,
  4552. RecordDate: item.RecordDate,
  4553. AdviceId: item.ID,
  4554. }
  4555. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4556. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4557. Creator := adminInfo.AdminUser.Id
  4558. //查询默认仓库剩余多少库存
  4559. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4560. var sum_count int64
  4561. for _, it := range list {
  4562. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4563. if it.MaxUnit == baseDrug.MaxUnit {
  4564. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4565. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4566. }
  4567. sum_count += it.StockMaxNumber + it.StockMinNumber
  4568. }
  4569. flow := &models.XtSelfDrugFlow{
  4570. WarehousingId: info.ID,
  4571. DrugId: item.DrugId,
  4572. Number: "",
  4573. BatchNumber: "",
  4574. Count: total_count - in_count,
  4575. UserOrgId: adminInfo.CurrentOrgId,
  4576. PatientId: item.PatientId,
  4577. SystemTime: time.Now().Unix(),
  4578. ConsumableType: 1,
  4579. IsSys: 1,
  4580. WarehousingOrder: warehousing_order,
  4581. WarehouseOutId: 0,
  4582. WarehouseOutOrderNumber: "",
  4583. IsEdit: 0,
  4584. CancelStockId: 0,
  4585. CancelOrderNumber: "",
  4586. Manufacturer: selfBasedrug.Manufacturer,
  4587. Dealer: selfBasedrug.Dealer,
  4588. Creator: Creator,
  4589. UpdateCreator: Creator,
  4590. Status: 1,
  4591. Ctime: item.AdviceDate,
  4592. Mtime: 0,
  4593. Price: item.Price,
  4594. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4595. WarehouseOutDetailId: 0,
  4596. CancelOutDetailId: 0,
  4597. ExpireDate: 0,
  4598. ProductDate: 0,
  4599. MaxUnit: selfBasedrug.MinUnit,
  4600. MinUnit: selfBasedrug.MinUnit,
  4601. StorehouseId: 0,
  4602. OverCount: sum_count,
  4603. OperateTime: time.Now().Unix(),
  4604. AdviceId: item.ID,
  4605. }
  4606. service.CreateSelfDrugFlow(flow, tx)
  4607. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4608. var total_count int64 // 入库总数量
  4609. var over_count int64 //剩余库存
  4610. for _, it := range drugInfolist {
  4611. if it.MaxUnit == selfBasedrug.MaxUnit {
  4612. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4613. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4614. }
  4615. }
  4616. for _, it := range drugInfolist {
  4617. total_count += it.WarehousingCount
  4618. over_count += it.StockMaxNumber + it.StockMinNumber
  4619. }
  4620. //查询该仓库是否有默认数据
  4621. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4622. if selfDrugStock.ID == 0 {
  4623. drugStock := models.XtSelfDrugStockCount{
  4624. UserOrgId: item.UserOrgId,
  4625. PatientId: item.PatientId,
  4626. SumInCount: total_count,
  4627. SumOutCount: 0,
  4628. SumCancelCount: 0,
  4629. DrugId: item.DrugId,
  4630. Ctime: time.Now().Unix(),
  4631. Mtime: 0,
  4632. Status: 1,
  4633. FlushCount: over_count,
  4634. SumActOutCount: 0,
  4635. }
  4636. service.CreateSelfDrugStockSum(drugStock, tx)
  4637. }
  4638. if selfDrugStock.ID > 0 {
  4639. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4640. }
  4641. }
  4642. //查询这个单据的出库数量
  4643. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4644. var his_out_count int64
  4645. for _, item := range drugFlowList {
  4646. his_out_count += item.Count
  4647. }
  4648. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4649. if (total_count + his_out_count) <= in_count {
  4650. // 出库
  4651. if total_count < in_count {
  4652. var cha_count int64
  4653. cha_count = in_count - total_count
  4654. var stock_number int64 = 0
  4655. //查询库存是否充足
  4656. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4657. // 将该批次的剩余库存数量转换为拆零数量
  4658. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4659. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4660. }
  4661. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4662. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4663. }
  4664. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4665. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4666. }
  4667. if stock_number >= cha_count {
  4668. var maxNumber int64 = 0
  4669. var minNumber int64 = 0
  4670. maxNumber = cha_count / selfBasedrug.MinNumber
  4671. minNumber = cha_count % selfBasedrug.MinNumber
  4672. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4673. minNumber = maxNumber
  4674. }
  4675. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4676. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4678. return
  4679. }
  4680. }
  4681. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4682. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4683. }
  4684. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4685. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4686. }
  4687. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4688. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4689. }
  4690. if warehouse.StockMaxNumber < 0 {
  4691. warehouse.StockMaxNumber = 0
  4692. }
  4693. if warehouse.StockMinNumber < 0 {
  4694. warehouse.StockMinNumber = 0
  4695. }
  4696. warehouse.Mtime = time.Now().Unix()
  4697. if warehouse.StockMinNumber < minNumber {
  4698. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4699. if warehouse.MaxUnit != warehouse.MinUnit {
  4700. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4701. }
  4702. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4703. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4704. }
  4705. } else {
  4706. if minNumber > 0 {
  4707. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4708. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4709. }
  4710. }
  4711. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4712. if warehouse.StockMinNumber > 0 {
  4713. if warehouse.StockMinNumber-cha_count >= 0 {
  4714. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4715. }
  4716. }
  4717. }
  4718. }
  4719. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4720. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4721. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4722. }
  4723. }
  4724. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4725. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4727. return
  4728. }
  4729. }
  4730. if warehouse.StockMinNumber <= 0 {
  4731. warehouse.StockMinNumber = 0
  4732. }
  4733. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4734. //查询该药品剩余库存
  4735. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4736. var over_count int64
  4737. for _, its := range infolist {
  4738. if its.MaxUnit == selfBasedrug.MaxUnit {
  4739. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4740. }
  4741. over_count += its.StockMaxNumber + its.StockMinNumber
  4742. }
  4743. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4744. drugflow := models.XtSelfDrugFlow{
  4745. WarehouseOutId: 0,
  4746. WarehouseOutOrderNumber: warehousing_order,
  4747. WarehousingOrder: warehousing_order,
  4748. DrugId: item.DrugId,
  4749. Number: warehouse.Number,
  4750. ProductDate: warehouse.ProductDate,
  4751. ExpireDate: warehouse.ExpiryDate,
  4752. Count: cha_count,
  4753. Price: warehouse.RetailPrice,
  4754. Status: 1,
  4755. Ctime: item.AdviceDate,
  4756. Mtime: time.Now().Unix(),
  4757. UserOrgId: item.UserOrgId,
  4758. Manufacturer: warehouse.Manufacturer,
  4759. Dealer: warehouse.Dealer,
  4760. BatchNumber: warehouse.BatchNumber,
  4761. MaxUnit: selfBasedrug.MinUnit,
  4762. ConsumableType: 20,
  4763. IsEdit: 1,
  4764. Creator: 0,
  4765. IsSys: 3,
  4766. WarehouseOutDetailId: drugWareInfo.ID,
  4767. AdviceId: item.ID,
  4768. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4769. StorehouseId: 0,
  4770. AdminUserId: creater,
  4771. LastPrice: warehouse.Price,
  4772. StockCount: "",
  4773. WarehousingDetailId: 0,
  4774. OverCount: over_count,
  4775. RetailPrice: item.Price, //手动出库出库价格
  4776. WarehousingId: warehouse.ID,
  4777. SystemTime: item.AdviceDate,
  4778. PatientId: item.PatientId,
  4779. Remark: "保存处方入库数据差",
  4780. OperateTime: time.Now().Unix(),
  4781. }
  4782. if warehouse.RetailPrice == 0 {
  4783. drugflow.Price = item.Price
  4784. }
  4785. service.CreateSelfDrugFlowOne(drugflow, tx)
  4786. var out_count int64
  4787. out_count = in_count - total_count
  4788. //
  4789. //fmt.Println("in_count------------------", in_count)
  4790. //fmt.Println("total_count------------------", total_count)
  4791. //添加出库数量
  4792. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4793. //查询剩余库存
  4794. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4795. var sum_count int64
  4796. for _, its := range stockInfo {
  4797. if its.MaxUnit == selfBasedrug.MaxUnit {
  4798. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4799. }
  4800. sum_count += its.StockMaxNumber + its.StockMinNumber
  4801. }
  4802. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4803. } else {
  4804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4805. return
  4806. }
  4807. }
  4808. }
  4809. }
  4810. }
  4811. }
  4812. }
  4813. tx.Commit()
  4814. if err == nil {
  4815. c.ServeSuccessJSON(map[string]interface{}{
  4816. "msg": "保存成功",
  4817. })
  4818. return
  4819. } else {
  4820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4821. return
  4822. }
  4823. }
  4824. }
  4825. //func (c *HisApiController) EditHisPrescription() {
  4826. // record_date := c.GetString("record_date")
  4827. // patient_id, _ := c.GetInt64("patient_id")
  4828. // reg_type, _ := c.GetInt64("reg_type")
  4829. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4830. // diagnose := c.GetString("diagnose")
  4831. // sick_type, _ := c.GetInt64("sick_type")
  4832. // sick_history := c.GetString("sick_history")
  4833. // doctor_id, _ := c.GetInt64("doctor", 0)
  4834. // department, _ := c.GetInt64("department", 0)
  4835. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4836. // p_type, _ := c.GetInt64("p_type")
  4837. //
  4838. // dataBody := make(map[string]interface{}, 0)
  4839. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4840. // if err != nil {
  4841. // utils.ErrorLog(err.Error())
  4842. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4843. // return
  4844. // }
  4845. //
  4846. // timeLayout := "2006-01-02"
  4847. // loc, _ := time.LoadLocation("Local")
  4848. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4849. // if err != nil {
  4850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4851. // return
  4852. // }
  4853. // adminInfo := c.GetAdminUserInfo()
  4854. // recordDateTime := theTime.Unix()
  4855. //
  4856. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4857. //
  4858. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4859. // var hpInfo models.HisPrescriptionInfo
  4860. // if info.ID == 0 {
  4861. // var randNum int
  4862. // randNum = rand.Intn(10000) + 1000
  4863. // timestamp := time.Now().Unix()
  4864. // tempTime := time.Unix(timestamp, 0)
  4865. // timeFormat := tempTime.Format("20060102150405")
  4866. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4867. //
  4868. // hpInfo = models.HisPrescriptionInfo{
  4869. // UserOrgId: adminInfo.CurrentOrgId,
  4870. // RecordDate: theTime.Unix(),
  4871. // PatientId: patient_id,
  4872. // Status: 1,
  4873. // Ctime: time.Now().Unix(),
  4874. // Mtime: time.Now().Unix(),
  4875. // Creator: adminInfo.AdminUser.Id,
  4876. // Modifier: adminInfo.AdminUser.Id,
  4877. // Diagnosis: diagnose,
  4878. // SickHistory: sick_history,
  4879. // Departments: department,
  4880. // RegisterType: reg_type,
  4881. // PrescriptionNumber: p_number,
  4882. // PrescriptionStatus: 1,
  4883. // Doctor: role.UserName,
  4884. // DoctorId: doctor_id,
  4885. // SickType: sick_type,
  4886. // PType: p_type,
  4887. // }
  4888. // service.SavePatientPrescriptionInfo(hpInfo)
  4889. //
  4890. // } else {
  4891. // hpInfo = models.HisPrescriptionInfo{
  4892. // ID: info.ID,
  4893. // UserOrgId: adminInfo.CurrentOrgId,
  4894. // RecordDate: info.RecordDate,
  4895. // PatientId: info.PatientId,
  4896. // Status: 1,
  4897. // Ctime: info.Ctime,
  4898. // Mtime: time.Now().Unix(),
  4899. // Creator: info.Creator,
  4900. // Modifier: adminInfo.AdminUser.Id,
  4901. // Diagnosis: diagnose,
  4902. // SickHistory: sick_history,
  4903. // Departments: department,
  4904. // RegisterType: reg_type,
  4905. // PrescriptionNumber: info.PrescriptionNumber,
  4906. // Doctor: role.UserName,
  4907. // PrescriptionStatus: info.PrescriptionStatus,
  4908. // DoctorId: doctor_id,
  4909. // SickType: sick_type,
  4910. // PType: info.PType,
  4911. // }
  4912. // service.SavePatientPrescriptionInfo(hpInfo)
  4913. // }
  4914. //
  4915. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4916. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4917. //
  4918. // if len(prescriptions) > 0 {
  4919. // for _, item := range prescriptions {
  4920. // items := item.(map[string]interface{})
  4921. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4922. // utils.ErrorLog("id")
  4923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4924. // return
  4925. // }
  4926. // id := int64(items["id"].(float64))
  4927. //
  4928. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4929. // utils.ErrorLog("type")
  4930. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. // return
  4932. // }
  4933. // types := int64(items["type"].(float64))
  4934. //
  4935. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4936. // utils.ErrorLog("med_type")
  4937. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4938. // return
  4939. // }
  4940. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4941. //
  4942. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4943. //
  4944. // ctime := time.Now().Unix()
  4945. //
  4946. // prescription := &models.HisPrescription{
  4947. // ID: id,
  4948. // PatientId: patient_id,
  4949. // UserOrgId: adminInfo.CurrentOrgId,
  4950. // RecordDate: recordDateTime,
  4951. // Ctime: ctime,
  4952. // Mtime: ctime,
  4953. // Type: types,
  4954. // Modifier: adminInfo.AdminUser.Id,
  4955. // Creator: adminInfo.AdminUser.Id,
  4956. // Status: 1,
  4957. // Doctor: role.UserName,
  4958. // HisPatientId: his_patient_id,
  4959. // OrderStatus: 1,
  4960. // BatchNumber: "",
  4961. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4962. // PType: hpInfo.PType,
  4963. // MedType: med_type,
  4964. // }
  4965. //
  4966. // if historyPrescription.ID > 0 {
  4967. // prescription.PreTime = historyPrescription.PreTime
  4968. //
  4969. // }
  4970. //
  4971. // service.SaveHisPrescription(prescription)
  4972. //
  4973. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4974. // advices := items["advices"].([]interface{})
  4975. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4976. // groupNo := int64(0)
  4977. // ctime := time.Now().Unix()
  4978. // mtime := ctime
  4979. // if len(advices) > 0 {
  4980. // for _, advice := range advices {
  4981. // var s models.HisDoctorAdviceInfo
  4982. // s.PrescriptionId = prescription.ID
  4983. // s.AdviceType = 2
  4984. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4985. // s.StopState = 2
  4986. // s.ExecutionState = 2
  4987. // s.AdviceDate = recordDateTime
  4988. // s.Status = 1
  4989. // s.UserOrgId = adminInfo.CurrentOrgId
  4990. // s.RecordDate = recordDateTime
  4991. // s.StartTime = prescription.PreTime
  4992. // s.Groupno = groupNo
  4993. // s.CreatedTime = ctime
  4994. // s.UpdatedTime = mtime
  4995. // s.PatientId = patient_id
  4996. // s.HisPatientId = his_patient_id
  4997. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4998. // if errcode > 0 {
  4999. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5000. // return
  5001. // }
  5002. //
  5003. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5004. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5005. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5006. // if s.Price == 0 {
  5007. // s.Price = lastWarehouse.RetailPrice
  5008. // }
  5009. // }
  5010. //
  5011. // service.CreateHisDoctorAdvice(&s)
  5012. // //记录日志
  5013. // byterequest, _ := json.Marshal(s)
  5014. // adviceLog := models.XtDoctorAdviceLog{
  5015. // UserOrgId: s.UserOrgId,
  5016. // PatientId: s.PatientId,
  5017. // AdminUserId: adminInfo.AdminUser.Id,
  5018. // Module: 1,
  5019. // ErrLog: string(byterequest),
  5020. // Status: 1,
  5021. // Ctime: time.Now().Unix(),
  5022. // Mtime: 0,
  5023. // Source: "电脑端his医嘱修改",
  5024. // RecordDate: s.AdviceDate,
  5025. // }
  5026. // service.CreateDoctorAdviceLog(adviceLog)
  5027. // redis := service.RedisClient()
  5028. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5029. // redis.Set(key, "", time.Second)
  5030. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5031. // fmt.Println("keyOne", keyOne)
  5032. // redis.Set(keyOne, "", time.Second)
  5033. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5034. // redis.Set(keySeven, "", time.Second)
  5035. // redis.Close()
  5036. //
  5037. // }
  5038. // }
  5039. // }
  5040. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5041. // projects := items["project"].([]interface{})
  5042. // if len(projects) > 0 {
  5043. // for _, project := range projects {
  5044. // var p models.HisPrescriptionProject
  5045. // p.PrescriptionId = prescription.ID
  5046. // p.Ctime = time.Now().Unix()
  5047. // p.Mtime = time.Now().Unix()
  5048. // p.PatientId = patient_id
  5049. // p.RecordDate = recordDateTime
  5050. // p.UserOrgId = adminInfo.CurrentOrgId
  5051. // p.HisPatientId = his_patient_id
  5052. // p.Status = 1
  5053. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5054. // if errcode > 0 {
  5055. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5056. // return
  5057. // }
  5058. // service.CreateHisProjectTwo(&p)
  5059. //
  5060. // //记录日志
  5061. // byterequest, _ := json.Marshal(p)
  5062. // adviceLog := models.XtDoctorAdviceLog{
  5063. // UserOrgId: p.UserOrgId,
  5064. // PatientId: p.PatientId,
  5065. // AdminUserId: adminInfo.AdminUser.Id,
  5066. // Module: 1,
  5067. // ErrLog: string(byterequest),
  5068. // Status: 1,
  5069. // Ctime: time.Now().Unix(),
  5070. // Mtime: 0,
  5071. // Source: "电脑端his项目修改",
  5072. // RecordDate: p.RecordDate,
  5073. // }
  5074. // service.CreateDoctorAdviceLog(adviceLog)
  5075. // }
  5076. // }
  5077. // }
  5078. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5079. // addition := items["addition"].([]interface{})
  5080. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5081. // ctime := time.Now().Unix()
  5082. // mtime := ctime
  5083. // if len(addition) > 0 {
  5084. // for _, item := range addition {
  5085. // var s models.HisAdditionalCharge
  5086. // s.PrescriptionId = prescription.ID
  5087. // s.Status = 1
  5088. // s.UserOrgId = adminInfo.CurrentOrgId
  5089. // s.RecordDate = recordDateTime
  5090. // s.CreatedTime = ctime
  5091. // s.UpdatedTime = mtime
  5092. // s.PatientId = patient_id
  5093. // s.HisPatientId = his_patient_id
  5094. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5095. // if errcode > 0 {
  5096. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5097. // return
  5098. // }
  5099. // service.CreateAdditionalCharge(&s)
  5100. // }
  5101. // }
  5102. // }
  5103. //
  5104. // }
  5105. // }
  5106. // }
  5107. // if err == nil {
  5108. // c.ServeSuccessJSON(map[string]interface{}{
  5109. // "msg": "保存成功",
  5110. // })
  5111. // return
  5112. //
  5113. // } else {
  5114. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5115. // return
  5116. // }
  5117. //}
  5118. func (c *HisApiController) DeletePrescription() {
  5119. prescription_id, _ := c.GetInt64("id")
  5120. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5121. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5122. ////同步到自备药
  5123. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5124. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5125. if selfPrescriptionOpen.IsOpen == 1 {
  5126. // 在函数结束时处理事务回滚
  5127. db := service.XTWriteDB()
  5128. tx := db.Begin()
  5129. defer func() {
  5130. if r := recover(); r != nil {
  5131. tx.Rollback()
  5132. } else {
  5133. tx.Commit()
  5134. }
  5135. }()
  5136. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5137. for _, item := range advicesList {
  5138. timeStr := time.Now().Format("2006-01-02")
  5139. timeArr := strings.Split(timeStr, "-")
  5140. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5141. total = total + 1
  5142. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5143. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5144. number = number + total
  5145. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5146. operation_time := time.Now().Unix()
  5147. creater := c.GetAdminUserInfo().AdminUser.Id
  5148. //创建一个出库单
  5149. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5150. WarehouseOutOrderNumber: warehousing_out_order,
  5151. OperationTime: operation_time,
  5152. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5153. Creater: creater,
  5154. Ctime: time.Now().Unix(),
  5155. Status: 1,
  5156. WarehouseOutTime: item.AdviceDate,
  5157. Type: 0,
  5158. PatientId: item.PatientId,
  5159. IsCheck: 1,
  5160. }
  5161. //查询今日是否有出库数据
  5162. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5163. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5164. if lastWarehouseOut.ID == 0 {
  5165. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5166. }
  5167. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5168. var total_count int64
  5169. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5170. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5171. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5172. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5173. }
  5174. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5175. total_count += prescribingNumberSeven
  5176. }
  5177. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5178. total_count += prescribingNumberSeven
  5179. }
  5180. //出库
  5181. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5182. WarehouseOutOrderNumber: warehousing_out_order,
  5183. WarehouseOutId: lastWarehouseOut.ID,
  5184. DrugId: item.DrugId,
  5185. Count: total_count,
  5186. Price: 0,
  5187. TotalPrice: 0,
  5188. Status: 1,
  5189. Ctime: item.AdviceDate,
  5190. Mtime: item.AdviceDate,
  5191. Remark: "",
  5192. OrgId: item.UserOrgId,
  5193. Type: 0,
  5194. Manufacturer: selfBasedrug.Manufacturer,
  5195. Dealer: selfBasedrug.Dealer,
  5196. RetailPrice: 0,
  5197. RetailTotalPrice: 0,
  5198. CountUnit: selfBasedrug.MinUnit,
  5199. ExpiryDate: 0,
  5200. ProductDate: 0,
  5201. Number: "",
  5202. BatchNumber: "",
  5203. IsSys: 1,
  5204. WarehouseInfoId: 0,
  5205. AdminUserId: 0,
  5206. StockCount: "",
  5207. IsCheck: 1,
  5208. SysRecordTime: item.AdviceDate,
  5209. PatientId: item.PatientId,
  5210. ClassType: "",
  5211. AdviceId: item.ID,
  5212. }
  5213. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5214. }
  5215. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5216. for _, it := range warehousingOutInfo {
  5217. //查询今日是否有出库数据
  5218. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5219. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5220. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5221. //出库逻辑
  5222. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5223. //查询剩余库存
  5224. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5225. var sum_count int64
  5226. for _, its := range stockInfo {
  5227. if its.MaxUnit == medical.MaxUnit {
  5228. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5229. }
  5230. sum_count += its.StockMaxNumber + its.StockMinNumber
  5231. }
  5232. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5233. }
  5234. }
  5235. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5236. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5237. //耗材保存处方出库
  5238. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5239. //已收费和已发药限制逻辑
  5240. isCharge := false
  5241. isMedicine := false
  5242. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5243. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5244. if new_prescription.IsMedicine == 1 {
  5245. isMedicine = true
  5246. }
  5247. for _, item := range new_prescriptions {
  5248. if item.OrderStatus == 4 {
  5249. isCharge = true
  5250. }
  5251. }
  5252. if p_err != nil {
  5253. if new_prescription.ID > 0 {
  5254. if new_prescription.OrderStatus == 2 {
  5255. isCharge = true
  5256. }
  5257. }
  5258. }
  5259. for _, item := range advices {
  5260. if item.IsMedicine == 1 {
  5261. isMedicine = true
  5262. }
  5263. }
  5264. if isCharge {
  5265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5266. return
  5267. }
  5268. if isMedicine {
  5269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5270. return
  5271. }
  5272. //已收费和已发药限制逻辑
  5273. if len(projects) > 0 {
  5274. for _, item := range projects {
  5275. service.DeletePrintInfo(item.ID) //删除打印信息
  5276. if goodOutConfig.IsOpen != 1 {
  5277. if stockConfig.IsOpen == 1 {
  5278. if item.Type == 3 && item.IsOut == 1 {
  5279. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5280. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5281. good.Total = good.Total + f_count
  5282. service.UpdateGoodInfo(&good)
  5283. operation_time := time.Now().Unix()
  5284. creater := c.GetAdminUserInfo().AdminUser.Id
  5285. //创建退库单
  5286. timeStr := time.Now().Format("2006-01-02")
  5287. timeArr := strings.Split(timeStr, "-")
  5288. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5289. total = total + 1
  5290. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5291. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5292. cancelStock := models.CancelStock{
  5293. OrderNumber: orderNumber,
  5294. OperaTime: operation_time,
  5295. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5296. Creater: creater,
  5297. Ctime: time.Now().Unix(),
  5298. Status: 1,
  5299. ReturnTime: item.RecordDate,
  5300. Type: 1,
  5301. StorehouseId: houseConfig.StorehouseOutInfo,
  5302. IsCheck: 1,
  5303. }
  5304. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5305. if msgerrkonde == gorm.ErrRecordNotFound {
  5306. service.AddSigleCancelStock(&cancelStock)
  5307. }
  5308. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5309. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5310. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5311. //查询该耗材是否出库
  5312. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5313. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5314. deaerler, _ := service.GetDealerById(info.Dealer)
  5315. var total_count int64
  5316. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5317. total_count += count
  5318. if info.ID > 0 {
  5319. if info.Count >= total_count {
  5320. //回退库存
  5321. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5322. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5323. var flush_count int64
  5324. for _, it := range goodList {
  5325. flush_count += it.StockCount
  5326. }
  5327. cancelStockInfo := models.CancelStockInfo{
  5328. GoodId: item.ProjectId,
  5329. CancelStockId: cancel.ID,
  5330. GoodTypeId: good.GoodTypeId,
  5331. Count: prescribingNumber,
  5332. Price: info.Price,
  5333. Total: 0,
  5334. ProductDate: info.ProductDate,
  5335. ExpiryDate: info.ExpiryDate,
  5336. Ctime: time.Now().Unix(),
  5337. Status: 1,
  5338. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5339. OrderNumber: cancel.OrderNumber,
  5340. Type: 0,
  5341. Dealer: deaerler.DealerName,
  5342. Manufacturer: manufacturer.ManufacturerName,
  5343. Number: info.Number,
  5344. RegisterAccount: "",
  5345. Remark: "",
  5346. WarehouseInfoId: info.WarehouseInfotId,
  5347. PatientId: info.PatientId,
  5348. RecordDate: info.SysRecordTime,
  5349. StorehouseId: houseConfig.StorehouseOutInfo,
  5350. IsCheck: 1,
  5351. }
  5352. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5353. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5354. flow := models.VmStockFlow{
  5355. WarehousingId: info.WarehouseInfotId,
  5356. GoodId: item.ProjectId,
  5357. Number: info.Number,
  5358. LicenseNumber: info.LicenseNumber,
  5359. Count: prescribingNumber,
  5360. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5361. PatientId: item.PatientId,
  5362. SystemTime: info.SysRecordTime,
  5363. ConsumableType: 7,
  5364. IsSys: 0,
  5365. WarehousingOrder: "",
  5366. WarehouseOutId: info.WarehouseOutId,
  5367. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5368. IsEdit: 0,
  5369. CancelStockId: cancel.ID,
  5370. CancelOrderNumber: cancel.OrderNumber,
  5371. Manufacturer: manufacturer.ID,
  5372. Dealer: 0,
  5373. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5374. UpdateCreator: 0,
  5375. Status: 1,
  5376. Ctime: time.Now().Unix(),
  5377. Mtime: 0,
  5378. Price: info.Price,
  5379. WarehousingDetailId: info.WarehouseInfotId,
  5380. WarehouseOutDetailId: info.ID,
  5381. CancelOutDetailId: cancelInfo.ID,
  5382. ProductDate: info.ProductDate,
  5383. ExpireDate: info.ExpiryDate,
  5384. StorehouseId: houseConfig.StorehouseOutInfo,
  5385. OverCount: flush_count,
  5386. OperateTime: time.Now().Unix(),
  5387. }
  5388. service.CreateStockFlowOne(flow)
  5389. //退库数量增加
  5390. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5391. //出库数量减少
  5392. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5393. }
  5394. if info.Count < total_count {
  5395. //回退库存
  5396. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5397. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5398. var flush_count int64
  5399. for _, it := range goodList {
  5400. flush_count += it.StockCount
  5401. }
  5402. cancelStockInfo := models.CancelStockInfo{
  5403. GoodId: item.ProjectId,
  5404. CancelStockId: cancel.ID,
  5405. GoodTypeId: good.GoodTypeId,
  5406. Count: info.Count,
  5407. Price: info.Price,
  5408. Total: 0,
  5409. ProductDate: info.ProductDate,
  5410. ExpiryDate: info.ExpiryDate,
  5411. Ctime: time.Now().Unix(),
  5412. Status: 1,
  5413. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5414. OrderNumber: cancel.OrderNumber,
  5415. Type: 0,
  5416. Dealer: deaerler.DealerName,
  5417. Manufacturer: manufacturer.ManufacturerName,
  5418. Number: info.Number,
  5419. RegisterAccount: "",
  5420. Remark: "",
  5421. WarehouseInfoId: info.WarehouseInfotId,
  5422. PatientId: info.PatientId,
  5423. RecordDate: info.SysRecordTime,
  5424. StorehouseId: houseConfig.StorehouseOutInfo,
  5425. IsCheck: 1,
  5426. }
  5427. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5428. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5429. flow := models.VmStockFlow{
  5430. WarehousingId: info.WarehouseInfotId,
  5431. GoodId: item.ProjectId,
  5432. Number: info.Number,
  5433. LicenseNumber: info.LicenseNumber,
  5434. Count: info.Count,
  5435. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5436. PatientId: item.PatientId,
  5437. SystemTime: info.SysRecordTime,
  5438. ConsumableType: 7,
  5439. IsSys: 0,
  5440. WarehousingOrder: "",
  5441. WarehouseOutId: info.WarehouseOutId,
  5442. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5443. IsEdit: 0,
  5444. CancelStockId: cancel.ID,
  5445. CancelOrderNumber: cancel.OrderNumber,
  5446. Manufacturer: manufacturer.ID,
  5447. Dealer: 0,
  5448. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5449. UpdateCreator: 0,
  5450. Status: 1,
  5451. Ctime: time.Now().Unix(),
  5452. Mtime: 0,
  5453. Price: info.Price,
  5454. WarehousingDetailId: info.WarehouseInfotId,
  5455. WarehouseOutDetailId: info.ID,
  5456. CancelOutDetailId: cancelInfo.ID,
  5457. ProductDate: info.ProductDate,
  5458. ExpireDate: info.ExpiryDate,
  5459. StorehouseId: houseConfig.StorehouseOutInfo,
  5460. OverCount: flush_count,
  5461. OperateTime: time.Now().Unix(),
  5462. }
  5463. service.CreateStockFlowOne(flow)
  5464. //退库数量增加
  5465. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5466. //出库数量减少
  5467. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5468. }
  5469. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5470. var flush_count int64
  5471. for _, it := range goodList {
  5472. flush_count += it.StockCount
  5473. }
  5474. //查询已出库数量
  5475. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5476. if prescribingNumber < dialysisInfo.Count {
  5477. //改变数量
  5478. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5479. }
  5480. if prescribingNumber >= dialysisInfo.Count {
  5481. //删除出库表
  5482. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5483. }
  5484. //更新库存
  5485. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5486. //更新基础库库存
  5487. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5488. }
  5489. }
  5490. }
  5491. }
  5492. //保存耗材出库
  5493. if goodOutConfig.IsOpen == 1 {
  5494. if item.Type == 3 {
  5495. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5496. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5497. good.Total = good.Total + f_count
  5498. service.UpdateGoodInfo(&good)
  5499. operation_time := time.Now().Unix()
  5500. creater := c.GetAdminUserInfo().AdminUser.Id
  5501. //创建退库单
  5502. timeStr := time.Now().Format("2006-01-02")
  5503. timeArr := strings.Split(timeStr, "-")
  5504. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5505. total = total + 1
  5506. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5507. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5508. cancelStock := models.CancelStock{
  5509. OrderNumber: orderNumber,
  5510. OperaTime: operation_time,
  5511. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5512. Creater: creater,
  5513. Ctime: time.Now().Unix(),
  5514. Status: 1,
  5515. ReturnTime: item.RecordDate,
  5516. Type: 1,
  5517. StorehouseId: houseConfig.StorehouseOutInfo,
  5518. IsCheck: 1,
  5519. }
  5520. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5521. if msgerrkonde == gorm.ErrRecordNotFound {
  5522. service.AddSigleCancelStock(&cancelStock)
  5523. }
  5524. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5525. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5526. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5527. //查询该耗材是否出库
  5528. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5529. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5530. deaerler, _ := service.GetDealerById(info.Dealer)
  5531. var total_count int64
  5532. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5533. total_count += count
  5534. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5535. var flush_count int64
  5536. for _, it := range goodList {
  5537. flush_count += it.StockCount
  5538. }
  5539. fmt.Println("历史出库数据", info.Count)
  5540. fmt.Println("出库数量", total_count)
  5541. if info.ID > 0 {
  5542. cancelStockInfo := models.CancelStockInfo{
  5543. GoodId: item.ProjectId,
  5544. CancelStockId: cancel.ID,
  5545. GoodTypeId: good.GoodTypeId,
  5546. Count: prescribingNumber,
  5547. Price: info.Price,
  5548. Total: 0,
  5549. ProductDate: info.ProductDate,
  5550. ExpiryDate: info.ExpiryDate,
  5551. Ctime: time.Now().Unix(),
  5552. Status: 1,
  5553. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5554. OrderNumber: cancel.OrderNumber,
  5555. Type: 0,
  5556. Dealer: deaerler.DealerName,
  5557. Manufacturer: manufacturer.ManufacturerName,
  5558. Number: info.Number,
  5559. RegisterAccount: "",
  5560. Remark: "",
  5561. WarehouseInfoId: info.WarehouseInfotId,
  5562. PatientId: info.PatientId,
  5563. RecordDate: info.SysRecordTime,
  5564. StorehouseId: houseConfig.StorehouseOutInfo,
  5565. IsCheck: 1,
  5566. }
  5567. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5568. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5569. //查询出库数量
  5570. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5571. //出库数据 大于 退库数量
  5572. if len(list) > 0 {
  5573. for _, it := range list {
  5574. //回退库存
  5575. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5576. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5577. var flush_count_one int64
  5578. for _, it := range goodList {
  5579. flush_count_one += it.StockCount
  5580. }
  5581. //查询该批次是否有退库数据
  5582. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5583. creater := c.GetAdminUserInfo().AdminUser.Id
  5584. flow := models.VmStockFlow{
  5585. WarehousingId: it.WarehouseInfotId,
  5586. GoodId: it.GoodId,
  5587. Number: it.Number,
  5588. LicenseNumber: it.LicenseNumber,
  5589. Count: it.Count,
  5590. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5591. PatientId: it.PatientId,
  5592. SystemTime: it.SysRecordTime,
  5593. ConsumableType: 7,
  5594. IsSys: 0,
  5595. WarehousingOrder: "",
  5596. WarehouseOutId: it.WarehouseOutId,
  5597. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5598. IsEdit: 0,
  5599. CancelStockId: cancel.ID,
  5600. CancelOrderNumber: cancel.OrderNumber,
  5601. Manufacturer: manufacturer.ID,
  5602. Dealer: 0,
  5603. Creator: creater,
  5604. UpdateCreator: 0,
  5605. Status: 1,
  5606. Ctime: time.Now().Unix(),
  5607. Mtime: 0,
  5608. Price: it.Price,
  5609. WarehousingDetailId: it.WarehouseInfotId,
  5610. WarehouseOutDetailId: it.ID,
  5611. CancelOutDetailId: cancelInfo.ID,
  5612. ProductDate: it.ProductDate,
  5613. ExpireDate: it.ExpiryDate,
  5614. StorehouseId: houseConfig.StorehouseOutInfo,
  5615. OverCount: flush_count_one,
  5616. }
  5617. service.CreateStockFlowOne(flow)
  5618. //if flow.ID > 0 {
  5619. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5620. //}
  5621. }
  5622. }
  5623. //flow := models.VmStockFlow{
  5624. // WarehousingId: info.WarehouseInfotId,
  5625. // GoodId: item.ProjectId,
  5626. // Number: info.Number,
  5627. // LicenseNumber: info.LicenseNumber,
  5628. // Count: prescribingNumber,
  5629. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5630. // PatientId: item.PatientId,
  5631. // SystemTime: info.SysRecordTime,
  5632. // ConsumableType: 7,
  5633. // IsSys: 0,
  5634. // WarehousingOrder: "",
  5635. // WarehouseOutId: info.WarehouseOutId,
  5636. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5637. // IsEdit: 0,
  5638. // CancelStockId: cancel.ID,
  5639. // CancelOrderNumber: cancel.OrderNumber,
  5640. // Manufacturer: manufacturer.ID,
  5641. // Dealer: 0,
  5642. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5643. // UpdateCreator: 0,
  5644. // Status: 1,
  5645. // Ctime: time.Now().Unix(),
  5646. // Mtime: 0,
  5647. // Price: info.Price,
  5648. // WarehousingDetailId: info.WarehouseInfotId,
  5649. // WarehouseOutDetailId: info.ID,
  5650. // CancelOutDetailId: cancelInfo.ID,
  5651. // ProductDate: info.ProductDate,
  5652. // ExpireDate: info.ExpiryDate,
  5653. // StorehouseId: houseConfig.StorehouseOutInfo,
  5654. // OverCount: flush_count,
  5655. //}
  5656. //service.CreateStockFlowOne(flow)
  5657. //退库数量增加
  5658. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5659. //出库数量减少
  5660. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5661. //查询已出库数量
  5662. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5663. if prescribingNumber < dialysisInfo.Count {
  5664. //改变数量
  5665. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5666. }
  5667. if prescribingNumber >= dialysisInfo.Count {
  5668. //删除出库表
  5669. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5670. }
  5671. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5672. var flush_count_one int64
  5673. for _, it := range goodList {
  5674. flush_count_one += it.StockCount
  5675. }
  5676. //更新库存
  5677. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5678. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5679. //更新基础库库存
  5680. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5681. }
  5682. }
  5683. }
  5684. }
  5685. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5686. fmt.Println(err)
  5687. }
  5688. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5689. fmt.Println(err)
  5690. if len(advices) > 0 {
  5691. for _, item := range advices {
  5692. redis := service.RedisClient()
  5693. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5694. redis.Set(keyFive, "", time.Second)
  5695. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5696. redis.Set(keyOne, "", time.Second)
  5697. redis.Close()
  5698. }
  5699. }
  5700. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5701. if len(advices) > 0 {
  5702. for _, item := range advices {
  5703. creater := c.GetAdminUserInfo().AdminUser.Id
  5704. service.DrugAutoAddCancelInfo(item, creater)
  5705. }
  5706. }
  5707. } else {
  5708. if drugOutConfig.IsOpen == 1 {
  5709. if len(advices) > 0 {
  5710. for _, item := range advices {
  5711. creater := c.GetAdminUserInfo().AdminUser.Id
  5712. service.DrugAutoAddCancelInfo(item, creater)
  5713. }
  5714. }
  5715. } else {
  5716. if len(advices) > 0 {
  5717. for _, item := range advices {
  5718. creater := c.GetAdminUserInfo().AdminUser.Id
  5719. service.DrugAutoAddCancelInfo(item, creater)
  5720. }
  5721. }
  5722. }
  5723. }
  5724. c.ServeSuccessJSON(map[string]interface{}{
  5725. "msg": "删除成功",
  5726. })
  5727. return
  5728. }
  5729. func (c *HisApiController) DeleteDoctorAdvice() {
  5730. id, _ := c.GetInt64("id")
  5731. advice, _ := service.GetHisDoctorAdvicesById(id)
  5732. ////同步到自备药
  5733. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5734. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5735. if selfPrescriptionOpen.IsOpen == 1 {
  5736. db := service.XTWriteDB()
  5737. tx := db.Begin()
  5738. defer func() {
  5739. if r := recover(); r != nil {
  5740. tx.Rollback()
  5741. } else {
  5742. tx.Commit()
  5743. }
  5744. }()
  5745. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5746. var total_count int64
  5747. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5748. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5749. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5750. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5751. }
  5752. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5753. total_count += prescribingNumberSeven
  5754. }
  5755. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5756. total_count += prescribingNumberSeven
  5757. }
  5758. timeStr := time.Now().Format("2006-01-02")
  5759. timeArr := strings.Split(timeStr, "-")
  5760. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5761. total = total + 1
  5762. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5763. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5764. number = number + total
  5765. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5766. operation_time := time.Now().Unix()
  5767. creater := c.GetAdminUserInfo().AdminUser.Id
  5768. //创建一个出库单
  5769. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5770. WarehouseOutOrderNumber: warehousing_out_order,
  5771. OperationTime: operation_time,
  5772. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5773. Creater: creater,
  5774. Ctime: time.Now().Unix(),
  5775. Status: 1,
  5776. WarehouseOutTime: advice.AdviceDate,
  5777. Type: 0,
  5778. PatientId: advice.PatientId,
  5779. IsCheck: 1,
  5780. }
  5781. //查询今日是否有出库数据
  5782. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5783. if lastWarehouseOut.ID == 0 {
  5784. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5785. }
  5786. //出库
  5787. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5788. WarehouseOutId: lastWarehouseOut.ID,
  5789. WarehouseOutOrderNumber: warehousing_out_order,
  5790. DrugId: advice.DrugId,
  5791. Count: total_count,
  5792. Price: 0,
  5793. TotalPrice: 0,
  5794. Status: 1,
  5795. Ctime: advice.AdviceDate,
  5796. Mtime: advice.AdviceDate,
  5797. Remark: "",
  5798. OrgId: advice.UserOrgId,
  5799. Type: 0,
  5800. Manufacturer: selfBasedrug.Manufacturer,
  5801. Dealer: selfBasedrug.Dealer,
  5802. RetailPrice: 0,
  5803. RetailTotalPrice: 0,
  5804. CountUnit: advice.PrescribingNumberUnit,
  5805. ExpiryDate: 0,
  5806. ProductDate: 0,
  5807. Number: "",
  5808. BatchNumber: "",
  5809. IsSys: 0,
  5810. WarehouseInfoId: 0,
  5811. AdminUserId: 0,
  5812. StockCount: "",
  5813. IsCheck: 1,
  5814. SysRecordTime: advice.AdviceDate,
  5815. PatientId: advice.PatientId,
  5816. AdviceId: advice.ID,
  5817. ClassType: "",
  5818. }
  5819. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5820. for _, it := range warehousingOutInfo {
  5821. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5822. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5823. //出库逻辑
  5824. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5825. //查询剩余库存
  5826. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5827. var sum_count int64
  5828. for _, its := range stockInfo {
  5829. if its.MaxUnit == medical.MaxUnit {
  5830. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5831. }
  5832. sum_count += its.StockMaxNumber + its.StockMinNumber
  5833. }
  5834. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5835. }
  5836. }
  5837. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5838. //已收费和已发药的限制逻辑
  5839. isCharge := false
  5840. isMedicine := false
  5841. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5842. //获取今天该患者所有处方,判断是否发药或者收费
  5843. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5844. //for _, item := range new_prescriptions {
  5845. if new_prescription.IsMedicine == 1 {
  5846. isMedicine = true
  5847. }
  5848. //}
  5849. for _, item := range new_prescriptions {
  5850. if item.OrderStatus == 4 {
  5851. isCharge = true
  5852. }
  5853. }
  5854. if isMedicine {
  5855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5856. return
  5857. }
  5858. if isCharge {
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5860. return
  5861. }
  5862. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5863. for _, item := range advices {
  5864. if item.IsMedicine == 1 {
  5865. isMedicine = true
  5866. }
  5867. }
  5868. if isMedicine {
  5869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5870. return
  5871. }
  5872. if new_prescription.ID > 0 {
  5873. if new_prescription.OrderStatus == 2 {
  5874. isCharge = true
  5875. }
  5876. }
  5877. if isCharge {
  5878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5879. return
  5880. }
  5881. //已收费和已发药的限制逻辑
  5882. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5883. redis := service.RedisClient()
  5884. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5885. redis.Set(keyFive, "", time.Second)
  5886. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5887. redis.Set(keyOne, "", time.Second)
  5888. defer redis.Close()
  5889. if err == nil {
  5890. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5891. //查询是否在处方中出库
  5892. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5893. if openConfig.IsOpen != 1 {
  5894. //判断该医嘱是否执行了
  5895. if advice.ExecutionState == 1 {
  5896. creater := c.GetAdminUserInfo().AdminUser.Id
  5897. service.DrugAutoAddCancelInfo(&advice, creater)
  5898. }
  5899. }
  5900. //开启保存处方扣减功能
  5901. if openConfig.IsOpen == 1 {
  5902. creater := c.GetAdminUserInfo().AdminUser.Id
  5903. service.DrugAutoAddCancelInfo(&advice, creater)
  5904. }
  5905. } else {
  5906. if drugOutConfig.IsOpen == 1 {
  5907. //查询是否在处方中出库
  5908. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5909. if openConfig.IsOpen != 1 {
  5910. //判断该医嘱是否执行了
  5911. if advice.ExecutionState == 1 {
  5912. creater := c.GetAdminUserInfo().AdminUser.Id
  5913. service.DrugAutoAddCancelInfo(&advice, creater)
  5914. }
  5915. }
  5916. //开启保存处方扣减功能
  5917. if openConfig.IsOpen == 1 {
  5918. creater := c.GetAdminUserInfo().AdminUser.Id
  5919. service.DrugAutoAddCancelInfo(&advice, creater)
  5920. }
  5921. } else {
  5922. //判断该医嘱是否执行了
  5923. if advice.ExecutionState == 1 {
  5924. creater := c.GetAdminUserInfo().AdminUser.Id
  5925. service.DrugAutoAddCancelInfo(&advice, creater)
  5926. }
  5927. }
  5928. }
  5929. c.ServeSuccessJSON(map[string]interface{}{
  5930. "msg": "删除成功",
  5931. })
  5932. return
  5933. } else {
  5934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5935. return
  5936. }
  5937. }
  5938. func (c *HisApiController) DeleteProject() {
  5939. id, _ := c.GetInt64("id")
  5940. adminInfo := c.GetAdminUserInfo()
  5941. project, _ := service.GetHisProjectByID(id)
  5942. // var consumable models.DialysisBeforePrepare
  5943. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5944. //耗材保存处方出库
  5945. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5946. isCharge := false
  5947. isMedicine := false
  5948. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5949. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5950. for _, item := range new_prescriptions {
  5951. if item.IsMedicine == 1 {
  5952. isMedicine = true
  5953. }
  5954. }
  5955. for _, item := range new_prescriptions {
  5956. if item.OrderStatus == 4 {
  5957. isCharge = true
  5958. }
  5959. }
  5960. if isMedicine {
  5961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5962. return
  5963. }
  5964. if isCharge {
  5965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5966. return
  5967. }
  5968. if new_prescription.ID > 0 {
  5969. if new_prescription.OrderStatus == 2 {
  5970. isCharge = true
  5971. }
  5972. }
  5973. if isCharge {
  5974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5975. return
  5976. }
  5977. service.DeletePrintInfo(id)
  5978. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5979. label.Status = 0
  5980. service.CreateHisLabelRecordTwo(&label)
  5981. fmt.Println(goodOutConfig.IsOpen)
  5982. if goodOutConfig.IsOpen != 1 {
  5983. if stockConfig.IsOpen == 1 {
  5984. if project.Type == 2 {
  5985. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5986. fmt.Println(err)
  5987. }
  5988. if project.Type == 3 && project.IsOut == 1 {
  5989. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5990. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5991. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5992. operation_time := time.Now().Unix()
  5993. creater := adminInfo.AdminUser.Id
  5994. //创建退库单
  5995. timeStr := time.Now().Format("2006-01-02")
  5996. timeArr := strings.Split(timeStr, "-")
  5997. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5998. total = total + 1
  5999. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6000. cancelStock := models.CancelStock{
  6001. OrderNumber: orderNumber,
  6002. OperaTime: operation_time,
  6003. OrgId: adminInfo.CurrentOrgId,
  6004. Creater: creater,
  6005. Ctime: time.Now().Unix(),
  6006. Status: 1,
  6007. ReturnTime: project.RecordDate,
  6008. Type: 1,
  6009. StorehouseId: houseConfig.StorehouseOutInfo,
  6010. IsCheck: 1,
  6011. }
  6012. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6013. if msgerrkonde == gorm.ErrRecordNotFound {
  6014. service.AddSigleCancelStock(&cancelStock)
  6015. }
  6016. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6017. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6018. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6019. //查询是否有出库
  6020. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6021. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6022. deaerler, _ := service.GetDealerById(info.Dealer)
  6023. if info.ID > 0 {
  6024. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6025. if info.Count >= prescribingNumber {
  6026. cancelStockInfo := models.CancelStockInfo{
  6027. GoodId: project.ProjectId,
  6028. CancelStockId: cancel.ID,
  6029. GoodTypeId: good.GoodTypeId,
  6030. Count: prescribingNumber,
  6031. Price: info.Price,
  6032. Total: 0,
  6033. ProductDate: info.ProductDate,
  6034. ExpiryDate: info.ExpiryDate,
  6035. Ctime: time.Now().Unix(),
  6036. Status: 1,
  6037. OrgId: adminInfo.CurrentOrgId,
  6038. OrderNumber: cancel.OrderNumber,
  6039. Type: 0,
  6040. Dealer: deaerler.DealerName,
  6041. Manufacturer: manufacturer.ManufacturerName,
  6042. Number: info.Number,
  6043. RegisterAccount: "",
  6044. Remark: "",
  6045. WarehouseInfoId: info.WarehouseInfotId,
  6046. PatientId: info.PatientId,
  6047. RecordDate: info.SysRecordTime,
  6048. StorehouseId: houseConfig.StorehouseOutInfo,
  6049. IsCheck: 1,
  6050. }
  6051. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6052. //回退库存
  6053. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6054. //退库数量增加
  6055. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6056. //出库数量减少
  6057. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6058. }
  6059. if info.Count < prescribingNumber {
  6060. cancelStockInfo := models.CancelStockInfo{
  6061. GoodId: project.ProjectId,
  6062. CancelStockId: cancel.ID,
  6063. GoodTypeId: good.GoodTypeId,
  6064. Count: info.Count,
  6065. Price: info.Price,
  6066. Total: 0,
  6067. ProductDate: info.ProductDate,
  6068. ExpiryDate: info.ExpiryDate,
  6069. Ctime: time.Now().Unix(),
  6070. Status: 1,
  6071. OrgId: adminInfo.CurrentOrgId,
  6072. OrderNumber: cancel.OrderNumber,
  6073. Type: 0,
  6074. Dealer: deaerler.DealerName,
  6075. Manufacturer: manufacturer.ManufacturerName,
  6076. Number: info.Number,
  6077. RegisterAccount: "",
  6078. Remark: "",
  6079. WarehouseInfoId: info.WarehouseInfotId,
  6080. PatientId: info.PatientId,
  6081. RecordDate: info.SysRecordTime,
  6082. StorehouseId: houseConfig.StorehouseOutInfo,
  6083. IsCheck: 1,
  6084. }
  6085. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6086. //回退库存
  6087. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6088. //退库数量增加
  6089. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6090. //出库数量减少
  6091. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6092. }
  6093. //查询剩余库存
  6094. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6095. var over_count int64
  6096. for _, it := range goodList {
  6097. over_count += it.StockCount
  6098. }
  6099. //出库数据 大于 退库数量
  6100. if info.Count >= prescribingNumber {
  6101. flow := models.VmStockFlow{
  6102. WarehousingId: info.WarehouseInfotId,
  6103. GoodId: project.ProjectId,
  6104. Number: info.Number,
  6105. LicenseNumber: info.LicenseNumber,
  6106. Count: prescribingNumber,
  6107. UserOrgId: adminInfo.CurrentOrgId,
  6108. PatientId: project.PatientId,
  6109. SystemTime: info.SysRecordTime,
  6110. ConsumableType: 7,
  6111. IsSys: 0,
  6112. WarehousingOrder: "",
  6113. WarehouseOutId: info.WarehouseOutId,
  6114. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6115. IsEdit: 0,
  6116. CancelStockId: cancel.ID,
  6117. CancelOrderNumber: cancel.OrderNumber,
  6118. Manufacturer: manufacturer.ID,
  6119. Dealer: 0,
  6120. Creator: adminInfo.AdminUser.Id,
  6121. UpdateCreator: 0,
  6122. Status: 1,
  6123. Ctime: time.Now().Unix(),
  6124. Mtime: 0,
  6125. Price: info.Price,
  6126. WarehousingDetailId: info.WarehouseInfotId,
  6127. WarehouseOutDetailId: info.ID,
  6128. CancelOutDetailId: cancelInfo.ID,
  6129. ProductDate: info.ProductDate,
  6130. ExpireDate: info.ExpiryDate,
  6131. StorehouseId: houseConfig.StorehouseOutInfo,
  6132. OverCount: over_count,
  6133. OperateTime: time.Now().Unix(),
  6134. }
  6135. service.CreateStockFlowOne(flow)
  6136. }
  6137. //出库数据小于退库数据
  6138. if info.Count < prescribingNumber {
  6139. flow := models.VmStockFlow{
  6140. WarehousingId: info.WarehouseInfotId,
  6141. GoodId: project.ProjectId,
  6142. Number: info.Number,
  6143. LicenseNumber: info.LicenseNumber,
  6144. Count: info.Count,
  6145. UserOrgId: adminInfo.CurrentOrgId,
  6146. PatientId: project.PatientId,
  6147. SystemTime: info.SysRecordTime,
  6148. ConsumableType: 7,
  6149. IsSys: 0,
  6150. WarehousingOrder: "",
  6151. WarehouseOutId: info.WarehouseOutId,
  6152. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6153. IsEdit: 0,
  6154. CancelStockId: cancel.ID,
  6155. CancelOrderNumber: cancel.OrderNumber,
  6156. Manufacturer: manufacturer.ID,
  6157. Dealer: 0,
  6158. Creator: adminInfo.AdminUser.Id,
  6159. UpdateCreator: 0,
  6160. Status: 1,
  6161. Ctime: time.Now().Unix(),
  6162. Mtime: 0,
  6163. Price: info.Price,
  6164. WarehousingDetailId: info.WarehouseInfotId,
  6165. WarehouseOutDetailId: info.ID,
  6166. CancelOutDetailId: cancelInfo.ID,
  6167. ProductDate: info.ProductDate,
  6168. ExpireDate: info.ExpiryDate,
  6169. StorehouseId: houseConfig.StorehouseOutInfo,
  6170. OverCount: over_count,
  6171. OperateTime: time.Now().Unix(),
  6172. }
  6173. service.CreateStockFlowOne(flow)
  6174. }
  6175. //查询已出库数量
  6176. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6177. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6178. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6179. if prescribingNumber < dialysisInfo.Count {
  6180. //改变数量
  6181. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6182. }
  6183. if prescribingNumber >= dialysisInfo.Count {
  6184. //删除出库表
  6185. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6186. }
  6187. //更新剩余库存
  6188. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6189. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6190. var total_count_one int64
  6191. for _, it := range stockList {
  6192. total_count_one += it.StockCount
  6193. }
  6194. //基础库插入数据
  6195. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6196. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6197. var flush_count int64
  6198. for _, it := range goodListOne {
  6199. flush_count += it.StockCount
  6200. }
  6201. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6202. if errs != nil {
  6203. goodErrcode := models.XtGoodErrcode{
  6204. UserOrgId: project.UserOrgId,
  6205. Errcode: "手动出库更新剩余出库失败",
  6206. GoodId: project.ProjectId,
  6207. Status: 1,
  6208. Ctime: time.Now().Unix(),
  6209. Mtime: 0,
  6210. Count: 0,
  6211. StockCount: 0,
  6212. Creater: creater,
  6213. BatchNumberId: 0,
  6214. WarehouseOutId: 0,
  6215. }
  6216. service.CreateGoodErrcode(goodErrcode)
  6217. }
  6218. }
  6219. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6220. fmt.Println(err)
  6221. } else {
  6222. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6223. fmt.Println(err)
  6224. }
  6225. } else {
  6226. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6227. fmt.Println(err)
  6228. }
  6229. }
  6230. //保存处方出库
  6231. if goodOutConfig.IsOpen == 1 {
  6232. if project.Type == 3 {
  6233. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6234. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6235. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6236. operation_time := time.Now().Unix()
  6237. creater := adminInfo.AdminUser.Id
  6238. //创建退库单
  6239. timeStr := time.Now().Format("2006-01-02")
  6240. timeArr := strings.Split(timeStr, "-")
  6241. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6242. total = total + 1
  6243. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6244. cancelStock := models.CancelStock{
  6245. OrderNumber: orderNumber,
  6246. OperaTime: operation_time,
  6247. OrgId: adminInfo.CurrentOrgId,
  6248. Creater: creater,
  6249. Ctime: time.Now().Unix(),
  6250. Status: 1,
  6251. ReturnTime: project.RecordDate,
  6252. Type: 1,
  6253. StorehouseId: houseConfig.StorehouseOutInfo,
  6254. IsCheck: 1,
  6255. }
  6256. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6257. if msgerrkonde == gorm.ErrRecordNotFound {
  6258. service.AddSigleCancelStock(&cancelStock)
  6259. }
  6260. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6261. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6262. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6263. //获取出库数据
  6264. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6265. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6266. deaerler, _ := service.GetDealerById(info.Dealer)
  6267. if info.ID > 0 {
  6268. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6269. if info.Count >= prescribingNumber {
  6270. cancelStockInfo := models.CancelStockInfo{
  6271. GoodId: project.ProjectId,
  6272. CancelStockId: cancel.ID,
  6273. GoodTypeId: good.GoodTypeId,
  6274. Count: prescribingNumber,
  6275. Price: info.Price,
  6276. Total: 0,
  6277. ProductDate: info.ProductDate,
  6278. ExpiryDate: info.ExpiryDate,
  6279. Ctime: time.Now().Unix(),
  6280. Status: 1,
  6281. OrgId: adminInfo.CurrentOrgId,
  6282. OrderNumber: cancel.OrderNumber,
  6283. Type: 0,
  6284. Dealer: deaerler.DealerName,
  6285. Manufacturer: manufacturer.ManufacturerName,
  6286. Number: info.Number,
  6287. RegisterAccount: "",
  6288. Remark: "",
  6289. WarehouseInfoId: info.WarehouseInfotId,
  6290. PatientId: info.PatientId,
  6291. RecordDate: info.SysRecordTime,
  6292. StorehouseId: houseConfig.StorehouseOutInfo,
  6293. IsCheck: 1,
  6294. }
  6295. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6296. //退库数量增加
  6297. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6298. //出库数量减少
  6299. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6300. }
  6301. if info.Count < prescribingNumber {
  6302. cancelStockInfo := models.CancelStockInfo{
  6303. GoodId: project.ProjectId,
  6304. CancelStockId: cancel.ID,
  6305. GoodTypeId: good.GoodTypeId,
  6306. Count: prescribingNumber,
  6307. Price: info.Price,
  6308. Total: 0,
  6309. ProductDate: info.ProductDate,
  6310. ExpiryDate: info.ExpiryDate,
  6311. Ctime: time.Now().Unix(),
  6312. Status: 1,
  6313. OrgId: adminInfo.CurrentOrgId,
  6314. OrderNumber: cancel.OrderNumber,
  6315. Type: 0,
  6316. Dealer: deaerler.DealerName,
  6317. Manufacturer: manufacturer.ManufacturerName,
  6318. Number: info.Number,
  6319. RegisterAccount: "",
  6320. Remark: "",
  6321. WarehouseInfoId: info.WarehouseInfotId,
  6322. PatientId: info.PatientId,
  6323. RecordDate: info.SysRecordTime,
  6324. StorehouseId: houseConfig.StorehouseOutInfo,
  6325. IsCheck: 1,
  6326. }
  6327. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6328. //回退库存
  6329. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6330. }
  6331. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6332. var over_count int64
  6333. for _, it := range goodList {
  6334. over_count += it.StockCount
  6335. }
  6336. //查询出库数量
  6337. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6338. //出库数据 大于 退库数量
  6339. if len(list) > 0 {
  6340. for _, it := range list {
  6341. //回退库存
  6342. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6343. //退库数量增加
  6344. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6345. //出库数量减少
  6346. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6347. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6348. var over_count_one int64
  6349. for _, it := range goodList {
  6350. over_count_one += it.StockCount
  6351. }
  6352. //查询该批次是否有退库数据
  6353. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6354. flow := models.VmStockFlow{
  6355. WarehousingId: it.WarehouseInfotId,
  6356. GoodId: it.GoodId,
  6357. Number: it.Number,
  6358. LicenseNumber: it.LicenseNumber,
  6359. Count: it.Count,
  6360. UserOrgId: adminInfo.CurrentOrgId,
  6361. PatientId: it.PatientId,
  6362. SystemTime: it.SysRecordTime,
  6363. ConsumableType: 7,
  6364. IsSys: 0,
  6365. WarehousingOrder: "",
  6366. WarehouseOutId: it.WarehouseOutId,
  6367. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6368. IsEdit: 0,
  6369. CancelStockId: cancel.ID,
  6370. CancelOrderNumber: cancel.OrderNumber,
  6371. Manufacturer: manufacturer.ID,
  6372. Dealer: 0,
  6373. Creator: adminInfo.AdminUser.Id,
  6374. UpdateCreator: 0,
  6375. Status: 1,
  6376. Ctime: time.Now().Unix(),
  6377. Mtime: 0,
  6378. Price: it.Price,
  6379. WarehousingDetailId: it.WarehouseInfotId,
  6380. WarehouseOutDetailId: it.ID,
  6381. CancelOutDetailId: cancelInfo.ID,
  6382. ProductDate: it.ProductDate,
  6383. ExpireDate: it.ExpiryDate,
  6384. StorehouseId: houseConfig.StorehouseOutInfo,
  6385. OverCount: over_count_one,
  6386. OperateTime: time.Now().Unix(),
  6387. }
  6388. service.CreateStockFlowOne(flow)
  6389. }
  6390. }
  6391. //查询已出库数量
  6392. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6393. if prescribingNumber < dialysisInfo.Count {
  6394. //改变数量
  6395. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6396. }
  6397. if prescribingNumber >= dialysisInfo.Count {
  6398. //删除出库表
  6399. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6400. }
  6401. //更新剩余库存
  6402. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6403. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6404. var total_count_one int64
  6405. for _, it := range stockList {
  6406. total_count_one += it.StockCount
  6407. }
  6408. //基础库插入数据
  6409. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6410. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6411. var flush_count int64
  6412. for _, it := range goodListOne {
  6413. flush_count += it.StockCount
  6414. }
  6415. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6416. if errs != nil {
  6417. goodErrcode := models.XtGoodErrcode{
  6418. UserOrgId: project.UserOrgId,
  6419. Errcode: "手动出库更新剩余出库失败",
  6420. GoodId: project.ProjectId,
  6421. Status: 1,
  6422. Ctime: time.Now().Unix(),
  6423. Mtime: 0,
  6424. Count: 0,
  6425. StockCount: 0,
  6426. Creater: creater,
  6427. BatchNumberId: 0,
  6428. WarehouseOutId: 0,
  6429. }
  6430. service.CreateGoodErrcode(goodErrcode)
  6431. }
  6432. }
  6433. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6434. fmt.Println(err)
  6435. } else {
  6436. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6437. fmt.Println(err)
  6438. }
  6439. }
  6440. c.ServeSuccessJSON(map[string]interface{}{
  6441. "msg": "删除成功",
  6442. })
  6443. return
  6444. }
  6445. func (c *HisApiController) CreateHisAdditionalCharge() {
  6446. his_patient_id, _ := c.GetInt64("his_patient_id")
  6447. patient_id, _ := c.GetInt64("patient_id")
  6448. record_date := c.GetString("record_date")
  6449. timeLayout := "2006-01-02"
  6450. loc, _ := time.LoadLocation("Local")
  6451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6452. if err != nil {
  6453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6454. return
  6455. }
  6456. adminInfo := c.GetAdminUserInfo()
  6457. recordDateTime := theTime.Unix()
  6458. dataBody := make(map[string]interface{}, 0)
  6459. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6460. if err != nil {
  6461. utils.ErrorLog(err.Error())
  6462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6463. return
  6464. }
  6465. var additions []*models.HisAdditionalCharge
  6466. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6467. additions, _ := dataBody["addition"].([]interface{})
  6468. if len(additions) > 0 {
  6469. for _, item := range additions {
  6470. items := item.(map[string]interface{})
  6471. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6472. utils.ErrorLog("item_id")
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6474. return
  6475. }
  6476. item_id := int64(items["item_id"].(float64))
  6477. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6478. utils.ErrorLog("item_name")
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6480. return
  6481. }
  6482. item_name := items["item_name"].(string)
  6483. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6484. utils.ErrorLog("price")
  6485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6486. return
  6487. }
  6488. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6489. ctime := time.Now().Unix()
  6490. additional := &models.HisAdditionalCharge{
  6491. PatientId: patient_id,
  6492. HisPatientId: his_patient_id,
  6493. UserOrgId: adminInfo.CurrentOrgId,
  6494. RecordDate: recordDateTime,
  6495. CreatedTime: ctime,
  6496. UpdatedTime: ctime,
  6497. Modifier: adminInfo.AdminUser.Id,
  6498. Creator: adminInfo.AdminUser.Id,
  6499. Price: price,
  6500. ItemName: item_name,
  6501. ItemId: item_id,
  6502. Status: 1,
  6503. }
  6504. additions = append(additions, additional)
  6505. }
  6506. }
  6507. }
  6508. for _, item := range additions {
  6509. service.CreateAddtionalCharge(item)
  6510. }
  6511. c.ServeSuccessJSON(map[string]interface{}{
  6512. "msg": "创建成功",
  6513. })
  6514. }
  6515. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6516. blood_fat := c.GetString("blood_fat")
  6517. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6518. blood_sugar := c.GetString("blood_sugar")
  6519. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6520. chief_conplaint := c.GetString("chief_conplaint")
  6521. dbp := c.GetString("dbp")
  6522. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6523. delivery_way, _ := c.GetInt64("delivery_way")
  6524. diagnostic := c.GetString("diagnostic")
  6525. family_history := c.GetString("family_history")
  6526. height := c.GetString("height")
  6527. history_of_present_illness := c.GetString("history_of_present_illness")
  6528. is_infect, _ := c.GetInt64("is_infect")
  6529. past_history := c.GetString("past_history")
  6530. patient_id, _ := c.GetInt64("patient_id")
  6531. his_patient_id, _ := c.GetInt64("his_patient_id")
  6532. personal_history := c.GetString("personal_history")
  6533. pulse := c.GetString("pulse")
  6534. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6535. sbp := c.GetString("sbp")
  6536. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6537. heightfloat, _ := strconv.ParseFloat(height, 64)
  6538. sicktype := c.GetString("sick_type")
  6539. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6540. symptom := c.GetString("symptom")
  6541. sick_date := c.GetString("sick_date")
  6542. temperatures := c.GetString("temperature")
  6543. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6544. record_date := c.GetString("record_date")
  6545. breathing := c.GetString("breathing")
  6546. doctor_advice := c.GetString("doctor_advice")
  6547. remark := c.GetString("remark")
  6548. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6549. sick, _ := c.GetInt64("sick")
  6550. diagnose, _ := c.GetInt64("diagnose")
  6551. //id, _ := c.GetInt64("id")
  6552. timeLayout := "2006-01-02"
  6553. loc, _ := time.LoadLocation("Local")
  6554. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6555. allergic_history := c.GetString("allergic_history")
  6556. if err != nil {
  6557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6558. return
  6559. }
  6560. recordDateTime := theTime.Unix()
  6561. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6562. if err != nil {
  6563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6564. return
  6565. }
  6566. sickTimes := sickTime.Unix()
  6567. ctime := time.Now().Unix()
  6568. primary_disease := c.GetString("primary_disease")
  6569. confirm_failure_date := c.GetString("confirm_failure_date")
  6570. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6571. drug_allergy_history := c.GetString("drug_allergy_history")
  6572. physical_examination := c.GetString("physical_examination")
  6573. special_inspection := c.GetString("special_inspection")
  6574. lab_apparatus := c.GetString("lab_apparatus")
  6575. caseHistory := models.HisPatientCaseHistory{
  6576. HisPatientId: his_patient_id,
  6577. PatientId: patient_id,
  6578. Temperature: temperature,
  6579. BloodSugar: bloodsugarfloat,
  6580. Pulse: pulsefloat,
  6581. Sbp: sbpfloat,
  6582. Dbp: dbpfloat,
  6583. Height: heightfloat,
  6584. BloodFat: bloodfatfloat,
  6585. SickType: sick_type,
  6586. Symptom: symptom,
  6587. SickDate: sickTimes,
  6588. IsInfect: is_infect,
  6589. HistoryOfPresentIllness: history_of_present_illness,
  6590. PastHistory: past_history,
  6591. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6592. ChiefConplaint: chief_conplaint,
  6593. PersonalHistory: personal_history,
  6594. FamilyHistory: family_history,
  6595. Diagnostic: diagnostic,
  6596. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6597. Status: 1,
  6598. Ctime: ctime,
  6599. Mtime: ctime,
  6600. RecordDate: recordDateTime,
  6601. DeliveryWay: delivery_way,
  6602. Breathing: breathingfloat,
  6603. DoctorAdvice: doctor_advice,
  6604. Remark: remark,
  6605. Sick: sick,
  6606. Diagnose: diagnose,
  6607. AllergicHistory: allergic_history,
  6608. PrimaryDisease: primary_disease,
  6609. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6610. DrugAllergyHistory: drug_allergy_history,
  6611. PhysicalExamination: physical_examination,
  6612. SpecialInspection: special_inspection,
  6613. LabApparatus: lab_apparatus,
  6614. }
  6615. //查询该患者是否有病历
  6616. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6617. if errcodes == gorm.ErrRecordNotFound {
  6618. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6619. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6620. if err != nil {
  6621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6622. return
  6623. }
  6624. c.ServeSuccessJSON(map[string]interface{}{
  6625. "caseHistory": caseHistory,
  6626. "historyInfo": historyInfo,
  6627. })
  6628. return
  6629. } else if errcodes == nil {
  6630. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6631. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6632. if err != nil {
  6633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6634. return
  6635. }
  6636. c.ServeSuccessJSON(map[string]interface{}{
  6637. "caseHistory": caseHistory,
  6638. "historyInfo": historyInfo,
  6639. })
  6640. }
  6641. //查询该患者是否有病历
  6642. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6643. //if errcode == gorm.ErrRecordNotFound {
  6644. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6645. // if err != nil {
  6646. // c.ServeSuccessJSON(map[string]interface{}{
  6647. // "msg": "保存成功",
  6648. // })
  6649. // }
  6650. //} else if errcode == nil {
  6651. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6652. // return
  6653. //}
  6654. }
  6655. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6656. patient_id, _ := c.GetInt64("patient_id", 0)
  6657. adminUser := c.GetAdminUserInfo()
  6658. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6659. c.ServeSuccessJSON(map[string]interface{}{
  6660. "list": caseHistorys,
  6661. })
  6662. }
  6663. func (c *HisApiController) GetHisPatientCaseHistory() {
  6664. record_date, _ := c.GetInt64("record_date", 0)
  6665. patient_id, _ := c.GetInt64("patient_id", 0)
  6666. admin := c.GetAdminUserInfo()
  6667. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6668. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6669. c.ServeSuccessJSON(map[string]interface{}{
  6670. "info": info,
  6671. "case_history": case_history,
  6672. })
  6673. }
  6674. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6675. template_name := c.GetString("template_name")
  6676. template_remark := c.GetString("template_remark")
  6677. doctor := c.GetAdminUserInfo().AdminUser.Id
  6678. diagnostic := c.GetString("diagnostic")
  6679. chief_conplaint := c.GetString("chief_conplain")
  6680. history_of_present_illness := c.GetString("history_of_present_illness")
  6681. past_history := c.GetString("past_history")
  6682. personal_history := c.GetString("personal_history")
  6683. family_history := c.GetString("family_history")
  6684. user_name := c.GetString("user_name")
  6685. doctor_advice := c.GetString("doctor_advice")
  6686. remark := c.GetString("remark")
  6687. //record_date := c.GetString("record_date")
  6688. //fmt.Println("record_date--------",record_date)
  6689. //timeLayout := "2006-01-02"
  6690. //loc, _ := time.LoadLocation("Local")
  6691. //
  6692. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6693. //if err != nil {
  6694. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6695. // return
  6696. //}
  6697. //recordDateTime := theTime.Unix()
  6698. ctime := time.Now().Unix()
  6699. template := models.HisCaseHistoryTemplate{
  6700. HistoryOfPresentIllness: history_of_present_illness,
  6701. PastHistory: past_history,
  6702. ChiefConplaint: chief_conplaint,
  6703. PersonalHistory: personal_history,
  6704. FamilyHistory: family_history,
  6705. Diagnostic: diagnostic,
  6706. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6707. Status: 1,
  6708. Ctime: ctime,
  6709. Mtime: ctime,
  6710. RecordDate: time.Now().Unix(),
  6711. TemplateName: template_name,
  6712. TemplateRemark: template_remark,
  6713. Creator: doctor,
  6714. Modifier: doctor,
  6715. UserName: user_name,
  6716. DoctorAdvice: doctor_advice,
  6717. Remark: remark,
  6718. }
  6719. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6720. if err == nil {
  6721. c.ServeSuccessJSON(map[string]interface{}{
  6722. "msg": "保存成功",
  6723. })
  6724. } else {
  6725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6726. return
  6727. }
  6728. }
  6729. func (c *HisApiController) GetCaseHistoryTemplate() {
  6730. timeLayout := "2006-01-02"
  6731. loc, _ := time.LoadLocation("Local")
  6732. keyword := c.GetString("keyword")
  6733. start_time := c.GetString("start_time")
  6734. end_time := c.GetString("end_time")
  6735. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6736. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6737. admin := c.GetAdminUserInfo()
  6738. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6739. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6740. c.ServeSuccessJSON(map[string]interface{}{
  6741. "template": template,
  6742. //"history": history,
  6743. })
  6744. }
  6745. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6746. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6747. utils.ErrorLog("drug_name")
  6748. return enums.ErrorCodeParamWrong
  6749. }
  6750. adviceName, _ := json["drug_name"].(string)
  6751. if len(adviceName) == 0 {
  6752. utils.ErrorLog("len(advice_name) == 0")
  6753. return enums.ErrorCodeParamWrong
  6754. }
  6755. advice.AdviceName = adviceName
  6756. adviceDesc, _ := json["advice_desc"].(string)
  6757. advice.AdviceDesc = adviceDesc
  6758. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6759. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6760. advice.DrugSpec = drugSpec
  6761. }
  6762. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6763. remark, _ := json["remark"].(string)
  6764. advice.Remark = remark
  6765. }
  6766. if json["id"] == nil {
  6767. advice.DrugId = 0
  6768. } else {
  6769. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6770. drug_id := int64(json["id"].(float64))
  6771. advice.DrugId = drug_id
  6772. }
  6773. }
  6774. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6775. advice_id := int64(json["advice_id"].(float64))
  6776. advice.ID = advice_id
  6777. if advice.ID > 0 {
  6778. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6779. if err == nil {
  6780. if hisAdvice.ID > 0 {
  6781. advice.ExecutionTime = hisAdvice.ExecutionTime
  6782. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6783. advice.ExecutionState = hisAdvice.ExecutionState
  6784. advice.CheckTime = hisAdvice.CheckTime
  6785. advice.Checker = hisAdvice.Checker
  6786. advice.CheckState = hisAdvice.CheckState
  6787. advice.StartTime = hisAdvice.StartTime
  6788. advice.FeedetlSn = hisAdvice.FeedetlSn
  6789. }
  6790. }
  6791. }
  6792. }
  6793. //
  6794. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6795. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6796. // advice.ExecutionTime = execution_time
  6797. //}
  6798. //
  6799. //
  6800. //
  6801. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6802. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6803. // advice.ExecutionStaff = execution_staff
  6804. //}
  6805. //
  6806. //
  6807. //
  6808. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6809. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6810. // advice.ExecutionState = execution_state
  6811. //}
  6812. //
  6813. //
  6814. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6815. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6816. // advice.CheckTime = check_time
  6817. //}
  6818. //
  6819. //
  6820. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6821. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6822. // advice.CheckState = check_state
  6823. //}
  6824. //
  6825. //
  6826. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6827. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6828. // advice.Checker = checker
  6829. //}
  6830. //
  6831. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6832. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6833. // advice.StartTime = start_time
  6834. //}
  6835. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6836. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6837. advice.IsSelfDrug = is_self_drug
  6838. }
  6839. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6840. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6841. drug_way_count, _ := json["drug_way_count"].(string)
  6842. advice.DrugWayCount = drug_way_count
  6843. }
  6844. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6845. drugSpecUnit, _ := json["min_unit"].(string)
  6846. advice.DrugSpecUnit = drugSpecUnit
  6847. }
  6848. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6849. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6850. advice.SingleDose = singleDose
  6851. }
  6852. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6853. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6854. advice.SingleDoseUnit = singleDoseUnit
  6855. }
  6856. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6857. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6858. advice.PrescribingNumber = prescribingNumber
  6859. }
  6860. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6861. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6862. advice.PrescribingNumberUnit = prescribingNumberUnit
  6863. }
  6864. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6865. deliveryWay, _ := json["delivery_way"].(string)
  6866. advice.DeliveryWay = deliveryWay
  6867. }
  6868. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6869. executionFrequency, _ := json["execution_frequency"].(string)
  6870. advice.ExecutionFrequency = executionFrequency
  6871. }
  6872. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6873. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6874. advice.Price = price
  6875. }
  6876. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6877. med_list_codg, _ := json["medical_insurance_number"].(string)
  6878. advice.MedListCodg = med_list_codg
  6879. }
  6880. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6881. day := int64(json["day"].(float64))
  6882. advice.Day = day
  6883. }
  6884. return 0
  6885. }
  6886. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6887. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6888. id := int64(json["id"].(float64))
  6889. project.ID = id
  6890. historyProject, _ := service.GetHisProjectByID(id)
  6891. project.FeedetlSn = historyProject.FeedetlSn
  6892. }
  6893. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6894. project_id := int64(json["project_id"].(float64))
  6895. project.ProjectId = project_id
  6896. }
  6897. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6898. // price := int64(json["price"].(float64))
  6899. // formatInt_price := strconv.FormatInt(price, 10)
  6900. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6901. // project.Price = float_price
  6902. // }
  6903. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6904. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6905. project.Price = price
  6906. }
  6907. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6908. total, _ := json["total"].(string)
  6909. project.Count = total
  6910. }
  6911. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6912. medical_code, _ := json["medical_code"].(string)
  6913. project.MedListCodg = medical_code
  6914. }
  6915. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6916. single_dose, _ := json["single_dose"].(string)
  6917. project.SingleDose = single_dose
  6918. }
  6919. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6920. delivery_way, _ := json["delivery_way"].(string)
  6921. project.DeliveryWay = delivery_way
  6922. }
  6923. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6924. execution_frequency, _ := json["execution_frequency"].(string)
  6925. project.ExecutionFrequency = execution_frequency
  6926. }
  6927. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6928. remark, _ := json["remark"].(string)
  6929. project.Remark = remark
  6930. }
  6931. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6932. day, _ := json["number_days"].(string)
  6933. project.Day = day
  6934. }
  6935. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6936. unit, _ := json["unit"].(string)
  6937. project.Unit = unit
  6938. }
  6939. return 0
  6940. }
  6941. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6942. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6943. id := int64(json["id"].(float64))
  6944. historyAddtions, _ := service.GetHisAdditionByID(id)
  6945. additionalCharge.ID = id
  6946. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6947. }
  6948. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6949. item_id := int64(json["item_id"].(float64))
  6950. additionalCharge.ItemId = item_id
  6951. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6952. if config.ID > 0 {
  6953. if len(config.Code) > 0 {
  6954. additionalCharge.MedListCodg = config.Code
  6955. }
  6956. }
  6957. }
  6958. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6959. // price := int64(json["price"].(float64))
  6960. // formatInt_price := strconv.FormatInt(price, 10)
  6961. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6962. // additionalCharge.Price = float_price
  6963. // }
  6964. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6965. // price := int64(json["price"].(float64))
  6966. // formatInt_price := strconv.FormatInt(price, 10)
  6967. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6968. // additionalCharge.Price = float_price
  6969. //}
  6970. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6971. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6972. additionalCharge.Price = price
  6973. }
  6974. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6975. count, _ := json["count"].(string)
  6976. counts, _ := strconv.ParseInt(count, 10, 64)
  6977. additionalCharge.Count = counts
  6978. }
  6979. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6980. item_name, _ := json["item_name"].(string)
  6981. additionalCharge.ItemName = item_name
  6982. }
  6983. return 0
  6984. }
  6985. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6986. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6987. utils.ErrorLog("drug_name")
  6988. return enums.ErrorCodeParamWrong
  6989. }
  6990. adviceName, _ := json["drug_name"].(string)
  6991. if len(adviceName) == 0 {
  6992. utils.ErrorLog("len(advice_name) == 0")
  6993. return enums.ErrorCodeParamWrong
  6994. }
  6995. advice.AdviceName = adviceName
  6996. adviceDesc, _ := json["advice_desc"].(string)
  6997. advice.AdviceDesc = adviceDesc
  6998. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6999. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7000. advice.DrugSpec = drugSpec
  7001. }
  7002. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7003. remark, _ := json["remark"].(string)
  7004. advice.Remark = remark
  7005. }
  7006. if json["id"] == nil {
  7007. advice.DrugId = 0
  7008. } else {
  7009. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7010. drug_id := int64(json["id"].(float64))
  7011. advice.DrugId = drug_id
  7012. }
  7013. }
  7014. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7015. groupno := int64(json["groupno"].(float64))
  7016. advice.Groupno = groupno
  7017. }
  7018. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7019. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7020. advice.IsSelfDrug = is_self_drug
  7021. }
  7022. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7023. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7024. drug_way_count, _ := json["drug_way_count"].(string)
  7025. advice.DrugWayCount = drug_way_count
  7026. }
  7027. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7028. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7029. advice.HospApprFlag = hosp_appr_flag
  7030. }
  7031. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7032. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7033. advice.PrescribingNumber = prescribingNumber
  7034. }
  7035. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7036. // frequency_type := int64(json["frequency_type"].(float64))
  7037. // advice.FrequencyType = frequency_type
  7038. //}
  7039. //
  7040. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7041. // day_count := int64(json["day_count"].(float64))
  7042. // advice.DayCount = day_count
  7043. //}
  7044. //
  7045. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7046. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7047. // week_day, _ := json["week_day"].(string)
  7048. // advice.WeekDay = week_day
  7049. //}
  7050. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7051. drugSpecUnit, _ := json["min_unit"].(string)
  7052. advice.DrugSpecUnit = drugSpecUnit
  7053. }
  7054. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7055. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7056. advice.SingleDose = singleDose
  7057. }
  7058. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7059. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7060. advice.SingleDoseUnit = singleDoseUnit
  7061. }
  7062. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7063. deliveryWay, _ := json["delivery_way"].(string)
  7064. advice.DeliveryWay = deliveryWay
  7065. }
  7066. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7067. executionFrequency, _ := json["execution_frequency"].(string)
  7068. advice.ExecutionFrequency = executionFrequency
  7069. }
  7070. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7071. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7072. advice.Price = price
  7073. }
  7074. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7075. med_list_codg, _ := json["medical_insurance_number"].(string)
  7076. advice.MedListCodg = med_list_codg
  7077. }
  7078. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7079. day := int64(json["day"].(float64))
  7080. advice.Day = day
  7081. }
  7082. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7083. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7084. advice.PrescribingNumberUnit = prescribingNumberUnit
  7085. }
  7086. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7087. advice_id := int64(json["advice_id"].(float64))
  7088. advice.ID = advice_id
  7089. if advice.ID > 0 {
  7090. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7091. if err == nil {
  7092. if hisAdvice.ID > 0 {
  7093. advice.ExecutionTime = hisAdvice.ExecutionTime
  7094. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7095. advice.ExecutionState = hisAdvice.ExecutionState
  7096. advice.CheckTime = hisAdvice.CheckTime
  7097. advice.Checker = hisAdvice.Checker
  7098. advice.CheckState = hisAdvice.CheckState
  7099. advice.StartTime = hisAdvice.StartTime
  7100. advice.HospApprFlag = hisAdvice.HospApprFlag
  7101. advice.IsMedicine = hisAdvice.IsMedicine
  7102. if hisAdvice.UserOrgId == 10028 {
  7103. 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 {
  7104. advice.ExecutionTime = 0
  7105. advice.ExecutionStaff = 0
  7106. advice.ExecutionState = 2
  7107. advice.CheckTime = 0
  7108. advice.Checker = 0
  7109. advice.CheckState = 2
  7110. }
  7111. } else {
  7112. 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 {
  7113. advice.ExecutionTime = 0
  7114. advice.ExecutionStaff = 0
  7115. advice.ExecutionState = 2
  7116. advice.CheckTime = 0
  7117. advice.Checker = 0
  7118. advice.CheckState = 2
  7119. advice.UpdatedTime = time.Now().Unix()
  7120. }
  7121. }
  7122. //advice.Groupno = hisAdvice.Groupno
  7123. }
  7124. }
  7125. }
  7126. }
  7127. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7128. //
  7129. //if drugStockConfig.IsOpen == 1 {
  7130. //
  7131. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7132. // if advice.ID == 0 { //医嘱不存在
  7133. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7134. // drug.Total = drug.Total - advice.PrescribingNumber
  7135. // service.UpdateBaseDrugLib(&drug)
  7136. //
  7137. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7138. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7139. // drug.Total = drug.Total - num
  7140. // service.UpdateBaseDrugLib(&drug)
  7141. // }
  7142. //
  7143. // } else if advice.ID > 0 { //医嘱存在
  7144. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7145. // var num float64
  7146. //
  7147. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7148. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7149. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7150. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7151. // drug.Total = drug.Total + num
  7152. // service.UpdateBaseDrugLib(&drug)
  7153. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7154. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7155. // drug.Total = drug.Total - num
  7156. // service.UpdateBaseDrugLib(&drug)
  7157. // }
  7158. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7159. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7160. // if num2 > advice.PrescribingNumber {
  7161. // num = num2 - advice.PrescribingNumber
  7162. // drug.Total = drug.Total + num
  7163. // service.UpdateBaseDrugLib(&drug)
  7164. // } else if num2 < advice.PrescribingNumber {
  7165. // num = advice.PrescribingNumber - num2
  7166. // drug.Total = drug.Total - num
  7167. // service.UpdateBaseDrugLib(&drug)
  7168. // }
  7169. //
  7170. // }
  7171. //
  7172. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7173. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7174. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7175. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7176. // if num1 > num2 {
  7177. // num = num1 - num2
  7178. // drug.Total = drug.Total + num
  7179. // service.UpdateBaseDrugLib(&drug)
  7180. // } else if num1 < num2 {
  7181. // num = num2 - num1
  7182. // drug.Total = drug.Total - num
  7183. // service.UpdateBaseDrugLib(&drug)
  7184. // }
  7185. //
  7186. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7187. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7188. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7189. // if hisAdvice.PrescribingNumber > num2 {
  7190. // num = hisAdvice.PrescribingNumber - num2
  7191. // drug.Total = drug.Total + num
  7192. // service.UpdateBaseDrugLib(&drug)
  7193. // } else if num2 < advice.PrescribingNumber {
  7194. // num = num2 - hisAdvice.PrescribingNumber
  7195. // drug.Total = drug.Total - num
  7196. // service.UpdateBaseDrugLib(&drug)
  7197. // }
  7198. //
  7199. // }
  7200. // }
  7201. // }
  7202. //}
  7203. //
  7204. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7205. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7206. // advice.ExecutionTime = execution_time
  7207. //}
  7208. //
  7209. //
  7210. //
  7211. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7212. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7213. // advice.ExecutionStaff = execution_staff
  7214. //}
  7215. //
  7216. //
  7217. //
  7218. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7219. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7220. // advice.ExecutionState = execution_state
  7221. //}
  7222. //
  7223. //
  7224. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7225. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7226. // advice.CheckTime = check_time
  7227. //}
  7228. //
  7229. //
  7230. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7231. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7232. // advice.CheckState = check_state
  7233. //}
  7234. //
  7235. //
  7236. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7237. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7238. // advice.Checker = checker
  7239. //}
  7240. //
  7241. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7242. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7243. // advice.StartTime = start_time
  7244. //}
  7245. return 0
  7246. }
  7247. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7248. project.ExecutionStaff = 0
  7249. project.ExecutionState = 2
  7250. project.ExecutionTime = 0
  7251. project.Checker = 0
  7252. project.CheckState = 2
  7253. project.CheckTime = 0
  7254. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7255. id := int64(json["id"].(float64))
  7256. project.ID = id
  7257. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7258. project.ExecutionStaff = temp_project.ExecutionStaff
  7259. project.ExecutionState = temp_project.ExecutionState
  7260. project.ExecutionTime = temp_project.ExecutionTime
  7261. project.Checker = temp_project.Checker
  7262. project.CheckState = temp_project.CheckState
  7263. project.CheckTime = temp_project.CheckTime
  7264. project.TeamId = temp_project.TeamId
  7265. }
  7266. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7267. types := int64(json["type"].(float64))
  7268. project.Type = types
  7269. }
  7270. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7271. project_id := int64(json["project_id"].(float64))
  7272. project.ProjectId = project_id
  7273. }
  7274. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7275. team_id := int64(json["team_id"].(float64))
  7276. project.TeamId = team_id
  7277. }
  7278. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7279. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7280. project.Price = price
  7281. }
  7282. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7283. total, _ := json["total"].(string)
  7284. //totals, _ := strconv.ParseInt(total, 10, 64)
  7285. project.Count = total
  7286. }
  7287. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7288. medical_code, _ := json["medical_code"].(string)
  7289. project.MedListCodg = medical_code
  7290. }
  7291. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7292. single_dose, _ := json["single_dose"].(string)
  7293. project.SingleDose = single_dose
  7294. }
  7295. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7296. delivery_way, _ := json["delivery_way"].(string)
  7297. project.DeliveryWay = delivery_way
  7298. }
  7299. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7300. execution_frequency, _ := json["execution_frequency"].(string)
  7301. project.ExecutionFrequency = execution_frequency
  7302. }
  7303. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7304. remark, _ := json["remark"].(string)
  7305. project.Remark = remark
  7306. }
  7307. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7308. day, _ := json["number_days"].(string)
  7309. project.Day = day
  7310. }
  7311. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7312. unit, _ := json["unit"].(string)
  7313. project.Unit = unit
  7314. }
  7315. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7316. // frequency_type := int64(json["frequency_type"].(float64))
  7317. // project.FrequencyType = frequency_type
  7318. //}
  7319. //
  7320. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7321. // day_count := int64(json["day_count"].(float64))
  7322. // project.DayCount = day_count
  7323. //}
  7324. //
  7325. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7326. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7327. // week_day, _ := json["week_day"].(string)
  7328. // project.WeekDay = week_day
  7329. //}
  7330. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7331. //
  7332. //if project.ID == 0 {
  7333. // if stockConfig.IsOpen == 1 {
  7334. // if project.Type == 3 {
  7335. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7336. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7337. // good.Total = good.Total - f_count
  7338. // service.UpdateGoodInfo(&good)
  7339. // }
  7340. // }
  7341. //
  7342. //} else {
  7343. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7344. //
  7345. // if stockConfig.IsOpen == 1 {
  7346. // if project.Type == 3 {
  7347. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7348. // if project.Count < temp_project.Count {
  7349. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7350. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7351. //
  7352. // other_count := f_count_two - f_count_one
  7353. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7354. // good.Total = good.Total + other_count_two
  7355. // service.UpdateGoodInfo(&good)
  7356. // } else if project.Count > temp_project.Count {
  7357. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7358. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7359. //
  7360. // other_count := f_count_one - f_count_two
  7361. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7362. // good.Total = good.Total - other_count_two
  7363. // service.UpdateGoodInfo(&good)
  7364. // }
  7365. //
  7366. // }
  7367. // }
  7368. //
  7369. //}
  7370. return 0
  7371. }
  7372. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7373. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7374. utils.ErrorLog("drug_name")
  7375. return enums.ErrorCodeParamWrong
  7376. }
  7377. adviceName, _ := json["drug_name"].(string)
  7378. if len(adviceName) == 0 {
  7379. utils.ErrorLog("len(advice_name) == 0")
  7380. return enums.ErrorCodeParamWrong
  7381. }
  7382. advice.AdviceName = adviceName
  7383. adviceDesc, _ := json["advice_desc"].(string)
  7384. advice.AdviceDesc = adviceDesc
  7385. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7386. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7387. advice.DrugSpec = drugSpec
  7388. }
  7389. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7390. remark, _ := json["remark"].(string)
  7391. advice.Remark = remark
  7392. }
  7393. if json["id"] == nil {
  7394. advice.DrugId = 0
  7395. } else {
  7396. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7397. drug_id := int64(json["id"].(float64))
  7398. advice.DrugId = drug_id
  7399. }
  7400. }
  7401. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7402. groupno := int64(json["groupno"].(float64))
  7403. advice.Groupno = groupno
  7404. }
  7405. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7406. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7407. advice.IsSelfDrug = is_self_drug
  7408. }
  7409. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7410. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7411. drug_way_count, _ := json["drug_way_count"].(string)
  7412. advice.DrugWayCount = drug_way_count
  7413. }
  7414. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7415. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7416. advice.HospApprFlag = hosp_appr_flag
  7417. }
  7418. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7419. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7420. advice.PrescribingNumber = prescribingNumber
  7421. }
  7422. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7423. // frequency_type := int64(json["frequency_type"].(float64))
  7424. // advice.FrequencyType = frequency_type
  7425. //}
  7426. //
  7427. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7428. // day_count := int64(json["day_count"].(float64))
  7429. // advice.DayCount = day_count
  7430. //}
  7431. //
  7432. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7433. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7434. // week_day, _ := json["week_day"].(string)
  7435. // advice.WeekDay = week_day
  7436. //}
  7437. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7438. drugSpecUnit, _ := json["min_unit"].(string)
  7439. advice.DrugSpecUnit = drugSpecUnit
  7440. }
  7441. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7442. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7443. advice.SingleDose = singleDose
  7444. }
  7445. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7446. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7447. advice.SingleDoseUnit = singleDoseUnit
  7448. }
  7449. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7450. deliveryWay, _ := json["delivery_way"].(string)
  7451. advice.DeliveryWay = deliveryWay
  7452. }
  7453. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7454. executionFrequency, _ := json["execution_frequency"].(string)
  7455. advice.ExecutionFrequency = executionFrequency
  7456. }
  7457. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7458. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7459. advice.Price = price
  7460. }
  7461. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7462. med_list_codg, _ := json["medical_insurance_number"].(string)
  7463. advice.MedListCodg = med_list_codg
  7464. }
  7465. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7466. day := int64(json["day"].(float64))
  7467. advice.Day = day
  7468. }
  7469. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7470. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7471. advice.PrescribingNumberUnit = prescribingNumberUnit
  7472. }
  7473. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7474. advice_id := int64(json["advice_id"].(float64))
  7475. advice.ID = advice_id
  7476. if advice.ID > 0 {
  7477. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7478. if err == nil {
  7479. if hisAdvice.ID > 0 {
  7480. advice.ExecutionTime = hisAdvice.ExecutionTime
  7481. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7482. advice.ExecutionState = hisAdvice.ExecutionState
  7483. advice.CheckTime = hisAdvice.CheckTime
  7484. advice.Checker = hisAdvice.Checker
  7485. advice.CheckState = hisAdvice.CheckState
  7486. advice.StartTime = hisAdvice.StartTime
  7487. advice.HospApprFlag = hisAdvice.HospApprFlag
  7488. advice.IsMedicine = hisAdvice.IsMedicine
  7489. if hisAdvice.UserOrgId == 10028 {
  7490. 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 {
  7491. advice.ExecutionTime = 0
  7492. advice.ExecutionStaff = 0
  7493. advice.ExecutionState = 2
  7494. advice.CheckTime = 0
  7495. advice.Checker = 0
  7496. advice.CheckState = 2
  7497. }
  7498. } else {
  7499. 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 {
  7500. advice.ExecutionTime = 0
  7501. advice.ExecutionStaff = 0
  7502. advice.ExecutionState = 2
  7503. advice.CheckTime = 0
  7504. advice.Checker = 0
  7505. advice.CheckState = 2
  7506. //advice.UpdatedTime = time.Now().Unix()
  7507. advice.CreatedTime = hisAdvice.CreatedTime
  7508. advice.UpdatedTime = time.Now().Unix()
  7509. } else {
  7510. advice.CreatedTime = hisAdvice.CreatedTime
  7511. advice.UpdatedTime = hisAdvice.UpdatedTime
  7512. }
  7513. }
  7514. //advice.Groupno = hisAdvice.Groupno
  7515. } else {
  7516. advice.IsMedicine = 0
  7517. ctime := time.Now().Unix()
  7518. advice.CreatedTime = ctime
  7519. advice.UpdatedTime = ctime
  7520. }
  7521. }
  7522. } else {
  7523. advice.IsMedicine = 0
  7524. ctime := time.Now().Unix()
  7525. advice.CreatedTime = ctime
  7526. advice.UpdatedTime = ctime
  7527. }
  7528. }
  7529. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7530. //
  7531. //if drugStockConfig.IsOpen == 1 {
  7532. //
  7533. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7534. // if advice.ID == 0 { //医嘱不存在
  7535. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7536. // drug.Total = drug.Total - advice.PrescribingNumber
  7537. // service.UpdateBaseDrugLib(&drug)
  7538. //
  7539. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7540. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7541. // drug.Total = drug.Total - num
  7542. // service.UpdateBaseDrugLib(&drug)
  7543. // }
  7544. //
  7545. // } else if advice.ID > 0 { //医嘱存在
  7546. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7547. // var num float64
  7548. //
  7549. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7550. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7551. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7552. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7553. // drug.Total = drug.Total + num
  7554. // service.UpdateBaseDrugLib(&drug)
  7555. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7556. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7557. // drug.Total = drug.Total - num
  7558. // service.UpdateBaseDrugLib(&drug)
  7559. // }
  7560. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7561. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7562. // if num2 > advice.PrescribingNumber {
  7563. // num = num2 - advice.PrescribingNumber
  7564. // drug.Total = drug.Total + num
  7565. // service.UpdateBaseDrugLib(&drug)
  7566. // } else if num2 < advice.PrescribingNumber {
  7567. // num = advice.PrescribingNumber - num2
  7568. // drug.Total = drug.Total - num
  7569. // service.UpdateBaseDrugLib(&drug)
  7570. // }
  7571. //
  7572. // }
  7573. //
  7574. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7575. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7576. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7577. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7578. // if num1 > num2 {
  7579. // num = num1 - num2
  7580. // drug.Total = drug.Total + num
  7581. // service.UpdateBaseDrugLib(&drug)
  7582. // } else if num1 < num2 {
  7583. // num = num2 - num1
  7584. // drug.Total = drug.Total - num
  7585. // service.UpdateBaseDrugLib(&drug)
  7586. // }
  7587. //
  7588. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7589. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7590. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7591. // if hisAdvice.PrescribingNumber > num2 {
  7592. // num = hisAdvice.PrescribingNumber - num2
  7593. // drug.Total = drug.Total + num
  7594. // service.UpdateBaseDrugLib(&drug)
  7595. // } else if num2 < advice.PrescribingNumber {
  7596. // num = num2 - hisAdvice.PrescribingNumber
  7597. // drug.Total = drug.Total - num
  7598. // service.UpdateBaseDrugLib(&drug)
  7599. // }
  7600. //
  7601. // }
  7602. // }
  7603. // }
  7604. //}
  7605. //
  7606. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7607. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7608. // advice.ExecutionTime = execution_time
  7609. //}
  7610. //
  7611. //
  7612. //
  7613. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7614. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7615. // advice.ExecutionStaff = execution_staff
  7616. //}
  7617. //
  7618. //
  7619. //
  7620. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7621. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7622. // advice.ExecutionState = execution_state
  7623. //}
  7624. //
  7625. //
  7626. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7627. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7628. // advice.CheckTime = check_time
  7629. //}
  7630. //
  7631. //
  7632. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7633. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7634. // advice.CheckState = check_state
  7635. //}
  7636. //
  7637. //
  7638. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7639. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7640. // advice.Checker = checker
  7641. //}
  7642. //
  7643. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7644. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7645. // advice.StartTime = start_time
  7646. //}
  7647. return 0
  7648. }
  7649. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7650. project.ExecutionStaff = 0
  7651. project.ExecutionState = 2
  7652. project.ExecutionTime = 0
  7653. project.Checker = 0
  7654. project.CheckState = 2
  7655. project.CheckTime = 0
  7656. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7657. id := int64(json["id"].(float64))
  7658. project.ID = id
  7659. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7660. project.ExecutionStaff = temp_project.ExecutionStaff
  7661. project.ExecutionState = temp_project.ExecutionState
  7662. project.ExecutionTime = temp_project.ExecutionTime
  7663. project.Checker = temp_project.Checker
  7664. project.CheckState = temp_project.CheckState
  7665. project.CheckTime = temp_project.CheckTime
  7666. project.TeamId = temp_project.TeamId
  7667. }
  7668. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7669. types := int64(json["type"].(float64))
  7670. project.Type = types
  7671. }
  7672. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7673. project_id := int64(json["project_id"].(float64))
  7674. project.ProjectId = project_id
  7675. }
  7676. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7677. team_id := int64(json["team_id"].(float64))
  7678. project.TeamId = team_id
  7679. }
  7680. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7681. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7682. project.Price = price
  7683. }
  7684. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7685. total, _ := json["total"].(string)
  7686. //totals, _ := strconv.ParseInt(total, 10, 64)
  7687. project.Count = total
  7688. }
  7689. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7690. medical_code, _ := json["medical_code"].(string)
  7691. project.MedListCodg = medical_code
  7692. }
  7693. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7694. single_dose, _ := json["single_dose"].(string)
  7695. project.SingleDose = single_dose
  7696. }
  7697. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7698. delivery_way, _ := json["delivery_way"].(string)
  7699. project.DeliveryWay = delivery_way
  7700. }
  7701. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7702. execution_frequency, _ := json["execution_frequency"].(string)
  7703. project.ExecutionFrequency = execution_frequency
  7704. }
  7705. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7706. remark, _ := json["remark"].(string)
  7707. project.Remark = remark
  7708. }
  7709. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7710. day, _ := json["number_days"].(string)
  7711. project.Day = day
  7712. }
  7713. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7714. unit, _ := json["unit"].(string)
  7715. project.Unit = unit
  7716. }
  7717. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7718. // frequency_type := int64(json["frequency_type"].(float64))
  7719. // project.FrequencyType = frequency_type
  7720. //}
  7721. //
  7722. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7723. // day_count := int64(json["day_count"].(float64))
  7724. // project.DayCount = day_count
  7725. //}
  7726. //
  7727. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7728. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7729. // week_day, _ := json["week_day"].(string)
  7730. // project.WeekDay = week_day
  7731. //}
  7732. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7733. //
  7734. //if project.ID == 0 {
  7735. // if stockConfig.IsOpen == 1 {
  7736. // if project.Type == 3 {
  7737. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7738. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7739. // good.Total = good.Total - f_count
  7740. // service.UpdateGoodInfo(&good)
  7741. // }
  7742. // }
  7743. //
  7744. //} else {
  7745. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7746. //
  7747. // if stockConfig.IsOpen == 1 {
  7748. // if project.Type == 3 {
  7749. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7750. // if project.Count < temp_project.Count {
  7751. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7752. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7753. //
  7754. // other_count := f_count_two - f_count_one
  7755. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7756. // good.Total = good.Total + other_count_two
  7757. // service.UpdateGoodInfo(&good)
  7758. // } else if project.Count > temp_project.Count {
  7759. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7760. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7761. //
  7762. // other_count := f_count_one - f_count_two
  7763. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7764. // good.Total = good.Total - other_count_two
  7765. // service.UpdateGoodInfo(&good)
  7766. // }
  7767. //
  7768. // }
  7769. // }
  7770. //
  7771. //}
  7772. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7773. id := int64(json["id"].(float64))
  7774. if id > 0 {
  7775. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7776. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7777. fmt.Println("666666")
  7778. project.Mtime = time.Now().Unix()
  7779. project.Ctime = temp_project.Ctime
  7780. } else {
  7781. project.Mtime = temp_project.Mtime
  7782. project.Ctime = temp_project.Ctime
  7783. }
  7784. } else {
  7785. ctime := time.Now().Unix()
  7786. project.Mtime = ctime
  7787. project.Ctime = ctime
  7788. }
  7789. }
  7790. return 0
  7791. }
  7792. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7793. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7794. id := int64(json["id"].(float64))
  7795. additionalCharge.ID = id
  7796. }
  7797. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7798. item_id := int64(json["item_id"].(float64))
  7799. additionalCharge.ItemId = item_id
  7800. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7801. if config.ID > 0 {
  7802. if len(config.Code) > 0 {
  7803. additionalCharge.MedListCodg = config.Code
  7804. }
  7805. }
  7806. }
  7807. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7808. // price := int64(json["price"].(float64))
  7809. // formatInt_price := strconv.FormatInt(price, 10)
  7810. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7811. // additionalCharge.Price = float_price
  7812. // }
  7813. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7814. // price := int64(json["price"].(float64))
  7815. // formatInt_price := strconv.FormatInt(price, 10)
  7816. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7817. // additionalCharge.Price = float_price
  7818. //}
  7819. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7820. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7821. additionalCharge.Price = price
  7822. }
  7823. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7824. count, _ := json["count"].(string)
  7825. counts, _ := strconv.ParseInt(count, 10, 64)
  7826. additionalCharge.Count = counts
  7827. }
  7828. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7829. item_name, _ := json["item_name"].(string)
  7830. additionalCharge.ItemName = item_name
  7831. }
  7832. return 0
  7833. }
  7834. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7835. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7836. utils.ErrorLog("drug_name")
  7837. return enums.ErrorCodeParamWrong
  7838. }
  7839. adviceName, _ := json["drug_name"].(string)
  7840. if len(adviceName) == 0 {
  7841. utils.ErrorLog("len(advice_name) == 0")
  7842. return enums.ErrorCodeParamWrong
  7843. }
  7844. advice.AdviceName = adviceName
  7845. adviceDesc, _ := json["advice_desc"].(string)
  7846. advice.AdviceDesc = adviceDesc
  7847. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7848. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7849. advice.DrugSpec = drugSpec
  7850. }
  7851. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7852. remark, _ := json["remark"].(string)
  7853. advice.Remark = remark
  7854. }
  7855. if json["id"] == nil {
  7856. advice.DrugId = 0
  7857. } else {
  7858. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7859. drug_id := int64(json["id"].(float64))
  7860. advice.DrugId = drug_id
  7861. }
  7862. }
  7863. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7864. groupno := int64(json["groupno"].(float64))
  7865. advice.Groupno = groupno
  7866. }
  7867. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7868. drugSpecUnit, _ := json["min_unit"].(string)
  7869. advice.DrugSpecUnit = drugSpecUnit
  7870. }
  7871. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7872. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7873. advice.SingleDose = singleDose
  7874. }
  7875. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7876. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7877. advice.SingleDoseUnit = singleDoseUnit
  7878. }
  7879. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7880. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7881. advice.PrescribingNumber = prescribingNumber
  7882. }
  7883. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7884. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7885. advice.PrescribingNumberUnit = prescribingNumberUnit
  7886. }
  7887. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7888. deliveryWay, _ := json["delivery_way"].(string)
  7889. advice.DeliveryWay = deliveryWay
  7890. }
  7891. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7892. executionFrequency, _ := json["execution_frequency"].(string)
  7893. advice.ExecutionFrequency = executionFrequency
  7894. }
  7895. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7896. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7897. advice.Price = price
  7898. }
  7899. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7900. med_list_codg, _ := json["medical_insurance_number"].(string)
  7901. advice.MedListCodg = med_list_codg
  7902. }
  7903. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7904. day := int64(json["day"].(float64))
  7905. advice.Day = day
  7906. }
  7907. advice.FrequencyType = 1
  7908. return 0
  7909. }
  7910. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7911. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7912. types := int64(json["type"].(float64))
  7913. project.Type = types
  7914. }
  7915. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7916. project_id := int64(json["project_id"].(float64))
  7917. project.ProjectId = project_id
  7918. }
  7919. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7920. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7921. project.Price = price
  7922. }
  7923. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7924. total, _ := json["total"].(string)
  7925. //totals, _ := strconv.ParseInt(total, 10, 64)
  7926. project.Count = total
  7927. }
  7928. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7929. medical_code, _ := json["medical_code"].(string)
  7930. project.MedListCodg = medical_code
  7931. }
  7932. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7933. single_dose, _ := json["single_dose"].(string)
  7934. project.SingleDose = single_dose
  7935. }
  7936. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7937. delivery_way, _ := json["delivery_way"].(string)
  7938. project.DeliveryWay = delivery_way
  7939. }
  7940. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7941. execution_frequency, _ := json["execution_frequency"].(string)
  7942. project.ExecutionFrequency = execution_frequency
  7943. }
  7944. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7945. remark, _ := json["remark"].(string)
  7946. project.Remark = remark
  7947. }
  7948. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7949. day, _ := json["number_days"].(string)
  7950. project.Day = day
  7951. }
  7952. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7953. unit, _ := json["unit"].(string)
  7954. project.Unit = unit
  7955. }
  7956. project.FrequencyType = 1
  7957. return 0
  7958. }
  7959. func (c *HisApiController) GetHisOrderListTwo() {
  7960. start_time := c.GetString("start_time")
  7961. end_time := c.GetString("end_time")
  7962. timeLayout := "2006-01-02"
  7963. loc, _ := time.LoadLocation("Local")
  7964. var startTime int64
  7965. if len(start_time) > 0 {
  7966. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7967. if err != nil {
  7968. //fmt.Println(err)
  7969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7970. return
  7971. }
  7972. startTime = theTime.Unix()
  7973. }
  7974. var endTime int64
  7975. if len(end_time) > 0 {
  7976. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7977. if err != nil {
  7978. utils.ErrorLog(err.Error())
  7979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7980. return
  7981. }
  7982. endTime = theTime.Unix()
  7983. }
  7984. adminUser := c.GetAdminUserInfo()
  7985. org_id := adminUser.CurrentOrgId
  7986. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7987. if err == nil {
  7988. c.ServeSuccessJSON(map[string]interface{}{
  7989. "order2": order,
  7990. })
  7991. } else {
  7992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7993. return
  7994. }
  7995. }
  7996. func (c *HisApiController) GetHisOrderList() {
  7997. page, _ := c.GetInt64("page", -1)
  7998. limit, _ := c.GetInt64("limit", -1)
  7999. start_time := c.GetString("start_time")
  8000. end_time := c.GetString("end_time")
  8001. types, _ := c.GetInt64("type", 0)
  8002. keywords := c.GetString("keywords")
  8003. p_type, _ := c.GetInt64("p_type", 0)
  8004. sort_type, _ := c.GetInt64("sort_type", 0)
  8005. charge_type, _ := c.GetInt64("charge_type", 0)
  8006. sch_type, _ := c.GetInt64("sch_type", 0)
  8007. zone_type, _ := c.GetInt64("zone_type", 0)
  8008. med_type, _ := c.GetInt64("med_type", 0)
  8009. timeLayout := "2006-01-02"
  8010. loc, _ := time.LoadLocation("Local")
  8011. var startTime int64
  8012. if len(start_time) > 0 {
  8013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8014. if err != nil {
  8015. //fmt.Println(err)
  8016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8017. return
  8018. }
  8019. startTime = theTime.Unix()
  8020. }
  8021. var endTime int64
  8022. if len(end_time) > 0 {
  8023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8024. if err != nil {
  8025. utils.ErrorLog(err.Error())
  8026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8027. return
  8028. }
  8029. endTime = theTime.Unix()
  8030. }
  8031. adminUser := c.GetAdminUserInfo()
  8032. org_id := adminUser.CurrentOrgId
  8033. 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)
  8034. for _, item := range order {
  8035. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8036. item.DoctorName = info.Doctor
  8037. item.DepartmentName = info.XtHisDepartment.Name
  8038. }
  8039. if err == nil {
  8040. c.ServeSuccessJSON(map[string]interface{}{
  8041. "order": order,
  8042. "total": total,
  8043. })
  8044. } else {
  8045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8046. return
  8047. }
  8048. }
  8049. func (c *HisApiController) GetHisOrder() {
  8050. patient_id, _ := c.GetInt64("patient_id", 0)
  8051. number := c.GetString("number")
  8052. adminInfo := c.GetAdminUserInfo()
  8053. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8054. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8055. if err == nil {
  8056. c.ServeSuccessJSON(map[string]interface{}{
  8057. "order": order,
  8058. "prescription": prescriptions,
  8059. })
  8060. } else {
  8061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8062. return
  8063. }
  8064. }
  8065. func (c *HisApiController) GetHisPrescriptionList() {
  8066. record_date := c.GetString("record_date")
  8067. keywords := c.GetString("keywords")
  8068. page, _ := c.GetInt64("page")
  8069. limit, _ := c.GetInt64("limit")
  8070. sch_type, _ := c.GetInt64("sch_type")
  8071. timeLayout := "2006-01-02"
  8072. loc, _ := time.LoadLocation("Local")
  8073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8074. if err != nil {
  8075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8076. return
  8077. }
  8078. recordDateTime := theTime.Unix()
  8079. adminInfo := c.GetAdminUserInfo()
  8080. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8081. //adminInfo := c.GetAdminUserInfo()
  8082. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8083. //fmt.Println(prescriptionOrder)
  8084. if err == nil {
  8085. c.ServeSuccessJSON(map[string]interface{}{
  8086. "order": prescriptionOrder,
  8087. "total": total,
  8088. })
  8089. } else {
  8090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8091. return
  8092. }
  8093. }
  8094. func (c *HisApiController) GetHisPrescriptionInfo() {
  8095. id, _ := c.GetInt64("id")
  8096. adminInfo := c.GetAdminUserInfo()
  8097. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8098. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8099. if err == nil {
  8100. c.ServeSuccessJSON(map[string]interface{}{
  8101. "order": prescriptionOrder,
  8102. "prescription": prescription,
  8103. })
  8104. } else {
  8105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8106. return
  8107. }
  8108. }
  8109. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8110. adminUser := c.GetAdminUserInfo()
  8111. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8112. c.ServeSuccessJSON(map[string]interface{}{
  8113. "config": config,
  8114. })
  8115. }
  8116. type ResultTwo struct {
  8117. ErrMsg interface{} `json:"err_msg"`
  8118. InfRefmsgid string `json:"inf_refmsgid"`
  8119. Infcode int64 `json:"infcode"`
  8120. Output struct {
  8121. Baseinfo struct {
  8122. Age float64 `json:"age"`
  8123. Brdy string `json:"brdy"`
  8124. Certno string `json:"certno"`
  8125. Gend string `json:"gend"`
  8126. Naty string `json:"naty"`
  8127. PsnCertType string `json:"psn_cert_type"`
  8128. PsnName string `json:"psn_name"`
  8129. PsnNo string `json:"psn_no"`
  8130. } `json:"baseinfo"`
  8131. Idetinfo []interface{} `json:"idetinfo"`
  8132. Iinfo []struct {
  8133. Balc float64 `json:"balc"`
  8134. CvlservFlag string `json:"cvlserv_flag"`
  8135. EmpName string `json:"emp_name"`
  8136. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8137. Insutype string `json:"insutype"`
  8138. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8139. PausInsuDate interface{} `json:"paus_insu_date"`
  8140. PsnInsuDate string `json:"psn_insu_date"`
  8141. PsnInsuStas string `json:"psn_insu_stas"`
  8142. PsnType string `json:"psn_type"`
  8143. } `json:"insuinfo"`
  8144. } `json:"output"`
  8145. RefmsgTime string `json:"refmsg_time"`
  8146. RespondTime string `json:"respond_time"`
  8147. Signtype interface{} `json:"signtype"`
  8148. WarnInfo interface{} `json:"warn_info"`
  8149. }
  8150. type ResultThree struct {
  8151. Cainfo interface{} `json:"cainfo"`
  8152. ErrMsg interface{} `json:"err_msg"`
  8153. InfRefmsgid string `json:"inf_refmsgid"`
  8154. Infcode int64 `json:"infcode"`
  8155. Output struct {
  8156. Data struct {
  8157. IptOtpNo string `json:"ipt_otp_no"`
  8158. MdtrtID string `json:"mdtrt_id"`
  8159. PsnNo string `json:"psn_no"`
  8160. } `json:"data"`
  8161. } `json:"output"`
  8162. RefmsgTime string `json:"refmsg_time"`
  8163. RespondTime string `json:"respond_time"`
  8164. Signtype interface{} `json:"signtype"`
  8165. WarnMsg interface{} `json:"warn_msg"`
  8166. }
  8167. type ResultFour struct {
  8168. Cainfo string `json:"cainfo"`
  8169. ErrMsg string `json:"err_msg"`
  8170. InfRefmsgid string `json:"inf_refmsgid"`
  8171. Infcode int64 `json:"infcode"`
  8172. Output struct {
  8173. Result []struct {
  8174. BasMednFlag string `json:"bas_medn_flag"`
  8175. ChldMedcFlag string `json:"chld_medc_flag"`
  8176. ChrgitmLv string `json:"chrgitm_lv"`
  8177. Cnt float64 `json:"cnt"`
  8178. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8179. DrtReimFlag string `json:"drt_reim_flag"`
  8180. FeedetlSn string `json:"feedetl_sn"`
  8181. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8182. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8183. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8184. ListSpItemFlag string `json:"list_sp_item_flag"`
  8185. LmtUsedFlag string `json:"lmt_used_flag"`
  8186. MedChrgitmType string `json:"med_chrgitm_type"`
  8187. Memo string `json:"memo"`
  8188. OverlmtAmt float64 `json:"overlmt_amt"`
  8189. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8190. Pric float64 `json:"pric"`
  8191. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8192. SelfpayProp float64 `json:"selfpay_prop"`
  8193. } `json:"result"`
  8194. } `json:"output"`
  8195. RefmsgTime string `json:"refmsg_time"`
  8196. RespondTime string `json:"respond_time"`
  8197. Signtype string `json:"signtype"`
  8198. WarnMsg string `json:"warn_msg"`
  8199. }
  8200. type ResultFive struct {
  8201. Insutype string `json:"insutype"`
  8202. }
  8203. type ResultSix struct {
  8204. Cainfo interface{} `json:"cainfo"`
  8205. ErrMsg interface{} `json:"err_msg"`
  8206. InfRefmsgid string `json:"inf_refmsgid"`
  8207. Infcode int64 `json:"infcode"`
  8208. Output struct {
  8209. } `json:"output"`
  8210. RefmsgTime string `json:"refmsg_time"`
  8211. RespondTime string `json:"respond_time"`
  8212. Signtype interface{} `json:"signtype"`
  8213. WarnMsg interface{} `json:"warn_msg"`
  8214. }
  8215. type ResultSeven struct {
  8216. Cainfo string `json:"cainfo"`
  8217. ErrMsg string `json:"err_msg"`
  8218. InfRefmsgid string `json:"inf_refmsgid"`
  8219. Infcode int64 `json:"infcode"`
  8220. Output struct {
  8221. Setldetail []interface{} `json:"setldetail"`
  8222. Setlinfo struct {
  8223. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8224. AcctPay float64 `json:"acct_pay"`
  8225. ActPayDedc float64 `json:"act_pay_dedc"`
  8226. Age float64 `json:"age"`
  8227. Balc float64 `json:"balc"`
  8228. Brdy string `json:"brdy"`
  8229. Certno string `json:"certno"`
  8230. ClrOptins string `json:"clr_optins"`
  8231. ClrType string `json:"clr_type"`
  8232. ClrWay string `json:"clr_way"`
  8233. CvlservFlag string `json:"cvlserv_flag"`
  8234. CvlservPay float64 `json:"cvlserv_pay"`
  8235. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8236. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8237. Gend string `json:"gend"`
  8238. HifesPay float64 `json:"hifes_pay"`
  8239. HifmiPay float64 `json:"hifmi_pay"`
  8240. HifobPay float64 `json:"hifob_pay"`
  8241. HifpPay float64 `json:"hifp_pay"`
  8242. HospPartAmt float64 `json:"hosp_part_amt"`
  8243. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8244. Insutype string `json:"insutype"`
  8245. MafPay float64 `json:"maf_pay"`
  8246. MdtrtCertType string `json:"mdtrt_cert_type"`
  8247. MdtrtID string `json:"mdtrt_id"`
  8248. MedType string `json:"med_type"`
  8249. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8250. MedinsSetlID string `json:"medins_setl_id"`
  8251. Naty string `json:"naty"`
  8252. OthPay float64 `json:"oth_pay"`
  8253. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8254. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8255. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8256. PsnCashPay float64 `json:"psn_cash_pay"`
  8257. PsnCertType string `json:"psn_cert_type"`
  8258. PsnName string `json:"psn_name"`
  8259. PsnNo string `json:"psn_no"`
  8260. PsnPartAmt float64 `json:"psn_part_amt"`
  8261. PsnType string `json:"psn_type"`
  8262. SetlID string `json:"setl_id"`
  8263. SetlTime string `json:"setl_time"`
  8264. } `json:"setlinfo"`
  8265. } `json:"output"`
  8266. RefmsgTime string `json:"refmsg_time"`
  8267. RespondTime string `json:"respond_time"`
  8268. Signtype interface{} `json:"signtype"`
  8269. WarnMsg interface{} `json:"warn_msg"`
  8270. }
  8271. type ResultEight struct {
  8272. Cainfo string `json:"cainfo"`
  8273. ErrMsg string `json:"err_msg"`
  8274. InfRefmsgid string `json:"inf_refmsgid"`
  8275. Infcode int64 `json:"infcode"`
  8276. Output struct {
  8277. Stmtinfo struct {
  8278. SetlOptins string `json:"setl_optins"`
  8279. StmtRslt string `json:"stmt_rslt"`
  8280. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8281. } `json:"stmtinfo"`
  8282. } `json:"output"`
  8283. RefmsgTime string `json:"refmsg_time"`
  8284. RespondTime string `json:"respond_time"`
  8285. Signtype interface{} `json:"signtype"`
  8286. WarnMsg interface{} `json:"warn_msg"`
  8287. }
  8288. type ResultNine struct {
  8289. Cainfo string `json:"cainfo"`
  8290. ErrMsg string `json:"err_msg"`
  8291. InfRefmsgid string `json:"inf_refmsgid"`
  8292. Infcode int64 `json:"infcode"`
  8293. Output struct {
  8294. FileQuryNo string `json:"file_qury_no"`
  8295. } `json:"output"`
  8296. RefmsgTime string `json:"refmsg_time"`
  8297. RespondTime string `json:"respond_time"`
  8298. Signtype interface{} `json:"signtype"`
  8299. WarnMsg interface{} `json:"warn_msg"`
  8300. }
  8301. type ResultTen struct {
  8302. Cainfo string `json:"cainfo"`
  8303. ErrMsg string `json:"err_msg"`
  8304. InfRefmsgid string `json:"inf_refmsgid"`
  8305. Infcode int64 `json:"infcode"`
  8306. Output struct {
  8307. DldEndtime string `json:"dld_endtime"`
  8308. FileQuryNo string `json:"file_qury_no"`
  8309. Filename string `json:"filename"`
  8310. } `json:"output"`
  8311. RefmsgTime string `json:"refmsg_time"`
  8312. RespondTime string `json:"respond_time"`
  8313. Signtype interface{} `json:"signtype"`
  8314. WarnMsg interface{} `json:"warn_msg"`
  8315. }
  8316. type ResultEleven struct {
  8317. Cainfo string `json:"cainfo"`
  8318. ErrMsg string `json:"err_msg"`
  8319. InfRefmsgid string `json:"inf_refmsgid"`
  8320. Infcode int64 `json:"infcode"`
  8321. Output struct {
  8322. Setlinfo struct {
  8323. FixmedinsName string `json:"fixmedins_name"`
  8324. FixmedinsCode string `json:"fixmedins_code"`
  8325. PsnNo string `json:"psn_no"`
  8326. PsnName string `json:"psn_name"`
  8327. HifobPay float64 `json:"hifob_pay"`
  8328. Gend string `json:"gend"`
  8329. Brdy string `json:"brdy"`
  8330. PsnCertType string `json:"psn_cert_type"`
  8331. PsnType string `json:"psn_type"`
  8332. EmpName string `json:"emp_name"`
  8333. Certno string `json:"certno"`
  8334. Insutype string `json:"insutype"`
  8335. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8336. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8337. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8338. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8339. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8340. ActPayDedc float64 `json:"act_pay_dedc"`
  8341. HifpPay float64 `json:"hifp_pay"`
  8342. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8343. CvlservPay float64 `json:"cvlserv_pay"`
  8344. HifesPay float64 `json:"hifes_pay"`
  8345. HifmiPay float64 `json:"hifmi_pay"`
  8346. MafPay float64 `json:"maf_pay"`
  8347. OthPay float64 `json:"oth_pay"`
  8348. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8349. PsnPay float64 `json:"psn_pay"`
  8350. AcctPay float64 `json:"acct_pay"`
  8351. CashPayamt float64 `json:"cash_payamt"`
  8352. Balc float64 `json:"balc"`
  8353. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8354. MedinsSetlId string `json:"medins_setl_id"`
  8355. RefdSetlFlag string `json:"refd_setl_flag"`
  8356. SetlTime string `json:"setl_time"`
  8357. MedType string `json:"med_type"`
  8358. } `json:"setlinfo"`
  8359. } `json:"output"`
  8360. RefmsgTime string `json:"refmsg_time"`
  8361. RespondTime string `json:"respond_time"`
  8362. Signtype interface{} `json:"signtype"`
  8363. WarnMsg interface{} `json:"warn_msg"`
  8364. }
  8365. type Custom struct {
  8366. DetItemFeeSumamt string
  8367. Cut string
  8368. FeedetlSn string
  8369. Price string
  8370. MedListCodg string
  8371. Type int64
  8372. AdviceId int64
  8373. ProjectId int64
  8374. ItemId int64
  8375. CostType int64
  8376. }
  8377. // 获取个人信息----挂号-----上传就诊信息
  8378. func (c *HisApiController) GetRegisterInfo() {
  8379. id, _ := c.GetInt64("id")
  8380. record_time := c.GetString("record_time")
  8381. settlementValue, _ := c.GetInt64("settlement_value")
  8382. medical_insurance_card := c.GetString("medical_insurance_card")
  8383. name := c.GetString("name")
  8384. id_card_type, _ := c.GetInt64("id_card_type")
  8385. certificates, _ := c.GetInt64("certificates")
  8386. medical_care, _ := c.GetInt64("medical_care")
  8387. birthday := c.GetString("birthday")
  8388. age, _ := c.GetInt64("age")
  8389. id_card := c.GetString("id_card")
  8390. register_type, _ := c.GetInt64("register")
  8391. doctor, _ := c.GetInt64("doctor")
  8392. department, _ := c.GetInt64("department")
  8393. gender, _ := c.GetInt64("sex")
  8394. phone := c.GetString("phone")
  8395. registration_fee, _ := c.GetFloat("registration_fee")
  8396. medical_expenses, _ := c.GetFloat("medical_expenses")
  8397. social_type, _ := c.GetInt64("social_type")
  8398. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8399. diagnosis_ids := c.GetString("diagnosis")
  8400. sick_type, _ := c.GetInt64("sick_type")
  8401. reg_type := c.GetString("p_type")
  8402. timeLayout := "2006-01-02"
  8403. loc, _ := time.LoadLocation("Local")
  8404. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8405. birthUnix := birthdays.Unix()
  8406. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8407. if err != nil {
  8408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8409. return
  8410. }
  8411. recordDateTime := theTime.Unix()
  8412. adminInfo := c.GetAdminUserInfo()
  8413. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8414. if tempPatient.ID == 0 {
  8415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8416. return
  8417. }
  8418. var patient service.Patients
  8419. if id == 0 {
  8420. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8421. } else {
  8422. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8423. }
  8424. if patient.ID == 0 {
  8425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8426. return
  8427. }
  8428. if len(patient.IdCardNo) == 0 {
  8429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8430. return
  8431. }
  8432. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8433. if len(his) >= 1 {
  8434. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8435. if len(his) >= 1 && order.ID == 0 {
  8436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8437. return
  8438. }
  8439. }
  8440. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8441. fmt.Println(timeStr)
  8442. timeArr := strings.Split(timeStr, " ")
  8443. fmt.Println(timeArr)
  8444. timeArrTwo := strings.Split(timeArr[0], "-")
  8445. timeArrThree := strings.Split(timeArr[1], ":")
  8446. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8447. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8448. if len(lists) == 0 {
  8449. var hisPatient models.XtHisPatient
  8450. hisPatient = models.XtHisPatient{
  8451. Name: name,
  8452. Age: age,
  8453. Gender: gender,
  8454. Birthday: birthUnix,
  8455. Phone: phone,
  8456. MedicalTreatmentType: medical_care,
  8457. IdType: certificates,
  8458. IdCardNo: id_card,
  8459. BalanceAccountsType: settlementValue,
  8460. SocialType: social_type,
  8461. MedicalInsuranceNumber: medical_insurance_card,
  8462. RegisterType: register_type,
  8463. RegisterCost: registration_fee,
  8464. TreatmentCost: medical_expenses,
  8465. AdminUserId: adminInfo.AdminUser.Id,
  8466. UserOrgId: adminInfo.CurrentOrgId,
  8467. Status: 1,
  8468. RecordDate: recordDateTime,
  8469. IsReturn: 1,
  8470. PatientId: patient.ID,
  8471. Ctime: time.Now().Unix(),
  8472. Mtime: time.Now().Unix(),
  8473. Number: str,
  8474. IdCardType: id_card_type,
  8475. Departments: department,
  8476. Doctor: doctor,
  8477. PType: reg_type,
  8478. Diagnosis: diagnosis_ids,
  8479. SickType: sick_type,
  8480. }
  8481. service.CreateHisPatient(&hisPatient)
  8482. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8483. c.ServeSuccessJSON(map[string]interface{}{
  8484. "his_info": hisPatient,
  8485. })
  8486. } else {
  8487. //chrgBchno := rand.Intn(1000000) + 10000
  8488. var hisPatient models.XtHisPatient
  8489. hisPatient = models.XtHisPatient{
  8490. Name: name,
  8491. Age: age,
  8492. Gender: gender,
  8493. Birthday: birthUnix,
  8494. Phone: phone,
  8495. MedicalTreatmentType: medical_care,
  8496. IdType: certificates,
  8497. IdCardNo: id_card,
  8498. BalanceAccountsType: settlementValue,
  8499. SocialType: social_type,
  8500. MedicalInsuranceNumber: medical_insurance_card,
  8501. RegisterType: register_type,
  8502. RegisterCost: registration_fee,
  8503. TreatmentCost: medical_expenses,
  8504. AdminUserId: adminInfo.AdminUser.Id,
  8505. UserOrgId: adminInfo.CurrentOrgId,
  8506. Status: 1,
  8507. RecordDate: recordDateTime,
  8508. IsReturn: 1,
  8509. PatientId: patient.ID,
  8510. Ctime: time.Now().Unix(),
  8511. Mtime: time.Now().Unix(),
  8512. Number: str,
  8513. IdCardType: id_card_type,
  8514. Departments: department,
  8515. Doctor: doctor,
  8516. PType: reg_type,
  8517. Diagnosis: diagnosis_ids,
  8518. SickType: sick_type,
  8519. }
  8520. service.CreateHisPatient(&hisPatient)
  8521. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8522. c.ServeSuccessJSON(map[string]interface{}{
  8523. "his_info": hisPatient,
  8524. })
  8525. }
  8526. }
  8527. // 上传明细----结算
  8528. func (c *HisApiController) GetUploadInfo() {
  8529. id, _ := c.GetInt64("id")
  8530. record_time := c.GetString("record_time")
  8531. his_patient_id, _ := c.GetInt64("his_patient_id")
  8532. oth_desc := c.GetString("oth_desc")
  8533. pay_way, _ := c.GetInt64("pay_way")
  8534. pay_ways := c.GetString("pay_ways")
  8535. pay_price, _ := c.GetFloat("pay_price")
  8536. pay_card_no := c.GetString("pay_card_no")
  8537. discount_price, _ := c.GetFloat("discount_price")
  8538. preferential_price, _ := c.GetFloat("preferential_price")
  8539. reality_price, _ := c.GetFloat("reality_price")
  8540. found_price, _ := c.GetFloat("found_price")
  8541. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8542. private_price, _ := c.GetFloat("private_price")
  8543. timeLayout := "2006-01-02"
  8544. loc, _ := time.LoadLocation("Local")
  8545. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8546. fapiao_code := c.GetString("fapiao_code")
  8547. fapiao_number := c.GetString("fapiao_number")
  8548. diagnosis_id := c.GetString("diagnosis")
  8549. sick_type, _ := c.GetInt64("sick_type")
  8550. reg_type, _ := c.GetInt64("p_type")
  8551. order_id, _ := c.GetInt64("order_id")
  8552. cash_pay := c.GetString("cash_pay")
  8553. wechat_pay := c.GetString("wechat_pay")
  8554. ali_pay := c.GetString("ali_pay")
  8555. jifen_pay := c.GetString("jifen_pay")
  8556. band_card_pay := c.GetString("band_card_pay")
  8557. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8558. tmp_decimal := c.GetString("tmp_decimal")
  8559. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8560. var decimal float64 //本次使用的押金
  8561. var errmsg error
  8562. tx := service.XTWriteDB().Begin() //开了事务
  8563. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8564. defer func() {
  8565. if errmsg != nil {
  8566. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8567. tx.Rollback()
  8568. } else {
  8569. tx.Commit()
  8570. }
  8571. }()
  8572. fmt.Println("dec_way", dec_way)
  8573. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8574. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8575. return
  8576. }
  8577. if len(tmp_decimal) > 0 {
  8578. if tmp_decimal[0] == 45 {
  8579. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8580. return
  8581. }
  8582. }
  8583. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8584. fmt.Println(errs)
  8585. decimal = tt
  8586. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8587. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8589. if err != nil {
  8590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8591. return
  8592. }
  8593. recordDateTime := theTime.Unix()
  8594. adminUser := c.GetAdminUserInfo()
  8595. var prescriptions []*models.HisPrescription
  8596. var prescriptionsOne []*models.HisPrescription
  8597. var start_time int64
  8598. var end_time int64
  8599. ids_str := c.GetString("ids")
  8600. ids_arr := strings.Split(ids_str, ",")
  8601. if tempOrder.ID == 0 {
  8602. if settle_accounts_type == 1 { //日结
  8603. fmt.Println(reg_type)
  8604. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8605. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8606. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8607. } else {
  8608. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8609. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8610. }
  8611. } else { //月结
  8612. start_time_str := c.GetString("start_time")
  8613. end_time_str := c.GetString("end_time")
  8614. timeLayout := "2006-01-02"
  8615. loc, _ := time.LoadLocation("Local")
  8616. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8617. if err != nil {
  8618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8619. return
  8620. }
  8621. recordStartTime := theStartTime.Unix()
  8622. start_time = recordStartTime
  8623. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8624. if err != nil {
  8625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8626. return
  8627. }
  8628. recordEndTime := theEndTime.Unix()
  8629. end_time = recordEndTime
  8630. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8631. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8632. }
  8633. var goods []*models.DialysisBeforePrepareGoods
  8634. var newGoods []*models.NewDialysisBeforePrepareGoods
  8635. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8636. var infos []*models.HisDoctorAdviceInfo
  8637. var infoList []*models.HisDoctorAdviceInfo
  8638. var hisAdvice []*models.HisDoctorAdviceInfo
  8639. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8640. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8641. //判断库存不足
  8642. //结算出库开关
  8643. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8644. if settConfig.IsOpen == 1 {
  8645. //判断库存的地方
  8646. for _, info := range prescriptions {
  8647. if info.Type == 1 {
  8648. infos = append(infos, info.HisDoctorAdviceInfo...)
  8649. }
  8650. if info.Type == 2 {
  8651. for _, sumItem := range info.HisPrescriptionProject {
  8652. if sumItem.Type == 3 {
  8653. var good models.DialysisBeforePrepareGoods
  8654. var newGood models.NewDialysisBeforePrepareGoods
  8655. good.GoodId = sumItem.GoodInfo.ID
  8656. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8657. count, _ := strconv.Atoi(sumItem.Count)
  8658. good.Count = int64(count)
  8659. good.StorehouseId = houseConfig.StorehouseOutInfo
  8660. good.ProjectId = sumItem.ID
  8661. goods = append(goods, &good)
  8662. newGood.GoodId = sumItem.GoodInfo.ID
  8663. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8664. count2, _ := strconv.Atoi(sumItem.Count)
  8665. newGood.Count = int64(count2)
  8666. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8667. newGood.ProjectId = sumItem.ID
  8668. newGoods = append(newGoods, &newGood)
  8669. }
  8670. }
  8671. }
  8672. }
  8673. for _, info := range prescriptionsOne {
  8674. if info.Type == 1 {
  8675. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8676. }
  8677. if info.Type == 2 {
  8678. for _, sumItem := range info.HisPrescriptionProject {
  8679. if sumItem.Type == 3 {
  8680. var newGood models.NewDialysisBeforePrepareGoods
  8681. newGood.GoodId = sumItem.GoodInfo.ID
  8682. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8683. count2, _ := strconv.Atoi(sumItem.Count)
  8684. newGood.Count = int64(count2)
  8685. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8686. newGood.ProjectId = sumItem.ID
  8687. newGoodOne = append(newGoodOne, &newGood)
  8688. }
  8689. }
  8690. }
  8691. }
  8692. //判断
  8693. for _, itemOne := range infos {
  8694. for _, itemTwo := range hisAdvice {
  8695. if itemOne.DrugId == itemTwo.DrugId {
  8696. itemTwo.Child = append(itemTwo.Child, itemOne)
  8697. }
  8698. }
  8699. }
  8700. for _, itemTwo := range hisAdvice {
  8701. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8702. var sum_out_count int64
  8703. for _, itemThree := range itemTwo.Child {
  8704. var prescribing_number int64
  8705. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8706. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8707. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8708. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8709. }
  8710. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8711. prescribing_number = parseIntPrescribingNumber
  8712. }
  8713. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8714. prescribing_number = parseIntPrescribingNumber
  8715. }
  8716. sum_out_count += prescribing_number
  8717. }
  8718. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8719. if sum_out_count > drugStockOut.FlushCount {
  8720. c.ServeSuccessJSON(map[string]interface{}{
  8721. "msg": "2",
  8722. "drug": medical,
  8723. })
  8724. return
  8725. }
  8726. }
  8727. for _, itemOne := range newGoods {
  8728. for _, item := range newGoodOne {
  8729. if itemOne.GoodId == item.GoodId {
  8730. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8731. }
  8732. }
  8733. }
  8734. for _, item := range newGoodOne {
  8735. var sum_out_count_one int64
  8736. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8737. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8738. sum_out_count_one += itemOne.Count
  8739. }
  8740. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8741. fmt.Println("sum_out_count_one", sum_out_count_one)
  8742. fmt.Println("list.FlushCount", list.FlushCount)
  8743. if sum_out_count_one > list.FlushCount {
  8744. c.ServeSuccessJSON(map[string]interface{}{
  8745. "msg": "3",
  8746. "good": good,
  8747. })
  8748. return
  8749. }
  8750. }
  8751. }
  8752. timestamp := time.Now().Unix()
  8753. tempTime := time.Unix(timestamp, 0)
  8754. timeFormat := tempTime.Format("20060102150405")
  8755. chrgBchno := rand.Intn(100000) + 10000
  8756. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8757. strconv.FormatInt(his.PatientId, 10)
  8758. var ids []int64
  8759. for _, item := range prescriptions {
  8760. ids = append(ids, item.ID)
  8761. }
  8762. var total float64
  8763. for _, item := range prescriptions {
  8764. fmt.Println(item)
  8765. if item.Type == 1 { //药品
  8766. for _, subItem := range item.HisDoctorAdviceInfo {
  8767. total = total + (subItem.Price * subItem.PrescribingNumber)
  8768. }
  8769. }
  8770. if item.Type == 2 { //项目
  8771. for _, subItem := range item.HisPrescriptionProject {
  8772. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8773. total = total + (subItem.Price * cnt)
  8774. }
  8775. }
  8776. for _, subItem := range item.HisAdditionalCharge {
  8777. total = total + (subItem.Price * float64(subItem.Count))
  8778. }
  8779. }
  8780. if reg_type == 1111 || reg_type == 1112 {
  8781. reg_type = 11
  8782. }
  8783. tm := time.Unix(time.Now().Unix(), 0)
  8784. allTotal := fmt.Sprintf("%.4f", total)
  8785. totals, _ := strconv.ParseFloat(allTotal, 64)
  8786. order := &models.HisOrder{
  8787. UserOrgId: adminUser.CurrentOrgId,
  8788. HisPatientId: his.ID,
  8789. PatientId: id,
  8790. SettleAccountsDate: recordDateTime,
  8791. Ctime: time.Now().Unix(),
  8792. Mtime: time.Now().Unix(),
  8793. Status: 1,
  8794. OrderStatus: 2,
  8795. MdtrtId: his.Number,
  8796. Number: chrg_bchno,
  8797. MedfeeSumamt: totals,
  8798. PayWay: pay_way,
  8799. PayWays: pay_ways,
  8800. PayPrice: pay_price,
  8801. MedType: strconv.Itoa(int(reg_type)),
  8802. PayCardNo: pay_card_no,
  8803. DiscountPrice: discount_price,
  8804. PreferentialPrice: preferential_price,
  8805. RealityPrice: reality_price,
  8806. FoundPrice: found_price,
  8807. MedicalInsurancePrice: medical_insurance_price,
  8808. PrivatePrice: private_price,
  8809. SettleEndTime: end_time,
  8810. SettleStartTime: start_time,
  8811. PsnPartAmt: totals,
  8812. PsnCashPay: totals,
  8813. SettleType: settle_accounts_type,
  8814. FaPiaoCode: fapiao_code,
  8815. FaPiaoNumber: fapiao_number,
  8816. Diagnosis: diagnosis_id,
  8817. PType: 2,
  8818. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8819. Decimal: decimal,
  8820. OthDesc: oth_desc,
  8821. CashPay: cash_pay,
  8822. WechatPay: wechat_pay,
  8823. AliPay: ali_pay,
  8824. JifenPay: jifen_pay,
  8825. BandCardPay: band_card_pay,
  8826. Creator: adminUser.AdminUser.Id,
  8827. }
  8828. err = service.CreateOrderTX(order, tx)
  8829. if err != nil {
  8830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8831. return
  8832. }
  8833. var customs []*Custom
  8834. for _, item := range prescriptions {
  8835. if item.Type == 1 { //药品a
  8836. for _, subItem := range item.HisDoctorAdviceInfo {
  8837. cus := &Custom{
  8838. AdviceId: subItem.ID,
  8839. ProjectId: 0,
  8840. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8841. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8842. FeedetlSn: subItem.FeedetlSn,
  8843. Price: fmt.Sprintf("%.4f", subItem.Price),
  8844. MedListCodg: subItem.MedListCodg,
  8845. Type: 1,
  8846. CostType: 9,
  8847. }
  8848. customs = append(customs, cus)
  8849. }
  8850. }
  8851. if item.Type == 2 { //项目
  8852. for _, subItem := range item.HisPrescriptionProject {
  8853. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8854. cus := &Custom{
  8855. AdviceId: 0,
  8856. ProjectId: subItem.ID,
  8857. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8858. Cut: fmt.Sprintf("%.4f", cnt),
  8859. FeedetlSn: subItem.FeedetlSn,
  8860. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8861. MedListCodg: subItem.MedListCodg,
  8862. Type: 2,
  8863. CostType: subItem.HisProject.CostClassify,
  8864. }
  8865. customs = append(customs, cus)
  8866. }
  8867. }
  8868. for _, item := range item.HisAdditionalCharge {
  8869. cus := &Custom{
  8870. ItemId: item.ID,
  8871. AdviceId: 0,
  8872. ProjectId: 0,
  8873. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8874. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8875. FeedetlSn: item.FeedetlSn,
  8876. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8877. MedListCodg: item.XtHisAddtionConfig.Code,
  8878. Type: 3,
  8879. CostType: 5,
  8880. }
  8881. customs = append(customs, cus)
  8882. }
  8883. }
  8884. for _, item := range customs {
  8885. var advice_id int64 = 0
  8886. var project_id int64 = 0
  8887. var item_id int64 = 0
  8888. var types int64 = 0
  8889. var med_chrgitm_type string
  8890. if item.Type == 1 {
  8891. advice_id = item.AdviceId
  8892. project_id = 0
  8893. item_id = 0
  8894. med_chrgitm_type = "09"
  8895. } else if item.Type == 2 {
  8896. med_chrgitm_type = "05"
  8897. if item.CostType == 3 {
  8898. med_chrgitm_type = "04"
  8899. }
  8900. if item.CostType == 8 {
  8901. med_chrgitm_type = "03"
  8902. }
  8903. advice_id = 0
  8904. item_id = 0
  8905. project_id = item.ProjectId
  8906. } else if item.Type == 3 {
  8907. advice_id = 0
  8908. item_id = item.ItemId
  8909. project_id = 0
  8910. med_chrgitm_type = "08"
  8911. }
  8912. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8913. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8914. pric, _ := strconv.ParseFloat(item.Price, 32)
  8915. info := &models.HisOrderInfo{
  8916. OrderNumber: order.Number,
  8917. UploadDate: time.Now().Unix(),
  8918. AdviceId: advice_id,
  8919. DetItemFeeSumamt: detItemFeeSumamt,
  8920. MedChrgitmType: med_chrgitm_type,
  8921. Cnt: cut,
  8922. Pric: pric,
  8923. PatientId: id,
  8924. Status: 1,
  8925. Mtime: time.Now().Unix(),
  8926. Ctime: time.Now().Unix(),
  8927. UserOrgId: adminUser.CurrentOrgId,
  8928. HisPatientId: his.ID,
  8929. OrderId: order.ID,
  8930. ProjectId: project_id,
  8931. Type: types,
  8932. ItemId: item_id,
  8933. }
  8934. service.CreateOrderInfoTX(info, tx)
  8935. }
  8936. his.Diagnosis = diagnosis_id
  8937. his.SickType = sick_type
  8938. his.RegisterType = reg_type
  8939. his.MedicalTreatmentType = reg_type
  8940. service.UpdataHisPateintTX(&his, tx)
  8941. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8942. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8943. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8944. //判断是否使用了押金
  8945. if dec_way == "true" {
  8946. tmpstring := strconv.FormatInt(order.ID, 10)
  8947. //扣押金
  8948. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8949. order.Decimal = decimal
  8950. service.UpDateOrderTwo(order, tx)
  8951. if errmsg != nil {
  8952. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8953. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8954. return
  8955. }
  8956. }
  8957. if err == nil {
  8958. for _, info := range prescriptions {
  8959. if info.Type == 1 {
  8960. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8961. }
  8962. if info.Type == 2 {
  8963. for _, sumItem := range info.HisPrescriptionProject {
  8964. if sumItem.Type == 3 {
  8965. var good models.DialysisBeforePrepareGoods
  8966. var newGood models.NewDialysisBeforePrepareGoods
  8967. var oldGood models.OldDialysisBeforePrepareGoods
  8968. good.GoodId = sumItem.GoodInfo.ID
  8969. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8970. count, _ := strconv.Atoi(sumItem.Count)
  8971. good.Count = int64(count)
  8972. good.StorehouseId = houseConfig.StorehouseOutInfo
  8973. good.ProjectId = sumItem.ID
  8974. good.PatientId = sumItem.PatientId
  8975. goods = append(goods, &good)
  8976. newGood.GoodId = sumItem.GoodInfo.ID
  8977. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8978. count2, _ := strconv.Atoi(sumItem.Count)
  8979. newGood.Count = int64(count2)
  8980. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8981. newGood.ProjectId = sumItem.ID
  8982. newGood.PatientId = sumItem.HisPatientId
  8983. newGoods = append(newGoods, &newGood)
  8984. oldGood.GoodId = sumItem.GoodInfo.ID
  8985. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8986. count3, _ := strconv.Atoi(sumItem.Count)
  8987. oldGood.Count = int64(count3)
  8988. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8989. oldGood.ProjectId = sumItem.ID
  8990. oldGood.RecordDate = sumItem.RecordDate
  8991. oldGood.PatientId = sumItem.HisPatientId
  8992. oldGoods = append(oldGoods, &oldGood)
  8993. }
  8994. }
  8995. }
  8996. }
  8997. if settConfig.IsOpen == 1 {
  8998. for _, item := range infoList {
  8999. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9000. if medical.IsUse == 2 {
  9001. //药品出库
  9002. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9003. //查询默认仓库
  9004. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9005. //查询默认仓库剩余多少库存
  9006. var sum_count int64
  9007. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9008. for _, its := range stockInfo {
  9009. if its.MaxUnit == medical.MaxUnit {
  9010. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9011. }
  9012. sum_count += its.StockMaxNumber + its.StockMinNumber
  9013. }
  9014. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9015. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9016. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9017. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9018. }
  9019. }
  9020. orgId := c.GetAdminUserInfo().CurrentOrgId
  9021. if len(oldGoods) > 0 {
  9022. timeStr := time.Now().Format("2006-01-02")
  9023. timeArr := strings.Split(timeStr, "-")
  9024. total, _ := service.FindAllWarehouseOut(orgId)
  9025. total = total + 1
  9026. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9027. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9028. number = number + total
  9029. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9030. operation_time := time.Now().Unix()
  9031. creater := c.GetAdminUserInfo().AdminUser.Id
  9032. //查询默认出库仓库库存
  9033. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9034. recordDateStr := time.Now().Format("2006-01-02")
  9035. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9036. nowtime := recordDate.Unix()
  9037. warehouseOut := models.WarehouseOut{
  9038. WarehouseOutOrderNumber: warehousing_out_order,
  9039. OperationTime: operation_time,
  9040. OrgId: orgId,
  9041. Creater: creater,
  9042. Ctime: time.Now().Unix(),
  9043. Status: 1,
  9044. WarehouseOutTime: nowtime,
  9045. Type: 1,
  9046. StorehouseId: storeConfig.StorehouseOutInfo,
  9047. IsCheck: 1,
  9048. OrderId: order.ID,
  9049. IsSys: 5,
  9050. }
  9051. //查询是否生成出库单
  9052. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9053. if out.ID == 0 {
  9054. service.AddSigleWarehouseOut(&warehouseOut)
  9055. }
  9056. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9057. for _, item := range oldGoods {
  9058. dialyPrepareOne := models.DialysisBeforePrepare{
  9059. GoodTypeId: item.GoodTypeId,
  9060. GoodId: item.GoodId,
  9061. PatientId: his.PatientId,
  9062. RecordDate: item.RecordDate,
  9063. UserOrgId: adminUser.CurrentOrgId,
  9064. Count: item.Count,
  9065. Ctime: time.Now().Unix(),
  9066. Creater: adminUser.AdminUser.Id,
  9067. CommdityCode: item.CommdityCode,
  9068. Status: 1,
  9069. StorehouseId: houseConfig.StorehouseOutInfo,
  9070. }
  9071. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9072. //非零用
  9073. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9074. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9075. //查询剩余库存
  9076. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9077. var sum_count int64
  9078. for _, item := range goodList {
  9079. sum_count += item.StockCount
  9080. }
  9081. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9082. //耗材
  9083. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9084. }
  9085. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9086. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9087. //查询剩余库存
  9088. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9089. var sum_count int64
  9090. for _, item := range goodList {
  9091. sum_count += item.StockCount
  9092. }
  9093. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9094. //耗材
  9095. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9096. }
  9097. }
  9098. }
  9099. }
  9100. c.ServeSuccessJSON(map[string]interface{}{
  9101. "msg": "结算成功",
  9102. })
  9103. }
  9104. }
  9105. }
  9106. // 退款
  9107. func (c *HisApiController) Refund() {
  9108. order_id, _ := c.GetInt64("order_id")
  9109. order, _ := service.GetHisOrderByID(order_id)
  9110. adminUser := c.GetAdminUserInfo()
  9111. orgid := c.GetAdminUserInfo().CurrentOrgId
  9112. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9113. if err != nil {
  9114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9115. return
  9116. }
  9117. tmp := strconv.FormatInt(order.ID, 10)
  9118. //当押金不为零时产生退费记录
  9119. if order.Decimal != 0 {
  9120. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9121. if err != nil {
  9122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9123. return
  9124. }
  9125. }
  9126. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9127. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9128. var goods []*models.DialysisBeforePrepareGoods
  9129. var newGoods []*models.NewDialysisBeforePrepareGoods
  9130. var infos []*models.HisDoctorAdviceInfo
  9131. for _, info := range orders {
  9132. if info.AdviceId > 0 && info.ProjectId == 0 {
  9133. infos = append(infos, &info.HisDoctorAdviceInfo)
  9134. }
  9135. if info.ProjectId > 0 && info.AdviceId == 0 {
  9136. if info.HisPrescriptionProject.Type == 3 {
  9137. var good models.DialysisBeforePrepareGoods
  9138. var newGood models.NewDialysisBeforePrepareGoods
  9139. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9140. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9141. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9142. good.Count = int64(count)
  9143. good.StorehouseId = houseConfig.StorehouseOutInfo
  9144. good.ProjectId = info.HisPrescriptionProject.ID
  9145. good.PatientId = info.PatientId
  9146. good.OrderId = order_id
  9147. goods = append(goods, &good)
  9148. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9149. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9150. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9151. newGood.Count = int64(count2)
  9152. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9153. newGood.ProjectId = info.HisPrescriptionProject.ID
  9154. newGood.RecordDate = order.SettleAccountsDate
  9155. newGood.UserOrgId = order.UserOrgId
  9156. newGood.PatientId = info.PatientId
  9157. newGood.OrderId = order_id
  9158. newGoods = append(newGoods, &newGood)
  9159. }
  9160. }
  9161. }
  9162. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9163. if settConfig.IsOpen == 1 {
  9164. for _, item := range infos {
  9165. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9166. }
  9167. for _, item := range newGoods {
  9168. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9169. }
  9170. }
  9171. c.ServeSuccessJSON(map[string]interface{}{
  9172. "msg": "退费成功",
  9173. })
  9174. }
  9175. func (c *HisApiController) RefundNumber() {
  9176. his_patient_id, _ := c.GetInt64("id")
  9177. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9178. info.Status = 0
  9179. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9180. if count > 0 {
  9181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9182. return
  9183. }
  9184. err := service.SaveHisPatient(info)
  9185. if err == nil {
  9186. c.ServeSuccessJSON(map[string]interface{}{
  9187. "msg": "退号成功",
  9188. })
  9189. } else {
  9190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9191. return
  9192. }
  9193. }
  9194. func (this *HisApiController) AdditionalCharge() {
  9195. dataBody := make(map[string]interface{}, 0)
  9196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9197. fmt.Println(err)
  9198. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9199. patient_id := int64(dataBody["patient_id"].(float64))
  9200. medicineData, _ := dataBody["medicineData"].([]interface{})
  9201. adminUserInfo := this.GetAdminUserInfo()
  9202. orgId := adminUserInfo.CurrentOrgId
  9203. admin_user_id := adminUserInfo.AdminUser.Id
  9204. timeStr := time.Now().Format("2006-01-02")
  9205. timeLayout := "2006-01-02 15:04:05"
  9206. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9207. timenow := timeStringToTime.Unix()
  9208. var additionalCharges []*models.HisAdditionalCharge
  9209. for _, item := range medicineData {
  9210. var randNum int
  9211. randNum = rand.Intn(10000) + 1000
  9212. timestamp := time.Now().Unix()
  9213. tempTime := time.Unix(timestamp, 0)
  9214. timeFormat := tempTime.Format("20060102150405")
  9215. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9216. items := item.(map[string]interface{})
  9217. money := items["price"].(string)
  9218. item_id_str := items["item_id"].(string)
  9219. name := items["name"].(string)
  9220. id_str := items["id"].(string)
  9221. moneys, _ := strconv.ParseInt(money, 10, 64)
  9222. monStr := strconv.FormatInt(moneys, 10)
  9223. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9224. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9225. id, _ := strconv.ParseInt(id_str, 10, 64)
  9226. additionalCharge := &models.HisAdditionalCharge{
  9227. ID: id,
  9228. HisPatientId: his_patient_id,
  9229. UserOrgId: orgId,
  9230. PatientId: patient_id,
  9231. RecordDate: timenow,
  9232. Price: monneyStr,
  9233. Status: 1,
  9234. ItemName: name,
  9235. ItemId: item_id,
  9236. AdminUserId: admin_user_id,
  9237. CreatedTime: time.Now().Unix(),
  9238. OrderStatus: 0,
  9239. PrescriptionNumber: "",
  9240. BatchNumber: "",
  9241. FeedetlSn: p_number,
  9242. }
  9243. service.CreateAdditionalCharge(additionalCharge)
  9244. additionalCharges = append(additionalCharges, additionalCharge)
  9245. }
  9246. this.ServeSuccessJSON(map[string]interface{}{
  9247. "msg": "添加成功",
  9248. "additional_charges": additionalCharges,
  9249. })
  9250. }
  9251. func (this *HisApiController) DeleteAddition() {
  9252. id, _ := this.GetInt64("id")
  9253. //TODO 需要判断是否已经结算
  9254. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9255. if err == nil {
  9256. this.ServeSuccessJSON(map[string]interface{}{
  9257. "msg": "删除成功",
  9258. })
  9259. return
  9260. } else {
  9261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9262. return
  9263. }
  9264. }
  9265. func (this *HisApiController) GetAdminUsers() {
  9266. adminUser := this.GetAdminUserInfo()
  9267. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9268. this.ServeSuccessJSON(map[string]interface{}{
  9269. "doctors": doctors,
  9270. })
  9271. }
  9272. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9273. change_type, _ := this.GetInt64("type", 0)
  9274. record_date := this.GetString("record_time")
  9275. patient_id, _ := this.GetInt64("patient_id", 0)
  9276. p_type, _ := this.GetInt64("p_type", 0)
  9277. timeLayout := "2006-01-02"
  9278. loc, _ := time.LoadLocation("Local")
  9279. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9280. record_time := theAdviceRecordTime.Unix()
  9281. adminUserInfo := this.GetAdminUserInfo()
  9282. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9283. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9284. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9285. if config.ID > 0 && config.IsOpen == 1 {
  9286. for _, subitems := range prescriptions {
  9287. for _, item := range subitems.VMHisPrescription {
  9288. for _, subItem := range item.HisDoctorAdviceInfo {
  9289. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9291. if info.RetailPrice > 0 {
  9292. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9293. subItem.Drug.RetailPrice = drug.RetailPrice
  9294. }
  9295. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9296. subItem.Drug.MinPrice = info.RetailPrice
  9297. subItem.Drug.RetailPrice = info.RetailPrice
  9298. }
  9299. }
  9300. }
  9301. }
  9302. }
  9303. }
  9304. if config.ID > 0 && config.IsOpen == 1 {
  9305. for _, subitems := range prescriptions {
  9306. for _, item := range subitems.VMHisPrescription {
  9307. for _, subItem := range item.HisPrescriptionProject {
  9308. if subItem.Type == 3 {
  9309. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9310. if info.Price > 0 {
  9311. subItem.GoodInfo.PackingPrice = info.Price
  9312. }
  9313. }
  9314. }
  9315. }
  9316. }
  9317. }
  9318. }
  9319. if err == nil {
  9320. if len(prescriptions) == 0 {
  9321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9322. return
  9323. } else {
  9324. this.ServeSuccessJSON(map[string]interface{}{
  9325. "prescriptions": prescriptions,
  9326. })
  9327. return
  9328. }
  9329. } else {
  9330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9331. return
  9332. }
  9333. }
  9334. func (this *HisApiController) GetCallHisPrescription() {
  9335. patient_id, _ := this.GetInt64("patient_id", 0)
  9336. timeLayout := "2006-01-02"
  9337. loc, _ := time.LoadLocation("Local")
  9338. start_time := this.GetString("start_time")
  9339. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9340. end_time := this.GetString("end_time")
  9341. p_type, _ := this.GetInt64("p_type")
  9342. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9343. adminUserInfo := this.GetAdminUserInfo()
  9344. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9345. //if
  9346. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9347. //
  9348. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9349. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9350. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9351. if config.ID > 0 && config.IsOpen == 1 {
  9352. for _, subitems := range prescriptions {
  9353. for _, item := range subitems.VMHisPrescription {
  9354. for _, subItem := range item.HisDoctorAdviceInfo {
  9355. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9356. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9357. if info.RetailPrice > 0 {
  9358. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9359. subItem.Drug.RetailPrice = drug.RetailPrice
  9360. }
  9361. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9362. subItem.Drug.MinPrice = info.RetailPrice
  9363. subItem.Drug.RetailPrice = info.RetailPrice
  9364. }
  9365. }
  9366. }
  9367. }
  9368. }
  9369. }
  9370. if config.ID > 0 && config.IsOpen == 1 {
  9371. for _, subitems := range prescriptions {
  9372. for _, item := range subitems.VMHisPrescription {
  9373. for _, subItem := range item.HisPrescriptionProject {
  9374. if subItem.Type == 3 {
  9375. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9376. if info.Price > 0 {
  9377. subItem.GoodInfo.PackingPrice = info.Price
  9378. }
  9379. }
  9380. }
  9381. }
  9382. }
  9383. }
  9384. }
  9385. if err == nil {
  9386. this.ServeSuccessJSON(map[string]interface{}{
  9387. "prescriptions": prescriptions,
  9388. })
  9389. return
  9390. } else {
  9391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9392. return
  9393. }
  9394. }
  9395. func (this *HisApiController) GetHisDayPrescription() {
  9396. timeLayout := "2006-01-02"
  9397. loc, _ := time.LoadLocation("Local")
  9398. start_time := this.GetString("start_time")
  9399. patient_id, _ := this.GetInt64("patient_id", 0)
  9400. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9401. end_time := this.GetString("end_time")
  9402. p_type, _ := this.GetInt64("p_type")
  9403. order_status, _ := this.GetInt64("type")
  9404. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9405. adminUserInfo := this.GetAdminUserInfo()
  9406. var dayHisPrescription []*models.HisPrescription
  9407. var err error
  9408. if order_status == 1 || order_status == 0 {
  9409. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9410. } else if order_status == 2 {
  9411. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9412. }
  9413. var settle_total float64
  9414. for _, item := range dayHisPrescription {
  9415. if len(item.HisPrescriptionProject) > 0 {
  9416. for _, subItem := range item.HisPrescriptionProject {
  9417. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9418. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9419. settle_total = settle_total + total
  9420. }
  9421. }
  9422. if len(item.HisDoctorAdviceInfo) > 0 {
  9423. for _, subItem := range item.HisDoctorAdviceInfo {
  9424. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9425. settle_total = settle_total + total
  9426. }
  9427. }
  9428. }
  9429. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9430. if err == nil {
  9431. this.ServeSuccessJSON(map[string]interface{}{
  9432. "day_prescription": dayHisPrescription,
  9433. "settle_total": settle_total,
  9434. })
  9435. return
  9436. } else {
  9437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9438. return
  9439. }
  9440. }
  9441. func (c *HisApiController) GetHisChargePatientList() {
  9442. record_date := c.GetString("record_date")
  9443. order_status, _ := c.GetInt64("type")
  9444. sch_type, _ := c.GetInt64("sch_type")
  9445. timeLayout := "2006-01-02"
  9446. loc, _ := time.LoadLocation("Local")
  9447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9448. if err != nil {
  9449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9450. return
  9451. }
  9452. recordDateTime := theTime.Unix()
  9453. adminInfo := c.GetAdminUserInfo()
  9454. var tempPatients []*service.NewTempPatients
  9455. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9456. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9457. if order_status != 2 {
  9458. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9459. } else {
  9460. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9461. }
  9462. } else {
  9463. if order_status != 2 {
  9464. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9465. } else {
  9466. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9467. }
  9468. }
  9469. var patients []*service.NewTempPatients
  9470. var patients_two []*service.NewTempPatients
  9471. for _, item := range tempPatients {
  9472. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9473. //过滤掉没挂号的和没开处方的
  9474. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9475. patients = append(patients, item)
  9476. }
  9477. //过滤掉没挂号的
  9478. if len(item.HisPatient) > 0 {
  9479. patients_two = append(patients_two, item)
  9480. }
  9481. } else {
  9482. if len(item.HisPrescription) > 0 {
  9483. patients = append(patients, item)
  9484. }
  9485. }
  9486. }
  9487. c.ServeSuccessJSON(map[string]interface{}{
  9488. "list": patients,
  9489. "list_two": patients_two,
  9490. })
  9491. }
  9492. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9493. record_date := c.GetString("record_date")
  9494. timeLayout := "2006-01-02"
  9495. loc, _ := time.LoadLocation("Local")
  9496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9497. if err != nil {
  9498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9499. return
  9500. }
  9501. recordDateTime := theTime.Unix()
  9502. adminUser := c.GetAdminUserInfo()
  9503. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9504. var patients []*service.Patients
  9505. for _, item := range tempPatients {
  9506. if item.HisPatient.ID == 0 {
  9507. patients = append(patients, item)
  9508. }
  9509. }
  9510. c.ServeSuccessJSON(map[string]interface{}{
  9511. "list": patients,
  9512. //"list_two": patients_two,
  9513. })
  9514. }
  9515. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9516. newArr = make([]*service.Patients, 0)
  9517. for i := 0; i < len(patient); i++ {
  9518. repeat := false
  9519. for j := i + 1; j < len(patient); j++ {
  9520. if patient[i].ID == patient[j].ID {
  9521. repeat = true
  9522. break
  9523. }
  9524. }
  9525. if !repeat {
  9526. newArr = append(newArr, patient[i])
  9527. }
  9528. }
  9529. return
  9530. }
  9531. func (c *HisApiController) GetHisChargePatientInfo() {
  9532. patient_id, _ := c.GetInt64("patient_id")
  9533. his_patient_id, _ := c.GetInt64("his_patient_id")
  9534. record_date := c.GetString("record_date")
  9535. //start_time := c.GetString("start_time")
  9536. //end_time := c.GetString("end_time")
  9537. order_status, _ := c.GetInt64("type", 0)
  9538. p_type, _ := c.GetInt64("p_type", 0)
  9539. order_id, _ := c.GetInt64("order_id", 0)
  9540. timeLayout := "2006-01-02"
  9541. loc, _ := time.LoadLocation("Local")
  9542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9543. if err != nil {
  9544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9545. return
  9546. }
  9547. recordDateTime := theTime.Unix()
  9548. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9549. //if err != nil {
  9550. //
  9551. //}
  9552. //startRecordDateTime := startTime.Unix()
  9553. //
  9554. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9555. //if err != nil {
  9556. //
  9557. //}
  9558. //endRecordDateTime := endTime.Unix()
  9559. admin := c.GetAdminUserInfo()
  9560. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9561. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9562. var prescriptions []*models.HisPrescription
  9563. //var unChargeMonthPrescriptions []*models.HisPrescription
  9564. order, _ := service.GetHisOrderByID(order_id)
  9565. if order_status == 1 || order_status == 0 {
  9566. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9567. } else if order_status == 2 {
  9568. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9569. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9570. }
  9571. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9572. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9573. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9574. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9575. //获取所有科室信息
  9576. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9577. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9578. c.ServeSuccessJSON(map[string]interface{}{
  9579. "his_info": his_patient_info,
  9580. "xt_info": xt_patient_info,
  9581. "prescription": prescriptions,
  9582. "case_history": case_history,
  9583. "info": patientPrescriptionInfo,
  9584. "last_info": lastPatientPrescriptionInfo,
  9585. "order": order,
  9586. "doctors": doctors,
  9587. "department": department,
  9588. "sch": sch,
  9589. })
  9590. return
  9591. }
  9592. func (c *HisApiController) GetAllOrderDetail() {
  9593. order_id, _ := c.GetInt64("id", 0)
  9594. order, _ := service.GetHisOrderByID(order_id)
  9595. if order.ID == 0 {
  9596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9597. return
  9598. }
  9599. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9600. org_id := c.GetAdminUserInfo().CurrentOrgId
  9601. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9602. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9603. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9604. c.ServeSuccessJSON(map[string]interface{}{
  9605. "order": order,
  9606. "order_info": order_info,
  9607. "patient": patient,
  9608. "admin_info": adminInfo,
  9609. "hospital_record": record,
  9610. })
  9611. return
  9612. }
  9613. func (c *HisApiController) GetAllOrderDetailCollect() {
  9614. order_id, _ := c.GetInt64("id", 0)
  9615. order, _ := service.GetHisOrderByID(order_id)
  9616. if order.ID == 0 {
  9617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9618. return
  9619. }
  9620. org_id := c.GetAdminUserInfo().CurrentOrgId
  9621. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9622. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9623. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9624. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9625. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9626. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9627. var bedCostTotal float64 = 0 //床位总费
  9628. //var bedCostSelfTotal float64 = 0 //床位自费
  9629. var operationCostTotal float64 = 0 //手术费
  9630. //var operationCostSelfTotal float64 = 0 //手术费
  9631. var otherCostTotal float64 = 0 //其他费用
  9632. //var otherCostSelfTotal float64 = 0 //其他费用
  9633. var materialCostTotal float64 = 0 //材料费
  9634. //var materialCostSelfTotal float64 = 0 //材料费
  9635. var westernMedicineCostTotal float64 = 0 //西药费
  9636. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9637. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9638. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9639. var checkCostTotal float64 = 0 //检查费
  9640. //var checkCostSelfTotal float64 = 0 //检查费
  9641. var laboratoryCostTotal float64 = 0 //化验费
  9642. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9643. var treatCostTotal float64 = 0 //治疗费用
  9644. //var treatCostSelfTotal float64 = 0 //治疗费用
  9645. var zhenChaCostTotal float64 = 0 //其他费用
  9646. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9647. decimal.DivisionPrecision = 2
  9648. var BalanceAccountsType int64
  9649. if his.ID > 0 {
  9650. BalanceAccountsType = his.BalanceAccountsType
  9651. } else {
  9652. BalanceAccountsType = record.BalanceAccountsType
  9653. }
  9654. if BalanceAccountsType != 2 {
  9655. for _, item := range order_info {
  9656. if org_id == 10215 {
  9657. if item.MedChrgitmType == "01" { //床位费
  9658. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9659. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9660. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9661. }
  9662. if item.MedChrgitmType == "02" { //诊察费
  9663. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9664. //zhenChaCostSelfTotal = zhenChaCostTotal
  9665. }
  9666. if item.MedChrgitmType == "03" { //检查费
  9667. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9668. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9669. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9670. }
  9671. //if item.MedChrgitmType == "02" { //检查费
  9672. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9673. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9674. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9675. //}
  9676. if item.MedChrgitmType == "04" { //化验费
  9677. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9678. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9679. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9680. }
  9681. if item.MedChrgitmType == "05" { //治疗费
  9682. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9683. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9684. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9685. }
  9686. if item.MedChrgitmType == "06" { //手术费
  9687. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9688. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9689. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9690. }
  9691. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9692. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9693. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9694. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9695. }
  9696. if item.MedChrgitmType == "09" { //西药费
  9697. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9698. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9699. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9700. }
  9701. if item.MedChrgitmType == "11" { //中成费
  9702. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9703. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9704. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9705. }
  9706. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9707. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9708. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9709. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9710. }
  9711. } else if org_id == 10188 || org_id == 10217 {
  9712. if item.MedChrgitmType == "01" { //床位费
  9713. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9714. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9715. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9716. }
  9717. if item.MedChrgitmType == "02" { //诊察费
  9718. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. //zhenChaCostSelfTotal = zhenChaCostTotal
  9720. }
  9721. if item.MedChrgitmType == "03" { //检查费
  9722. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9723. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9725. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9726. }
  9727. //if item.MedChrgitmType == "02" { //检查费
  9728. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9730. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9731. //}
  9732. if item.MedChrgitmType == "04" { //化验费
  9733. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9735. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9736. }
  9737. if item.MedChrgitmType == "05" { //治疗费
  9738. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9740. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9741. }
  9742. if item.MedChrgitmType == "06" { //手术费
  9743. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9745. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9746. }
  9747. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9748. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9750. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9751. }
  9752. if item.MedChrgitmType == "09" { //西药费
  9753. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9755. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9756. }
  9757. if item.MedChrgitmType == "11" { //中成费
  9758. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9759. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9760. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9761. }
  9762. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9763. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9764. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9765. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9766. }
  9767. } else {
  9768. if item.MedChrgitmType == "01" { //床位费
  9769. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9771. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9772. }
  9773. //if item.MedChrgitmType == "02" { //诊察费
  9774. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9776. //}
  9777. if item.MedChrgitmType == "03" { //检查费
  9778. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9779. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9780. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9781. }
  9782. //if item.MedChrgitmType == "02" { //检查费
  9783. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9784. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9785. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9786. //}
  9787. if item.MedChrgitmType == "04" { //化验费
  9788. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9789. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9790. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9791. }
  9792. if item.MedChrgitmType == "05" { //治疗费
  9793. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9794. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9795. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9796. }
  9797. if item.MedChrgitmType == "06" { //手术费
  9798. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9799. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9800. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9801. }
  9802. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9803. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9804. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9805. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9806. }
  9807. if item.MedChrgitmType == "09" { //西药费
  9808. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9809. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9810. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9811. }
  9812. if item.MedChrgitmType == "11" { //中成费
  9813. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9814. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9815. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9816. }
  9817. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9818. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9819. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9820. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9821. }
  9822. }
  9823. }
  9824. c.ServeSuccessJSON(map[string]interface{}{
  9825. "order": order,
  9826. "order_info": order_info,
  9827. "patient": patient,
  9828. "admin_info": adminInfo,
  9829. "his_hospital": record,
  9830. "bedCostTotal": bedCostTotal,
  9831. "operationCostTotal": operationCostTotal,
  9832. "otherCostTotal": otherCostTotal,
  9833. "materialCostTotal": materialCostTotal,
  9834. "westernMedicineCostTotal": westernMedicineCostTotal,
  9835. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9836. "checkCostTotal": checkCostTotal,
  9837. "zhenChaCostTotal": zhenChaCostTotal,
  9838. "laboratoryCostTotal": laboratoryCostTotal,
  9839. "treatCostTotal": treatCostTotal,
  9840. })
  9841. } else {
  9842. for _, item := range order_info {
  9843. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9844. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9845. item.MedChrgitmType = "09"
  9846. }
  9847. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9848. if item.HisPrescriptionProject.Type == 2 {
  9849. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9850. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9851. case 0:
  9852. item.MedChrgitmType = "0"
  9853. break
  9854. case 1:
  9855. item.MedChrgitmType = "14"
  9856. break
  9857. case 2:
  9858. item.MedChrgitmType = "05"
  9859. break
  9860. case 3:
  9861. item.MedChrgitmType = "03"
  9862. break
  9863. case 4:
  9864. item.MedChrgitmType = "03"
  9865. break
  9866. case 5:
  9867. item.MedChrgitmType = "08"
  9868. break
  9869. case 6:
  9870. item.MedChrgitmType = "14"
  9871. break
  9872. case 7:
  9873. item.MedChrgitmType = "14"
  9874. break
  9875. case 8:
  9876. item.MedChrgitmType = "03"
  9877. break
  9878. case 9:
  9879. item.MedChrgitmType = "14"
  9880. break
  9881. case 10:
  9882. item.MedChrgitmType = "14"
  9883. break
  9884. case 11:
  9885. item.MedChrgitmType = "06"
  9886. break
  9887. case 12:
  9888. item.MedChrgitmType = "12"
  9889. break
  9890. case 13:
  9891. item.MedChrgitmType = "01"
  9892. break
  9893. case 14:
  9894. item.MedChrgitmType = "04"
  9895. break
  9896. case 15:
  9897. item.MedChrgitmType = "14"
  9898. break
  9899. }
  9900. } else {
  9901. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9902. case 1:
  9903. item.MedChrgitmType = "14"
  9904. break
  9905. case 2:
  9906. item.MedChrgitmType = "05"
  9907. break
  9908. case 3:
  9909. item.MedChrgitmType = "04"
  9910. break
  9911. case 4:
  9912. item.MedChrgitmType = "14"
  9913. break
  9914. case 5:
  9915. item.MedChrgitmType = "08"
  9916. break
  9917. case 6:
  9918. item.MedChrgitmType = "14"
  9919. break
  9920. case 7:
  9921. item.MedChrgitmType = "14"
  9922. break
  9923. case 8:
  9924. item.MedChrgitmType = "03"
  9925. break
  9926. case 9:
  9927. item.MedChrgitmType = "14"
  9928. break
  9929. }
  9930. }
  9931. } else if item.HisPrescriptionProject.Type == 3 {
  9932. item.MedChrgitmType = "08"
  9933. }
  9934. }
  9935. }
  9936. for _, item := range order_info {
  9937. if org_id == 10215 {
  9938. if item.MedChrgitmType == "01" { //床位费
  9939. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9940. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9941. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9942. }
  9943. if item.MedChrgitmType == "02" { //诊察费
  9944. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9945. //zhenChaCostSelfTotal = zhenChaCostTotal
  9946. }
  9947. if item.MedChrgitmType == "03" { //检查费
  9948. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9949. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9950. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9951. }
  9952. //if item.MedChrgitmType == "02" { //检查费
  9953. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9954. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9955. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9956. //}
  9957. if item.MedChrgitmType == "04" { //化验费
  9958. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9959. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9960. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9961. }
  9962. if item.MedChrgitmType == "05" { //治疗费
  9963. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9964. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9965. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9966. }
  9967. if item.MedChrgitmType == "06" { //手术费
  9968. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9969. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9970. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9971. }
  9972. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9973. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9974. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9975. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9976. }
  9977. if item.MedChrgitmType == "09" { //西药费
  9978. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9979. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9980. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9981. }
  9982. if item.MedChrgitmType == "11" { //中成费
  9983. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9984. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9985. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9986. }
  9987. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9988. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9989. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9990. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9991. }
  9992. } else {
  9993. if item.MedChrgitmType == "01" { //床位费
  9994. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9995. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9996. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9997. }
  9998. //if item.MedChrgitmType == "02" { //诊察费
  9999. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10000. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10001. //}
  10002. if item.MedChrgitmType == "03" { //检查费
  10003. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10004. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10005. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10006. }
  10007. //if item.MedChrgitmType == "02" { //检查费
  10008. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10009. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10010. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10011. //}
  10012. if item.MedChrgitmType == "04" { //化验费
  10013. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10014. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10015. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10016. }
  10017. if item.MedChrgitmType == "05" { //治疗费
  10018. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10019. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10020. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10021. }
  10022. if item.MedChrgitmType == "06" { //手术费
  10023. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10024. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10025. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10026. }
  10027. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10028. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10029. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10030. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10031. }
  10032. if item.MedChrgitmType == "09" { //西药费
  10033. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10034. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10035. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10036. }
  10037. if item.MedChrgitmType == "11" { //中成费
  10038. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10039. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10040. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10041. }
  10042. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10043. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10044. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10045. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10046. }
  10047. }
  10048. }
  10049. c.ServeSuccessJSON(map[string]interface{}{
  10050. "order": order,
  10051. "order_info": order_info,
  10052. "patient": patient,
  10053. "admin_info": adminInfo,
  10054. "his_hospital": record,
  10055. "bedCostTotal": bedCostTotal,
  10056. "operationCostTotal": operationCostTotal,
  10057. "otherCostTotal": otherCostTotal,
  10058. "materialCostTotal": materialCostTotal,
  10059. "westernMedicineCostTotal": westernMedicineCostTotal,
  10060. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10061. "checkCostTotal": checkCostTotal,
  10062. "zhenChaCostTotal": zhenChaCostTotal,
  10063. "laboratoryCostTotal": laboratoryCostTotal,
  10064. "treatCostTotal": treatCostTotal,
  10065. })
  10066. }
  10067. }
  10068. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10069. page, _ := c.GetInt64("page")
  10070. limit, _ := c.GetInt64("limit")
  10071. keywords := c.GetString("keywords")
  10072. start_time := c.GetString("start_time")
  10073. end_time := c.GetString("end_time")
  10074. //clr_type := c.GetString("clr_type")
  10075. insutype := c.GetString("insutype")
  10076. timeLayout := "2006-01-02"
  10077. loc, _ := time.LoadLocation("Local")
  10078. var theStartTIme int64
  10079. if len(start_time) > 0 {
  10080. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10081. theStartTIme = theTime.Unix()
  10082. }
  10083. var theEndtTIme int64
  10084. if len(end_time) > 0 {
  10085. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10086. theEndtTIme = theTime.Unix()
  10087. }
  10088. if page <= 0 {
  10089. page = 1
  10090. }
  10091. if limit <= 0 {
  10092. limit = 10
  10093. }
  10094. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10095. c.ServeSuccessJSON(map[string]interface{}{
  10096. "total": total,
  10097. "list": list,
  10098. })
  10099. return
  10100. }
  10101. func (c *HisApiController) GetPutOnRecordList() {
  10102. page, _ := c.GetInt64("page")
  10103. limit, _ := c.GetInt64("limit")
  10104. keywords := c.GetString("keywords")
  10105. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10106. if page <= 0 {
  10107. page = 1
  10108. }
  10109. if limit <= 0 {
  10110. limit = 10
  10111. }
  10112. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10113. c.ServeSuccessJSON(map[string]interface{}{
  10114. "total": total,
  10115. "list": list,
  10116. })
  10117. return
  10118. }
  10119. func (c *HisApiController) GetCompareData() {
  10120. start_time := c.GetString("start_time")
  10121. end_time := c.GetString("end_time")
  10122. insutype := c.GetString("insutype")
  10123. clr_type := c.GetString("clr_type")
  10124. timeLayout := "2006-01-02"
  10125. loc, _ := time.LoadLocation("Local")
  10126. var theStartTIme int64
  10127. if len(start_time) > 0 {
  10128. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10129. if err != nil {
  10130. theStartTIme = 0
  10131. }
  10132. theStartTIme = theTime.Unix()
  10133. }
  10134. var theEndtTIme int64
  10135. if len(end_time) > 0 {
  10136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10137. if err != nil {
  10138. theEndtTIme = 0
  10139. }
  10140. theEndtTIme = theTime.Unix()
  10141. }
  10142. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10143. fmt.Println(err)
  10144. if err == nil {
  10145. c.ServeSuccessJSON(map[string]interface{}{
  10146. "list": formData,
  10147. })
  10148. } else {
  10149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10150. return
  10151. }
  10152. }
  10153. func (c *HisApiController) GetFaPiaoData() {
  10154. order_id, _ := c.GetInt64("order_id")
  10155. patient_id, _ := c.GetInt64("patient_id")
  10156. //number := c.GetString("number")
  10157. adminUser := c.GetAdminUserInfo()
  10158. order, _ := service.GetHisOrderByID(order_id)
  10159. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10160. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10161. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10162. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10163. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10164. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10165. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10166. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10167. var bedCostTotal float64 = 0 //床位总费
  10168. var bedCostSelfTotal float64 = 0 //床位自费
  10169. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10170. var operationCostTotal float64 = 0 //手术费
  10171. var operationCostSelfTotal float64 = 0 //手术费
  10172. var operationCostPartSelfTotal float64 = 0 //手术费
  10173. var otherCostTotal float64 = 0 //其他费用
  10174. var otherCostSelfTotal float64 = 0 //其他费用
  10175. var otherCostPartSelfTotal float64 = 0 //其他费用
  10176. var materialCostTotal float64 = 0 //材料费
  10177. var materialCostSelfTotal float64 = 0 //材料费
  10178. var materialCostPartSelfTotal float64 = 0 //材料费
  10179. var westernMedicineCostTotal float64 = 0 //西药费
  10180. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10181. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10182. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10183. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10184. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10185. var checkCostTotal float64 = 0 //检查费
  10186. var checkCostSelfTotal float64 = 0 //检查费
  10187. var checkCostPartSelfTotal float64 = 0 //检查费
  10188. var hiliCostTotal float64 = 0 //护理费
  10189. var hiliCostSelfTotal float64 = 0 //护理费
  10190. var hiliCostPartSelfTotal float64 = 0 //护理费
  10191. var laboratoryCostTotal float64 = 0 //化验费
  10192. var laboratoryCostSelfTotal float64 = 0 //化验费
  10193. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10194. var treatCostTotal float64 = 0 //治疗费用
  10195. var treatCostSelfTotal float64 = 0 //治疗费用
  10196. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10197. var zhenChaCostTotal float64 = 0 //其他费用
  10198. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10199. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10200. decimal.DivisionPrecision = 2
  10201. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10202. var balanceAccountsType int64
  10203. if his.ID > 0 {
  10204. balanceAccountsType = his.BalanceAccountsType
  10205. } else {
  10206. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10207. }
  10208. if balanceAccountsType == 2 {
  10209. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10210. for _, item := range orderInfos_two {
  10211. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10212. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10213. item.MedChrgitmType = "09"
  10214. }
  10215. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10216. if item.HisPrescriptionProject.Type == 2 {
  10217. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10218. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10219. case 0:
  10220. item.MedChrgitmType = "0"
  10221. break
  10222. case 1:
  10223. item.MedChrgitmType = "14"
  10224. break
  10225. case 2:
  10226. item.MedChrgitmType = "05"
  10227. break
  10228. case 3:
  10229. item.MedChrgitmType = "03"
  10230. break
  10231. case 4:
  10232. item.MedChrgitmType = "03"
  10233. break
  10234. case 5:
  10235. item.MedChrgitmType = "08"
  10236. break
  10237. case 6:
  10238. item.MedChrgitmType = "14"
  10239. break
  10240. case 7:
  10241. item.MedChrgitmType = "14"
  10242. break
  10243. case 8:
  10244. item.MedChrgitmType = "03"
  10245. break
  10246. case 9:
  10247. item.MedChrgitmType = "14"
  10248. break
  10249. case 10:
  10250. item.MedChrgitmType = "14"
  10251. break
  10252. case 11:
  10253. item.MedChrgitmType = "06"
  10254. break
  10255. case 12:
  10256. item.MedChrgitmType = "12"
  10257. break
  10258. case 13:
  10259. item.MedChrgitmType = "01"
  10260. break
  10261. case 14:
  10262. item.MedChrgitmType = "04"
  10263. break
  10264. case 15:
  10265. item.MedChrgitmType = "02"
  10266. break
  10267. }
  10268. } else {
  10269. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10270. case 1:
  10271. item.MedChrgitmType = "14"
  10272. break
  10273. case 2:
  10274. item.MedChrgitmType = "05"
  10275. break
  10276. case 3:
  10277. item.MedChrgitmType = "04"
  10278. break
  10279. case 4:
  10280. item.MedChrgitmType = "03"
  10281. break
  10282. case 5:
  10283. item.MedChrgitmType = "08"
  10284. break
  10285. case 6:
  10286. item.MedChrgitmType = "14"
  10287. break
  10288. case 7:
  10289. item.MedChrgitmType = "14"
  10290. break
  10291. case 8:
  10292. item.MedChrgitmType = "03"
  10293. break
  10294. case 9:
  10295. item.MedChrgitmType = "14"
  10296. break
  10297. }
  10298. }
  10299. } else if item.HisPrescriptionProject.Type == 3 {
  10300. item.MedChrgitmType = "08"
  10301. }
  10302. }
  10303. }
  10304. for _, item := range orderInfos_two {
  10305. fmt.Println(item.MedChrgitmType)
  10306. if item.MedChrgitmType == "07" { //床位费
  10307. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10308. hiliCostSelfTotal = hiliCostTotal
  10309. }
  10310. if item.MedChrgitmType == "01" { //床位费
  10311. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. bedCostSelfTotal = bedCostTotal
  10313. }
  10314. if item.MedChrgitmType == "02" { //诊察费
  10315. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. zhenChaCostSelfTotal = zhenChaCostTotal
  10317. }
  10318. if item.MedChrgitmType == "03" { //检查费
  10319. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10320. checkCostSelfTotal = checkCostTotal
  10321. }
  10322. if item.MedChrgitmType == "04" { //化验费
  10323. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10324. laboratoryCostSelfTotal = laboratoryCostTotal
  10325. }
  10326. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10327. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10328. treatCostSelfTotal = treatCostTotal
  10329. }
  10330. if item.MedChrgitmType == "06" { //手术费
  10331. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. operationCostSelfTotal = treatCostTotal
  10333. }
  10334. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10335. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10336. materialCostSelfTotal = materialCostTotal
  10337. }
  10338. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10339. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10340. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10341. }
  10342. if item.MedChrgitmType == "11" { //中成费
  10343. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10344. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10345. }
  10346. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10347. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10348. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10349. otherCostSelfTotal = otherCostTotal
  10350. }
  10351. } else {
  10352. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10353. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10354. otherCostSelfTotal = otherCostTotal
  10355. }
  10356. }
  10357. }
  10358. } else {
  10359. for _, item := range orderInfos {
  10360. if item.MedChrgitmType == "01" { //床位费
  10361. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10363. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10364. }
  10365. if item.MedChrgitmType == "02" { //诊察费
  10366. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10368. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10369. }
  10370. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10371. if item.MedChrgitmType == "03" { //检查费
  10372. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10373. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10374. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10375. }
  10376. } else {
  10377. if item.MedChrgitmType == "03" { //检查费
  10378. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10379. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10380. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10381. }
  10382. }
  10383. if item.MedChrgitmType == "04" { //化验费
  10384. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10385. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10386. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10387. }
  10388. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10389. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. }
  10393. if item.MedChrgitmType == "06" { //手术费
  10394. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10395. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10396. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10397. }
  10398. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10399. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10400. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10401. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10402. }
  10403. if item.MedChrgitmType == "07" { //护理
  10404. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10405. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10406. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10407. }
  10408. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10409. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10410. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10411. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10412. }
  10413. if item.MedChrgitmType == "11" { //中成费
  10414. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10415. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10416. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10417. }
  10418. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10419. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10420. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10421. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10422. }
  10423. }
  10424. }
  10425. timeLayout := "2006-01-02"
  10426. loc, _ := time.LoadLocation("Local")
  10427. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10428. if err != nil {
  10429. }
  10430. startRecordDateTime := startTime.Unix()
  10431. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10432. if err != nil {
  10433. }
  10434. endRecordDateTime := endTime.Unix()
  10435. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10436. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10437. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10438. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10439. c.ServeSuccessJSON(map[string]interface{}{
  10440. "charge_admin_name": charge_admin.UserName,
  10441. "order_number": order.Number, //业务流水号
  10442. "id_card_no": his.IdCardNo, //社会保障号
  10443. "patient": patient,
  10444. "department_name": department.Name, //科室
  10445. "number": his.Number, //门诊号
  10446. "date": order.SettleAccountsDate, //结算日期
  10447. "name": order.PsnName, //姓名
  10448. "gender": patient.Gender, //性别
  10449. "psn_cash_money": order.PsnCashPay, //个人支付
  10450. "pay_way": "门诊", //结算方式
  10451. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10452. "admin_user_name": admin.UserName, //收款员
  10453. "order": order,
  10454. "order_info": orderInfos_two,
  10455. "his": his,
  10456. "bedCostTotal": bedCostTotal,
  10457. "bedCostSelfTotal": bedCostSelfTotal,
  10458. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10459. "operationCostTotal": operationCostTotal,
  10460. "operationCostSelfTotal": operationCostSelfTotal,
  10461. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10462. "otherCostTotal": otherCostTotal,
  10463. "otherCostSelfTotal": otherCostSelfTotal,
  10464. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10465. "materialCostTotal": materialCostTotal,
  10466. "materialCostSelfTotal": materialCostSelfTotal,
  10467. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10468. "westernMedicineCostTotal": westernMedicineCostTotal,
  10469. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10470. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10471. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10472. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10473. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10474. "checkCostTotal": checkCostTotal,
  10475. "checkCostSelfTotal": checkCostSelfTotal,
  10476. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10477. "laboratoryCostTotal": laboratoryCostTotal,
  10478. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10479. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10480. "treatCostTotal": treatCostTotal,
  10481. "treatCostSelfTotal": treatCostSelfTotal,
  10482. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10483. "zhenChaCostTotal": zhenChaCostTotal,
  10484. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10485. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10486. "his_hospital_record": his_hospital_record,
  10487. "pre_pay_money": pre_pay_money,
  10488. "refund_sum": sum,
  10489. "doctor_info": doctor_info,
  10490. "hiliCostTotal": hiliCostTotal,
  10491. "hiliCostSelfTotal": hiliCostSelfTotal,
  10492. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10493. })
  10494. }
  10495. //func (c *HisApiController) GetFaPiaoDatas() {
  10496. // order_ids := c.GetString("order_ids")
  10497. // patient_id, _ := c.GetInt64("patient_id")
  10498. // adminUser := c.GetAdminUserInfo()
  10499. //
  10500. // orders := strings.Split(order_ids, ",")
  10501. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10502. //
  10503. // for _, item := range orders {
  10504. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10505. // order, _ := service.GetHisOrderByID(order_id)
  10506. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10507. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10508. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10509. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10510. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10511. //
  10512. // }
  10513. //
  10514. // var bedCostTotal float64 = 0 //床位总费
  10515. // var bedCostSelfTotal float64 = 0 //床位自费
  10516. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10517. //
  10518. // var operationCostTotal float64 = 0 //手术费
  10519. // var operationCostSelfTotal float64 = 0 //手术费
  10520. // var operationCostPartSelfTotal float64 = 0 //手术费
  10521. //
  10522. // var otherCostTotal float64 = 0 //其他费用
  10523. // var otherCostSelfTotal float64 = 0 //其他费用
  10524. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10525. //
  10526. // var materialCostTotal float64 = 0 //材料费
  10527. // var materialCostSelfTotal float64 = 0 //材料费
  10528. // var materialCostPartSelfTotal float64 = 0 //材料费
  10529. //
  10530. // var westernMedicineCostTotal float64 = 0 //西药费
  10531. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10532. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10533. //
  10534. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10535. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10536. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10537. //
  10538. // var checkCostTotal float64 = 0 //检查费
  10539. // var checkCostSelfTotal float64 = 0 //检查费
  10540. // var checkCostPartSelfTotal float64 = 0 //检查费
  10541. //
  10542. // var laboratoryCostTotal float64 = 0 //化验费
  10543. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10544. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10545. //
  10546. // var treatCostTotal float64 = 0 //治疗费用
  10547. // var treatCostSelfTotal float64 = 0 //治疗费用
  10548. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10549. //
  10550. // var zhenChaCostTotal float64 = 0 //其他费用
  10551. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10552. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10553. //
  10554. // decimal.DivisionPrecision = 2
  10555. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10556. //
  10557. // var balanceAccountsType int64
  10558. // if his.ID > 0 {
  10559. // balanceAccountsType = his.BalanceAccountsType
  10560. // } else {
  10561. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10562. // }
  10563. // if balanceAccountsType == 2 {
  10564. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10565. // for _, item := range orderInfos_two {
  10566. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10567. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10568. // item.MedChrgitmType = "09"
  10569. // }
  10570. //
  10571. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10572. // if item.HisPrescriptionProject.Type == 2 {
  10573. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10574. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10575. // case 0:
  10576. // item.MedChrgitmType = "0"
  10577. // break
  10578. // case 1:
  10579. // item.MedChrgitmType = "14"
  10580. // break
  10581. // case 2:
  10582. // item.MedChrgitmType = "05"
  10583. //
  10584. // break
  10585. // case 3:
  10586. // item.MedChrgitmType = "03"
  10587. //
  10588. // break
  10589. // case 4:
  10590. // item.MedChrgitmType = "03"
  10591. //
  10592. // break
  10593. // case 5:
  10594. // item.MedChrgitmType = "08"
  10595. //
  10596. // break
  10597. // case 6:
  10598. // item.MedChrgitmType = "14"
  10599. //
  10600. // break
  10601. // case 7:
  10602. // item.MedChrgitmType = "14"
  10603. //
  10604. // break
  10605. // case 8:
  10606. // item.MedChrgitmType = "03"
  10607. // break
  10608. // case 9:
  10609. // item.MedChrgitmType = "14"
  10610. // break
  10611. // case 10:
  10612. // item.MedChrgitmType = "14"
  10613. // break
  10614. // case 11:
  10615. // item.MedChrgitmType = "06"
  10616. // break
  10617. // case 12:
  10618. // item.MedChrgitmType = "12"
  10619. // break
  10620. // case 13:
  10621. // item.MedChrgitmType = "01"
  10622. // break
  10623. // case 14:
  10624. // item.MedChrgitmType = "04"
  10625. // break
  10626. // case 15:
  10627. // item.MedChrgitmType = "02"
  10628. // break
  10629. //
  10630. // }
  10631. //
  10632. // } else {
  10633. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10634. //
  10635. // case 1:
  10636. // item.MedChrgitmType = "14"
  10637. // break
  10638. // case 2:
  10639. // item.MedChrgitmType = "05"
  10640. //
  10641. // break
  10642. // case 3:
  10643. // item.MedChrgitmType = "03"
  10644. //
  10645. // break
  10646. // case 4:
  10647. // item.MedChrgitmType = "03"
  10648. //
  10649. // break
  10650. // case 5:
  10651. // item.MedChrgitmType = "08"
  10652. //
  10653. // break
  10654. // case 6:
  10655. // item.MedChrgitmType = "14"
  10656. //
  10657. // break
  10658. // case 7:
  10659. // item.MedChrgitmType = "14"
  10660. //
  10661. // break
  10662. // case 8:
  10663. // item.MedChrgitmType = "03"
  10664. // break
  10665. // case 9:
  10666. // item.MedChrgitmType = "14"
  10667. // break
  10668. //
  10669. // }
  10670. //
  10671. // }
  10672. //
  10673. // } else if item.HisPrescriptionProject.Type == 3 {
  10674. // item.MedChrgitmType = "08"
  10675. // }
  10676. // }
  10677. // }
  10678. //
  10679. // for _, item := range orderInfos_two {
  10680. // fmt.Println(item.MedChrgitmType)
  10681. // if item.MedChrgitmType == "01" { //床位费
  10682. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10683. // bedCostSelfTotal = bedCostTotal
  10684. // }
  10685. //
  10686. // if item.MedChrgitmType == "02" { //诊察费
  10687. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10688. // zhenChaCostSelfTotal = zhenChaCostTotal
  10689. // }
  10690. //
  10691. // if item.MedChrgitmType == "03" { //检查费
  10692. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10693. // checkCostSelfTotal = checkCostTotal
  10694. // }
  10695. //
  10696. // if item.MedChrgitmType == "04" { //化验费
  10697. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10698. // laboratoryCostSelfTotal = laboratoryCostTotal
  10699. // }
  10700. //
  10701. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10702. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10703. // treatCostSelfTotal = treatCostTotal
  10704. // }
  10705. //
  10706. // if item.MedChrgitmType == "06" { //手术费
  10707. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10708. // operationCostSelfTotal = treatCostTotal
  10709. // }
  10710. //
  10711. // if item.MedChrgitmType == "08" { //材料费
  10712. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10713. // materialCostSelfTotal = materialCostTotal
  10714. // }
  10715. //
  10716. // if item.MedChrgitmType == "09" { //西药费
  10717. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10718. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10719. // }
  10720. //
  10721. // if item.MedChrgitmType == "11" { //中成费
  10722. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10724. // }
  10725. //
  10726. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10727. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10728. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10729. // otherCostSelfTotal = otherCostTotal
  10730. // }
  10731. // } else {
  10732. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10733. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10734. // otherCostSelfTotal = otherCostTotal
  10735. // }
  10736. //
  10737. // }
  10738. //
  10739. // }
  10740. //
  10741. // } else {
  10742. // for _, item := range orderInfos {
  10743. // if item.MedChrgitmType == "01" { //床位费
  10744. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10745. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10746. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10747. // }
  10748. //
  10749. // if item.MedChrgitmType == "02" { //诊察费
  10750. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10751. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10752. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10753. // }
  10754. //
  10755. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10756. // if item.MedChrgitmType == "03" { //检查费
  10757. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10758. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10759. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10760. //
  10761. // }
  10762. // } else {
  10763. // if item.MedChrgitmType == "03" { //检查费
  10764. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10765. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10766. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10767. // }
  10768. //
  10769. // }
  10770. //
  10771. // if item.MedChrgitmType == "04" { //化验费
  10772. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10773. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10774. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10775. //
  10776. // }
  10777. //
  10778. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10779. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10780. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10781. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10782. //
  10783. // }
  10784. //
  10785. // if item.MedChrgitmType == "06" { //手术费
  10786. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10787. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10788. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10789. // }
  10790. //
  10791. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10792. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10793. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10794. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10795. // }
  10796. //
  10797. // if item.MedChrgitmType == "09" { //西药费
  10798. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10799. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10800. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10801. // }
  10802. //
  10803. // if item.MedChrgitmType == "11" { //中成费
  10804. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10805. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10806. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10807. // }
  10808. //
  10809. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10810. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10811. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10812. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10813. // }
  10814. //
  10815. // }
  10816. // }
  10817. // timeLayout := "2006-01-02"
  10818. // loc, _ := time.LoadLocation("Local")
  10819. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10820. // if err != nil {
  10821. // }
  10822. // startRecordDateTime := startTime.Unix()
  10823. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10824. // if err != nil {
  10825. // }
  10826. // endRecordDateTime := endTime.Unix()
  10827. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10828. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10829. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10830. //
  10831. // c.ServeSuccessJSON(map[string]interface{}{
  10832. // "order_number": order.Number, //业务流水号
  10833. // "id_card_no": his.IdCardNo, //社会保障号
  10834. // "department_name": department.Name, //科室
  10835. // "number": his.Number, //门诊号
  10836. // "date": order.SettleAccountsDate, //结算日期
  10837. // "name": order.PsnName, //姓名
  10838. // "gender": patient.Gender, //性别
  10839. // "psn_cash_money": order.PsnCashPay, //个人支付
  10840. // "pay_way": "门诊", //结算方式
  10841. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10842. // "admin_user_name": admin.UserName, //收款员
  10843. // "order": order,
  10844. // "order_info": orderInfos_two,
  10845. // "his": his,
  10846. // "bedCostTotal": bedCostTotal,
  10847. // "bedCostSelfTotal": bedCostSelfTotal,
  10848. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10849. // "operationCostTotal": operationCostTotal,
  10850. // "operationCostSelfTotal": operationCostSelfTotal,
  10851. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10852. // "otherCostTotal": otherCostTotal,
  10853. // "otherCostSelfTotal": otherCostSelfTotal,
  10854. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10855. // "materialCostTotal": materialCostTotal,
  10856. // "materialCostSelfTotal": materialCostSelfTotal,
  10857. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10858. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10859. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10860. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10861. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10862. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10863. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10864. // "checkCostTotal": checkCostTotal,
  10865. // "checkCostSelfTotal": checkCostSelfTotal,
  10866. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10867. // "laboratoryCostTotal": laboratoryCostTotal,
  10868. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10869. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10870. // "treatCostTotal": treatCostTotal,
  10871. // "treatCostSelfTotal": treatCostSelfTotal,
  10872. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10873. // "zhenChaCostTotal": zhenChaCostTotal,
  10874. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10875. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10876. // "his_hospital_record": his_hospital_record,
  10877. // "pre_pay_money": pre_pay_money,
  10878. // "refund_sum": sum,
  10879. // })
  10880. //
  10881. //}
  10882. func (this *HisApiController) GetIncomeStatisticsData() {
  10883. start_time := this.GetString("start_time")
  10884. end_time := this.GetString("end_time")
  10885. key_words := this.GetString("key_words")
  10886. limit, _ := this.GetInt64("limit")
  10887. page, _ := this.GetInt64("page")
  10888. if page <= 0 {
  10889. page = 1
  10890. }
  10891. if limit <= 0 {
  10892. limit = 10
  10893. }
  10894. statistics_type, _ := this.GetInt64("statistics_type")
  10895. admin := this.GetAdminUserInfo()
  10896. timeLayout := "2006-01-02"
  10897. loc, _ := time.LoadLocation("Local")
  10898. var theStartTIme int64
  10899. if len(start_time) > 0 {
  10900. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10901. if err != nil {
  10902. theStartTIme = 0
  10903. }
  10904. theStartTIme = theTime.Unix()
  10905. }
  10906. var theEndtTIme int64
  10907. if len(end_time) > 0 {
  10908. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10909. if err != nil {
  10910. theEndtTIme = 0
  10911. }
  10912. theEndtTIme = theTime.Unix()
  10913. }
  10914. if statistics_type == 1 {
  10915. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10916. this.ServeSuccessJSON(map[string]interface{}{
  10917. "list": list,
  10918. "total": total,
  10919. })
  10920. } else {
  10921. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10922. this.ServeSuccessJSON(map[string]interface{}{
  10923. "list": list,
  10924. "total": total,
  10925. })
  10926. }
  10927. }
  10928. func (c *HisApiController) PostProjectInformation() {
  10929. adminUser := c.GetAdminUserInfo()
  10930. orgId := adminUser.CurrentOrgId
  10931. dataBody := make(map[string]interface{}, 0)
  10932. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10933. if err != nil {
  10934. utils.ErrorLog(err.Error())
  10935. return
  10936. }
  10937. utils.ErrorLog("%v", dataBody)
  10938. var projectList []*models.HisProject
  10939. var total_goods []interface{}
  10940. tempProjects := dataBody["projects"].([]interface{})
  10941. total_goods = tempProjects
  10942. for index, projectMap := range tempProjects {
  10943. projectM := projectMap.(map[string]interface{})
  10944. var project models.HisProject
  10945. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10946. utils.ErrorLog("project_name")
  10947. return
  10948. }
  10949. project_name, _ := projectM["project_name"].(string)
  10950. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10951. err_log := models.ExportErrLog{
  10952. LogType: 6,
  10953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10954. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10955. Status: 1,
  10956. CreateTime: time.Now().Unix(),
  10957. UpdateTime: time.Now().Unix(),
  10958. ExportTime: time.Now().Unix(),
  10959. }
  10960. service.CreateExportErrLog(&err_log)
  10961. continue
  10962. }
  10963. project.ProjectName = project_name
  10964. prices := projectM["price"].(string)
  10965. price, _ := strconv.ParseFloat(prices, 64)
  10966. if price <= 0 { //名字为空则生成一条导入错误日志
  10967. err_log := models.ExportErrLog{
  10968. LogType: 6,
  10969. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10970. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10971. Status: 1,
  10972. CreateTime: time.Now().Unix(),
  10973. UpdateTime: time.Now().Unix(),
  10974. ExportTime: time.Now().Unix(),
  10975. }
  10976. service.CreateExportErrLog(&err_log)
  10977. continue
  10978. }
  10979. project.Price = price
  10980. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10981. utils.ErrorLog("unit_id")
  10982. return
  10983. }
  10984. unit := projectM["unit"].(string)
  10985. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10986. err_log := models.ExportErrLog{
  10987. LogType: 6,
  10988. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10989. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10990. Status: 1,
  10991. CreateTime: time.Now().Unix(),
  10992. UpdateTime: time.Now().Unix(),
  10993. ExportTime: time.Now().Unix(),
  10994. }
  10995. service.CreateExportErrLog(&err_log)
  10996. continue
  10997. }
  10998. project.Unit = unit
  10999. cost_classify := projectM["cost_classify"].(string)
  11000. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11001. err_log := models.ExportErrLog{
  11002. LogType: 6,
  11003. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11004. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11005. Status: 1,
  11006. CreateTime: time.Now().Unix(),
  11007. UpdateTime: time.Now().Unix(),
  11008. ExportTime: time.Now().Unix(),
  11009. }
  11010. service.CreateExportErrLog(&err_log)
  11011. continue
  11012. }
  11013. var costClassify = "费用类别"
  11014. var cost_classify_id int64
  11015. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11016. if len(cost_classify) != 0 {
  11017. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11018. if errcode == gorm.ErrRecordNotFound {
  11019. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11020. dataconfig := models.DictDataconfig{
  11021. ParentId: costClassifyConfig.ID,
  11022. Module: "system",
  11023. OrgId: orgId,
  11024. Name: cost_classify,
  11025. FieldName: "",
  11026. Value: costConfig.Value + 1,
  11027. CreatedTime: "",
  11028. UpdatedTime: "",
  11029. CreateUserId: adminUser.AdminUser.Id,
  11030. Status: 1,
  11031. Remark: "",
  11032. DeleteIdSystem: 0,
  11033. Title: "",
  11034. Content: "",
  11035. Order: 0,
  11036. Code: "",
  11037. }
  11038. service.CreatedDicConfig(&dataconfig)
  11039. }
  11040. }
  11041. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11042. for _, it := range costClassList {
  11043. if cost_classify == it.Name {
  11044. cost_classify_id = int64(it.Value)
  11045. }
  11046. }
  11047. project.CostClassify = cost_classify_id
  11048. executive_section := projectM["executive_section"].(string)
  11049. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11050. err_log := models.ExportErrLog{
  11051. LogType: 6,
  11052. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11053. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11054. Status: 1,
  11055. CreateTime: time.Now().Unix(),
  11056. UpdateTime: time.Now().Unix(),
  11057. ExportTime: time.Now().Unix(),
  11058. }
  11059. service.CreateExportErrLog(&err_log)
  11060. continue
  11061. }
  11062. if len(executive_section) != 0 {
  11063. //查找科室是否有内容
  11064. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11065. if errcodedepart == gorm.ErrRecordNotFound {
  11066. department := models.XtHisDepartment{
  11067. Name: executive_section,
  11068. Status: 1,
  11069. UserOrgId: adminUser.CurrentOrgId,
  11070. CreatedTime: time.Now().Unix(),
  11071. }
  11072. service.CreateDePartment(&department)
  11073. }
  11074. }
  11075. var executive_section_id int64
  11076. departMentList, _ := service.GetAllDepartMent(orgId)
  11077. for _, it := range departMentList {
  11078. if executive_section == it.Name {
  11079. executive_section_id = it.ID
  11080. }
  11081. }
  11082. project.ExecutiveSection = executive_section_id
  11083. medical_coverage := projectM["medical_coverage"].(string)
  11084. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11085. err_log := models.ExportErrLog{
  11086. LogType: 6,
  11087. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11088. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11089. Status: 1,
  11090. CreateTime: time.Now().Unix(),
  11091. UpdateTime: time.Now().Unix(),
  11092. ExportTime: time.Now().Unix(),
  11093. }
  11094. service.CreateExportErrLog(&err_log)
  11095. continue
  11096. }
  11097. var medicalCoverage = "医保等级"
  11098. var medical_coverage_id int64
  11099. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11100. if len(medical_coverage) != 0 {
  11101. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11102. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11103. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11104. dataconfig := models.DictDataconfig{
  11105. ParentId: medicalCoverageConfig.ID,
  11106. Module: "system",
  11107. OrgId: orgId,
  11108. Name: medical_coverage,
  11109. FieldName: "",
  11110. Value: medicalCoverageConfig.Value + 1,
  11111. CreatedTime: "",
  11112. UpdatedTime: "",
  11113. CreateUserId: adminUser.AdminUser.Id,
  11114. Status: 1,
  11115. Remark: "",
  11116. DeleteIdSystem: 0,
  11117. Title: "",
  11118. Content: "",
  11119. Order: 0,
  11120. Code: "",
  11121. }
  11122. service.CreatedDicConfig(&dataconfig)
  11123. }
  11124. }
  11125. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11126. for _, it := range medicalCoverageList {
  11127. if medical_coverage == it.Name {
  11128. medical_coverage_id = int64(it.Value)
  11129. }
  11130. }
  11131. project.MedicalCoverage = medical_coverage_id
  11132. pinyin := projectM["pinyin"].(string)
  11133. project.Pinyin = pinyin
  11134. wubi := projectM["wubi"].(string)
  11135. project.Wubi = wubi
  11136. statistical_classification := projectM["statistical_classification"].(string)
  11137. var statisticalClassification = "统计分类"
  11138. var statistical_classification_id int64
  11139. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11140. if len(statistical_classification) != 0 {
  11141. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11142. if classificationerrcodes == gorm.ErrRecordNotFound {
  11143. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11144. dataconfig := models.DictDataconfig{
  11145. ParentId: classiFication.ID,
  11146. Module: "system",
  11147. OrgId: orgId,
  11148. Name: statistical_classification,
  11149. FieldName: "",
  11150. Value: classiFicationConfig.Value + 1,
  11151. CreatedTime: "",
  11152. UpdatedTime: "",
  11153. CreateUserId: adminUser.AdminUser.Id,
  11154. Status: 1,
  11155. Remark: "",
  11156. DeleteIdSystem: 0,
  11157. Title: "",
  11158. Content: "",
  11159. Order: 0,
  11160. Code: "",
  11161. }
  11162. service.CreatedDicConfig(&dataconfig)
  11163. }
  11164. }
  11165. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11166. for _, it := range classiFicationList {
  11167. if statistical_classification == it.Name {
  11168. statistical_classification_id = int64(it.Value)
  11169. }
  11170. }
  11171. project.StatisticalClassification = statistical_classification_id
  11172. disease_directory := int64(projectM["disease_directory"].(float64))
  11173. project.DiseaseDirectory = disease_directory
  11174. is_record := int64(projectM["is_record"].(float64))
  11175. project.IsRecord = is_record
  11176. medical_code := projectM["medical_code"].(string)
  11177. project.MedicalCode = medical_code
  11178. tube_color := projectM["tube_color"].(string)
  11179. var tubeColor = "试管颜色"
  11180. var tube_color_id int64
  11181. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11182. if len(tube_color) != 0 {
  11183. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11184. if errcodetube == gorm.ErrRecordNotFound {
  11185. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11186. dataconfig := models.DictDataconfig{
  11187. ParentId: tubeColorConfig.ID,
  11188. Module: "system",
  11189. OrgId: orgId,
  11190. Name: tube_color,
  11191. FieldName: "",
  11192. Value: tubeConfig.Value + 1,
  11193. CreatedTime: "",
  11194. UpdatedTime: "",
  11195. CreateUserId: adminUser.AdminUser.Id,
  11196. Status: 1,
  11197. Remark: "",
  11198. DeleteIdSystem: 0,
  11199. Title: "",
  11200. Content: "",
  11201. Order: 0,
  11202. Code: "",
  11203. }
  11204. service.CreatedDicConfig(&dataconfig)
  11205. }
  11206. }
  11207. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11208. for _, it := range tubeColorList {
  11209. if tube_color == it.Name {
  11210. tube_color_id = int64(it.Value)
  11211. }
  11212. }
  11213. project.TubeColor = tube_color_id
  11214. single_dose := projectM["single_dose"].(string)
  11215. project.SingleDose = single_dose
  11216. execution_frequency := projectM["execution_frequency"].(string)
  11217. project.ExecutionFrequency = execution_frequency
  11218. delivery_way := projectM["delivery_way"].(string)
  11219. project.DeliveryWay = delivery_way
  11220. number_days := projectM["number_days"].(string)
  11221. project.NumberDays = number_days
  11222. total := projectM["total"].(string)
  11223. project.Total = total
  11224. medical_status := int64(projectM["medical_status"].(float64))
  11225. project.MedicalStatus = medical_status
  11226. category := int64(projectM["category"].(float64))
  11227. project.Category = category
  11228. specail_project := int64(projectM["specail_project"].(float64))
  11229. project.SpecailProject = specail_project
  11230. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11231. project.SocialSecurityDirectoryCode = social_security_directory_code
  11232. remark := projectM["remark"].(string)
  11233. project.Remark = remark
  11234. record_date := projectM["record_date"].(string)
  11235. timeLayout := "2006-01-02"
  11236. loc, _ := time.LoadLocation("Local")
  11237. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11238. project.RecordDate = theTime.Unix()
  11239. projectList = append(projectList, &project)
  11240. }
  11241. export_time := time.Now().Unix()
  11242. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11243. if len(projectList) > 0 {
  11244. for _, item := range projectList {
  11245. hans := item.ProjectName // 要转换的汉字字符串
  11246. // 创建一个拼音转换器
  11247. p := pinyin.NewArgs()
  11248. // 将汉字转为拼音
  11249. pinyinSlice := pinyin.Pinyin(hans, p)
  11250. // 输出拼音
  11251. fmt.Println("Pinyin:", pinyinSlice)
  11252. // 获取首字母
  11253. firstLetter := ""
  11254. for _, py := range pinyinSlice {
  11255. if len(py) > 0 {
  11256. firstLetter += string(py[0][0])
  11257. }
  11258. }
  11259. item.FirstLetter = firstLetter
  11260. project := models.HisProject{
  11261. ProjectName: item.ProjectName,
  11262. Price: item.Price,
  11263. Unit: item.Unit,
  11264. CostClassify: item.CostClassify,
  11265. ExecutiveSection: item.ExecutiveSection,
  11266. MedicalCoverage: item.MedicalCoverage,
  11267. UserOrgId: orgId,
  11268. Status: 1,
  11269. CreatedTime: time.Now().Unix(),
  11270. Pinyin: item.Pinyin,
  11271. Wubi: item.Wubi,
  11272. StatisticalClassification: item.StatisticalClassification,
  11273. DiseaseDirectory: item.DiseaseDirectory,
  11274. IsRecord: item.IsRecord,
  11275. MedicalCode: item.MedicalCode,
  11276. TubeColor: item.TubeColor,
  11277. SingleDose: item.SingleDose,
  11278. DeliveryWay: item.DeliveryWay,
  11279. NumberDays: item.NumberDays,
  11280. Total: item.Total,
  11281. Category: item.Category,
  11282. MedicalStatus: item.MedicalStatus,
  11283. SpecailProject: item.SpecailProject,
  11284. RecordDate: item.RecordDate,
  11285. Remark: item.Remark,
  11286. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11287. ExecutionFrequency: item.ExecutionFrequency,
  11288. FirstLetter: item.FirstLetter,
  11289. }
  11290. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11291. if errcodeproject == gorm.ErrRecordNotFound {
  11292. service.CreateProjectInfomation(&project)
  11293. } else if errcodeproject == nil {
  11294. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11295. }
  11296. log := models.ExportLog{
  11297. LogType: 6,
  11298. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11299. TotalNum: int64(len(total_goods)),
  11300. FailNum: int64(len(errLogs)),
  11301. SuccessNum: int64(len(projectList)),
  11302. CreateTime: time.Now().Unix(),
  11303. UpdateTime: time.Now().Unix(),
  11304. ExportTime: export_time,
  11305. Status: 1,
  11306. }
  11307. service.CreateExportLog(&log)
  11308. c.ServeSuccessJSON(map[string]interface{}{
  11309. "msg": "导入成功",
  11310. "total_num": len(total_goods),
  11311. "success_num": len(projectList),
  11312. "fail_num": int64(len(errLogs)),
  11313. })
  11314. }
  11315. } else {
  11316. log := models.ExportLog{
  11317. LogType: 6,
  11318. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11319. TotalNum: int64(len(total_goods)),
  11320. FailNum: int64(len(errLogs)),
  11321. SuccessNum: int64(len(projectList)),
  11322. CreateTime: time.Now().Unix(),
  11323. UpdateTime: time.Now().Unix(),
  11324. ExportTime: export_time,
  11325. Status: 1,
  11326. }
  11327. service.CreateExportLog(&log)
  11328. c.ServeSuccessJSON(map[string]interface{}{
  11329. "msg": "导入成功",
  11330. "total_num": len(total_goods),
  11331. "success_num": len(projectList),
  11332. "fail_num": int64(len(errLogs)),
  11333. })
  11334. }
  11335. }
  11336. //func (this *HisApiController) EditProjectInformation(){
  11337. //
  11338. // id, _ := this.GetInt64("id")
  11339. // project_team := this.GetString("project_team")
  11340. // price := this.GetString("price")
  11341. // price_float, _ := strconv.ParseFloat(price, 64)
  11342. // pinyin := this.GetString("pinyin")
  11343. // wubi := this.GetString("wubi")
  11344. // tube_color, _ := this.GetInt64("tube_color")
  11345. // team_type, _ := this.GetInt64("team_type")
  11346. // remark := this.GetString("remark")
  11347. // ids := this.GetString("ids")
  11348. // item_id := this.GetString("item_id")
  11349. // projectTeam := models.XtHisProjectTeam{
  11350. // ProjectTeam: project_team,
  11351. // Price: price_float,
  11352. // Pinyin: pinyin,
  11353. // Wubi: wubi,
  11354. // TubeColor: tube_color,
  11355. // TeamType: team_type,
  11356. // Remark: remark,
  11357. // ProjectId: ids,
  11358. // ItemId: item_id,
  11359. // }
  11360. //
  11361. //
  11362. // dataBody := make(map[string]interface{}, 0)
  11363. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11364. // if err != nil {
  11365. // utils.ErrorLog(err.Error())
  11366. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11367. // return
  11368. // }
  11369. //
  11370. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11371. //
  11372. //
  11373. // if err != nil {
  11374. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11375. // return
  11376. // }
  11377. //
  11378. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11379. // infos, _ := dataBody["info"].([]interface{})
  11380. // if len(infos) > 0 {
  11381. // var ids []string
  11382. //
  11383. // for _, item := range infos {
  11384. // items := item.(map[string]interface{})
  11385. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11386. // utils.ErrorLog("id")
  11387. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11388. // return
  11389. // }
  11390. // id := int64(items["id"].(float64))
  11391. //
  11392. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11393. // utils.ErrorLog("type")
  11394. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11395. // return
  11396. // }
  11397. // types := int64(items["type"].(float64))
  11398. //
  11399. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11400. // utils.ErrorLog("number")
  11401. // }
  11402. //
  11403. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11404. //
  11405. // projectList := models.XtHisProjectList{
  11406. // Number: number,
  11407. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11408. // ProjectId: id,
  11409. // Status: 1,
  11410. // CreatedTime: time.Now().Unix(),
  11411. // UpdatedTime: time.Now().Unix(),
  11412. // TeamId: projectTeam.ID,
  11413. // Type: types,
  11414. // }
  11415. // list := projectList
  11416. //
  11417. // service.CreateProjectList(&list)
  11418. //
  11419. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11420. //
  11421. // }
  11422. // ids_str := strings.Join(ids, ",")
  11423. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11424. // service.SaveProjectTeam(&projectTeam)
  11425. // this.ServeSuccessJSON(map[string]interface{}{
  11426. // "projectTeam": projectTeam,
  11427. // })
  11428. // }
  11429. // }
  11430. //}
  11431. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11432. name := c.GetString("name")
  11433. mode_id, _ := c.GetInt64("mode", 0)
  11434. types, _ := c.GetInt64("type", 0)
  11435. patient_id, _ := c.GetInt64("patient_id", 0)
  11436. types = 1
  11437. adminInfo := c.GetAdminUserInfo()
  11438. template := &models.HisPrescriptionTemplate{
  11439. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11440. PatientId: patient_id,
  11441. Type: types,
  11442. Status: 1,
  11443. Ctime: time.Now().Unix(),
  11444. Mtime: time.Now().Unix(),
  11445. Name: name,
  11446. Mode: mode_id,
  11447. }
  11448. dataBody := make(map[string]interface{}, 0)
  11449. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11450. if err != nil {
  11451. utils.ErrorLog(err.Error())
  11452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11453. return
  11454. }
  11455. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11456. //如果已经存在记录则删除处方
  11457. if template_one.ID > 0 {
  11458. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11459. var ids []int64
  11460. var org_id int64
  11461. for _, item := range ps {
  11462. org_id = c.GetAdminUserInfo().CurrentOrgId
  11463. ids = append(ids, item.ID)
  11464. }
  11465. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11466. if err2 == nil {
  11467. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11468. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11469. if len(prescriptions) > 0 {
  11470. for _, item := range prescriptions {
  11471. items := item.(map[string]interface{})
  11472. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11473. utils.ErrorLog("type")
  11474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11475. return
  11476. }
  11477. types := int64(items["type"].(float64))
  11478. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11479. utils.ErrorLog("med_type")
  11480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11481. return
  11482. }
  11483. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11484. ctime := time.Now().Unix()
  11485. prescription := &models.HisPrescriptionInfoTemplate{
  11486. PatientId: patient_id,
  11487. UserOrgId: adminInfo.CurrentOrgId,
  11488. Ctime: ctime,
  11489. Mtime: ctime,
  11490. Type: types,
  11491. Modifier: adminInfo.AdminUser.Id,
  11492. Creator: adminInfo.AdminUser.Id,
  11493. Status: 1,
  11494. PTemplateId: template_one.ID,
  11495. MedType: med_type,
  11496. }
  11497. service.CreateHisPrescriptionInfoTemplate(prescription)
  11498. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11499. advices := items["advices"].([]interface{})
  11500. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11501. ctime := time.Now().Unix()
  11502. mtime := ctime
  11503. if len(advices) > 0 {
  11504. for _, advice := range advices {
  11505. var s models.HisPrescriptionAdviceTemplate
  11506. s.PrescriptionId = prescription.ID
  11507. s.AdviceType = 2
  11508. s.StopState = 2
  11509. s.ExecutionState = 2
  11510. s.Status = 1
  11511. s.UserOrgId = adminInfo.CurrentOrgId
  11512. s.CreatedTime = ctime
  11513. s.UpdatedTime = mtime
  11514. s.PatientId = patient_id
  11515. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11516. if errcode > 0 {
  11517. c.ServeFailJSONWithSGJErrorCode(errcode)
  11518. return
  11519. }
  11520. service.CreateHisPrescriptionAdviceTemplate(&s)
  11521. }
  11522. }
  11523. }
  11524. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11525. projects := items["project"].([]interface{})
  11526. if len(projects) > 0 {
  11527. for _, project := range projects {
  11528. var p models.HisPrescriptionProjectTemplate
  11529. p.PrescriptionId = prescription.ID
  11530. p.Ctime = time.Now().Unix()
  11531. p.Mtime = time.Now().Unix()
  11532. p.PatientId = patient_id
  11533. p.UserOrgId = adminInfo.CurrentOrgId
  11534. p.Status = 1
  11535. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11536. if errcode > 0 {
  11537. c.ServeFailJSONWithSGJErrorCode(errcode)
  11538. return
  11539. }
  11540. service.CreateHisPrescriptionProjectTemplate(&p)
  11541. }
  11542. }
  11543. }
  11544. }
  11545. c.ServeSuccessJSON(map[string]interface{}{
  11546. "msg": "创建成功",
  11547. })
  11548. }
  11549. }
  11550. } else {
  11551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11552. return
  11553. }
  11554. } else {
  11555. err3 := service.CreateHisPrescriptionTemplate(template)
  11556. if err3 == nil {
  11557. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11558. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11559. if len(prescriptions) > 0 {
  11560. for _, item := range prescriptions {
  11561. items := item.(map[string]interface{})
  11562. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11563. utils.ErrorLog("type")
  11564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11565. return
  11566. }
  11567. types := int64(items["type"].(float64))
  11568. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11569. utils.ErrorLog("med_type")
  11570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11571. return
  11572. }
  11573. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11574. ctime := time.Now().Unix()
  11575. prescription := &models.HisPrescriptionInfoTemplate{
  11576. PatientId: patient_id,
  11577. UserOrgId: adminInfo.CurrentOrgId,
  11578. Ctime: ctime,
  11579. Mtime: ctime,
  11580. Type: types,
  11581. Modifier: adminInfo.AdminUser.Id,
  11582. Creator: adminInfo.AdminUser.Id,
  11583. Status: 1,
  11584. PTemplateId: template.ID,
  11585. MedType: med_type,
  11586. }
  11587. service.CreateHisPrescriptionInfoTemplate(prescription)
  11588. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11589. advices := items["advices"].([]interface{})
  11590. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11591. ctime := time.Now().Unix()
  11592. mtime := ctime
  11593. if len(advices) > 0 {
  11594. for _, advice := range advices {
  11595. var s models.HisPrescriptionAdviceTemplate
  11596. s.PrescriptionId = prescription.ID
  11597. s.AdviceType = 2
  11598. s.StopState = 2
  11599. s.ExecutionState = 2
  11600. s.Status = 1
  11601. s.UserOrgId = adminInfo.CurrentOrgId
  11602. s.CreatedTime = ctime
  11603. s.UpdatedTime = mtime
  11604. s.PatientId = patient_id
  11605. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11606. if errcode > 0 {
  11607. c.ServeFailJSONWithSGJErrorCode(errcode)
  11608. return
  11609. }
  11610. service.CreateHisPrescriptionAdviceTemplate(&s)
  11611. }
  11612. }
  11613. }
  11614. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11615. projects := items["project"].([]interface{})
  11616. if len(projects) > 0 {
  11617. for _, project := range projects {
  11618. var p models.HisPrescriptionProjectTemplate
  11619. p.PrescriptionId = prescription.ID
  11620. p.Ctime = time.Now().Unix()
  11621. p.Mtime = time.Now().Unix()
  11622. p.PatientId = patient_id
  11623. p.UserOrgId = adminInfo.CurrentOrgId
  11624. p.Status = 1
  11625. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11626. if errcode > 0 {
  11627. c.ServeFailJSONWithSGJErrorCode(errcode)
  11628. return
  11629. }
  11630. service.CreateHisPrescriptionProjectTemplate(&p)
  11631. }
  11632. }
  11633. }
  11634. }
  11635. c.ServeSuccessJSON(map[string]interface{}{
  11636. "msg": "创建成功",
  11637. })
  11638. }
  11639. }
  11640. } else {
  11641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11642. return
  11643. }
  11644. }
  11645. }
  11646. func (c *HisApiController) PreSettle() {
  11647. id, _ := c.GetInt64("id")
  11648. record_time := c.GetString("record_time")
  11649. his_patient_id, _ := c.GetInt64("his_patient_id")
  11650. timeLayout := "2006-01-02"
  11651. loc, _ := time.LoadLocation("Local")
  11652. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11653. diagnosis_id := c.GetString("diagnosis")
  11654. sick_type, _ := c.GetInt64("sick_type")
  11655. reg_type, _ := c.GetInt64("p_type")
  11656. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11658. if err != nil {
  11659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11660. return
  11661. }
  11662. recordDateTime := theTime.Unix()
  11663. adminUser := c.GetAdminUserInfo()
  11664. var prescriptions []*models.HisPrescription
  11665. var start_time int64
  11666. var end_time int64
  11667. ids_str := c.GetString("ids")
  11668. ids_arr := strings.Split(ids_str, ",")
  11669. fmt.Println(reg_type)
  11670. if settle_accounts_type == 1 { //日结
  11671. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11672. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11673. } else {
  11674. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11675. }
  11676. fmt.Println(prescriptions)
  11677. } else { //月结
  11678. start_time_str := c.GetString("start_time")
  11679. end_time_str := c.GetString("end_time")
  11680. timeLayout := "2006-01-02"
  11681. loc, _ := time.LoadLocation("Local")
  11682. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11683. if err != nil {
  11684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11685. return
  11686. }
  11687. recordStartTime := theStartTime.Unix()
  11688. start_time = recordStartTime
  11689. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11690. if err != nil {
  11691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11692. return
  11693. }
  11694. recordEndTime := theEndTime.Unix()
  11695. end_time = recordEndTime
  11696. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11697. }
  11698. if reg_type == 1111 || reg_type == 1112 {
  11699. reg_type = 11
  11700. }
  11701. timestamp := time.Now().Unix()
  11702. tempTime := time.Unix(timestamp, 0)
  11703. timeFormat := tempTime.Format("20060102150405")
  11704. chrgBchno := rand.Intn(100000) + 10000
  11705. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11706. strconv.FormatInt(his.PatientId, 10)
  11707. var ids []int64
  11708. for _, item := range prescriptions {
  11709. ids = append(ids, item.ID)
  11710. }
  11711. fmt.Println(ids)
  11712. var total float64
  11713. for _, item := range prescriptions {
  11714. fmt.Println(item)
  11715. if item.Type == 1 { //药品
  11716. for _, subItem := range item.HisDoctorAdviceInfo {
  11717. total = total + (subItem.Price * subItem.PrescribingNumber)
  11718. }
  11719. }
  11720. if item.Type == 2 { //项目
  11721. for _, subItem := range item.HisPrescriptionProject {
  11722. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11723. total = total + (subItem.Price * cnt)
  11724. }
  11725. }
  11726. for _, subItem := range item.HisAdditionalCharge {
  11727. total = total + (subItem.Price * float64(subItem.Count))
  11728. }
  11729. }
  11730. allTotal := fmt.Sprintf("%.2f", total)
  11731. totals, _ := strconv.ParseFloat(allTotal, 64)
  11732. order := &models.HisOrder{
  11733. UserOrgId: adminUser.CurrentOrgId,
  11734. HisPatientId: his.ID,
  11735. PatientId: id,
  11736. SettleAccountsDate: recordDateTime,
  11737. Ctime: time.Now().Unix(),
  11738. Mtime: time.Now().Unix(),
  11739. Status: 1,
  11740. OrderStatus: 1,
  11741. MdtrtId: his.Number,
  11742. Number: chrg_bchno,
  11743. MedfeeSumamt: totals,
  11744. SettleEndTime: end_time,
  11745. SettleStartTime: start_time,
  11746. SettleType: settle_accounts_type,
  11747. PsnPartAmt: totals,
  11748. PsnCashPay: totals,
  11749. PType: 2,
  11750. IsPre: 1,
  11751. MedType: strconv.Itoa(int(reg_type)),
  11752. Diagnosis: diagnosis_id,
  11753. }
  11754. err = service.CreateOrder(order)
  11755. if err != nil {
  11756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11757. return
  11758. }
  11759. var customs []*Custom
  11760. for _, item := range prescriptions {
  11761. fmt.Println(item.Type)
  11762. if item.Type == 1 { //药品
  11763. for _, subItem := range item.HisDoctorAdviceInfo {
  11764. cus := &Custom{
  11765. AdviceId: subItem.ID,
  11766. ProjectId: 0,
  11767. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11768. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11769. FeedetlSn: subItem.FeedetlSn,
  11770. Price: fmt.Sprintf("%.2f", subItem.Price),
  11771. MedListCodg: subItem.MedListCodg,
  11772. Type: 1,
  11773. }
  11774. customs = append(customs, cus)
  11775. }
  11776. }
  11777. if item.Type == 2 { //项目
  11778. for _, subItem := range item.HisPrescriptionProject {
  11779. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11780. cus := &Custom{
  11781. AdviceId: 0,
  11782. ProjectId: subItem.ID,
  11783. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11784. Cut: fmt.Sprintf("%.2f", cnt),
  11785. FeedetlSn: subItem.FeedetlSn,
  11786. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11787. MedListCodg: subItem.MedListCodg,
  11788. Type: 2,
  11789. }
  11790. customs = append(customs, cus)
  11791. }
  11792. }
  11793. for _, item := range item.HisAdditionalCharge {
  11794. cus := &Custom{
  11795. ItemId: item.ID,
  11796. AdviceId: 0,
  11797. ProjectId: 0,
  11798. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11799. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11800. FeedetlSn: item.FeedetlSn,
  11801. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11802. MedListCodg: item.XtHisAddtionConfig.Code,
  11803. Type: 3,
  11804. }
  11805. customs = append(customs, cus)
  11806. }
  11807. }
  11808. fmt.Println(customs)
  11809. for _, item := range customs {
  11810. var advice_id int64 = 0
  11811. var project_id int64 = 0
  11812. var item_id int64 = 0
  11813. var types int64 = 0
  11814. if item.Type == 1 {
  11815. advice_id = item.AdviceId
  11816. project_id = 0
  11817. item_id = 0
  11818. } else if item.Type == 2 {
  11819. advice_id = 0
  11820. item_id = 0
  11821. project_id = item.ProjectId
  11822. } else if item.Type == 3 {
  11823. advice_id = 0
  11824. item_id = item.ItemId
  11825. project_id = 0
  11826. }
  11827. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11828. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11829. pric, _ := strconv.ParseFloat(item.Price, 32)
  11830. info := &models.HisOrderInfo{
  11831. OrderNumber: order.Number,
  11832. UploadDate: time.Now().Unix(),
  11833. AdviceId: advice_id,
  11834. DetItemFeeSumamt: detItemFeeSumamt,
  11835. Cnt: cut,
  11836. Pric: pric,
  11837. PatientId: id,
  11838. Status: 1,
  11839. Mtime: time.Now().Unix(),
  11840. Ctime: time.Now().Unix(),
  11841. UserOrgId: adminUser.CurrentOrgId,
  11842. HisPatientId: his.ID,
  11843. OrderId: order.ID,
  11844. ProjectId: project_id,
  11845. Type: types,
  11846. ItemId: item_id,
  11847. }
  11848. service.CreateOrderInfo(info)
  11849. }
  11850. his.SickType = sick_type
  11851. service.UpdataHisPateint(&his)
  11852. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11853. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11854. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11855. if err == nil {
  11856. c.ServeSuccessJSON(map[string]interface{}{
  11857. "msg": "结算成功",
  11858. })
  11859. }
  11860. }
  11861. type CustomOrderInfo struct {
  11862. Name string
  11863. Spec string
  11864. Unit string
  11865. Count float64
  11866. Price float64
  11867. Total float64
  11868. }
  11869. func (c *HisApiController) GetPrivateExpensesInfo() {
  11870. order_id, _ := c.GetInt64("id", 0)
  11871. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11872. order, _ := service.GetHisOrderByID(order_id)
  11873. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11874. if order.ID == 0 {
  11875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11876. return
  11877. }
  11878. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11879. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11880. org_id := c.GetAdminUserInfo().CurrentOrgId
  11881. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11882. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11883. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11884. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11885. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11886. //var orderInfos_four []*models.HisOrderInfoTwo
  11887. //for _, item := range orderInfos_three {
  11888. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11889. // item.HisPrescriptionProject.IsCheckTeam = 1
  11890. // orderInfos_four = append(orderInfos_four, item)
  11891. //
  11892. // }
  11893. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11894. // item.HisPrescriptionProject.IsCheckTeam = 2
  11895. // orderInfos_two = append(orderInfos_two, item)
  11896. // }
  11897. //}
  11898. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11899. //var cus_slice []CustomOrderInfo
  11900. //for _, item := range new_order_info {
  11901. // var cus CustomOrderInfo
  11902. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11903. // cus.Unit = ""
  11904. // cus.Spec = ""
  11905. // var total float64
  11906. // for _, subItem := range orderInfos_four {
  11907. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11908. // total = total + subItem.DetItemFeeSumamt
  11909. // fmt.Println(subItem.DetItemFeeSumamt)
  11910. // }
  11911. // }
  11912. // cus.Count = 1
  11913. // cus.Total = total
  11914. // cus_slice = append(cus_slice, cus)
  11915. //}
  11916. orderInfos = append(orderInfos, orderInfos_two...)
  11917. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11918. //orderInfos = append(orderInfos, orderInfos_three...)
  11919. //}/**/
  11920. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11921. c.ServeSuccessJSON(map[string]interface{}{
  11922. "order": order,
  11923. "order_info": orderInfos,
  11924. "patient": patient,
  11925. "admin_info": adminInfo,
  11926. "his": his,
  11927. "current_admin": role,
  11928. "org_config": miConfig,
  11929. //"new_order_info": cus_slice,
  11930. })
  11931. }
  11932. func (this *HisApiController) ChangeMedType() {
  11933. med_type := this.GetString("med_type")
  11934. old_med_type := this.GetString("old_med_type")
  11935. ids := this.GetString("ids")
  11936. settle_type, _ := this.GetInt64("settle_type")
  11937. start_time := this.GetString("start_time")
  11938. end_time := this.GetString("end_time")
  11939. ids_arr := strings.Split(ids, ",")
  11940. if settle_type == 1 { //日结
  11941. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11942. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11943. prescription.MedType = med_type
  11944. err := service.SaveHisPrescriptionTwo(&prescription)
  11945. if err == nil {
  11946. this.ServeSuccessJSON(map[string]interface{}{
  11947. "msg": "修改成功",
  11948. })
  11949. } else {
  11950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11951. return
  11952. }
  11953. } else if settle_type == 2 {
  11954. timeLayout := "2006-01-02"
  11955. loc, _ := time.LoadLocation("Local")
  11956. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11957. if err != nil {
  11958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11959. return
  11960. }
  11961. recordStartTime := theStartTime.Unix()
  11962. start_time_timestamp := recordStartTime
  11963. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11964. if err != nil {
  11965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11966. return
  11967. }
  11968. recordEndTime := theEndTime.Unix()
  11969. end_time_timestamp := recordEndTime
  11970. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11971. if updateErr == nil {
  11972. this.ServeSuccessJSON(map[string]interface{}{
  11973. "msg": "修改成功",
  11974. })
  11975. } else {
  11976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11977. return
  11978. }
  11979. }
  11980. }
  11981. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11982. patient_id, _ := c.GetInt64("patient_id")
  11983. his_patient_id, _ := c.GetInt64("his_patient_id")
  11984. record_date := c.GetString("record_date")
  11985. start_time := c.GetString("start_time")
  11986. end_time := c.GetString("end_time")
  11987. order_status, _ := c.GetInt64("type", 0)
  11988. p_type, _ := c.GetInt64("p_type", 0)
  11989. order_id, _ := c.GetInt64("order_id", 0)
  11990. timeLayout := "2006-01-02"
  11991. loc, _ := time.LoadLocation("Local")
  11992. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11993. if err != nil {
  11994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11995. return
  11996. }
  11997. recordDateTime := theTime.Unix()
  11998. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11999. if err != nil {
  12000. }
  12001. startRecordDateTime := startTime.Unix()
  12002. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12003. if err != nil {
  12004. }
  12005. endRecordDateTime := endTime.Unix()
  12006. admin := c.GetAdminUserInfo()
  12007. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12008. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12009. order, _ := service.GetHisOrderByID(order_id)
  12010. var monthPrescriptions []*models.HisPrescription
  12011. if order_status == 1 || order_status == 0 {
  12012. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12013. } else if order_status == 2 {
  12014. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12015. }
  12016. var settle_total float64
  12017. for _, item := range monthPrescriptions {
  12018. if len(item.HisPrescriptionProject) > 0 {
  12019. for _, subItem := range item.HisPrescriptionProject {
  12020. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12021. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12022. settle_total = settle_total + total
  12023. }
  12024. }
  12025. if len(item.HisDoctorAdviceInfo) > 0 {
  12026. for _, subItem := range item.HisDoctorAdviceInfo {
  12027. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12028. settle_total = settle_total + total
  12029. }
  12030. }
  12031. }
  12032. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12033. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12034. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12035. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12036. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12037. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12038. //获取所有科室信息
  12039. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12040. var dia string
  12041. for _, item := range month_p_info {
  12042. if len(dia) == 0 {
  12043. dia = item.Diagnosis
  12044. } else {
  12045. dia = dia + "," + item.Diagnosis
  12046. }
  12047. }
  12048. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12049. dia_arr = removeEmptyStrings(dia_arr)
  12050. c.ServeSuccessJSON(map[string]interface{}{
  12051. "his_info": his_patient_info,
  12052. "xt_info": xt_patient_info,
  12053. "case_history": case_history,
  12054. "info": patientPrescriptionInfo,
  12055. "last_info": lastPatientPrescriptionInfo,
  12056. "month_prescriptions": monthPrescriptions,
  12057. "order": order,
  12058. "doctors": doctors,
  12059. "department": department,
  12060. "settle_total": settle_total,
  12061. "dia_arr": dia_arr,
  12062. })
  12063. return
  12064. }
  12065. func removeEmptyStrings(input []string) []string {
  12066. var output []string
  12067. for _, s := range input {
  12068. if s != "" {
  12069. output = append(output, s)
  12070. }
  12071. }
  12072. return output
  12073. }
  12074. func removeDuplicates(input []string) []string {
  12075. seen := make(map[string]bool)
  12076. output := []string{}
  12077. for _, s := range input {
  12078. if _, exists := seen[s]; !exists {
  12079. seen[s] = true
  12080. output = append(output, s)
  12081. }
  12082. }
  12083. return output
  12084. }
  12085. func (c *HisApiController) GetHisMonthPatientInfo() {
  12086. patient_id, _ := c.GetInt64("patient_id")
  12087. his_patient_id, _ := c.GetInt64("his_patient_id")
  12088. record_date := c.GetString("record_date")
  12089. number := c.GetString("number")
  12090. start_time := c.GetString("start_time")
  12091. end_time := c.GetString("end_time")
  12092. p_type, _ := c.GetInt64("p_type")
  12093. timeLayout := "2006-01-02"
  12094. loc, _ := time.LoadLocation("Local")
  12095. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12096. if err != nil {
  12097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12098. return
  12099. }
  12100. recordDateTime := theTime.Unix()
  12101. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12102. if err != nil {
  12103. }
  12104. startRecordDateTime := startTime.Unix()
  12105. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12106. if err != nil {
  12107. }
  12108. endRecordDateTime := endTime.Unix()
  12109. admin := c.GetAdminUserInfo()
  12110. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12111. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12112. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12113. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12114. var settle_total float64
  12115. for _, item := range monthPrescriptions {
  12116. if len(item.HisPrescriptionProject) > 0 {
  12117. for _, subItem := range item.HisPrescriptionProject {
  12118. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12119. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12120. settle_total = settle_total + total
  12121. }
  12122. }
  12123. if len(item.HisDoctorAdviceInfo) > 0 {
  12124. for _, subItem := range item.HisDoctorAdviceInfo {
  12125. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12126. settle_total = settle_total + total
  12127. }
  12128. }
  12129. }
  12130. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12131. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12132. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12133. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12134. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12135. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12136. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12137. //获取所有科室信息
  12138. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12139. c.ServeSuccessJSON(map[string]interface{}{
  12140. "his_info": his_patient_info,
  12141. "xt_info": xt_patient_info,
  12142. "case_history": case_history,
  12143. "info": patientPrescriptionInfo,
  12144. "month_prescriptions": monthPrescriptions,
  12145. "order": order,
  12146. "doctors": doctors,
  12147. "department": department,
  12148. "count": count,
  12149. "drugStockConfig": drugStockConfig,
  12150. "last_info": lastPatientPrescriptionInfo,
  12151. "settle_total": settle_total,
  12152. })
  12153. return
  12154. }
  12155. func (c *HisApiController) GetAllOrder() {
  12156. org_id := c.GetAdminUserInfo().CurrentOrgId
  12157. orders, _ := service.GetNewHisOrderList(org_id)
  12158. c.ServeSuccessJSON(map[string]interface{}{
  12159. "order": orders,
  12160. })
  12161. return
  12162. }
  12163. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12164. newArr = make([]*models.HisOrderInfoTwo, 0)
  12165. for i := 0; i < len(arr); i++ {
  12166. repeat := false
  12167. for j := i + 1; j < len(arr); j++ {
  12168. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12169. repeat = true
  12170. break
  12171. }
  12172. }
  12173. if !repeat {
  12174. newArr = append(newArr, arr[i])
  12175. }
  12176. }
  12177. return
  12178. }
  12179. // 修改处方退库操作 参数传修改之前的处方数据
  12180. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12181. if advice.ExecutionState == 1 {
  12182. //查询该病人该药品是否有库存记录
  12183. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12184. if errcode == gorm.ErrRecordNotFound {
  12185. } else {
  12186. //退库
  12187. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12188. if advice.PrescribingNumberUnit == drug.MinUnit {
  12189. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12190. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12191. //退库
  12192. warehouseInfo := models.DrugWarehouseInfo{
  12193. StockMinNumber: prescribingNumber,
  12194. }
  12195. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12196. operation_time := time.Now().Unix()
  12197. creater := advice.AdviceDoctor
  12198. ctime := time.Now().Unix()
  12199. timeStr := time.Now().Format("2006-01-02")
  12200. timeArr := strings.Split(timeStr, "-")
  12201. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12202. total = total + 1
  12203. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12204. cancelStock := models.DrugCancelStock{
  12205. OrderNumber: orderNumber,
  12206. OperaTime: operation_time,
  12207. OrgId: advice.UserOrgId,
  12208. Creater: creater,
  12209. Ctime: ctime,
  12210. Status: 1,
  12211. ReturnTime: advice.AdviceDate,
  12212. Dealer: info.Dealer,
  12213. Manufacturer: info.Manufacturer,
  12214. Type: 1,
  12215. }
  12216. service.AddSigleDrugCancelStock(&cancelStock)
  12217. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12218. dealer, _ := service.GetDealerById(info.Dealer)
  12219. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12220. cancelStockInfo := models.DrugCancelStockInfo{
  12221. OrderNumber: cancelInfo.OrderNumber,
  12222. CancelStockId: cancelInfo.ID,
  12223. DrugId: info.DrugId,
  12224. Count: info.Count,
  12225. Status: 1,
  12226. Ctime: ctime,
  12227. OrgId: advice.UserOrgId,
  12228. Type: 1,
  12229. Manufacturer: manufactureName.ManufacturerName,
  12230. Dealer: dealer.DealerName,
  12231. Total: 0,
  12232. RetailPrice: info.RetailPrice,
  12233. RetailTotalPrice: info.RetailTotalPrice,
  12234. Price: info.Price,
  12235. RegisterAccount: "",
  12236. Remark: info.Remark,
  12237. BatchNumber: info.BatchNumber,
  12238. MaxUnit: info.CountUnit,
  12239. ProductDate: info.ProductDate,
  12240. ExpiryDate: info.ExpiryDate,
  12241. BatchNumberId: info.WarehouseInfoId,
  12242. }
  12243. flow := models.DrugFlow{
  12244. WarehousingId: 0,
  12245. DrugId: info.DrugId,
  12246. Number: "",
  12247. BatchNumber: info.BatchNumber,
  12248. Count: info.Count,
  12249. UserOrgId: advice.UserOrgId,
  12250. PatientId: 0,
  12251. SystemTime: ctime,
  12252. ConsumableType: 4,
  12253. IsSys: 0,
  12254. WarehousingOrder: "",
  12255. WarehouseOutId: 0,
  12256. WarehouseOutOrderNumber: "",
  12257. IsEdit: 0,
  12258. CancelStockId: cancelStock.ID,
  12259. CancelOrderNumber: cancelStock.OrderNumber,
  12260. Manufacturer: info.Manufacturer,
  12261. Dealer: info.Dealer,
  12262. Creator: advice.UserOrgId,
  12263. UpdateCreator: 0,
  12264. Status: 1,
  12265. Ctime: time.Now().Unix(),
  12266. Mtime: 0,
  12267. Price: info.Price,
  12268. WarehousingDetailId: 0,
  12269. WarehouseOutDetailId: 0,
  12270. CancelOutDetailId: 0,
  12271. ExpireDate: info.ExpiryDate,
  12272. ProductDate: info.ProductDate,
  12273. MaxUnit: info.CountUnit,
  12274. MinUnit: "",
  12275. }
  12276. service.CreatedCancelStock(cancelStockInfo)
  12277. service.CreateDrugFlowOne(flow)
  12278. } else {
  12279. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12280. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12281. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12282. warehouseInfo := models.DrugWarehouseInfo{
  12283. StockMinNumber: prescribingNumber,
  12284. }
  12285. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12286. }
  12287. operation_time := time.Now().Unix()
  12288. creater := advice.AdviceDoctor
  12289. ctime := time.Now().Unix()
  12290. timeStr := time.Now().Format("2006-01-02")
  12291. timeArr := strings.Split(timeStr, "-")
  12292. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12293. total = total + 1
  12294. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12295. cancelStock := models.DrugCancelStock{
  12296. OrderNumber: orderNumber,
  12297. OperaTime: operation_time,
  12298. OrgId: advice.UserOrgId,
  12299. Creater: creater,
  12300. Ctime: ctime,
  12301. Status: 1,
  12302. ReturnTime: advice.AdviceDate,
  12303. Dealer: info.Dealer,
  12304. Manufacturer: info.Manufacturer,
  12305. Type: 1,
  12306. }
  12307. service.AddSigleDrugCancelStock(&cancelStock)
  12308. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12309. dealer, _ := service.GetDealerById(info.Dealer)
  12310. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12311. cancelStockInfo := models.DrugCancelStockInfo{
  12312. OrderNumber: cancelInfo.OrderNumber,
  12313. CancelStockId: cancelInfo.ID,
  12314. DrugId: info.DrugId,
  12315. Count: info.Count,
  12316. Status: 1,
  12317. Ctime: ctime,
  12318. OrgId: advice.UserOrgId,
  12319. Type: 1,
  12320. Manufacturer: manufactureName.ManufacturerName,
  12321. Dealer: dealer.DealerName,
  12322. Total: 0,
  12323. RetailPrice: info.RetailPrice,
  12324. RetailTotalPrice: info.RetailTotalPrice,
  12325. Price: info.Price,
  12326. RegisterAccount: "",
  12327. Remark: info.Remark,
  12328. BatchNumber: info.BatchNumber,
  12329. MaxUnit: info.CountUnit,
  12330. ProductDate: info.ProductDate,
  12331. ExpiryDate: info.ExpiryDate,
  12332. BatchNumberId: info.WarehouseInfoId,
  12333. }
  12334. flow := models.DrugFlow{
  12335. WarehousingId: 0,
  12336. DrugId: info.DrugId,
  12337. Number: "",
  12338. BatchNumber: info.BatchNumber,
  12339. Count: info.Count,
  12340. UserOrgId: advice.UserOrgId,
  12341. PatientId: 0,
  12342. SystemTime: ctime,
  12343. ConsumableType: 4,
  12344. IsSys: 0,
  12345. WarehousingOrder: "",
  12346. WarehouseOutId: 0,
  12347. WarehouseOutOrderNumber: "",
  12348. IsEdit: 0,
  12349. CancelStockId: cancelStock.ID,
  12350. CancelOrderNumber: cancelStock.OrderNumber,
  12351. Manufacturer: info.Manufacturer,
  12352. Dealer: info.Dealer,
  12353. Creator: advice.AdviceDoctor,
  12354. UpdateCreator: 0,
  12355. Status: 1,
  12356. Ctime: time.Now().Unix(),
  12357. Mtime: 0,
  12358. Price: info.Price,
  12359. WarehousingDetailId: 0,
  12360. WarehouseOutDetailId: 0,
  12361. CancelOutDetailId: 0,
  12362. ExpireDate: info.ExpiryDate,
  12363. ProductDate: info.ProductDate,
  12364. MaxUnit: info.CountUnit,
  12365. MinUnit: "",
  12366. }
  12367. service.CreatedCancelStock(cancelStockInfo)
  12368. service.CreateDrugFlowOne(flow)
  12369. }
  12370. }
  12371. }
  12372. return err
  12373. }
  12374. func (this *HisApiController) DeleteNCDS() {
  12375. id, _ := this.GetInt64("id", 0)
  12376. if id > 0 {
  12377. service.DeletePsnNCDSRecordById(id)
  12378. this.ServeSuccessJSON(map[string]interface{}{
  12379. "msg": "删除成功",
  12380. })
  12381. } else {
  12382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12383. return
  12384. }
  12385. }
  12386. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12387. id, _ := c.GetInt64("id")
  12388. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12389. c.ServeSuccessJSON(map[string]interface{}{
  12390. "advice": advice,
  12391. })
  12392. return
  12393. }
  12394. func (c *HisApiController) GetHisMonthChargePatientList() {
  12395. record_date := c.GetString("record_date")
  12396. start_time := c.GetString("start_time")
  12397. end_time := c.GetString("end_time")
  12398. timeLayout := "2006-01-02"
  12399. loc, _ := time.LoadLocation("Local")
  12400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12401. if err != nil {
  12402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12403. return
  12404. }
  12405. if err != nil {
  12406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12407. return
  12408. }
  12409. recordDateTime := theTime.Unix()
  12410. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12411. if err != nil {
  12412. }
  12413. startRecordDateTime := startTime.Unix()
  12414. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12415. if err != nil {
  12416. }
  12417. endRecordDateTime := endTime.Unix()
  12418. adminInfo := c.GetAdminUserInfo()
  12419. var tempMonthChargePatients []*service.MonthChargePatients
  12420. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12421. for _, item := range tempPatients {
  12422. //过滤没有处方的
  12423. if len(item.HisPrescription) == 0 {
  12424. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12425. }
  12426. }
  12427. c.ServeSuccessJSON(map[string]interface{}{
  12428. "list": tempMonthChargePatients,
  12429. })
  12430. }
  12431. // PrescriptionDifference 医嘱数量差值结构体
  12432. type PrescriptionDrugDifference struct {
  12433. DrugID int64 //基础库药品id
  12434. ID int64 //医嘱id
  12435. Difference float64 //差值
  12436. Unit string //单位
  12437. }
  12438. type PrescriptionGoodDifference struct {
  12439. GoodID int64 //基础库项目耗材id
  12440. ID int64 //医嘱id
  12441. Difference int64 //差值
  12442. Unit string //单位
  12443. Type int64 //类型
  12444. }
  12445. type EditCustomData struct {
  12446. adviceList []*models.HisDoctorAdviceInfo
  12447. projectList []*models.HisPrescriptionProject
  12448. }
  12449. type SrcCustomData struct {
  12450. adviceList []*models.HisDoctorAdviceInfo
  12451. projectList []*models.HisPrescriptionProject
  12452. }
  12453. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12454. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12455. differences := make([]*PrescriptionDrugDifference, 0)
  12456. // 创建一个 map 来存储第一个切片中的药品信息
  12457. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12458. for _, advice := range firstPrescription {
  12459. firstMap[advice.DrugId] = advice
  12460. }
  12461. // 遍历第二个切片中的药品信息,并比较数量差值
  12462. for _, advice := range secondPrescription {
  12463. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12464. diff := &PrescriptionDrugDifference{
  12465. DrugID: advice.DrugId,
  12466. ID: firstAdvice.ID,
  12467. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12468. Unit: firstAdvice.PrescribingNumberUnit,
  12469. }
  12470. differences = append(differences, diff)
  12471. }
  12472. }
  12473. return differences
  12474. }
  12475. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12476. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12477. differences := make([]*PrescriptionGoodDifference, 0)
  12478. // 创建一个 map 来存储第一个切片中的耗材信息
  12479. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12480. for _, good := range firstPrescription {
  12481. firstMap[good.ProjectId] = good
  12482. }
  12483. // 遍历第二个切片中的耗材信息,并比较数量差值
  12484. for _, good := range secondPrescription {
  12485. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12486. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12487. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12488. diff := &PrescriptionGoodDifference{
  12489. GoodID: good.ProjectId,
  12490. ID: firstGood.ID,
  12491. Difference: count - firstCount,
  12492. Unit: firstGood.Unit,
  12493. Type: firstGood.Type,
  12494. }
  12495. differences = append(differences, diff)
  12496. }
  12497. }
  12498. return differences
  12499. }
  12500. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12501. var adviceList []*models.HisDoctorAdviceInfo
  12502. var projectList []*models.HisPrescriptionProject
  12503. var advice_ids []int64
  12504. var project_ids []int64
  12505. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12506. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12507. //var tempPrescription *models.HisPrescriptionProjectscription
  12508. if len(prescriptions) > 0 {
  12509. for _, item := range prescriptions {
  12510. items := item.(map[string]interface{})
  12511. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12512. advices := items["advices"].([]interface{})
  12513. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12514. groupNo := int64(0)
  12515. ctime := time.Now().Unix()
  12516. mtime := ctime
  12517. if len(advices) > 0 {
  12518. for _, advice := range advices {
  12519. var s models.HisDoctorAdviceInfo
  12520. s.AdviceType = 2
  12521. s.StopState = 2
  12522. s.ExecutionState = 2
  12523. s.Status = 1
  12524. s.Groupno = groupNo
  12525. s.CreatedTime = ctime
  12526. s.UpdatedTime = mtime
  12527. s.IsSettle = 2
  12528. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12529. //存储切片中
  12530. if s.ID > 0 {
  12531. advice_ids = append(advice_ids, s.ID)
  12532. adviceList = append(adviceList, &s)
  12533. }
  12534. }
  12535. }
  12536. }
  12537. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12538. projects := items["project"].([]interface{})
  12539. if len(projects) > 0 {
  12540. for _, project := range projects {
  12541. var p models.HisPrescriptionProject
  12542. p.Ctime = time.Now().Unix()
  12543. p.Mtime = time.Now().Unix()
  12544. p.Status = 1
  12545. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12546. if p.ID > 0 {
  12547. project_ids = append(project_ids, p.ID)
  12548. projectList = append(projectList, &p)
  12549. }
  12550. }
  12551. }
  12552. }
  12553. }
  12554. }
  12555. }
  12556. editCustomData.projectList = projectList
  12557. editCustomData.adviceList = adviceList
  12558. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12559. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12560. srcCustomData.adviceList = list
  12561. srcCustomData.projectList = list2
  12562. return
  12563. }