his_api_controller.go 506KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025
  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/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. if number >= 1000 {
  188. zero = "0000" + strconv.FormatInt(number, 10)
  189. } else if number >= 10000 {
  190. zero = "000" + strconv.FormatInt(number, 10)
  191. } else if number >= 100000 {
  192. zero = "00" + strconv.FormatInt(number, 10)
  193. } else if number >= 1000000 {
  194. zero = "0" + strconv.FormatInt(number, 10)
  195. } else {
  196. zero = strconv.FormatInt(number, 10)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. for _, item := range orderInfos {
  1023. if item.MedChrgitmType == "01" { //床位费
  1024. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1025. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1026. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1027. }
  1028. if item.MedChrgitmType == "02" { //诊察费
  1029. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1030. //zhenChaCostSelfTotal = zhenChaCostTotal
  1031. }
  1032. if item.MedChrgitmType == "03" { //检查费
  1033. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1034. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1035. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1036. }
  1037. if item.MedChrgitmType == "02" { //检查费
  1038. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1039. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1040. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1041. }
  1042. if item.MedChrgitmType == "04" { //化验费
  1043. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1044. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1045. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1046. }
  1047. if item.MedChrgitmType == "05" { //治疗费
  1048. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1049. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1050. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1051. }
  1052. if item.MedChrgitmType == "06" { //手术费
  1053. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1054. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1055. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1056. }
  1057. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1058. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1059. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1060. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1061. }
  1062. if item.MedChrgitmType == "09" { //西药费
  1063. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1064. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1065. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1066. }
  1067. if item.MedChrgitmType == "11" { //中成费
  1068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1069. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1070. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. }
  1077. }
  1078. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1079. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1080. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1081. var dia_config []*models.HisXtDiagnoseConfig
  1082. var diagnosis_ids []string
  1083. if his.ID > 0 {
  1084. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1085. } else {
  1086. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1087. }
  1088. for _, item := range diagnosis_ids {
  1089. id, _ := strconv.ParseInt(item, 10, 64)
  1090. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1091. dia_config = append(dia_config, diagnosisConfig)
  1092. }
  1093. var rf []CustomFundPay
  1094. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1095. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "patient": patient,
  1098. "order_infos": orderInfos,
  1099. "diagnosis": name,
  1100. "bedCostTotal": bedCostTotal,
  1101. "bedCostSelfTotal": bedCostTotal,
  1102. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1103. "operationCostTotal": operationCostTotal,
  1104. "operationCostSelfTotal": operationCostTotal,
  1105. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1106. "otherCostTotal": otherCostTotal,
  1107. "otherCostSelfTotal": otherCostTotal,
  1108. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1109. "materialCostTotal": materialCostTotal,
  1110. "materialCostSelfTotal": materialCostTotal,
  1111. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1112. "westernMedicineCostTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1115. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1118. "checkCostTotal": checkCostTotal,
  1119. "checkCostSelfTotal": checkCostTotal,
  1120. "zhenChaCostTotal": zhenChaCostTotal,
  1121. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1122. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1123. "laboratoryCostTotal": laboratoryCostTotal,
  1124. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1125. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1126. "treatCostTotal": treatCostTotal,
  1127. "treatCostSelfTotal": treatCostTotal,
  1128. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1129. "charge_admin": charge_admin,
  1130. "printor_admin": printor_admin,
  1131. "org_name": org.OrgName,
  1132. "org_code": miConfig.Code,
  1133. "name": patient.Name,
  1134. "number": order.MdtrtId,
  1135. "date": order.SettleAccountsDate,
  1136. "info": order,
  1137. "new_order": order,
  1138. "his_hospital": his_hospital,
  1139. "his": his,
  1140. "funds": rf,
  1141. "dia_config": dia_config,
  1142. })
  1143. }
  1144. func (c *HisApiController) RefudDetail() {
  1145. order_id, _ := c.GetInt64("order_id")
  1146. order, _ := service.GetHisOrderByID(order_id)
  1147. adminUser := c.GetAdminUserInfo()
  1148. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "msg": "撤销成功",
  1151. })
  1152. }
  1153. func (c *HisApiController) Sscard() {
  1154. //r := CardInit()
  1155. //if r == 0 {
  1156. // GetBaseInfo()
  1157. //}
  1158. //c.ServeSuccessJSON(map[string]interface{}{
  1159. // "list": "11",
  1160. //})
  1161. }
  1162. func GetBaseInfo() error {
  1163. //handle := syscall.MustLoadDLL("SSCard.dll")
  1164. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1165. //
  1166. //str := make([]byte, 256)
  1167. //str1 := make([]byte, 256)
  1168. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1169. //if ferr != nil {
  1170. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1171. // return ferr
  1172. //}
  1173. //
  1174. //fmt.Println(string(str))
  1175. //
  1176. //fmt.Println(r)
  1177. return nil
  1178. }
  1179. func CardInit() int {
  1180. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1181. //add := DllTestDef.MustFindProc("Init")
  1182. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1183. //if err != nil {
  1184. // fmt.Println("SSCard的运算结果为:", ret)
  1185. //}
  1186. //result := int(ret)
  1187. return 0
  1188. }
  1189. func IntPtr(n int) uintptr {
  1190. return uintptr(n)
  1191. }
  1192. func StrPtr(s string) uintptr {
  1193. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1194. }
  1195. func (c *HisApiController) GetHisPatientList() {
  1196. //types, _ := c.GetInt64("type", 0)
  1197. record_date := c.GetString("record_date")
  1198. sch_type, _ := c.GetInt64("sch_type")
  1199. timeLayout := "2006-01-02"
  1200. loc, _ := time.LoadLocation("Local")
  1201. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1202. if err != nil {
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. recordDateTime := theTime.Unix()
  1207. adminInfo := c.GetAdminUserInfo()
  1208. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1209. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1210. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1211. //获取当前用户的信息
  1212. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1213. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1214. //获取所有科室信息
  1215. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1216. c.ServeSuccessJSON(map[string]interface{}{
  1217. "list": patients,
  1218. "list_two": patients_two,
  1219. "info": adminUserInfo,
  1220. "doctors": doctors,
  1221. "department": department,
  1222. })
  1223. }
  1224. type CustomTemplate struct {
  1225. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1226. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1227. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1228. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1229. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1230. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1231. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1232. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1233. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1234. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1235. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1236. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1237. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1238. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1239. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1240. }
  1241. func (c *HisApiController) GetHisPatientInfo() {
  1242. patient_id, _ := c.GetInt64("patient_id")
  1243. his_patient_id, _ := c.GetInt64("his_patient_id")
  1244. record_date := c.GetString("record_date")
  1245. number := c.GetString("number")
  1246. //start_time := c.GetString("start_time")
  1247. //end_time := c.GetString("end_time")
  1248. p_type, _ := c.GetInt64("p_type")
  1249. timeLayout := "2006-01-02"
  1250. loc, _ := time.LoadLocation("Local")
  1251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1252. if err != nil {
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. recordDateTime := theTime.Unix()
  1257. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1258. //if err != nil {
  1259. //
  1260. //}
  1261. //startRecordDateTime := startTime.Unix()
  1262. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1263. //if err != nil {
  1264. //
  1265. //}
  1266. //endRecordDateTime := endTime.Unix()
  1267. admin := c.GetAdminUserInfo()
  1268. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1270. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1271. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1272. var prescriptions []*models.HisPrescription
  1273. var last_prescriptions []*models.HisPrescription
  1274. var sch_prescriptions []CustomTemplate
  1275. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1276. if p_type == 1 { //住院
  1277. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1278. for _, item := range prescriptions {
  1279. for _, subItem := range item.HisDoctorAdviceInfo {
  1280. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1281. if info.RetailPrice > 0 {
  1282. subItem.Drug.MinPrice = info.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1287. } else { //门诊
  1288. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1289. for _, item := range prescriptions {
  1290. for _, subItem := range item.HisDoctorAdviceInfo {
  1291. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1292. if info.RetailPrice > 0 {
  1293. subItem.Drug.MinPrice = info.RetailPrice
  1294. }
  1295. }
  1296. }
  1297. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1298. }
  1299. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1300. if sch.ID > 0 {
  1301. var week string
  1302. t := time.Now()
  1303. switch t.Weekday().String() {
  1304. case "Monday":
  1305. week = "周一"
  1306. break
  1307. case "Tuesday":
  1308. week = "周二"
  1309. break
  1310. case "Wednesday":
  1311. week = "周三"
  1312. break
  1313. case "Thursday":
  1314. week = "周四"
  1315. break
  1316. case "Friday":
  1317. week = "周五"
  1318. break
  1319. case "Saturday":
  1320. week = "周六"
  1321. break
  1322. case "Sunday":
  1323. week = "周日"
  1324. break
  1325. }
  1326. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1327. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1328. //根据推送频率组装新的数组
  1329. for _, item := range temp_sch_prescriptions {
  1330. var cus CustomTemplate
  1331. cus.ID = item.ID
  1332. cus.UserOrgId = item.UserOrgId
  1333. cus.PatientId = item.PatientId
  1334. cus.MedType = item.MedType
  1335. cus.RecordDate = item.RecordDate
  1336. cus.Type = item.Type
  1337. cus.PType = item.PType
  1338. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1339. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1340. if subItem.FrequencyType == 1 { //每次必推
  1341. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1342. }
  1343. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1344. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1345. }
  1346. if subItem.FrequencyType == 2 { //按照天数频率
  1347. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1348. now := p.Unix()
  1349. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1350. dayStr2 := "-" + dayStr
  1351. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1352. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1353. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1354. if len(advices) == 0 {
  1355. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1361. if subItem.Type == 2 {
  1362. if subItem.XtHisProject.MedicalStatus != 1 {
  1363. if subItem.FrequencyType == 1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1367. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1368. }
  1369. if subItem.FrequencyType == 2 {
  1370. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1371. now := p.Unix()
  1372. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1373. dayStr2 := "-" + dayStr
  1374. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1375. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1376. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1377. if len(projects) == 0 {
  1378. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1379. }
  1380. }
  1381. }
  1382. } else if subItem.Type == 3 {
  1383. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1384. if subItem.FrequencyType == 1 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1388. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1389. }
  1390. if subItem.FrequencyType == 2 {
  1391. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1392. now := p.Unix()
  1393. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1394. dayStr2 := "-" + dayStr
  1395. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1396. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1397. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1398. if len(projects) == 0 {
  1399. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. sch_prescriptions = append(sch_prescriptions, cus)
  1406. }
  1407. for _, item := range sch_prescriptions {
  1408. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1409. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1410. }
  1411. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1412. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1413. }
  1414. }
  1415. }
  1416. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1417. if config.ID > 0 && config.IsOpen == 1 {
  1418. for _, item := range sch_prescriptions {
  1419. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1424. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1425. fmt.Println("haaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
  1426. }
  1427. }
  1428. }
  1429. }
  1430. if config.ID > 0 && config.IsOpen == 1 {
  1431. for _, item := range sch_prescriptions {
  1432. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1433. if subItem.Type == 3 {
  1434. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1435. if info.Price > 0 {
  1436. subItem.GoodInfo.PackingPrice = info.Price
  1437. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1438. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1439. fmt.Println("baaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1446. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1447. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1448. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1449. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1450. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1451. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1452. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1453. //获取所有科室信息
  1454. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "his_info": his_patient_info,
  1457. "xt_info": xt_patient_info,
  1458. "prescription": prescriptions,
  1459. "case_history": case_history,
  1460. "info": patientPrescriptionInfo,
  1461. //"month_prescriptions": monthPrescriptions,
  1462. "order": order,
  1463. "doctors": doctors,
  1464. "department": department,
  1465. "sch_prescriptions": sch_prescriptions,
  1466. "last_prescriptions": last_prescriptions,
  1467. "schedule": sch,
  1468. "count": count,
  1469. "drugStockConfig": drugStockConfig,
  1470. "last_info": lastPatientPrescriptionInfo,
  1471. })
  1472. return
  1473. }
  1474. func (c *HisApiController) GetHisPrescriptionConfig() {
  1475. adminInfo := c.GetAdminUserInfo()
  1476. //获取医嘱模版
  1477. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1478. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1479. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1480. //获取所有基础药
  1481. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1482. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1483. if config.ID > 0 && config.IsOpen == 1 {
  1484. for _, item := range drugs {
  1485. var index = 0
  1486. for _, subItem := range item.OtherDrugWarehouseInfo {
  1487. if index == 0 {
  1488. index = index + 1
  1489. if subItem.RetailPrice > 0 {
  1490. item.MinPrice = subItem.RetailPrice
  1491. }
  1492. }
  1493. }
  1494. }
  1495. }
  1496. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1497. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1498. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1499. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1500. //获取所有科室信息
  1501. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1502. //获取诊断信息
  1503. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1504. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1505. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1506. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1507. //获取是否开启保存耗材出库的开关
  1508. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1509. c.ServeSuccessJSON(map[string]interface{}{
  1510. "drugs": drugs,
  1511. "advices_template": advices,
  1512. "drugways": drugways,
  1513. "efs": efs,
  1514. "doctors": doctors,
  1515. "department": department,
  1516. "sick": sick,
  1517. "additions": additions,
  1518. "diagnose": diagnose,
  1519. "manufacturers": manufacturers,
  1520. "goodOutOpen": goodOutOpen,
  1521. "patientDiagnose": patientDiagnose,
  1522. })
  1523. }
  1524. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1525. //获取所有基础药
  1526. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1527. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1528. if config.ID > 0 && config.IsOpen == 1 {
  1529. for _, item := range drugs {
  1530. var index = 0
  1531. for _, subItem := range item.OtherDrugWarehouseInfo {
  1532. if index == 0 {
  1533. index = index + 1
  1534. if subItem.RetailPrice > 0 {
  1535. item.MinPrice = subItem.RetailPrice
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1542. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1543. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1544. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1545. //获取所有科室信息
  1546. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1547. //获取诊断信息
  1548. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1549. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1550. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1551. //获取是否开启保存耗材出库的开关
  1552. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1553. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1554. c.ServeSuccessJSON(map[string]interface{}{
  1555. "drugs": drugs,
  1556. "advices_template": advices,
  1557. "drugways": drugways,
  1558. "efs": efs,
  1559. "doctors": doctors,
  1560. "department": department,
  1561. "sick": sick,
  1562. "additions": additions,
  1563. "diagnose": diagnose,
  1564. "manufacturers": manufacturers,
  1565. "goodOutOpen": goodOutOpen,
  1566. "patientDiagnose": patientDiagnose,
  1567. })
  1568. }
  1569. }
  1570. func (c *HisApiController) CreateHisPrescription() {
  1571. record_date := c.GetString("record_date")
  1572. patient_id, _ := c.GetInt64("patient_id")
  1573. reg_type, _ := c.GetInt64("reg_type")
  1574. diagnose := c.GetString("diagnose")
  1575. sick_type, _ := c.GetInt64("sick_type")
  1576. sick_history := c.GetString("sick_history")
  1577. doctor_id, _ := c.GetInt64("doctor", 0)
  1578. department, _ := c.GetInt64("department", 0)
  1579. his_patient_id, _ := c.GetInt64("his_patient_id")
  1580. p_type, _ := c.GetInt64("p_type")
  1581. patient_diagnose := c.GetString("patient_diagnose")
  1582. dataBody := make(map[string]interface{}, 0)
  1583. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1584. if err != nil {
  1585. utils.ErrorLog(err.Error())
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. //edit, src := GetCompareData(dataBody)
  1590. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1591. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1592. //fmt.Println(drugResult)
  1593. //fmt.Println(goodResult)
  1594. timeLayout := "2006-01-02"
  1595. loc, _ := time.LoadLocation("Local")
  1596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1597. if err != nil {
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. adminInfo := c.GetAdminUserInfo()
  1602. recordDateTime := theTime.Unix()
  1603. //查询默认出库仓库库存
  1604. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1605. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1606. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1607. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1608. if len(lists) == 1 {
  1609. his_patient_id = lists[0].ID
  1610. }
  1611. }
  1612. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1613. //保存处方出库
  1614. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1615. //自动出库
  1616. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1617. //耗材保存处方出库
  1618. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1619. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1620. //已发药和已收费限制逻辑
  1621. isMidicine := false
  1622. isCharge := false
  1623. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1624. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1625. if len(prescriptions) > 0 {
  1626. for _, item := range prescriptions {
  1627. items := item.(map[string]interface{})
  1628. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1629. utils.ErrorLog("id")
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1631. return
  1632. }
  1633. id := int64(items["id"].(float64))
  1634. if id > 0 {
  1635. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1636. if err != nil {
  1637. if new_prescription.OrderStatus == 4 {
  1638. isCharge = true
  1639. }
  1640. }
  1641. }
  1642. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1643. advices := items["advices"].([]interface{})
  1644. if len(advices) > 0 {
  1645. for _, advice := range advices {
  1646. var adviceId int64
  1647. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1648. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1649. }
  1650. if adviceId > 0 {
  1651. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1652. if err == nil {
  1653. if his_advice_info.IsMedicine == 1 {
  1654. isMidicine = true
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. if isMidicine == true {
  1665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1666. return
  1667. }
  1668. if isCharge == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1670. return
  1671. }
  1672. // 开始主事务
  1673. db := service.XTWriteDB()
  1674. tx := db.Begin()
  1675. // 在函数结束时处理事务回滚
  1676. defer func() {
  1677. if r := recover(); r != nil {
  1678. tx.Rollback()
  1679. }
  1680. }()
  1681. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1682. //药品发药出库
  1683. if pharmacyConfig.IsOpen == 1 {
  1684. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1685. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1686. if len(prescriptions) > 0 {
  1687. for _, item := range prescriptions {
  1688. items := item.(map[string]interface{})
  1689. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1690. advices := items["advices"].([]interface{})
  1691. if len(advices) > 0 {
  1692. for _, advice := range advices {
  1693. var drug_id int64
  1694. var prescribing_number float64
  1695. var prescribingNumberUnit string
  1696. var adviceId int64
  1697. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1698. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1699. }
  1700. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1701. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1702. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1705. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1706. }
  1707. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1708. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1709. }
  1710. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1711. if drug.ID == 0 {
  1712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1713. return
  1714. }
  1715. //查询药品的所有库存
  1716. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1717. var total_count int64
  1718. for _, it := range list {
  1719. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1720. }
  1721. totals := strconv.FormatInt(total_count, 10)
  1722. //查询该药品是否存在开药记录
  1723. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1724. //新增处方
  1725. if advicelist.ID == 0 {
  1726. all_count, _ := strconv.ParseFloat(totals, 64)
  1727. if prescribingNumberUnit == drug.MinUnit {
  1728. if drug.IsUse != 1 {
  1729. if drug.IsProject == 0 || drug.IsProject == 2 {
  1730. if all_count == 0 {
  1731. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1732. return
  1733. }
  1734. if prescribing_number > all_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. }
  1739. }
  1740. }
  1741. if prescribingNumberUnit == drug.MaxUnit {
  1742. num := prescribing_number * float64(drug.MinNumber)
  1743. if drug.IsUse != 1 {
  1744. if drug.IsProject == 0 || drug.IsProject == 2 {
  1745. if all_count == 0 {
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1747. return
  1748. }
  1749. if num > all_count {
  1750. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1751. return
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1758. if drugOutConfig.IsOpen != 1 {
  1759. //修改处方
  1760. for _, advice := range advices {
  1761. var drug_id int64
  1762. var prescribing_number float64
  1763. var prescribingNumberUnit string
  1764. var prescribingNumber string
  1765. var adviceId int64
  1766. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1767. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1770. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1771. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1772. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1773. }
  1774. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1775. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1776. }
  1777. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1778. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1779. }
  1780. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1781. if drug.ID == 0 {
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. //查询药品的所有库存
  1786. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1787. var total_count int64
  1788. for _, it := range list {
  1789. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1790. }
  1791. totals := strconv.FormatInt(total_count, 10)
  1792. //查询该药品是否存在开药记录
  1793. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1794. //新增处方
  1795. if advicelist.ID == 0 {
  1796. all_count, _ := strconv.ParseFloat(totals, 64)
  1797. if prescribingNumberUnit == drug.MinUnit {
  1798. if drug.IsUse != 1 {
  1799. if drug.IsProject == 0 || drug.IsProject == 2 {
  1800. if all_count == 0 {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1802. return
  1803. }
  1804. if prescribing_number > all_count {
  1805. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1806. return
  1807. }
  1808. }
  1809. }
  1810. } else {
  1811. if prescribingNumberUnit == drug.MaxUnit {
  1812. num := prescribing_number * float64(drug.MinNumber)
  1813. if drug.IsUse != 1 {
  1814. if drug.IsProject == 0 || drug.IsProject == 2 {
  1815. if all_count == 0 {
  1816. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1817. return
  1818. }
  1819. if num > all_count {
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. //修改处方
  1829. if advicelist.ID > 0 {
  1830. var device_number int64
  1831. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1832. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1833. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1834. device_number = prescribingNumberInt * drug.MinNumber
  1835. }
  1836. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt
  1840. }
  1841. var number_count int64
  1842. if prescribingNumberUnit == drug.MaxUnit {
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1844. number_count = prescribingNumberInt * drug.MinNumber
  1845. }
  1846. if prescribingNumberUnit == drug.MinUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt
  1849. }
  1850. //如果修改的数量大于之前修改的数量
  1851. if (number_count - device_number) > 0 {
  1852. //如果修改的差数量 大于库存数量
  1853. if drug.IsUse != 1 {
  1854. if (number_count - device_number) > total_count {
  1855. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1856. return
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. //已发药和已收费限制逻辑
  1871. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1872. //校验库存总量
  1873. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1874. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1875. if len(prescriptions) > 0 {
  1876. for _, item := range prescriptions {
  1877. items := item.(map[string]interface{})
  1878. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1879. advices := items["advices"].([]interface{})
  1880. if len(advices) > 0 {
  1881. for _, advice := range advices {
  1882. var drug_id int64
  1883. var prescribing_number float64
  1884. var prescribingNumberUnit string
  1885. var adviceId int64
  1886. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1887. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1888. }
  1889. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1890. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1891. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1892. }
  1893. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1894. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1895. }
  1896. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1897. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1898. }
  1899. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1900. if drug.ID == 0 {
  1901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1902. return
  1903. }
  1904. //查询药品的所有库存
  1905. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1906. var total_count int64
  1907. for _, it := range list {
  1908. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1909. }
  1910. totals := strconv.FormatInt(total_count, 10)
  1911. //查询该药品是否存在开药记录
  1912. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1913. //查询最新批次库存
  1914. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1915. var batch_number_count int64
  1916. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1917. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1918. //新增处方
  1919. if advicelist.ID == 0 {
  1920. all_count, _ := strconv.ParseFloat(totals, 64)
  1921. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1922. if prescribingNumberUnit == drug.MinUnit {
  1923. if drug.IsUse != 1 {
  1924. if drug.IsProject == 0 || drug.IsProject == 2 {
  1925. if all_count == 0 {
  1926. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1927. return
  1928. }
  1929. if prescribing_number > all_count {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1931. return
  1932. }
  1933. }
  1934. if adminInfo.CurrentOrgId == 10215 {
  1935. if prescribing_number > batch_number_all_count {
  1936. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1937. return
  1938. }
  1939. }
  1940. }
  1941. }
  1942. if prescribingNumberUnit == drug.MaxUnit {
  1943. num := prescribing_number * float64(drug.MinNumber)
  1944. if drug.IsUse != 1 {
  1945. if drug.IsProject == 0 || drug.IsProject == 2 {
  1946. if all_count == 0 {
  1947. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1948. return
  1949. }
  1950. if num > all_count {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1952. return
  1953. }
  1954. }
  1955. if adminInfo.CurrentOrgId == 10215 {
  1956. if num > batch_number_all_count {
  1957. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1958. return
  1959. }
  1960. }
  1961. }
  1962. }
  1963. }
  1964. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1965. if drugOutConfig.IsOpen != 1 {
  1966. //修改处方
  1967. for _, advice := range advices {
  1968. var drug_id int64
  1969. var prescribing_number float64
  1970. var prescribingNumberUnit string
  1971. var prescribingNumber string
  1972. var adviceId int64
  1973. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1974. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1975. }
  1976. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1977. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1978. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1979. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1980. }
  1981. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1982. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1983. }
  1984. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1985. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1986. }
  1987. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1988. if drug.ID == 0 {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1990. return
  1991. }
  1992. //查询药品的所有库存
  1993. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1994. var total_count int64
  1995. for _, it := range list {
  1996. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1997. }
  1998. totals := strconv.FormatInt(total_count, 10)
  1999. //查询该药品是否存在开药记录
  2000. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2001. //新增处方
  2002. if advicelist.ID == 0 {
  2003. //查询最新批次库存
  2004. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2005. var batch_number_count int64
  2006. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2007. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2008. all_count, _ := strconv.ParseFloat(totals, 64)
  2009. if prescribingNumberUnit == drug.MinUnit {
  2010. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2011. if drug.IsUse != 1 {
  2012. if drug.IsProject == 0 || drug.IsProject == 2 {
  2013. if all_count == 0 {
  2014. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2015. return
  2016. }
  2017. if prescribing_number > all_count {
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2019. return
  2020. }
  2021. }
  2022. if adminInfo.CurrentOrgId == 10215 {
  2023. if prescribing_number > batch_number_all_count {
  2024. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2025. return
  2026. }
  2027. }
  2028. }
  2029. } else {
  2030. if prescribingNumberUnit == drug.MaxUnit {
  2031. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2032. num := prescribing_number * float64(drug.MinNumber)
  2033. if drug.IsUse != 1 {
  2034. if drug.IsProject == 0 || drug.IsProject == 2 {
  2035. if all_count == 0 {
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. if num > all_count {
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. }
  2044. if adminInfo.CurrentOrgId == 10215 {
  2045. if prescribing_number > batch_number_all_count {
  2046. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2047. return
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. }
  2054. //修改处方
  2055. if advicelist.ID > 0 {
  2056. //查询最新批次库存
  2057. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2058. var batch_number_count int64
  2059. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2060. var device_number int64
  2061. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2062. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2064. device_number = prescribingNumberInt * drug.MinNumber
  2065. }
  2066. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2067. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2068. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2069. device_number = prescribingNumberInt
  2070. }
  2071. var number_count int64
  2072. if prescribingNumberUnit == drug.MaxUnit {
  2073. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2074. number_count = prescribingNumberInt * drug.MinNumber
  2075. }
  2076. if prescribingNumberUnit == drug.MinUnit {
  2077. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2078. number_count = prescribingNumberInt
  2079. }
  2080. //如果修改的数量大于之前修改的数量
  2081. if (number_count - device_number) > 0 {
  2082. //如果修改的差数量 大于库存数量
  2083. if drug.IsUse != 1 {
  2084. if drug.IsProject == 0 || drug.IsProject == 2 {
  2085. if total_count == 0 {
  2086. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2087. return
  2088. }
  2089. if (number_count - device_number) > total_count {
  2090. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2091. return
  2092. }
  2093. if (number_count - device_number) > batch_number_count {
  2094. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2095. return
  2096. }
  2097. }
  2098. if adminInfo.CurrentOrgId == 10215 {
  2099. // 查询该药品最后一次出库记录
  2100. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2101. var out_count int64
  2102. var in_count int64
  2103. var stock_max_number int64
  2104. var stock_min_number int64
  2105. for _, it := range outInfo {
  2106. if it.CountUnit == drug.MaxUnit {
  2107. it.Count = it.Count * drug.MinNumber
  2108. }
  2109. out_count += it.Count
  2110. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2111. stock_max_number = warehouseInfoList.StockMaxNumber
  2112. stock_min_number = warehouseInfoList.StockMinNumber
  2113. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2114. }
  2115. if out_count > 0 {
  2116. if (number_count - device_number) > in_count {
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2118. return
  2119. }
  2120. }
  2121. // 未出库
  2122. if out_count == 0 {
  2123. var sum_in_count int64
  2124. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2125. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2126. fmt.Println("sum_in_count", sum_in_count)
  2127. //如果修改的数量大于有库存的第一个批次
  2128. if number_count > sum_in_count {
  2129. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2130. return
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2137. if pharmacyConfig.IsOpen != 1 {
  2138. if device_number != number_count {
  2139. // 查询该药品最后一次出库记录
  2140. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2141. //回退库存
  2142. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2143. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2144. }
  2145. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2146. var stock_max_number int64
  2147. var stock_min_number int64
  2148. if number_count >= drug.MinNumber {
  2149. stock_max_number = device_number / drug.MinNumber
  2150. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2151. stock_min_number = device_number % drug.MinNumber
  2152. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2153. } else {
  2154. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2155. }
  2156. }
  2157. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2158. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2159. }
  2160. //删除记录
  2161. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2162. //查询默认仓库剩余多少库存
  2163. var sum_count int64
  2164. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2165. for _, its := range stockInfo {
  2166. if its.MaxUnit == drug.MaxUnit {
  2167. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2168. }
  2169. sum_count += its.StockMaxNumber + its.StockMinNumber
  2170. }
  2171. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2172. }
  2173. }
  2174. }
  2175. }
  2176. }
  2177. //保存处方开药
  2178. if drugOutConfig.IsOpen == 1 {
  2179. //修改处方
  2180. for _, advice := range advices {
  2181. var drug_id int64
  2182. var prescribing_number float64
  2183. var prescribingNumberUnit string
  2184. var prescribingNumber string
  2185. var adviceId int64
  2186. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2187. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2188. }
  2189. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2190. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2191. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2192. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2193. }
  2194. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2195. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2196. }
  2197. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2198. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2199. }
  2200. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2201. if drug.ID == 0 {
  2202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2203. return
  2204. }
  2205. //查询药品的所有库存
  2206. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2207. var total_count int64
  2208. for _, it := range list {
  2209. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2210. }
  2211. totals := strconv.FormatInt(total_count, 10)
  2212. //查询该药品是否存在开药记录
  2213. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2214. //新增处方
  2215. if advicelist.ID == 0 {
  2216. //查询最新批次库存
  2217. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2218. var batch_number_count int64
  2219. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2220. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2221. all_count, _ := strconv.ParseFloat(totals, 64)
  2222. if prescribingNumberUnit == drug.MinUnit {
  2223. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2224. if drug.IsUse != 1 {
  2225. if drug.IsProject == 0 || drug.IsProject == 2 {
  2226. if all_count == 0 {
  2227. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2228. return
  2229. }
  2230. if prescribing_number > all_count {
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. }
  2235. if adminInfo.CurrentOrgId == 10215 {
  2236. if prescribing_number > batch_number_all_count {
  2237. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2238. return
  2239. }
  2240. }
  2241. }
  2242. } else {
  2243. if prescribingNumberUnit == drug.MaxUnit {
  2244. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2245. num := prescribing_number * float64(drug.MinNumber)
  2246. if drug.IsUse != 1 {
  2247. if drug.IsProject == 0 || drug.IsProject == 2 {
  2248. if all_count == 0 {
  2249. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2250. return
  2251. }
  2252. if num > all_count {
  2253. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2254. return
  2255. }
  2256. }
  2257. if adminInfo.CurrentOrgId == 10215 {
  2258. if prescribing_number > batch_number_all_count {
  2259. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2260. return
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. }
  2267. //修改处方
  2268. if advicelist.ID > 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. var device_number int64
  2274. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2275. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2277. device_number = prescribingNumberInt * drug.MinNumber
  2278. }
  2279. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2282. device_number = prescribingNumberInt
  2283. }
  2284. var number_count int64
  2285. if prescribingNumberUnit == drug.MaxUnit {
  2286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2287. number_count = prescribingNumberInt * drug.MinNumber
  2288. }
  2289. if prescribingNumberUnit == drug.MinUnit {
  2290. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2291. number_count = prescribingNumberInt
  2292. }
  2293. //如果修改的数量大于之前修改的数量
  2294. if (number_count - device_number) > 0 {
  2295. //如果修改的差数量 大于库存数量
  2296. if drug.IsUse != 1 {
  2297. if drug.IsProject == 0 || drug.IsProject == 2 {
  2298. if total_count == 0 {
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2300. return
  2301. }
  2302. if (number_count - device_number) > total_count {
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2304. return
  2305. }
  2306. }
  2307. if adminInfo.CurrentOrgId == 10215 {
  2308. if (number_count - device_number) > batch_number_count {
  2309. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2310. return
  2311. }
  2312. }
  2313. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2314. //查询历史出库数据总批次
  2315. // 查询该药品最后一次出库记录
  2316. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2317. var out_count int64
  2318. var in_count int64
  2319. var stock_max_number int64
  2320. var stock_min_number int64
  2321. for _, it := range outInfo {
  2322. if it.CountUnit == drug.MaxUnit {
  2323. it.Count = it.Count * drug.MinNumber
  2324. }
  2325. out_count += it.Count
  2326. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2327. stock_max_number = warehouseInfoList.StockMaxNumber
  2328. stock_min_number = warehouseInfoList.StockMinNumber
  2329. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2330. }
  2331. if out_count > 0 {
  2332. if (number_count - device_number) > in_count {
  2333. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2334. return
  2335. }
  2336. }
  2337. // 未出库
  2338. if out_count == 0 {
  2339. var sum_in_count int64
  2340. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2341. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2342. if sum_in_count == 0 {
  2343. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2344. return
  2345. }
  2346. //如果修改的数量大于有库存的第一个批次
  2347. if number_count > sum_in_count {
  2348. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2349. return
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. //校验耗材库存
  2366. if goodOutConfig.IsOpen == 1 {
  2367. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2368. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2369. if len(prescriptions) > 0 {
  2370. for _, item := range prescriptions {
  2371. items := item.(map[string]interface{})
  2372. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2373. projects := items["project"].([]interface{})
  2374. if len(projects) > 0 {
  2375. for _, project := range projects {
  2376. var project_id int64
  2377. var project_type int64
  2378. var totals float64
  2379. var project_name string
  2380. var parsetotal int64
  2381. var id int64
  2382. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2383. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2384. }
  2385. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2386. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2387. }
  2388. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2389. total, _ := project.(map[string]interface{})["total"].(string)
  2390. totals, _ = strconv.ParseFloat(total, 64)
  2391. }
  2392. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2393. project_name = project.(map[string]interface{})["project_name"].(string)
  2394. }
  2395. if project_type == 3 {
  2396. //查找该耗材的出库记录
  2397. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2398. if len(goodWarehouseInfo) == 0 {
  2399. //查询耗材库存
  2400. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2401. var stock_count int64
  2402. for _, it := range list {
  2403. stock_count += it.StockCount
  2404. }
  2405. stock_counts := strconv.FormatInt(stock_count, 10)
  2406. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2407. if stock_total_count == 0 {
  2408. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2409. return
  2410. }
  2411. if totals > stock_total_count {
  2412. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2413. return
  2414. }
  2415. }
  2416. if len(goodWarehouseInfo) > 0 {
  2417. //查询该患者耗材的历史数据
  2418. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2419. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2420. //数量发生改变
  2421. if parsetotal != count {
  2422. //如果现在的数量大于历史数量,就要看库存是否足够
  2423. if parsetotal > count {
  2424. //查询耗材所有库存
  2425. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2426. var stock_count int64
  2427. for _, it := range list {
  2428. stock_count += it.StockCount
  2429. }
  2430. //库存不足
  2431. if stock_count == 0 {
  2432. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2433. return
  2434. }
  2435. if (parsetotal - count) > stock_count {
  2436. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2437. return
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. //不使用耗材保存处方出库
  2451. if goodOutConfig.IsOpen != 1 {
  2452. if stockConfig.IsOpen == 1 {
  2453. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2454. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2455. if len(prescriptions) > 0 {
  2456. for _, item := range prescriptions {
  2457. items := item.(map[string]interface{})
  2458. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2459. projects := items["project"].([]interface{})
  2460. if len(projects) > 0 {
  2461. for _, project := range projects {
  2462. var project_id int64
  2463. var project_type int64
  2464. var totals float64
  2465. var project_name string
  2466. var parsetotal int64
  2467. var id int64
  2468. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2469. id = int64(project.(map[string]interface{})["id"].(float64))
  2470. }
  2471. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2472. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2473. }
  2474. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2475. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2476. }
  2477. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2478. total, _ := project.(map[string]interface{})["total"].(string)
  2479. totals, _ = strconv.ParseFloat(total, 64)
  2480. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2481. }
  2482. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2483. project_name = project.(map[string]interface{})["project_name"].(string)
  2484. }
  2485. if project_type == 3 {
  2486. //查找该耗材的出库记录
  2487. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2488. //没有出库记录
  2489. if len(goodWarehouseInfo) == 0 {
  2490. //查询耗材库存
  2491. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2492. var stock_count int64
  2493. for _, it := range list {
  2494. stock_count += it.StockCount
  2495. }
  2496. stock_counts := strconv.FormatInt(stock_count, 10)
  2497. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2498. if stock_total_count == 0 {
  2499. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2500. return
  2501. }
  2502. if totals > stock_total_count {
  2503. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2504. return
  2505. }
  2506. //查找今日该患者已经出库的所有耗材
  2507. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2508. for _, item := range goodList {
  2509. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2510. var flush_count int64
  2511. for _, it := range goodListSix {
  2512. flush_count += it.StockCount
  2513. }
  2514. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2515. creater := adminInfo.AdminUser.Id
  2516. if errs != nil {
  2517. goodErrcode := models.XtGoodErrcode{
  2518. UserOrgId: item.OrgId,
  2519. Errcode: "手动出库更新剩余出库失败",
  2520. GoodId: item.GoodId,
  2521. Status: 1,
  2522. Ctime: time.Now().Unix(),
  2523. Mtime: 0,
  2524. Count: 0,
  2525. StockCount: 0,
  2526. Creater: creater,
  2527. BatchNumberId: 0,
  2528. WarehouseOutId: 0,
  2529. }
  2530. service.CreateGoodErrcode(goodErrcode)
  2531. }
  2532. }
  2533. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2534. }
  2535. //有出库记录
  2536. if len(goodWarehouseInfo) > 0 {
  2537. //查询该患者耗材的历史数据
  2538. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2539. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2540. //数量发生改变
  2541. if parsetotal != count {
  2542. //查找今日该患者已经出库的所有耗材
  2543. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2544. for _, item := range goodList {
  2545. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2546. var flush_count int64
  2547. for _, it := range goodListSix {
  2548. flush_count += it.StockCount
  2549. }
  2550. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2551. //减少出库数量
  2552. creater := adminInfo.AdminUser.Id
  2553. if errs != nil {
  2554. goodErrcode := models.XtGoodErrcode{
  2555. UserOrgId: item.OrgId,
  2556. Errcode: "手动出库更新剩余出库失败",
  2557. GoodId: item.GoodId,
  2558. Status: 1,
  2559. Ctime: time.Now().Unix(),
  2560. Mtime: 0,
  2561. Count: 0,
  2562. StockCount: 0,
  2563. Creater: creater,
  2564. BatchNumberId: 0,
  2565. WarehouseOutId: 0,
  2566. }
  2567. service.CreateGoodErrcode(goodErrcode)
  2568. }
  2569. //查询默认仓库
  2570. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2571. var total_count int64
  2572. for _, it := range stockList {
  2573. total_count += it.StockCount
  2574. }
  2575. //基础库插入数据
  2576. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2577. }
  2578. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. }
  2588. }
  2589. }
  2590. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2591. var hpInfo models.HisPrescriptionInfo
  2592. if info.ID == 0 {
  2593. var randNum int
  2594. randNum = rand.Intn(10000) + 1000
  2595. timestamp := time.Now().Unix()
  2596. tempTime := time.Unix(timestamp, 0)
  2597. timeFormat := tempTime.Format("20060102150405")
  2598. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2599. hpInfo = models.HisPrescriptionInfo{
  2600. HisPatientId: his_patient_id,
  2601. UserOrgId: adminInfo.CurrentOrgId,
  2602. RecordDate: theTime.Unix(),
  2603. PatientId: patient_id,
  2604. Status: 1,
  2605. Ctime: time.Now().Unix(),
  2606. Mtime: time.Now().Unix(),
  2607. Creator: adminInfo.AdminUser.Id,
  2608. Modifier: adminInfo.AdminUser.Id,
  2609. Diagnosis: diagnose,
  2610. SickHistory: sick_history,
  2611. Departments: department,
  2612. RegisterType: reg_type,
  2613. PrescriptionNumber: p_number,
  2614. PrescriptionStatus: 1,
  2615. Doctor: role.UserName,
  2616. DoctorId: doctor_id,
  2617. SickType: sick_type,
  2618. PType: p_type,
  2619. PatientDiagnosis: patient_diagnose,
  2620. }
  2621. service.SavePatientPrescriptionInfo(hpInfo)
  2622. //创建步骤表
  2623. finish := models.XtDialysisFinish{
  2624. IsFinish: 1,
  2625. UserOrgId: adminInfo.CurrentOrgId,
  2626. Status: 1,
  2627. Ctime: time.Now().Unix(),
  2628. Mtime: 0,
  2629. Module: 4,
  2630. RecordDate: theTime.Unix(),
  2631. Sourse: 1,
  2632. PatientId: patient_id,
  2633. }
  2634. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2635. if dialysisFinish.ID == 0 {
  2636. service.CreateDialysisFinish(finish)
  2637. }
  2638. redis := service.RedisClient()
  2639. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2640. redis.Set(key, "", time.Second)
  2641. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2642. redis.Set(keyOne, "", time.Second)
  2643. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2644. redis.Set(keySeven, "", time.Second)
  2645. defer redis.Close()
  2646. } else {
  2647. hpInfo = models.HisPrescriptionInfo{
  2648. ID: info.ID,
  2649. UserOrgId: adminInfo.CurrentOrgId,
  2650. RecordDate: info.RecordDate,
  2651. PatientId: info.PatientId,
  2652. Status: 1,
  2653. Ctime: info.Ctime,
  2654. Mtime: time.Now().Unix(),
  2655. Creator: info.Creator,
  2656. Modifier: adminInfo.AdminUser.Id,
  2657. Diagnosis: diagnose,
  2658. SickHistory: sick_history,
  2659. Departments: department,
  2660. RegisterType: reg_type,
  2661. PrescriptionNumber: info.PrescriptionNumber,
  2662. Doctor: role.UserName,
  2663. PrescriptionStatus: info.PrescriptionStatus,
  2664. DoctorId: doctor_id,
  2665. SickType: sick_type,
  2666. PType: info.PType,
  2667. HisPatientId: info.HisPatientId,
  2668. PatientDiagnosis: patient_diagnose,
  2669. }
  2670. service.SavePatientPrescriptionInfo(hpInfo)
  2671. //创建步骤表
  2672. finish := models.XtDialysisFinish{
  2673. IsFinish: 1,
  2674. UserOrgId: adminInfo.CurrentOrgId,
  2675. Status: 1,
  2676. Ctime: time.Now().Unix(),
  2677. Mtime: 0,
  2678. Module: 4,
  2679. RecordDate: info.RecordDate,
  2680. Sourse: 1,
  2681. PatientId: info.PatientId,
  2682. }
  2683. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2684. if dialysisFinish.ID == 0 {
  2685. service.CreateDialysisFinish(finish)
  2686. }
  2687. redis := service.RedisClient()
  2688. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2689. redis.Set(key, "", time.Second)
  2690. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2691. redis.Set(keyOne, "", time.Second)
  2692. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2693. redis.Set(keySeven, "", time.Second)
  2694. defer redis.Close()
  2695. }
  2696. //定义切片
  2697. var adviceList []models.HisDoctorAdviceInfo
  2698. var projectList []models.HisPrescriptionProject
  2699. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 {
  2700. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2701. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2702. var tempPrescription *models.HisPrescription
  2703. if len(prescriptions) > 0 {
  2704. for _, item := range prescriptions {
  2705. // 开始外部循环的事务
  2706. tx := db.Begin()
  2707. // 在函数结束时处理事务回滚
  2708. defer func() {
  2709. if r := recover(); r != nil {
  2710. tx.Rollback()
  2711. }
  2712. }()
  2713. items := item.(map[string]interface{})
  2714. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2715. utils.ErrorLog("id")
  2716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2717. return
  2718. }
  2719. id := int64(items["id"].(float64))
  2720. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2721. tempPrescription = &new_prescription
  2722. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2723. utils.ErrorLog("type")
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. return
  2726. }
  2727. types := int64(items["type"].(float64))
  2728. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2729. utils.ErrorLog("med_type")
  2730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2731. return
  2732. }
  2733. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2734. if med_type == "0" {
  2735. med_type = "14"
  2736. }
  2737. //if order_status == 0 {
  2738. // order_status = 1
  2739. //}
  2740. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2741. utils.ErrorLog("pre_time")
  2742. }
  2743. preTime, _ := items["pre_time"].(string)
  2744. fmt.Println("preTime", preTime)
  2745. timeLayout := "2006-01-02"
  2746. loc, _ := time.LoadLocation("Local")
  2747. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2748. result := strings.Split(preTime, " ")
  2749. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2750. if err != nil {
  2751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2752. return
  2753. }
  2754. pTime := theTime2.Unix()
  2755. ctime := time.Now().Unix()
  2756. if tempPrescription.ID == 0 {
  2757. prescription := &models.HisPrescription{
  2758. ID: 0,
  2759. PatientId: patient_id,
  2760. UserOrgId: adminInfo.CurrentOrgId,
  2761. RecordDate: recordDateTime,
  2762. Ctime: ctime,
  2763. Mtime: ctime,
  2764. Type: types,
  2765. Modifier: adminInfo.AdminUser.Id,
  2766. Creator: adminInfo.AdminUser.Id,
  2767. Status: 1,
  2768. Doctor: role.UserName,
  2769. HisPatientId: his_patient_id,
  2770. OrderStatus: 1,
  2771. BatchNumber: "",
  2772. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2773. PreTime: pTime,
  2774. PType: p_type,
  2775. MedType: med_type,
  2776. }
  2777. tempPrescription = prescription
  2778. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2779. redis := service.RedisClient()
  2780. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2781. redis.Set(key, "", time.Second)
  2782. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2783. redis.Set(keyOne, "", time.Second)
  2784. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2785. redis.Set(keySeven, "", time.Second)
  2786. defer redis.Close()
  2787. } else {
  2788. tempPrescription.ID = id
  2789. tempPrescription.Type = types
  2790. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2791. tempPrescription.Mtime = time.Now().Unix()
  2792. tempPrescription.Doctor = role.UserName
  2793. //tempPrescription.OrderStatus = order_status
  2794. tempPrescription.PreTime = pTime
  2795. tempPrescription.MedType = med_type
  2796. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2797. redis := service.RedisClient()
  2798. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2799. redis.Set(key, "", time.Second)
  2800. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2801. redis.Set(keyOne, "", time.Second)
  2802. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2803. redis.Set(keySeven, "", time.Second)
  2804. defer redis.Close()
  2805. }
  2806. //service.SaveHisPrescription(prescription)
  2807. //更改患者挂号状态
  2808. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2809. fmt.Println("更改失败", err2)
  2810. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2811. advices := items["advices"].([]interface{})
  2812. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2813. groupNo := int64(0)
  2814. ctime := time.Now().Unix()
  2815. mtime := ctime
  2816. if len(advices) > 0 {
  2817. for _, advice := range advices {
  2818. tx := db.Begin()
  2819. // 在函数结束时处理事务回滚
  2820. defer func() {
  2821. if r := recover(); r != nil {
  2822. tx.Rollback()
  2823. }
  2824. }()
  2825. var s models.HisDoctorAdviceInfo
  2826. s.PrescriptionId = tempPrescription.ID
  2827. s.AdviceType = 2
  2828. s.AdviceDoctor = doctor_id
  2829. s.StopState = 2
  2830. s.ExecutionState = 2
  2831. s.AdviceDate = theTime3.Unix()
  2832. s.Status = 1
  2833. s.UserOrgId = adminInfo.CurrentOrgId
  2834. s.RecordDate = theTime3.Unix()
  2835. s.StartTime = tempPrescription.PreTime
  2836. s.Groupno = groupNo
  2837. s.CreatedTime = ctime
  2838. s.UpdatedTime = mtime
  2839. s.PatientId = patient_id
  2840. s.HisPatientId = his_patient_id
  2841. s.StartTime = pTime
  2842. s.IsSettle = 2
  2843. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2844. if errcode > 0 {
  2845. c.ServeFailJSONWithSGJErrorCode(errcode)
  2846. return
  2847. }
  2848. s.StartTime = pTime
  2849. var total_count int64 //处方总库存
  2850. //查询改药品信息
  2851. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2852. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2853. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2854. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2855. total_count += prescribingNumberSeven * medical.MinNumber
  2856. }
  2857. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2858. total_count += prescribingNumberSeven
  2859. }
  2860. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2861. total_count += prescribingNumberSeven
  2862. }
  2863. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2864. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2865. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2866. if s.Price != lastWarehouse.RetailPrice {
  2867. s.Price = lastWarehouse.RetailPrice
  2868. }
  2869. if s.Price == 0 {
  2870. s.Price = lastWarehouse.RetailPrice
  2871. }
  2872. }
  2873. //查询保存处方出库开关是否打开
  2874. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2875. if drugOutConfig.IsOpen == 1 {
  2876. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2877. // 查询该药品最后一次出库记录
  2878. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2879. if len(druginfo) > 0 {
  2880. //回退库存
  2881. for _, it := range druginfo {
  2882. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2883. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2884. }
  2885. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2886. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2887. }
  2888. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2889. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2890. }
  2891. }
  2892. //删除记录
  2893. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2894. }
  2895. service.CreateHisDoctorAdviceOne(&s, tx)
  2896. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2897. //出库
  2898. if drug.IsUse == 2 {
  2899. creater := adminInfo.AdminUser.Id
  2900. newadviceInfo := &models.HisDoctorAdviceInfo{
  2901. ID: advicelast.ID,
  2902. UserOrgId: s.UserOrgId,
  2903. PatientId: s.PatientId,
  2904. HisPatientId: s.HisPatientId,
  2905. AdviceType: s.AdviceType,
  2906. AdviceDate: s.AdviceDate,
  2907. StartTime: s.StartTime,
  2908. AdviceName: s.AdviceName,
  2909. AdviceDesc: s.AdviceDesc,
  2910. ReminderDate: s.ReminderDate,
  2911. SingleDose: s.SingleDose,
  2912. SingleDoseUnit: s.SingleDoseUnit,
  2913. PrescribingNumber: s.PrescribingNumber,
  2914. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2915. DeliveryWay: s.DeliveryWay,
  2916. ExecutionFrequency: s.ExecutionFrequency,
  2917. AdviceDoctor: s.AdviceDoctor,
  2918. Status: s.Status,
  2919. CreatedTime: s.CreatedTime,
  2920. UpdatedTime: s.UpdatedTime,
  2921. AdviceAffirm: s.AdviceAffirm,
  2922. Remark: s.Remark,
  2923. StopTime: s.StopTime,
  2924. StopReason: s.StopReason,
  2925. StopDoctor: s.StopDoctor,
  2926. StopState: s.StopState,
  2927. ParentId: s.ParentId,
  2928. ExecutionTime: s.ExecutionTime,
  2929. ExecutionStaff: s.ExecutionStaff,
  2930. ExecutionState: s.ExecutionState,
  2931. Checker: s.Checker,
  2932. RecordDate: s.RecordDate,
  2933. DialysisOrderId: s.DialysisOrderId,
  2934. CheckTime: s.CheckTime,
  2935. CheckState: s.CheckState,
  2936. DrugSpec: s.DrugSpec,
  2937. DrugSpecUnit: s.DrugSpecUnit,
  2938. Groupno: s.Groupno,
  2939. RemindType: s.RemindType,
  2940. FrequencyType: s.FrequencyType,
  2941. DayCount: s.DayCount,
  2942. WeekDay: s.WeekDay,
  2943. TemplateId: s.TemplateId,
  2944. Modifier: s.Modifier,
  2945. DrugId: s.DrugId,
  2946. Price: s.Price,
  2947. PrescriptionId: s.PrescriptionId,
  2948. MedListCodg: s.MedListCodg,
  2949. FeedetlSn: s.FeedetlSn,
  2950. Day: s.DayCount,
  2951. ChildDoctorAdvice: nil,
  2952. Drug: models.Drug{},
  2953. Diagnosis: s.Diagnosis,
  2954. Way: s.Way,
  2955. HospApprFlag: s.HospApprFlag,
  2956. LmtUsedFlag: s.LmtUsedFlag,
  2957. HisOrderInfo: models.HisOrderInfo{},
  2958. IsMedicine: s.IsMedicine,
  2959. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2960. Child: nil,
  2961. IsSettle: s.IsSettle,
  2962. IsMobile: s.IsMobile,
  2963. IsSelfDrug: s.IsSelfDrug,
  2964. DrugWayCount: s.DrugWayCount,
  2965. }
  2966. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2967. }
  2968. //更新字典里面的库存
  2969. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2970. var sum_count int64
  2971. for _, its := range stockInfo {
  2972. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2973. if its.MaxUnit == baseDrug.MaxUnit {
  2974. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2975. }
  2976. sum_count += its.StockMaxNumber + its.StockMinNumber
  2977. }
  2978. //更新基础库存
  2979. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2980. //剩余库存
  2981. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2982. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2983. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2984. }
  2985. //记录日志
  2986. byterequest, _ := json.Marshal(s)
  2987. adviceLog := models.XtDoctorAdviceLog{
  2988. UserOrgId: s.UserOrgId,
  2989. PatientId: s.PatientId,
  2990. AdminUserId: adminInfo.AdminUser.Id,
  2991. Module: 1,
  2992. ErrLog: string(byterequest),
  2993. Status: 1,
  2994. Ctime: time.Now().Unix(),
  2995. Mtime: 0,
  2996. Source: "电脑端新建his医嘱",
  2997. RecordDate: s.AdviceDate,
  2998. }
  2999. service.CreateDoctorAdviceLog(adviceLog)
  3000. //存储切片中
  3001. adviceList = append(adviceList, s)
  3002. redis := service.RedisClient()
  3003. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3004. redis.Set(key, "", time.Second)
  3005. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3006. redis.Set(keyOne, "", time.Second)
  3007. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3008. redis.Set(keySeven, "", time.Second)
  3009. var randNum int
  3010. randNum = rand.Intn(10000) + 1000
  3011. timestamp := time.Now().Unix()
  3012. tempTime := time.Unix(timestamp, 0)
  3013. timeFormat := tempTime.Format("20060102150405")
  3014. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3015. service.CreateHisDoctorAdviceOne(&s, tx)
  3016. tx.Commit()
  3017. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3018. redis.Set(keySix, "", time.Second)
  3019. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3020. redis.Set(keyFive, "", time.Second)
  3021. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3022. redis.Set(keyEight, "", time.Second)
  3023. defer redis.Close()
  3024. }
  3025. }
  3026. }
  3027. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3028. projects := items["project"].([]interface{})
  3029. if len(projects) > 0 {
  3030. for _, project := range projects {
  3031. tx := db.Begin()
  3032. // 在函数结束时处理事务回滚
  3033. defer func() {
  3034. if r := recover(); r != nil {
  3035. tx.Rollback()
  3036. }
  3037. }()
  3038. var p models.HisPrescriptionProject
  3039. p.PrescriptionId = tempPrescription.ID
  3040. p.Ctime = time.Now().Unix()
  3041. p.Mtime = time.Now().Unix()
  3042. p.PatientId = patient_id
  3043. p.RecordDate = theTime3.Unix()
  3044. p.Doctor = doctor_id
  3045. p.UserOrgId = adminInfo.CurrentOrgId
  3046. p.HisPatientId = his_patient_id
  3047. p.Status = 1
  3048. p.StartTime = pTime
  3049. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3050. if errcode > 0 {
  3051. c.ServeFailJSONWithSGJErrorCode(errcode)
  3052. return
  3053. }
  3054. if p.ID == 0 {
  3055. p.IsOut = 2
  3056. }
  3057. if p.ID > 0 {
  3058. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3059. p.IsOut = projectDetail.IsOut
  3060. }
  3061. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3062. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3063. if p.Type == 3 {
  3064. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3065. if p.Price != lastWarehouse.PackingPrice {
  3066. p.Price = lastWarehouse.PackingPrice
  3067. }
  3068. if p.Unit == "" {
  3069. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3070. p.Unit = goodInfoOne.PackingUnit
  3071. }
  3072. }
  3073. }
  3074. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3075. //
  3076. // if p.Type == 3 {
  3077. // //查询该耗材是否停用
  3078. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3079. // //表示该耗材已经停用,不能保存
  3080. // if goodInfoSeven.ID == 0 {
  3081. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3082. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3083. // return
  3084. // }
  3085. // }
  3086. //
  3087. //}
  3088. var randNum int
  3089. randNum = rand.Intn(10000) + 1000
  3090. timestamp := time.Now().Unix()
  3091. tempTime := time.Unix(timestamp, 0)
  3092. timeFormat := tempTime.Format("20060102150405")
  3093. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3094. service.CreateNewHisProjectTwo(&p, tx)
  3095. //查询保存耗材出库开关是否打开
  3096. if goodOutConfig.IsOpen == 1 {
  3097. //耗材出库
  3098. if p.Type == 3 {
  3099. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3100. //查询历史出库数据
  3101. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3102. var out_count_five int64
  3103. for _, item := range flowGood {
  3104. out_count_five += item.Count
  3105. }
  3106. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3107. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3108. if out_count_five != parseIntCount {
  3109. //查询耗材最后一次出库记录
  3110. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3111. //查询默认出库仓库库存
  3112. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3113. if len(wareOut) > 0 {
  3114. for _, it := range wareOut {
  3115. //回退库存
  3116. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3117. //删除出库记录
  3118. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3119. }
  3120. }
  3121. timeStr := time.Now().Format("2006-01-02")
  3122. timeArr := strings.Split(timeStr, "-")
  3123. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3124. total = total + 1
  3125. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3126. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3127. number = number + total
  3128. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3129. operation_time := time.Now().Unix()
  3130. creater := c.GetAdminUserInfo().AdminUser.Id
  3131. recordDateStr := time.Now().Format("2006-01-02")
  3132. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3133. nowtime := recordDate.Unix()
  3134. warehouseOut := models.WarehouseOut{
  3135. WarehouseOutOrderNumber: warehousing_out_order,
  3136. OperationTime: operation_time,
  3137. OrgId: adminInfo.CurrentOrgId,
  3138. Creater: creater,
  3139. Ctime: time.Now().Unix(),
  3140. Status: 1,
  3141. WarehouseOutTime: nowtime,
  3142. Type: 1,
  3143. StorehouseId: storeConfig.StorehouseOutInfo,
  3144. IsCheck: 1,
  3145. IsSys: 1,
  3146. }
  3147. //查询是否生成出库单
  3148. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3149. if out.ID == 0 {
  3150. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3151. }
  3152. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3153. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3154. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3155. dialyPrepareOne := models.DialysisBeforePrepare{
  3156. GoodTypeId: goodObj.GoodTypeId,
  3157. GoodId: p.ProjectId,
  3158. PatientId: p.PatientId,
  3159. RecordDate: p.RecordDate,
  3160. UserOrgId: adminInfo.CurrentOrgId,
  3161. Count: parseIntCount,
  3162. Ctime: time.Now().Unix(),
  3163. Creater: creater,
  3164. Status: 1,
  3165. StorehouseId: houseConfig.StorehouseOutInfo,
  3166. ProjectId: lastHisProject.ID,
  3167. }
  3168. //判断是否是零用耗材(非零用)
  3169. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3170. //查询历史出库数据
  3171. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3172. var out_count int64
  3173. for _, item := range flowGood {
  3174. out_count += item.Count
  3175. }
  3176. //如果历史数和当前数据不想等才进行退库出库
  3177. if out_count != parseIntCount {
  3178. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3179. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3180. detail := models.AutomaticReduceDetail{
  3181. WarehouseOutId: 0,
  3182. WarehouseOutOrderNumber: "",
  3183. PatientId: p.PatientId,
  3184. Ctime: time.Now().Unix(),
  3185. Mtime: 0,
  3186. Status: 1,
  3187. RecordTime: p.RecordDate,
  3188. OrgId: p.UserOrgId,
  3189. GoodId: p.ProjectId,
  3190. GoodTypeId: 0,
  3191. Count: parseIntCount,
  3192. Type: 0,
  3193. ProjectId: lastHisProject.ID,
  3194. StorehouseId: 0,
  3195. }
  3196. service.CreateNewAutoDetail(detail, tx)
  3197. //查询剩余库存
  3198. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3199. var sum_count int64
  3200. for _, item := range goodList {
  3201. sum_count += item.StockCount
  3202. }
  3203. //更新剩余库存
  3204. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3205. //耗材
  3206. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3207. }
  3208. //判断是否是零用耗材(零用但是是出库耗材)
  3209. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3210. //查询历史出库数据
  3211. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3212. var out_count int64
  3213. for _, item := range flowGood {
  3214. out_count += item.Count
  3215. }
  3216. //如果历史数和当前数据不想等才进行退库出库
  3217. if out_count != parseIntCount {
  3218. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3219. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3220. detail := models.AutomaticReduceDetail{
  3221. WarehouseOutId: 0,
  3222. WarehouseOutOrderNumber: "",
  3223. PatientId: p.PatientId,
  3224. Ctime: time.Now().Unix(),
  3225. Mtime: 0,
  3226. Status: 1,
  3227. RecordTime: p.RecordDate,
  3228. OrgId: p.UserOrgId,
  3229. GoodId: p.ProjectId,
  3230. GoodTypeId: 0,
  3231. Count: parseIntCount,
  3232. Type: 0,
  3233. ProjectId: p.ID,
  3234. StorehouseId: 0,
  3235. }
  3236. service.CreateNewAutoDetail(detail, tx)
  3237. //查询剩余库存
  3238. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3239. var sum_count int64
  3240. for _, item := range goodList {
  3241. sum_count += item.StockCount
  3242. }
  3243. //更新剩余库存
  3244. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3245. //耗材
  3246. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3247. }
  3248. }
  3249. }
  3250. }
  3251. //记录日志
  3252. byterequest, _ := json.Marshal(p)
  3253. adviceLog := models.XtDoctorAdviceLog{
  3254. UserOrgId: p.UserOrgId,
  3255. PatientId: p.PatientId,
  3256. AdminUserId: adminInfo.AdminUser.Id,
  3257. Module: 1,
  3258. ErrLog: string(byterequest),
  3259. Status: 1,
  3260. Ctime: time.Now().Unix(),
  3261. Mtime: 0,
  3262. Source: "电脑端新建his项目",
  3263. RecordDate: p.RecordDate,
  3264. }
  3265. service.CreateDoctorAdviceLog(adviceLog)
  3266. projectList = append(projectList, p)
  3267. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3268. //新增或者编辑项目,修改对应的标签数据
  3269. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3270. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3271. var label models.HisLabelPrintInfo
  3272. project, _ := service.GetProjectDetail(p.ProjectId)
  3273. if project.CostClassify == 3 { //类别为检验检查
  3274. if p.TeamId > 0 { //检验检查组套
  3275. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3276. if tempLabel.ID == 0 {
  3277. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3278. label.Number = tempPrescription.PrescriptionNumber
  3279. label.ProjectId = project.ID
  3280. label.Status = 1
  3281. label.IsPrint = 2
  3282. label.DoctorId = info.DoctorId
  3283. label.UserOrgId = p.UserOrgId
  3284. label.PatientId = patient_id
  3285. label.RecordDate = recordDateTime
  3286. label.Ctime = time.Now().Unix()
  3287. label.Mtime = time.Now().Unix()
  3288. label.ItemId = p.TeamId
  3289. label.FeedetlSn = p.FeedetlSn
  3290. label.PProjectId = p.ID
  3291. label.ProjectName = team.ProjectTeam
  3292. label.PatientName = patient.Name
  3293. service.CreateNewHisLabelRecord(&label, tx)
  3294. }
  3295. } else { //单条检验检查项目
  3296. label.Number = tempPrescription.PrescriptionNumber
  3297. label.ProjectId = project.ID
  3298. label.Status = 1
  3299. label.DoctorId = info.DoctorId
  3300. label.UserOrgId = p.UserOrgId
  3301. label.PatientId = patient_id
  3302. label.RecordDate = recordDateTime
  3303. label.IsPrint = 2
  3304. label.Ctime = time.Now().Unix()
  3305. label.Mtime = time.Now().Unix()
  3306. label.FeedetlSn = p.FeedetlSn
  3307. label.PProjectId = p.ID
  3308. label.ItemId = p.TeamId
  3309. label.ProjectName = project.ProjectName
  3310. label.PatientName = patient.Name
  3311. service.CreateNewHisLabelRecord(&label, tx)
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. tx.Commit()
  3319. }
  3320. }
  3321. }
  3322. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3323. // addition := items["addition"].([]interface{})
  3324. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3325. // ctime := time.Now().Unix()
  3326. // mtime := ctime
  3327. // if len(addition) > 0 {
  3328. // for _, item := range addition {
  3329. // var s models.HisAdditionalCharge
  3330. // s.PrescriptionId = tempPrescription.ID
  3331. // s.Status = 1
  3332. // s.UserOrgId = adminInfo.CurrentOrgId
  3333. // s.RecordDate = recordDateTime
  3334. // s.CreatedTime = ctime
  3335. // s.UpdatedTime = mtime
  3336. // s.PatientId = patient_id
  3337. // s.HisPatientId = his_patient_id
  3338. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3339. // if errcode > 0 {
  3340. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3341. // return
  3342. // }
  3343. // service.CreateAdditionalCharge(&s)
  3344. // var randNum int
  3345. // randNum = rand.Intn(10000) + 1000
  3346. // timestamp := time.Now().Unix()
  3347. // tempTime := time.Unix(timestamp, 0)
  3348. // timeFormat := tempTime.Format("20060102150405")
  3349. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3350. // service.CreateAdditionalCharge(&s)
  3351. //
  3352. // }
  3353. // }
  3354. //}
  3355. }
  3356. }
  3357. //查询今日该患者开的药品处方
  3358. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3359. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3360. //药品出库
  3361. //if drugOutConfig.IsOpen == 1 {
  3362. // for _, item := range hisdoctorlist {
  3363. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3364. //
  3365. // // 查询该药品最后一次出库记录
  3366. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3367. //
  3368. // if len(druginfo) > 0 {
  3369. // //回退库存
  3370. // for _, it := range druginfo {
  3371. //
  3372. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3373. //
  3374. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3375. //
  3376. // }
  3377. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3378. //
  3379. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3380. //
  3381. // }
  3382. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3383. //
  3384. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3385. //
  3386. // }
  3387. // }
  3388. // }
  3389. //
  3390. // //删除记录
  3391. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3392. // //查询最后一次数据
  3393. // if drugOutConfig.IsOpen == 1 {
  3394. // //出库
  3395. // if drug.IsUse == 2 {
  3396. // creater := adminInfo.AdminUser.Id
  3397. //
  3398. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3399. //
  3400. // }
  3401. //
  3402. // //更新字典里面的库存
  3403. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3404. // var sum_count int64
  3405. // for _, its := range stockInfo {
  3406. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3407. // if its.MaxUnit == baseDrug.MaxUnit {
  3408. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3409. // }
  3410. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3411. // }
  3412. // //更新基础库存
  3413. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3414. // //剩余库存
  3415. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3416. //
  3417. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3418. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3419. //
  3420. // }
  3421. // }
  3422. //}
  3423. //耗材保存处方出库
  3424. //if goodOutConfig.IsOpen == 1 {
  3425. //
  3426. // //查询今日耗材出库数量
  3427. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3428. //
  3429. // for _, item := range hisgoodlist {
  3430. //
  3431. // //查询历史出库数据
  3432. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3433. // var out_count_five int64
  3434. // for _, item := range flowGood {
  3435. // out_count_five += item.Count
  3436. // }
  3437. //
  3438. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3439. //
  3440. // if out_count_five != parseIntCount {
  3441. //
  3442. // //查询耗材最后一次出库记录
  3443. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3444. // //查询默认出库仓库库存
  3445. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3446. // if len(wareOut) > 0 {
  3447. //
  3448. // for _, it := range wareOut {
  3449. // //回退库存
  3450. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3451. //
  3452. // //删除出库记录
  3453. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3454. //
  3455. // }
  3456. // }
  3457. //
  3458. // timeStr := time.Now().Format("2006-01-02")
  3459. // timeArr := strings.Split(timeStr, "-")
  3460. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3461. //
  3462. // total = total + 1
  3463. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3464. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3465. // number = number + total
  3466. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3467. //
  3468. // operation_time := time.Now().Unix()
  3469. // creater := c.GetAdminUserInfo().AdminUser.Id
  3470. //
  3471. // recordDateStr := time.Now().Format("2006-01-02")
  3472. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3473. // nowtime := recordDate.Unix()
  3474. // warehouseOut := models.WarehouseOut{
  3475. // WarehouseOutOrderNumber: warehousing_out_order,
  3476. // OperationTime: operation_time,
  3477. // OrgId: adminInfo.CurrentOrgId,
  3478. // Creater: creater,
  3479. // Ctime: time.Now().Unix(),
  3480. // Status: 1,
  3481. // WarehouseOutTime: nowtime,
  3482. // Type: 1,
  3483. // StorehouseId: storeConfig.StorehouseOutInfo,
  3484. // IsCheck: 1,
  3485. // IsSys: 1,
  3486. // }
  3487. // //查询是否生成出库单
  3488. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3489. //
  3490. // if out.ID == 0 {
  3491. // service.AddSigleWarehouseOut(&warehouseOut)
  3492. // }
  3493. //
  3494. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3495. //
  3496. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3497. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3498. //
  3499. // dialyPrepareOne := models.DialysisBeforePrepare{
  3500. // GoodTypeId: goodObj.GoodTypeId,
  3501. // GoodId: item.ProjectId,
  3502. // PatientId: item.PatientId,
  3503. // RecordDate: item.RecordDate,
  3504. // UserOrgId: adminInfo.CurrentOrgId,
  3505. // Count: parseIntCount,
  3506. // Ctime: time.Now().Unix(),
  3507. // Creater: creater,
  3508. // Status: 1,
  3509. // StorehouseId: houseConfig.StorehouseOutInfo,
  3510. // ProjectId: item.ID,
  3511. // }
  3512. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3513. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3514. //
  3515. // //查询历史出库数据
  3516. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3517. // var out_count int64
  3518. // for _, item := range flowGood {
  3519. // out_count += item.Count
  3520. // }
  3521. //
  3522. // //如果历史数和当前数据不想等才进行退库出库
  3523. // if out_count != parseIntCount {
  3524. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3525. //
  3526. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3527. // detail := models.AutomaticReduceDetail{
  3528. // WarehouseOutId: 0,
  3529. // WarehouseOutOrderNumber: "",
  3530. // PatientId: item.PatientId,
  3531. // Ctime: time.Now().Unix(),
  3532. // Mtime: 0,
  3533. // Status: 1,
  3534. // RecordTime: item.RecordDate,
  3535. // OrgId: item.UserOrgId,
  3536. // GoodId: item.ProjectId,
  3537. // GoodTypeId: 0,
  3538. // Count: parseIntCount,
  3539. // Type: 0,
  3540. // ProjectId: item.ID,
  3541. // StorehouseId: 0,
  3542. // }
  3543. //
  3544. // service.CreateAutoDetail(detail)
  3545. //
  3546. // //查询剩余库存
  3547. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3548. // var sum_count int64
  3549. // for _, item := range goodList {
  3550. // sum_count += item.StockCount
  3551. // }
  3552. //
  3553. // //更新剩余库存
  3554. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3555. //
  3556. // //耗材
  3557. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3558. // }
  3559. //
  3560. // }
  3561. //
  3562. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3563. // //查询历史出库数据
  3564. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3565. // var out_count int64
  3566. // for _, item := range flowGood {
  3567. // out_count += item.Count
  3568. // }
  3569. // //如果历史数和当前数据不想等才进行退库出库
  3570. // if out_count != parseIntCount {
  3571. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3572. //
  3573. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3574. // detail := models.AutomaticReduceDetail{
  3575. // WarehouseOutId: 0,
  3576. // WarehouseOutOrderNumber: "",
  3577. // PatientId: item.PatientId,
  3578. // Ctime: time.Now().Unix(),
  3579. // Mtime: 0,
  3580. // Status: 1,
  3581. // RecordTime: item.RecordDate,
  3582. // OrgId: item.UserOrgId,
  3583. // GoodId: item.ProjectId,
  3584. // GoodTypeId: 0,
  3585. // Count: parseIntCount,
  3586. // Type: 0,
  3587. // ProjectId: item.ID,
  3588. // StorehouseId: 0,
  3589. // }
  3590. //
  3591. // service.CreateAutoDetail(detail)
  3592. //
  3593. // //查询剩余库存
  3594. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3595. // var sum_count int64
  3596. // for _, item := range goodList {
  3597. // sum_count += item.StockCount
  3598. // }
  3599. //
  3600. // //更新剩余库存
  3601. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3602. //
  3603. // //耗材
  3604. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3605. // }
  3606. //
  3607. // }
  3608. //
  3609. // }
  3610. // }
  3611. //}
  3612. }
  3613. tx.Commit()
  3614. if err == nil {
  3615. c.ServeSuccessJSON(map[string]interface{}{
  3616. "msg": "保存成功",
  3617. })
  3618. return
  3619. } else {
  3620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3621. return
  3622. }
  3623. } else {
  3624. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3625. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3626. var tempPrescription *models.HisPrescription
  3627. if len(prescriptions) > 0 {
  3628. for _, item := range prescriptions {
  3629. items := item.(map[string]interface{})
  3630. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3631. utils.ErrorLog("id")
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. return
  3634. }
  3635. id := int64(items["id"].(float64))
  3636. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3637. tempPrescription = &new_prescription
  3638. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3639. utils.ErrorLog("type")
  3640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3641. return
  3642. }
  3643. types := int64(items["type"].(float64))
  3644. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3645. utils.ErrorLog("med_type")
  3646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3647. return
  3648. }
  3649. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3650. if med_type == "0" {
  3651. med_type = "14"
  3652. }
  3653. //if order_status == 0 {
  3654. // order_status = 1
  3655. //}
  3656. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3657. utils.ErrorLog("pre_time")
  3658. }
  3659. preTime, _ := items["pre_time"].(string)
  3660. timeLayout := "2006-01-02"
  3661. loc, _ := time.LoadLocation("Local")
  3662. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3663. result := strings.Split(preTime, " ")
  3664. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3665. if err != nil {
  3666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3667. return
  3668. }
  3669. pTime := theTime2.Unix()
  3670. ctime := time.Now().Unix()
  3671. if tempPrescription.ID == 0 {
  3672. prescription := &models.HisPrescription{
  3673. ID: 0,
  3674. PatientId: patient_id,
  3675. UserOrgId: adminInfo.CurrentOrgId,
  3676. RecordDate: recordDateTime,
  3677. Ctime: ctime,
  3678. Mtime: ctime,
  3679. Type: types,
  3680. Modifier: adminInfo.AdminUser.Id,
  3681. Creator: adminInfo.AdminUser.Id,
  3682. Status: 1,
  3683. Doctor: role.UserName,
  3684. HisPatientId: his_patient_id,
  3685. OrderStatus: 1,
  3686. BatchNumber: "",
  3687. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3688. PreTime: pTime,
  3689. PType: p_type,
  3690. MedType: med_type,
  3691. }
  3692. tempPrescription = prescription
  3693. service.SaveHisPrescription(tempPrescription)
  3694. redis := service.RedisClient()
  3695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3696. redis.Set(key, "", time.Second)
  3697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3698. redis.Set(keyOne, "", time.Second)
  3699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3700. redis.Set(keySeven, "", time.Second)
  3701. defer redis.Close()
  3702. } else {
  3703. tempPrescription.ID = id
  3704. tempPrescription.Type = types
  3705. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3706. tempPrescription.Mtime = time.Now().Unix()
  3707. tempPrescription.Doctor = role.UserName
  3708. //tempPrescription.OrderStatus = order_status
  3709. tempPrescription.PreTime = pTime
  3710. tempPrescription.MedType = med_type
  3711. service.SaveHisPrescription(tempPrescription)
  3712. redis := service.RedisClient()
  3713. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3714. redis.Set(key, "", time.Second)
  3715. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3716. redis.Set(keyOne, "", time.Second)
  3717. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3718. redis.Set(keySeven, "", time.Second)
  3719. defer redis.Close()
  3720. }
  3721. //service.SaveHisPrescription(prescription)
  3722. //更改患者挂号状态
  3723. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3724. fmt.Println("更改失败", err2)
  3725. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3726. advices := items["advices"].([]interface{})
  3727. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3728. groupNo := int64(0)
  3729. ctime := time.Now().Unix()
  3730. mtime := ctime
  3731. if len(advices) > 0 {
  3732. for _, advice := range advices {
  3733. var s models.HisDoctorAdviceInfo
  3734. s.PrescriptionId = tempPrescription.ID
  3735. s.AdviceType = 2
  3736. s.AdviceDoctor = doctor_id
  3737. s.StopState = 2
  3738. s.ExecutionState = 2
  3739. s.AdviceDate = theTime3.Unix()
  3740. s.Status = 1
  3741. s.UserOrgId = adminInfo.CurrentOrgId
  3742. s.RecordDate = theTime3.Unix()
  3743. s.StartTime = tempPrescription.PreTime
  3744. s.Groupno = groupNo
  3745. s.CreatedTime = ctime
  3746. s.UpdatedTime = mtime
  3747. s.PatientId = patient_id
  3748. s.HisPatientId = his_patient_id
  3749. s.StartTime = pTime
  3750. s.IsSettle = 2
  3751. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3752. if errcode > 0 {
  3753. c.ServeFailJSONWithSGJErrorCode(errcode)
  3754. return
  3755. }
  3756. s.StartTime = pTime
  3757. var total_count int64 //处方总库存
  3758. //查询改药品信息
  3759. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3760. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3761. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3762. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3763. total_count += prescribingNumberSeven * medical.MinNumber
  3764. }
  3765. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3766. total_count += prescribingNumberSeven
  3767. }
  3768. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3769. total_count += prescribingNumberSeven
  3770. }
  3771. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3772. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3773. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3774. if s.Price != lastWarehouse.RetailPrice {
  3775. s.Price = lastWarehouse.RetailPrice
  3776. }
  3777. if s.Price == 0 {
  3778. s.Price = lastWarehouse.RetailPrice
  3779. }
  3780. }
  3781. service.CreateHisDoctorAdvice(&s)
  3782. //记录日志
  3783. byterequest, _ := json.Marshal(s)
  3784. adviceLog := models.XtDoctorAdviceLog{
  3785. UserOrgId: s.UserOrgId,
  3786. PatientId: s.PatientId,
  3787. AdminUserId: adminInfo.AdminUser.Id,
  3788. Module: 1,
  3789. ErrLog: string(byterequest),
  3790. Status: 1,
  3791. Ctime: time.Now().Unix(),
  3792. Mtime: 0,
  3793. Source: "电脑端新建his医嘱",
  3794. RecordDate: s.AdviceDate,
  3795. }
  3796. service.CreateDoctorAdviceLog(adviceLog)
  3797. //存储切片中
  3798. adviceList = append(adviceList, s)
  3799. redis := service.RedisClient()
  3800. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3801. redis.Set(key, "", time.Second)
  3802. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3803. redis.Set(keyOne, "", time.Second)
  3804. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3805. redis.Set(keySeven, "", time.Second)
  3806. var randNum int
  3807. randNum = rand.Intn(10000) + 1000
  3808. timestamp := time.Now().Unix()
  3809. tempTime := time.Unix(timestamp, 0)
  3810. timeFormat := tempTime.Format("20060102150405")
  3811. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3812. service.CreateHisDoctorAdvice(&s)
  3813. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3814. redis.Set(keySix, "", time.Second)
  3815. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3816. redis.Set(keyFive, "", time.Second)
  3817. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3818. redis.Set(keyEight, "", time.Second)
  3819. defer redis.Close()
  3820. }
  3821. }
  3822. }
  3823. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3824. projects := items["project"].([]interface{})
  3825. if len(projects) > 0 {
  3826. for _, project := range projects {
  3827. var p models.HisPrescriptionProject
  3828. p.PrescriptionId = tempPrescription.ID
  3829. p.Ctime = time.Now().Unix()
  3830. p.Mtime = time.Now().Unix()
  3831. p.PatientId = patient_id
  3832. p.RecordDate = theTime3.Unix()
  3833. p.Doctor = doctor_id
  3834. p.UserOrgId = adminInfo.CurrentOrgId
  3835. p.HisPatientId = his_patient_id
  3836. p.Status = 1
  3837. p.StartTime = pTime
  3838. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3839. if errcode > 0 {
  3840. c.ServeFailJSONWithSGJErrorCode(errcode)
  3841. return
  3842. }
  3843. if p.ID == 0 {
  3844. p.IsOut = 2
  3845. }
  3846. if p.ID > 0 {
  3847. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3848. p.IsOut = projectDetail.IsOut
  3849. }
  3850. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3851. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3852. if p.Type == 3 {
  3853. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3854. if p.Price != lastWarehouse.PackingPrice {
  3855. p.Price = lastWarehouse.PackingPrice
  3856. }
  3857. if p.Unit == "" {
  3858. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3859. p.Unit = goodInfoOne.PackingUnit
  3860. }
  3861. }
  3862. }
  3863. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3864. //
  3865. // if p.Type == 3 {
  3866. // //查询该耗材是否停用
  3867. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3868. // //表示该耗材已经停用,不能保存
  3869. // if goodInfoSeven.ID == 0 {
  3870. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3871. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3872. // return
  3873. // }
  3874. // }
  3875. //
  3876. //}
  3877. service.CreateHisProjectTwo(&p)
  3878. //记录日志
  3879. byterequest, _ := json.Marshal(p)
  3880. adviceLog := models.XtDoctorAdviceLog{
  3881. UserOrgId: p.UserOrgId,
  3882. PatientId: p.PatientId,
  3883. AdminUserId: adminInfo.AdminUser.Id,
  3884. Module: 1,
  3885. ErrLog: string(byterequest),
  3886. Status: 1,
  3887. Ctime: time.Now().Unix(),
  3888. Mtime: 0,
  3889. Source: "电脑端新建his项目",
  3890. RecordDate: p.RecordDate,
  3891. }
  3892. service.CreateDoctorAdviceLog(adviceLog)
  3893. projectList = append(projectList, p)
  3894. var randNum int
  3895. randNum = rand.Intn(10000) + 1000
  3896. timestamp := time.Now().Unix()
  3897. tempTime := time.Unix(timestamp, 0)
  3898. timeFormat := tempTime.Format("20060102150405")
  3899. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3900. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3901. //新增或者编辑项目,修改对应的标签数据
  3902. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3903. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3904. var label models.HisLabelPrintInfo
  3905. project, _ := service.GetProjectDetail(p.ProjectId)
  3906. if project.CostClassify == 3 { //类别为检验检查
  3907. if p.TeamId > 0 { //检验检查组套
  3908. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3909. if tempLabel.ID == 0 {
  3910. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3911. label.Number = tempPrescription.PrescriptionNumber
  3912. label.ProjectId = project.ID
  3913. label.Status = 1
  3914. label.IsPrint = 2
  3915. label.DoctorId = info.DoctorId
  3916. label.UserOrgId = p.UserOrgId
  3917. label.PatientId = patient_id
  3918. label.RecordDate = recordDateTime
  3919. label.Ctime = time.Now().Unix()
  3920. label.Mtime = time.Now().Unix()
  3921. label.ItemId = p.TeamId
  3922. label.FeedetlSn = p.FeedetlSn
  3923. label.PProjectId = p.ID
  3924. label.ProjectName = team.ProjectTeam
  3925. label.PatientName = patient.Name
  3926. service.CreateHisLabelRecord(&label)
  3927. }
  3928. } else { //单条检验检查项目
  3929. label.Number = tempPrescription.PrescriptionNumber
  3930. label.ProjectId = project.ID
  3931. label.Status = 1
  3932. label.DoctorId = info.DoctorId
  3933. label.UserOrgId = p.UserOrgId
  3934. label.PatientId = patient_id
  3935. label.RecordDate = recordDateTime
  3936. label.IsPrint = 2
  3937. label.Ctime = time.Now().Unix()
  3938. label.Mtime = time.Now().Unix()
  3939. label.FeedetlSn = p.FeedetlSn
  3940. label.PProjectId = p.ID
  3941. label.ItemId = p.TeamId
  3942. label.ProjectName = project.ProjectName
  3943. label.PatientName = patient.Name
  3944. service.CreateHisLabelRecord(&label)
  3945. }
  3946. }
  3947. }
  3948. }
  3949. service.SaveHisProjectTwo(&p)
  3950. }
  3951. }
  3952. }
  3953. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3954. // addition := items["addition"].([]interface{})
  3955. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3956. // ctime := time.Now().Unix()
  3957. // mtime := ctime
  3958. // if len(addition) > 0 {
  3959. // for _, item := range addition {
  3960. // var s models.HisAdditionalCharge
  3961. // s.PrescriptionId = tempPrescription.ID
  3962. // s.Status = 1
  3963. // s.UserOrgId = adminInfo.CurrentOrgId
  3964. // s.RecordDate = recordDateTime
  3965. // s.CreatedTime = ctime
  3966. // s.UpdatedTime = mtime
  3967. // s.PatientId = patient_id
  3968. // s.HisPatientId = his_patient_id
  3969. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3970. // if errcode > 0 {
  3971. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3972. // return
  3973. // }
  3974. // service.CreateAdditionalCharge(&s)
  3975. // var randNum int
  3976. // randNum = rand.Intn(10000) + 1000
  3977. // timestamp := time.Now().Unix()
  3978. // tempTime := time.Unix(timestamp, 0)
  3979. // timeFormat := tempTime.Format("20060102150405")
  3980. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3981. // service.CreateAdditionalCharge(&s)
  3982. //
  3983. // }
  3984. // }
  3985. //}
  3986. }
  3987. }
  3988. //查询今日该患者开的药品处方
  3989. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3990. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3991. //药品出库
  3992. if drugOutConfig.IsOpen == 1 {
  3993. for _, item := range hisdoctorlist {
  3994. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3995. // 查询该药品最后一次出库记录
  3996. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3997. if len(druginfo) > 0 {
  3998. //回退库存
  3999. for _, it := range druginfo {
  4000. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4001. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4002. }
  4003. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4004. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4005. }
  4006. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4007. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4008. }
  4009. }
  4010. }
  4011. //删除记录
  4012. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4013. //查询最后一次数据
  4014. if drugOutConfig.IsOpen == 1 {
  4015. //出库
  4016. if drug.IsUse == 2 {
  4017. creater := adminInfo.AdminUser.Id
  4018. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4019. }
  4020. //更新字典里面的库存
  4021. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4022. var sum_count int64
  4023. for _, its := range stockInfo {
  4024. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4025. if its.MaxUnit == baseDrug.MaxUnit {
  4026. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4027. }
  4028. sum_count += its.StockMaxNumber + its.StockMinNumber
  4029. }
  4030. //更新基础库存
  4031. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4032. //剩余库存
  4033. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4034. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4035. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4036. }
  4037. }
  4038. }
  4039. //耗材保存处方出库
  4040. if goodOutConfig.IsOpen == 1 {
  4041. //查询今日耗材出库数量
  4042. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4043. for _, item := range hisgoodlist {
  4044. //查询历史出库数据
  4045. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4046. var out_count_five int64
  4047. for _, item := range flowGood {
  4048. out_count_five += item.Count
  4049. }
  4050. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4051. if out_count_five != parseIntCount {
  4052. //查询耗材最后一次出库记录
  4053. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4054. //查询默认出库仓库库存
  4055. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4056. if len(wareOut) > 0 {
  4057. for _, it := range wareOut {
  4058. //回退库存
  4059. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4060. //删除出库记录
  4061. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4062. }
  4063. }
  4064. timeStr := time.Now().Format("2006-01-02")
  4065. timeArr := strings.Split(timeStr, "-")
  4066. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4067. total = total + 1
  4068. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4069. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4070. number = number + total
  4071. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4072. operation_time := time.Now().Unix()
  4073. creater := c.GetAdminUserInfo().AdminUser.Id
  4074. recordDateStr := time.Now().Format("2006-01-02")
  4075. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4076. nowtime := recordDate.Unix()
  4077. warehouseOut := models.WarehouseOut{
  4078. WarehouseOutOrderNumber: warehousing_out_order,
  4079. OperationTime: operation_time,
  4080. OrgId: adminInfo.CurrentOrgId,
  4081. Creater: creater,
  4082. Ctime: time.Now().Unix(),
  4083. Status: 1,
  4084. WarehouseOutTime: nowtime,
  4085. Type: 1,
  4086. StorehouseId: storeConfig.StorehouseOutInfo,
  4087. IsCheck: 1,
  4088. IsSys: 1,
  4089. }
  4090. //查询是否生成出库单
  4091. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4092. if out.ID == 0 {
  4093. service.AddSigleWarehouseOut(&warehouseOut)
  4094. }
  4095. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4096. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4097. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4098. dialyPrepareOne := models.DialysisBeforePrepare{
  4099. GoodTypeId: goodObj.GoodTypeId,
  4100. GoodId: item.ProjectId,
  4101. PatientId: item.PatientId,
  4102. RecordDate: item.RecordDate,
  4103. UserOrgId: adminInfo.CurrentOrgId,
  4104. Count: parseIntCount,
  4105. Ctime: time.Now().Unix(),
  4106. Creater: creater,
  4107. Status: 1,
  4108. StorehouseId: houseConfig.StorehouseOutInfo,
  4109. ProjectId: item.ID,
  4110. }
  4111. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4112. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4113. //查询历史出库数据
  4114. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4115. var out_count int64
  4116. for _, item := range flowGood {
  4117. out_count += item.Count
  4118. }
  4119. //如果历史数和当前数据不想等才进行退库出库
  4120. if out_count != parseIntCount {
  4121. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4122. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4123. detail := models.AutomaticReduceDetail{
  4124. WarehouseOutId: 0,
  4125. WarehouseOutOrderNumber: "",
  4126. PatientId: item.PatientId,
  4127. Ctime: time.Now().Unix(),
  4128. Mtime: 0,
  4129. Status: 1,
  4130. RecordTime: item.RecordDate,
  4131. OrgId: item.UserOrgId,
  4132. GoodId: item.ProjectId,
  4133. GoodTypeId: 0,
  4134. Count: parseIntCount,
  4135. Type: 0,
  4136. ProjectId: item.ID,
  4137. StorehouseId: 0,
  4138. }
  4139. service.CreateAutoDetail(detail)
  4140. //查询剩余库存
  4141. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4142. var sum_count int64
  4143. for _, item := range goodList {
  4144. sum_count += item.StockCount
  4145. }
  4146. //更新剩余库存
  4147. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4148. //耗材
  4149. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4150. }
  4151. }
  4152. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4153. //查询历史出库数据
  4154. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4155. var out_count int64
  4156. for _, item := range flowGood {
  4157. out_count += item.Count
  4158. }
  4159. //如果历史数和当前数据不想等才进行退库出库
  4160. if out_count != parseIntCount {
  4161. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4162. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4163. detail := models.AutomaticReduceDetail{
  4164. WarehouseOutId: 0,
  4165. WarehouseOutOrderNumber: "",
  4166. PatientId: item.PatientId,
  4167. Ctime: time.Now().Unix(),
  4168. Mtime: 0,
  4169. Status: 1,
  4170. RecordTime: item.RecordDate,
  4171. OrgId: item.UserOrgId,
  4172. GoodId: item.ProjectId,
  4173. GoodTypeId: 0,
  4174. Count: parseIntCount,
  4175. Type: 0,
  4176. ProjectId: item.ID,
  4177. StorehouseId: 0,
  4178. }
  4179. service.CreateAutoDetail(detail)
  4180. //查询剩余库存
  4181. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4182. var sum_count int64
  4183. for _, item := range goodList {
  4184. sum_count += item.StockCount
  4185. }
  4186. //更新剩余库存
  4187. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4188. //耗材
  4189. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4190. }
  4191. }
  4192. }
  4193. }
  4194. }
  4195. }
  4196. tx.Commit()
  4197. if err == nil {
  4198. c.ServeSuccessJSON(map[string]interface{}{
  4199. "msg": "保存成功",
  4200. })
  4201. return
  4202. } else {
  4203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4204. return
  4205. }
  4206. }
  4207. }
  4208. //func (c *HisApiController) EditHisPrescription() {
  4209. // record_date := c.GetString("record_date")
  4210. // patient_id, _ := c.GetInt64("patient_id")
  4211. // reg_type, _ := c.GetInt64("reg_type")
  4212. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4213. // diagnose := c.GetString("diagnose")
  4214. // sick_type, _ := c.GetInt64("sick_type")
  4215. // sick_history := c.GetString("sick_history")
  4216. // doctor_id, _ := c.GetInt64("doctor", 0)
  4217. // department, _ := c.GetInt64("department", 0)
  4218. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4219. // p_type, _ := c.GetInt64("p_type")
  4220. //
  4221. // dataBody := make(map[string]interface{}, 0)
  4222. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4223. // if err != nil {
  4224. // utils.ErrorLog(err.Error())
  4225. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. // return
  4227. // }
  4228. //
  4229. // timeLayout := "2006-01-02"
  4230. // loc, _ := time.LoadLocation("Local")
  4231. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4232. // if err != nil {
  4233. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4234. // return
  4235. // }
  4236. // adminInfo := c.GetAdminUserInfo()
  4237. // recordDateTime := theTime.Unix()
  4238. //
  4239. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4240. //
  4241. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4242. // var hpInfo models.HisPrescriptionInfo
  4243. // if info.ID == 0 {
  4244. // var randNum int
  4245. // randNum = rand.Intn(10000) + 1000
  4246. // timestamp := time.Now().Unix()
  4247. // tempTime := time.Unix(timestamp, 0)
  4248. // timeFormat := tempTime.Format("20060102150405")
  4249. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4250. //
  4251. // hpInfo = models.HisPrescriptionInfo{
  4252. // UserOrgId: adminInfo.CurrentOrgId,
  4253. // RecordDate: theTime.Unix(),
  4254. // PatientId: patient_id,
  4255. // Status: 1,
  4256. // Ctime: time.Now().Unix(),
  4257. // Mtime: time.Now().Unix(),
  4258. // Creator: adminInfo.AdminUser.Id,
  4259. // Modifier: adminInfo.AdminUser.Id,
  4260. // Diagnosis: diagnose,
  4261. // SickHistory: sick_history,
  4262. // Departments: department,
  4263. // RegisterType: reg_type,
  4264. // PrescriptionNumber: p_number,
  4265. // PrescriptionStatus: 1,
  4266. // Doctor: role.UserName,
  4267. // DoctorId: doctor_id,
  4268. // SickType: sick_type,
  4269. // PType: p_type,
  4270. // }
  4271. // service.SavePatientPrescriptionInfo(hpInfo)
  4272. //
  4273. // } else {
  4274. // hpInfo = models.HisPrescriptionInfo{
  4275. // ID: info.ID,
  4276. // UserOrgId: adminInfo.CurrentOrgId,
  4277. // RecordDate: info.RecordDate,
  4278. // PatientId: info.PatientId,
  4279. // Status: 1,
  4280. // Ctime: info.Ctime,
  4281. // Mtime: time.Now().Unix(),
  4282. // Creator: info.Creator,
  4283. // Modifier: adminInfo.AdminUser.Id,
  4284. // Diagnosis: diagnose,
  4285. // SickHistory: sick_history,
  4286. // Departments: department,
  4287. // RegisterType: reg_type,
  4288. // PrescriptionNumber: info.PrescriptionNumber,
  4289. // Doctor: role.UserName,
  4290. // PrescriptionStatus: info.PrescriptionStatus,
  4291. // DoctorId: doctor_id,
  4292. // SickType: sick_type,
  4293. // PType: info.PType,
  4294. // }
  4295. // service.SavePatientPrescriptionInfo(hpInfo)
  4296. // }
  4297. //
  4298. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4299. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4300. //
  4301. // if len(prescriptions) > 0 {
  4302. // for _, item := range prescriptions {
  4303. // items := item.(map[string]interface{})
  4304. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4305. // utils.ErrorLog("id")
  4306. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4307. // return
  4308. // }
  4309. // id := int64(items["id"].(float64))
  4310. //
  4311. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4312. // utils.ErrorLog("type")
  4313. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4314. // return
  4315. // }
  4316. // types := int64(items["type"].(float64))
  4317. //
  4318. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4319. // utils.ErrorLog("med_type")
  4320. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4321. // return
  4322. // }
  4323. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4324. //
  4325. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4326. //
  4327. // ctime := time.Now().Unix()
  4328. //
  4329. // prescription := &models.HisPrescription{
  4330. // ID: id,
  4331. // PatientId: patient_id,
  4332. // UserOrgId: adminInfo.CurrentOrgId,
  4333. // RecordDate: recordDateTime,
  4334. // Ctime: ctime,
  4335. // Mtime: ctime,
  4336. // Type: types,
  4337. // Modifier: adminInfo.AdminUser.Id,
  4338. // Creator: adminInfo.AdminUser.Id,
  4339. // Status: 1,
  4340. // Doctor: role.UserName,
  4341. // HisPatientId: his_patient_id,
  4342. // OrderStatus: 1,
  4343. // BatchNumber: "",
  4344. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4345. // PType: hpInfo.PType,
  4346. // MedType: med_type,
  4347. // }
  4348. //
  4349. // if historyPrescription.ID > 0 {
  4350. // prescription.PreTime = historyPrescription.PreTime
  4351. //
  4352. // }
  4353. //
  4354. // service.SaveHisPrescription(prescription)
  4355. //
  4356. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4357. // advices := items["advices"].([]interface{})
  4358. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4359. // groupNo := int64(0)
  4360. // ctime := time.Now().Unix()
  4361. // mtime := ctime
  4362. // if len(advices) > 0 {
  4363. // for _, advice := range advices {
  4364. // var s models.HisDoctorAdviceInfo
  4365. // s.PrescriptionId = prescription.ID
  4366. // s.AdviceType = 2
  4367. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4368. // s.StopState = 2
  4369. // s.ExecutionState = 2
  4370. // s.AdviceDate = recordDateTime
  4371. // s.Status = 1
  4372. // s.UserOrgId = adminInfo.CurrentOrgId
  4373. // s.RecordDate = recordDateTime
  4374. // s.StartTime = prescription.PreTime
  4375. // s.Groupno = groupNo
  4376. // s.CreatedTime = ctime
  4377. // s.UpdatedTime = mtime
  4378. // s.PatientId = patient_id
  4379. // s.HisPatientId = his_patient_id
  4380. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4381. // if errcode > 0 {
  4382. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4383. // return
  4384. // }
  4385. //
  4386. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4387. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4388. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4389. // if s.Price == 0 {
  4390. // s.Price = lastWarehouse.RetailPrice
  4391. // }
  4392. // }
  4393. //
  4394. // service.CreateHisDoctorAdvice(&s)
  4395. // //记录日志
  4396. // byterequest, _ := json.Marshal(s)
  4397. // adviceLog := models.XtDoctorAdviceLog{
  4398. // UserOrgId: s.UserOrgId,
  4399. // PatientId: s.PatientId,
  4400. // AdminUserId: adminInfo.AdminUser.Id,
  4401. // Module: 1,
  4402. // ErrLog: string(byterequest),
  4403. // Status: 1,
  4404. // Ctime: time.Now().Unix(),
  4405. // Mtime: 0,
  4406. // Source: "电脑端his医嘱修改",
  4407. // RecordDate: s.AdviceDate,
  4408. // }
  4409. // service.CreateDoctorAdviceLog(adviceLog)
  4410. // redis := service.RedisClient()
  4411. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4412. // redis.Set(key, "", time.Second)
  4413. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4414. // fmt.Println("keyOne", keyOne)
  4415. // redis.Set(keyOne, "", time.Second)
  4416. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4417. // redis.Set(keySeven, "", time.Second)
  4418. // redis.Close()
  4419. //
  4420. // }
  4421. // }
  4422. // }
  4423. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4424. // projects := items["project"].([]interface{})
  4425. // if len(projects) > 0 {
  4426. // for _, project := range projects {
  4427. // var p models.HisPrescriptionProject
  4428. // p.PrescriptionId = prescription.ID
  4429. // p.Ctime = time.Now().Unix()
  4430. // p.Mtime = time.Now().Unix()
  4431. // p.PatientId = patient_id
  4432. // p.RecordDate = recordDateTime
  4433. // p.UserOrgId = adminInfo.CurrentOrgId
  4434. // p.HisPatientId = his_patient_id
  4435. // p.Status = 1
  4436. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4437. // if errcode > 0 {
  4438. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4439. // return
  4440. // }
  4441. // service.CreateHisProjectTwo(&p)
  4442. //
  4443. // //记录日志
  4444. // byterequest, _ := json.Marshal(p)
  4445. // adviceLog := models.XtDoctorAdviceLog{
  4446. // UserOrgId: p.UserOrgId,
  4447. // PatientId: p.PatientId,
  4448. // AdminUserId: adminInfo.AdminUser.Id,
  4449. // Module: 1,
  4450. // ErrLog: string(byterequest),
  4451. // Status: 1,
  4452. // Ctime: time.Now().Unix(),
  4453. // Mtime: 0,
  4454. // Source: "电脑端his项目修改",
  4455. // RecordDate: p.RecordDate,
  4456. // }
  4457. // service.CreateDoctorAdviceLog(adviceLog)
  4458. // }
  4459. // }
  4460. // }
  4461. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4462. // addition := items["addition"].([]interface{})
  4463. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4464. // ctime := time.Now().Unix()
  4465. // mtime := ctime
  4466. // if len(addition) > 0 {
  4467. // for _, item := range addition {
  4468. // var s models.HisAdditionalCharge
  4469. // s.PrescriptionId = prescription.ID
  4470. // s.Status = 1
  4471. // s.UserOrgId = adminInfo.CurrentOrgId
  4472. // s.RecordDate = recordDateTime
  4473. // s.CreatedTime = ctime
  4474. // s.UpdatedTime = mtime
  4475. // s.PatientId = patient_id
  4476. // s.HisPatientId = his_patient_id
  4477. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4478. // if errcode > 0 {
  4479. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4480. // return
  4481. // }
  4482. // service.CreateAdditionalCharge(&s)
  4483. // }
  4484. // }
  4485. // }
  4486. //
  4487. // }
  4488. // }
  4489. // }
  4490. // if err == nil {
  4491. // c.ServeSuccessJSON(map[string]interface{}{
  4492. // "msg": "保存成功",
  4493. // })
  4494. // return
  4495. //
  4496. // } else {
  4497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4498. // return
  4499. // }
  4500. //}
  4501. func (c *HisApiController) DeletePrescription() {
  4502. prescription_id, _ := c.GetInt64("id")
  4503. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4504. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4505. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4506. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4507. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4508. //耗材保存处方出库
  4509. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4510. //已收费和已发药限制逻辑
  4511. isCharge := false
  4512. isMedicine := false
  4513. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4514. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4515. for _, item := range new_prescriptions {
  4516. if item.IsMedicine == 1 {
  4517. isMedicine = true
  4518. }
  4519. }
  4520. for _, item := range new_prescriptions {
  4521. if item.OrderStatus == 4 {
  4522. isCharge = true
  4523. }
  4524. }
  4525. if p_err != nil {
  4526. if new_prescription.ID > 0 {
  4527. if new_prescription.OrderStatus == 2 {
  4528. isCharge = true
  4529. }
  4530. }
  4531. }
  4532. for _, item := range advices {
  4533. if item.IsMedicine == 1 {
  4534. isMedicine = true
  4535. }
  4536. }
  4537. if isCharge {
  4538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4539. return
  4540. }
  4541. if isMedicine {
  4542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4543. return
  4544. }
  4545. //已收费和已发药限制逻辑
  4546. if len(projects) > 0 {
  4547. for _, item := range projects {
  4548. service.DeletePrintInfo(item.ID) //删除打印信息
  4549. if goodOutConfig.IsOpen != 1 {
  4550. if stockConfig.IsOpen == 1 {
  4551. if item.Type == 3 && item.IsOut == 1 {
  4552. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4553. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4554. good.Total = good.Total + f_count
  4555. service.UpdateGoodInfo(&good)
  4556. operation_time := time.Now().Unix()
  4557. creater := c.GetAdminUserInfo().AdminUser.Id
  4558. //创建退库单
  4559. timeStr := time.Now().Format("2006-01-02")
  4560. timeArr := strings.Split(timeStr, "-")
  4561. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4562. total = total + 1
  4563. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4564. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4565. cancelStock := models.CancelStock{
  4566. OrderNumber: orderNumber,
  4567. OperaTime: operation_time,
  4568. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4569. Creater: creater,
  4570. Ctime: time.Now().Unix(),
  4571. Status: 1,
  4572. ReturnTime: item.RecordDate,
  4573. Type: 1,
  4574. StorehouseId: houseConfig.StorehouseOutInfo,
  4575. IsCheck: 1,
  4576. }
  4577. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4578. if msgerrkonde == gorm.ErrRecordNotFound {
  4579. service.AddSigleCancelStock(&cancelStock)
  4580. }
  4581. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4582. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4583. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4584. //查询该耗材是否出库
  4585. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4586. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4587. deaerler, _ := service.GetDealerById(info.Dealer)
  4588. var total_count int64
  4589. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4590. total_count += count
  4591. if info.ID > 0 {
  4592. if info.Count >= total_count {
  4593. //回退库存
  4594. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4595. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4596. var flush_count int64
  4597. for _, it := range goodList {
  4598. flush_count += it.StockCount
  4599. }
  4600. cancelStockInfo := models.CancelStockInfo{
  4601. GoodId: item.ProjectId,
  4602. CancelStockId: cancel.ID,
  4603. GoodTypeId: good.GoodTypeId,
  4604. Count: prescribingNumber,
  4605. Price: info.Price,
  4606. Total: 0,
  4607. ProductDate: info.ProductDate,
  4608. ExpiryDate: info.ExpiryDate,
  4609. Ctime: time.Now().Unix(),
  4610. Status: 1,
  4611. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4612. OrderNumber: cancel.OrderNumber,
  4613. Type: 0,
  4614. Dealer: deaerler.DealerName,
  4615. Manufacturer: manufacturer.ManufacturerName,
  4616. Number: info.Number,
  4617. RegisterAccount: "",
  4618. Remark: "",
  4619. WarehouseInfoId: info.WarehouseInfotId,
  4620. PatientId: info.PatientId,
  4621. RecordDate: info.SysRecordTime,
  4622. StorehouseId: houseConfig.StorehouseOutInfo,
  4623. IsCheck: 1,
  4624. }
  4625. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4626. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4627. flow := models.VmStockFlow{
  4628. WarehousingId: info.WarehouseInfotId,
  4629. GoodId: item.ProjectId,
  4630. Number: info.Number,
  4631. LicenseNumber: info.LicenseNumber,
  4632. Count: prescribingNumber,
  4633. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4634. PatientId: item.PatientId,
  4635. SystemTime: info.SysRecordTime,
  4636. ConsumableType: 7,
  4637. IsSys: 0,
  4638. WarehousingOrder: "",
  4639. WarehouseOutId: info.WarehouseOutId,
  4640. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4641. IsEdit: 0,
  4642. CancelStockId: cancel.ID,
  4643. CancelOrderNumber: cancel.OrderNumber,
  4644. Manufacturer: manufacturer.ID,
  4645. Dealer: 0,
  4646. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4647. UpdateCreator: 0,
  4648. Status: 1,
  4649. Ctime: time.Now().Unix(),
  4650. Mtime: 0,
  4651. Price: info.Price,
  4652. WarehousingDetailId: info.WarehouseInfotId,
  4653. WarehouseOutDetailId: info.ID,
  4654. CancelOutDetailId: cancelInfo.ID,
  4655. ProductDate: info.ProductDate,
  4656. ExpireDate: info.ExpiryDate,
  4657. StorehouseId: houseConfig.StorehouseOutInfo,
  4658. OverCount: flush_count,
  4659. }
  4660. service.CreateStockFlowOne(flow)
  4661. //退库数量增加
  4662. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4663. //出库数量减少
  4664. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4665. }
  4666. if info.Count < total_count {
  4667. //回退库存
  4668. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4669. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4670. var flush_count int64
  4671. for _, it := range goodList {
  4672. flush_count += it.StockCount
  4673. }
  4674. cancelStockInfo := models.CancelStockInfo{
  4675. GoodId: item.ProjectId,
  4676. CancelStockId: cancel.ID,
  4677. GoodTypeId: good.GoodTypeId,
  4678. Count: info.Count,
  4679. Price: info.Price,
  4680. Total: 0,
  4681. ProductDate: info.ProductDate,
  4682. ExpiryDate: info.ExpiryDate,
  4683. Ctime: time.Now().Unix(),
  4684. Status: 1,
  4685. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4686. OrderNumber: cancel.OrderNumber,
  4687. Type: 0,
  4688. Dealer: deaerler.DealerName,
  4689. Manufacturer: manufacturer.ManufacturerName,
  4690. Number: info.Number,
  4691. RegisterAccount: "",
  4692. Remark: "",
  4693. WarehouseInfoId: info.WarehouseInfotId,
  4694. PatientId: info.PatientId,
  4695. RecordDate: info.SysRecordTime,
  4696. StorehouseId: houseConfig.StorehouseOutInfo,
  4697. IsCheck: 1,
  4698. }
  4699. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4700. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4701. flow := models.VmStockFlow{
  4702. WarehousingId: info.WarehouseInfotId,
  4703. GoodId: item.ProjectId,
  4704. Number: info.Number,
  4705. LicenseNumber: info.LicenseNumber,
  4706. Count: info.Count,
  4707. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4708. PatientId: item.PatientId,
  4709. SystemTime: info.SysRecordTime,
  4710. ConsumableType: 7,
  4711. IsSys: 0,
  4712. WarehousingOrder: "",
  4713. WarehouseOutId: info.WarehouseOutId,
  4714. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4715. IsEdit: 0,
  4716. CancelStockId: cancel.ID,
  4717. CancelOrderNumber: cancel.OrderNumber,
  4718. Manufacturer: manufacturer.ID,
  4719. Dealer: 0,
  4720. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4721. UpdateCreator: 0,
  4722. Status: 1,
  4723. Ctime: time.Now().Unix(),
  4724. Mtime: 0,
  4725. Price: info.Price,
  4726. WarehousingDetailId: info.WarehouseInfotId,
  4727. WarehouseOutDetailId: info.ID,
  4728. CancelOutDetailId: cancelInfo.ID,
  4729. ProductDate: info.ProductDate,
  4730. ExpireDate: info.ExpiryDate,
  4731. StorehouseId: houseConfig.StorehouseOutInfo,
  4732. OverCount: flush_count,
  4733. }
  4734. service.CreateStockFlowOne(flow)
  4735. //退库数量增加
  4736. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4737. //出库数量减少
  4738. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4739. }
  4740. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4741. var flush_count int64
  4742. for _, it := range goodList {
  4743. flush_count += it.StockCount
  4744. }
  4745. //查询已出库数量
  4746. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4747. if prescribingNumber < dialysisInfo.Count {
  4748. //改变数量
  4749. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4750. }
  4751. if prescribingNumber >= dialysisInfo.Count {
  4752. //删除出库表
  4753. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4754. }
  4755. //更新库存
  4756. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4757. //更新基础库库存
  4758. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4759. }
  4760. }
  4761. }
  4762. }
  4763. //保存耗材出库
  4764. if goodOutConfig.IsOpen == 1 {
  4765. if item.Type == 3 {
  4766. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4767. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4768. good.Total = good.Total + f_count
  4769. service.UpdateGoodInfo(&good)
  4770. operation_time := time.Now().Unix()
  4771. creater := c.GetAdminUserInfo().AdminUser.Id
  4772. //创建退库单
  4773. timeStr := time.Now().Format("2006-01-02")
  4774. timeArr := strings.Split(timeStr, "-")
  4775. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4776. total = total + 1
  4777. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4778. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4779. cancelStock := models.CancelStock{
  4780. OrderNumber: orderNumber,
  4781. OperaTime: operation_time,
  4782. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4783. Creater: creater,
  4784. Ctime: time.Now().Unix(),
  4785. Status: 1,
  4786. ReturnTime: item.RecordDate,
  4787. Type: 1,
  4788. StorehouseId: houseConfig.StorehouseOutInfo,
  4789. IsCheck: 1,
  4790. }
  4791. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4792. if msgerrkonde == gorm.ErrRecordNotFound {
  4793. service.AddSigleCancelStock(&cancelStock)
  4794. }
  4795. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4796. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4797. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4798. //查询该耗材是否出库
  4799. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4800. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4801. deaerler, _ := service.GetDealerById(info.Dealer)
  4802. var total_count int64
  4803. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4804. total_count += count
  4805. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4806. var flush_count int64
  4807. for _, it := range goodList {
  4808. flush_count += it.StockCount
  4809. }
  4810. fmt.Println("历史出库数据", info.Count)
  4811. fmt.Println("出库数量", total_count)
  4812. if info.ID > 0 {
  4813. cancelStockInfo := models.CancelStockInfo{
  4814. GoodId: item.ProjectId,
  4815. CancelStockId: cancel.ID,
  4816. GoodTypeId: good.GoodTypeId,
  4817. Count: prescribingNumber,
  4818. Price: info.Price,
  4819. Total: 0,
  4820. ProductDate: info.ProductDate,
  4821. ExpiryDate: info.ExpiryDate,
  4822. Ctime: time.Now().Unix(),
  4823. Status: 1,
  4824. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4825. OrderNumber: cancel.OrderNumber,
  4826. Type: 0,
  4827. Dealer: deaerler.DealerName,
  4828. Manufacturer: manufacturer.ManufacturerName,
  4829. Number: info.Number,
  4830. RegisterAccount: "",
  4831. Remark: "",
  4832. WarehouseInfoId: info.WarehouseInfotId,
  4833. PatientId: info.PatientId,
  4834. RecordDate: info.SysRecordTime,
  4835. StorehouseId: houseConfig.StorehouseOutInfo,
  4836. IsCheck: 1,
  4837. }
  4838. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4839. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4840. //查询出库数量
  4841. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4842. //出库数据 大于 退库数量
  4843. if len(list) > 0 {
  4844. for _, it := range list {
  4845. //回退库存
  4846. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4847. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4848. var flush_count_one int64
  4849. for _, it := range goodList {
  4850. flush_count_one += it.StockCount
  4851. }
  4852. //查询该批次是否有退库数据
  4853. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4854. creater := c.GetAdminUserInfo().AdminUser.Id
  4855. flow := models.VmStockFlow{
  4856. WarehousingId: it.WarehouseInfotId,
  4857. GoodId: it.GoodId,
  4858. Number: it.Number,
  4859. LicenseNumber: it.LicenseNumber,
  4860. Count: it.Count,
  4861. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4862. PatientId: it.PatientId,
  4863. SystemTime: it.SysRecordTime,
  4864. ConsumableType: 7,
  4865. IsSys: 0,
  4866. WarehousingOrder: "",
  4867. WarehouseOutId: it.WarehouseOutId,
  4868. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4869. IsEdit: 0,
  4870. CancelStockId: cancel.ID,
  4871. CancelOrderNumber: cancel.OrderNumber,
  4872. Manufacturer: manufacturer.ID,
  4873. Dealer: 0,
  4874. Creator: creater,
  4875. UpdateCreator: 0,
  4876. Status: 1,
  4877. Ctime: time.Now().Unix(),
  4878. Mtime: 0,
  4879. Price: it.Price,
  4880. WarehousingDetailId: it.WarehouseInfotId,
  4881. WarehouseOutDetailId: it.ID,
  4882. CancelOutDetailId: cancelInfo.ID,
  4883. ProductDate: it.ProductDate,
  4884. ExpireDate: it.ExpiryDate,
  4885. StorehouseId: houseConfig.StorehouseOutInfo,
  4886. OverCount: flush_count_one,
  4887. }
  4888. service.CreateStockFlowOne(flow)
  4889. //if flow.ID > 0 {
  4890. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4891. //}
  4892. }
  4893. }
  4894. //flow := models.VmStockFlow{
  4895. // WarehousingId: info.WarehouseInfotId,
  4896. // GoodId: item.ProjectId,
  4897. // Number: info.Number,
  4898. // LicenseNumber: info.LicenseNumber,
  4899. // Count: prescribingNumber,
  4900. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4901. // PatientId: item.PatientId,
  4902. // SystemTime: info.SysRecordTime,
  4903. // ConsumableType: 7,
  4904. // IsSys: 0,
  4905. // WarehousingOrder: "",
  4906. // WarehouseOutId: info.WarehouseOutId,
  4907. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4908. // IsEdit: 0,
  4909. // CancelStockId: cancel.ID,
  4910. // CancelOrderNumber: cancel.OrderNumber,
  4911. // Manufacturer: manufacturer.ID,
  4912. // Dealer: 0,
  4913. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4914. // UpdateCreator: 0,
  4915. // Status: 1,
  4916. // Ctime: time.Now().Unix(),
  4917. // Mtime: 0,
  4918. // Price: info.Price,
  4919. // WarehousingDetailId: info.WarehouseInfotId,
  4920. // WarehouseOutDetailId: info.ID,
  4921. // CancelOutDetailId: cancelInfo.ID,
  4922. // ProductDate: info.ProductDate,
  4923. // ExpireDate: info.ExpiryDate,
  4924. // StorehouseId: houseConfig.StorehouseOutInfo,
  4925. // OverCount: flush_count,
  4926. //}
  4927. //service.CreateStockFlowOne(flow)
  4928. //退库数量增加
  4929. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4930. //出库数量减少
  4931. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4932. //查询已出库数量
  4933. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4934. if prescribingNumber < dialysisInfo.Count {
  4935. //改变数量
  4936. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4937. }
  4938. if prescribingNumber >= dialysisInfo.Count {
  4939. //删除出库表
  4940. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4941. }
  4942. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4943. var flush_count_one int64
  4944. for _, it := range goodList {
  4945. flush_count_one += it.StockCount
  4946. }
  4947. //更新库存
  4948. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4949. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4950. //更新基础库库存
  4951. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4952. }
  4953. }
  4954. }
  4955. }
  4956. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4957. fmt.Println(err)
  4958. }
  4959. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4960. fmt.Println(err)
  4961. if len(advices) > 0 {
  4962. for _, item := range advices {
  4963. redis := service.RedisClient()
  4964. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4965. redis.Set(keyFive, "", time.Second)
  4966. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4967. redis.Set(keyOne, "", time.Second)
  4968. redis.Close()
  4969. }
  4970. }
  4971. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4972. if len(advices) > 0 {
  4973. for _, item := range advices {
  4974. creater := c.GetAdminUserInfo().AdminUser.Id
  4975. service.DrugAutoAddCancelInfo(item, creater)
  4976. }
  4977. }
  4978. } else {
  4979. if drugOutConfig.IsOpen == 1 {
  4980. if len(advices) > 0 {
  4981. for _, item := range advices {
  4982. creater := c.GetAdminUserInfo().AdminUser.Id
  4983. service.DrugAutoAddCancelInfo(item, creater)
  4984. }
  4985. }
  4986. } else {
  4987. if len(advices) > 0 {
  4988. for _, item := range advices {
  4989. creater := c.GetAdminUserInfo().AdminUser.Id
  4990. service.DrugAutoAddCancelInfo(item, creater)
  4991. }
  4992. }
  4993. }
  4994. }
  4995. c.ServeSuccessJSON(map[string]interface{}{
  4996. "msg": "删除成功",
  4997. })
  4998. return
  4999. }
  5000. func (c *HisApiController) DeleteDoctorAdvice() {
  5001. id, _ := c.GetInt64("id")
  5002. advice, _ := service.GetHisDoctorAdvicesById(id)
  5003. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5004. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5005. //已收费和已发药的限制逻辑
  5006. isCharge := false
  5007. isMedicine := false
  5008. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5009. //获取今天该患者所有处方,判断是否发药或者收费
  5010. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5011. for _, item := range new_prescriptions {
  5012. if item.IsMedicine == 1 {
  5013. isMedicine = true
  5014. }
  5015. }
  5016. for _, item := range new_prescriptions {
  5017. if item.OrderStatus == 4 {
  5018. isCharge = true
  5019. }
  5020. }
  5021. if isMedicine {
  5022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5023. return
  5024. }
  5025. if isCharge {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5027. return
  5028. }
  5029. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5030. for _, item := range advices {
  5031. if item.IsMedicine == 1 {
  5032. isMedicine = true
  5033. }
  5034. }
  5035. if isMedicine {
  5036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5037. return
  5038. }
  5039. if new_prescription.ID > 0 {
  5040. if new_prescription.OrderStatus == 2 {
  5041. isCharge = true
  5042. }
  5043. }
  5044. if isCharge {
  5045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5046. return
  5047. }
  5048. //已收费和已发药的限制逻辑
  5049. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5050. redis := service.RedisClient()
  5051. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5052. redis.Set(keyFive, "", time.Second)
  5053. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5054. redis.Set(keyOne, "", time.Second)
  5055. defer redis.Close()
  5056. if err == nil {
  5057. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5058. //查询是否在处方中出库
  5059. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5060. if openConfig.IsOpen != 1 {
  5061. //判断该医嘱是否执行了
  5062. if advice.ExecutionState == 1 {
  5063. creater := c.GetAdminUserInfo().AdminUser.Id
  5064. service.DrugAutoAddCancelInfo(&advice, creater)
  5065. }
  5066. }
  5067. //开启保存处方扣减功能
  5068. if openConfig.IsOpen == 1 {
  5069. creater := c.GetAdminUserInfo().AdminUser.Id
  5070. service.DrugAutoAddCancelInfo(&advice, creater)
  5071. }
  5072. } else {
  5073. if drugOutConfig.IsOpen == 1 {
  5074. //查询是否在处方中出库
  5075. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5076. if openConfig.IsOpen != 1 {
  5077. //判断该医嘱是否执行了
  5078. if advice.ExecutionState == 1 {
  5079. creater := c.GetAdminUserInfo().AdminUser.Id
  5080. service.DrugAutoAddCancelInfo(&advice, creater)
  5081. }
  5082. }
  5083. //开启保存处方扣减功能
  5084. if openConfig.IsOpen == 1 {
  5085. creater := c.GetAdminUserInfo().AdminUser.Id
  5086. service.DrugAutoAddCancelInfo(&advice, creater)
  5087. }
  5088. } else {
  5089. //判断该医嘱是否执行了
  5090. if advice.ExecutionState == 1 {
  5091. creater := c.GetAdminUserInfo().AdminUser.Id
  5092. service.DrugAutoAddCancelInfo(&advice, creater)
  5093. }
  5094. }
  5095. }
  5096. c.ServeSuccessJSON(map[string]interface{}{
  5097. "msg": "删除成功",
  5098. })
  5099. return
  5100. } else {
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5102. return
  5103. }
  5104. }
  5105. func (c *HisApiController) DeleteProject() {
  5106. id, _ := c.GetInt64("id")
  5107. adminInfo := c.GetAdminUserInfo()
  5108. project, _ := service.GetHisProjectByID(id)
  5109. // var consumable models.DialysisBeforePrepare
  5110. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5111. //耗材保存处方出库
  5112. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5113. isCharge := false
  5114. isMedicine := false
  5115. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5116. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5117. for _, item := range new_prescriptions {
  5118. if item.IsMedicine == 1 {
  5119. isMedicine = true
  5120. }
  5121. }
  5122. for _, item := range new_prescriptions {
  5123. if item.OrderStatus == 4 {
  5124. isCharge = true
  5125. }
  5126. }
  5127. if isMedicine {
  5128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5129. return
  5130. }
  5131. if isCharge {
  5132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5133. return
  5134. }
  5135. if new_prescription.ID > 0 {
  5136. if new_prescription.OrderStatus == 2 {
  5137. isCharge = true
  5138. }
  5139. }
  5140. if isCharge {
  5141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5142. return
  5143. }
  5144. service.DeletePrintInfo(id)
  5145. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5146. label.Status = 0
  5147. service.CreateHisLabelRecordTwo(&label)
  5148. fmt.Println(goodOutConfig.IsOpen)
  5149. if goodOutConfig.IsOpen != 1 {
  5150. if stockConfig.IsOpen == 1 {
  5151. if project.Type == 2 {
  5152. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5153. fmt.Println(err)
  5154. }
  5155. if project.Type == 3 && project.IsOut == 1 {
  5156. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5157. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5158. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5159. operation_time := time.Now().Unix()
  5160. creater := adminInfo.AdminUser.Id
  5161. //创建退库单
  5162. timeStr := time.Now().Format("2006-01-02")
  5163. timeArr := strings.Split(timeStr, "-")
  5164. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5165. total = total + 1
  5166. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5167. cancelStock := models.CancelStock{
  5168. OrderNumber: orderNumber,
  5169. OperaTime: operation_time,
  5170. OrgId: adminInfo.CurrentOrgId,
  5171. Creater: creater,
  5172. Ctime: time.Now().Unix(),
  5173. Status: 1,
  5174. ReturnTime: project.RecordDate,
  5175. Type: 1,
  5176. StorehouseId: houseConfig.StorehouseOutInfo,
  5177. IsCheck: 1,
  5178. }
  5179. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5180. if msgerrkonde == gorm.ErrRecordNotFound {
  5181. service.AddSigleCancelStock(&cancelStock)
  5182. }
  5183. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5184. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5185. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5186. //查询是否有出库
  5187. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5188. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5189. deaerler, _ := service.GetDealerById(info.Dealer)
  5190. if info.ID > 0 {
  5191. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5192. if info.Count >= prescribingNumber {
  5193. cancelStockInfo := models.CancelStockInfo{
  5194. GoodId: project.ProjectId,
  5195. CancelStockId: cancel.ID,
  5196. GoodTypeId: good.GoodTypeId,
  5197. Count: prescribingNumber,
  5198. Price: info.Price,
  5199. Total: 0,
  5200. ProductDate: info.ProductDate,
  5201. ExpiryDate: info.ExpiryDate,
  5202. Ctime: time.Now().Unix(),
  5203. Status: 1,
  5204. OrgId: adminInfo.CurrentOrgId,
  5205. OrderNumber: cancel.OrderNumber,
  5206. Type: 0,
  5207. Dealer: deaerler.DealerName,
  5208. Manufacturer: manufacturer.ManufacturerName,
  5209. Number: info.Number,
  5210. RegisterAccount: "",
  5211. Remark: "",
  5212. WarehouseInfoId: info.WarehouseInfotId,
  5213. PatientId: info.PatientId,
  5214. RecordDate: info.SysRecordTime,
  5215. StorehouseId: houseConfig.StorehouseOutInfo,
  5216. IsCheck: 1,
  5217. }
  5218. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5219. //回退库存
  5220. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5221. //退库数量增加
  5222. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5223. //出库数量减少
  5224. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5225. }
  5226. if info.Count < prescribingNumber {
  5227. cancelStockInfo := models.CancelStockInfo{
  5228. GoodId: project.ProjectId,
  5229. CancelStockId: cancel.ID,
  5230. GoodTypeId: good.GoodTypeId,
  5231. Count: info.Count,
  5232. Price: info.Price,
  5233. Total: 0,
  5234. ProductDate: info.ProductDate,
  5235. ExpiryDate: info.ExpiryDate,
  5236. Ctime: time.Now().Unix(),
  5237. Status: 1,
  5238. OrgId: adminInfo.CurrentOrgId,
  5239. OrderNumber: cancel.OrderNumber,
  5240. Type: 0,
  5241. Dealer: deaerler.DealerName,
  5242. Manufacturer: manufacturer.ManufacturerName,
  5243. Number: info.Number,
  5244. RegisterAccount: "",
  5245. Remark: "",
  5246. WarehouseInfoId: info.WarehouseInfotId,
  5247. PatientId: info.PatientId,
  5248. RecordDate: info.SysRecordTime,
  5249. StorehouseId: houseConfig.StorehouseOutInfo,
  5250. IsCheck: 1,
  5251. }
  5252. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5253. //回退库存
  5254. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5255. //退库数量增加
  5256. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5257. //出库数量减少
  5258. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5259. }
  5260. //查询剩余库存
  5261. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5262. var over_count int64
  5263. for _, it := range goodList {
  5264. over_count += it.StockCount
  5265. }
  5266. //出库数据 大于 退库数量
  5267. if info.Count >= prescribingNumber {
  5268. flow := models.VmStockFlow{
  5269. WarehousingId: info.WarehouseInfotId,
  5270. GoodId: project.ProjectId,
  5271. Number: info.Number,
  5272. LicenseNumber: info.LicenseNumber,
  5273. Count: prescribingNumber,
  5274. UserOrgId: adminInfo.CurrentOrgId,
  5275. PatientId: project.PatientId,
  5276. SystemTime: info.SysRecordTime,
  5277. ConsumableType: 7,
  5278. IsSys: 0,
  5279. WarehousingOrder: "",
  5280. WarehouseOutId: info.WarehouseOutId,
  5281. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5282. IsEdit: 0,
  5283. CancelStockId: cancel.ID,
  5284. CancelOrderNumber: cancel.OrderNumber,
  5285. Manufacturer: manufacturer.ID,
  5286. Dealer: 0,
  5287. Creator: adminInfo.AdminUser.Id,
  5288. UpdateCreator: 0,
  5289. Status: 1,
  5290. Ctime: time.Now().Unix(),
  5291. Mtime: 0,
  5292. Price: info.Price,
  5293. WarehousingDetailId: info.WarehouseInfotId,
  5294. WarehouseOutDetailId: info.ID,
  5295. CancelOutDetailId: cancelInfo.ID,
  5296. ProductDate: info.ProductDate,
  5297. ExpireDate: info.ExpiryDate,
  5298. StorehouseId: houseConfig.StorehouseOutInfo,
  5299. OverCount: over_count,
  5300. }
  5301. service.CreateStockFlowOne(flow)
  5302. }
  5303. //出库数据小于退库数据
  5304. if info.Count < prescribingNumber {
  5305. flow := models.VmStockFlow{
  5306. WarehousingId: info.WarehouseInfotId,
  5307. GoodId: project.ProjectId,
  5308. Number: info.Number,
  5309. LicenseNumber: info.LicenseNumber,
  5310. Count: info.Count,
  5311. UserOrgId: adminInfo.CurrentOrgId,
  5312. PatientId: project.PatientId,
  5313. SystemTime: info.SysRecordTime,
  5314. ConsumableType: 7,
  5315. IsSys: 0,
  5316. WarehousingOrder: "",
  5317. WarehouseOutId: info.WarehouseOutId,
  5318. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5319. IsEdit: 0,
  5320. CancelStockId: cancel.ID,
  5321. CancelOrderNumber: cancel.OrderNumber,
  5322. Manufacturer: manufacturer.ID,
  5323. Dealer: 0,
  5324. Creator: adminInfo.AdminUser.Id,
  5325. UpdateCreator: 0,
  5326. Status: 1,
  5327. Ctime: time.Now().Unix(),
  5328. Mtime: 0,
  5329. Price: info.Price,
  5330. WarehousingDetailId: info.WarehouseInfotId,
  5331. WarehouseOutDetailId: info.ID,
  5332. CancelOutDetailId: cancelInfo.ID,
  5333. ProductDate: info.ProductDate,
  5334. ExpireDate: info.ExpiryDate,
  5335. StorehouseId: houseConfig.StorehouseOutInfo,
  5336. OverCount: over_count,
  5337. }
  5338. service.CreateStockFlowOne(flow)
  5339. }
  5340. //查询已出库数量
  5341. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5342. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5343. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5344. if prescribingNumber < dialysisInfo.Count {
  5345. //改变数量
  5346. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5347. }
  5348. if prescribingNumber >= dialysisInfo.Count {
  5349. //删除出库表
  5350. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5351. }
  5352. //更新剩余库存
  5353. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5354. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5355. var total_count_one int64
  5356. for _, it := range stockList {
  5357. total_count_one += it.StockCount
  5358. }
  5359. //基础库插入数据
  5360. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5361. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5362. var flush_count int64
  5363. for _, it := range goodListOne {
  5364. flush_count += it.StockCount
  5365. }
  5366. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5367. if errs != nil {
  5368. goodErrcode := models.XtGoodErrcode{
  5369. UserOrgId: project.UserOrgId,
  5370. Errcode: "手动出库更新剩余出库失败",
  5371. GoodId: project.ProjectId,
  5372. Status: 1,
  5373. Ctime: time.Now().Unix(),
  5374. Mtime: 0,
  5375. Count: 0,
  5376. StockCount: 0,
  5377. Creater: creater,
  5378. BatchNumberId: 0,
  5379. WarehouseOutId: 0,
  5380. }
  5381. service.CreateGoodErrcode(goodErrcode)
  5382. }
  5383. }
  5384. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5385. fmt.Println(err)
  5386. } else {
  5387. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5388. fmt.Println(err)
  5389. }
  5390. } else {
  5391. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5392. fmt.Println(err)
  5393. }
  5394. }
  5395. //保存处方出库
  5396. if goodOutConfig.IsOpen == 1 {
  5397. if project.Type == 3 {
  5398. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5399. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5400. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5401. operation_time := time.Now().Unix()
  5402. creater := adminInfo.AdminUser.Id
  5403. //创建退库单
  5404. timeStr := time.Now().Format("2006-01-02")
  5405. timeArr := strings.Split(timeStr, "-")
  5406. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5407. total = total + 1
  5408. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5409. cancelStock := models.CancelStock{
  5410. OrderNumber: orderNumber,
  5411. OperaTime: operation_time,
  5412. OrgId: adminInfo.CurrentOrgId,
  5413. Creater: creater,
  5414. Ctime: time.Now().Unix(),
  5415. Status: 1,
  5416. ReturnTime: project.RecordDate,
  5417. Type: 1,
  5418. StorehouseId: houseConfig.StorehouseOutInfo,
  5419. IsCheck: 1,
  5420. }
  5421. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5422. if msgerrkonde == gorm.ErrRecordNotFound {
  5423. service.AddSigleCancelStock(&cancelStock)
  5424. }
  5425. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5426. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5427. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5428. //获取出库数据
  5429. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5430. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5431. deaerler, _ := service.GetDealerById(info.Dealer)
  5432. if info.ID > 0 {
  5433. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5434. if info.Count >= prescribingNumber {
  5435. cancelStockInfo := models.CancelStockInfo{
  5436. GoodId: project.ProjectId,
  5437. CancelStockId: cancel.ID,
  5438. GoodTypeId: good.GoodTypeId,
  5439. Count: prescribingNumber,
  5440. Price: info.Price,
  5441. Total: 0,
  5442. ProductDate: info.ProductDate,
  5443. ExpiryDate: info.ExpiryDate,
  5444. Ctime: time.Now().Unix(),
  5445. Status: 1,
  5446. OrgId: adminInfo.CurrentOrgId,
  5447. OrderNumber: cancel.OrderNumber,
  5448. Type: 0,
  5449. Dealer: deaerler.DealerName,
  5450. Manufacturer: manufacturer.ManufacturerName,
  5451. Number: info.Number,
  5452. RegisterAccount: "",
  5453. Remark: "",
  5454. WarehouseInfoId: info.WarehouseInfotId,
  5455. PatientId: info.PatientId,
  5456. RecordDate: info.SysRecordTime,
  5457. StorehouseId: houseConfig.StorehouseOutInfo,
  5458. IsCheck: 1,
  5459. }
  5460. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5461. //退库数量增加
  5462. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5463. //出库数量减少
  5464. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5465. }
  5466. if info.Count < prescribingNumber {
  5467. cancelStockInfo := models.CancelStockInfo{
  5468. GoodId: project.ProjectId,
  5469. CancelStockId: cancel.ID,
  5470. GoodTypeId: good.GoodTypeId,
  5471. Count: prescribingNumber,
  5472. Price: info.Price,
  5473. Total: 0,
  5474. ProductDate: info.ProductDate,
  5475. ExpiryDate: info.ExpiryDate,
  5476. Ctime: time.Now().Unix(),
  5477. Status: 1,
  5478. OrgId: adminInfo.CurrentOrgId,
  5479. OrderNumber: cancel.OrderNumber,
  5480. Type: 0,
  5481. Dealer: deaerler.DealerName,
  5482. Manufacturer: manufacturer.ManufacturerName,
  5483. Number: info.Number,
  5484. RegisterAccount: "",
  5485. Remark: "",
  5486. WarehouseInfoId: info.WarehouseInfotId,
  5487. PatientId: info.PatientId,
  5488. RecordDate: info.SysRecordTime,
  5489. StorehouseId: houseConfig.StorehouseOutInfo,
  5490. IsCheck: 1,
  5491. }
  5492. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5493. //回退库存
  5494. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5495. }
  5496. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5497. var over_count int64
  5498. for _, it := range goodList {
  5499. over_count += it.StockCount
  5500. }
  5501. //查询出库数量
  5502. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5503. //出库数据 大于 退库数量
  5504. if len(list) > 0 {
  5505. for _, it := range list {
  5506. //回退库存
  5507. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5508. //退库数量增加
  5509. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5510. //出库数量减少
  5511. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5512. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5513. var over_count_one int64
  5514. for _, it := range goodList {
  5515. over_count_one += it.StockCount
  5516. }
  5517. //查询该批次是否有退库数据
  5518. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5519. flow := models.VmStockFlow{
  5520. WarehousingId: it.WarehouseInfotId,
  5521. GoodId: it.GoodId,
  5522. Number: it.Number,
  5523. LicenseNumber: it.LicenseNumber,
  5524. Count: it.Count,
  5525. UserOrgId: adminInfo.CurrentOrgId,
  5526. PatientId: it.PatientId,
  5527. SystemTime: it.SysRecordTime,
  5528. ConsumableType: 7,
  5529. IsSys: 0,
  5530. WarehousingOrder: "",
  5531. WarehouseOutId: it.WarehouseOutId,
  5532. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5533. IsEdit: 0,
  5534. CancelStockId: cancel.ID,
  5535. CancelOrderNumber: cancel.OrderNumber,
  5536. Manufacturer: manufacturer.ID,
  5537. Dealer: 0,
  5538. Creator: adminInfo.AdminUser.Id,
  5539. UpdateCreator: 0,
  5540. Status: 1,
  5541. Ctime: time.Now().Unix(),
  5542. Mtime: 0,
  5543. Price: it.Price,
  5544. WarehousingDetailId: it.WarehouseInfotId,
  5545. WarehouseOutDetailId: it.ID,
  5546. CancelOutDetailId: cancelInfo.ID,
  5547. ProductDate: it.ProductDate,
  5548. ExpireDate: it.ExpiryDate,
  5549. StorehouseId: houseConfig.StorehouseOutInfo,
  5550. OverCount: over_count_one,
  5551. }
  5552. service.CreateStockFlowOne(flow)
  5553. }
  5554. }
  5555. //查询已出库数量
  5556. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5557. if prescribingNumber < dialysisInfo.Count {
  5558. //改变数量
  5559. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5560. }
  5561. if prescribingNumber >= dialysisInfo.Count {
  5562. //删除出库表
  5563. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5564. }
  5565. //更新剩余库存
  5566. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5567. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5568. var total_count_one int64
  5569. for _, it := range stockList {
  5570. total_count_one += it.StockCount
  5571. }
  5572. //基础库插入数据
  5573. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5574. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5575. var flush_count int64
  5576. for _, it := range goodListOne {
  5577. flush_count += it.StockCount
  5578. }
  5579. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5580. if errs != nil {
  5581. goodErrcode := models.XtGoodErrcode{
  5582. UserOrgId: project.UserOrgId,
  5583. Errcode: "手动出库更新剩余出库失败",
  5584. GoodId: project.ProjectId,
  5585. Status: 1,
  5586. Ctime: time.Now().Unix(),
  5587. Mtime: 0,
  5588. Count: 0,
  5589. StockCount: 0,
  5590. Creater: creater,
  5591. BatchNumberId: 0,
  5592. WarehouseOutId: 0,
  5593. }
  5594. service.CreateGoodErrcode(goodErrcode)
  5595. }
  5596. }
  5597. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5598. fmt.Println(err)
  5599. } else {
  5600. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5601. fmt.Println(err)
  5602. }
  5603. }
  5604. c.ServeSuccessJSON(map[string]interface{}{
  5605. "msg": "删除成功",
  5606. })
  5607. return
  5608. }
  5609. func (c *HisApiController) CreateHisAdditionalCharge() {
  5610. his_patient_id, _ := c.GetInt64("his_patient_id")
  5611. patient_id, _ := c.GetInt64("patient_id")
  5612. record_date := c.GetString("record_date")
  5613. timeLayout := "2006-01-02"
  5614. loc, _ := time.LoadLocation("Local")
  5615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5616. if err != nil {
  5617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. return
  5619. }
  5620. adminInfo := c.GetAdminUserInfo()
  5621. recordDateTime := theTime.Unix()
  5622. dataBody := make(map[string]interface{}, 0)
  5623. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5624. if err != nil {
  5625. utils.ErrorLog(err.Error())
  5626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5627. return
  5628. }
  5629. var additions []*models.HisAdditionalCharge
  5630. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5631. additions, _ := dataBody["addition"].([]interface{})
  5632. if len(additions) > 0 {
  5633. for _, item := range additions {
  5634. items := item.(map[string]interface{})
  5635. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5636. utils.ErrorLog("item_id")
  5637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5638. return
  5639. }
  5640. item_id := int64(items["item_id"].(float64))
  5641. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5642. utils.ErrorLog("item_name")
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5644. return
  5645. }
  5646. item_name := items["item_name"].(string)
  5647. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5648. utils.ErrorLog("price")
  5649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5650. return
  5651. }
  5652. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5653. ctime := time.Now().Unix()
  5654. additional := &models.HisAdditionalCharge{
  5655. PatientId: patient_id,
  5656. HisPatientId: his_patient_id,
  5657. UserOrgId: adminInfo.CurrentOrgId,
  5658. RecordDate: recordDateTime,
  5659. CreatedTime: ctime,
  5660. UpdatedTime: ctime,
  5661. Modifier: adminInfo.AdminUser.Id,
  5662. Creator: adminInfo.AdminUser.Id,
  5663. Price: price,
  5664. ItemName: item_name,
  5665. ItemId: item_id,
  5666. Status: 1,
  5667. }
  5668. additions = append(additions, additional)
  5669. }
  5670. }
  5671. }
  5672. for _, item := range additions {
  5673. service.CreateAddtionalCharge(item)
  5674. }
  5675. c.ServeSuccessJSON(map[string]interface{}{
  5676. "msg": "创建成功",
  5677. })
  5678. }
  5679. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5680. blood_fat := c.GetString("blood_fat")
  5681. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5682. blood_sugar := c.GetString("blood_sugar")
  5683. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5684. chief_conplaint := c.GetString("chief_conplaint")
  5685. dbp := c.GetString("dbp")
  5686. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5687. delivery_way, _ := c.GetInt64("delivery_way")
  5688. diagnostic := c.GetString("diagnostic")
  5689. family_history := c.GetString("family_history")
  5690. height := c.GetString("height")
  5691. history_of_present_illness := c.GetString("history_of_present_illness")
  5692. is_infect, _ := c.GetInt64("is_infect")
  5693. past_history := c.GetString("past_history")
  5694. patient_id, _ := c.GetInt64("patient_id")
  5695. his_patient_id, _ := c.GetInt64("his_patient_id")
  5696. personal_history := c.GetString("personal_history")
  5697. pulse := c.GetString("pulse")
  5698. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5699. sbp := c.GetString("sbp")
  5700. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5701. heightfloat, _ := strconv.ParseFloat(height, 64)
  5702. sicktype := c.GetString("sick_type")
  5703. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5704. symptom := c.GetString("symptom")
  5705. sick_date := c.GetString("sick_date")
  5706. temperatures := c.GetString("temperature")
  5707. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5708. record_date := c.GetString("record_date")
  5709. breathing := c.GetString("breathing")
  5710. doctor_advice := c.GetString("doctor_advice")
  5711. remark := c.GetString("remark")
  5712. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5713. sick, _ := c.GetInt64("sick")
  5714. diagnose, _ := c.GetInt64("diagnose")
  5715. //id, _ := c.GetInt64("id")
  5716. timeLayout := "2006-01-02"
  5717. loc, _ := time.LoadLocation("Local")
  5718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5719. allergic_history := c.GetString("allergic_history")
  5720. if err != nil {
  5721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5722. return
  5723. }
  5724. recordDateTime := theTime.Unix()
  5725. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5726. if err != nil {
  5727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5728. return
  5729. }
  5730. sickTimes := sickTime.Unix()
  5731. ctime := time.Now().Unix()
  5732. primary_disease := c.GetString("primary_disease")
  5733. confirm_failure_date := c.GetString("confirm_failure_date")
  5734. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5735. drug_allergy_history := c.GetString("drug_allergy_history")
  5736. physical_examination := c.GetString("physical_examination")
  5737. special_inspection := c.GetString("special_inspection")
  5738. lab_apparatus := c.GetString("lab_apparatus")
  5739. caseHistory := models.HisPatientCaseHistory{
  5740. HisPatientId: his_patient_id,
  5741. PatientId: patient_id,
  5742. Temperature: temperature,
  5743. BloodSugar: bloodsugarfloat,
  5744. Pulse: pulsefloat,
  5745. Sbp: sbpfloat,
  5746. Dbp: dbpfloat,
  5747. Height: heightfloat,
  5748. BloodFat: bloodfatfloat,
  5749. SickType: sick_type,
  5750. Symptom: symptom,
  5751. SickDate: sickTimes,
  5752. IsInfect: is_infect,
  5753. HistoryOfPresentIllness: history_of_present_illness,
  5754. PastHistory: past_history,
  5755. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5756. ChiefConplaint: chief_conplaint,
  5757. PersonalHistory: personal_history,
  5758. FamilyHistory: family_history,
  5759. Diagnostic: diagnostic,
  5760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5761. Status: 1,
  5762. Ctime: ctime,
  5763. Mtime: ctime,
  5764. RecordDate: recordDateTime,
  5765. DeliveryWay: delivery_way,
  5766. Breathing: breathingfloat,
  5767. DoctorAdvice: doctor_advice,
  5768. Remark: remark,
  5769. Sick: sick,
  5770. Diagnose: diagnose,
  5771. AllergicHistory: allergic_history,
  5772. PrimaryDisease: primary_disease,
  5773. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5774. DrugAllergyHistory: drug_allergy_history,
  5775. PhysicalExamination: physical_examination,
  5776. SpecialInspection: special_inspection,
  5777. LabApparatus: lab_apparatus,
  5778. }
  5779. //查询该患者是否有病历
  5780. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5781. if errcodes == gorm.ErrRecordNotFound {
  5782. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5783. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5784. if err != nil {
  5785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5786. return
  5787. }
  5788. c.ServeSuccessJSON(map[string]interface{}{
  5789. "caseHistory": caseHistory,
  5790. "historyInfo": historyInfo,
  5791. })
  5792. return
  5793. } else if errcodes == nil {
  5794. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5795. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5796. if err != nil {
  5797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5798. return
  5799. }
  5800. c.ServeSuccessJSON(map[string]interface{}{
  5801. "caseHistory": caseHistory,
  5802. "historyInfo": historyInfo,
  5803. })
  5804. }
  5805. //查询该患者是否有病历
  5806. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5807. //if errcode == gorm.ErrRecordNotFound {
  5808. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5809. // if err != nil {
  5810. // c.ServeSuccessJSON(map[string]interface{}{
  5811. // "msg": "保存成功",
  5812. // })
  5813. // }
  5814. //} else if errcode == nil {
  5815. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5816. // return
  5817. //}
  5818. }
  5819. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5820. patient_id, _ := c.GetInt64("patient_id", 0)
  5821. adminUser := c.GetAdminUserInfo()
  5822. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5823. c.ServeSuccessJSON(map[string]interface{}{
  5824. "list": caseHistorys,
  5825. })
  5826. }
  5827. func (c *HisApiController) GetHisPatientCaseHistory() {
  5828. record_date, _ := c.GetInt64("record_date", 0)
  5829. patient_id, _ := c.GetInt64("patient_id", 0)
  5830. admin := c.GetAdminUserInfo()
  5831. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5832. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5833. c.ServeSuccessJSON(map[string]interface{}{
  5834. "info": info,
  5835. "case_history": case_history,
  5836. })
  5837. }
  5838. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5839. template_name := c.GetString("template_name")
  5840. template_remark := c.GetString("template_remark")
  5841. doctor := c.GetAdminUserInfo().AdminUser.Id
  5842. diagnostic := c.GetString("diagnostic")
  5843. chief_conplaint := c.GetString("chief_conplain")
  5844. history_of_present_illness := c.GetString("history_of_present_illness")
  5845. past_history := c.GetString("past_history")
  5846. personal_history := c.GetString("personal_history")
  5847. family_history := c.GetString("family_history")
  5848. user_name := c.GetString("user_name")
  5849. doctor_advice := c.GetString("doctor_advice")
  5850. remark := c.GetString("remark")
  5851. //record_date := c.GetString("record_date")
  5852. //fmt.Println("record_date--------",record_date)
  5853. //timeLayout := "2006-01-02"
  5854. //loc, _ := time.LoadLocation("Local")
  5855. //
  5856. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5857. //if err != nil {
  5858. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5859. // return
  5860. //}
  5861. //recordDateTime := theTime.Unix()
  5862. ctime := time.Now().Unix()
  5863. template := models.HisCaseHistoryTemplate{
  5864. HistoryOfPresentIllness: history_of_present_illness,
  5865. PastHistory: past_history,
  5866. ChiefConplaint: chief_conplaint,
  5867. PersonalHistory: personal_history,
  5868. FamilyHistory: family_history,
  5869. Diagnostic: diagnostic,
  5870. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5871. Status: 1,
  5872. Ctime: ctime,
  5873. Mtime: ctime,
  5874. RecordDate: time.Now().Unix(),
  5875. TemplateName: template_name,
  5876. TemplateRemark: template_remark,
  5877. Creator: doctor,
  5878. Modifier: doctor,
  5879. UserName: user_name,
  5880. DoctorAdvice: doctor_advice,
  5881. Remark: remark,
  5882. }
  5883. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5884. if err == nil {
  5885. c.ServeSuccessJSON(map[string]interface{}{
  5886. "msg": "保存成功",
  5887. })
  5888. } else {
  5889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5890. return
  5891. }
  5892. }
  5893. func (c *HisApiController) GetCaseHistoryTemplate() {
  5894. timeLayout := "2006-01-02"
  5895. loc, _ := time.LoadLocation("Local")
  5896. keyword := c.GetString("keyword")
  5897. start_time := c.GetString("start_time")
  5898. end_time := c.GetString("end_time")
  5899. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5900. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5901. admin := c.GetAdminUserInfo()
  5902. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5903. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5904. c.ServeSuccessJSON(map[string]interface{}{
  5905. "template": template,
  5906. //"history": history,
  5907. })
  5908. }
  5909. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5910. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5911. utils.ErrorLog("drug_name")
  5912. return enums.ErrorCodeParamWrong
  5913. }
  5914. adviceName, _ := json["drug_name"].(string)
  5915. if len(adviceName) == 0 {
  5916. utils.ErrorLog("len(advice_name) == 0")
  5917. return enums.ErrorCodeParamWrong
  5918. }
  5919. advice.AdviceName = adviceName
  5920. adviceDesc, _ := json["advice_desc"].(string)
  5921. advice.AdviceDesc = adviceDesc
  5922. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5923. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5924. advice.DrugSpec = drugSpec
  5925. }
  5926. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5927. remark, _ := json["remark"].(string)
  5928. advice.Remark = remark
  5929. }
  5930. if json["id"] == nil {
  5931. advice.DrugId = 0
  5932. } else {
  5933. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5934. drug_id := int64(json["id"].(float64))
  5935. advice.DrugId = drug_id
  5936. }
  5937. }
  5938. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5939. advice_id := int64(json["advice_id"].(float64))
  5940. advice.ID = advice_id
  5941. if advice.ID > 0 {
  5942. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5943. if err == nil {
  5944. if hisAdvice.ID > 0 {
  5945. advice.ExecutionTime = hisAdvice.ExecutionTime
  5946. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5947. advice.ExecutionState = hisAdvice.ExecutionState
  5948. advice.CheckTime = hisAdvice.CheckTime
  5949. advice.Checker = hisAdvice.Checker
  5950. advice.CheckState = hisAdvice.CheckState
  5951. advice.StartTime = hisAdvice.StartTime
  5952. advice.FeedetlSn = hisAdvice.FeedetlSn
  5953. }
  5954. }
  5955. }
  5956. }
  5957. //
  5958. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5959. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5960. // advice.ExecutionTime = execution_time
  5961. //}
  5962. //
  5963. //
  5964. //
  5965. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5966. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5967. // advice.ExecutionStaff = execution_staff
  5968. //}
  5969. //
  5970. //
  5971. //
  5972. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5973. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5974. // advice.ExecutionState = execution_state
  5975. //}
  5976. //
  5977. //
  5978. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5979. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5980. // advice.CheckTime = check_time
  5981. //}
  5982. //
  5983. //
  5984. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5985. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5986. // advice.CheckState = check_state
  5987. //}
  5988. //
  5989. //
  5990. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5991. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5992. // advice.Checker = checker
  5993. //}
  5994. //
  5995. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5996. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5997. // advice.StartTime = start_time
  5998. //}
  5999. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6000. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6001. advice.IsSelfDrug = is_self_drug
  6002. }
  6003. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6004. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6005. drug_way_count, _ := json["drug_way_count"].(string)
  6006. advice.DrugWayCount = drug_way_count
  6007. }
  6008. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6009. drugSpecUnit, _ := json["min_unit"].(string)
  6010. advice.DrugSpecUnit = drugSpecUnit
  6011. }
  6012. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6013. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6014. advice.SingleDose = singleDose
  6015. }
  6016. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6017. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6018. advice.SingleDoseUnit = singleDoseUnit
  6019. }
  6020. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6021. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6022. advice.PrescribingNumber = prescribingNumber
  6023. }
  6024. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6025. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6026. advice.PrescribingNumberUnit = prescribingNumberUnit
  6027. }
  6028. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6029. deliveryWay, _ := json["delivery_way"].(string)
  6030. advice.DeliveryWay = deliveryWay
  6031. }
  6032. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6033. executionFrequency, _ := json["execution_frequency"].(string)
  6034. advice.ExecutionFrequency = executionFrequency
  6035. }
  6036. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6037. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6038. advice.Price = price
  6039. }
  6040. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6041. med_list_codg, _ := json["medical_insurance_number"].(string)
  6042. advice.MedListCodg = med_list_codg
  6043. }
  6044. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6045. day := int64(json["day"].(float64))
  6046. advice.Day = day
  6047. }
  6048. return 0
  6049. }
  6050. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6051. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6052. id := int64(json["id"].(float64))
  6053. project.ID = id
  6054. historyProject, _ := service.GetHisProjectByID(id)
  6055. project.FeedetlSn = historyProject.FeedetlSn
  6056. }
  6057. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6058. project_id := int64(json["project_id"].(float64))
  6059. project.ProjectId = project_id
  6060. }
  6061. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6062. // price := int64(json["price"].(float64))
  6063. // formatInt_price := strconv.FormatInt(price, 10)
  6064. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6065. // project.Price = float_price
  6066. // }
  6067. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6068. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6069. project.Price = price
  6070. }
  6071. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6072. total, _ := json["total"].(string)
  6073. project.Count = total
  6074. }
  6075. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6076. medical_code, _ := json["medical_code"].(string)
  6077. project.MedListCodg = medical_code
  6078. }
  6079. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6080. single_dose, _ := json["single_dose"].(string)
  6081. project.SingleDose = single_dose
  6082. }
  6083. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6084. delivery_way, _ := json["delivery_way"].(string)
  6085. project.DeliveryWay = delivery_way
  6086. }
  6087. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6088. execution_frequency, _ := json["execution_frequency"].(string)
  6089. project.ExecutionFrequency = execution_frequency
  6090. }
  6091. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6092. remark, _ := json["remark"].(string)
  6093. project.Remark = remark
  6094. }
  6095. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6096. day, _ := json["number_days"].(string)
  6097. project.Day = day
  6098. }
  6099. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6100. unit, _ := json["unit"].(string)
  6101. project.Unit = unit
  6102. }
  6103. return 0
  6104. }
  6105. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6106. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6107. id := int64(json["id"].(float64))
  6108. historyAddtions, _ := service.GetHisAdditionByID(id)
  6109. additionalCharge.ID = id
  6110. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6111. }
  6112. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6113. item_id := int64(json["item_id"].(float64))
  6114. additionalCharge.ItemId = item_id
  6115. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6116. if config.ID > 0 {
  6117. if len(config.Code) > 0 {
  6118. additionalCharge.MedListCodg = config.Code
  6119. }
  6120. }
  6121. }
  6122. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6123. // price := int64(json["price"].(float64))
  6124. // formatInt_price := strconv.FormatInt(price, 10)
  6125. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6126. // additionalCharge.Price = float_price
  6127. // }
  6128. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6129. // price := int64(json["price"].(float64))
  6130. // formatInt_price := strconv.FormatInt(price, 10)
  6131. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6132. // additionalCharge.Price = float_price
  6133. //}
  6134. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6135. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6136. additionalCharge.Price = price
  6137. }
  6138. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6139. count, _ := json["count"].(string)
  6140. counts, _ := strconv.ParseInt(count, 10, 64)
  6141. additionalCharge.Count = counts
  6142. }
  6143. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6144. item_name, _ := json["item_name"].(string)
  6145. additionalCharge.ItemName = item_name
  6146. }
  6147. return 0
  6148. }
  6149. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6150. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6151. utils.ErrorLog("drug_name")
  6152. return enums.ErrorCodeParamWrong
  6153. }
  6154. adviceName, _ := json["drug_name"].(string)
  6155. if len(adviceName) == 0 {
  6156. utils.ErrorLog("len(advice_name) == 0")
  6157. return enums.ErrorCodeParamWrong
  6158. }
  6159. advice.AdviceName = adviceName
  6160. adviceDesc, _ := json["advice_desc"].(string)
  6161. advice.AdviceDesc = adviceDesc
  6162. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6163. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6164. advice.DrugSpec = drugSpec
  6165. }
  6166. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6167. remark, _ := json["remark"].(string)
  6168. advice.Remark = remark
  6169. }
  6170. if json["id"] == nil {
  6171. advice.DrugId = 0
  6172. } else {
  6173. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6174. drug_id := int64(json["id"].(float64))
  6175. advice.DrugId = drug_id
  6176. }
  6177. }
  6178. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6179. groupno := int64(json["groupno"].(float64))
  6180. advice.Groupno = groupno
  6181. }
  6182. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6183. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6184. advice.IsSelfDrug = is_self_drug
  6185. }
  6186. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6187. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6188. drug_way_count, _ := json["drug_way_count"].(string)
  6189. advice.DrugWayCount = drug_way_count
  6190. }
  6191. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6192. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6193. advice.HospApprFlag = hosp_appr_flag
  6194. }
  6195. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6196. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6197. advice.PrescribingNumber = prescribingNumber
  6198. }
  6199. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6200. // frequency_type := int64(json["frequency_type"].(float64))
  6201. // advice.FrequencyType = frequency_type
  6202. //}
  6203. //
  6204. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6205. // day_count := int64(json["day_count"].(float64))
  6206. // advice.DayCount = day_count
  6207. //}
  6208. //
  6209. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6210. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6211. // week_day, _ := json["week_day"].(string)
  6212. // advice.WeekDay = week_day
  6213. //}
  6214. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6215. drugSpecUnit, _ := json["min_unit"].(string)
  6216. advice.DrugSpecUnit = drugSpecUnit
  6217. }
  6218. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6219. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6220. advice.SingleDose = singleDose
  6221. }
  6222. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6223. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6224. advice.SingleDoseUnit = singleDoseUnit
  6225. }
  6226. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6227. deliveryWay, _ := json["delivery_way"].(string)
  6228. advice.DeliveryWay = deliveryWay
  6229. }
  6230. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6231. executionFrequency, _ := json["execution_frequency"].(string)
  6232. advice.ExecutionFrequency = executionFrequency
  6233. }
  6234. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6235. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6236. advice.Price = price
  6237. }
  6238. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6239. med_list_codg, _ := json["medical_insurance_number"].(string)
  6240. advice.MedListCodg = med_list_codg
  6241. }
  6242. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6243. day := int64(json["day"].(float64))
  6244. advice.Day = day
  6245. }
  6246. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6247. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6248. advice.PrescribingNumberUnit = prescribingNumberUnit
  6249. }
  6250. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6251. advice_id := int64(json["advice_id"].(float64))
  6252. advice.ID = advice_id
  6253. if advice.ID > 0 {
  6254. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6255. if err == nil {
  6256. if hisAdvice.ID > 0 {
  6257. advice.ExecutionTime = hisAdvice.ExecutionTime
  6258. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6259. advice.ExecutionState = hisAdvice.ExecutionState
  6260. advice.CheckTime = hisAdvice.CheckTime
  6261. advice.Checker = hisAdvice.Checker
  6262. advice.CheckState = hisAdvice.CheckState
  6263. advice.StartTime = hisAdvice.StartTime
  6264. advice.HospApprFlag = hisAdvice.HospApprFlag
  6265. advice.IsMedicine = hisAdvice.IsMedicine
  6266. if hisAdvice.UserOrgId == 10028 {
  6267. 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 {
  6268. advice.ExecutionTime = 0
  6269. advice.ExecutionStaff = 0
  6270. advice.ExecutionState = 2
  6271. advice.CheckTime = 0
  6272. advice.Checker = 0
  6273. advice.CheckState = 2
  6274. }
  6275. } else {
  6276. 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 {
  6277. advice.ExecutionTime = 0
  6278. advice.ExecutionStaff = 0
  6279. advice.ExecutionState = 2
  6280. advice.CheckTime = 0
  6281. advice.Checker = 0
  6282. advice.CheckState = 2
  6283. }
  6284. }
  6285. //advice.Groupno = hisAdvice.Groupno
  6286. }
  6287. }
  6288. }
  6289. }
  6290. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6291. //
  6292. //if drugStockConfig.IsOpen == 1 {
  6293. //
  6294. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6295. // if advice.ID == 0 { //医嘱不存在
  6296. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6297. // drug.Total = drug.Total - advice.PrescribingNumber
  6298. // service.UpdateBaseDrugLib(&drug)
  6299. //
  6300. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6301. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6302. // drug.Total = drug.Total - num
  6303. // service.UpdateBaseDrugLib(&drug)
  6304. // }
  6305. //
  6306. // } else if advice.ID > 0 { //医嘱存在
  6307. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6308. // var num float64
  6309. //
  6310. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6311. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6312. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6313. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6314. // drug.Total = drug.Total + num
  6315. // service.UpdateBaseDrugLib(&drug)
  6316. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6317. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6318. // drug.Total = drug.Total - num
  6319. // service.UpdateBaseDrugLib(&drug)
  6320. // }
  6321. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6322. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6323. // if num2 > advice.PrescribingNumber {
  6324. // num = num2 - advice.PrescribingNumber
  6325. // drug.Total = drug.Total + num
  6326. // service.UpdateBaseDrugLib(&drug)
  6327. // } else if num2 < advice.PrescribingNumber {
  6328. // num = advice.PrescribingNumber - num2
  6329. // drug.Total = drug.Total - num
  6330. // service.UpdateBaseDrugLib(&drug)
  6331. // }
  6332. //
  6333. // }
  6334. //
  6335. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6336. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6337. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6338. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6339. // if num1 > num2 {
  6340. // num = num1 - num2
  6341. // drug.Total = drug.Total + num
  6342. // service.UpdateBaseDrugLib(&drug)
  6343. // } else if num1 < num2 {
  6344. // num = num2 - num1
  6345. // drug.Total = drug.Total - num
  6346. // service.UpdateBaseDrugLib(&drug)
  6347. // }
  6348. //
  6349. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6350. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6351. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6352. // if hisAdvice.PrescribingNumber > num2 {
  6353. // num = hisAdvice.PrescribingNumber - num2
  6354. // drug.Total = drug.Total + num
  6355. // service.UpdateBaseDrugLib(&drug)
  6356. // } else if num2 < advice.PrescribingNumber {
  6357. // num = num2 - hisAdvice.PrescribingNumber
  6358. // drug.Total = drug.Total - num
  6359. // service.UpdateBaseDrugLib(&drug)
  6360. // }
  6361. //
  6362. // }
  6363. // }
  6364. // }
  6365. //}
  6366. //
  6367. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6368. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6369. // advice.ExecutionTime = execution_time
  6370. //}
  6371. //
  6372. //
  6373. //
  6374. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6375. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6376. // advice.ExecutionStaff = execution_staff
  6377. //}
  6378. //
  6379. //
  6380. //
  6381. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6382. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6383. // advice.ExecutionState = execution_state
  6384. //}
  6385. //
  6386. //
  6387. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6388. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6389. // advice.CheckTime = check_time
  6390. //}
  6391. //
  6392. //
  6393. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6394. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6395. // advice.CheckState = check_state
  6396. //}
  6397. //
  6398. //
  6399. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6400. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6401. // advice.Checker = checker
  6402. //}
  6403. //
  6404. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6405. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6406. // advice.StartTime = start_time
  6407. //}
  6408. return 0
  6409. }
  6410. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6411. project.ExecutionStaff = 0
  6412. project.ExecutionState = 2
  6413. project.ExecutionTime = 0
  6414. project.Checker = 0
  6415. project.CheckState = 2
  6416. project.CheckTime = 0
  6417. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6418. id := int64(json["id"].(float64))
  6419. project.ID = id
  6420. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6421. project.ExecutionStaff = temp_project.ExecutionStaff
  6422. project.ExecutionState = temp_project.ExecutionState
  6423. project.ExecutionTime = temp_project.ExecutionTime
  6424. project.Checker = temp_project.Checker
  6425. project.CheckState = temp_project.CheckState
  6426. project.CheckTime = temp_project.CheckTime
  6427. project.TeamId = temp_project.TeamId
  6428. }
  6429. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6430. types := int64(json["type"].(float64))
  6431. project.Type = types
  6432. }
  6433. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6434. project_id := int64(json["project_id"].(float64))
  6435. project.ProjectId = project_id
  6436. }
  6437. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6438. team_id := int64(json["team_id"].(float64))
  6439. project.TeamId = team_id
  6440. }
  6441. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6442. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6443. project.Price = price
  6444. }
  6445. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6446. total, _ := json["total"].(string)
  6447. //totals, _ := strconv.ParseInt(total, 10, 64)
  6448. project.Count = total
  6449. }
  6450. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6451. medical_code, _ := json["medical_code"].(string)
  6452. project.MedListCodg = medical_code
  6453. }
  6454. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6455. single_dose, _ := json["single_dose"].(string)
  6456. project.SingleDose = single_dose
  6457. }
  6458. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6459. delivery_way, _ := json["delivery_way"].(string)
  6460. project.DeliveryWay = delivery_way
  6461. }
  6462. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6463. execution_frequency, _ := json["execution_frequency"].(string)
  6464. project.ExecutionFrequency = execution_frequency
  6465. }
  6466. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6467. remark, _ := json["remark"].(string)
  6468. project.Remark = remark
  6469. }
  6470. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6471. day, _ := json["number_days"].(string)
  6472. project.Day = day
  6473. }
  6474. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6475. unit, _ := json["unit"].(string)
  6476. project.Unit = unit
  6477. }
  6478. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6479. // frequency_type := int64(json["frequency_type"].(float64))
  6480. // project.FrequencyType = frequency_type
  6481. //}
  6482. //
  6483. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6484. // day_count := int64(json["day_count"].(float64))
  6485. // project.DayCount = day_count
  6486. //}
  6487. //
  6488. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6489. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6490. // week_day, _ := json["week_day"].(string)
  6491. // project.WeekDay = week_day
  6492. //}
  6493. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6494. //
  6495. //if project.ID == 0 {
  6496. // if stockConfig.IsOpen == 1 {
  6497. // if project.Type == 3 {
  6498. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6499. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6500. // good.Total = good.Total - f_count
  6501. // service.UpdateGoodInfo(&good)
  6502. // }
  6503. // }
  6504. //
  6505. //} else {
  6506. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6507. //
  6508. // if stockConfig.IsOpen == 1 {
  6509. // if project.Type == 3 {
  6510. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6511. // if project.Count < temp_project.Count {
  6512. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6513. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6514. //
  6515. // other_count := f_count_two - f_count_one
  6516. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6517. // good.Total = good.Total + other_count_two
  6518. // service.UpdateGoodInfo(&good)
  6519. // } else if project.Count > temp_project.Count {
  6520. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6521. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6522. //
  6523. // other_count := f_count_one - f_count_two
  6524. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6525. // good.Total = good.Total - other_count_two
  6526. // service.UpdateGoodInfo(&good)
  6527. // }
  6528. //
  6529. // }
  6530. // }
  6531. //
  6532. //}
  6533. return 0
  6534. }
  6535. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6536. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6537. utils.ErrorLog("drug_name")
  6538. return enums.ErrorCodeParamWrong
  6539. }
  6540. adviceName, _ := json["drug_name"].(string)
  6541. if len(adviceName) == 0 {
  6542. utils.ErrorLog("len(advice_name) == 0")
  6543. return enums.ErrorCodeParamWrong
  6544. }
  6545. advice.AdviceName = adviceName
  6546. adviceDesc, _ := json["advice_desc"].(string)
  6547. advice.AdviceDesc = adviceDesc
  6548. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6549. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6550. advice.DrugSpec = drugSpec
  6551. }
  6552. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6553. remark, _ := json["remark"].(string)
  6554. advice.Remark = remark
  6555. }
  6556. if json["id"] == nil {
  6557. advice.DrugId = 0
  6558. } else {
  6559. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6560. drug_id := int64(json["id"].(float64))
  6561. advice.DrugId = drug_id
  6562. }
  6563. }
  6564. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6565. groupno := int64(json["groupno"].(float64))
  6566. advice.Groupno = groupno
  6567. }
  6568. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6569. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6570. advice.IsSelfDrug = is_self_drug
  6571. }
  6572. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6573. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6574. drug_way_count, _ := json["drug_way_count"].(string)
  6575. advice.DrugWayCount = drug_way_count
  6576. }
  6577. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6578. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6579. advice.HospApprFlag = hosp_appr_flag
  6580. }
  6581. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6582. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6583. advice.PrescribingNumber = prescribingNumber
  6584. }
  6585. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6586. // frequency_type := int64(json["frequency_type"].(float64))
  6587. // advice.FrequencyType = frequency_type
  6588. //}
  6589. //
  6590. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6591. // day_count := int64(json["day_count"].(float64))
  6592. // advice.DayCount = day_count
  6593. //}
  6594. //
  6595. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6596. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6597. // week_day, _ := json["week_day"].(string)
  6598. // advice.WeekDay = week_day
  6599. //}
  6600. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6601. drugSpecUnit, _ := json["min_unit"].(string)
  6602. advice.DrugSpecUnit = drugSpecUnit
  6603. }
  6604. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6605. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6606. advice.SingleDose = singleDose
  6607. }
  6608. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6609. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6610. advice.SingleDoseUnit = singleDoseUnit
  6611. }
  6612. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6613. deliveryWay, _ := json["delivery_way"].(string)
  6614. advice.DeliveryWay = deliveryWay
  6615. }
  6616. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6617. executionFrequency, _ := json["execution_frequency"].(string)
  6618. advice.ExecutionFrequency = executionFrequency
  6619. }
  6620. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6621. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6622. advice.Price = price
  6623. }
  6624. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6625. med_list_codg, _ := json["medical_insurance_number"].(string)
  6626. advice.MedListCodg = med_list_codg
  6627. }
  6628. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6629. day := int64(json["day"].(float64))
  6630. advice.Day = day
  6631. }
  6632. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6633. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6634. advice.PrescribingNumberUnit = prescribingNumberUnit
  6635. }
  6636. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6637. advice_id := int64(json["advice_id"].(float64))
  6638. advice.ID = advice_id
  6639. if advice.ID > 0 {
  6640. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6641. if err == nil {
  6642. if hisAdvice.ID > 0 {
  6643. advice.ExecutionTime = hisAdvice.ExecutionTime
  6644. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6645. advice.ExecutionState = hisAdvice.ExecutionState
  6646. advice.CheckTime = hisAdvice.CheckTime
  6647. advice.Checker = hisAdvice.Checker
  6648. advice.CheckState = hisAdvice.CheckState
  6649. advice.StartTime = hisAdvice.StartTime
  6650. advice.HospApprFlag = hisAdvice.HospApprFlag
  6651. advice.IsMedicine = hisAdvice.IsMedicine
  6652. if hisAdvice.UserOrgId == 10028 {
  6653. 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 {
  6654. advice.ExecutionTime = 0
  6655. advice.ExecutionStaff = 0
  6656. advice.ExecutionState = 2
  6657. advice.CheckTime = 0
  6658. advice.Checker = 0
  6659. advice.CheckState = 2
  6660. }
  6661. } else {
  6662. 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 {
  6663. advice.ExecutionTime = 0
  6664. advice.ExecutionStaff = 0
  6665. advice.ExecutionState = 2
  6666. advice.CheckTime = 0
  6667. advice.Checker = 0
  6668. advice.CheckState = 2
  6669. }
  6670. }
  6671. //advice.Groupno = hisAdvice.Groupno
  6672. }
  6673. }
  6674. }
  6675. }
  6676. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6677. //
  6678. //if drugStockConfig.IsOpen == 1 {
  6679. //
  6680. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6681. // if advice.ID == 0 { //医嘱不存在
  6682. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6683. // drug.Total = drug.Total - advice.PrescribingNumber
  6684. // service.UpdateBaseDrugLib(&drug)
  6685. //
  6686. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6687. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6688. // drug.Total = drug.Total - num
  6689. // service.UpdateBaseDrugLib(&drug)
  6690. // }
  6691. //
  6692. // } else if advice.ID > 0 { //医嘱存在
  6693. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6694. // var num float64
  6695. //
  6696. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6697. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6698. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6699. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6700. // drug.Total = drug.Total + num
  6701. // service.UpdateBaseDrugLib(&drug)
  6702. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6703. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6704. // drug.Total = drug.Total - num
  6705. // service.UpdateBaseDrugLib(&drug)
  6706. // }
  6707. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6708. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6709. // if num2 > advice.PrescribingNumber {
  6710. // num = num2 - advice.PrescribingNumber
  6711. // drug.Total = drug.Total + num
  6712. // service.UpdateBaseDrugLib(&drug)
  6713. // } else if num2 < advice.PrescribingNumber {
  6714. // num = advice.PrescribingNumber - num2
  6715. // drug.Total = drug.Total - num
  6716. // service.UpdateBaseDrugLib(&drug)
  6717. // }
  6718. //
  6719. // }
  6720. //
  6721. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6722. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6723. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6724. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6725. // if num1 > num2 {
  6726. // num = num1 - num2
  6727. // drug.Total = drug.Total + num
  6728. // service.UpdateBaseDrugLib(&drug)
  6729. // } else if num1 < num2 {
  6730. // num = num2 - num1
  6731. // drug.Total = drug.Total - num
  6732. // service.UpdateBaseDrugLib(&drug)
  6733. // }
  6734. //
  6735. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6736. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6737. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6738. // if hisAdvice.PrescribingNumber > num2 {
  6739. // num = hisAdvice.PrescribingNumber - num2
  6740. // drug.Total = drug.Total + num
  6741. // service.UpdateBaseDrugLib(&drug)
  6742. // } else if num2 < advice.PrescribingNumber {
  6743. // num = num2 - hisAdvice.PrescribingNumber
  6744. // drug.Total = drug.Total - num
  6745. // service.UpdateBaseDrugLib(&drug)
  6746. // }
  6747. //
  6748. // }
  6749. // }
  6750. // }
  6751. //}
  6752. //
  6753. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6754. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6755. // advice.ExecutionTime = execution_time
  6756. //}
  6757. //
  6758. //
  6759. //
  6760. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6761. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6762. // advice.ExecutionStaff = execution_staff
  6763. //}
  6764. //
  6765. //
  6766. //
  6767. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6768. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6769. // advice.ExecutionState = execution_state
  6770. //}
  6771. //
  6772. //
  6773. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6774. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6775. // advice.CheckTime = check_time
  6776. //}
  6777. //
  6778. //
  6779. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6780. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6781. // advice.CheckState = check_state
  6782. //}
  6783. //
  6784. //
  6785. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6786. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6787. // advice.Checker = checker
  6788. //}
  6789. //
  6790. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6791. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6792. // advice.StartTime = start_time
  6793. //}
  6794. return 0
  6795. }
  6796. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6797. project.ExecutionStaff = 0
  6798. project.ExecutionState = 2
  6799. project.ExecutionTime = 0
  6800. project.Checker = 0
  6801. project.CheckState = 2
  6802. project.CheckTime = 0
  6803. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6804. id := int64(json["id"].(float64))
  6805. project.ID = id
  6806. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6807. project.ExecutionStaff = temp_project.ExecutionStaff
  6808. project.ExecutionState = temp_project.ExecutionState
  6809. project.ExecutionTime = temp_project.ExecutionTime
  6810. project.Checker = temp_project.Checker
  6811. project.CheckState = temp_project.CheckState
  6812. project.CheckTime = temp_project.CheckTime
  6813. project.TeamId = temp_project.TeamId
  6814. }
  6815. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6816. types := int64(json["type"].(float64))
  6817. project.Type = types
  6818. }
  6819. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6820. project_id := int64(json["project_id"].(float64))
  6821. project.ProjectId = project_id
  6822. }
  6823. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6824. team_id := int64(json["team_id"].(float64))
  6825. project.TeamId = team_id
  6826. }
  6827. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6828. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6829. project.Price = price
  6830. }
  6831. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6832. total, _ := json["total"].(string)
  6833. //totals, _ := strconv.ParseInt(total, 10, 64)
  6834. project.Count = total
  6835. }
  6836. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6837. medical_code, _ := json["medical_code"].(string)
  6838. project.MedListCodg = medical_code
  6839. }
  6840. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6841. single_dose, _ := json["single_dose"].(string)
  6842. project.SingleDose = single_dose
  6843. }
  6844. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6845. delivery_way, _ := json["delivery_way"].(string)
  6846. project.DeliveryWay = delivery_way
  6847. }
  6848. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6849. execution_frequency, _ := json["execution_frequency"].(string)
  6850. project.ExecutionFrequency = execution_frequency
  6851. }
  6852. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6853. remark, _ := json["remark"].(string)
  6854. project.Remark = remark
  6855. }
  6856. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6857. day, _ := json["number_days"].(string)
  6858. project.Day = day
  6859. }
  6860. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6861. unit, _ := json["unit"].(string)
  6862. project.Unit = unit
  6863. }
  6864. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6865. // frequency_type := int64(json["frequency_type"].(float64))
  6866. // project.FrequencyType = frequency_type
  6867. //}
  6868. //
  6869. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6870. // day_count := int64(json["day_count"].(float64))
  6871. // project.DayCount = day_count
  6872. //}
  6873. //
  6874. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6875. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6876. // week_day, _ := json["week_day"].(string)
  6877. // project.WeekDay = week_day
  6878. //}
  6879. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6880. //
  6881. //if project.ID == 0 {
  6882. // if stockConfig.IsOpen == 1 {
  6883. // if project.Type == 3 {
  6884. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6885. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6886. // good.Total = good.Total - f_count
  6887. // service.UpdateGoodInfo(&good)
  6888. // }
  6889. // }
  6890. //
  6891. //} else {
  6892. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6893. //
  6894. // if stockConfig.IsOpen == 1 {
  6895. // if project.Type == 3 {
  6896. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6897. // if project.Count < temp_project.Count {
  6898. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6899. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6900. //
  6901. // other_count := f_count_two - f_count_one
  6902. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6903. // good.Total = good.Total + other_count_two
  6904. // service.UpdateGoodInfo(&good)
  6905. // } else if project.Count > temp_project.Count {
  6906. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6907. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6908. //
  6909. // other_count := f_count_one - f_count_two
  6910. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6911. // good.Total = good.Total - other_count_two
  6912. // service.UpdateGoodInfo(&good)
  6913. // }
  6914. //
  6915. // }
  6916. // }
  6917. //
  6918. //}
  6919. return 0
  6920. }
  6921. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6922. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6923. id := int64(json["id"].(float64))
  6924. additionalCharge.ID = id
  6925. }
  6926. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6927. item_id := int64(json["item_id"].(float64))
  6928. additionalCharge.ItemId = item_id
  6929. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6930. if config.ID > 0 {
  6931. if len(config.Code) > 0 {
  6932. additionalCharge.MedListCodg = config.Code
  6933. }
  6934. }
  6935. }
  6936. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6937. // price := int64(json["price"].(float64))
  6938. // formatInt_price := strconv.FormatInt(price, 10)
  6939. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6940. // additionalCharge.Price = float_price
  6941. // }
  6942. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6943. // price := int64(json["price"].(float64))
  6944. // formatInt_price := strconv.FormatInt(price, 10)
  6945. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6946. // additionalCharge.Price = float_price
  6947. //}
  6948. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6949. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6950. additionalCharge.Price = price
  6951. }
  6952. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6953. count, _ := json["count"].(string)
  6954. counts, _ := strconv.ParseInt(count, 10, 64)
  6955. additionalCharge.Count = counts
  6956. }
  6957. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6958. item_name, _ := json["item_name"].(string)
  6959. additionalCharge.ItemName = item_name
  6960. }
  6961. return 0
  6962. }
  6963. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6964. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6965. utils.ErrorLog("drug_name")
  6966. return enums.ErrorCodeParamWrong
  6967. }
  6968. adviceName, _ := json["drug_name"].(string)
  6969. if len(adviceName) == 0 {
  6970. utils.ErrorLog("len(advice_name) == 0")
  6971. return enums.ErrorCodeParamWrong
  6972. }
  6973. advice.AdviceName = adviceName
  6974. adviceDesc, _ := json["advice_desc"].(string)
  6975. advice.AdviceDesc = adviceDesc
  6976. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6977. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6978. advice.DrugSpec = drugSpec
  6979. }
  6980. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6981. remark, _ := json["remark"].(string)
  6982. advice.Remark = remark
  6983. }
  6984. if json["id"] == nil {
  6985. advice.DrugId = 0
  6986. } else {
  6987. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6988. drug_id := int64(json["id"].(float64))
  6989. advice.DrugId = drug_id
  6990. }
  6991. }
  6992. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6993. groupno := int64(json["groupno"].(float64))
  6994. advice.Groupno = groupno
  6995. }
  6996. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6997. drugSpecUnit, _ := json["min_unit"].(string)
  6998. advice.DrugSpecUnit = drugSpecUnit
  6999. }
  7000. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7001. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7002. advice.SingleDose = singleDose
  7003. }
  7004. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7005. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7006. advice.SingleDoseUnit = singleDoseUnit
  7007. }
  7008. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7009. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7010. advice.PrescribingNumber = prescribingNumber
  7011. }
  7012. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7013. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7014. advice.PrescribingNumberUnit = prescribingNumberUnit
  7015. }
  7016. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7017. deliveryWay, _ := json["delivery_way"].(string)
  7018. advice.DeliveryWay = deliveryWay
  7019. }
  7020. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7021. executionFrequency, _ := json["execution_frequency"].(string)
  7022. advice.ExecutionFrequency = executionFrequency
  7023. }
  7024. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7025. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7026. advice.Price = price
  7027. }
  7028. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7029. med_list_codg, _ := json["medical_insurance_number"].(string)
  7030. advice.MedListCodg = med_list_codg
  7031. }
  7032. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7033. day := int64(json["day"].(float64))
  7034. advice.Day = day
  7035. }
  7036. advice.FrequencyType = 1
  7037. return 0
  7038. }
  7039. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7040. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7041. types := int64(json["type"].(float64))
  7042. project.Type = types
  7043. }
  7044. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7045. project_id := int64(json["project_id"].(float64))
  7046. project.ProjectId = project_id
  7047. }
  7048. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7049. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7050. project.Price = price
  7051. }
  7052. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7053. total, _ := json["total"].(string)
  7054. //totals, _ := strconv.ParseInt(total, 10, 64)
  7055. project.Count = total
  7056. }
  7057. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7058. medical_code, _ := json["medical_code"].(string)
  7059. project.MedListCodg = medical_code
  7060. }
  7061. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7062. single_dose, _ := json["single_dose"].(string)
  7063. project.SingleDose = single_dose
  7064. }
  7065. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7066. delivery_way, _ := json["delivery_way"].(string)
  7067. project.DeliveryWay = delivery_way
  7068. }
  7069. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7070. execution_frequency, _ := json["execution_frequency"].(string)
  7071. project.ExecutionFrequency = execution_frequency
  7072. }
  7073. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7074. remark, _ := json["remark"].(string)
  7075. project.Remark = remark
  7076. }
  7077. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7078. day, _ := json["number_days"].(string)
  7079. project.Day = day
  7080. }
  7081. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7082. unit, _ := json["unit"].(string)
  7083. project.Unit = unit
  7084. }
  7085. project.FrequencyType = 1
  7086. return 0
  7087. }
  7088. func (c *HisApiController) GetHisOrderListTwo() {
  7089. start_time := c.GetString("start_time")
  7090. end_time := c.GetString("end_time")
  7091. timeLayout := "2006-01-02"
  7092. loc, _ := time.LoadLocation("Local")
  7093. var startTime int64
  7094. if len(start_time) > 0 {
  7095. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7096. if err != nil {
  7097. //fmt.Println(err)
  7098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7099. return
  7100. }
  7101. startTime = theTime.Unix()
  7102. }
  7103. var endTime int64
  7104. if len(end_time) > 0 {
  7105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7106. if err != nil {
  7107. utils.ErrorLog(err.Error())
  7108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7109. return
  7110. }
  7111. endTime = theTime.Unix()
  7112. }
  7113. adminUser := c.GetAdminUserInfo()
  7114. org_id := adminUser.CurrentOrgId
  7115. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7116. if err == nil {
  7117. c.ServeSuccessJSON(map[string]interface{}{
  7118. "order2": order,
  7119. })
  7120. } else {
  7121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7122. return
  7123. }
  7124. }
  7125. func (c *HisApiController) GetHisOrderList() {
  7126. page, _ := c.GetInt64("page", -1)
  7127. limit, _ := c.GetInt64("limit", -1)
  7128. start_time := c.GetString("start_time")
  7129. end_time := c.GetString("end_time")
  7130. types, _ := c.GetInt64("type", 0)
  7131. keywords := c.GetString("keywords")
  7132. p_type, _ := c.GetInt64("p_type", 0)
  7133. sort_type, _ := c.GetInt64("sort_type", 0)
  7134. charge_type, _ := c.GetInt64("charge_type", 0)
  7135. sch_type, _ := c.GetInt64("sch_type", 0)
  7136. zone_type, _ := c.GetInt64("zone_type", 0)
  7137. med_type, _ := c.GetInt64("med_type", 0)
  7138. timeLayout := "2006-01-02"
  7139. loc, _ := time.LoadLocation("Local")
  7140. var startTime int64
  7141. if len(start_time) > 0 {
  7142. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7143. if err != nil {
  7144. //fmt.Println(err)
  7145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7146. return
  7147. }
  7148. startTime = theTime.Unix()
  7149. }
  7150. var endTime int64
  7151. if len(end_time) > 0 {
  7152. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7153. if err != nil {
  7154. utils.ErrorLog(err.Error())
  7155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7156. return
  7157. }
  7158. endTime = theTime.Unix()
  7159. }
  7160. adminUser := c.GetAdminUserInfo()
  7161. org_id := adminUser.CurrentOrgId
  7162. 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)
  7163. for _, item := range order {
  7164. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7165. item.DoctorName = info.Doctor
  7166. item.DepartmentName = info.XtHisDepartment.Name
  7167. }
  7168. if err == nil {
  7169. c.ServeSuccessJSON(map[string]interface{}{
  7170. "order": order,
  7171. "total": total,
  7172. })
  7173. } else {
  7174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7175. return
  7176. }
  7177. }
  7178. func (c *HisApiController) GetHisOrder() {
  7179. patient_id, _ := c.GetInt64("patient_id", 0)
  7180. number := c.GetString("number")
  7181. adminInfo := c.GetAdminUserInfo()
  7182. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7183. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7184. if err == nil {
  7185. c.ServeSuccessJSON(map[string]interface{}{
  7186. "order": order,
  7187. "prescription": prescriptions,
  7188. })
  7189. } else {
  7190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7191. return
  7192. }
  7193. }
  7194. func (c *HisApiController) GetHisPrescriptionList() {
  7195. record_date := c.GetString("record_date")
  7196. keywords := c.GetString("keywords")
  7197. page, _ := c.GetInt64("page")
  7198. limit, _ := c.GetInt64("limit")
  7199. sch_type, _ := c.GetInt64("sch_type")
  7200. timeLayout := "2006-01-02"
  7201. loc, _ := time.LoadLocation("Local")
  7202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7203. if err != nil {
  7204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7205. return
  7206. }
  7207. recordDateTime := theTime.Unix()
  7208. adminInfo := c.GetAdminUserInfo()
  7209. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7210. //adminInfo := c.GetAdminUserInfo()
  7211. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7212. //fmt.Println(prescriptionOrder)
  7213. if err == nil {
  7214. c.ServeSuccessJSON(map[string]interface{}{
  7215. "order": prescriptionOrder,
  7216. "total": total,
  7217. })
  7218. } else {
  7219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7220. return
  7221. }
  7222. }
  7223. func (c *HisApiController) GetHisPrescriptionInfo() {
  7224. id, _ := c.GetInt64("id")
  7225. adminInfo := c.GetAdminUserInfo()
  7226. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7227. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7228. if err == nil {
  7229. c.ServeSuccessJSON(map[string]interface{}{
  7230. "order": prescriptionOrder,
  7231. "prescription": prescription,
  7232. })
  7233. } else {
  7234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7235. return
  7236. }
  7237. }
  7238. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7239. adminUser := c.GetAdminUserInfo()
  7240. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7241. c.ServeSuccessJSON(map[string]interface{}{
  7242. "config": config,
  7243. })
  7244. }
  7245. type ResultTwo struct {
  7246. ErrMsg interface{} `json:"err_msg"`
  7247. InfRefmsgid string `json:"inf_refmsgid"`
  7248. Infcode int64 `json:"infcode"`
  7249. Output struct {
  7250. Baseinfo struct {
  7251. Age float64 `json:"age"`
  7252. Brdy string `json:"brdy"`
  7253. Certno string `json:"certno"`
  7254. Gend string `json:"gend"`
  7255. Naty string `json:"naty"`
  7256. PsnCertType string `json:"psn_cert_type"`
  7257. PsnName string `json:"psn_name"`
  7258. PsnNo string `json:"psn_no"`
  7259. } `json:"baseinfo"`
  7260. Idetinfo []interface{} `json:"idetinfo"`
  7261. Iinfo []struct {
  7262. Balc float64 `json:"balc"`
  7263. CvlservFlag string `json:"cvlserv_flag"`
  7264. EmpName string `json:"emp_name"`
  7265. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7266. Insutype string `json:"insutype"`
  7267. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7268. PausInsuDate interface{} `json:"paus_insu_date"`
  7269. PsnInsuDate string `json:"psn_insu_date"`
  7270. PsnInsuStas string `json:"psn_insu_stas"`
  7271. PsnType string `json:"psn_type"`
  7272. } `json:"insuinfo"`
  7273. } `json:"output"`
  7274. RefmsgTime string `json:"refmsg_time"`
  7275. RespondTime string `json:"respond_time"`
  7276. Signtype interface{} `json:"signtype"`
  7277. WarnInfo interface{} `json:"warn_info"`
  7278. }
  7279. type ResultThree struct {
  7280. Cainfo interface{} `json:"cainfo"`
  7281. ErrMsg interface{} `json:"err_msg"`
  7282. InfRefmsgid string `json:"inf_refmsgid"`
  7283. Infcode int64 `json:"infcode"`
  7284. Output struct {
  7285. Data struct {
  7286. IptOtpNo string `json:"ipt_otp_no"`
  7287. MdtrtID string `json:"mdtrt_id"`
  7288. PsnNo string `json:"psn_no"`
  7289. } `json:"data"`
  7290. } `json:"output"`
  7291. RefmsgTime string `json:"refmsg_time"`
  7292. RespondTime string `json:"respond_time"`
  7293. Signtype interface{} `json:"signtype"`
  7294. WarnMsg interface{} `json:"warn_msg"`
  7295. }
  7296. type ResultFour struct {
  7297. Cainfo string `json:"cainfo"`
  7298. ErrMsg string `json:"err_msg"`
  7299. InfRefmsgid string `json:"inf_refmsgid"`
  7300. Infcode int64 `json:"infcode"`
  7301. Output struct {
  7302. Result []struct {
  7303. BasMednFlag string `json:"bas_medn_flag"`
  7304. ChldMedcFlag string `json:"chld_medc_flag"`
  7305. ChrgitmLv string `json:"chrgitm_lv"`
  7306. Cnt float64 `json:"cnt"`
  7307. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7308. DrtReimFlag string `json:"drt_reim_flag"`
  7309. FeedetlSn string `json:"feedetl_sn"`
  7310. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7311. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7312. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7313. ListSpItemFlag string `json:"list_sp_item_flag"`
  7314. LmtUsedFlag string `json:"lmt_used_flag"`
  7315. MedChrgitmType string `json:"med_chrgitm_type"`
  7316. Memo string `json:"memo"`
  7317. OverlmtAmt float64 `json:"overlmt_amt"`
  7318. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7319. Pric float64 `json:"pric"`
  7320. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7321. SelfpayProp float64 `json:"selfpay_prop"`
  7322. } `json:"result"`
  7323. } `json:"output"`
  7324. RefmsgTime string `json:"refmsg_time"`
  7325. RespondTime string `json:"respond_time"`
  7326. Signtype string `json:"signtype"`
  7327. WarnMsg string `json:"warn_msg"`
  7328. }
  7329. type ResultFive struct {
  7330. Insutype string `json:"insutype"`
  7331. }
  7332. type ResultSix struct {
  7333. Cainfo interface{} `json:"cainfo"`
  7334. ErrMsg interface{} `json:"err_msg"`
  7335. InfRefmsgid string `json:"inf_refmsgid"`
  7336. Infcode int64 `json:"infcode"`
  7337. Output struct {
  7338. } `json:"output"`
  7339. RefmsgTime string `json:"refmsg_time"`
  7340. RespondTime string `json:"respond_time"`
  7341. Signtype interface{} `json:"signtype"`
  7342. WarnMsg interface{} `json:"warn_msg"`
  7343. }
  7344. type ResultSeven struct {
  7345. Cainfo string `json:"cainfo"`
  7346. ErrMsg string `json:"err_msg"`
  7347. InfRefmsgid string `json:"inf_refmsgid"`
  7348. Infcode int64 `json:"infcode"`
  7349. Output struct {
  7350. Setldetail []interface{} `json:"setldetail"`
  7351. Setlinfo struct {
  7352. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7353. AcctPay float64 `json:"acct_pay"`
  7354. ActPayDedc float64 `json:"act_pay_dedc"`
  7355. Age float64 `json:"age"`
  7356. Balc float64 `json:"balc"`
  7357. Brdy string `json:"brdy"`
  7358. Certno string `json:"certno"`
  7359. ClrOptins string `json:"clr_optins"`
  7360. ClrType string `json:"clr_type"`
  7361. ClrWay string `json:"clr_way"`
  7362. CvlservFlag string `json:"cvlserv_flag"`
  7363. CvlservPay float64 `json:"cvlserv_pay"`
  7364. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7365. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7366. Gend string `json:"gend"`
  7367. HifesPay float64 `json:"hifes_pay"`
  7368. HifmiPay float64 `json:"hifmi_pay"`
  7369. HifobPay float64 `json:"hifob_pay"`
  7370. HifpPay float64 `json:"hifp_pay"`
  7371. HospPartAmt float64 `json:"hosp_part_amt"`
  7372. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7373. Insutype string `json:"insutype"`
  7374. MafPay float64 `json:"maf_pay"`
  7375. MdtrtCertType string `json:"mdtrt_cert_type"`
  7376. MdtrtID string `json:"mdtrt_id"`
  7377. MedType string `json:"med_type"`
  7378. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7379. MedinsSetlID string `json:"medins_setl_id"`
  7380. Naty string `json:"naty"`
  7381. OthPay float64 `json:"oth_pay"`
  7382. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7383. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7384. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7385. PsnCashPay float64 `json:"psn_cash_pay"`
  7386. PsnCertType string `json:"psn_cert_type"`
  7387. PsnName string `json:"psn_name"`
  7388. PsnNo string `json:"psn_no"`
  7389. PsnPartAmt float64 `json:"psn_part_amt"`
  7390. PsnType string `json:"psn_type"`
  7391. SetlID string `json:"setl_id"`
  7392. SetlTime string `json:"setl_time"`
  7393. } `json:"setlinfo"`
  7394. } `json:"output"`
  7395. RefmsgTime string `json:"refmsg_time"`
  7396. RespondTime string `json:"respond_time"`
  7397. Signtype interface{} `json:"signtype"`
  7398. WarnMsg interface{} `json:"warn_msg"`
  7399. }
  7400. type ResultEight struct {
  7401. Cainfo string `json:"cainfo"`
  7402. ErrMsg string `json:"err_msg"`
  7403. InfRefmsgid string `json:"inf_refmsgid"`
  7404. Infcode int64 `json:"infcode"`
  7405. Output struct {
  7406. Stmtinfo struct {
  7407. SetlOptins string `json:"setl_optins"`
  7408. StmtRslt string `json:"stmt_rslt"`
  7409. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7410. } `json:"stmtinfo"`
  7411. } `json:"output"`
  7412. RefmsgTime string `json:"refmsg_time"`
  7413. RespondTime string `json:"respond_time"`
  7414. Signtype interface{} `json:"signtype"`
  7415. WarnMsg interface{} `json:"warn_msg"`
  7416. }
  7417. type ResultNine struct {
  7418. Cainfo string `json:"cainfo"`
  7419. ErrMsg string `json:"err_msg"`
  7420. InfRefmsgid string `json:"inf_refmsgid"`
  7421. Infcode int64 `json:"infcode"`
  7422. Output struct {
  7423. FileQuryNo string `json:"file_qury_no"`
  7424. } `json:"output"`
  7425. RefmsgTime string `json:"refmsg_time"`
  7426. RespondTime string `json:"respond_time"`
  7427. Signtype interface{} `json:"signtype"`
  7428. WarnMsg interface{} `json:"warn_msg"`
  7429. }
  7430. type ResultTen struct {
  7431. Cainfo string `json:"cainfo"`
  7432. ErrMsg string `json:"err_msg"`
  7433. InfRefmsgid string `json:"inf_refmsgid"`
  7434. Infcode int64 `json:"infcode"`
  7435. Output struct {
  7436. DldEndtime string `json:"dld_endtime"`
  7437. FileQuryNo string `json:"file_qury_no"`
  7438. Filename string `json:"filename"`
  7439. } `json:"output"`
  7440. RefmsgTime string `json:"refmsg_time"`
  7441. RespondTime string `json:"respond_time"`
  7442. Signtype interface{} `json:"signtype"`
  7443. WarnMsg interface{} `json:"warn_msg"`
  7444. }
  7445. type ResultEleven struct {
  7446. Cainfo string `json:"cainfo"`
  7447. ErrMsg string `json:"err_msg"`
  7448. InfRefmsgid string `json:"inf_refmsgid"`
  7449. Infcode int64 `json:"infcode"`
  7450. Output struct {
  7451. Setlinfo struct {
  7452. FixmedinsName string `json:"fixmedins_name"`
  7453. FixmedinsCode string `json:"fixmedins_code"`
  7454. PsnNo string `json:"psn_no"`
  7455. PsnName string `json:"psn_name"`
  7456. HifobPay float64 `json:"hifob_pay"`
  7457. Gend string `json:"gend"`
  7458. Brdy string `json:"brdy"`
  7459. PsnCertType string `json:"psn_cert_type"`
  7460. PsnType string `json:"psn_type"`
  7461. EmpName string `json:"emp_name"`
  7462. Certno string `json:"certno"`
  7463. Insutype string `json:"insutype"`
  7464. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7465. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7466. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7467. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7468. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7469. ActPayDedc float64 `json:"act_pay_dedc"`
  7470. HifpPay float64 `json:"hifp_pay"`
  7471. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7472. CvlservPay float64 `json:"cvlserv_pay"`
  7473. HifesPay float64 `json:"hifes_pay"`
  7474. HifmiPay float64 `json:"hifmi_pay"`
  7475. MafPay float64 `json:"maf_pay"`
  7476. OthPay float64 `json:"oth_pay"`
  7477. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7478. PsnPay float64 `json:"psn_pay"`
  7479. AcctPay float64 `json:"acct_pay"`
  7480. CashPayamt float64 `json:"cash_payamt"`
  7481. Balc float64 `json:"balc"`
  7482. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7483. MedinsSetlId string `json:"medins_setl_id"`
  7484. RefdSetlFlag string `json:"refd_setl_flag"`
  7485. SetlTime string `json:"setl_time"`
  7486. MedType string `json:"med_type"`
  7487. } `json:"setlinfo"`
  7488. } `json:"output"`
  7489. RefmsgTime string `json:"refmsg_time"`
  7490. RespondTime string `json:"respond_time"`
  7491. Signtype interface{} `json:"signtype"`
  7492. WarnMsg interface{} `json:"warn_msg"`
  7493. }
  7494. type Custom struct {
  7495. DetItemFeeSumamt string
  7496. Cut string
  7497. FeedetlSn string
  7498. Price string
  7499. MedListCodg string
  7500. Type int64
  7501. AdviceId int64
  7502. ProjectId int64
  7503. ItemId int64
  7504. }
  7505. // 获取个人信息----挂号-----上传就诊信息
  7506. func (c *HisApiController) GetRegisterInfo() {
  7507. id, _ := c.GetInt64("id")
  7508. record_time := c.GetString("record_time")
  7509. settlementValue, _ := c.GetInt64("settlement_value")
  7510. medical_insurance_card := c.GetString("medical_insurance_card")
  7511. name := c.GetString("name")
  7512. id_card_type, _ := c.GetInt64("id_card_type")
  7513. certificates, _ := c.GetInt64("certificates")
  7514. medical_care, _ := c.GetInt64("medical_care")
  7515. birthday := c.GetString("birthday")
  7516. age, _ := c.GetInt64("age")
  7517. id_card := c.GetString("id_card")
  7518. register_type, _ := c.GetInt64("register")
  7519. doctor, _ := c.GetInt64("doctor")
  7520. department, _ := c.GetInt64("department")
  7521. gender, _ := c.GetInt64("sex")
  7522. phone := c.GetString("phone")
  7523. registration_fee, _ := c.GetFloat("registration_fee")
  7524. medical_expenses, _ := c.GetFloat("medical_expenses")
  7525. social_type, _ := c.GetInt64("social_type")
  7526. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7527. diagnosis_ids := c.GetString("diagnosis")
  7528. sick_type, _ := c.GetInt64("sick_type")
  7529. reg_type := c.GetString("p_type")
  7530. timeLayout := "2006-01-02"
  7531. loc, _ := time.LoadLocation("Local")
  7532. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7533. birthUnix := birthdays.Unix()
  7534. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7535. if err != nil {
  7536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7537. return
  7538. }
  7539. recordDateTime := theTime.Unix()
  7540. adminInfo := c.GetAdminUserInfo()
  7541. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7542. if tempPatient.ID == 0 {
  7543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7544. return
  7545. }
  7546. var patient service.Patients
  7547. if id == 0 {
  7548. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7549. } else {
  7550. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7551. }
  7552. if patient.ID == 0 {
  7553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7554. return
  7555. }
  7556. if len(patient.IdCardNo) == 0 {
  7557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7558. return
  7559. }
  7560. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7561. if len(his) >= 1 {
  7562. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7563. if len(his) >= 1 && order.ID == 0 {
  7564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7565. return
  7566. }
  7567. }
  7568. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7569. fmt.Println(timeStr)
  7570. timeArr := strings.Split(timeStr, " ")
  7571. fmt.Println(timeArr)
  7572. timeArrTwo := strings.Split(timeArr[0], "-")
  7573. timeArrThree := strings.Split(timeArr[1], ":")
  7574. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7575. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7576. if len(lists) == 0 {
  7577. var hisPatient models.XtHisPatient
  7578. hisPatient = models.XtHisPatient{
  7579. Name: name,
  7580. Age: age,
  7581. Gender: gender,
  7582. Birthday: birthUnix,
  7583. Phone: phone,
  7584. MedicalTreatmentType: medical_care,
  7585. IdType: certificates,
  7586. IdCardNo: id_card,
  7587. BalanceAccountsType: settlementValue,
  7588. SocialType: social_type,
  7589. MedicalInsuranceNumber: medical_insurance_card,
  7590. RegisterType: register_type,
  7591. RegisterCost: registration_fee,
  7592. TreatmentCost: medical_expenses,
  7593. AdminUserId: adminInfo.AdminUser.Id,
  7594. UserOrgId: adminInfo.CurrentOrgId,
  7595. Status: 1,
  7596. RecordDate: recordDateTime,
  7597. IsReturn: 1,
  7598. PatientId: patient.ID,
  7599. Ctime: time.Now().Unix(),
  7600. Mtime: time.Now().Unix(),
  7601. Number: str,
  7602. IdCardType: id_card_type,
  7603. Departments: department,
  7604. Doctor: doctor,
  7605. PType: reg_type,
  7606. Diagnosis: diagnosis_ids,
  7607. SickType: sick_type,
  7608. }
  7609. service.CreateHisPatient(&hisPatient)
  7610. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7611. c.ServeSuccessJSON(map[string]interface{}{
  7612. "his_info": hisPatient,
  7613. })
  7614. } else {
  7615. //chrgBchno := rand.Intn(1000000) + 10000
  7616. var hisPatient models.XtHisPatient
  7617. hisPatient = models.XtHisPatient{
  7618. Name: name,
  7619. Age: age,
  7620. Gender: gender,
  7621. Birthday: birthUnix,
  7622. Phone: phone,
  7623. MedicalTreatmentType: medical_care,
  7624. IdType: certificates,
  7625. IdCardNo: id_card,
  7626. BalanceAccountsType: settlementValue,
  7627. SocialType: social_type,
  7628. MedicalInsuranceNumber: medical_insurance_card,
  7629. RegisterType: register_type,
  7630. RegisterCost: registration_fee,
  7631. TreatmentCost: medical_expenses,
  7632. AdminUserId: adminInfo.AdminUser.Id,
  7633. UserOrgId: adminInfo.CurrentOrgId,
  7634. Status: 1,
  7635. RecordDate: recordDateTime,
  7636. IsReturn: 1,
  7637. PatientId: patient.ID,
  7638. Ctime: time.Now().Unix(),
  7639. Mtime: time.Now().Unix(),
  7640. Number: str,
  7641. IdCardType: id_card_type,
  7642. Departments: department,
  7643. Doctor: doctor,
  7644. PType: reg_type,
  7645. Diagnosis: diagnosis_ids,
  7646. SickType: sick_type,
  7647. }
  7648. service.CreateHisPatient(&hisPatient)
  7649. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7650. c.ServeSuccessJSON(map[string]interface{}{
  7651. "his_info": hisPatient,
  7652. })
  7653. }
  7654. }
  7655. // 上传明细----结算
  7656. func (c *HisApiController) GetUploadInfo() {
  7657. id, _ := c.GetInt64("id")
  7658. record_time := c.GetString("record_time")
  7659. his_patient_id, _ := c.GetInt64("his_patient_id")
  7660. oth_desc := c.GetString("oth_desc")
  7661. pay_way, _ := c.GetInt64("pay_way")
  7662. pay_ways := c.GetString("pay_ways")
  7663. pay_price, _ := c.GetFloat("pay_price")
  7664. pay_card_no := c.GetString("pay_card_no")
  7665. discount_price, _ := c.GetFloat("discount_price")
  7666. preferential_price, _ := c.GetFloat("preferential_price")
  7667. reality_price, _ := c.GetFloat("reality_price")
  7668. found_price, _ := c.GetFloat("found_price")
  7669. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7670. private_price, _ := c.GetFloat("private_price")
  7671. timeLayout := "2006-01-02"
  7672. loc, _ := time.LoadLocation("Local")
  7673. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7674. fapiao_code := c.GetString("fapiao_code")
  7675. fapiao_number := c.GetString("fapiao_number")
  7676. diagnosis_id := c.GetString("diagnosis")
  7677. sick_type, _ := c.GetInt64("sick_type")
  7678. reg_type, _ := c.GetInt64("p_type")
  7679. order_id, _ := c.GetInt64("order_id")
  7680. cash_pay := c.GetString("cash_pay")
  7681. wechat_pay := c.GetString("wechat_pay")
  7682. ali_pay := c.GetString("ali_pay")
  7683. jifen_pay := c.GetString("jifen_pay")
  7684. band_card_pay := c.GetString("band_card_pay")
  7685. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7686. tmp_decimal := c.GetString("tmp_decimal")
  7687. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7688. var decimal float64 //本次使用的押金
  7689. var errmsg error
  7690. tx := service.XTWriteDB().Begin() //开了事务
  7691. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7692. defer func() {
  7693. if errmsg != nil {
  7694. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7695. tx.Rollback()
  7696. } else {
  7697. tx.Commit()
  7698. }
  7699. }()
  7700. fmt.Println("dec_way", dec_way)
  7701. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7702. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7703. return
  7704. }
  7705. if len(tmp_decimal) > 0 {
  7706. if tmp_decimal[0] == 45 {
  7707. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7708. return
  7709. }
  7710. }
  7711. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7712. fmt.Println(errs)
  7713. decimal = tt
  7714. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7715. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7717. if err != nil {
  7718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7719. return
  7720. }
  7721. recordDateTime := theTime.Unix()
  7722. adminUser := c.GetAdminUserInfo()
  7723. var prescriptions []*models.HisPrescription
  7724. var prescriptionsOne []*models.HisPrescription
  7725. var start_time int64
  7726. var end_time int64
  7727. ids_str := c.GetString("ids")
  7728. ids_arr := strings.Split(ids_str, ",")
  7729. if tempOrder.ID == 0 {
  7730. if settle_accounts_type == 1 { //日结
  7731. fmt.Println(reg_type)
  7732. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7733. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7734. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7735. } else {
  7736. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7737. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7738. }
  7739. } else { //月结
  7740. start_time_str := c.GetString("start_time")
  7741. end_time_str := c.GetString("end_time")
  7742. timeLayout := "2006-01-02"
  7743. loc, _ := time.LoadLocation("Local")
  7744. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7745. if err != nil {
  7746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7747. return
  7748. }
  7749. recordStartTime := theStartTime.Unix()
  7750. start_time = recordStartTime
  7751. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7752. if err != nil {
  7753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7754. return
  7755. }
  7756. recordEndTime := theEndTime.Unix()
  7757. end_time = recordEndTime
  7758. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7759. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7760. }
  7761. var goods []*models.DialysisBeforePrepareGoods
  7762. var newGoods []*models.NewDialysisBeforePrepareGoods
  7763. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7764. var infos []*models.HisDoctorAdviceInfo
  7765. var infoList []*models.HisDoctorAdviceInfo
  7766. var hisAdvice []*models.HisDoctorAdviceInfo
  7767. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7768. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7769. //判断库存不足
  7770. //结算出库开关
  7771. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7772. if settConfig.IsOpen == 1 {
  7773. //判断库存的地方
  7774. for _, info := range prescriptions {
  7775. if info.Type == 1 {
  7776. infos = append(infos, info.HisDoctorAdviceInfo...)
  7777. }
  7778. if info.Type == 2 {
  7779. for _, sumItem := range info.HisPrescriptionProject {
  7780. if sumItem.Type == 3 {
  7781. var good models.DialysisBeforePrepareGoods
  7782. var newGood models.NewDialysisBeforePrepareGoods
  7783. good.GoodId = sumItem.GoodInfo.ID
  7784. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7785. count, _ := strconv.Atoi(sumItem.Count)
  7786. good.Count = int64(count)
  7787. good.StorehouseId = houseConfig.StorehouseOutInfo
  7788. good.ProjectId = sumItem.ID
  7789. goods = append(goods, &good)
  7790. newGood.GoodId = sumItem.GoodInfo.ID
  7791. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7792. count2, _ := strconv.Atoi(sumItem.Count)
  7793. newGood.Count = int64(count2)
  7794. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7795. newGood.ProjectId = sumItem.ID
  7796. newGoods = append(newGoods, &newGood)
  7797. }
  7798. }
  7799. }
  7800. }
  7801. for _, info := range prescriptionsOne {
  7802. if info.Type == 1 {
  7803. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7804. }
  7805. if info.Type == 2 {
  7806. for _, sumItem := range info.HisPrescriptionProject {
  7807. if sumItem.Type == 3 {
  7808. var newGood models.NewDialysisBeforePrepareGoods
  7809. newGood.GoodId = sumItem.GoodInfo.ID
  7810. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7811. count2, _ := strconv.Atoi(sumItem.Count)
  7812. newGood.Count = int64(count2)
  7813. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7814. newGood.ProjectId = sumItem.ID
  7815. newGoodOne = append(newGoodOne, &newGood)
  7816. }
  7817. }
  7818. }
  7819. }
  7820. //判断
  7821. for _, itemOne := range infos {
  7822. for _, itemTwo := range hisAdvice {
  7823. if itemOne.DrugId == itemTwo.DrugId {
  7824. itemTwo.Child = append(itemTwo.Child, itemOne)
  7825. }
  7826. }
  7827. }
  7828. for _, itemTwo := range hisAdvice {
  7829. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7830. var sum_out_count int64
  7831. for _, itemThree := range itemTwo.Child {
  7832. var prescribing_number int64
  7833. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7834. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7835. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7836. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7837. }
  7838. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7839. prescribing_number = parseIntPrescribingNumber
  7840. }
  7841. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7842. prescribing_number = parseIntPrescribingNumber
  7843. }
  7844. sum_out_count += prescribing_number
  7845. }
  7846. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7847. if sum_out_count > drugStockOut.FlushCount {
  7848. c.ServeSuccessJSON(map[string]interface{}{
  7849. "msg": "2",
  7850. "drug": medical,
  7851. })
  7852. return
  7853. }
  7854. }
  7855. for _, itemOne := range newGoods {
  7856. for _, item := range newGoodOne {
  7857. if itemOne.GoodId == item.GoodId {
  7858. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7859. }
  7860. }
  7861. }
  7862. for _, item := range newGoodOne {
  7863. var sum_out_count_one int64
  7864. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7865. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7866. sum_out_count_one += itemOne.Count
  7867. }
  7868. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7869. fmt.Println("sum_out_count_one", sum_out_count_one)
  7870. fmt.Println("list.FlushCount", list.FlushCount)
  7871. if sum_out_count_one > list.FlushCount {
  7872. c.ServeSuccessJSON(map[string]interface{}{
  7873. "msg": "3",
  7874. "good": good,
  7875. })
  7876. return
  7877. }
  7878. }
  7879. }
  7880. timestamp := time.Now().Unix()
  7881. tempTime := time.Unix(timestamp, 0)
  7882. timeFormat := tempTime.Format("20060102150405")
  7883. chrgBchno := rand.Intn(100000) + 10000
  7884. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7885. strconv.FormatInt(his.PatientId, 10)
  7886. var ids []int64
  7887. for _, item := range prescriptions {
  7888. ids = append(ids, item.ID)
  7889. }
  7890. var total float64
  7891. for _, item := range prescriptions {
  7892. fmt.Println(item)
  7893. if item.Type == 1 { //药品
  7894. for _, subItem := range item.HisDoctorAdviceInfo {
  7895. total = total + (subItem.Price * subItem.PrescribingNumber)
  7896. }
  7897. }
  7898. if item.Type == 2 { //项目
  7899. for _, subItem := range item.HisPrescriptionProject {
  7900. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7901. total = total + (subItem.Price * cnt)
  7902. }
  7903. }
  7904. for _, subItem := range item.HisAdditionalCharge {
  7905. total = total + (subItem.Price * float64(subItem.Count))
  7906. }
  7907. }
  7908. if reg_type == 1111 || reg_type == 1112 {
  7909. reg_type = 11
  7910. }
  7911. tm := time.Unix(time.Now().Unix(), 0)
  7912. allTotal := fmt.Sprintf("%.4f", total)
  7913. totals, _ := strconv.ParseFloat(allTotal, 64)
  7914. order := &models.HisOrder{
  7915. UserOrgId: adminUser.CurrentOrgId,
  7916. HisPatientId: his.ID,
  7917. PatientId: id,
  7918. SettleAccountsDate: recordDateTime,
  7919. Ctime: time.Now().Unix(),
  7920. Mtime: time.Now().Unix(),
  7921. Status: 1,
  7922. OrderStatus: 2,
  7923. MdtrtId: his.Number,
  7924. Number: chrg_bchno,
  7925. MedfeeSumamt: totals,
  7926. PayWay: pay_way,
  7927. PayWays: pay_ways,
  7928. PayPrice: pay_price,
  7929. MedType: strconv.Itoa(int(reg_type)),
  7930. PayCardNo: pay_card_no,
  7931. DiscountPrice: discount_price,
  7932. PreferentialPrice: preferential_price,
  7933. RealityPrice: reality_price,
  7934. FoundPrice: found_price,
  7935. MedicalInsurancePrice: medical_insurance_price,
  7936. PrivatePrice: private_price,
  7937. SettleEndTime: end_time,
  7938. SettleStartTime: start_time,
  7939. PsnPartAmt: totals,
  7940. PsnCashPay: totals,
  7941. SettleType: settle_accounts_type,
  7942. FaPiaoCode: fapiao_code,
  7943. FaPiaoNumber: fapiao_number,
  7944. Diagnosis: diagnosis_id,
  7945. PType: 2,
  7946. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7947. Decimal: decimal,
  7948. OthDesc: oth_desc,
  7949. CashPay: cash_pay,
  7950. WechatPay: wechat_pay,
  7951. AliPay: ali_pay,
  7952. JifenPay: jifen_pay,
  7953. BandCardPay: band_card_pay,
  7954. Creator: adminUser.AdminUser.Id,
  7955. }
  7956. err = service.CreateOrderTX(order, tx)
  7957. if err != nil {
  7958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7959. return
  7960. }
  7961. var customs []*Custom
  7962. for _, item := range prescriptions {
  7963. if item.Type == 1 { //药品a
  7964. for _, subItem := range item.HisDoctorAdviceInfo {
  7965. cus := &Custom{
  7966. AdviceId: subItem.ID,
  7967. ProjectId: 0,
  7968. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7969. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7970. FeedetlSn: subItem.FeedetlSn,
  7971. Price: fmt.Sprintf("%.4f", subItem.Price),
  7972. MedListCodg: subItem.MedListCodg,
  7973. Type: 1,
  7974. }
  7975. customs = append(customs, cus)
  7976. }
  7977. }
  7978. if item.Type == 2 { //项目
  7979. for _, subItem := range item.HisPrescriptionProject {
  7980. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7981. cus := &Custom{
  7982. AdviceId: 0,
  7983. ProjectId: subItem.ID,
  7984. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7985. Cut: fmt.Sprintf("%.4f", cnt),
  7986. FeedetlSn: subItem.FeedetlSn,
  7987. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7988. MedListCodg: subItem.MedListCodg,
  7989. Type: 2,
  7990. }
  7991. customs = append(customs, cus)
  7992. }
  7993. }
  7994. for _, item := range item.HisAdditionalCharge {
  7995. cus := &Custom{
  7996. ItemId: item.ID,
  7997. AdviceId: 0,
  7998. ProjectId: 0,
  7999. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8000. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8001. FeedetlSn: item.FeedetlSn,
  8002. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8003. MedListCodg: item.XtHisAddtionConfig.Code,
  8004. Type: 3,
  8005. }
  8006. customs = append(customs, cus)
  8007. }
  8008. }
  8009. for _, item := range customs {
  8010. var advice_id int64 = 0
  8011. var project_id int64 = 0
  8012. var item_id int64 = 0
  8013. var types int64 = 0
  8014. if item.Type == 1 {
  8015. advice_id = item.AdviceId
  8016. project_id = 0
  8017. item_id = 0
  8018. } else if item.Type == 2 {
  8019. advice_id = 0
  8020. item_id = 0
  8021. project_id = item.ProjectId
  8022. } else if item.Type == 3 {
  8023. advice_id = 0
  8024. item_id = item.ItemId
  8025. project_id = 0
  8026. }
  8027. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8028. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8029. pric, _ := strconv.ParseFloat(item.Price, 32)
  8030. info := &models.HisOrderInfo{
  8031. OrderNumber: order.Number,
  8032. UploadDate: time.Now().Unix(),
  8033. AdviceId: advice_id,
  8034. DetItemFeeSumamt: detItemFeeSumamt,
  8035. Cnt: cut,
  8036. Pric: pric,
  8037. PatientId: id,
  8038. Status: 1,
  8039. Mtime: time.Now().Unix(),
  8040. Ctime: time.Now().Unix(),
  8041. UserOrgId: adminUser.CurrentOrgId,
  8042. HisPatientId: his.ID,
  8043. OrderId: order.ID,
  8044. ProjectId: project_id,
  8045. Type: types,
  8046. ItemId: item_id,
  8047. }
  8048. service.CreateOrderInfoTX(info, tx)
  8049. }
  8050. his.Diagnosis = diagnosis_id
  8051. his.SickType = sick_type
  8052. his.RegisterType = reg_type
  8053. his.MedicalTreatmentType = reg_type
  8054. service.UpdataHisPateintTX(&his, tx)
  8055. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8056. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8057. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8058. //判断是否使用了押金
  8059. if dec_way == "true" {
  8060. tmpstring := strconv.FormatInt(order.ID, 10)
  8061. //扣押金
  8062. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8063. order.Decimal = decimal
  8064. service.UpDateOrderTwo(order, tx)
  8065. if errmsg != nil {
  8066. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8067. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8068. return
  8069. }
  8070. }
  8071. if err == nil {
  8072. for _, info := range prescriptions {
  8073. if info.Type == 1 {
  8074. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8075. }
  8076. if info.Type == 2 {
  8077. for _, sumItem := range info.HisPrescriptionProject {
  8078. if sumItem.Type == 3 {
  8079. var good models.DialysisBeforePrepareGoods
  8080. var newGood models.NewDialysisBeforePrepareGoods
  8081. var oldGood models.OldDialysisBeforePrepareGoods
  8082. good.GoodId = sumItem.GoodInfo.ID
  8083. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8084. count, _ := strconv.Atoi(sumItem.Count)
  8085. good.Count = int64(count)
  8086. good.StorehouseId = houseConfig.StorehouseOutInfo
  8087. good.ProjectId = sumItem.ID
  8088. good.PatientId = sumItem.PatientId
  8089. goods = append(goods, &good)
  8090. newGood.GoodId = sumItem.GoodInfo.ID
  8091. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8092. count2, _ := strconv.Atoi(sumItem.Count)
  8093. newGood.Count = int64(count2)
  8094. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8095. newGood.ProjectId = sumItem.ID
  8096. newGood.PatientId = sumItem.HisPatientId
  8097. newGoods = append(newGoods, &newGood)
  8098. oldGood.GoodId = sumItem.GoodInfo.ID
  8099. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8100. count3, _ := strconv.Atoi(sumItem.Count)
  8101. oldGood.Count = int64(count3)
  8102. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8103. oldGood.ProjectId = sumItem.ID
  8104. oldGood.RecordDate = sumItem.RecordDate
  8105. oldGood.PatientId = sumItem.HisPatientId
  8106. oldGoods = append(oldGoods, &oldGood)
  8107. }
  8108. }
  8109. }
  8110. }
  8111. if settConfig.IsOpen == 1 {
  8112. for _, item := range infoList {
  8113. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8114. if medical.IsUse == 2 {
  8115. //药品出库
  8116. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8117. //查询默认仓库
  8118. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8119. //查询默认仓库剩余多少库存
  8120. var sum_count int64
  8121. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8122. for _, its := range stockInfo {
  8123. if its.MaxUnit == medical.MaxUnit {
  8124. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8125. }
  8126. sum_count += its.StockMaxNumber + its.StockMinNumber
  8127. }
  8128. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8129. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8130. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8131. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8132. }
  8133. }
  8134. orgId := c.GetAdminUserInfo().CurrentOrgId
  8135. if len(oldGoods) > 0 {
  8136. timeStr := time.Now().Format("2006-01-02")
  8137. timeArr := strings.Split(timeStr, "-")
  8138. total, _ := service.FindAllWarehouseOut(orgId)
  8139. total = total + 1
  8140. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8141. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8142. number = number + total
  8143. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8144. operation_time := time.Now().Unix()
  8145. creater := c.GetAdminUserInfo().AdminUser.Id
  8146. //查询默认出库仓库库存
  8147. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8148. recordDateStr := time.Now().Format("2006-01-02")
  8149. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8150. nowtime := recordDate.Unix()
  8151. warehouseOut := models.WarehouseOut{
  8152. WarehouseOutOrderNumber: warehousing_out_order,
  8153. OperationTime: operation_time,
  8154. OrgId: orgId,
  8155. Creater: creater,
  8156. Ctime: time.Now().Unix(),
  8157. Status: 1,
  8158. WarehouseOutTime: nowtime,
  8159. Type: 1,
  8160. StorehouseId: storeConfig.StorehouseOutInfo,
  8161. IsCheck: 1,
  8162. OrderId: order.ID,
  8163. IsSys: 5,
  8164. }
  8165. //查询是否生成出库单
  8166. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8167. if out.ID == 0 {
  8168. service.AddSigleWarehouseOut(&warehouseOut)
  8169. }
  8170. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8171. for _, item := range oldGoods {
  8172. dialyPrepareOne := models.DialysisBeforePrepare{
  8173. GoodTypeId: item.GoodTypeId,
  8174. GoodId: item.GoodId,
  8175. PatientId: his.PatientId,
  8176. RecordDate: item.RecordDate,
  8177. UserOrgId: adminUser.CurrentOrgId,
  8178. Count: item.Count,
  8179. Ctime: time.Now().Unix(),
  8180. Creater: adminUser.AdminUser.Id,
  8181. CommdityCode: item.CommdityCode,
  8182. Status: 1,
  8183. StorehouseId: houseConfig.StorehouseOutInfo,
  8184. }
  8185. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8186. //非零用
  8187. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8188. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8189. //查询剩余库存
  8190. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8191. var sum_count int64
  8192. for _, item := range goodList {
  8193. sum_count += item.StockCount
  8194. }
  8195. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8196. //耗材
  8197. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8198. }
  8199. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8200. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8201. //查询剩余库存
  8202. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8203. var sum_count int64
  8204. for _, item := range goodList {
  8205. sum_count += item.StockCount
  8206. }
  8207. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8208. //耗材
  8209. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8210. }
  8211. }
  8212. }
  8213. }
  8214. c.ServeSuccessJSON(map[string]interface{}{
  8215. "msg": "结算成功",
  8216. })
  8217. }
  8218. }
  8219. }
  8220. // 退款
  8221. func (c *HisApiController) Refund() {
  8222. order_id, _ := c.GetInt64("order_id")
  8223. order, _ := service.GetHisOrderByID(order_id)
  8224. adminUser := c.GetAdminUserInfo()
  8225. orgid := c.GetAdminUserInfo().CurrentOrgId
  8226. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8227. if err != nil {
  8228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8229. return
  8230. }
  8231. tmp := strconv.FormatInt(order.ID, 10)
  8232. //当押金不为零时产生退费记录
  8233. if order.Decimal != 0 {
  8234. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8235. if err != nil {
  8236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8237. return
  8238. }
  8239. }
  8240. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8241. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8242. var goods []*models.DialysisBeforePrepareGoods
  8243. var newGoods []*models.NewDialysisBeforePrepareGoods
  8244. var infos []*models.HisDoctorAdviceInfo
  8245. for _, info := range orders {
  8246. if info.AdviceId > 0 && info.ProjectId == 0 {
  8247. infos = append(infos, &info.HisDoctorAdviceInfo)
  8248. }
  8249. if info.ProjectId > 0 && info.AdviceId == 0 {
  8250. if info.HisPrescriptionProject.Type == 3 {
  8251. var good models.DialysisBeforePrepareGoods
  8252. var newGood models.NewDialysisBeforePrepareGoods
  8253. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8254. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8255. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8256. good.Count = int64(count)
  8257. good.StorehouseId = houseConfig.StorehouseOutInfo
  8258. good.ProjectId = info.HisPrescriptionProject.ID
  8259. good.PatientId = info.PatientId
  8260. good.OrderId = order_id
  8261. goods = append(goods, &good)
  8262. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8263. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8264. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8265. newGood.Count = int64(count2)
  8266. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8267. newGood.ProjectId = info.HisPrescriptionProject.ID
  8268. newGood.RecordDate = order.SettleAccountsDate
  8269. newGood.UserOrgId = order.UserOrgId
  8270. newGood.PatientId = info.PatientId
  8271. newGood.OrderId = order_id
  8272. newGoods = append(newGoods, &newGood)
  8273. }
  8274. }
  8275. }
  8276. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8277. if settConfig.IsOpen == 1 {
  8278. for _, item := range infos {
  8279. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8280. }
  8281. for _, item := range newGoods {
  8282. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8283. }
  8284. }
  8285. c.ServeSuccessJSON(map[string]interface{}{
  8286. "msg": "退费成功",
  8287. })
  8288. }
  8289. func (c *HisApiController) RefundNumber() {
  8290. his_patient_id, _ := c.GetInt64("id")
  8291. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8292. info.Status = 0
  8293. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8294. if count > 0 {
  8295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8296. return
  8297. }
  8298. err := service.SaveHisPatient(info)
  8299. if err == nil {
  8300. c.ServeSuccessJSON(map[string]interface{}{
  8301. "msg": "退号成功",
  8302. })
  8303. } else {
  8304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8305. return
  8306. }
  8307. }
  8308. func (this *HisApiController) AdditionalCharge() {
  8309. dataBody := make(map[string]interface{}, 0)
  8310. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8311. fmt.Println(err)
  8312. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8313. patient_id := int64(dataBody["patient_id"].(float64))
  8314. medicineData, _ := dataBody["medicineData"].([]interface{})
  8315. adminUserInfo := this.GetAdminUserInfo()
  8316. orgId := adminUserInfo.CurrentOrgId
  8317. admin_user_id := adminUserInfo.AdminUser.Id
  8318. timeStr := time.Now().Format("2006-01-02")
  8319. timeLayout := "2006-01-02 15:04:05"
  8320. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8321. timenow := timeStringToTime.Unix()
  8322. var additionalCharges []*models.HisAdditionalCharge
  8323. for _, item := range medicineData {
  8324. var randNum int
  8325. randNum = rand.Intn(10000) + 1000
  8326. timestamp := time.Now().Unix()
  8327. tempTime := time.Unix(timestamp, 0)
  8328. timeFormat := tempTime.Format("20060102150405")
  8329. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8330. items := item.(map[string]interface{})
  8331. money := items["price"].(string)
  8332. item_id_str := items["item_id"].(string)
  8333. name := items["name"].(string)
  8334. id_str := items["id"].(string)
  8335. moneys, _ := strconv.ParseInt(money, 10, 64)
  8336. monStr := strconv.FormatInt(moneys, 10)
  8337. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8338. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8339. id, _ := strconv.ParseInt(id_str, 10, 64)
  8340. additionalCharge := &models.HisAdditionalCharge{
  8341. ID: id,
  8342. HisPatientId: his_patient_id,
  8343. UserOrgId: orgId,
  8344. PatientId: patient_id,
  8345. RecordDate: timenow,
  8346. Price: monneyStr,
  8347. Status: 1,
  8348. ItemName: name,
  8349. ItemId: item_id,
  8350. AdminUserId: admin_user_id,
  8351. CreatedTime: time.Now().Unix(),
  8352. OrderStatus: 0,
  8353. PrescriptionNumber: "",
  8354. BatchNumber: "",
  8355. FeedetlSn: p_number,
  8356. }
  8357. service.CreateAdditionalCharge(additionalCharge)
  8358. additionalCharges = append(additionalCharges, additionalCharge)
  8359. }
  8360. this.ServeSuccessJSON(map[string]interface{}{
  8361. "msg": "添加成功",
  8362. "additional_charges": additionalCharges,
  8363. })
  8364. }
  8365. func (this *HisApiController) DeleteAddition() {
  8366. id, _ := this.GetInt64("id")
  8367. //TODO 需要判断是否已经结算
  8368. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8369. if err == nil {
  8370. this.ServeSuccessJSON(map[string]interface{}{
  8371. "msg": "删除成功",
  8372. })
  8373. return
  8374. } else {
  8375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8376. return
  8377. }
  8378. }
  8379. func (this *HisApiController) GetAdminUsers() {
  8380. adminUser := this.GetAdminUserInfo()
  8381. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8382. this.ServeSuccessJSON(map[string]interface{}{
  8383. "doctors": doctors,
  8384. })
  8385. }
  8386. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8387. change_type, _ := this.GetInt64("type", 0)
  8388. record_date := this.GetString("record_time")
  8389. patient_id, _ := this.GetInt64("patient_id", 0)
  8390. p_type, _ := this.GetInt64("p_type", 0)
  8391. timeLayout := "2006-01-02"
  8392. loc, _ := time.LoadLocation("Local")
  8393. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8394. record_time := theAdviceRecordTime.Unix()
  8395. adminUserInfo := this.GetAdminUserInfo()
  8396. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8397. if err == nil {
  8398. if len(prescriptions) == 0 {
  8399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8400. return
  8401. } else {
  8402. this.ServeSuccessJSON(map[string]interface{}{
  8403. "prescriptions": prescriptions,
  8404. })
  8405. return
  8406. }
  8407. } else {
  8408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8409. return
  8410. }
  8411. }
  8412. func (this *HisApiController) GetCallHisPrescription() {
  8413. patient_id, _ := this.GetInt64("patient_id", 0)
  8414. timeLayout := "2006-01-02"
  8415. loc, _ := time.LoadLocation("Local")
  8416. start_time := this.GetString("start_time")
  8417. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8418. end_time := this.GetString("end_time")
  8419. p_type, _ := this.GetInt64("p_type")
  8420. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8421. adminUserInfo := this.GetAdminUserInfo()
  8422. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8423. if err == nil {
  8424. this.ServeSuccessJSON(map[string]interface{}{
  8425. "prescriptions": prescriptions,
  8426. })
  8427. return
  8428. } else {
  8429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8430. return
  8431. }
  8432. }
  8433. func (this *HisApiController) GetHisDayPrescription() {
  8434. timeLayout := "2006-01-02"
  8435. loc, _ := time.LoadLocation("Local")
  8436. start_time := this.GetString("start_time")
  8437. patient_id, _ := this.GetInt64("patient_id", 0)
  8438. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8439. end_time := this.GetString("end_time")
  8440. p_type, _ := this.GetInt64("p_type")
  8441. order_status, _ := this.GetInt64("type")
  8442. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8443. adminUserInfo := this.GetAdminUserInfo()
  8444. var dayHisPrescription []*models.HisPrescription
  8445. var err error
  8446. if order_status == 1 || order_status == 0 {
  8447. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8448. } else if order_status == 2 {
  8449. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8450. }
  8451. var settle_total float64
  8452. for _, item := range dayHisPrescription {
  8453. if len(item.HisPrescriptionProject) > 0 {
  8454. for _, subItem := range item.HisPrescriptionProject {
  8455. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8456. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8457. settle_total = settle_total + total
  8458. }
  8459. }
  8460. if len(item.HisDoctorAdviceInfo) > 0 {
  8461. for _, subItem := range item.HisDoctorAdviceInfo {
  8462. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8463. settle_total = settle_total + total
  8464. }
  8465. }
  8466. }
  8467. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8468. if err == nil {
  8469. this.ServeSuccessJSON(map[string]interface{}{
  8470. "day_prescription": dayHisPrescription,
  8471. "settle_total": settle_total,
  8472. })
  8473. return
  8474. } else {
  8475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8476. return
  8477. }
  8478. }
  8479. func (c *HisApiController) GetHisChargePatientList() {
  8480. record_date := c.GetString("record_date")
  8481. order_status, _ := c.GetInt64("type")
  8482. sch_type, _ := c.GetInt64("sch_type")
  8483. timeLayout := "2006-01-02"
  8484. loc, _ := time.LoadLocation("Local")
  8485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8486. if err != nil {
  8487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8488. return
  8489. }
  8490. recordDateTime := theTime.Unix()
  8491. adminInfo := c.GetAdminUserInfo()
  8492. var tempPatients []*service.NewTempPatients
  8493. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8494. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8495. if order_status != 2 {
  8496. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8497. } else {
  8498. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8499. }
  8500. } else {
  8501. if order_status != 2 {
  8502. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8503. } else {
  8504. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8505. }
  8506. }
  8507. var patients []*service.NewTempPatients
  8508. var patients_two []*service.NewTempPatients
  8509. for _, item := range tempPatients {
  8510. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8511. //过滤掉没挂号的和没开处方的
  8512. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8513. patients = append(patients, item)
  8514. }
  8515. //过滤掉没挂号的
  8516. if len(item.HisPatient) > 0 {
  8517. patients_two = append(patients_two, item)
  8518. }
  8519. } else {
  8520. if len(item.HisPrescription) > 0 {
  8521. patients = append(patients, item)
  8522. }
  8523. }
  8524. }
  8525. c.ServeSuccessJSON(map[string]interface{}{
  8526. "list": patients,
  8527. "list_two": patients_two,
  8528. })
  8529. }
  8530. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8531. record_date := c.GetString("record_date")
  8532. timeLayout := "2006-01-02"
  8533. loc, _ := time.LoadLocation("Local")
  8534. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8535. if err != nil {
  8536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8537. return
  8538. }
  8539. recordDateTime := theTime.Unix()
  8540. adminUser := c.GetAdminUserInfo()
  8541. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8542. var patients []*service.Patients
  8543. for _, item := range tempPatients {
  8544. if item.HisPatient.ID == 0 {
  8545. patients = append(patients, item)
  8546. }
  8547. }
  8548. c.ServeSuccessJSON(map[string]interface{}{
  8549. "list": patients,
  8550. //"list_two": patients_two,
  8551. })
  8552. }
  8553. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8554. newArr = make([]*service.Patients, 0)
  8555. for i := 0; i < len(patient); i++ {
  8556. repeat := false
  8557. for j := i + 1; j < len(patient); j++ {
  8558. if patient[i].ID == patient[j].ID {
  8559. repeat = true
  8560. break
  8561. }
  8562. }
  8563. if !repeat {
  8564. newArr = append(newArr, patient[i])
  8565. }
  8566. }
  8567. return
  8568. }
  8569. func (c *HisApiController) GetHisChargePatientInfo() {
  8570. patient_id, _ := c.GetInt64("patient_id")
  8571. his_patient_id, _ := c.GetInt64("his_patient_id")
  8572. record_date := c.GetString("record_date")
  8573. //start_time := c.GetString("start_time")
  8574. //end_time := c.GetString("end_time")
  8575. order_status, _ := c.GetInt64("type", 0)
  8576. p_type, _ := c.GetInt64("p_type", 0)
  8577. order_id, _ := c.GetInt64("order_id", 0)
  8578. timeLayout := "2006-01-02"
  8579. loc, _ := time.LoadLocation("Local")
  8580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8581. if err != nil {
  8582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8583. return
  8584. }
  8585. recordDateTime := theTime.Unix()
  8586. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8587. //if err != nil {
  8588. //
  8589. //}
  8590. //startRecordDateTime := startTime.Unix()
  8591. //
  8592. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8593. //if err != nil {
  8594. //
  8595. //}
  8596. //endRecordDateTime := endTime.Unix()
  8597. admin := c.GetAdminUserInfo()
  8598. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8599. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8600. var prescriptions []*models.HisPrescription
  8601. //var unChargeMonthPrescriptions []*models.HisPrescription
  8602. order, _ := service.GetHisOrderByID(order_id)
  8603. if order_status == 1 || order_status == 0 {
  8604. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8605. } else if order_status == 2 {
  8606. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8607. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8608. }
  8609. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8610. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8611. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8612. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8613. //获取所有科室信息
  8614. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8615. c.ServeSuccessJSON(map[string]interface{}{
  8616. "his_info": his_patient_info,
  8617. "xt_info": xt_patient_info,
  8618. "prescription": prescriptions,
  8619. "case_history": case_history,
  8620. "info": patientPrescriptionInfo,
  8621. "last_info": lastPatientPrescriptionInfo,
  8622. "order": order,
  8623. "doctors": doctors,
  8624. "department": department,
  8625. })
  8626. return
  8627. }
  8628. func (c *HisApiController) GetAllOrderDetail() {
  8629. order_id, _ := c.GetInt64("id", 0)
  8630. order, _ := service.GetHisOrderByID(order_id)
  8631. if order.ID == 0 {
  8632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8633. return
  8634. }
  8635. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8636. org_id := c.GetAdminUserInfo().CurrentOrgId
  8637. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8638. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8639. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8640. c.ServeSuccessJSON(map[string]interface{}{
  8641. "order": order,
  8642. "order_info": order_info,
  8643. "patient": patient,
  8644. "admin_info": adminInfo,
  8645. "hospital_record": record,
  8646. })
  8647. return
  8648. }
  8649. func (c *HisApiController) GetAllOrderDetailCollect() {
  8650. order_id, _ := c.GetInt64("id", 0)
  8651. order, _ := service.GetHisOrderByID(order_id)
  8652. if order.ID == 0 {
  8653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8654. return
  8655. }
  8656. org_id := c.GetAdminUserInfo().CurrentOrgId
  8657. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8658. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8659. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8660. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8661. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8662. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8663. var bedCostTotal float64 = 0 //床位总费
  8664. //var bedCostSelfTotal float64 = 0 //床位自费
  8665. var operationCostTotal float64 = 0 //手术费
  8666. //var operationCostSelfTotal float64 = 0 //手术费
  8667. var otherCostTotal float64 = 0 //其他费用
  8668. //var otherCostSelfTotal float64 = 0 //其他费用
  8669. var materialCostTotal float64 = 0 //材料费
  8670. //var materialCostSelfTotal float64 = 0 //材料费
  8671. var westernMedicineCostTotal float64 = 0 //西药费
  8672. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8673. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8674. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8675. var checkCostTotal float64 = 0 //检查费
  8676. //var checkCostSelfTotal float64 = 0 //检查费
  8677. var laboratoryCostTotal float64 = 0 //化验费
  8678. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8679. var treatCostTotal float64 = 0 //治疗费用
  8680. //var treatCostSelfTotal float64 = 0 //治疗费用
  8681. var zhenChaCostTotal float64 = 0 //其他费用
  8682. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8683. decimal.DivisionPrecision = 2
  8684. var BalanceAccountsType int64
  8685. if his.ID > 0 {
  8686. BalanceAccountsType = his.BalanceAccountsType
  8687. } else {
  8688. BalanceAccountsType = record.BalanceAccountsType
  8689. }
  8690. if BalanceAccountsType != 2 {
  8691. for _, item := range order_info {
  8692. if org_id == 10215 {
  8693. if item.MedChrgitmType == "01" { //床位费
  8694. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8695. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8696. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8697. }
  8698. if item.MedChrgitmType == "02" { //诊察费
  8699. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8700. //zhenChaCostSelfTotal = zhenChaCostTotal
  8701. }
  8702. if item.MedChrgitmType == "03" { //检查费
  8703. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8704. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8705. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8706. }
  8707. //if item.MedChrgitmType == "02" { //检查费
  8708. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8709. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8710. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8711. //}
  8712. if item.MedChrgitmType == "04" { //化验费
  8713. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8714. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8715. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8716. }
  8717. if item.MedChrgitmType == "05" { //治疗费
  8718. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8719. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8720. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8721. }
  8722. if item.MedChrgitmType == "06" { //手术费
  8723. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8724. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8725. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8726. }
  8727. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8728. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8729. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8730. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8731. }
  8732. if item.MedChrgitmType == "09" { //西药费
  8733. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8734. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8735. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8736. }
  8737. if item.MedChrgitmType == "11" { //中成费
  8738. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8739. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8740. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8741. }
  8742. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8743. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8744. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8745. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8746. }
  8747. } else if org_id == 10188 || org_id == 10217 {
  8748. if item.MedChrgitmType == "01" { //床位费
  8749. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8750. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8751. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8752. }
  8753. if item.MedChrgitmType == "02" { //诊察费
  8754. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. //zhenChaCostSelfTotal = zhenChaCostTotal
  8756. }
  8757. if item.MedChrgitmType == "03" { //检查费
  8758. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8759. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8760. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8761. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8762. }
  8763. //if item.MedChrgitmType == "02" { //检查费
  8764. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8765. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8766. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8767. //}
  8768. if item.MedChrgitmType == "04" { //化验费
  8769. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8770. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8771. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8772. }
  8773. if item.MedChrgitmType == "05" { //治疗费
  8774. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8775. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8776. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8777. }
  8778. if item.MedChrgitmType == "06" { //手术费
  8779. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8780. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8781. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8782. }
  8783. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8784. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8785. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8786. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8787. }
  8788. if item.MedChrgitmType == "09" { //西药费
  8789. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8790. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8791. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8792. }
  8793. if item.MedChrgitmType == "11" { //中成费
  8794. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8796. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8797. }
  8798. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8799. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8800. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8801. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8802. }
  8803. } else {
  8804. if item.MedChrgitmType == "01" { //床位费
  8805. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8806. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8807. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8808. }
  8809. //if item.MedChrgitmType == "02" { //诊察费
  8810. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8811. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8812. //}
  8813. if item.MedChrgitmType == "03" { //检查费
  8814. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8815. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8816. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8817. }
  8818. //if item.MedChrgitmType == "02" { //检查费
  8819. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8820. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8821. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8822. //}
  8823. if item.MedChrgitmType == "04" { //化验费
  8824. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8825. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8826. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8827. }
  8828. if item.MedChrgitmType == "05" { //治疗费
  8829. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8830. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8831. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8832. }
  8833. if item.MedChrgitmType == "06" { //手术费
  8834. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8835. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8836. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8837. }
  8838. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8839. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8840. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8841. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8842. }
  8843. if item.MedChrgitmType == "09" { //西药费
  8844. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8845. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8846. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8847. }
  8848. if item.MedChrgitmType == "11" { //中成费
  8849. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8851. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8852. }
  8853. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8854. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8856. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8857. }
  8858. }
  8859. }
  8860. c.ServeSuccessJSON(map[string]interface{}{
  8861. "order": order,
  8862. "order_info": order_info,
  8863. "patient": patient,
  8864. "admin_info": adminInfo,
  8865. "his_hospital": record,
  8866. "bedCostTotal": bedCostTotal,
  8867. "operationCostTotal": operationCostTotal,
  8868. "otherCostTotal": otherCostTotal,
  8869. "materialCostTotal": materialCostTotal,
  8870. "westernMedicineCostTotal": westernMedicineCostTotal,
  8871. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8872. "checkCostTotal": checkCostTotal,
  8873. "zhenChaCostTotal": zhenChaCostTotal,
  8874. "laboratoryCostTotal": laboratoryCostTotal,
  8875. "treatCostTotal": treatCostTotal,
  8876. })
  8877. } else {
  8878. for _, item := range order_info {
  8879. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8880. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8881. item.MedChrgitmType = "09"
  8882. }
  8883. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8884. if item.HisPrescriptionProject.Type == 2 {
  8885. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8886. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8887. case 0:
  8888. item.MedChrgitmType = "0"
  8889. break
  8890. case 1:
  8891. item.MedChrgitmType = "14"
  8892. break
  8893. case 2:
  8894. item.MedChrgitmType = "05"
  8895. break
  8896. case 3:
  8897. item.MedChrgitmType = "03"
  8898. break
  8899. case 4:
  8900. item.MedChrgitmType = "03"
  8901. break
  8902. case 5:
  8903. item.MedChrgitmType = "08"
  8904. break
  8905. case 6:
  8906. item.MedChrgitmType = "14"
  8907. break
  8908. case 7:
  8909. item.MedChrgitmType = "14"
  8910. break
  8911. case 8:
  8912. item.MedChrgitmType = "03"
  8913. break
  8914. case 9:
  8915. item.MedChrgitmType = "14"
  8916. break
  8917. case 10:
  8918. item.MedChrgitmType = "14"
  8919. break
  8920. case 11:
  8921. item.MedChrgitmType = "06"
  8922. break
  8923. case 12:
  8924. item.MedChrgitmType = "12"
  8925. break
  8926. case 13:
  8927. item.MedChrgitmType = "01"
  8928. break
  8929. case 14:
  8930. item.MedChrgitmType = "04"
  8931. break
  8932. case 15:
  8933. item.MedChrgitmType = "14"
  8934. break
  8935. }
  8936. } else {
  8937. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8938. case 1:
  8939. item.MedChrgitmType = "14"
  8940. break
  8941. case 2:
  8942. item.MedChrgitmType = "05"
  8943. break
  8944. case 3:
  8945. item.MedChrgitmType = "04"
  8946. break
  8947. case 4:
  8948. item.MedChrgitmType = "14"
  8949. break
  8950. case 5:
  8951. item.MedChrgitmType = "08"
  8952. break
  8953. case 6:
  8954. item.MedChrgitmType = "14"
  8955. break
  8956. case 7:
  8957. item.MedChrgitmType = "14"
  8958. break
  8959. case 8:
  8960. item.MedChrgitmType = "03"
  8961. break
  8962. case 9:
  8963. item.MedChrgitmType = "14"
  8964. break
  8965. }
  8966. }
  8967. } else if item.HisPrescriptionProject.Type == 3 {
  8968. item.MedChrgitmType = "08"
  8969. }
  8970. }
  8971. }
  8972. for _, item := range order_info {
  8973. if org_id == 10215 {
  8974. if item.MedChrgitmType == "01" { //床位费
  8975. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8976. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8977. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8978. }
  8979. if item.MedChrgitmType == "02" { //诊察费
  8980. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8981. //zhenChaCostSelfTotal = zhenChaCostTotal
  8982. }
  8983. if item.MedChrgitmType == "03" { //检查费
  8984. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8985. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8986. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8987. }
  8988. //if item.MedChrgitmType == "02" { //检查费
  8989. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8990. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8991. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8992. //}
  8993. if item.MedChrgitmType == "04" { //化验费
  8994. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8995. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8996. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8997. }
  8998. if item.MedChrgitmType == "05" { //治疗费
  8999. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9000. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9001. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9002. }
  9003. if item.MedChrgitmType == "06" { //手术费
  9004. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9005. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9006. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9007. }
  9008. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9009. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9010. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9011. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9012. }
  9013. if item.MedChrgitmType == "09" { //西药费
  9014. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9015. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9016. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9017. }
  9018. if item.MedChrgitmType == "11" { //中成费
  9019. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9020. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9021. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9022. }
  9023. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9024. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9025. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9026. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9027. }
  9028. } else {
  9029. if item.MedChrgitmType == "01" { //床位费
  9030. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9031. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9032. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9033. }
  9034. //if item.MedChrgitmType == "02" { //诊察费
  9035. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9036. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9037. //}
  9038. if item.MedChrgitmType == "03" { //检查费
  9039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9042. }
  9043. //if item.MedChrgitmType == "02" { //检查费
  9044. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9045. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9046. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9047. //}
  9048. if item.MedChrgitmType == "04" { //化验费
  9049. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9050. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9051. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9052. }
  9053. if item.MedChrgitmType == "05" { //治疗费
  9054. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9055. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9056. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9057. }
  9058. if item.MedChrgitmType == "06" { //手术费
  9059. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9060. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9061. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9062. }
  9063. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9064. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9065. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9066. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9067. }
  9068. if item.MedChrgitmType == "09" { //西药费
  9069. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9070. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9071. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9072. }
  9073. if item.MedChrgitmType == "11" { //中成费
  9074. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9075. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9076. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9077. }
  9078. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9079. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9080. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9081. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9082. }
  9083. }
  9084. }
  9085. c.ServeSuccessJSON(map[string]interface{}{
  9086. "order": order,
  9087. "order_info": order_info,
  9088. "patient": patient,
  9089. "admin_info": adminInfo,
  9090. "his_hospital": record,
  9091. "bedCostTotal": bedCostTotal,
  9092. "operationCostTotal": operationCostTotal,
  9093. "otherCostTotal": otherCostTotal,
  9094. "materialCostTotal": materialCostTotal,
  9095. "westernMedicineCostTotal": westernMedicineCostTotal,
  9096. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9097. "checkCostTotal": checkCostTotal,
  9098. "zhenChaCostTotal": zhenChaCostTotal,
  9099. "laboratoryCostTotal": laboratoryCostTotal,
  9100. "treatCostTotal": treatCostTotal,
  9101. })
  9102. }
  9103. }
  9104. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9105. page, _ := c.GetInt64("page")
  9106. limit, _ := c.GetInt64("limit")
  9107. keywords := c.GetString("keywords")
  9108. start_time := c.GetString("start_time")
  9109. end_time := c.GetString("end_time")
  9110. //clr_type := c.GetString("clr_type")
  9111. insutype := c.GetString("insutype")
  9112. timeLayout := "2006-01-02"
  9113. loc, _ := time.LoadLocation("Local")
  9114. var theStartTIme int64
  9115. if len(start_time) > 0 {
  9116. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9117. theStartTIme = theTime.Unix()
  9118. }
  9119. var theEndtTIme int64
  9120. if len(end_time) > 0 {
  9121. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9122. theEndtTIme = theTime.Unix()
  9123. }
  9124. if page <= 0 {
  9125. page = 1
  9126. }
  9127. if limit <= 0 {
  9128. limit = 10
  9129. }
  9130. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9131. c.ServeSuccessJSON(map[string]interface{}{
  9132. "total": total,
  9133. "list": list,
  9134. })
  9135. return
  9136. }
  9137. func (c *HisApiController) GetPutOnRecordList() {
  9138. page, _ := c.GetInt64("page")
  9139. limit, _ := c.GetInt64("limit")
  9140. keywords := c.GetString("keywords")
  9141. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9142. if page <= 0 {
  9143. page = 1
  9144. }
  9145. if limit <= 0 {
  9146. limit = 10
  9147. }
  9148. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9149. c.ServeSuccessJSON(map[string]interface{}{
  9150. "total": total,
  9151. "list": list,
  9152. })
  9153. return
  9154. }
  9155. func (c *HisApiController) GetCompareData() {
  9156. start_time := c.GetString("start_time")
  9157. end_time := c.GetString("end_time")
  9158. insutype := c.GetString("insutype")
  9159. clr_type := c.GetString("clr_type")
  9160. timeLayout := "2006-01-02"
  9161. loc, _ := time.LoadLocation("Local")
  9162. var theStartTIme int64
  9163. if len(start_time) > 0 {
  9164. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9165. if err != nil {
  9166. theStartTIme = 0
  9167. }
  9168. theStartTIme = theTime.Unix()
  9169. }
  9170. var theEndtTIme int64
  9171. if len(end_time) > 0 {
  9172. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9173. if err != nil {
  9174. theEndtTIme = 0
  9175. }
  9176. theEndtTIme = theTime.Unix()
  9177. }
  9178. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9179. fmt.Println(err)
  9180. if err == nil {
  9181. c.ServeSuccessJSON(map[string]interface{}{
  9182. "list": formData,
  9183. })
  9184. } else {
  9185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9186. return
  9187. }
  9188. }
  9189. func (c *HisApiController) GetFaPiaoData() {
  9190. order_id, _ := c.GetInt64("order_id")
  9191. patient_id, _ := c.GetInt64("patient_id")
  9192. //number := c.GetString("number")
  9193. adminUser := c.GetAdminUserInfo()
  9194. order, _ := service.GetHisOrderByID(order_id)
  9195. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9196. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9197. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9198. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9199. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9200. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9201. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9202. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9203. var bedCostTotal float64 = 0 //床位总费
  9204. var bedCostSelfTotal float64 = 0 //床位自费
  9205. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9206. var operationCostTotal float64 = 0 //手术费
  9207. var operationCostSelfTotal float64 = 0 //手术费
  9208. var operationCostPartSelfTotal float64 = 0 //手术费
  9209. var otherCostTotal float64 = 0 //其他费用
  9210. var otherCostSelfTotal float64 = 0 //其他费用
  9211. var otherCostPartSelfTotal float64 = 0 //其他费用
  9212. var materialCostTotal float64 = 0 //材料费
  9213. var materialCostSelfTotal float64 = 0 //材料费
  9214. var materialCostPartSelfTotal float64 = 0 //材料费
  9215. var westernMedicineCostTotal float64 = 0 //西药费
  9216. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9217. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9218. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9219. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9220. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9221. var checkCostTotal float64 = 0 //检查费
  9222. var checkCostSelfTotal float64 = 0 //检查费
  9223. var checkCostPartSelfTotal float64 = 0 //检查费
  9224. var hiliCostTotal float64 = 0 //护理费
  9225. var hiliCostSelfTotal float64 = 0 //护理费
  9226. var hiliCostPartSelfTotal float64 = 0 //护理费
  9227. var laboratoryCostTotal float64 = 0 //化验费
  9228. var laboratoryCostSelfTotal float64 = 0 //化验费
  9229. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9230. var treatCostTotal float64 = 0 //治疗费用
  9231. var treatCostSelfTotal float64 = 0 //治疗费用
  9232. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9233. var zhenChaCostTotal float64 = 0 //其他费用
  9234. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9235. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9236. decimal.DivisionPrecision = 2
  9237. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9238. var balanceAccountsType int64
  9239. if his.ID > 0 {
  9240. balanceAccountsType = his.BalanceAccountsType
  9241. } else {
  9242. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9243. }
  9244. if balanceAccountsType == 2 {
  9245. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9246. for _, item := range orderInfos_two {
  9247. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9248. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9249. item.MedChrgitmType = "09"
  9250. }
  9251. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9252. if item.HisPrescriptionProject.Type == 2 {
  9253. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9254. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9255. case 0:
  9256. item.MedChrgitmType = "0"
  9257. break
  9258. case 1:
  9259. item.MedChrgitmType = "14"
  9260. break
  9261. case 2:
  9262. item.MedChrgitmType = "05"
  9263. break
  9264. case 3:
  9265. item.MedChrgitmType = "03"
  9266. break
  9267. case 4:
  9268. item.MedChrgitmType = "03"
  9269. break
  9270. case 5:
  9271. item.MedChrgitmType = "08"
  9272. break
  9273. case 6:
  9274. item.MedChrgitmType = "14"
  9275. break
  9276. case 7:
  9277. item.MedChrgitmType = "14"
  9278. break
  9279. case 8:
  9280. item.MedChrgitmType = "03"
  9281. break
  9282. case 9:
  9283. item.MedChrgitmType = "14"
  9284. break
  9285. case 10:
  9286. item.MedChrgitmType = "14"
  9287. break
  9288. case 11:
  9289. item.MedChrgitmType = "06"
  9290. break
  9291. case 12:
  9292. item.MedChrgitmType = "12"
  9293. break
  9294. case 13:
  9295. item.MedChrgitmType = "01"
  9296. break
  9297. case 14:
  9298. item.MedChrgitmType = "04"
  9299. break
  9300. case 15:
  9301. item.MedChrgitmType = "02"
  9302. break
  9303. }
  9304. } else {
  9305. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9306. case 1:
  9307. item.MedChrgitmType = "14"
  9308. break
  9309. case 2:
  9310. item.MedChrgitmType = "05"
  9311. break
  9312. case 3:
  9313. item.MedChrgitmType = "03"
  9314. break
  9315. case 4:
  9316. item.MedChrgitmType = "03"
  9317. break
  9318. case 5:
  9319. item.MedChrgitmType = "08"
  9320. break
  9321. case 6:
  9322. item.MedChrgitmType = "14"
  9323. break
  9324. case 7:
  9325. item.MedChrgitmType = "14"
  9326. break
  9327. case 8:
  9328. item.MedChrgitmType = "03"
  9329. break
  9330. case 9:
  9331. item.MedChrgitmType = "14"
  9332. break
  9333. }
  9334. }
  9335. } else if item.HisPrescriptionProject.Type == 3 {
  9336. item.MedChrgitmType = "08"
  9337. }
  9338. }
  9339. }
  9340. for _, item := range orderInfos_two {
  9341. fmt.Println(item.MedChrgitmType)
  9342. if item.MedChrgitmType == "07" { //床位费
  9343. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9344. hiliCostSelfTotal = hiliCostTotal
  9345. }
  9346. if item.MedChrgitmType == "01" { //床位费
  9347. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9348. bedCostSelfTotal = bedCostTotal
  9349. }
  9350. if item.MedChrgitmType == "02" { //诊察费
  9351. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9352. zhenChaCostSelfTotal = zhenChaCostTotal
  9353. }
  9354. if item.MedChrgitmType == "03" { //检查费
  9355. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9356. checkCostSelfTotal = checkCostTotal
  9357. }
  9358. if item.MedChrgitmType == "04" { //化验费
  9359. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9360. laboratoryCostSelfTotal = laboratoryCostTotal
  9361. }
  9362. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9363. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9364. treatCostSelfTotal = treatCostTotal
  9365. }
  9366. if item.MedChrgitmType == "06" { //手术费
  9367. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9368. operationCostSelfTotal = treatCostTotal
  9369. }
  9370. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9371. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9372. materialCostSelfTotal = materialCostTotal
  9373. }
  9374. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9375. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9376. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9377. }
  9378. if item.MedChrgitmType == "11" { //中成费
  9379. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9380. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9381. }
  9382. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9383. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9384. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9385. otherCostSelfTotal = otherCostTotal
  9386. }
  9387. } else {
  9388. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9389. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9390. otherCostSelfTotal = otherCostTotal
  9391. }
  9392. }
  9393. }
  9394. } else {
  9395. for _, item := range orderInfos {
  9396. if item.MedChrgitmType == "01" { //床位费
  9397. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9398. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9399. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9400. }
  9401. if item.MedChrgitmType == "02" { //诊察费
  9402. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9403. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9404. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9405. }
  9406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9407. if item.MedChrgitmType == "03" { //检查费
  9408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9411. }
  9412. } else {
  9413. if item.MedChrgitmType == "03" { //检查费
  9414. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9415. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9416. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9417. }
  9418. }
  9419. if item.MedChrgitmType == "04" { //化验费
  9420. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9421. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9422. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9423. }
  9424. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9428. }
  9429. if item.MedChrgitmType == "06" { //手术费
  9430. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9431. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9432. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9433. }
  9434. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9435. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9436. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9437. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9438. }
  9439. if item.MedChrgitmType == "07" { //护理
  9440. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9441. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9442. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9443. }
  9444. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9445. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9446. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9447. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9448. }
  9449. if item.MedChrgitmType == "11" { //中成费
  9450. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9452. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9453. }
  9454. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9455. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9456. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9457. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9458. }
  9459. }
  9460. }
  9461. timeLayout := "2006-01-02"
  9462. loc, _ := time.LoadLocation("Local")
  9463. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9464. if err != nil {
  9465. }
  9466. startRecordDateTime := startTime.Unix()
  9467. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9468. if err != nil {
  9469. }
  9470. endRecordDateTime := endTime.Unix()
  9471. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9472. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9473. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9474. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9475. c.ServeSuccessJSON(map[string]interface{}{
  9476. "charge_admin_name": charge_admin.UserName,
  9477. "order_number": order.Number, //业务流水号
  9478. "id_card_no": his.IdCardNo, //社会保障号
  9479. "patient": patient,
  9480. "department_name": department.Name, //科室
  9481. "number": his.Number, //门诊号
  9482. "date": order.SettleAccountsDate, //结算日期
  9483. "name": order.PsnName, //姓名
  9484. "gender": patient.Gender, //性别
  9485. "psn_cash_money": order.PsnCashPay, //个人支付
  9486. "pay_way": "门诊", //结算方式
  9487. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9488. "admin_user_name": admin.UserName, //收款员
  9489. "order": order,
  9490. "order_info": orderInfos_two,
  9491. "his": his,
  9492. "bedCostTotal": bedCostTotal,
  9493. "bedCostSelfTotal": bedCostSelfTotal,
  9494. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9495. "operationCostTotal": operationCostTotal,
  9496. "operationCostSelfTotal": operationCostSelfTotal,
  9497. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9498. "otherCostTotal": otherCostTotal,
  9499. "otherCostSelfTotal": otherCostSelfTotal,
  9500. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9501. "materialCostTotal": materialCostTotal,
  9502. "materialCostSelfTotal": materialCostSelfTotal,
  9503. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9504. "westernMedicineCostTotal": westernMedicineCostTotal,
  9505. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9506. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9507. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9508. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9509. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9510. "checkCostTotal": checkCostTotal,
  9511. "checkCostSelfTotal": checkCostSelfTotal,
  9512. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9513. "laboratoryCostTotal": laboratoryCostTotal,
  9514. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9515. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9516. "treatCostTotal": treatCostTotal,
  9517. "treatCostSelfTotal": treatCostSelfTotal,
  9518. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9519. "zhenChaCostTotal": zhenChaCostTotal,
  9520. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9521. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9522. "his_hospital_record": his_hospital_record,
  9523. "pre_pay_money": pre_pay_money,
  9524. "refund_sum": sum,
  9525. "doctor_info": doctor_info,
  9526. "hiliCostTotal": hiliCostTotal,
  9527. "hiliCostSelfTotal": hiliCostSelfTotal,
  9528. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9529. })
  9530. }
  9531. //func (c *HisApiController) GetFaPiaoDatas() {
  9532. // order_ids := c.GetString("order_ids")
  9533. // patient_id, _ := c.GetInt64("patient_id")
  9534. // adminUser := c.GetAdminUserInfo()
  9535. //
  9536. // orders := strings.Split(order_ids, ",")
  9537. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9538. //
  9539. // for _, item := range orders {
  9540. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9541. // order, _ := service.GetHisOrderByID(order_id)
  9542. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9543. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9544. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9545. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9546. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9547. //
  9548. // }
  9549. //
  9550. // var bedCostTotal float64 = 0 //床位总费
  9551. // var bedCostSelfTotal float64 = 0 //床位自费
  9552. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9553. //
  9554. // var operationCostTotal float64 = 0 //手术费
  9555. // var operationCostSelfTotal float64 = 0 //手术费
  9556. // var operationCostPartSelfTotal float64 = 0 //手术费
  9557. //
  9558. // var otherCostTotal float64 = 0 //其他费用
  9559. // var otherCostSelfTotal float64 = 0 //其他费用
  9560. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9561. //
  9562. // var materialCostTotal float64 = 0 //材料费
  9563. // var materialCostSelfTotal float64 = 0 //材料费
  9564. // var materialCostPartSelfTotal float64 = 0 //材料费
  9565. //
  9566. // var westernMedicineCostTotal float64 = 0 //西药费
  9567. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9568. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9569. //
  9570. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9571. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9572. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9573. //
  9574. // var checkCostTotal float64 = 0 //检查费
  9575. // var checkCostSelfTotal float64 = 0 //检查费
  9576. // var checkCostPartSelfTotal float64 = 0 //检查费
  9577. //
  9578. // var laboratoryCostTotal float64 = 0 //化验费
  9579. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9580. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9581. //
  9582. // var treatCostTotal float64 = 0 //治疗费用
  9583. // var treatCostSelfTotal float64 = 0 //治疗费用
  9584. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9585. //
  9586. // var zhenChaCostTotal float64 = 0 //其他费用
  9587. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9588. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9589. //
  9590. // decimal.DivisionPrecision = 2
  9591. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9592. //
  9593. // var balanceAccountsType int64
  9594. // if his.ID > 0 {
  9595. // balanceAccountsType = his.BalanceAccountsType
  9596. // } else {
  9597. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9598. // }
  9599. // if balanceAccountsType == 2 {
  9600. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9601. // for _, item := range orderInfos_two {
  9602. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9603. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9604. // item.MedChrgitmType = "09"
  9605. // }
  9606. //
  9607. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9608. // if item.HisPrescriptionProject.Type == 2 {
  9609. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9610. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9611. // case 0:
  9612. // item.MedChrgitmType = "0"
  9613. // break
  9614. // case 1:
  9615. // item.MedChrgitmType = "14"
  9616. // break
  9617. // case 2:
  9618. // item.MedChrgitmType = "05"
  9619. //
  9620. // break
  9621. // case 3:
  9622. // item.MedChrgitmType = "03"
  9623. //
  9624. // break
  9625. // case 4:
  9626. // item.MedChrgitmType = "03"
  9627. //
  9628. // break
  9629. // case 5:
  9630. // item.MedChrgitmType = "08"
  9631. //
  9632. // break
  9633. // case 6:
  9634. // item.MedChrgitmType = "14"
  9635. //
  9636. // break
  9637. // case 7:
  9638. // item.MedChrgitmType = "14"
  9639. //
  9640. // break
  9641. // case 8:
  9642. // item.MedChrgitmType = "03"
  9643. // break
  9644. // case 9:
  9645. // item.MedChrgitmType = "14"
  9646. // break
  9647. // case 10:
  9648. // item.MedChrgitmType = "14"
  9649. // break
  9650. // case 11:
  9651. // item.MedChrgitmType = "06"
  9652. // break
  9653. // case 12:
  9654. // item.MedChrgitmType = "12"
  9655. // break
  9656. // case 13:
  9657. // item.MedChrgitmType = "01"
  9658. // break
  9659. // case 14:
  9660. // item.MedChrgitmType = "04"
  9661. // break
  9662. // case 15:
  9663. // item.MedChrgitmType = "02"
  9664. // break
  9665. //
  9666. // }
  9667. //
  9668. // } else {
  9669. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9670. //
  9671. // case 1:
  9672. // item.MedChrgitmType = "14"
  9673. // break
  9674. // case 2:
  9675. // item.MedChrgitmType = "05"
  9676. //
  9677. // break
  9678. // case 3:
  9679. // item.MedChrgitmType = "03"
  9680. //
  9681. // break
  9682. // case 4:
  9683. // item.MedChrgitmType = "03"
  9684. //
  9685. // break
  9686. // case 5:
  9687. // item.MedChrgitmType = "08"
  9688. //
  9689. // break
  9690. // case 6:
  9691. // item.MedChrgitmType = "14"
  9692. //
  9693. // break
  9694. // case 7:
  9695. // item.MedChrgitmType = "14"
  9696. //
  9697. // break
  9698. // case 8:
  9699. // item.MedChrgitmType = "03"
  9700. // break
  9701. // case 9:
  9702. // item.MedChrgitmType = "14"
  9703. // break
  9704. //
  9705. // }
  9706. //
  9707. // }
  9708. //
  9709. // } else if item.HisPrescriptionProject.Type == 3 {
  9710. // item.MedChrgitmType = "08"
  9711. // }
  9712. // }
  9713. // }
  9714. //
  9715. // for _, item := range orderInfos_two {
  9716. // fmt.Println(item.MedChrgitmType)
  9717. // if item.MedChrgitmType == "01" { //床位费
  9718. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. // bedCostSelfTotal = bedCostTotal
  9720. // }
  9721. //
  9722. // if item.MedChrgitmType == "02" { //诊察费
  9723. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. // zhenChaCostSelfTotal = zhenChaCostTotal
  9725. // }
  9726. //
  9727. // if item.MedChrgitmType == "03" { //检查费
  9728. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. // checkCostSelfTotal = checkCostTotal
  9730. // }
  9731. //
  9732. // if item.MedChrgitmType == "04" { //化验费
  9733. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. // laboratoryCostSelfTotal = laboratoryCostTotal
  9735. // }
  9736. //
  9737. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9738. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. // treatCostSelfTotal = treatCostTotal
  9740. // }
  9741. //
  9742. // if item.MedChrgitmType == "06" { //手术费
  9743. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. // operationCostSelfTotal = treatCostTotal
  9745. // }
  9746. //
  9747. // if item.MedChrgitmType == "08" { //材料费
  9748. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. // materialCostSelfTotal = materialCostTotal
  9750. // }
  9751. //
  9752. // if item.MedChrgitmType == "09" { //西药费
  9753. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9755. // }
  9756. //
  9757. // if item.MedChrgitmType == "11" { //中成费
  9758. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9759. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9760. // }
  9761. //
  9762. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9763. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9764. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. // otherCostSelfTotal = otherCostTotal
  9766. // }
  9767. // } else {
  9768. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9769. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. // otherCostSelfTotal = otherCostTotal
  9771. // }
  9772. //
  9773. // }
  9774. //
  9775. // }
  9776. //
  9777. // } else {
  9778. // for _, item := range orderInfos {
  9779. // if item.MedChrgitmType == "01" { //床位费
  9780. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. // }
  9784. //
  9785. // if item.MedChrgitmType == "02" { //诊察费
  9786. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9787. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9788. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9789. // }
  9790. //
  9791. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9792. // if item.MedChrgitmType == "03" { //检查费
  9793. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9794. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9795. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9796. //
  9797. // }
  9798. // } else {
  9799. // if item.MedChrgitmType == "03" { //检查费
  9800. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9801. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9802. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9803. // }
  9804. //
  9805. // }
  9806. //
  9807. // if item.MedChrgitmType == "04" { //化验费
  9808. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9809. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9810. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9811. //
  9812. // }
  9813. //
  9814. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9815. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9816. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9817. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9818. //
  9819. // }
  9820. //
  9821. // if item.MedChrgitmType == "06" { //手术费
  9822. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9823. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9824. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9825. // }
  9826. //
  9827. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9828. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9829. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9830. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9831. // }
  9832. //
  9833. // if item.MedChrgitmType == "09" { //西药费
  9834. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9835. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9836. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9837. // }
  9838. //
  9839. // if item.MedChrgitmType == "11" { //中成费
  9840. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9841. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9842. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9843. // }
  9844. //
  9845. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9846. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9847. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9848. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9849. // }
  9850. //
  9851. // }
  9852. // }
  9853. // timeLayout := "2006-01-02"
  9854. // loc, _ := time.LoadLocation("Local")
  9855. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9856. // if err != nil {
  9857. // }
  9858. // startRecordDateTime := startTime.Unix()
  9859. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9860. // if err != nil {
  9861. // }
  9862. // endRecordDateTime := endTime.Unix()
  9863. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9864. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9865. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9866. //
  9867. // c.ServeSuccessJSON(map[string]interface{}{
  9868. // "order_number": order.Number, //业务流水号
  9869. // "id_card_no": his.IdCardNo, //社会保障号
  9870. // "department_name": department.Name, //科室
  9871. // "number": his.Number, //门诊号
  9872. // "date": order.SettleAccountsDate, //结算日期
  9873. // "name": order.PsnName, //姓名
  9874. // "gender": patient.Gender, //性别
  9875. // "psn_cash_money": order.PsnCashPay, //个人支付
  9876. // "pay_way": "门诊", //结算方式
  9877. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9878. // "admin_user_name": admin.UserName, //收款员
  9879. // "order": order,
  9880. // "order_info": orderInfos_two,
  9881. // "his": his,
  9882. // "bedCostTotal": bedCostTotal,
  9883. // "bedCostSelfTotal": bedCostSelfTotal,
  9884. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9885. // "operationCostTotal": operationCostTotal,
  9886. // "operationCostSelfTotal": operationCostSelfTotal,
  9887. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9888. // "otherCostTotal": otherCostTotal,
  9889. // "otherCostSelfTotal": otherCostSelfTotal,
  9890. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9891. // "materialCostTotal": materialCostTotal,
  9892. // "materialCostSelfTotal": materialCostSelfTotal,
  9893. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9894. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9895. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9896. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9897. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9898. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9899. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9900. // "checkCostTotal": checkCostTotal,
  9901. // "checkCostSelfTotal": checkCostSelfTotal,
  9902. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9903. // "laboratoryCostTotal": laboratoryCostTotal,
  9904. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9905. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9906. // "treatCostTotal": treatCostTotal,
  9907. // "treatCostSelfTotal": treatCostSelfTotal,
  9908. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9909. // "zhenChaCostTotal": zhenChaCostTotal,
  9910. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9911. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9912. // "his_hospital_record": his_hospital_record,
  9913. // "pre_pay_money": pre_pay_money,
  9914. // "refund_sum": sum,
  9915. // })
  9916. //
  9917. //}
  9918. func (this *HisApiController) GetIncomeStatisticsData() {
  9919. start_time := this.GetString("start_time")
  9920. end_time := this.GetString("end_time")
  9921. key_words := this.GetString("key_words")
  9922. limit, _ := this.GetInt64("limit")
  9923. page, _ := this.GetInt64("page")
  9924. if page <= 0 {
  9925. page = 1
  9926. }
  9927. if limit <= 0 {
  9928. limit = 10
  9929. }
  9930. statistics_type, _ := this.GetInt64("statistics_type")
  9931. admin := this.GetAdminUserInfo()
  9932. timeLayout := "2006-01-02"
  9933. loc, _ := time.LoadLocation("Local")
  9934. var theStartTIme int64
  9935. if len(start_time) > 0 {
  9936. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9937. if err != nil {
  9938. theStartTIme = 0
  9939. }
  9940. theStartTIme = theTime.Unix()
  9941. }
  9942. var theEndtTIme int64
  9943. if len(end_time) > 0 {
  9944. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9945. if err != nil {
  9946. theEndtTIme = 0
  9947. }
  9948. theEndtTIme = theTime.Unix()
  9949. }
  9950. if statistics_type == 1 {
  9951. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9952. this.ServeSuccessJSON(map[string]interface{}{
  9953. "list": list,
  9954. "total": total,
  9955. })
  9956. } else {
  9957. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9958. this.ServeSuccessJSON(map[string]interface{}{
  9959. "list": list,
  9960. "total": total,
  9961. })
  9962. }
  9963. }
  9964. func (c *HisApiController) PostProjectInformation() {
  9965. adminUser := c.GetAdminUserInfo()
  9966. orgId := adminUser.CurrentOrgId
  9967. dataBody := make(map[string]interface{}, 0)
  9968. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9969. if err != nil {
  9970. utils.ErrorLog(err.Error())
  9971. return
  9972. }
  9973. utils.ErrorLog("%v", dataBody)
  9974. var projectList []*models.HisProject
  9975. var total_goods []interface{}
  9976. tempProjects := dataBody["projects"].([]interface{})
  9977. total_goods = tempProjects
  9978. for index, projectMap := range tempProjects {
  9979. projectM := projectMap.(map[string]interface{})
  9980. var project models.HisProject
  9981. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9982. utils.ErrorLog("project_name")
  9983. return
  9984. }
  9985. project_name, _ := projectM["project_name"].(string)
  9986. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9987. err_log := models.ExportErrLog{
  9988. LogType: 6,
  9989. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9990. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9991. Status: 1,
  9992. CreateTime: time.Now().Unix(),
  9993. UpdateTime: time.Now().Unix(),
  9994. ExportTime: time.Now().Unix(),
  9995. }
  9996. service.CreateExportErrLog(&err_log)
  9997. continue
  9998. }
  9999. project.ProjectName = project_name
  10000. prices := projectM["price"].(string)
  10001. price, _ := strconv.ParseFloat(prices, 64)
  10002. if price <= 0 { //名字为空则生成一条导入错误日志
  10003. err_log := models.ExportErrLog{
  10004. LogType: 6,
  10005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10006. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10007. Status: 1,
  10008. CreateTime: time.Now().Unix(),
  10009. UpdateTime: time.Now().Unix(),
  10010. ExportTime: time.Now().Unix(),
  10011. }
  10012. service.CreateExportErrLog(&err_log)
  10013. continue
  10014. }
  10015. project.Price = price
  10016. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10017. utils.ErrorLog("unit_id")
  10018. return
  10019. }
  10020. unit := projectM["unit"].(string)
  10021. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10022. err_log := models.ExportErrLog{
  10023. LogType: 6,
  10024. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10025. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10026. Status: 1,
  10027. CreateTime: time.Now().Unix(),
  10028. UpdateTime: time.Now().Unix(),
  10029. ExportTime: time.Now().Unix(),
  10030. }
  10031. service.CreateExportErrLog(&err_log)
  10032. continue
  10033. }
  10034. project.Unit = unit
  10035. cost_classify := projectM["cost_classify"].(string)
  10036. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10037. err_log := models.ExportErrLog{
  10038. LogType: 6,
  10039. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10040. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10041. Status: 1,
  10042. CreateTime: time.Now().Unix(),
  10043. UpdateTime: time.Now().Unix(),
  10044. ExportTime: time.Now().Unix(),
  10045. }
  10046. service.CreateExportErrLog(&err_log)
  10047. continue
  10048. }
  10049. var costClassify = "费用类别"
  10050. var cost_classify_id int64
  10051. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10052. if len(cost_classify) != 0 {
  10053. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10054. if errcode == gorm.ErrRecordNotFound {
  10055. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10056. dataconfig := models.DictDataconfig{
  10057. ParentId: costClassifyConfig.ID,
  10058. Module: "system",
  10059. OrgId: orgId,
  10060. Name: cost_classify,
  10061. FieldName: "",
  10062. Value: costConfig.Value + 1,
  10063. CreatedTime: "",
  10064. UpdatedTime: "",
  10065. CreateUserId: adminUser.AdminUser.Id,
  10066. Status: 1,
  10067. Remark: "",
  10068. DeleteIdSystem: 0,
  10069. Title: "",
  10070. Content: "",
  10071. Order: 0,
  10072. Code: "",
  10073. }
  10074. service.CreatedDicConfig(&dataconfig)
  10075. }
  10076. }
  10077. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10078. for _, it := range costClassList {
  10079. if cost_classify == it.Name {
  10080. cost_classify_id = int64(it.Value)
  10081. }
  10082. }
  10083. project.CostClassify = cost_classify_id
  10084. executive_section := projectM["executive_section"].(string)
  10085. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10086. err_log := models.ExportErrLog{
  10087. LogType: 6,
  10088. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10089. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10090. Status: 1,
  10091. CreateTime: time.Now().Unix(),
  10092. UpdateTime: time.Now().Unix(),
  10093. ExportTime: time.Now().Unix(),
  10094. }
  10095. service.CreateExportErrLog(&err_log)
  10096. continue
  10097. }
  10098. if len(executive_section) != 0 {
  10099. //查找科室是否有内容
  10100. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10101. if errcodedepart == gorm.ErrRecordNotFound {
  10102. department := models.XtHisDepartment{
  10103. Name: executive_section,
  10104. Status: 1,
  10105. UserOrgId: adminUser.CurrentOrgId,
  10106. CreatedTime: time.Now().Unix(),
  10107. }
  10108. service.CreateDePartment(&department)
  10109. }
  10110. }
  10111. var executive_section_id int64
  10112. departMentList, _ := service.GetAllDepartMent(orgId)
  10113. for _, it := range departMentList {
  10114. if executive_section == it.Name {
  10115. executive_section_id = it.ID
  10116. }
  10117. }
  10118. project.ExecutiveSection = executive_section_id
  10119. medical_coverage := projectM["medical_coverage"].(string)
  10120. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10121. err_log := models.ExportErrLog{
  10122. LogType: 6,
  10123. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10124. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10125. Status: 1,
  10126. CreateTime: time.Now().Unix(),
  10127. UpdateTime: time.Now().Unix(),
  10128. ExportTime: time.Now().Unix(),
  10129. }
  10130. service.CreateExportErrLog(&err_log)
  10131. continue
  10132. }
  10133. var medicalCoverage = "医保等级"
  10134. var medical_coverage_id int64
  10135. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10136. if len(medical_coverage) != 0 {
  10137. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10138. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10139. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10140. dataconfig := models.DictDataconfig{
  10141. ParentId: medicalCoverageConfig.ID,
  10142. Module: "system",
  10143. OrgId: orgId,
  10144. Name: medical_coverage,
  10145. FieldName: "",
  10146. Value: medicalCoverageConfig.Value + 1,
  10147. CreatedTime: "",
  10148. UpdatedTime: "",
  10149. CreateUserId: adminUser.AdminUser.Id,
  10150. Status: 1,
  10151. Remark: "",
  10152. DeleteIdSystem: 0,
  10153. Title: "",
  10154. Content: "",
  10155. Order: 0,
  10156. Code: "",
  10157. }
  10158. service.CreatedDicConfig(&dataconfig)
  10159. }
  10160. }
  10161. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10162. for _, it := range medicalCoverageList {
  10163. if medical_coverage == it.Name {
  10164. medical_coverage_id = int64(it.Value)
  10165. }
  10166. }
  10167. project.MedicalCoverage = medical_coverage_id
  10168. pinyin := projectM["pinyin"].(string)
  10169. project.Pinyin = pinyin
  10170. wubi := projectM["wubi"].(string)
  10171. project.Wubi = wubi
  10172. statistical_classification := projectM["statistical_classification"].(string)
  10173. var statisticalClassification = "统计分类"
  10174. var statistical_classification_id int64
  10175. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10176. if len(statistical_classification) != 0 {
  10177. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10178. if classificationerrcodes == gorm.ErrRecordNotFound {
  10179. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10180. dataconfig := models.DictDataconfig{
  10181. ParentId: classiFication.ID,
  10182. Module: "system",
  10183. OrgId: orgId,
  10184. Name: statistical_classification,
  10185. FieldName: "",
  10186. Value: classiFicationConfig.Value + 1,
  10187. CreatedTime: "",
  10188. UpdatedTime: "",
  10189. CreateUserId: adminUser.AdminUser.Id,
  10190. Status: 1,
  10191. Remark: "",
  10192. DeleteIdSystem: 0,
  10193. Title: "",
  10194. Content: "",
  10195. Order: 0,
  10196. Code: "",
  10197. }
  10198. service.CreatedDicConfig(&dataconfig)
  10199. }
  10200. }
  10201. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10202. for _, it := range classiFicationList {
  10203. if statistical_classification == it.Name {
  10204. statistical_classification_id = int64(it.Value)
  10205. }
  10206. }
  10207. project.StatisticalClassification = statistical_classification_id
  10208. disease_directory := int64(projectM["disease_directory"].(float64))
  10209. project.DiseaseDirectory = disease_directory
  10210. is_record := int64(projectM["is_record"].(float64))
  10211. project.IsRecord = is_record
  10212. medical_code := projectM["medical_code"].(string)
  10213. project.MedicalCode = medical_code
  10214. tube_color := projectM["tube_color"].(string)
  10215. var tubeColor = "试管颜色"
  10216. var tube_color_id int64
  10217. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10218. if len(tube_color) != 0 {
  10219. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10220. if errcodetube == gorm.ErrRecordNotFound {
  10221. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10222. dataconfig := models.DictDataconfig{
  10223. ParentId: tubeColorConfig.ID,
  10224. Module: "system",
  10225. OrgId: orgId,
  10226. Name: tube_color,
  10227. FieldName: "",
  10228. Value: tubeConfig.Value + 1,
  10229. CreatedTime: "",
  10230. UpdatedTime: "",
  10231. CreateUserId: adminUser.AdminUser.Id,
  10232. Status: 1,
  10233. Remark: "",
  10234. DeleteIdSystem: 0,
  10235. Title: "",
  10236. Content: "",
  10237. Order: 0,
  10238. Code: "",
  10239. }
  10240. service.CreatedDicConfig(&dataconfig)
  10241. }
  10242. }
  10243. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10244. for _, it := range tubeColorList {
  10245. if tube_color == it.Name {
  10246. tube_color_id = int64(it.Value)
  10247. }
  10248. }
  10249. project.TubeColor = tube_color_id
  10250. single_dose := projectM["single_dose"].(string)
  10251. project.SingleDose = single_dose
  10252. execution_frequency := projectM["execution_frequency"].(string)
  10253. project.ExecutionFrequency = execution_frequency
  10254. delivery_way := projectM["delivery_way"].(string)
  10255. project.DeliveryWay = delivery_way
  10256. number_days := projectM["number_days"].(string)
  10257. project.NumberDays = number_days
  10258. total := projectM["total"].(string)
  10259. project.Total = total
  10260. medical_status := int64(projectM["medical_status"].(float64))
  10261. project.MedicalStatus = medical_status
  10262. category := int64(projectM["category"].(float64))
  10263. project.Category = category
  10264. specail_project := int64(projectM["specail_project"].(float64))
  10265. project.SpecailProject = specail_project
  10266. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10267. project.SocialSecurityDirectoryCode = social_security_directory_code
  10268. remark := projectM["remark"].(string)
  10269. project.Remark = remark
  10270. record_date := projectM["record_date"].(string)
  10271. timeLayout := "2006-01-02"
  10272. loc, _ := time.LoadLocation("Local")
  10273. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10274. project.RecordDate = theTime.Unix()
  10275. projectList = append(projectList, &project)
  10276. }
  10277. export_time := time.Now().Unix()
  10278. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10279. if len(projectList) > 0 {
  10280. for _, item := range projectList {
  10281. hans := item.ProjectName // 要转换的汉字字符串
  10282. // 创建一个拼音转换器
  10283. p := pinyin.NewArgs()
  10284. // 将汉字转为拼音
  10285. pinyinSlice := pinyin.Pinyin(hans, p)
  10286. // 输出拼音
  10287. fmt.Println("Pinyin:", pinyinSlice)
  10288. // 获取首字母
  10289. firstLetter := ""
  10290. for _, py := range pinyinSlice {
  10291. if len(py) > 0 {
  10292. firstLetter += string(py[0][0])
  10293. }
  10294. }
  10295. item.FirstLetter = firstLetter
  10296. project := models.HisProject{
  10297. ProjectName: item.ProjectName,
  10298. Price: item.Price,
  10299. Unit: item.Unit,
  10300. CostClassify: item.CostClassify,
  10301. ExecutiveSection: item.ExecutiveSection,
  10302. MedicalCoverage: item.MedicalCoverage,
  10303. UserOrgId: orgId,
  10304. Status: 1,
  10305. CreatedTime: time.Now().Unix(),
  10306. Pinyin: item.Pinyin,
  10307. Wubi: item.Wubi,
  10308. StatisticalClassification: item.StatisticalClassification,
  10309. DiseaseDirectory: item.DiseaseDirectory,
  10310. IsRecord: item.IsRecord,
  10311. MedicalCode: item.MedicalCode,
  10312. TubeColor: item.TubeColor,
  10313. SingleDose: item.SingleDose,
  10314. DeliveryWay: item.DeliveryWay,
  10315. NumberDays: item.NumberDays,
  10316. Total: item.Total,
  10317. Category: item.Category,
  10318. MedicalStatus: item.MedicalStatus,
  10319. SpecailProject: item.SpecailProject,
  10320. RecordDate: item.RecordDate,
  10321. Remark: item.Remark,
  10322. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10323. ExecutionFrequency: item.ExecutionFrequency,
  10324. FirstLetter: item.FirstLetter,
  10325. }
  10326. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10327. if errcodeproject == gorm.ErrRecordNotFound {
  10328. service.CreateProjectInfomation(&project)
  10329. } else if errcodeproject == nil {
  10330. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10331. }
  10332. log := models.ExportLog{
  10333. LogType: 6,
  10334. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10335. TotalNum: int64(len(total_goods)),
  10336. FailNum: int64(len(errLogs)),
  10337. SuccessNum: int64(len(projectList)),
  10338. CreateTime: time.Now().Unix(),
  10339. UpdateTime: time.Now().Unix(),
  10340. ExportTime: export_time,
  10341. Status: 1,
  10342. }
  10343. service.CreateExportLog(&log)
  10344. c.ServeSuccessJSON(map[string]interface{}{
  10345. "msg": "导入成功",
  10346. "total_num": len(total_goods),
  10347. "success_num": len(projectList),
  10348. "fail_num": int64(len(errLogs)),
  10349. })
  10350. }
  10351. } else {
  10352. log := models.ExportLog{
  10353. LogType: 6,
  10354. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10355. TotalNum: int64(len(total_goods)),
  10356. FailNum: int64(len(errLogs)),
  10357. SuccessNum: int64(len(projectList)),
  10358. CreateTime: time.Now().Unix(),
  10359. UpdateTime: time.Now().Unix(),
  10360. ExportTime: export_time,
  10361. Status: 1,
  10362. }
  10363. service.CreateExportLog(&log)
  10364. c.ServeSuccessJSON(map[string]interface{}{
  10365. "msg": "导入成功",
  10366. "total_num": len(total_goods),
  10367. "success_num": len(projectList),
  10368. "fail_num": int64(len(errLogs)),
  10369. })
  10370. }
  10371. }
  10372. //func (this *HisApiController) EditProjectInformation(){
  10373. //
  10374. // id, _ := this.GetInt64("id")
  10375. // project_team := this.GetString("project_team")
  10376. // price := this.GetString("price")
  10377. // price_float, _ := strconv.ParseFloat(price, 64)
  10378. // pinyin := this.GetString("pinyin")
  10379. // wubi := this.GetString("wubi")
  10380. // tube_color, _ := this.GetInt64("tube_color")
  10381. // team_type, _ := this.GetInt64("team_type")
  10382. // remark := this.GetString("remark")
  10383. // ids := this.GetString("ids")
  10384. // item_id := this.GetString("item_id")
  10385. // projectTeam := models.XtHisProjectTeam{
  10386. // ProjectTeam: project_team,
  10387. // Price: price_float,
  10388. // Pinyin: pinyin,
  10389. // Wubi: wubi,
  10390. // TubeColor: tube_color,
  10391. // TeamType: team_type,
  10392. // Remark: remark,
  10393. // ProjectId: ids,
  10394. // ItemId: item_id,
  10395. // }
  10396. //
  10397. //
  10398. // dataBody := make(map[string]interface{}, 0)
  10399. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10400. // if err != nil {
  10401. // utils.ErrorLog(err.Error())
  10402. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10403. // return
  10404. // }
  10405. //
  10406. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10407. //
  10408. //
  10409. // if err != nil {
  10410. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10411. // return
  10412. // }
  10413. //
  10414. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10415. // infos, _ := dataBody["info"].([]interface{})
  10416. // if len(infos) > 0 {
  10417. // var ids []string
  10418. //
  10419. // for _, item := range infos {
  10420. // items := item.(map[string]interface{})
  10421. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10422. // utils.ErrorLog("id")
  10423. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10424. // return
  10425. // }
  10426. // id := int64(items["id"].(float64))
  10427. //
  10428. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10429. // utils.ErrorLog("type")
  10430. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10431. // return
  10432. // }
  10433. // types := int64(items["type"].(float64))
  10434. //
  10435. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10436. // utils.ErrorLog("number")
  10437. // }
  10438. //
  10439. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10440. //
  10441. // projectList := models.XtHisProjectList{
  10442. // Number: number,
  10443. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10444. // ProjectId: id,
  10445. // Status: 1,
  10446. // CreatedTime: time.Now().Unix(),
  10447. // UpdatedTime: time.Now().Unix(),
  10448. // TeamId: projectTeam.ID,
  10449. // Type: types,
  10450. // }
  10451. // list := projectList
  10452. //
  10453. // service.CreateProjectList(&list)
  10454. //
  10455. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10456. //
  10457. // }
  10458. // ids_str := strings.Join(ids, ",")
  10459. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10460. // service.SaveProjectTeam(&projectTeam)
  10461. // this.ServeSuccessJSON(map[string]interface{}{
  10462. // "projectTeam": projectTeam,
  10463. // })
  10464. // }
  10465. // }
  10466. //}
  10467. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10468. name := c.GetString("name")
  10469. mode_id, _ := c.GetInt64("mode", 0)
  10470. types, _ := c.GetInt64("type", 0)
  10471. patient_id, _ := c.GetInt64("patient_id", 0)
  10472. types = 1
  10473. adminInfo := c.GetAdminUserInfo()
  10474. template := &models.HisPrescriptionTemplate{
  10475. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10476. PatientId: patient_id,
  10477. Type: types,
  10478. Status: 1,
  10479. Ctime: time.Now().Unix(),
  10480. Mtime: time.Now().Unix(),
  10481. Name: name,
  10482. Mode: mode_id,
  10483. }
  10484. dataBody := make(map[string]interface{}, 0)
  10485. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10486. if err != nil {
  10487. utils.ErrorLog(err.Error())
  10488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10489. return
  10490. }
  10491. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10492. //如果已经存在记录则删除处方
  10493. if template_one.ID > 0 {
  10494. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10495. var ids []int64
  10496. var org_id int64
  10497. for _, item := range ps {
  10498. org_id = c.GetAdminUserInfo().CurrentOrgId
  10499. ids = append(ids, item.ID)
  10500. }
  10501. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10502. if err2 == nil {
  10503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10505. if len(prescriptions) > 0 {
  10506. for _, item := range prescriptions {
  10507. items := item.(map[string]interface{})
  10508. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10509. utils.ErrorLog("type")
  10510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10511. return
  10512. }
  10513. types := int64(items["type"].(float64))
  10514. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10515. utils.ErrorLog("med_type")
  10516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10517. return
  10518. }
  10519. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10520. ctime := time.Now().Unix()
  10521. prescription := &models.HisPrescriptionInfoTemplate{
  10522. PatientId: patient_id,
  10523. UserOrgId: adminInfo.CurrentOrgId,
  10524. Ctime: ctime,
  10525. Mtime: ctime,
  10526. Type: types,
  10527. Modifier: adminInfo.AdminUser.Id,
  10528. Creator: adminInfo.AdminUser.Id,
  10529. Status: 1,
  10530. PTemplateId: template_one.ID,
  10531. MedType: med_type,
  10532. }
  10533. service.CreateHisPrescriptionInfoTemplate(prescription)
  10534. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10535. advices := items["advices"].([]interface{})
  10536. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10537. ctime := time.Now().Unix()
  10538. mtime := ctime
  10539. if len(advices) > 0 {
  10540. for _, advice := range advices {
  10541. var s models.HisPrescriptionAdviceTemplate
  10542. s.PrescriptionId = prescription.ID
  10543. s.AdviceType = 2
  10544. s.StopState = 2
  10545. s.ExecutionState = 2
  10546. s.Status = 1
  10547. s.UserOrgId = adminInfo.CurrentOrgId
  10548. s.CreatedTime = ctime
  10549. s.UpdatedTime = mtime
  10550. s.PatientId = patient_id
  10551. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10552. if errcode > 0 {
  10553. c.ServeFailJSONWithSGJErrorCode(errcode)
  10554. return
  10555. }
  10556. service.CreateHisPrescriptionAdviceTemplate(&s)
  10557. }
  10558. }
  10559. }
  10560. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10561. projects := items["project"].([]interface{})
  10562. if len(projects) > 0 {
  10563. for _, project := range projects {
  10564. var p models.HisPrescriptionProjectTemplate
  10565. p.PrescriptionId = prescription.ID
  10566. p.Ctime = time.Now().Unix()
  10567. p.Mtime = time.Now().Unix()
  10568. p.PatientId = patient_id
  10569. p.UserOrgId = adminInfo.CurrentOrgId
  10570. p.Status = 1
  10571. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10572. if errcode > 0 {
  10573. c.ServeFailJSONWithSGJErrorCode(errcode)
  10574. return
  10575. }
  10576. service.CreateHisPrescriptionProjectTemplate(&p)
  10577. }
  10578. }
  10579. }
  10580. }
  10581. c.ServeSuccessJSON(map[string]interface{}{
  10582. "msg": "创建成功",
  10583. })
  10584. }
  10585. }
  10586. } else {
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10588. return
  10589. }
  10590. } else {
  10591. err3 := service.CreateHisPrescriptionTemplate(template)
  10592. if err3 == nil {
  10593. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10594. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10595. if len(prescriptions) > 0 {
  10596. for _, item := range prescriptions {
  10597. items := item.(map[string]interface{})
  10598. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10599. utils.ErrorLog("type")
  10600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10601. return
  10602. }
  10603. types := int64(items["type"].(float64))
  10604. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10605. utils.ErrorLog("med_type")
  10606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10607. return
  10608. }
  10609. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10610. ctime := time.Now().Unix()
  10611. prescription := &models.HisPrescriptionInfoTemplate{
  10612. PatientId: patient_id,
  10613. UserOrgId: adminInfo.CurrentOrgId,
  10614. Ctime: ctime,
  10615. Mtime: ctime,
  10616. Type: types,
  10617. Modifier: adminInfo.AdminUser.Id,
  10618. Creator: adminInfo.AdminUser.Id,
  10619. Status: 1,
  10620. PTemplateId: template.ID,
  10621. MedType: med_type,
  10622. }
  10623. service.CreateHisPrescriptionInfoTemplate(prescription)
  10624. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10625. advices := items["advices"].([]interface{})
  10626. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10627. ctime := time.Now().Unix()
  10628. mtime := ctime
  10629. if len(advices) > 0 {
  10630. for _, advice := range advices {
  10631. var s models.HisPrescriptionAdviceTemplate
  10632. s.PrescriptionId = prescription.ID
  10633. s.AdviceType = 2
  10634. s.StopState = 2
  10635. s.ExecutionState = 2
  10636. s.Status = 1
  10637. s.UserOrgId = adminInfo.CurrentOrgId
  10638. s.CreatedTime = ctime
  10639. s.UpdatedTime = mtime
  10640. s.PatientId = patient_id
  10641. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10642. if errcode > 0 {
  10643. c.ServeFailJSONWithSGJErrorCode(errcode)
  10644. return
  10645. }
  10646. service.CreateHisPrescriptionAdviceTemplate(&s)
  10647. }
  10648. }
  10649. }
  10650. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10651. projects := items["project"].([]interface{})
  10652. if len(projects) > 0 {
  10653. for _, project := range projects {
  10654. var p models.HisPrescriptionProjectTemplate
  10655. p.PrescriptionId = prescription.ID
  10656. p.Ctime = time.Now().Unix()
  10657. p.Mtime = time.Now().Unix()
  10658. p.PatientId = patient_id
  10659. p.UserOrgId = adminInfo.CurrentOrgId
  10660. p.Status = 1
  10661. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10662. if errcode > 0 {
  10663. c.ServeFailJSONWithSGJErrorCode(errcode)
  10664. return
  10665. }
  10666. service.CreateHisPrescriptionProjectTemplate(&p)
  10667. }
  10668. }
  10669. }
  10670. }
  10671. c.ServeSuccessJSON(map[string]interface{}{
  10672. "msg": "创建成功",
  10673. })
  10674. }
  10675. }
  10676. } else {
  10677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10678. return
  10679. }
  10680. }
  10681. }
  10682. func (c *HisApiController) PreSettle() {
  10683. id, _ := c.GetInt64("id")
  10684. record_time := c.GetString("record_time")
  10685. his_patient_id, _ := c.GetInt64("his_patient_id")
  10686. timeLayout := "2006-01-02"
  10687. loc, _ := time.LoadLocation("Local")
  10688. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10689. diagnosis_id := c.GetString("diagnosis")
  10690. sick_type, _ := c.GetInt64("sick_type")
  10691. reg_type, _ := c.GetInt64("p_type")
  10692. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10694. if err != nil {
  10695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10696. return
  10697. }
  10698. recordDateTime := theTime.Unix()
  10699. adminUser := c.GetAdminUserInfo()
  10700. var prescriptions []*models.HisPrescription
  10701. var start_time int64
  10702. var end_time int64
  10703. ids_str := c.GetString("ids")
  10704. ids_arr := strings.Split(ids_str, ",")
  10705. fmt.Println(reg_type)
  10706. if settle_accounts_type == 1 { //日结
  10707. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10708. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10709. } else {
  10710. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10711. }
  10712. fmt.Println(prescriptions)
  10713. } else { //月结
  10714. start_time_str := c.GetString("start_time")
  10715. end_time_str := c.GetString("end_time")
  10716. timeLayout := "2006-01-02"
  10717. loc, _ := time.LoadLocation("Local")
  10718. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10719. if err != nil {
  10720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10721. return
  10722. }
  10723. recordStartTime := theStartTime.Unix()
  10724. start_time = recordStartTime
  10725. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10726. if err != nil {
  10727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10728. return
  10729. }
  10730. recordEndTime := theEndTime.Unix()
  10731. end_time = recordEndTime
  10732. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10733. }
  10734. if reg_type == 1111 || reg_type == 1112 {
  10735. reg_type = 11
  10736. }
  10737. timestamp := time.Now().Unix()
  10738. tempTime := time.Unix(timestamp, 0)
  10739. timeFormat := tempTime.Format("20060102150405")
  10740. chrgBchno := rand.Intn(100000) + 10000
  10741. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10742. strconv.FormatInt(his.PatientId, 10)
  10743. var ids []int64
  10744. for _, item := range prescriptions {
  10745. ids = append(ids, item.ID)
  10746. }
  10747. fmt.Println(ids)
  10748. var total float64
  10749. for _, item := range prescriptions {
  10750. fmt.Println(item)
  10751. if item.Type == 1 { //药品
  10752. for _, subItem := range item.HisDoctorAdviceInfo {
  10753. total = total + (subItem.Price * subItem.PrescribingNumber)
  10754. }
  10755. }
  10756. if item.Type == 2 { //项目
  10757. for _, subItem := range item.HisPrescriptionProject {
  10758. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10759. total = total + (subItem.Price * cnt)
  10760. }
  10761. }
  10762. for _, subItem := range item.HisAdditionalCharge {
  10763. total = total + (subItem.Price * float64(subItem.Count))
  10764. }
  10765. }
  10766. allTotal := fmt.Sprintf("%.2f", total)
  10767. totals, _ := strconv.ParseFloat(allTotal, 64)
  10768. order := &models.HisOrder{
  10769. UserOrgId: adminUser.CurrentOrgId,
  10770. HisPatientId: his.ID,
  10771. PatientId: id,
  10772. SettleAccountsDate: recordDateTime,
  10773. Ctime: time.Now().Unix(),
  10774. Mtime: time.Now().Unix(),
  10775. Status: 1,
  10776. OrderStatus: 1,
  10777. MdtrtId: his.Number,
  10778. Number: chrg_bchno,
  10779. MedfeeSumamt: totals,
  10780. SettleEndTime: end_time,
  10781. SettleStartTime: start_time,
  10782. SettleType: settle_accounts_type,
  10783. PsnPartAmt: totals,
  10784. PsnCashPay: totals,
  10785. PType: 2,
  10786. IsPre: 1,
  10787. MedType: strconv.Itoa(int(reg_type)),
  10788. Diagnosis: diagnosis_id,
  10789. }
  10790. err = service.CreateOrder(order)
  10791. if err != nil {
  10792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10793. return
  10794. }
  10795. var customs []*Custom
  10796. for _, item := range prescriptions {
  10797. fmt.Println(item.Type)
  10798. if item.Type == 1 { //药品
  10799. for _, subItem := range item.HisDoctorAdviceInfo {
  10800. cus := &Custom{
  10801. AdviceId: subItem.ID,
  10802. ProjectId: 0,
  10803. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10804. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10805. FeedetlSn: subItem.FeedetlSn,
  10806. Price: fmt.Sprintf("%.2f", subItem.Price),
  10807. MedListCodg: subItem.MedListCodg,
  10808. Type: 1,
  10809. }
  10810. customs = append(customs, cus)
  10811. }
  10812. }
  10813. if item.Type == 2 { //项目
  10814. for _, subItem := range item.HisPrescriptionProject {
  10815. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10816. cus := &Custom{
  10817. AdviceId: 0,
  10818. ProjectId: subItem.ID,
  10819. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10820. Cut: fmt.Sprintf("%.2f", cnt),
  10821. FeedetlSn: subItem.FeedetlSn,
  10822. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10823. MedListCodg: subItem.MedListCodg,
  10824. Type: 2,
  10825. }
  10826. customs = append(customs, cus)
  10827. }
  10828. }
  10829. for _, item := range item.HisAdditionalCharge {
  10830. cus := &Custom{
  10831. ItemId: item.ID,
  10832. AdviceId: 0,
  10833. ProjectId: 0,
  10834. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10835. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10836. FeedetlSn: item.FeedetlSn,
  10837. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10838. MedListCodg: item.XtHisAddtionConfig.Code,
  10839. Type: 3,
  10840. }
  10841. customs = append(customs, cus)
  10842. }
  10843. }
  10844. fmt.Println(customs)
  10845. for _, item := range customs {
  10846. var advice_id int64 = 0
  10847. var project_id int64 = 0
  10848. var item_id int64 = 0
  10849. var types int64 = 0
  10850. if item.Type == 1 {
  10851. advice_id = item.AdviceId
  10852. project_id = 0
  10853. item_id = 0
  10854. } else if item.Type == 2 {
  10855. advice_id = 0
  10856. item_id = 0
  10857. project_id = item.ProjectId
  10858. } else if item.Type == 3 {
  10859. advice_id = 0
  10860. item_id = item.ItemId
  10861. project_id = 0
  10862. }
  10863. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10864. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10865. pric, _ := strconv.ParseFloat(item.Price, 32)
  10866. info := &models.HisOrderInfo{
  10867. OrderNumber: order.Number,
  10868. UploadDate: time.Now().Unix(),
  10869. AdviceId: advice_id,
  10870. DetItemFeeSumamt: detItemFeeSumamt,
  10871. Cnt: cut,
  10872. Pric: pric,
  10873. PatientId: id,
  10874. Status: 1,
  10875. Mtime: time.Now().Unix(),
  10876. Ctime: time.Now().Unix(),
  10877. UserOrgId: adminUser.CurrentOrgId,
  10878. HisPatientId: his.ID,
  10879. OrderId: order.ID,
  10880. ProjectId: project_id,
  10881. Type: types,
  10882. ItemId: item_id,
  10883. }
  10884. service.CreateOrderInfo(info)
  10885. }
  10886. his.SickType = sick_type
  10887. service.UpdataHisPateint(&his)
  10888. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10889. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10890. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10891. if err == nil {
  10892. c.ServeSuccessJSON(map[string]interface{}{
  10893. "msg": "结算成功",
  10894. })
  10895. }
  10896. }
  10897. type CustomOrderInfo struct {
  10898. Name string
  10899. Spec string
  10900. Unit string
  10901. Count float64
  10902. Price float64
  10903. Total float64
  10904. }
  10905. func (c *HisApiController) GetPrivateExpensesInfo() {
  10906. order_id, _ := c.GetInt64("id", 0)
  10907. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10908. order, _ := service.GetHisOrderByID(order_id)
  10909. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10910. if order.ID == 0 {
  10911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10912. return
  10913. }
  10914. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10915. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10916. org_id := c.GetAdminUserInfo().CurrentOrgId
  10917. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10918. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10919. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10920. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10921. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10922. //var orderInfos_four []*models.HisOrderInfoTwo
  10923. //for _, item := range orderInfos_three {
  10924. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10925. // item.HisPrescriptionProject.IsCheckTeam = 1
  10926. // orderInfos_four = append(orderInfos_four, item)
  10927. //
  10928. // }
  10929. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10930. // item.HisPrescriptionProject.IsCheckTeam = 2
  10931. // orderInfos_two = append(orderInfos_two, item)
  10932. // }
  10933. //}
  10934. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10935. //var cus_slice []CustomOrderInfo
  10936. //for _, item := range new_order_info {
  10937. // var cus CustomOrderInfo
  10938. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10939. // cus.Unit = ""
  10940. // cus.Spec = ""
  10941. // var total float64
  10942. // for _, subItem := range orderInfos_four {
  10943. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10944. // total = total + subItem.DetItemFeeSumamt
  10945. // fmt.Println(subItem.DetItemFeeSumamt)
  10946. // }
  10947. // }
  10948. // cus.Count = 1
  10949. // cus.Total = total
  10950. // cus_slice = append(cus_slice, cus)
  10951. //}
  10952. orderInfos = append(orderInfos, orderInfos_two...)
  10953. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10954. //orderInfos = append(orderInfos, orderInfos_three...)
  10955. //}/**/
  10956. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10957. c.ServeSuccessJSON(map[string]interface{}{
  10958. "order": order,
  10959. "order_info": orderInfos,
  10960. "patient": patient,
  10961. "admin_info": adminInfo,
  10962. "his": his,
  10963. "current_admin": role,
  10964. "org_config": miConfig,
  10965. //"new_order_info": cus_slice,
  10966. })
  10967. }
  10968. func (this *HisApiController) ChangeMedType() {
  10969. med_type := this.GetString("med_type")
  10970. old_med_type := this.GetString("old_med_type")
  10971. ids := this.GetString("ids")
  10972. settle_type, _ := this.GetInt64("settle_type")
  10973. start_time := this.GetString("start_time")
  10974. end_time := this.GetString("end_time")
  10975. ids_arr := strings.Split(ids, ",")
  10976. if settle_type == 1 { //日结
  10977. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10978. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10979. prescription.MedType = med_type
  10980. err := service.SaveHisPrescriptionTwo(&prescription)
  10981. if err == nil {
  10982. this.ServeSuccessJSON(map[string]interface{}{
  10983. "msg": "修改成功",
  10984. })
  10985. } else {
  10986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10987. return
  10988. }
  10989. } else if settle_type == 2 {
  10990. timeLayout := "2006-01-02"
  10991. loc, _ := time.LoadLocation("Local")
  10992. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10993. if err != nil {
  10994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10995. return
  10996. }
  10997. recordStartTime := theStartTime.Unix()
  10998. start_time_timestamp := recordStartTime
  10999. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11000. if err != nil {
  11001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11002. return
  11003. }
  11004. recordEndTime := theEndTime.Unix()
  11005. end_time_timestamp := recordEndTime
  11006. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11007. if updateErr == nil {
  11008. this.ServeSuccessJSON(map[string]interface{}{
  11009. "msg": "修改成功",
  11010. })
  11011. } else {
  11012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11013. return
  11014. }
  11015. }
  11016. }
  11017. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11018. patient_id, _ := c.GetInt64("patient_id")
  11019. his_patient_id, _ := c.GetInt64("his_patient_id")
  11020. record_date := c.GetString("record_date")
  11021. start_time := c.GetString("start_time")
  11022. end_time := c.GetString("end_time")
  11023. order_status, _ := c.GetInt64("type", 0)
  11024. p_type, _ := c.GetInt64("p_type", 0)
  11025. order_id, _ := c.GetInt64("order_id", 0)
  11026. timeLayout := "2006-01-02"
  11027. loc, _ := time.LoadLocation("Local")
  11028. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11029. if err != nil {
  11030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11031. return
  11032. }
  11033. recordDateTime := theTime.Unix()
  11034. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11035. if err != nil {
  11036. }
  11037. startRecordDateTime := startTime.Unix()
  11038. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11039. if err != nil {
  11040. }
  11041. endRecordDateTime := endTime.Unix()
  11042. admin := c.GetAdminUserInfo()
  11043. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11044. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11045. order, _ := service.GetHisOrderByID(order_id)
  11046. var monthPrescriptions []*models.HisPrescription
  11047. if order_status == 1 || order_status == 0 {
  11048. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11049. } else if order_status == 2 {
  11050. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11051. }
  11052. var settle_total float64
  11053. for _, item := range monthPrescriptions {
  11054. if len(item.HisPrescriptionProject) > 0 {
  11055. for _, subItem := range item.HisPrescriptionProject {
  11056. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11057. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11058. settle_total = settle_total + total
  11059. }
  11060. }
  11061. if len(item.HisDoctorAdviceInfo) > 0 {
  11062. for _, subItem := range item.HisDoctorAdviceInfo {
  11063. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11064. settle_total = settle_total + total
  11065. }
  11066. }
  11067. }
  11068. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11069. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11070. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11071. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11072. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11073. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11074. //获取所有科室信息
  11075. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11076. var dia string
  11077. for _, item := range month_p_info {
  11078. if len(dia) == 0 {
  11079. dia = item.Diagnosis
  11080. } else {
  11081. dia = dia + "," + item.Diagnosis
  11082. }
  11083. }
  11084. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11085. dia_arr = removeEmptyStrings(dia_arr)
  11086. c.ServeSuccessJSON(map[string]interface{}{
  11087. "his_info": his_patient_info,
  11088. "xt_info": xt_patient_info,
  11089. "case_history": case_history,
  11090. "info": patientPrescriptionInfo,
  11091. "last_info": lastPatientPrescriptionInfo,
  11092. "month_prescriptions": monthPrescriptions,
  11093. "order": order,
  11094. "doctors": doctors,
  11095. "department": department,
  11096. "settle_total": settle_total,
  11097. "dia_arr": dia_arr,
  11098. })
  11099. return
  11100. }
  11101. func removeEmptyStrings(input []string) []string {
  11102. var output []string
  11103. for _, s := range input {
  11104. if s != "" {
  11105. output = append(output, s)
  11106. }
  11107. }
  11108. return output
  11109. }
  11110. func removeDuplicates(input []string) []string {
  11111. seen := make(map[string]bool)
  11112. output := []string{}
  11113. for _, s := range input {
  11114. if _, exists := seen[s]; !exists {
  11115. seen[s] = true
  11116. output = append(output, s)
  11117. }
  11118. }
  11119. return output
  11120. }
  11121. func (c *HisApiController) GetHisMonthPatientInfo() {
  11122. patient_id, _ := c.GetInt64("patient_id")
  11123. his_patient_id, _ := c.GetInt64("his_patient_id")
  11124. record_date := c.GetString("record_date")
  11125. number := c.GetString("number")
  11126. start_time := c.GetString("start_time")
  11127. end_time := c.GetString("end_time")
  11128. p_type, _ := c.GetInt64("p_type")
  11129. timeLayout := "2006-01-02"
  11130. loc, _ := time.LoadLocation("Local")
  11131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11132. if err != nil {
  11133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11134. return
  11135. }
  11136. recordDateTime := theTime.Unix()
  11137. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11138. if err != nil {
  11139. }
  11140. startRecordDateTime := startTime.Unix()
  11141. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11142. if err != nil {
  11143. }
  11144. endRecordDateTime := endTime.Unix()
  11145. admin := c.GetAdminUserInfo()
  11146. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11147. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11148. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11149. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11150. var settle_total float64
  11151. for _, item := range monthPrescriptions {
  11152. if len(item.HisPrescriptionProject) > 0 {
  11153. for _, subItem := range item.HisPrescriptionProject {
  11154. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11155. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11156. settle_total = settle_total + total
  11157. }
  11158. }
  11159. if len(item.HisDoctorAdviceInfo) > 0 {
  11160. for _, subItem := range item.HisDoctorAdviceInfo {
  11161. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11162. settle_total = settle_total + total
  11163. }
  11164. }
  11165. }
  11166. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11167. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11168. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11169. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11170. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11171. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11172. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11173. //获取所有科室信息
  11174. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11175. c.ServeSuccessJSON(map[string]interface{}{
  11176. "his_info": his_patient_info,
  11177. "xt_info": xt_patient_info,
  11178. "case_history": case_history,
  11179. "info": patientPrescriptionInfo,
  11180. "month_prescriptions": monthPrescriptions,
  11181. "order": order,
  11182. "doctors": doctors,
  11183. "department": department,
  11184. "count": count,
  11185. "drugStockConfig": drugStockConfig,
  11186. "last_info": lastPatientPrescriptionInfo,
  11187. "settle_total": settle_total,
  11188. })
  11189. return
  11190. }
  11191. func (c *HisApiController) GetAllOrder() {
  11192. org_id := c.GetAdminUserInfo().CurrentOrgId
  11193. orders, _ := service.GetNewHisOrderList(org_id)
  11194. c.ServeSuccessJSON(map[string]interface{}{
  11195. "order": orders,
  11196. })
  11197. return
  11198. }
  11199. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11200. newArr = make([]*models.HisOrderInfoTwo, 0)
  11201. for i := 0; i < len(arr); i++ {
  11202. repeat := false
  11203. for j := i + 1; j < len(arr); j++ {
  11204. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11205. repeat = true
  11206. break
  11207. }
  11208. }
  11209. if !repeat {
  11210. newArr = append(newArr, arr[i])
  11211. }
  11212. }
  11213. return
  11214. }
  11215. // 修改处方退库操作 参数传修改之前的处方数据
  11216. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11217. if advice.ExecutionState == 1 {
  11218. //查询该病人该药品是否有库存记录
  11219. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11220. if errcode == gorm.ErrRecordNotFound {
  11221. } else {
  11222. //退库
  11223. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11224. if advice.PrescribingNumberUnit == drug.MinUnit {
  11225. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11226. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11227. //退库
  11228. warehouseInfo := models.DrugWarehouseInfo{
  11229. StockMinNumber: prescribingNumber,
  11230. }
  11231. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11232. operation_time := time.Now().Unix()
  11233. creater := advice.AdviceDoctor
  11234. ctime := time.Now().Unix()
  11235. timeStr := time.Now().Format("2006-01-02")
  11236. timeArr := strings.Split(timeStr, "-")
  11237. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11238. total = total + 1
  11239. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11240. cancelStock := models.DrugCancelStock{
  11241. OrderNumber: orderNumber,
  11242. OperaTime: operation_time,
  11243. OrgId: advice.UserOrgId,
  11244. Creater: creater,
  11245. Ctime: ctime,
  11246. Status: 1,
  11247. ReturnTime: advice.AdviceDate,
  11248. Dealer: info.Dealer,
  11249. Manufacturer: info.Manufacturer,
  11250. Type: 1,
  11251. }
  11252. service.AddSigleDrugCancelStock(&cancelStock)
  11253. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11254. dealer, _ := service.GetDealerById(info.Dealer)
  11255. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11256. cancelStockInfo := models.DrugCancelStockInfo{
  11257. OrderNumber: cancelInfo.OrderNumber,
  11258. CancelStockId: cancelInfo.ID,
  11259. DrugId: info.DrugId,
  11260. Count: info.Count,
  11261. Status: 1,
  11262. Ctime: ctime,
  11263. OrgId: advice.UserOrgId,
  11264. Type: 1,
  11265. Manufacturer: manufactureName.ManufacturerName,
  11266. Dealer: dealer.DealerName,
  11267. Total: 0,
  11268. RetailPrice: info.RetailPrice,
  11269. RetailTotalPrice: info.RetailTotalPrice,
  11270. Price: info.Price,
  11271. RegisterAccount: "",
  11272. Remark: info.Remark,
  11273. BatchNumber: info.BatchNumber,
  11274. MaxUnit: info.CountUnit,
  11275. ProductDate: info.ProductDate,
  11276. ExpiryDate: info.ExpiryDate,
  11277. BatchNumberId: info.WarehouseInfoId,
  11278. }
  11279. flow := models.DrugFlow{
  11280. WarehousingId: 0,
  11281. DrugId: info.DrugId,
  11282. Number: "",
  11283. BatchNumber: info.BatchNumber,
  11284. Count: info.Count,
  11285. UserOrgId: advice.UserOrgId,
  11286. PatientId: 0,
  11287. SystemTime: ctime,
  11288. ConsumableType: 4,
  11289. IsSys: 0,
  11290. WarehousingOrder: "",
  11291. WarehouseOutId: 0,
  11292. WarehouseOutOrderNumber: "",
  11293. IsEdit: 0,
  11294. CancelStockId: cancelStock.ID,
  11295. CancelOrderNumber: cancelStock.OrderNumber,
  11296. Manufacturer: info.Manufacturer,
  11297. Dealer: info.Dealer,
  11298. Creator: advice.UserOrgId,
  11299. UpdateCreator: 0,
  11300. Status: 1,
  11301. Ctime: time.Now().Unix(),
  11302. Mtime: 0,
  11303. Price: info.Price,
  11304. WarehousingDetailId: 0,
  11305. WarehouseOutDetailId: 0,
  11306. CancelOutDetailId: 0,
  11307. ExpireDate: info.ExpiryDate,
  11308. ProductDate: info.ProductDate,
  11309. MaxUnit: info.CountUnit,
  11310. MinUnit: "",
  11311. }
  11312. service.CreatedCancelStock(cancelStockInfo)
  11313. service.CreateDrugFlowOne(flow)
  11314. } else {
  11315. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11316. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11317. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11318. warehouseInfo := models.DrugWarehouseInfo{
  11319. StockMinNumber: prescribingNumber,
  11320. }
  11321. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11322. }
  11323. operation_time := time.Now().Unix()
  11324. creater := advice.AdviceDoctor
  11325. ctime := time.Now().Unix()
  11326. timeStr := time.Now().Format("2006-01-02")
  11327. timeArr := strings.Split(timeStr, "-")
  11328. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11329. total = total + 1
  11330. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11331. cancelStock := models.DrugCancelStock{
  11332. OrderNumber: orderNumber,
  11333. OperaTime: operation_time,
  11334. OrgId: advice.UserOrgId,
  11335. Creater: creater,
  11336. Ctime: ctime,
  11337. Status: 1,
  11338. ReturnTime: advice.AdviceDate,
  11339. Dealer: info.Dealer,
  11340. Manufacturer: info.Manufacturer,
  11341. Type: 1,
  11342. }
  11343. service.AddSigleDrugCancelStock(&cancelStock)
  11344. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11345. dealer, _ := service.GetDealerById(info.Dealer)
  11346. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11347. cancelStockInfo := models.DrugCancelStockInfo{
  11348. OrderNumber: cancelInfo.OrderNumber,
  11349. CancelStockId: cancelInfo.ID,
  11350. DrugId: info.DrugId,
  11351. Count: info.Count,
  11352. Status: 1,
  11353. Ctime: ctime,
  11354. OrgId: advice.UserOrgId,
  11355. Type: 1,
  11356. Manufacturer: manufactureName.ManufacturerName,
  11357. Dealer: dealer.DealerName,
  11358. Total: 0,
  11359. RetailPrice: info.RetailPrice,
  11360. RetailTotalPrice: info.RetailTotalPrice,
  11361. Price: info.Price,
  11362. RegisterAccount: "",
  11363. Remark: info.Remark,
  11364. BatchNumber: info.BatchNumber,
  11365. MaxUnit: info.CountUnit,
  11366. ProductDate: info.ProductDate,
  11367. ExpiryDate: info.ExpiryDate,
  11368. BatchNumberId: info.WarehouseInfoId,
  11369. }
  11370. flow := models.DrugFlow{
  11371. WarehousingId: 0,
  11372. DrugId: info.DrugId,
  11373. Number: "",
  11374. BatchNumber: info.BatchNumber,
  11375. Count: info.Count,
  11376. UserOrgId: advice.UserOrgId,
  11377. PatientId: 0,
  11378. SystemTime: ctime,
  11379. ConsumableType: 4,
  11380. IsSys: 0,
  11381. WarehousingOrder: "",
  11382. WarehouseOutId: 0,
  11383. WarehouseOutOrderNumber: "",
  11384. IsEdit: 0,
  11385. CancelStockId: cancelStock.ID,
  11386. CancelOrderNumber: cancelStock.OrderNumber,
  11387. Manufacturer: info.Manufacturer,
  11388. Dealer: info.Dealer,
  11389. Creator: advice.AdviceDoctor,
  11390. UpdateCreator: 0,
  11391. Status: 1,
  11392. Ctime: time.Now().Unix(),
  11393. Mtime: 0,
  11394. Price: info.Price,
  11395. WarehousingDetailId: 0,
  11396. WarehouseOutDetailId: 0,
  11397. CancelOutDetailId: 0,
  11398. ExpireDate: info.ExpiryDate,
  11399. ProductDate: info.ProductDate,
  11400. MaxUnit: info.CountUnit,
  11401. MinUnit: "",
  11402. }
  11403. service.CreatedCancelStock(cancelStockInfo)
  11404. service.CreateDrugFlowOne(flow)
  11405. }
  11406. }
  11407. }
  11408. return err
  11409. }
  11410. func (this *HisApiController) DeleteNCDS() {
  11411. id, _ := this.GetInt64("id", 0)
  11412. if id > 0 {
  11413. service.DeletePsnNCDSRecordById(id)
  11414. this.ServeSuccessJSON(map[string]interface{}{
  11415. "msg": "删除成功",
  11416. })
  11417. } else {
  11418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11419. return
  11420. }
  11421. }
  11422. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11423. id, _ := c.GetInt64("id")
  11424. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11425. c.ServeSuccessJSON(map[string]interface{}{
  11426. "advice": advice,
  11427. })
  11428. return
  11429. }
  11430. func (c *HisApiController) GetHisMonthChargePatientList() {
  11431. record_date := c.GetString("record_date")
  11432. start_time := c.GetString("start_time")
  11433. end_time := c.GetString("end_time")
  11434. timeLayout := "2006-01-02"
  11435. loc, _ := time.LoadLocation("Local")
  11436. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11437. if err != nil {
  11438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11439. return
  11440. }
  11441. if err != nil {
  11442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11443. return
  11444. }
  11445. recordDateTime := theTime.Unix()
  11446. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11447. if err != nil {
  11448. }
  11449. startRecordDateTime := startTime.Unix()
  11450. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11451. if err != nil {
  11452. }
  11453. endRecordDateTime := endTime.Unix()
  11454. adminInfo := c.GetAdminUserInfo()
  11455. var tempMonthChargePatients []*service.MonthChargePatients
  11456. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11457. for _, item := range tempPatients {
  11458. //过滤没有处方的
  11459. if len(item.HisPrescription) == 0 {
  11460. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11461. }
  11462. }
  11463. c.ServeSuccessJSON(map[string]interface{}{
  11464. "list": tempMonthChargePatients,
  11465. })
  11466. }
  11467. // PrescriptionDifference 医嘱数量差值结构体
  11468. type PrescriptionDrugDifference struct {
  11469. DrugID int64 //基础库药品id
  11470. ID int64 //医嘱id
  11471. Difference float64 //差值
  11472. Unit string //单位
  11473. }
  11474. type PrescriptionGoodDifference struct {
  11475. GoodID int64 //基础库项目耗材id
  11476. ID int64 //医嘱id
  11477. Difference int64 //差值
  11478. Unit string //单位
  11479. Type int64 //类型
  11480. }
  11481. type EditCustomData struct {
  11482. adviceList []*models.HisDoctorAdviceInfo
  11483. projectList []*models.HisPrescriptionProject
  11484. }
  11485. type SrcCustomData struct {
  11486. adviceList []*models.HisDoctorAdviceInfo
  11487. projectList []*models.HisPrescriptionProject
  11488. }
  11489. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11490. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11491. differences := make([]*PrescriptionDrugDifference, 0)
  11492. // 创建一个 map 来存储第一个切片中的药品信息
  11493. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11494. for _, advice := range firstPrescription {
  11495. firstMap[advice.DrugId] = advice
  11496. }
  11497. // 遍历第二个切片中的药品信息,并比较数量差值
  11498. for _, advice := range secondPrescription {
  11499. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11500. diff := &PrescriptionDrugDifference{
  11501. DrugID: advice.DrugId,
  11502. ID: firstAdvice.ID,
  11503. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11504. Unit: firstAdvice.PrescribingNumberUnit,
  11505. }
  11506. differences = append(differences, diff)
  11507. }
  11508. }
  11509. return differences
  11510. }
  11511. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11512. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11513. differences := make([]*PrescriptionGoodDifference, 0)
  11514. // 创建一个 map 来存储第一个切片中的耗材信息
  11515. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11516. for _, good := range firstPrescription {
  11517. firstMap[good.ProjectId] = good
  11518. }
  11519. // 遍历第二个切片中的耗材信息,并比较数量差值
  11520. for _, good := range secondPrescription {
  11521. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11522. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11523. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11524. diff := &PrescriptionGoodDifference{
  11525. GoodID: good.ProjectId,
  11526. ID: firstGood.ID,
  11527. Difference: count - firstCount,
  11528. Unit: firstGood.Unit,
  11529. Type: firstGood.Type,
  11530. }
  11531. differences = append(differences, diff)
  11532. }
  11533. }
  11534. return differences
  11535. }
  11536. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11537. var adviceList []*models.HisDoctorAdviceInfo
  11538. var projectList []*models.HisPrescriptionProject
  11539. var advice_ids []int64
  11540. var project_ids []int64
  11541. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11542. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11543. //var tempPrescription *models.HisPrescriptionProjectscription
  11544. if len(prescriptions) > 0 {
  11545. for _, item := range prescriptions {
  11546. items := item.(map[string]interface{})
  11547. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11548. advices := items["advices"].([]interface{})
  11549. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11550. groupNo := int64(0)
  11551. ctime := time.Now().Unix()
  11552. mtime := ctime
  11553. if len(advices) > 0 {
  11554. for _, advice := range advices {
  11555. var s models.HisDoctorAdviceInfo
  11556. s.AdviceType = 2
  11557. s.StopState = 2
  11558. s.ExecutionState = 2
  11559. s.Status = 1
  11560. s.Groupno = groupNo
  11561. s.CreatedTime = ctime
  11562. s.UpdatedTime = mtime
  11563. s.IsSettle = 2
  11564. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11565. //存储切片中
  11566. if s.ID > 0 {
  11567. advice_ids = append(advice_ids, s.ID)
  11568. adviceList = append(adviceList, &s)
  11569. }
  11570. }
  11571. }
  11572. }
  11573. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11574. projects := items["project"].([]interface{})
  11575. if len(projects) > 0 {
  11576. for _, project := range projects {
  11577. var p models.HisPrescriptionProject
  11578. p.Ctime = time.Now().Unix()
  11579. p.Mtime = time.Now().Unix()
  11580. p.Status = 1
  11581. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11582. if p.ID > 0 {
  11583. project_ids = append(project_ids, p.ID)
  11584. projectList = append(projectList, &p)
  11585. }
  11586. }
  11587. }
  11588. }
  11589. }
  11590. }
  11591. }
  11592. editCustomData.projectList = projectList
  11593. editCustomData.adviceList = adviceList
  11594. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11595. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11596. srcCustomData.adviceList = list
  11597. srcCustomData.projectList = list2
  11598. return
  11599. }