his_api_controller.go 464KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1666. //药品发药出库
  1667. if pharmacyConfig.IsOpen == 1 {
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. //新增处方
  1709. if advicelist.ID == 0 {
  1710. all_count, _ := strconv.ParseFloat(totals, 64)
  1711. if prescribingNumberUnit == drug.MinUnit {
  1712. fmt.Println("prescribing_number", prescribing_number)
  1713. fmt.Println("all_count", all_count)
  1714. if drug.IsUse != 1 {
  1715. if drug.IsProject == 0 || drug.IsProject == 2 {
  1716. if all_count == 0 {
  1717. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1718. return
  1719. }
  1720. if prescribing_number > all_count {
  1721. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1722. return
  1723. }
  1724. }
  1725. }
  1726. }
  1727. if prescribingNumberUnit == drug.MaxUnit {
  1728. num := prescribing_number * float64(drug.MinNumber)
  1729. if drug.IsUse != 1 {
  1730. if drug.IsProject == 0 || drug.IsProject == 2 {
  1731. if all_count == 0 {
  1732. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1733. return
  1734. }
  1735. if num > all_count {
  1736. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1737. return
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1744. if drugOutConfig.IsOpen != 1 {
  1745. //修改处方
  1746. for _, advice := range advices {
  1747. var drug_id int64
  1748. var prescribing_number float64
  1749. var prescribingNumberUnit string
  1750. var prescribingNumber string
  1751. var adviceId int64
  1752. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1753. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1754. }
  1755. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1756. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1757. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1758. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1759. }
  1760. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1761. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1762. }
  1763. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1764. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1765. }
  1766. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1767. if drug.ID == 0 {
  1768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1769. return
  1770. }
  1771. //查询药品的所有库存
  1772. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1773. var total_count int64
  1774. for _, it := range list {
  1775. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1776. }
  1777. totals := strconv.FormatInt(total_count, 10)
  1778. //查询该药品是否存在开药记录
  1779. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1780. //新增处方
  1781. if advicelist.ID == 0 {
  1782. all_count, _ := strconv.ParseFloat(totals, 64)
  1783. if prescribingNumberUnit == drug.MinUnit {
  1784. if drug.IsUse != 1 {
  1785. if drug.IsProject == 0 || drug.IsProject == 2 {
  1786. if all_count == 0 {
  1787. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1788. return
  1789. }
  1790. if prescribing_number > all_count {
  1791. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1792. return
  1793. }
  1794. }
  1795. }
  1796. } else {
  1797. if prescribingNumberUnit == drug.MaxUnit {
  1798. num := prescribing_number * float64(drug.MinNumber)
  1799. if drug.IsUse != 1 {
  1800. if drug.IsProject == 0 || drug.IsProject == 2 {
  1801. if all_count == 0 {
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1803. return
  1804. }
  1805. if num > all_count {
  1806. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1807. return
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. //修改处方
  1815. if advicelist.ID > 0 {
  1816. var device_number int64
  1817. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1818. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1819. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1820. device_number = prescribingNumberInt * drug.MinNumber
  1821. }
  1822. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1823. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1824. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1825. device_number = prescribingNumberInt
  1826. }
  1827. var number_count int64
  1828. if prescribingNumberUnit == drug.MaxUnit {
  1829. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1830. number_count = prescribingNumberInt * drug.MinNumber
  1831. }
  1832. if prescribingNumberUnit == drug.MinUnit {
  1833. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1834. number_count = prescribingNumberInt
  1835. }
  1836. //如果修改的数量大于之前修改的数量
  1837. if (number_count - device_number) > 0 {
  1838. //如果修改的差数量 大于库存数量
  1839. if drug.IsUse != 1 {
  1840. if (number_count - device_number) > total_count {
  1841. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1842. return
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. //已发药和已收费限制逻辑
  1857. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1858. //校验库存总量
  1859. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1860. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1861. if len(prescriptions) > 0 {
  1862. for _, item := range prescriptions {
  1863. items := item.(map[string]interface{})
  1864. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1865. advices := items["advices"].([]interface{})
  1866. if len(advices) > 0 {
  1867. for _, advice := range advices {
  1868. var drug_id int64
  1869. var prescribing_number float64
  1870. var prescribingNumberUnit string
  1871. var adviceId int64
  1872. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1873. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1874. }
  1875. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1876. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1877. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1878. }
  1879. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1880. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1881. }
  1882. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1883. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1884. }
  1885. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1886. if drug.ID == 0 {
  1887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1888. return
  1889. }
  1890. //查询药品的所有库存
  1891. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1892. var total_count int64
  1893. for _, it := range list {
  1894. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1895. }
  1896. totals := strconv.FormatInt(total_count, 10)
  1897. //查询该药品是否存在开药记录
  1898. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1899. //查询最新批次库存
  1900. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1901. var batch_number_count int64
  1902. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1903. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1904. //新增处方
  1905. if advicelist.ID == 0 {
  1906. all_count, _ := strconv.ParseFloat(totals, 64)
  1907. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1908. if prescribingNumberUnit == drug.MinUnit {
  1909. if drug.IsUse != 1 {
  1910. if drug.IsProject == 0 || drug.IsProject == 2 {
  1911. if all_count == 0 {
  1912. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1913. return
  1914. }
  1915. if prescribing_number > all_count {
  1916. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1917. return
  1918. }
  1919. }
  1920. if adminInfo.CurrentOrgId == 10215 {
  1921. if prescribing_number > batch_number_all_count {
  1922. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1923. return
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if prescribingNumberUnit == drug.MaxUnit {
  1929. num := prescribing_number * float64(drug.MinNumber)
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1934. return
  1935. }
  1936. if num > all_count {
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1938. return
  1939. }
  1940. }
  1941. if adminInfo.CurrentOrgId == 10215 {
  1942. if num > batch_number_all_count {
  1943. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1944. return
  1945. }
  1946. }
  1947. }
  1948. }
  1949. }
  1950. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1951. if drugOutConfig.IsOpen != 1 {
  1952. //修改处方
  1953. for _, advice := range advices {
  1954. var drug_id int64
  1955. var prescribing_number float64
  1956. var prescribingNumberUnit string
  1957. var prescribingNumber string
  1958. var adviceId int64
  1959. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1960. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1961. }
  1962. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1963. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1964. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1965. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1968. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1969. }
  1970. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1971. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1972. }
  1973. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1974. if drug.ID == 0 {
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1976. return
  1977. }
  1978. //查询药品的所有库存
  1979. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1980. var total_count int64
  1981. for _, it := range list {
  1982. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1983. }
  1984. totals := strconv.FormatInt(total_count, 10)
  1985. //查询该药品是否存在开药记录
  1986. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1987. //新增处方
  1988. if advicelist.ID == 0 {
  1989. //查询最新批次库存
  1990. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1991. var batch_number_count int64
  1992. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1993. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1994. all_count, _ := strconv.ParseFloat(totals, 64)
  1995. if prescribingNumberUnit == drug.MinUnit {
  1996. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1997. if drug.IsUse != 1 {
  1998. if drug.IsProject == 0 || drug.IsProject == 2 {
  1999. if all_count == 0 {
  2000. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2001. return
  2002. }
  2003. if prescribing_number > all_count {
  2004. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2005. return
  2006. }
  2007. }
  2008. if adminInfo.CurrentOrgId == 10215 {
  2009. if prescribing_number > batch_number_all_count {
  2010. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2011. return
  2012. }
  2013. }
  2014. }
  2015. } else {
  2016. if prescribingNumberUnit == drug.MaxUnit {
  2017. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2018. num := prescribing_number * float64(drug.MinNumber)
  2019. if drug.IsUse != 1 {
  2020. if drug.IsProject == 0 || drug.IsProject == 2 {
  2021. if all_count == 0 {
  2022. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2023. return
  2024. }
  2025. if num > all_count {
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. }
  2030. if adminInfo.CurrentOrgId == 10215 {
  2031. if prescribing_number > batch_number_all_count {
  2032. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2033. return
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. //修改处方
  2041. if advicelist.ID > 0 {
  2042. //查询最新批次库存
  2043. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2044. var batch_number_count int64
  2045. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2046. var device_number int64
  2047. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2048. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2049. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2050. device_number = prescribingNumberInt * drug.MinNumber
  2051. }
  2052. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2053. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2054. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2055. device_number = prescribingNumberInt
  2056. }
  2057. var number_count int64
  2058. if prescribingNumberUnit == drug.MaxUnit {
  2059. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2060. number_count = prescribingNumberInt * drug.MinNumber
  2061. }
  2062. if prescribingNumberUnit == drug.MinUnit {
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2064. number_count = prescribingNumberInt
  2065. }
  2066. //如果修改的数量大于之前修改的数量
  2067. if (number_count - device_number) > 0 {
  2068. //如果修改的差数量 大于库存数量
  2069. if drug.IsUse != 1 {
  2070. if drug.IsProject == 0 || drug.IsProject == 2 {
  2071. if total_count == 0 {
  2072. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2073. return
  2074. }
  2075. if (number_count - device_number) > total_count {
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2077. return
  2078. }
  2079. if (number_count - device_number) > batch_number_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. if adminInfo.CurrentOrgId == 10215 {
  2085. // 查询该药品最后一次出库记录
  2086. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2087. var out_count int64
  2088. var in_count int64
  2089. var stock_max_number int64
  2090. var stock_min_number int64
  2091. for _, it := range outInfo {
  2092. if it.CountUnit == drug.MaxUnit {
  2093. it.Count = it.Count * drug.MinNumber
  2094. }
  2095. out_count += it.Count
  2096. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2097. stock_max_number = warehouseInfoList.StockMaxNumber
  2098. stock_min_number = warehouseInfoList.StockMinNumber
  2099. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2100. }
  2101. if out_count > 0 {
  2102. if (number_count - device_number) > in_count {
  2103. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2104. return
  2105. }
  2106. }
  2107. // 未出库
  2108. if out_count == 0 {
  2109. var sum_in_count int64
  2110. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2111. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2112. fmt.Println("sum_in_count", sum_in_count)
  2113. //如果修改的数量大于有库存的第一个批次
  2114. if number_count > sum_in_count {
  2115. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2116. return
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2123. if pharmacyConfig.IsOpen != 1 {
  2124. if device_number != number_count {
  2125. // 查询该药品最后一次出库记录
  2126. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2127. //回退库存
  2128. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2129. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2130. }
  2131. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2132. var stock_max_number int64
  2133. var stock_min_number int64
  2134. if number_count >= drug.MinNumber {
  2135. stock_max_number = device_number / drug.MinNumber
  2136. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2137. stock_min_number = device_number % drug.MinNumber
  2138. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2139. } else {
  2140. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2141. }
  2142. }
  2143. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2144. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2145. }
  2146. //删除记录
  2147. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2148. //查询默认仓库剩余多少库存
  2149. var sum_count int64
  2150. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2151. for _, its := range stockInfo {
  2152. if its.MaxUnit == drug.MaxUnit {
  2153. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2154. }
  2155. sum_count += its.StockMaxNumber + its.StockMinNumber
  2156. }
  2157. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2158. }
  2159. }
  2160. }
  2161. }
  2162. }
  2163. //保存处方开药
  2164. if drugOutConfig.IsOpen == 1 {
  2165. //修改处方
  2166. for _, advice := range advices {
  2167. var drug_id int64
  2168. var prescribing_number float64
  2169. var prescribingNumberUnit string
  2170. var prescribingNumber string
  2171. var adviceId int64
  2172. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2173. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2174. }
  2175. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2176. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2177. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2178. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2179. }
  2180. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2181. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2182. }
  2183. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2184. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2185. }
  2186. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2187. if drug.ID == 0 {
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2189. return
  2190. }
  2191. //查询药品的所有库存
  2192. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2193. var total_count int64
  2194. for _, it := range list {
  2195. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2196. }
  2197. totals := strconv.FormatInt(total_count, 10)
  2198. //查询该药品是否存在开药记录
  2199. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2200. //新增处方
  2201. if advicelist.ID == 0 {
  2202. //查询最新批次库存
  2203. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2204. var batch_number_count int64
  2205. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2206. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2207. all_count, _ := strconv.ParseFloat(totals, 64)
  2208. if prescribingNumberUnit == drug.MinUnit {
  2209. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2210. if drug.IsUse != 1 {
  2211. if drug.IsProject == 0 || drug.IsProject == 2 {
  2212. if all_count == 0 {
  2213. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2214. return
  2215. }
  2216. if prescribing_number > all_count {
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2218. return
  2219. }
  2220. }
  2221. if adminInfo.CurrentOrgId == 10215 {
  2222. if prescribing_number > batch_number_all_count {
  2223. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2224. return
  2225. }
  2226. }
  2227. }
  2228. } else {
  2229. if prescribingNumberUnit == drug.MaxUnit {
  2230. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2231. num := prescribing_number * float64(drug.MinNumber)
  2232. if drug.IsUse != 1 {
  2233. if drug.IsProject == 0 || drug.IsProject == 2 {
  2234. if all_count == 0 {
  2235. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2236. return
  2237. }
  2238. if num > all_count {
  2239. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2240. return
  2241. }
  2242. }
  2243. if adminInfo.CurrentOrgId == 10215 {
  2244. if prescribing_number > batch_number_all_count {
  2245. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2246. return
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. }
  2253. //修改处方
  2254. if advicelist.ID > 0 {
  2255. //查询最新批次库存
  2256. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2257. var batch_number_count int64
  2258. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2259. var device_number int64
  2260. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2261. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2262. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2263. device_number = prescribingNumberInt * drug.MinNumber
  2264. }
  2265. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2266. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2267. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2268. device_number = prescribingNumberInt
  2269. }
  2270. var number_count int64
  2271. if prescribingNumberUnit == drug.MaxUnit {
  2272. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2273. number_count = prescribingNumberInt * drug.MinNumber
  2274. }
  2275. if prescribingNumberUnit == drug.MinUnit {
  2276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2277. number_count = prescribingNumberInt
  2278. }
  2279. //如果修改的数量大于之前修改的数量
  2280. if (number_count - device_number) > 0 {
  2281. //如果修改的差数量 大于库存数量
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if total_count == 0 {
  2285. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2286. return
  2287. }
  2288. if (number_count - device_number) > total_count {
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2290. return
  2291. }
  2292. }
  2293. if adminInfo.CurrentOrgId == 10215 {
  2294. if (number_count - device_number) > batch_number_count {
  2295. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2296. return
  2297. }
  2298. }
  2299. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2300. //查询历史出库数据总批次
  2301. // 查询该药品最后一次出库记录
  2302. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2303. var out_count int64
  2304. var in_count int64
  2305. var stock_max_number int64
  2306. var stock_min_number int64
  2307. for _, it := range outInfo {
  2308. if it.CountUnit == drug.MaxUnit {
  2309. it.Count = it.Count * drug.MinNumber
  2310. }
  2311. out_count += it.Count
  2312. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2313. stock_max_number = warehouseInfoList.StockMaxNumber
  2314. stock_min_number = warehouseInfoList.StockMinNumber
  2315. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2316. }
  2317. if out_count > 0 {
  2318. if (number_count - device_number) > in_count {
  2319. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2320. return
  2321. }
  2322. }
  2323. // 未出库
  2324. if out_count == 0 {
  2325. var sum_in_count int64
  2326. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2327. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2328. if sum_in_count == 0 {
  2329. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2330. return
  2331. }
  2332. //如果修改的数量大于有库存的第一个批次
  2333. if number_count > sum_in_count {
  2334. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2335. return
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. //校验耗材库存
  2352. if goodOutConfig.IsOpen == 1 {
  2353. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2354. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2355. if len(prescriptions) > 0 {
  2356. for _, item := range prescriptions {
  2357. items := item.(map[string]interface{})
  2358. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2359. projects := items["project"].([]interface{})
  2360. if len(projects) > 0 {
  2361. for _, project := range projects {
  2362. var project_id int64
  2363. var project_type int64
  2364. var totals float64
  2365. var project_name string
  2366. var parsetotal int64
  2367. var id int64
  2368. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2369. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2370. }
  2371. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2372. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2373. }
  2374. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2375. total, _ := project.(map[string]interface{})["total"].(string)
  2376. totals, _ = strconv.ParseFloat(total, 64)
  2377. }
  2378. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2379. project_name = project.(map[string]interface{})["project_name"].(string)
  2380. }
  2381. if project_type == 3 {
  2382. //查找该耗材的出库记录
  2383. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2384. if len(goodWarehouseInfo) == 0 {
  2385. //查询耗材库存
  2386. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2387. var stock_count int64
  2388. for _, it := range list {
  2389. stock_count += it.StockCount
  2390. }
  2391. stock_counts := strconv.FormatInt(stock_count, 10)
  2392. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2393. if stock_total_count == 0 {
  2394. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2395. return
  2396. }
  2397. if totals > stock_total_count {
  2398. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2399. return
  2400. }
  2401. }
  2402. if len(goodWarehouseInfo) > 0 {
  2403. //查询该患者耗材的历史数据
  2404. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2405. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2406. //数量发生改变
  2407. if parsetotal != count {
  2408. //如果现在的数量大于历史数量,就要看库存是否足够
  2409. if parsetotal > count {
  2410. //查询耗材所有库存
  2411. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2412. var stock_count int64
  2413. for _, it := range list {
  2414. stock_count += it.StockCount
  2415. }
  2416. //库存不足
  2417. if stock_count == 0 {
  2418. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2419. return
  2420. }
  2421. if (parsetotal - count) > stock_count {
  2422. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2423. return
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. //不使用耗材保存处方出库
  2437. if goodOutConfig.IsOpen != 1 {
  2438. if stockConfig.IsOpen == 1 {
  2439. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2440. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2441. if len(prescriptions) > 0 {
  2442. for _, item := range prescriptions {
  2443. items := item.(map[string]interface{})
  2444. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2445. projects := items["project"].([]interface{})
  2446. if len(projects) > 0 {
  2447. for _, project := range projects {
  2448. var project_id int64
  2449. var project_type int64
  2450. var totals float64
  2451. var project_name string
  2452. var parsetotal int64
  2453. var id int64
  2454. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2455. id = int64(project.(map[string]interface{})["id"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2458. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2459. }
  2460. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2461. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2462. }
  2463. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2464. total, _ := project.(map[string]interface{})["total"].(string)
  2465. totals, _ = strconv.ParseFloat(total, 64)
  2466. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2467. }
  2468. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2469. project_name = project.(map[string]interface{})["project_name"].(string)
  2470. }
  2471. if project_type == 3 {
  2472. //查找该耗材的出库记录
  2473. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2474. //没有出库记录
  2475. if len(goodWarehouseInfo) == 0 {
  2476. //查询耗材库存
  2477. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2478. var stock_count int64
  2479. for _, it := range list {
  2480. stock_count += it.StockCount
  2481. }
  2482. stock_counts := strconv.FormatInt(stock_count, 10)
  2483. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2484. if stock_total_count == 0 {
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. if totals > stock_total_count {
  2489. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2490. return
  2491. }
  2492. //查找今日该患者已经出库的所有耗材
  2493. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2494. for _, item := range goodList {
  2495. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2496. var flush_count int64
  2497. for _, it := range goodListSix {
  2498. flush_count += it.StockCount
  2499. }
  2500. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2501. creater := adminInfo.AdminUser.Id
  2502. if errs != nil {
  2503. goodErrcode := models.XtGoodErrcode{
  2504. UserOrgId: item.OrgId,
  2505. Errcode: "手动出库更新剩余出库失败",
  2506. GoodId: item.GoodId,
  2507. Status: 1,
  2508. Ctime: time.Now().Unix(),
  2509. Mtime: 0,
  2510. Count: 0,
  2511. StockCount: 0,
  2512. Creater: creater,
  2513. BatchNumberId: 0,
  2514. WarehouseOutId: 0,
  2515. }
  2516. service.CreateGoodErrcode(goodErrcode)
  2517. }
  2518. }
  2519. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2520. }
  2521. //有出库记录
  2522. if len(goodWarehouseInfo) > 0 {
  2523. //查询该患者耗材的历史数据
  2524. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2525. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2526. //数量发生改变
  2527. if parsetotal != count {
  2528. //查找今日该患者已经出库的所有耗材
  2529. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2530. for _, item := range goodList {
  2531. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2532. var flush_count int64
  2533. for _, it := range goodListSix {
  2534. flush_count += it.StockCount
  2535. }
  2536. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2537. //减少出库数量
  2538. creater := adminInfo.AdminUser.Id
  2539. if errs != nil {
  2540. goodErrcode := models.XtGoodErrcode{
  2541. UserOrgId: item.OrgId,
  2542. Errcode: "手动出库更新剩余出库失败",
  2543. GoodId: item.GoodId,
  2544. Status: 1,
  2545. Ctime: time.Now().Unix(),
  2546. Mtime: 0,
  2547. Count: 0,
  2548. StockCount: 0,
  2549. Creater: creater,
  2550. BatchNumberId: 0,
  2551. WarehouseOutId: 0,
  2552. }
  2553. service.CreateGoodErrcode(goodErrcode)
  2554. }
  2555. //查询默认仓库
  2556. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2557. var total_count int64
  2558. for _, it := range stockList {
  2559. total_count += it.StockCount
  2560. }
  2561. //基础库插入数据
  2562. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2563. }
  2564. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. }
  2574. }
  2575. }
  2576. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2577. var hpInfo models.HisPrescriptionInfo
  2578. if info.ID == 0 {
  2579. var randNum int
  2580. randNum = rand.Intn(10000) + 1000
  2581. timestamp := time.Now().Unix()
  2582. tempTime := time.Unix(timestamp, 0)
  2583. timeFormat := tempTime.Format("20060102150405")
  2584. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2585. hpInfo = models.HisPrescriptionInfo{
  2586. HisPatientId: his_patient_id,
  2587. UserOrgId: adminInfo.CurrentOrgId,
  2588. RecordDate: theTime.Unix(),
  2589. PatientId: patient_id,
  2590. Status: 1,
  2591. Ctime: time.Now().Unix(),
  2592. Mtime: time.Now().Unix(),
  2593. Creator: adminInfo.AdminUser.Id,
  2594. Modifier: adminInfo.AdminUser.Id,
  2595. Diagnosis: diagnose,
  2596. SickHistory: sick_history,
  2597. Departments: department,
  2598. RegisterType: reg_type,
  2599. PrescriptionNumber: p_number,
  2600. PrescriptionStatus: 1,
  2601. Doctor: role.UserName,
  2602. DoctorId: doctor_id,
  2603. SickType: sick_type,
  2604. PType: p_type,
  2605. PatientDiagnosis: patient_diagnose,
  2606. }
  2607. service.SavePatientPrescriptionInfo(hpInfo)
  2608. //创建步骤表
  2609. finish := models.XtDialysisFinish{
  2610. IsFinish: 1,
  2611. UserOrgId: adminInfo.CurrentOrgId,
  2612. Status: 1,
  2613. Ctime: time.Now().Unix(),
  2614. Mtime: 0,
  2615. Module: 4,
  2616. RecordDate: theTime.Unix(),
  2617. Sourse: 1,
  2618. PatientId: patient_id,
  2619. }
  2620. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2621. if dialysisFinish.ID == 0 {
  2622. service.CreateDialysisFinish(finish)
  2623. }
  2624. redis := service.RedisClient()
  2625. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2626. redis.Set(key, "", time.Second)
  2627. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2628. redis.Set(keyOne, "", time.Second)
  2629. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2630. redis.Set(keySeven, "", time.Second)
  2631. defer redis.Close()
  2632. } else {
  2633. hpInfo = models.HisPrescriptionInfo{
  2634. ID: info.ID,
  2635. UserOrgId: adminInfo.CurrentOrgId,
  2636. RecordDate: info.RecordDate,
  2637. PatientId: info.PatientId,
  2638. Status: 1,
  2639. Ctime: info.Ctime,
  2640. Mtime: time.Now().Unix(),
  2641. Creator: info.Creator,
  2642. Modifier: adminInfo.AdminUser.Id,
  2643. Diagnosis: diagnose,
  2644. SickHistory: sick_history,
  2645. Departments: department,
  2646. RegisterType: reg_type,
  2647. PrescriptionNumber: info.PrescriptionNumber,
  2648. Doctor: role.UserName,
  2649. PrescriptionStatus: info.PrescriptionStatus,
  2650. DoctorId: doctor_id,
  2651. SickType: sick_type,
  2652. PType: info.PType,
  2653. HisPatientId: info.HisPatientId,
  2654. PatientDiagnosis: patient_diagnose,
  2655. }
  2656. service.SavePatientPrescriptionInfo(hpInfo)
  2657. //创建步骤表
  2658. finish := models.XtDialysisFinish{
  2659. IsFinish: 1,
  2660. UserOrgId: adminInfo.CurrentOrgId,
  2661. Status: 1,
  2662. Ctime: time.Now().Unix(),
  2663. Mtime: 0,
  2664. Module: 4,
  2665. RecordDate: info.RecordDate,
  2666. Sourse: 1,
  2667. PatientId: info.PatientId,
  2668. }
  2669. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2670. if dialysisFinish.ID == 0 {
  2671. service.CreateDialysisFinish(finish)
  2672. }
  2673. redis := service.RedisClient()
  2674. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2675. redis.Set(key, "", time.Second)
  2676. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2677. redis.Set(keyOne, "", time.Second)
  2678. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2679. redis.Set(keySeven, "", time.Second)
  2680. defer redis.Close()
  2681. }
  2682. //定义切片
  2683. var adviceList []models.HisDoctorAdviceInfo
  2684. var projectList []models.HisPrescriptionProject
  2685. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2686. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2687. var tempPrescription *models.HisPrescription
  2688. if len(prescriptions) > 0 {
  2689. for _, item := range prescriptions {
  2690. items := item.(map[string]interface{})
  2691. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2692. utils.ErrorLog("id")
  2693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2694. return
  2695. }
  2696. id := int64(items["id"].(float64))
  2697. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2698. tempPrescription = &new_prescription
  2699. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2700. utils.ErrorLog("type")
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. types := int64(items["type"].(float64))
  2705. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2706. utils.ErrorLog("med_type")
  2707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2708. return
  2709. }
  2710. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2711. if med_type == "0" {
  2712. med_type = "14"
  2713. }
  2714. //if order_status == 0 {
  2715. // order_status = 1
  2716. //}
  2717. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2718. utils.ErrorLog("pre_time")
  2719. }
  2720. preTime, _ := items["pre_time"].(string)
  2721. timeLayout := "2006-01-02"
  2722. loc, _ := time.LoadLocation("Local")
  2723. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2724. if err != nil {
  2725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2726. return
  2727. }
  2728. pTime := theTime2.Unix()
  2729. ctime := time.Now().Unix()
  2730. if tempPrescription.ID == 0 {
  2731. prescription := &models.HisPrescription{
  2732. ID: 0,
  2733. PatientId: patient_id,
  2734. UserOrgId: adminInfo.CurrentOrgId,
  2735. RecordDate: recordDateTime,
  2736. Ctime: ctime,
  2737. Mtime: ctime,
  2738. Type: types,
  2739. Modifier: adminInfo.AdminUser.Id,
  2740. Creator: adminInfo.AdminUser.Id,
  2741. Status: 1,
  2742. Doctor: role.UserName,
  2743. HisPatientId: his_patient_id,
  2744. OrderStatus: 1,
  2745. BatchNumber: "",
  2746. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2747. PreTime: pTime,
  2748. PType: p_type,
  2749. MedType: med_type,
  2750. }
  2751. tempPrescription = prescription
  2752. service.SaveHisPrescription(tempPrescription)
  2753. redis := service.RedisClient()
  2754. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2755. redis.Set(key, "", time.Second)
  2756. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2757. redis.Set(keyOne, "", time.Second)
  2758. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2759. redis.Set(keySeven, "", time.Second)
  2760. defer redis.Close()
  2761. } else {
  2762. tempPrescription.ID = id
  2763. tempPrescription.Type = types
  2764. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2765. tempPrescription.Mtime = time.Now().Unix()
  2766. tempPrescription.Doctor = role.UserName
  2767. //tempPrescription.OrderStatus = order_status
  2768. tempPrescription.PreTime = pTime
  2769. tempPrescription.MedType = med_type
  2770. service.SaveHisPrescription(tempPrescription)
  2771. redis := service.RedisClient()
  2772. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2773. redis.Set(key, "", time.Second)
  2774. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2775. redis.Set(keyOne, "", time.Second)
  2776. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2777. redis.Set(keySeven, "", time.Second)
  2778. defer redis.Close()
  2779. }
  2780. //service.SaveHisPrescription(prescription)
  2781. //更改患者挂号状态
  2782. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2783. fmt.Println("更改失败", err2)
  2784. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2785. advices := items["advices"].([]interface{})
  2786. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2787. groupNo := int64(0)
  2788. ctime := time.Now().Unix()
  2789. mtime := ctime
  2790. if len(advices) > 0 {
  2791. for _, advice := range advices {
  2792. var s models.HisDoctorAdviceInfo
  2793. s.PrescriptionId = tempPrescription.ID
  2794. s.AdviceType = 2
  2795. s.AdviceDoctor = doctor_id
  2796. s.StopState = 2
  2797. s.ExecutionState = 2
  2798. s.AdviceDate = recordDateTime
  2799. s.Status = 1
  2800. s.UserOrgId = adminInfo.CurrentOrgId
  2801. s.RecordDate = recordDateTime
  2802. s.StartTime = tempPrescription.PreTime
  2803. s.Groupno = groupNo
  2804. s.CreatedTime = ctime
  2805. s.UpdatedTime = mtime
  2806. s.PatientId = patient_id
  2807. s.HisPatientId = his_patient_id
  2808. s.StartTime = pTime
  2809. s.IsSettle = 2
  2810. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2811. if errcode > 0 {
  2812. c.ServeFailJSONWithSGJErrorCode(errcode)
  2813. return
  2814. }
  2815. s.StartTime = pTime
  2816. var total_count int64 //处方总库存
  2817. //查询改药品信息
  2818. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2819. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2820. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2821. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2822. total_count += prescribingNumberSeven * medical.MinNumber
  2823. }
  2824. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2825. total_count += prescribingNumberSeven
  2826. }
  2827. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2828. total_count += prescribingNumberSeven
  2829. }
  2830. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2831. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2832. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2833. if s.Price != lastWarehouse.RetailPrice {
  2834. s.Price = lastWarehouse.RetailPrice
  2835. }
  2836. if s.Price == 0 {
  2837. s.Price = lastWarehouse.RetailPrice
  2838. }
  2839. }
  2840. service.CreateHisDoctorAdvice(&s)
  2841. //记录日志
  2842. byterequest, _ := json.Marshal(s)
  2843. adviceLog := models.XtDoctorAdviceLog{
  2844. UserOrgId: s.UserOrgId,
  2845. PatientId: s.PatientId,
  2846. AdminUserId: adminInfo.AdminUser.Id,
  2847. Module: 1,
  2848. ErrLog: string(byterequest),
  2849. Status: 1,
  2850. Ctime: time.Now().Unix(),
  2851. Mtime: 0,
  2852. Source: "电脑端新建his医嘱",
  2853. RecordDate: s.AdviceDate,
  2854. }
  2855. service.CreateDoctorAdviceLog(adviceLog)
  2856. //存储切片中
  2857. adviceList = append(adviceList, s)
  2858. redis := service.RedisClient()
  2859. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2860. redis.Set(key, "", time.Second)
  2861. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2862. redis.Set(keyOne, "", time.Second)
  2863. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2864. redis.Set(keySeven, "", time.Second)
  2865. var randNum int
  2866. randNum = rand.Intn(10000) + 1000
  2867. timestamp := time.Now().Unix()
  2868. tempTime := time.Unix(timestamp, 0)
  2869. timeFormat := tempTime.Format("20060102150405")
  2870. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2871. service.CreateHisDoctorAdvice(&s)
  2872. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2873. redis.Set(keySix, "", time.Second)
  2874. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2875. redis.Set(keyFive, "", time.Second)
  2876. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2877. redis.Set(keyEight, "", time.Second)
  2878. defer redis.Close()
  2879. }
  2880. }
  2881. }
  2882. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2883. projects := items["project"].([]interface{})
  2884. if len(projects) > 0 {
  2885. for _, project := range projects {
  2886. var p models.HisPrescriptionProject
  2887. p.PrescriptionId = tempPrescription.ID
  2888. p.Ctime = time.Now().Unix()
  2889. p.Mtime = time.Now().Unix()
  2890. p.PatientId = patient_id
  2891. p.RecordDate = recordDateTime
  2892. p.Doctor = doctor_id
  2893. p.UserOrgId = adminInfo.CurrentOrgId
  2894. p.HisPatientId = his_patient_id
  2895. p.Status = 1
  2896. p.StartTime = pTime
  2897. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2898. if errcode > 0 {
  2899. c.ServeFailJSONWithSGJErrorCode(errcode)
  2900. return
  2901. }
  2902. if p.ID == 0 {
  2903. p.IsOut = 2
  2904. }
  2905. if p.ID > 0 {
  2906. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2907. p.IsOut = projectDetail.IsOut
  2908. }
  2909. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2910. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2911. if p.Type == 3 {
  2912. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2913. if p.Price != lastWarehouse.PackingPrice {
  2914. p.Price = lastWarehouse.PackingPrice
  2915. }
  2916. if p.Unit == "" {
  2917. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2918. p.Unit = goodInfoOne.PackingUnit
  2919. }
  2920. }
  2921. }
  2922. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2923. //
  2924. // if p.Type == 3 {
  2925. // //查询该耗材是否停用
  2926. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2927. // //表示该耗材已经停用,不能保存
  2928. // if goodInfoSeven.ID == 0 {
  2929. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2930. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2931. // return
  2932. // }
  2933. // }
  2934. //
  2935. //}
  2936. service.CreateHisProjectTwo(&p)
  2937. //记录日志
  2938. byterequest, _ := json.Marshal(p)
  2939. adviceLog := models.XtDoctorAdviceLog{
  2940. UserOrgId: p.UserOrgId,
  2941. PatientId: p.PatientId,
  2942. AdminUserId: adminInfo.AdminUser.Id,
  2943. Module: 1,
  2944. ErrLog: string(byterequest),
  2945. Status: 1,
  2946. Ctime: time.Now().Unix(),
  2947. Mtime: 0,
  2948. Source: "电脑端新建his项目",
  2949. RecordDate: p.RecordDate,
  2950. }
  2951. service.CreateDoctorAdviceLog(adviceLog)
  2952. projectList = append(projectList, p)
  2953. var randNum int
  2954. randNum = rand.Intn(10000) + 1000
  2955. timestamp := time.Now().Unix()
  2956. tempTime := time.Unix(timestamp, 0)
  2957. timeFormat := tempTime.Format("20060102150405")
  2958. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2959. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2960. //新增或者编辑项目,修改对应的标签数据
  2961. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2962. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2963. var label models.HisLabelPrintInfo
  2964. project, _ := service.GetProjectDetail(p.ProjectId)
  2965. if project.CostClassify == 3 { //类别为检验检查
  2966. if p.TeamId > 0 { //检验检查组套
  2967. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2968. if tempLabel.ID == 0 {
  2969. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2970. label.Number = tempPrescription.PrescriptionNumber
  2971. label.ProjectId = project.ID
  2972. label.Status = 1
  2973. label.IsPrint = 2
  2974. label.DoctorId = info.DoctorId
  2975. label.UserOrgId = p.UserOrgId
  2976. label.PatientId = patient_id
  2977. label.RecordDate = recordDateTime
  2978. label.Ctime = time.Now().Unix()
  2979. label.Mtime = time.Now().Unix()
  2980. label.ItemId = p.TeamId
  2981. label.FeedetlSn = p.FeedetlSn
  2982. label.PProjectId = p.ID
  2983. label.ProjectName = team.ProjectTeam
  2984. label.PatientName = patient.Name
  2985. service.CreateHisLabelRecord(&label)
  2986. }
  2987. } else { //单条检验检查项目
  2988. label.Number = tempPrescription.PrescriptionNumber
  2989. label.ProjectId = project.ID
  2990. label.Status = 1
  2991. label.DoctorId = info.DoctorId
  2992. label.UserOrgId = p.UserOrgId
  2993. label.PatientId = patient_id
  2994. label.RecordDate = recordDateTime
  2995. label.IsPrint = 2
  2996. label.Ctime = time.Now().Unix()
  2997. label.Mtime = time.Now().Unix()
  2998. label.FeedetlSn = p.FeedetlSn
  2999. label.PProjectId = p.ID
  3000. label.ItemId = p.TeamId
  3001. label.ProjectName = project.ProjectName
  3002. label.PatientName = patient.Name
  3003. service.CreateHisLabelRecord(&label)
  3004. }
  3005. }
  3006. }
  3007. }
  3008. service.SaveHisProjectTwo(&p)
  3009. }
  3010. }
  3011. }
  3012. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3013. // addition := items["addition"].([]interface{})
  3014. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3015. // ctime := time.Now().Unix()
  3016. // mtime := ctime
  3017. // if len(addition) > 0 {
  3018. // for _, item := range addition {
  3019. // var s models.HisAdditionalCharge
  3020. // s.PrescriptionId = tempPrescription.ID
  3021. // s.Status = 1
  3022. // s.UserOrgId = adminInfo.CurrentOrgId
  3023. // s.RecordDate = recordDateTime
  3024. // s.CreatedTime = ctime
  3025. // s.UpdatedTime = mtime
  3026. // s.PatientId = patient_id
  3027. // s.HisPatientId = his_patient_id
  3028. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3029. // if errcode > 0 {
  3030. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3031. // return
  3032. // }
  3033. // service.CreateAdditionalCharge(&s)
  3034. // var randNum int
  3035. // randNum = rand.Intn(10000) + 1000
  3036. // timestamp := time.Now().Unix()
  3037. // tempTime := time.Unix(timestamp, 0)
  3038. // timeFormat := tempTime.Format("20060102150405")
  3039. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3040. // service.CreateAdditionalCharge(&s)
  3041. //
  3042. // }
  3043. // }
  3044. //}
  3045. }
  3046. }
  3047. //查询今日该患者开的药品处方
  3048. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3049. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3050. //药品出库
  3051. if drugOutConfig.IsOpen == 1 {
  3052. for _, item := range hisdoctorlist {
  3053. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3054. // 查询该药品最后一次出库记录
  3055. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3056. if len(druginfo) > 0 {
  3057. //回退库存
  3058. for _, it := range druginfo {
  3059. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3060. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3061. }
  3062. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3063. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3064. }
  3065. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3066. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3067. }
  3068. }
  3069. }
  3070. //删除记录
  3071. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3072. //查询最后一次数据
  3073. if drugOutConfig.IsOpen == 1 {
  3074. //出库
  3075. if drug.IsUse == 2 {
  3076. creater := adminInfo.AdminUser.Id
  3077. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3078. }
  3079. //更新字典里面的库存
  3080. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3081. var sum_count int64
  3082. for _, its := range stockInfo {
  3083. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3084. if its.MaxUnit == baseDrug.MaxUnit {
  3085. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3086. }
  3087. sum_count += its.StockMaxNumber + its.StockMinNumber
  3088. }
  3089. //更新基础库存
  3090. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3091. //剩余库存
  3092. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3093. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3094. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3095. }
  3096. }
  3097. }
  3098. //耗材保存处方出库
  3099. if goodOutConfig.IsOpen == 1 {
  3100. //查询今日耗材出库数量
  3101. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3102. for _, item := range hisgoodlist {
  3103. //查询历史出库数据
  3104. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3105. var out_count_five int64
  3106. for _, item := range flowGood {
  3107. out_count_five += item.Count
  3108. }
  3109. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3110. if out_count_five != parseIntCount {
  3111. //查询耗材最后一次出库记录
  3112. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3113. //查询默认出库仓库库存
  3114. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3115. if len(wareOut) > 0 {
  3116. for _, it := range wareOut {
  3117. //回退库存
  3118. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3119. //删除出库记录
  3120. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3121. }
  3122. }
  3123. timeStr := time.Now().Format("2006-01-02")
  3124. timeArr := strings.Split(timeStr, "-")
  3125. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3126. total = total + 1
  3127. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3128. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3129. number = number + total
  3130. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3131. operation_time := time.Now().Unix()
  3132. creater := c.GetAdminUserInfo().AdminUser.Id
  3133. recordDateStr := time.Now().Format("2006-01-02")
  3134. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3135. nowtime := recordDate.Unix()
  3136. warehouseOut := models.WarehouseOut{
  3137. WarehouseOutOrderNumber: warehousing_out_order,
  3138. OperationTime: operation_time,
  3139. OrgId: adminInfo.CurrentOrgId,
  3140. Creater: creater,
  3141. Ctime: time.Now().Unix(),
  3142. Status: 1,
  3143. WarehouseOutTime: nowtime,
  3144. Type: 1,
  3145. StorehouseId: storeConfig.StorehouseOutInfo,
  3146. IsCheck: 1,
  3147. IsSys: 1,
  3148. }
  3149. //查询是否生成出库单
  3150. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3151. if out.ID == 0 {
  3152. service.AddSigleWarehouseOut(&warehouseOut)
  3153. }
  3154. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3155. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3156. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3157. dialyPrepareOne := models.DialysisBeforePrepare{
  3158. GoodTypeId: goodObj.GoodTypeId,
  3159. GoodId: item.ProjectId,
  3160. PatientId: item.PatientId,
  3161. RecordDate: item.RecordDate,
  3162. UserOrgId: adminInfo.CurrentOrgId,
  3163. Count: parseIntCount,
  3164. Ctime: time.Now().Unix(),
  3165. Creater: creater,
  3166. Status: 1,
  3167. StorehouseId: houseConfig.StorehouseOutInfo,
  3168. ProjectId: item.ID,
  3169. }
  3170. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3171. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3172. //查询历史出库数据
  3173. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3174. var out_count int64
  3175. for _, item := range flowGood {
  3176. out_count += item.Count
  3177. }
  3178. //如果历史数和当前数据不想等才进行退库出库
  3179. if out_count != parseIntCount {
  3180. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3181. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3182. detail := models.AutomaticReduceDetail{
  3183. WarehouseOutId: 0,
  3184. WarehouseOutOrderNumber: "",
  3185. PatientId: item.PatientId,
  3186. Ctime: time.Now().Unix(),
  3187. Mtime: 0,
  3188. Status: 1,
  3189. RecordTime: item.RecordDate,
  3190. OrgId: item.UserOrgId,
  3191. GoodId: item.ProjectId,
  3192. GoodTypeId: 0,
  3193. Count: parseIntCount,
  3194. Type: 0,
  3195. ProjectId: item.ID,
  3196. StorehouseId: 0,
  3197. }
  3198. service.CreateAutoDetail(detail)
  3199. //查询剩余库存
  3200. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3201. var sum_count int64
  3202. for _, item := range goodList {
  3203. sum_count += item.StockCount
  3204. }
  3205. //更新剩余库存
  3206. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3207. //耗材
  3208. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3209. }
  3210. }
  3211. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3212. //查询历史出库数据
  3213. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3214. var out_count int64
  3215. for _, item := range flowGood {
  3216. out_count += item.Count
  3217. }
  3218. //如果历史数和当前数据不想等才进行退库出库
  3219. if out_count != parseIntCount {
  3220. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3221. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3222. detail := models.AutomaticReduceDetail{
  3223. WarehouseOutId: 0,
  3224. WarehouseOutOrderNumber: "",
  3225. PatientId: item.PatientId,
  3226. Ctime: time.Now().Unix(),
  3227. Mtime: 0,
  3228. Status: 1,
  3229. RecordTime: item.RecordDate,
  3230. OrgId: item.UserOrgId,
  3231. GoodId: item.ProjectId,
  3232. GoodTypeId: 0,
  3233. Count: parseIntCount,
  3234. Type: 0,
  3235. ProjectId: item.ID,
  3236. StorehouseId: 0,
  3237. }
  3238. service.CreateAutoDetail(detail)
  3239. //查询剩余库存
  3240. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3241. var sum_count int64
  3242. for _, item := range goodList {
  3243. sum_count += item.StockCount
  3244. }
  3245. //更新剩余库存
  3246. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3247. //耗材
  3248. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3249. }
  3250. }
  3251. }
  3252. }
  3253. }
  3254. }
  3255. //redisClient := service.RedisClient()
  3256. //defer redisClient.Close()
  3257. //
  3258. //list := models.HisList{
  3259. // Patient_id: patient_id,
  3260. // Advice_id:0,
  3261. // Record_date: 0,
  3262. // Advice: adviceList,
  3263. // Project: nil,
  3264. //}
  3265. //hisLis = append(hisLis, list)
  3266. //
  3267. //advice_json, _ := json.Marshal(&hisLis)
  3268. //redisClient.RPush("111", advice_json).Result()
  3269. //result, _ := redisClient.RPop("111").Result()
  3270. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3271. //
  3272. //var dat []map[string]interface{}
  3273. //json.Unmarshal([]byte(result), &dat)
  3274. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3275. //
  3276. //for k,v:=range dat{
  3277. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3278. //}
  3279. //project_json, _ := json.Marshal(&projectList)
  3280. //redisClient.LPush("222", project_json).Result()
  3281. if err == nil {
  3282. c.ServeSuccessJSON(map[string]interface{}{
  3283. "msg": "保存成功",
  3284. })
  3285. return
  3286. } else {
  3287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3288. return
  3289. }
  3290. }
  3291. func (c *HisApiController) EditHisPrescription() {
  3292. record_date := c.GetString("record_date")
  3293. patient_id, _ := c.GetInt64("patient_id")
  3294. reg_type, _ := c.GetInt64("reg_type")
  3295. //diagnose, _ := c.GetInt64("diagnose", 0)
  3296. diagnose := c.GetString("diagnose")
  3297. sick_type, _ := c.GetInt64("sick_type")
  3298. sick_history := c.GetString("sick_history")
  3299. doctor_id, _ := c.GetInt64("doctor", 0)
  3300. department, _ := c.GetInt64("department", 0)
  3301. his_patient_id, _ := c.GetInt64("his_patient_id")
  3302. p_type, _ := c.GetInt64("p_type")
  3303. dataBody := make(map[string]interface{}, 0)
  3304. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3305. if err != nil {
  3306. utils.ErrorLog(err.Error())
  3307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3308. return
  3309. }
  3310. timeLayout := "2006-01-02"
  3311. loc, _ := time.LoadLocation("Local")
  3312. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3313. if err != nil {
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3315. return
  3316. }
  3317. adminInfo := c.GetAdminUserInfo()
  3318. recordDateTime := theTime.Unix()
  3319. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3320. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3321. var hpInfo models.HisPrescriptionInfo
  3322. if info.ID == 0 {
  3323. var randNum int
  3324. randNum = rand.Intn(10000) + 1000
  3325. timestamp := time.Now().Unix()
  3326. tempTime := time.Unix(timestamp, 0)
  3327. timeFormat := tempTime.Format("20060102150405")
  3328. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3329. hpInfo = models.HisPrescriptionInfo{
  3330. UserOrgId: adminInfo.CurrentOrgId,
  3331. RecordDate: theTime.Unix(),
  3332. PatientId: patient_id,
  3333. Status: 1,
  3334. Ctime: time.Now().Unix(),
  3335. Mtime: time.Now().Unix(),
  3336. Creator: adminInfo.AdminUser.Id,
  3337. Modifier: adminInfo.AdminUser.Id,
  3338. Diagnosis: diagnose,
  3339. SickHistory: sick_history,
  3340. Departments: department,
  3341. RegisterType: reg_type,
  3342. PrescriptionNumber: p_number,
  3343. PrescriptionStatus: 1,
  3344. Doctor: role.UserName,
  3345. DoctorId: doctor_id,
  3346. SickType: sick_type,
  3347. PType: p_type,
  3348. }
  3349. service.SavePatientPrescriptionInfo(hpInfo)
  3350. } else {
  3351. hpInfo = models.HisPrescriptionInfo{
  3352. ID: info.ID,
  3353. UserOrgId: adminInfo.CurrentOrgId,
  3354. RecordDate: info.RecordDate,
  3355. PatientId: info.PatientId,
  3356. Status: 1,
  3357. Ctime: info.Ctime,
  3358. Mtime: time.Now().Unix(),
  3359. Creator: info.Creator,
  3360. Modifier: adminInfo.AdminUser.Id,
  3361. Diagnosis: diagnose,
  3362. SickHistory: sick_history,
  3363. Departments: department,
  3364. RegisterType: reg_type,
  3365. PrescriptionNumber: info.PrescriptionNumber,
  3366. Doctor: role.UserName,
  3367. PrescriptionStatus: info.PrescriptionStatus,
  3368. DoctorId: doctor_id,
  3369. SickType: sick_type,
  3370. PType: info.PType,
  3371. }
  3372. service.SavePatientPrescriptionInfo(hpInfo)
  3373. }
  3374. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3375. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3376. if len(prescriptions) > 0 {
  3377. for _, item := range prescriptions {
  3378. items := item.(map[string]interface{})
  3379. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3380. utils.ErrorLog("id")
  3381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3382. return
  3383. }
  3384. id := int64(items["id"].(float64))
  3385. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3386. utils.ErrorLog("type")
  3387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3388. return
  3389. }
  3390. types := int64(items["type"].(float64))
  3391. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3392. utils.ErrorLog("med_type")
  3393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3394. return
  3395. }
  3396. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3397. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3398. ctime := time.Now().Unix()
  3399. prescription := &models.HisPrescription{
  3400. ID: id,
  3401. PatientId: patient_id,
  3402. UserOrgId: adminInfo.CurrentOrgId,
  3403. RecordDate: recordDateTime,
  3404. Ctime: ctime,
  3405. Mtime: ctime,
  3406. Type: types,
  3407. Modifier: adminInfo.AdminUser.Id,
  3408. Creator: adminInfo.AdminUser.Id,
  3409. Status: 1,
  3410. Doctor: role.UserName,
  3411. HisPatientId: his_patient_id,
  3412. OrderStatus: 1,
  3413. BatchNumber: "",
  3414. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3415. PType: hpInfo.PType,
  3416. MedType: med_type,
  3417. }
  3418. if historyPrescription.ID > 0 {
  3419. prescription.PreTime = historyPrescription.PreTime
  3420. }
  3421. service.SaveHisPrescription(prescription)
  3422. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3423. advices := items["advices"].([]interface{})
  3424. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3425. groupNo := int64(0)
  3426. ctime := time.Now().Unix()
  3427. mtime := ctime
  3428. if len(advices) > 0 {
  3429. for _, advice := range advices {
  3430. var s models.HisDoctorAdviceInfo
  3431. s.PrescriptionId = prescription.ID
  3432. s.AdviceType = 2
  3433. s.AdviceDoctor = adminInfo.AdminUser.Id
  3434. s.StopState = 2
  3435. s.ExecutionState = 2
  3436. s.AdviceDate = recordDateTime
  3437. s.Status = 1
  3438. s.UserOrgId = adminInfo.CurrentOrgId
  3439. s.RecordDate = recordDateTime
  3440. s.StartTime = prescription.PreTime
  3441. s.Groupno = groupNo
  3442. s.CreatedTime = ctime
  3443. s.UpdatedTime = mtime
  3444. s.PatientId = patient_id
  3445. s.HisPatientId = his_patient_id
  3446. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3447. if errcode > 0 {
  3448. c.ServeFailJSONWithSGJErrorCode(errcode)
  3449. return
  3450. }
  3451. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3452. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3453. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3454. if s.Price == 0 {
  3455. s.Price = lastWarehouse.RetailPrice
  3456. }
  3457. }
  3458. service.CreateHisDoctorAdvice(&s)
  3459. //记录日志
  3460. byterequest, _ := json.Marshal(s)
  3461. adviceLog := models.XtDoctorAdviceLog{
  3462. UserOrgId: s.UserOrgId,
  3463. PatientId: s.PatientId,
  3464. AdminUserId: adminInfo.AdminUser.Id,
  3465. Module: 1,
  3466. ErrLog: string(byterequest),
  3467. Status: 1,
  3468. Ctime: time.Now().Unix(),
  3469. Mtime: 0,
  3470. Source: "电脑端his医嘱修改",
  3471. RecordDate: s.AdviceDate,
  3472. }
  3473. service.CreateDoctorAdviceLog(adviceLog)
  3474. redis := service.RedisClient()
  3475. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3476. redis.Set(key, "", time.Second)
  3477. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3478. fmt.Println("keyOne", keyOne)
  3479. redis.Set(keyOne, "", time.Second)
  3480. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3481. redis.Set(keySeven, "", time.Second)
  3482. redis.Close()
  3483. }
  3484. }
  3485. }
  3486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3487. projects := items["project"].([]interface{})
  3488. if len(projects) > 0 {
  3489. for _, project := range projects {
  3490. var p models.HisPrescriptionProject
  3491. p.PrescriptionId = prescription.ID
  3492. p.Ctime = time.Now().Unix()
  3493. p.Mtime = time.Now().Unix()
  3494. p.PatientId = patient_id
  3495. p.RecordDate = recordDateTime
  3496. p.UserOrgId = adminInfo.CurrentOrgId
  3497. p.HisPatientId = his_patient_id
  3498. p.Status = 1
  3499. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3500. if errcode > 0 {
  3501. c.ServeFailJSONWithSGJErrorCode(errcode)
  3502. return
  3503. }
  3504. service.CreateHisProjectTwo(&p)
  3505. //记录日志
  3506. byterequest, _ := json.Marshal(p)
  3507. adviceLog := models.XtDoctorAdviceLog{
  3508. UserOrgId: p.UserOrgId,
  3509. PatientId: p.PatientId,
  3510. AdminUserId: adminInfo.AdminUser.Id,
  3511. Module: 1,
  3512. ErrLog: string(byterequest),
  3513. Status: 1,
  3514. Ctime: time.Now().Unix(),
  3515. Mtime: 0,
  3516. Source: "电脑端his项目修改",
  3517. RecordDate: p.RecordDate,
  3518. }
  3519. service.CreateDoctorAdviceLog(adviceLog)
  3520. }
  3521. }
  3522. }
  3523. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3524. addition := items["addition"].([]interface{})
  3525. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3526. ctime := time.Now().Unix()
  3527. mtime := ctime
  3528. if len(addition) > 0 {
  3529. for _, item := range addition {
  3530. var s models.HisAdditionalCharge
  3531. s.PrescriptionId = prescription.ID
  3532. s.Status = 1
  3533. s.UserOrgId = adminInfo.CurrentOrgId
  3534. s.RecordDate = recordDateTime
  3535. s.CreatedTime = ctime
  3536. s.UpdatedTime = mtime
  3537. s.PatientId = patient_id
  3538. s.HisPatientId = his_patient_id
  3539. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3540. if errcode > 0 {
  3541. c.ServeFailJSONWithSGJErrorCode(errcode)
  3542. return
  3543. }
  3544. service.CreateAdditionalCharge(&s)
  3545. }
  3546. }
  3547. }
  3548. }
  3549. }
  3550. }
  3551. if err == nil {
  3552. c.ServeSuccessJSON(map[string]interface{}{
  3553. "msg": "保存成功",
  3554. })
  3555. return
  3556. } else {
  3557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3558. return
  3559. }
  3560. }
  3561. func (c *HisApiController) DeletePrescription() {
  3562. prescription_id, _ := c.GetInt64("id")
  3563. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3564. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3565. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3566. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3567. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3568. //耗材保存处方出库
  3569. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3570. //已收费和已发药限制逻辑
  3571. isCharge := false
  3572. isMedicine := false
  3573. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3574. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3575. for _, item := range new_prescriptions {
  3576. if item.IsMedicine == 1 {
  3577. isMedicine = true
  3578. }
  3579. }
  3580. for _, item := range new_prescriptions {
  3581. if item.OrderStatus == 4 {
  3582. isCharge = true
  3583. }
  3584. }
  3585. if p_err != nil {
  3586. if new_prescription.ID > 0 {
  3587. if new_prescription.OrderStatus == 2 {
  3588. isCharge = true
  3589. }
  3590. }
  3591. }
  3592. for _, item := range advices {
  3593. if item.IsMedicine == 1 {
  3594. isMedicine = true
  3595. }
  3596. }
  3597. if isCharge {
  3598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3599. return
  3600. }
  3601. if isMedicine {
  3602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3603. return
  3604. }
  3605. //已收费和已发药限制逻辑
  3606. if len(projects) > 0 {
  3607. for _, item := range projects {
  3608. service.DeletePrintInfo(item.ID) //删除打印信息
  3609. if goodOutConfig.IsOpen != 1 {
  3610. if stockConfig.IsOpen == 1 {
  3611. if item.Type == 3 && item.IsOut == 1 {
  3612. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3613. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3614. good.Total = good.Total + f_count
  3615. service.UpdateGoodInfo(&good)
  3616. operation_time := time.Now().Unix()
  3617. creater := c.GetAdminUserInfo().AdminUser.Id
  3618. //创建退库单
  3619. timeStr := time.Now().Format("2006-01-02")
  3620. timeArr := strings.Split(timeStr, "-")
  3621. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3622. total = total + 1
  3623. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3624. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3625. cancelStock := models.CancelStock{
  3626. OrderNumber: orderNumber,
  3627. OperaTime: operation_time,
  3628. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3629. Creater: creater,
  3630. Ctime: time.Now().Unix(),
  3631. Status: 1,
  3632. ReturnTime: item.RecordDate,
  3633. Type: 1,
  3634. StorehouseId: houseConfig.StorehouseOutInfo,
  3635. IsCheck: 1,
  3636. }
  3637. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3638. if msgerrkonde == gorm.ErrRecordNotFound {
  3639. service.AddSigleCancelStock(&cancelStock)
  3640. }
  3641. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3642. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3643. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3644. //查询该耗材是否出库
  3645. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3646. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3647. deaerler, _ := service.GetDealerById(info.Dealer)
  3648. var total_count int64
  3649. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3650. total_count += count
  3651. if info.ID > 0 {
  3652. if info.Count >= total_count {
  3653. //回退库存
  3654. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3655. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3656. var flush_count int64
  3657. for _, it := range goodList {
  3658. flush_count += it.StockCount
  3659. }
  3660. cancelStockInfo := models.CancelStockInfo{
  3661. GoodId: item.ProjectId,
  3662. CancelStockId: cancel.ID,
  3663. GoodTypeId: good.GoodTypeId,
  3664. Count: prescribingNumber,
  3665. Price: info.Price,
  3666. Total: 0,
  3667. ProductDate: info.ProductDate,
  3668. ExpiryDate: info.ExpiryDate,
  3669. Ctime: time.Now().Unix(),
  3670. Status: 1,
  3671. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3672. OrderNumber: cancel.OrderNumber,
  3673. Type: 0,
  3674. Dealer: deaerler.DealerName,
  3675. Manufacturer: manufacturer.ManufacturerName,
  3676. Number: info.Number,
  3677. RegisterAccount: "",
  3678. Remark: "",
  3679. WarehouseInfoId: info.WarehouseInfotId,
  3680. PatientId: info.PatientId,
  3681. RecordDate: info.SysRecordTime,
  3682. StorehouseId: houseConfig.StorehouseOutInfo,
  3683. IsCheck: 1,
  3684. }
  3685. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3686. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3687. flow := models.VmStockFlow{
  3688. WarehousingId: info.WarehouseInfotId,
  3689. GoodId: item.ProjectId,
  3690. Number: info.Number,
  3691. LicenseNumber: info.LicenseNumber,
  3692. Count: prescribingNumber,
  3693. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3694. PatientId: item.PatientId,
  3695. SystemTime: info.SysRecordTime,
  3696. ConsumableType: 7,
  3697. IsSys: 0,
  3698. WarehousingOrder: "",
  3699. WarehouseOutId: info.WarehouseOutId,
  3700. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3701. IsEdit: 0,
  3702. CancelStockId: cancel.ID,
  3703. CancelOrderNumber: cancel.OrderNumber,
  3704. Manufacturer: manufacturer.ID,
  3705. Dealer: 0,
  3706. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3707. UpdateCreator: 0,
  3708. Status: 1,
  3709. Ctime: time.Now().Unix(),
  3710. Mtime: 0,
  3711. Price: info.Price,
  3712. WarehousingDetailId: info.WarehouseInfotId,
  3713. WarehouseOutDetailId: info.ID,
  3714. CancelOutDetailId: cancelInfo.ID,
  3715. ProductDate: info.ProductDate,
  3716. ExpireDate: info.ExpiryDate,
  3717. StorehouseId: houseConfig.StorehouseOutInfo,
  3718. OverCount: flush_count,
  3719. }
  3720. service.CreateStockFlowOne(flow)
  3721. //退库数量增加
  3722. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3723. //出库数量减少
  3724. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3725. }
  3726. if info.Count < total_count {
  3727. //回退库存
  3728. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3729. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3730. var flush_count int64
  3731. for _, it := range goodList {
  3732. flush_count += it.StockCount
  3733. }
  3734. cancelStockInfo := models.CancelStockInfo{
  3735. GoodId: item.ProjectId,
  3736. CancelStockId: cancel.ID,
  3737. GoodTypeId: good.GoodTypeId,
  3738. Count: info.Count,
  3739. Price: info.Price,
  3740. Total: 0,
  3741. ProductDate: info.ProductDate,
  3742. ExpiryDate: info.ExpiryDate,
  3743. Ctime: time.Now().Unix(),
  3744. Status: 1,
  3745. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3746. OrderNumber: cancel.OrderNumber,
  3747. Type: 0,
  3748. Dealer: deaerler.DealerName,
  3749. Manufacturer: manufacturer.ManufacturerName,
  3750. Number: info.Number,
  3751. RegisterAccount: "",
  3752. Remark: "",
  3753. WarehouseInfoId: info.WarehouseInfotId,
  3754. PatientId: info.PatientId,
  3755. RecordDate: info.SysRecordTime,
  3756. StorehouseId: houseConfig.StorehouseOutInfo,
  3757. IsCheck: 1,
  3758. }
  3759. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3760. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3761. flow := models.VmStockFlow{
  3762. WarehousingId: info.WarehouseInfotId,
  3763. GoodId: item.ProjectId,
  3764. Number: info.Number,
  3765. LicenseNumber: info.LicenseNumber,
  3766. Count: info.Count,
  3767. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3768. PatientId: item.PatientId,
  3769. SystemTime: info.SysRecordTime,
  3770. ConsumableType: 7,
  3771. IsSys: 0,
  3772. WarehousingOrder: "",
  3773. WarehouseOutId: info.WarehouseOutId,
  3774. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3775. IsEdit: 0,
  3776. CancelStockId: cancel.ID,
  3777. CancelOrderNumber: cancel.OrderNumber,
  3778. Manufacturer: manufacturer.ID,
  3779. Dealer: 0,
  3780. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3781. UpdateCreator: 0,
  3782. Status: 1,
  3783. Ctime: time.Now().Unix(),
  3784. Mtime: 0,
  3785. Price: info.Price,
  3786. WarehousingDetailId: info.WarehouseInfotId,
  3787. WarehouseOutDetailId: info.ID,
  3788. CancelOutDetailId: cancelInfo.ID,
  3789. ProductDate: info.ProductDate,
  3790. ExpireDate: info.ExpiryDate,
  3791. StorehouseId: houseConfig.StorehouseOutInfo,
  3792. OverCount: flush_count,
  3793. }
  3794. service.CreateStockFlowOne(flow)
  3795. //退库数量增加
  3796. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3797. //出库数量减少
  3798. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3799. }
  3800. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3801. var flush_count int64
  3802. for _, it := range goodList {
  3803. flush_count += it.StockCount
  3804. }
  3805. //查询已出库数量
  3806. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3807. if prescribingNumber < dialysisInfo.Count {
  3808. //改变数量
  3809. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3810. }
  3811. if prescribingNumber >= dialysisInfo.Count {
  3812. //删除出库表
  3813. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3814. }
  3815. //更新库存
  3816. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3817. //更新基础库库存
  3818. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3819. }
  3820. }
  3821. }
  3822. }
  3823. //保存耗材出库
  3824. if goodOutConfig.IsOpen == 1 {
  3825. if item.Type == 3 {
  3826. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3827. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3828. good.Total = good.Total + f_count
  3829. service.UpdateGoodInfo(&good)
  3830. operation_time := time.Now().Unix()
  3831. creater := c.GetAdminUserInfo().AdminUser.Id
  3832. //创建退库单
  3833. timeStr := time.Now().Format("2006-01-02")
  3834. timeArr := strings.Split(timeStr, "-")
  3835. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3836. total = total + 1
  3837. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3838. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3839. cancelStock := models.CancelStock{
  3840. OrderNumber: orderNumber,
  3841. OperaTime: operation_time,
  3842. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3843. Creater: creater,
  3844. Ctime: time.Now().Unix(),
  3845. Status: 1,
  3846. ReturnTime: item.RecordDate,
  3847. Type: 1,
  3848. StorehouseId: houseConfig.StorehouseOutInfo,
  3849. IsCheck: 1,
  3850. }
  3851. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3852. if msgerrkonde == gorm.ErrRecordNotFound {
  3853. service.AddSigleCancelStock(&cancelStock)
  3854. }
  3855. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3856. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3857. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3858. //查询该耗材是否出库
  3859. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3860. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3861. deaerler, _ := service.GetDealerById(info.Dealer)
  3862. var total_count int64
  3863. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3864. total_count += count
  3865. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3866. var flush_count int64
  3867. for _, it := range goodList {
  3868. flush_count += it.StockCount
  3869. }
  3870. fmt.Println("历史出库数据", info.Count)
  3871. fmt.Println("出库数量", total_count)
  3872. if info.ID > 0 {
  3873. cancelStockInfo := models.CancelStockInfo{
  3874. GoodId: item.ProjectId,
  3875. CancelStockId: cancel.ID,
  3876. GoodTypeId: good.GoodTypeId,
  3877. Count: prescribingNumber,
  3878. Price: info.Price,
  3879. Total: 0,
  3880. ProductDate: info.ProductDate,
  3881. ExpiryDate: info.ExpiryDate,
  3882. Ctime: time.Now().Unix(),
  3883. Status: 1,
  3884. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3885. OrderNumber: cancel.OrderNumber,
  3886. Type: 0,
  3887. Dealer: deaerler.DealerName,
  3888. Manufacturer: manufacturer.ManufacturerName,
  3889. Number: info.Number,
  3890. RegisterAccount: "",
  3891. Remark: "",
  3892. WarehouseInfoId: info.WarehouseInfotId,
  3893. PatientId: info.PatientId,
  3894. RecordDate: info.SysRecordTime,
  3895. StorehouseId: houseConfig.StorehouseOutInfo,
  3896. IsCheck: 1,
  3897. }
  3898. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3899. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3900. //查询出库数量
  3901. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3902. //出库数据 大于 退库数量
  3903. if len(list) > 0 {
  3904. for _, it := range list {
  3905. //回退库存
  3906. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3907. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3908. var flush_count_one int64
  3909. for _, it := range goodList {
  3910. flush_count_one += it.StockCount
  3911. }
  3912. //查询该批次是否有退库数据
  3913. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3914. creater := c.GetAdminUserInfo().AdminUser.Id
  3915. flow := models.VmStockFlow{
  3916. WarehousingId: it.WarehouseInfotId,
  3917. GoodId: it.GoodId,
  3918. Number: it.Number,
  3919. LicenseNumber: it.LicenseNumber,
  3920. Count: it.Count,
  3921. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3922. PatientId: it.PatientId,
  3923. SystemTime: it.SysRecordTime,
  3924. ConsumableType: 7,
  3925. IsSys: 0,
  3926. WarehousingOrder: "",
  3927. WarehouseOutId: it.WarehouseOutId,
  3928. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3929. IsEdit: 0,
  3930. CancelStockId: cancel.ID,
  3931. CancelOrderNumber: cancel.OrderNumber,
  3932. Manufacturer: manufacturer.ID,
  3933. Dealer: 0,
  3934. Creator: creater,
  3935. UpdateCreator: 0,
  3936. Status: 1,
  3937. Ctime: time.Now().Unix(),
  3938. Mtime: 0,
  3939. Price: it.Price,
  3940. WarehousingDetailId: it.WarehouseInfotId,
  3941. WarehouseOutDetailId: it.ID,
  3942. CancelOutDetailId: cancelInfo.ID,
  3943. ProductDate: it.ProductDate,
  3944. ExpireDate: it.ExpiryDate,
  3945. StorehouseId: houseConfig.StorehouseOutInfo,
  3946. OverCount: flush_count_one,
  3947. }
  3948. service.CreateStockFlowOne(flow)
  3949. //if flow.ID > 0 {
  3950. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3951. //}
  3952. }
  3953. }
  3954. //flow := models.VmStockFlow{
  3955. // WarehousingId: info.WarehouseInfotId,
  3956. // GoodId: item.ProjectId,
  3957. // Number: info.Number,
  3958. // LicenseNumber: info.LicenseNumber,
  3959. // Count: prescribingNumber,
  3960. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3961. // PatientId: item.PatientId,
  3962. // SystemTime: info.SysRecordTime,
  3963. // ConsumableType: 7,
  3964. // IsSys: 0,
  3965. // WarehousingOrder: "",
  3966. // WarehouseOutId: info.WarehouseOutId,
  3967. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3968. // IsEdit: 0,
  3969. // CancelStockId: cancel.ID,
  3970. // CancelOrderNumber: cancel.OrderNumber,
  3971. // Manufacturer: manufacturer.ID,
  3972. // Dealer: 0,
  3973. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3974. // UpdateCreator: 0,
  3975. // Status: 1,
  3976. // Ctime: time.Now().Unix(),
  3977. // Mtime: 0,
  3978. // Price: info.Price,
  3979. // WarehousingDetailId: info.WarehouseInfotId,
  3980. // WarehouseOutDetailId: info.ID,
  3981. // CancelOutDetailId: cancelInfo.ID,
  3982. // ProductDate: info.ProductDate,
  3983. // ExpireDate: info.ExpiryDate,
  3984. // StorehouseId: houseConfig.StorehouseOutInfo,
  3985. // OverCount: flush_count,
  3986. //}
  3987. //service.CreateStockFlowOne(flow)
  3988. //退库数量增加
  3989. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3990. //出库数量减少
  3991. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3992. //查询已出库数量
  3993. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3994. if prescribingNumber < dialysisInfo.Count {
  3995. //改变数量
  3996. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3997. }
  3998. if prescribingNumber >= dialysisInfo.Count {
  3999. //删除出库表
  4000. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4001. }
  4002. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4003. var flush_count_one int64
  4004. for _, it := range goodList {
  4005. flush_count_one += it.StockCount
  4006. }
  4007. //更新库存
  4008. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4009. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4010. //更新基础库库存
  4011. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4012. }
  4013. }
  4014. }
  4015. }
  4016. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4017. fmt.Println(err)
  4018. }
  4019. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4020. fmt.Println(err)
  4021. if len(advices) > 0 {
  4022. for _, item := range advices {
  4023. redis := service.RedisClient()
  4024. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4025. redis.Set(keyFive, "", time.Second)
  4026. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4027. redis.Set(keyOne, "", time.Second)
  4028. redis.Close()
  4029. }
  4030. }
  4031. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4032. if len(advices) > 0 {
  4033. for _, item := range advices {
  4034. creater := c.GetAdminUserInfo().AdminUser.Id
  4035. service.DrugAutoAddCancelInfo(item, creater)
  4036. }
  4037. }
  4038. } else {
  4039. if drugOutConfig.IsOpen == 1 {
  4040. if len(advices) > 0 {
  4041. for _, item := range advices {
  4042. creater := c.GetAdminUserInfo().AdminUser.Id
  4043. service.DrugAutoAddCancelInfo(item, creater)
  4044. }
  4045. }
  4046. } else {
  4047. if len(advices) > 0 {
  4048. for _, item := range advices {
  4049. creater := c.GetAdminUserInfo().AdminUser.Id
  4050. service.DrugAutoAddCancelInfo(item, creater)
  4051. }
  4052. }
  4053. }
  4054. }
  4055. c.ServeSuccessJSON(map[string]interface{}{
  4056. "msg": "删除成功",
  4057. })
  4058. return
  4059. }
  4060. func (c *HisApiController) DeleteDoctorAdvice() {
  4061. id, _ := c.GetInt64("id")
  4062. advice, _ := service.GetHisDoctorAdvicesById(id)
  4063. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4064. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4065. //已收费和已发药的限制逻辑
  4066. isCharge := false
  4067. isMedicine := false
  4068. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4069. //获取今天该患者所有处方,判断是否发药或者收费
  4070. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4071. for _, item := range new_prescriptions {
  4072. if item.IsMedicine == 1 {
  4073. isMedicine = true
  4074. }
  4075. }
  4076. for _, item := range new_prescriptions {
  4077. if item.OrderStatus == 4 {
  4078. isCharge = true
  4079. }
  4080. }
  4081. if isMedicine {
  4082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4083. return
  4084. }
  4085. if isCharge {
  4086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4087. return
  4088. }
  4089. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4090. for _, item := range advices {
  4091. if item.IsMedicine == 1 {
  4092. isMedicine = true
  4093. }
  4094. }
  4095. if isMedicine {
  4096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4097. return
  4098. }
  4099. if new_prescription.ID > 0 {
  4100. if new_prescription.OrderStatus == 2 {
  4101. isCharge = true
  4102. }
  4103. }
  4104. if isCharge {
  4105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4106. return
  4107. }
  4108. //已收费和已发药的限制逻辑
  4109. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4110. redis := service.RedisClient()
  4111. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4112. redis.Set(keyFive, "", time.Second)
  4113. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4114. redis.Set(keyOne, "", time.Second)
  4115. defer redis.Close()
  4116. if err == nil {
  4117. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4118. //查询是否在处方中出库
  4119. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4120. if openConfig.IsOpen != 1 {
  4121. //判断该医嘱是否执行了
  4122. if advice.ExecutionState == 1 {
  4123. creater := c.GetAdminUserInfo().AdminUser.Id
  4124. service.DrugAutoAddCancelInfo(&advice, creater)
  4125. }
  4126. }
  4127. //开启保存处方扣减功能
  4128. if openConfig.IsOpen == 1 {
  4129. creater := c.GetAdminUserInfo().AdminUser.Id
  4130. service.DrugAutoAddCancelInfo(&advice, creater)
  4131. }
  4132. } else {
  4133. if drugOutConfig.IsOpen == 1 {
  4134. //查询是否在处方中出库
  4135. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4136. if openConfig.IsOpen != 1 {
  4137. //判断该医嘱是否执行了
  4138. if advice.ExecutionState == 1 {
  4139. creater := c.GetAdminUserInfo().AdminUser.Id
  4140. service.DrugAutoAddCancelInfo(&advice, creater)
  4141. }
  4142. }
  4143. //开启保存处方扣减功能
  4144. if openConfig.IsOpen == 1 {
  4145. creater := c.GetAdminUserInfo().AdminUser.Id
  4146. service.DrugAutoAddCancelInfo(&advice, creater)
  4147. }
  4148. } else {
  4149. //判断该医嘱是否执行了
  4150. if advice.ExecutionState == 1 {
  4151. creater := c.GetAdminUserInfo().AdminUser.Id
  4152. service.DrugAutoAddCancelInfo(&advice, creater)
  4153. }
  4154. }
  4155. }
  4156. c.ServeSuccessJSON(map[string]interface{}{
  4157. "msg": "删除成功",
  4158. })
  4159. return
  4160. } else {
  4161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4162. return
  4163. }
  4164. }
  4165. func (c *HisApiController) DeleteProject() {
  4166. id, _ := c.GetInt64("id")
  4167. adminInfo := c.GetAdminUserInfo()
  4168. project, _ := service.GetHisProjectByID(id)
  4169. // var consumable models.DialysisBeforePrepare
  4170. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4171. //耗材保存处方出库
  4172. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4173. isCharge := false
  4174. isMedicine := false
  4175. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4176. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4177. for _, item := range new_prescriptions {
  4178. if item.IsMedicine == 1 {
  4179. isMedicine = true
  4180. }
  4181. }
  4182. for _, item := range new_prescriptions {
  4183. if item.OrderStatus == 4 {
  4184. isCharge = true
  4185. }
  4186. }
  4187. if isMedicine {
  4188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4189. return
  4190. }
  4191. if isCharge {
  4192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4193. return
  4194. }
  4195. if new_prescription.ID > 0 {
  4196. if new_prescription.OrderStatus == 2 {
  4197. isCharge = true
  4198. }
  4199. }
  4200. if isCharge {
  4201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4202. return
  4203. }
  4204. service.DeletePrintInfo(id)
  4205. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4206. label.Status = 0
  4207. service.CreateHisLabelRecord(&label)
  4208. fmt.Println(goodOutConfig.IsOpen)
  4209. if goodOutConfig.IsOpen != 1 {
  4210. if stockConfig.IsOpen == 1 {
  4211. if project.Type == 2 {
  4212. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4213. fmt.Println(err)
  4214. }
  4215. if project.Type == 3 && project.IsOut == 1 {
  4216. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4217. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4218. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4219. operation_time := time.Now().Unix()
  4220. creater := adminInfo.AdminUser.Id
  4221. //创建退库单
  4222. timeStr := time.Now().Format("2006-01-02")
  4223. timeArr := strings.Split(timeStr, "-")
  4224. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4225. total = total + 1
  4226. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4227. cancelStock := models.CancelStock{
  4228. OrderNumber: orderNumber,
  4229. OperaTime: operation_time,
  4230. OrgId: adminInfo.CurrentOrgId,
  4231. Creater: creater,
  4232. Ctime: time.Now().Unix(),
  4233. Status: 1,
  4234. ReturnTime: project.RecordDate,
  4235. Type: 1,
  4236. StorehouseId: houseConfig.StorehouseOutInfo,
  4237. IsCheck: 1,
  4238. }
  4239. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4240. if msgerrkonde == gorm.ErrRecordNotFound {
  4241. service.AddSigleCancelStock(&cancelStock)
  4242. }
  4243. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4244. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4245. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4246. //查询是否有出库
  4247. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4248. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4249. deaerler, _ := service.GetDealerById(info.Dealer)
  4250. if info.ID > 0 {
  4251. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4252. if info.Count >= prescribingNumber {
  4253. cancelStockInfo := models.CancelStockInfo{
  4254. GoodId: project.ProjectId,
  4255. CancelStockId: cancel.ID,
  4256. GoodTypeId: good.GoodTypeId,
  4257. Count: prescribingNumber,
  4258. Price: info.Price,
  4259. Total: 0,
  4260. ProductDate: info.ProductDate,
  4261. ExpiryDate: info.ExpiryDate,
  4262. Ctime: time.Now().Unix(),
  4263. Status: 1,
  4264. OrgId: adminInfo.CurrentOrgId,
  4265. OrderNumber: cancel.OrderNumber,
  4266. Type: 0,
  4267. Dealer: deaerler.DealerName,
  4268. Manufacturer: manufacturer.ManufacturerName,
  4269. Number: info.Number,
  4270. RegisterAccount: "",
  4271. Remark: "",
  4272. WarehouseInfoId: info.WarehouseInfotId,
  4273. PatientId: info.PatientId,
  4274. RecordDate: info.SysRecordTime,
  4275. StorehouseId: houseConfig.StorehouseOutInfo,
  4276. IsCheck: 1,
  4277. }
  4278. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4279. //回退库存
  4280. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4281. //退库数量增加
  4282. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4283. //出库数量减少
  4284. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4285. }
  4286. if info.Count < prescribingNumber {
  4287. cancelStockInfo := models.CancelStockInfo{
  4288. GoodId: project.ProjectId,
  4289. CancelStockId: cancel.ID,
  4290. GoodTypeId: good.GoodTypeId,
  4291. Count: info.Count,
  4292. Price: info.Price,
  4293. Total: 0,
  4294. ProductDate: info.ProductDate,
  4295. ExpiryDate: info.ExpiryDate,
  4296. Ctime: time.Now().Unix(),
  4297. Status: 1,
  4298. OrgId: adminInfo.CurrentOrgId,
  4299. OrderNumber: cancel.OrderNumber,
  4300. Type: 0,
  4301. Dealer: deaerler.DealerName,
  4302. Manufacturer: manufacturer.ManufacturerName,
  4303. Number: info.Number,
  4304. RegisterAccount: "",
  4305. Remark: "",
  4306. WarehouseInfoId: info.WarehouseInfotId,
  4307. PatientId: info.PatientId,
  4308. RecordDate: info.SysRecordTime,
  4309. StorehouseId: houseConfig.StorehouseOutInfo,
  4310. IsCheck: 1,
  4311. }
  4312. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4313. //回退库存
  4314. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4315. //退库数量增加
  4316. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4317. //出库数量减少
  4318. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4319. }
  4320. //查询剩余库存
  4321. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4322. var over_count int64
  4323. for _, it := range goodList {
  4324. over_count += it.StockCount
  4325. }
  4326. //出库数据 大于 退库数量
  4327. if info.Count >= prescribingNumber {
  4328. flow := models.VmStockFlow{
  4329. WarehousingId: info.WarehouseInfotId,
  4330. GoodId: project.ProjectId,
  4331. Number: info.Number,
  4332. LicenseNumber: info.LicenseNumber,
  4333. Count: prescribingNumber,
  4334. UserOrgId: adminInfo.CurrentOrgId,
  4335. PatientId: project.PatientId,
  4336. SystemTime: info.SysRecordTime,
  4337. ConsumableType: 7,
  4338. IsSys: 0,
  4339. WarehousingOrder: "",
  4340. WarehouseOutId: info.WarehouseOutId,
  4341. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4342. IsEdit: 0,
  4343. CancelStockId: cancel.ID,
  4344. CancelOrderNumber: cancel.OrderNumber,
  4345. Manufacturer: manufacturer.ID,
  4346. Dealer: 0,
  4347. Creator: adminInfo.AdminUser.Id,
  4348. UpdateCreator: 0,
  4349. Status: 1,
  4350. Ctime: time.Now().Unix(),
  4351. Mtime: 0,
  4352. Price: info.Price,
  4353. WarehousingDetailId: info.WarehouseInfotId,
  4354. WarehouseOutDetailId: info.ID,
  4355. CancelOutDetailId: cancelInfo.ID,
  4356. ProductDate: info.ProductDate,
  4357. ExpireDate: info.ExpiryDate,
  4358. StorehouseId: houseConfig.StorehouseOutInfo,
  4359. OverCount: over_count,
  4360. }
  4361. service.CreateStockFlowOne(flow)
  4362. }
  4363. //出库数据小于退库数据
  4364. if info.Count < prescribingNumber {
  4365. flow := models.VmStockFlow{
  4366. WarehousingId: info.WarehouseInfotId,
  4367. GoodId: project.ProjectId,
  4368. Number: info.Number,
  4369. LicenseNumber: info.LicenseNumber,
  4370. Count: info.Count,
  4371. UserOrgId: adminInfo.CurrentOrgId,
  4372. PatientId: project.PatientId,
  4373. SystemTime: info.SysRecordTime,
  4374. ConsumableType: 7,
  4375. IsSys: 0,
  4376. WarehousingOrder: "",
  4377. WarehouseOutId: info.WarehouseOutId,
  4378. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4379. IsEdit: 0,
  4380. CancelStockId: cancel.ID,
  4381. CancelOrderNumber: cancel.OrderNumber,
  4382. Manufacturer: manufacturer.ID,
  4383. Dealer: 0,
  4384. Creator: adminInfo.AdminUser.Id,
  4385. UpdateCreator: 0,
  4386. Status: 1,
  4387. Ctime: time.Now().Unix(),
  4388. Mtime: 0,
  4389. Price: info.Price,
  4390. WarehousingDetailId: info.WarehouseInfotId,
  4391. WarehouseOutDetailId: info.ID,
  4392. CancelOutDetailId: cancelInfo.ID,
  4393. ProductDate: info.ProductDate,
  4394. ExpireDate: info.ExpiryDate,
  4395. StorehouseId: houseConfig.StorehouseOutInfo,
  4396. OverCount: over_count,
  4397. }
  4398. service.CreateStockFlowOne(flow)
  4399. }
  4400. //查询已出库数量
  4401. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4402. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4403. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4404. if prescribingNumber < dialysisInfo.Count {
  4405. //改变数量
  4406. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4407. }
  4408. if prescribingNumber >= dialysisInfo.Count {
  4409. //删除出库表
  4410. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4411. }
  4412. //更新剩余库存
  4413. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4414. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4415. var total_count_one int64
  4416. for _, it := range stockList {
  4417. total_count_one += it.StockCount
  4418. }
  4419. //基础库插入数据
  4420. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4421. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4422. var flush_count int64
  4423. for _, it := range goodListOne {
  4424. flush_count += it.StockCount
  4425. }
  4426. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4427. if errs != nil {
  4428. goodErrcode := models.XtGoodErrcode{
  4429. UserOrgId: project.UserOrgId,
  4430. Errcode: "手动出库更新剩余出库失败",
  4431. GoodId: project.ProjectId,
  4432. Status: 1,
  4433. Ctime: time.Now().Unix(),
  4434. Mtime: 0,
  4435. Count: 0,
  4436. StockCount: 0,
  4437. Creater: creater,
  4438. BatchNumberId: 0,
  4439. WarehouseOutId: 0,
  4440. }
  4441. service.CreateGoodErrcode(goodErrcode)
  4442. }
  4443. }
  4444. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4445. fmt.Println(err)
  4446. } else {
  4447. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4448. fmt.Println(err)
  4449. }
  4450. } else {
  4451. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4452. fmt.Println(err)
  4453. }
  4454. }
  4455. //保存处方出库
  4456. if goodOutConfig.IsOpen == 1 {
  4457. if project.Type == 3 {
  4458. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4459. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4460. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4461. operation_time := time.Now().Unix()
  4462. creater := adminInfo.AdminUser.Id
  4463. //创建退库单
  4464. timeStr := time.Now().Format("2006-01-02")
  4465. timeArr := strings.Split(timeStr, "-")
  4466. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4467. total = total + 1
  4468. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4469. cancelStock := models.CancelStock{
  4470. OrderNumber: orderNumber,
  4471. OperaTime: operation_time,
  4472. OrgId: adminInfo.CurrentOrgId,
  4473. Creater: creater,
  4474. Ctime: time.Now().Unix(),
  4475. Status: 1,
  4476. ReturnTime: project.RecordDate,
  4477. Type: 1,
  4478. StorehouseId: houseConfig.StorehouseOutInfo,
  4479. IsCheck: 1,
  4480. }
  4481. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4482. if msgerrkonde == gorm.ErrRecordNotFound {
  4483. service.AddSigleCancelStock(&cancelStock)
  4484. }
  4485. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4486. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4487. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4488. //获取出库数据
  4489. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4490. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4491. deaerler, _ := service.GetDealerById(info.Dealer)
  4492. if info.ID > 0 {
  4493. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4494. if info.Count >= prescribingNumber {
  4495. cancelStockInfo := models.CancelStockInfo{
  4496. GoodId: project.ProjectId,
  4497. CancelStockId: cancel.ID,
  4498. GoodTypeId: good.GoodTypeId,
  4499. Count: prescribingNumber,
  4500. Price: info.Price,
  4501. Total: 0,
  4502. ProductDate: info.ProductDate,
  4503. ExpiryDate: info.ExpiryDate,
  4504. Ctime: time.Now().Unix(),
  4505. Status: 1,
  4506. OrgId: adminInfo.CurrentOrgId,
  4507. OrderNumber: cancel.OrderNumber,
  4508. Type: 0,
  4509. Dealer: deaerler.DealerName,
  4510. Manufacturer: manufacturer.ManufacturerName,
  4511. Number: info.Number,
  4512. RegisterAccount: "",
  4513. Remark: "",
  4514. WarehouseInfoId: info.WarehouseInfotId,
  4515. PatientId: info.PatientId,
  4516. RecordDate: info.SysRecordTime,
  4517. StorehouseId: houseConfig.StorehouseOutInfo,
  4518. IsCheck: 1,
  4519. }
  4520. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4521. //退库数量增加
  4522. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4523. //出库数量减少
  4524. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4525. }
  4526. if info.Count < prescribingNumber {
  4527. cancelStockInfo := models.CancelStockInfo{
  4528. GoodId: project.ProjectId,
  4529. CancelStockId: cancel.ID,
  4530. GoodTypeId: good.GoodTypeId,
  4531. Count: prescribingNumber,
  4532. Price: info.Price,
  4533. Total: 0,
  4534. ProductDate: info.ProductDate,
  4535. ExpiryDate: info.ExpiryDate,
  4536. Ctime: time.Now().Unix(),
  4537. Status: 1,
  4538. OrgId: adminInfo.CurrentOrgId,
  4539. OrderNumber: cancel.OrderNumber,
  4540. Type: 0,
  4541. Dealer: deaerler.DealerName,
  4542. Manufacturer: manufacturer.ManufacturerName,
  4543. Number: info.Number,
  4544. RegisterAccount: "",
  4545. Remark: "",
  4546. WarehouseInfoId: info.WarehouseInfotId,
  4547. PatientId: info.PatientId,
  4548. RecordDate: info.SysRecordTime,
  4549. StorehouseId: houseConfig.StorehouseOutInfo,
  4550. IsCheck: 1,
  4551. }
  4552. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4553. //回退库存
  4554. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4555. }
  4556. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4557. var over_count int64
  4558. for _, it := range goodList {
  4559. over_count += it.StockCount
  4560. }
  4561. //查询出库数量
  4562. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4563. //出库数据 大于 退库数量
  4564. if len(list) > 0 {
  4565. for _, it := range list {
  4566. //回退库存
  4567. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4568. //退库数量增加
  4569. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4570. //出库数量减少
  4571. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4572. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4573. var over_count_one int64
  4574. for _, it := range goodList {
  4575. over_count_one += it.StockCount
  4576. }
  4577. //查询该批次是否有退库数据
  4578. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4579. flow := models.VmStockFlow{
  4580. WarehousingId: it.WarehouseInfotId,
  4581. GoodId: it.GoodId,
  4582. Number: it.Number,
  4583. LicenseNumber: it.LicenseNumber,
  4584. Count: it.Count,
  4585. UserOrgId: adminInfo.CurrentOrgId,
  4586. PatientId: it.PatientId,
  4587. SystemTime: it.SysRecordTime,
  4588. ConsumableType: 7,
  4589. IsSys: 0,
  4590. WarehousingOrder: "",
  4591. WarehouseOutId: it.WarehouseOutId,
  4592. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4593. IsEdit: 0,
  4594. CancelStockId: cancel.ID,
  4595. CancelOrderNumber: cancel.OrderNumber,
  4596. Manufacturer: manufacturer.ID,
  4597. Dealer: 0,
  4598. Creator: adminInfo.AdminUser.Id,
  4599. UpdateCreator: 0,
  4600. Status: 1,
  4601. Ctime: time.Now().Unix(),
  4602. Mtime: 0,
  4603. Price: it.Price,
  4604. WarehousingDetailId: it.WarehouseInfotId,
  4605. WarehouseOutDetailId: it.ID,
  4606. CancelOutDetailId: cancelInfo.ID,
  4607. ProductDate: it.ProductDate,
  4608. ExpireDate: it.ExpiryDate,
  4609. StorehouseId: houseConfig.StorehouseOutInfo,
  4610. OverCount: over_count_one,
  4611. }
  4612. service.CreateStockFlowOne(flow)
  4613. }
  4614. }
  4615. //查询已出库数量
  4616. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4617. if prescribingNumber < dialysisInfo.Count {
  4618. //改变数量
  4619. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4620. }
  4621. if prescribingNumber >= dialysisInfo.Count {
  4622. //删除出库表
  4623. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4624. }
  4625. //更新剩余库存
  4626. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4627. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4628. var total_count_one int64
  4629. for _, it := range stockList {
  4630. total_count_one += it.StockCount
  4631. }
  4632. //基础库插入数据
  4633. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4634. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4635. var flush_count int64
  4636. for _, it := range goodListOne {
  4637. flush_count += it.StockCount
  4638. }
  4639. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4640. if errs != nil {
  4641. goodErrcode := models.XtGoodErrcode{
  4642. UserOrgId: project.UserOrgId,
  4643. Errcode: "手动出库更新剩余出库失败",
  4644. GoodId: project.ProjectId,
  4645. Status: 1,
  4646. Ctime: time.Now().Unix(),
  4647. Mtime: 0,
  4648. Count: 0,
  4649. StockCount: 0,
  4650. Creater: creater,
  4651. BatchNumberId: 0,
  4652. WarehouseOutId: 0,
  4653. }
  4654. service.CreateGoodErrcode(goodErrcode)
  4655. }
  4656. }
  4657. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4658. fmt.Println(err)
  4659. } else {
  4660. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4661. fmt.Println(err)
  4662. }
  4663. }
  4664. c.ServeSuccessJSON(map[string]interface{}{
  4665. "msg": "删除成功",
  4666. })
  4667. return
  4668. }
  4669. func (c *HisApiController) CreateHisAdditionalCharge() {
  4670. his_patient_id, _ := c.GetInt64("his_patient_id")
  4671. patient_id, _ := c.GetInt64("patient_id")
  4672. record_date := c.GetString("record_date")
  4673. timeLayout := "2006-01-02"
  4674. loc, _ := time.LoadLocation("Local")
  4675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4676. if err != nil {
  4677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4678. return
  4679. }
  4680. adminInfo := c.GetAdminUserInfo()
  4681. recordDateTime := theTime.Unix()
  4682. dataBody := make(map[string]interface{}, 0)
  4683. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4684. if err != nil {
  4685. utils.ErrorLog(err.Error())
  4686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4687. return
  4688. }
  4689. var additions []*models.HisAdditionalCharge
  4690. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4691. additions, _ := dataBody["addition"].([]interface{})
  4692. if len(additions) > 0 {
  4693. for _, item := range additions {
  4694. items := item.(map[string]interface{})
  4695. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4696. utils.ErrorLog("item_id")
  4697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4698. return
  4699. }
  4700. item_id := int64(items["item_id"].(float64))
  4701. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4702. utils.ErrorLog("item_name")
  4703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4704. return
  4705. }
  4706. item_name := items["item_name"].(string)
  4707. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4708. utils.ErrorLog("price")
  4709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4710. return
  4711. }
  4712. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4713. ctime := time.Now().Unix()
  4714. additional := &models.HisAdditionalCharge{
  4715. PatientId: patient_id,
  4716. HisPatientId: his_patient_id,
  4717. UserOrgId: adminInfo.CurrentOrgId,
  4718. RecordDate: recordDateTime,
  4719. CreatedTime: ctime,
  4720. UpdatedTime: ctime,
  4721. Modifier: adminInfo.AdminUser.Id,
  4722. Creator: adminInfo.AdminUser.Id,
  4723. Price: price,
  4724. ItemName: item_name,
  4725. ItemId: item_id,
  4726. Status: 1,
  4727. }
  4728. additions = append(additions, additional)
  4729. }
  4730. }
  4731. }
  4732. for _, item := range additions {
  4733. service.CreateAddtionalCharge(item)
  4734. }
  4735. c.ServeSuccessJSON(map[string]interface{}{
  4736. "msg": "创建成功",
  4737. })
  4738. }
  4739. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4740. blood_fat := c.GetString("blood_fat")
  4741. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4742. blood_sugar := c.GetString("blood_sugar")
  4743. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4744. chief_conplaint := c.GetString("chief_conplaint")
  4745. dbp := c.GetString("dbp")
  4746. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4747. delivery_way, _ := c.GetInt64("delivery_way")
  4748. diagnostic := c.GetString("diagnostic")
  4749. family_history := c.GetString("family_history")
  4750. height := c.GetString("height")
  4751. history_of_present_illness := c.GetString("history_of_present_illness")
  4752. is_infect, _ := c.GetInt64("is_infect")
  4753. past_history := c.GetString("past_history")
  4754. patient_id, _ := c.GetInt64("patient_id")
  4755. his_patient_id, _ := c.GetInt64("his_patient_id")
  4756. personal_history := c.GetString("personal_history")
  4757. pulse := c.GetString("pulse")
  4758. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4759. sbp := c.GetString("sbp")
  4760. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4761. heightfloat, _ := strconv.ParseFloat(height, 64)
  4762. sicktype := c.GetString("sick_type")
  4763. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4764. symptom := c.GetString("symptom")
  4765. sick_date := c.GetString("sick_date")
  4766. temperatures := c.GetString("temperature")
  4767. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4768. record_date := c.GetString("record_date")
  4769. breathing := c.GetString("breathing")
  4770. doctor_advice := c.GetString("doctor_advice")
  4771. remark := c.GetString("remark")
  4772. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4773. sick, _ := c.GetInt64("sick")
  4774. diagnose, _ := c.GetInt64("diagnose")
  4775. //id, _ := c.GetInt64("id")
  4776. timeLayout := "2006-01-02"
  4777. loc, _ := time.LoadLocation("Local")
  4778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4779. allergic_history := c.GetString("allergic_history")
  4780. if err != nil {
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4782. return
  4783. }
  4784. recordDateTime := theTime.Unix()
  4785. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4786. if err != nil {
  4787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4788. return
  4789. }
  4790. sickTimes := sickTime.Unix()
  4791. ctime := time.Now().Unix()
  4792. primary_disease := c.GetString("primary_disease")
  4793. confirm_failure_date := c.GetString("confirm_failure_date")
  4794. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4795. drug_allergy_history := c.GetString("drug_allergy_history")
  4796. physical_examination := c.GetString("physical_examination")
  4797. special_inspection := c.GetString("special_inspection")
  4798. lab_apparatus := c.GetString("lab_apparatus")
  4799. caseHistory := models.HisPatientCaseHistory{
  4800. HisPatientId: his_patient_id,
  4801. PatientId: patient_id,
  4802. Temperature: temperature,
  4803. BloodSugar: bloodsugarfloat,
  4804. Pulse: pulsefloat,
  4805. Sbp: sbpfloat,
  4806. Dbp: dbpfloat,
  4807. Height: heightfloat,
  4808. BloodFat: bloodfatfloat,
  4809. SickType: sick_type,
  4810. Symptom: symptom,
  4811. SickDate: sickTimes,
  4812. IsInfect: is_infect,
  4813. HistoryOfPresentIllness: history_of_present_illness,
  4814. PastHistory: past_history,
  4815. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4816. ChiefConplaint: chief_conplaint,
  4817. PersonalHistory: personal_history,
  4818. FamilyHistory: family_history,
  4819. Diagnostic: diagnostic,
  4820. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4821. Status: 1,
  4822. Ctime: ctime,
  4823. Mtime: ctime,
  4824. RecordDate: recordDateTime,
  4825. DeliveryWay: delivery_way,
  4826. Breathing: breathingfloat,
  4827. DoctorAdvice: doctor_advice,
  4828. Remark: remark,
  4829. Sick: sick,
  4830. Diagnose: diagnose,
  4831. AllergicHistory: allergic_history,
  4832. PrimaryDisease: primary_disease,
  4833. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4834. DrugAllergyHistory: drug_allergy_history,
  4835. PhysicalExamination: physical_examination,
  4836. SpecialInspection: special_inspection,
  4837. LabApparatus: lab_apparatus,
  4838. }
  4839. //查询该患者是否有病历
  4840. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4841. if errcodes == gorm.ErrRecordNotFound {
  4842. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4843. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4844. if err != nil {
  4845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4846. return
  4847. }
  4848. c.ServeSuccessJSON(map[string]interface{}{
  4849. "caseHistory": caseHistory,
  4850. "historyInfo": historyInfo,
  4851. })
  4852. return
  4853. } else if errcodes == nil {
  4854. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4855. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4856. if err != nil {
  4857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4858. return
  4859. }
  4860. c.ServeSuccessJSON(map[string]interface{}{
  4861. "caseHistory": caseHistory,
  4862. "historyInfo": historyInfo,
  4863. })
  4864. }
  4865. //查询该患者是否有病历
  4866. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4867. //if errcode == gorm.ErrRecordNotFound {
  4868. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4869. // if err != nil {
  4870. // c.ServeSuccessJSON(map[string]interface{}{
  4871. // "msg": "保存成功",
  4872. // })
  4873. // }
  4874. //} else if errcode == nil {
  4875. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4876. // return
  4877. //}
  4878. }
  4879. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4880. patient_id, _ := c.GetInt64("patient_id", 0)
  4881. adminUser := c.GetAdminUserInfo()
  4882. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4883. c.ServeSuccessJSON(map[string]interface{}{
  4884. "list": caseHistorys,
  4885. })
  4886. }
  4887. func (c *HisApiController) GetHisPatientCaseHistory() {
  4888. record_date, _ := c.GetInt64("record_date", 0)
  4889. patient_id, _ := c.GetInt64("patient_id", 0)
  4890. admin := c.GetAdminUserInfo()
  4891. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4892. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4893. c.ServeSuccessJSON(map[string]interface{}{
  4894. "info": info,
  4895. "case_history": case_history,
  4896. })
  4897. }
  4898. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4899. template_name := c.GetString("template_name")
  4900. template_remark := c.GetString("template_remark")
  4901. doctor := c.GetAdminUserInfo().AdminUser.Id
  4902. diagnostic := c.GetString("diagnostic")
  4903. chief_conplaint := c.GetString("chief_conplain")
  4904. history_of_present_illness := c.GetString("history_of_present_illness")
  4905. past_history := c.GetString("past_history")
  4906. personal_history := c.GetString("personal_history")
  4907. family_history := c.GetString("family_history")
  4908. user_name := c.GetString("user_name")
  4909. doctor_advice := c.GetString("doctor_advice")
  4910. remark := c.GetString("remark")
  4911. //record_date := c.GetString("record_date")
  4912. //fmt.Println("record_date--------",record_date)
  4913. //timeLayout := "2006-01-02"
  4914. //loc, _ := time.LoadLocation("Local")
  4915. //
  4916. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4917. //if err != nil {
  4918. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4919. // return
  4920. //}
  4921. //recordDateTime := theTime.Unix()
  4922. ctime := time.Now().Unix()
  4923. template := models.HisCaseHistoryTemplate{
  4924. HistoryOfPresentIllness: history_of_present_illness,
  4925. PastHistory: past_history,
  4926. ChiefConplaint: chief_conplaint,
  4927. PersonalHistory: personal_history,
  4928. FamilyHistory: family_history,
  4929. Diagnostic: diagnostic,
  4930. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4931. Status: 1,
  4932. Ctime: ctime,
  4933. Mtime: ctime,
  4934. RecordDate: time.Now().Unix(),
  4935. TemplateName: template_name,
  4936. TemplateRemark: template_remark,
  4937. Creator: doctor,
  4938. Modifier: doctor,
  4939. UserName: user_name,
  4940. DoctorAdvice: doctor_advice,
  4941. Remark: remark,
  4942. }
  4943. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4944. if err == nil {
  4945. c.ServeSuccessJSON(map[string]interface{}{
  4946. "msg": "保存成功",
  4947. })
  4948. } else {
  4949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4950. return
  4951. }
  4952. }
  4953. func (c *HisApiController) GetCaseHistoryTemplate() {
  4954. timeLayout := "2006-01-02"
  4955. loc, _ := time.LoadLocation("Local")
  4956. keyword := c.GetString("keyword")
  4957. start_time := c.GetString("start_time")
  4958. end_time := c.GetString("end_time")
  4959. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4960. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4961. admin := c.GetAdminUserInfo()
  4962. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4963. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4964. c.ServeSuccessJSON(map[string]interface{}{
  4965. "template": template,
  4966. //"history": history,
  4967. })
  4968. }
  4969. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4970. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4971. utils.ErrorLog("drug_name")
  4972. return enums.ErrorCodeParamWrong
  4973. }
  4974. adviceName, _ := json["drug_name"].(string)
  4975. if len(adviceName) == 0 {
  4976. utils.ErrorLog("len(advice_name) == 0")
  4977. return enums.ErrorCodeParamWrong
  4978. }
  4979. advice.AdviceName = adviceName
  4980. adviceDesc, _ := json["advice_desc"].(string)
  4981. advice.AdviceDesc = adviceDesc
  4982. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4983. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4984. advice.DrugSpec = drugSpec
  4985. }
  4986. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4987. remark, _ := json["remark"].(string)
  4988. advice.Remark = remark
  4989. }
  4990. if json["id"] == nil {
  4991. advice.DrugId = 0
  4992. } else {
  4993. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4994. drug_id := int64(json["id"].(float64))
  4995. advice.DrugId = drug_id
  4996. }
  4997. }
  4998. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4999. advice_id := int64(json["advice_id"].(float64))
  5000. advice.ID = advice_id
  5001. if advice.ID > 0 {
  5002. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5003. if err == nil {
  5004. if hisAdvice.ID > 0 {
  5005. advice.ExecutionTime = hisAdvice.ExecutionTime
  5006. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5007. advice.ExecutionState = hisAdvice.ExecutionState
  5008. advice.CheckTime = hisAdvice.CheckTime
  5009. advice.Checker = hisAdvice.Checker
  5010. advice.CheckState = hisAdvice.CheckState
  5011. advice.StartTime = hisAdvice.StartTime
  5012. advice.FeedetlSn = hisAdvice.FeedetlSn
  5013. }
  5014. }
  5015. }
  5016. }
  5017. //
  5018. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5019. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5020. // advice.ExecutionTime = execution_time
  5021. //}
  5022. //
  5023. //
  5024. //
  5025. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5026. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5027. // advice.ExecutionStaff = execution_staff
  5028. //}
  5029. //
  5030. //
  5031. //
  5032. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5033. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5034. // advice.ExecutionState = execution_state
  5035. //}
  5036. //
  5037. //
  5038. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5039. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5040. // advice.CheckTime = check_time
  5041. //}
  5042. //
  5043. //
  5044. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5045. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5046. // advice.CheckState = check_state
  5047. //}
  5048. //
  5049. //
  5050. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5051. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5052. // advice.Checker = checker
  5053. //}
  5054. //
  5055. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5056. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5057. // advice.StartTime = start_time
  5058. //}
  5059. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5060. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5061. advice.IsSelfDrug = is_self_drug
  5062. }
  5063. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5064. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5065. drug_way_count, _ := json["drug_way_count"].(string)
  5066. advice.DrugWayCount = drug_way_count
  5067. }
  5068. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5069. drugSpecUnit, _ := json["min_unit"].(string)
  5070. advice.DrugSpecUnit = drugSpecUnit
  5071. }
  5072. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5073. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5074. advice.SingleDose = singleDose
  5075. }
  5076. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5077. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5078. advice.SingleDoseUnit = singleDoseUnit
  5079. }
  5080. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5081. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5082. advice.PrescribingNumber = prescribingNumber
  5083. }
  5084. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5085. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5086. advice.PrescribingNumberUnit = prescribingNumberUnit
  5087. }
  5088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5089. deliveryWay, _ := json["delivery_way"].(string)
  5090. advice.DeliveryWay = deliveryWay
  5091. }
  5092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5093. executionFrequency, _ := json["execution_frequency"].(string)
  5094. advice.ExecutionFrequency = executionFrequency
  5095. }
  5096. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5097. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5098. advice.Price = price
  5099. }
  5100. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5101. med_list_codg, _ := json["medical_insurance_number"].(string)
  5102. advice.MedListCodg = med_list_codg
  5103. }
  5104. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5105. day := int64(json["day"].(float64))
  5106. advice.Day = day
  5107. }
  5108. return 0
  5109. }
  5110. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5111. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5112. id := int64(json["id"].(float64))
  5113. project.ID = id
  5114. historyProject, _ := service.GetHisProjectByID(id)
  5115. project.FeedetlSn = historyProject.FeedetlSn
  5116. }
  5117. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5118. project_id := int64(json["project_id"].(float64))
  5119. project.ProjectId = project_id
  5120. }
  5121. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5122. // price := int64(json["price"].(float64))
  5123. // formatInt_price := strconv.FormatInt(price, 10)
  5124. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5125. // project.Price = float_price
  5126. // }
  5127. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5128. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5129. project.Price = price
  5130. }
  5131. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5132. total, _ := json["total"].(string)
  5133. project.Count = total
  5134. }
  5135. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5136. medical_code, _ := json["medical_code"].(string)
  5137. project.MedListCodg = medical_code
  5138. }
  5139. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5140. single_dose, _ := json["single_dose"].(string)
  5141. project.SingleDose = single_dose
  5142. }
  5143. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5144. delivery_way, _ := json["delivery_way"].(string)
  5145. project.DeliveryWay = delivery_way
  5146. }
  5147. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5148. execution_frequency, _ := json["execution_frequency"].(string)
  5149. project.ExecutionFrequency = execution_frequency
  5150. }
  5151. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5152. remark, _ := json["remark"].(string)
  5153. project.Remark = remark
  5154. }
  5155. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5156. day, _ := json["number_days"].(string)
  5157. project.Day = day
  5158. }
  5159. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5160. unit, _ := json["unit"].(string)
  5161. project.Unit = unit
  5162. }
  5163. return 0
  5164. }
  5165. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5166. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5167. id := int64(json["id"].(float64))
  5168. historyAddtions, _ := service.GetHisAdditionByID(id)
  5169. additionalCharge.ID = id
  5170. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5171. }
  5172. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5173. item_id := int64(json["item_id"].(float64))
  5174. additionalCharge.ItemId = item_id
  5175. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5176. if config.ID > 0 {
  5177. if len(config.Code) > 0 {
  5178. additionalCharge.MedListCodg = config.Code
  5179. }
  5180. }
  5181. }
  5182. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5183. // price := int64(json["price"].(float64))
  5184. // formatInt_price := strconv.FormatInt(price, 10)
  5185. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5186. // additionalCharge.Price = float_price
  5187. // }
  5188. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5189. // price := int64(json["price"].(float64))
  5190. // formatInt_price := strconv.FormatInt(price, 10)
  5191. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5192. // additionalCharge.Price = float_price
  5193. //}
  5194. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5195. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5196. additionalCharge.Price = price
  5197. }
  5198. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5199. count, _ := json["count"].(string)
  5200. counts, _ := strconv.ParseInt(count, 10, 64)
  5201. additionalCharge.Count = counts
  5202. }
  5203. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5204. item_name, _ := json["item_name"].(string)
  5205. additionalCharge.ItemName = item_name
  5206. }
  5207. return 0
  5208. }
  5209. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5210. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5211. utils.ErrorLog("drug_name")
  5212. return enums.ErrorCodeParamWrong
  5213. }
  5214. adviceName, _ := json["drug_name"].(string)
  5215. if len(adviceName) == 0 {
  5216. utils.ErrorLog("len(advice_name) == 0")
  5217. return enums.ErrorCodeParamWrong
  5218. }
  5219. advice.AdviceName = adviceName
  5220. adviceDesc, _ := json["advice_desc"].(string)
  5221. advice.AdviceDesc = adviceDesc
  5222. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5223. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5224. advice.DrugSpec = drugSpec
  5225. }
  5226. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5227. remark, _ := json["remark"].(string)
  5228. advice.Remark = remark
  5229. }
  5230. if json["id"] == nil {
  5231. advice.DrugId = 0
  5232. } else {
  5233. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5234. drug_id := int64(json["id"].(float64))
  5235. advice.DrugId = drug_id
  5236. }
  5237. }
  5238. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5239. groupno := int64(json["groupno"].(float64))
  5240. advice.Groupno = groupno
  5241. }
  5242. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5243. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5244. advice.IsSelfDrug = is_self_drug
  5245. }
  5246. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5247. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5248. drug_way_count, _ := json["drug_way_count"].(string)
  5249. advice.DrugWayCount = drug_way_count
  5250. }
  5251. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5252. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5253. advice.HospApprFlag = hosp_appr_flag
  5254. }
  5255. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5256. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5257. advice.PrescribingNumber = prescribingNumber
  5258. }
  5259. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5260. // frequency_type := int64(json["frequency_type"].(float64))
  5261. // advice.FrequencyType = frequency_type
  5262. //}
  5263. //
  5264. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5265. // day_count := int64(json["day_count"].(float64))
  5266. // advice.DayCount = day_count
  5267. //}
  5268. //
  5269. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5270. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5271. // week_day, _ := json["week_day"].(string)
  5272. // advice.WeekDay = week_day
  5273. //}
  5274. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5275. drugSpecUnit, _ := json["min_unit"].(string)
  5276. advice.DrugSpecUnit = drugSpecUnit
  5277. }
  5278. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5279. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5280. advice.SingleDose = singleDose
  5281. }
  5282. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5283. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5284. advice.SingleDoseUnit = singleDoseUnit
  5285. }
  5286. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5287. deliveryWay, _ := json["delivery_way"].(string)
  5288. advice.DeliveryWay = deliveryWay
  5289. }
  5290. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5291. executionFrequency, _ := json["execution_frequency"].(string)
  5292. advice.ExecutionFrequency = executionFrequency
  5293. }
  5294. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5295. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5296. advice.Price = price
  5297. }
  5298. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5299. med_list_codg, _ := json["medical_insurance_number"].(string)
  5300. advice.MedListCodg = med_list_codg
  5301. }
  5302. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5303. day := int64(json["day"].(float64))
  5304. advice.Day = day
  5305. }
  5306. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5307. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5308. advice.PrescribingNumberUnit = prescribingNumberUnit
  5309. }
  5310. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5311. advice_id := int64(json["advice_id"].(float64))
  5312. advice.ID = advice_id
  5313. if advice.ID > 0 {
  5314. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5315. if err == nil {
  5316. if hisAdvice.ID > 0 {
  5317. advice.ExecutionTime = hisAdvice.ExecutionTime
  5318. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5319. advice.ExecutionState = hisAdvice.ExecutionState
  5320. advice.CheckTime = hisAdvice.CheckTime
  5321. advice.Checker = hisAdvice.Checker
  5322. advice.CheckState = hisAdvice.CheckState
  5323. advice.StartTime = hisAdvice.StartTime
  5324. advice.HospApprFlag = hisAdvice.HospApprFlag
  5325. advice.IsMedicine = hisAdvice.IsMedicine
  5326. if hisAdvice.UserOrgId == 10028 {
  5327. 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 {
  5328. advice.ExecutionTime = 0
  5329. advice.ExecutionStaff = 0
  5330. advice.ExecutionState = 2
  5331. advice.CheckTime = 0
  5332. advice.Checker = 0
  5333. advice.CheckState = 2
  5334. }
  5335. } else {
  5336. 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 {
  5337. advice.ExecutionTime = 0
  5338. advice.ExecutionStaff = 0
  5339. advice.ExecutionState = 2
  5340. advice.CheckTime = 0
  5341. advice.Checker = 0
  5342. advice.CheckState = 2
  5343. }
  5344. }
  5345. //advice.Groupno = hisAdvice.Groupno
  5346. }
  5347. }
  5348. }
  5349. }
  5350. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5351. //
  5352. //if drugStockConfig.IsOpen == 1 {
  5353. //
  5354. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5355. // if advice.ID == 0 { //医嘱不存在
  5356. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5357. // drug.Total = drug.Total - advice.PrescribingNumber
  5358. // service.UpdateBaseDrugLib(&drug)
  5359. //
  5360. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5361. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5362. // drug.Total = drug.Total - num
  5363. // service.UpdateBaseDrugLib(&drug)
  5364. // }
  5365. //
  5366. // } else if advice.ID > 0 { //医嘱存在
  5367. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5368. // var num float64
  5369. //
  5370. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5371. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5372. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5373. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5374. // drug.Total = drug.Total + num
  5375. // service.UpdateBaseDrugLib(&drug)
  5376. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5377. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5378. // drug.Total = drug.Total - num
  5379. // service.UpdateBaseDrugLib(&drug)
  5380. // }
  5381. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5382. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5383. // if num2 > advice.PrescribingNumber {
  5384. // num = num2 - advice.PrescribingNumber
  5385. // drug.Total = drug.Total + num
  5386. // service.UpdateBaseDrugLib(&drug)
  5387. // } else if num2 < advice.PrescribingNumber {
  5388. // num = advice.PrescribingNumber - num2
  5389. // drug.Total = drug.Total - num
  5390. // service.UpdateBaseDrugLib(&drug)
  5391. // }
  5392. //
  5393. // }
  5394. //
  5395. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5396. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5397. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5398. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5399. // if num1 > num2 {
  5400. // num = num1 - num2
  5401. // drug.Total = drug.Total + num
  5402. // service.UpdateBaseDrugLib(&drug)
  5403. // } else if num1 < num2 {
  5404. // num = num2 - num1
  5405. // drug.Total = drug.Total - num
  5406. // service.UpdateBaseDrugLib(&drug)
  5407. // }
  5408. //
  5409. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5410. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5411. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5412. // if hisAdvice.PrescribingNumber > num2 {
  5413. // num = hisAdvice.PrescribingNumber - num2
  5414. // drug.Total = drug.Total + num
  5415. // service.UpdateBaseDrugLib(&drug)
  5416. // } else if num2 < advice.PrescribingNumber {
  5417. // num = num2 - hisAdvice.PrescribingNumber
  5418. // drug.Total = drug.Total - num
  5419. // service.UpdateBaseDrugLib(&drug)
  5420. // }
  5421. //
  5422. // }
  5423. // }
  5424. // }
  5425. //}
  5426. //
  5427. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5428. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5429. // advice.ExecutionTime = execution_time
  5430. //}
  5431. //
  5432. //
  5433. //
  5434. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5435. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5436. // advice.ExecutionStaff = execution_staff
  5437. //}
  5438. //
  5439. //
  5440. //
  5441. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5442. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5443. // advice.ExecutionState = execution_state
  5444. //}
  5445. //
  5446. //
  5447. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5448. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5449. // advice.CheckTime = check_time
  5450. //}
  5451. //
  5452. //
  5453. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5454. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5455. // advice.CheckState = check_state
  5456. //}
  5457. //
  5458. //
  5459. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5460. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5461. // advice.Checker = checker
  5462. //}
  5463. //
  5464. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5465. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5466. // advice.StartTime = start_time
  5467. //}
  5468. return 0
  5469. }
  5470. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5471. project.ExecutionStaff = 0
  5472. project.ExecutionState = 2
  5473. project.ExecutionTime = 0
  5474. project.Checker = 0
  5475. project.CheckState = 2
  5476. project.CheckTime = 0
  5477. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5478. id := int64(json["id"].(float64))
  5479. project.ID = id
  5480. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5481. project.ExecutionStaff = temp_project.ExecutionStaff
  5482. project.ExecutionState = temp_project.ExecutionState
  5483. project.ExecutionTime = temp_project.ExecutionTime
  5484. project.Checker = temp_project.Checker
  5485. project.CheckState = temp_project.CheckState
  5486. project.CheckTime = temp_project.CheckTime
  5487. project.TeamId = temp_project.TeamId
  5488. }
  5489. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5490. types := int64(json["type"].(float64))
  5491. project.Type = types
  5492. }
  5493. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5494. project_id := int64(json["project_id"].(float64))
  5495. project.ProjectId = project_id
  5496. }
  5497. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5498. team_id := int64(json["team_id"].(float64))
  5499. project.TeamId = team_id
  5500. }
  5501. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5502. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5503. project.Price = price
  5504. }
  5505. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5506. total, _ := json["total"].(string)
  5507. //totals, _ := strconv.ParseInt(total, 10, 64)
  5508. project.Count = total
  5509. }
  5510. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5511. medical_code, _ := json["medical_code"].(string)
  5512. project.MedListCodg = medical_code
  5513. }
  5514. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5515. single_dose, _ := json["single_dose"].(string)
  5516. project.SingleDose = single_dose
  5517. }
  5518. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5519. delivery_way, _ := json["delivery_way"].(string)
  5520. project.DeliveryWay = delivery_way
  5521. }
  5522. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5523. execution_frequency, _ := json["execution_frequency"].(string)
  5524. project.ExecutionFrequency = execution_frequency
  5525. }
  5526. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5527. remark, _ := json["remark"].(string)
  5528. project.Remark = remark
  5529. }
  5530. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5531. day, _ := json["number_days"].(string)
  5532. project.Day = day
  5533. }
  5534. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5535. unit, _ := json["unit"].(string)
  5536. project.Unit = unit
  5537. }
  5538. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5539. // frequency_type := int64(json["frequency_type"].(float64))
  5540. // project.FrequencyType = frequency_type
  5541. //}
  5542. //
  5543. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5544. // day_count := int64(json["day_count"].(float64))
  5545. // project.DayCount = day_count
  5546. //}
  5547. //
  5548. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5549. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5550. // week_day, _ := json["week_day"].(string)
  5551. // project.WeekDay = week_day
  5552. //}
  5553. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5554. //
  5555. //if project.ID == 0 {
  5556. // if stockConfig.IsOpen == 1 {
  5557. // if project.Type == 3 {
  5558. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5559. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5560. // good.Total = good.Total - f_count
  5561. // service.UpdateGoodInfo(&good)
  5562. // }
  5563. // }
  5564. //
  5565. //} else {
  5566. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5567. //
  5568. // if stockConfig.IsOpen == 1 {
  5569. // if project.Type == 3 {
  5570. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5571. // if project.Count < temp_project.Count {
  5572. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5573. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5574. //
  5575. // other_count := f_count_two - f_count_one
  5576. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5577. // good.Total = good.Total + other_count_two
  5578. // service.UpdateGoodInfo(&good)
  5579. // } else if project.Count > temp_project.Count {
  5580. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5581. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5582. //
  5583. // other_count := f_count_one - f_count_two
  5584. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5585. // good.Total = good.Total - other_count_two
  5586. // service.UpdateGoodInfo(&good)
  5587. // }
  5588. //
  5589. // }
  5590. // }
  5591. //
  5592. //}
  5593. return 0
  5594. }
  5595. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5596. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5597. utils.ErrorLog("drug_name")
  5598. return enums.ErrorCodeParamWrong
  5599. }
  5600. adviceName, _ := json["drug_name"].(string)
  5601. if len(adviceName) == 0 {
  5602. utils.ErrorLog("len(advice_name) == 0")
  5603. return enums.ErrorCodeParamWrong
  5604. }
  5605. advice.AdviceName = adviceName
  5606. adviceDesc, _ := json["advice_desc"].(string)
  5607. advice.AdviceDesc = adviceDesc
  5608. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5609. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5610. advice.DrugSpec = drugSpec
  5611. }
  5612. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5613. remark, _ := json["remark"].(string)
  5614. advice.Remark = remark
  5615. }
  5616. if json["id"] == nil {
  5617. advice.DrugId = 0
  5618. } else {
  5619. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5620. drug_id := int64(json["id"].(float64))
  5621. advice.DrugId = drug_id
  5622. }
  5623. }
  5624. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5625. groupno := int64(json["groupno"].(float64))
  5626. advice.Groupno = groupno
  5627. }
  5628. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5629. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5630. advice.IsSelfDrug = is_self_drug
  5631. }
  5632. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5633. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5634. drug_way_count, _ := json["drug_way_count"].(string)
  5635. advice.DrugWayCount = drug_way_count
  5636. }
  5637. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5638. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5639. advice.HospApprFlag = hosp_appr_flag
  5640. }
  5641. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5642. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5643. advice.PrescribingNumber = prescribingNumber
  5644. }
  5645. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5646. // frequency_type := int64(json["frequency_type"].(float64))
  5647. // advice.FrequencyType = frequency_type
  5648. //}
  5649. //
  5650. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5651. // day_count := int64(json["day_count"].(float64))
  5652. // advice.DayCount = day_count
  5653. //}
  5654. //
  5655. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5656. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5657. // week_day, _ := json["week_day"].(string)
  5658. // advice.WeekDay = week_day
  5659. //}
  5660. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5661. drugSpecUnit, _ := json["min_unit"].(string)
  5662. advice.DrugSpecUnit = drugSpecUnit
  5663. }
  5664. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5665. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5666. advice.SingleDose = singleDose
  5667. }
  5668. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5669. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5670. advice.SingleDoseUnit = singleDoseUnit
  5671. }
  5672. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5673. deliveryWay, _ := json["delivery_way"].(string)
  5674. advice.DeliveryWay = deliveryWay
  5675. }
  5676. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5677. executionFrequency, _ := json["execution_frequency"].(string)
  5678. advice.ExecutionFrequency = executionFrequency
  5679. }
  5680. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5681. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5682. advice.Price = price
  5683. }
  5684. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5685. med_list_codg, _ := json["medical_insurance_number"].(string)
  5686. advice.MedListCodg = med_list_codg
  5687. }
  5688. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5689. day := int64(json["day"].(float64))
  5690. advice.Day = day
  5691. }
  5692. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5693. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5694. advice.PrescribingNumberUnit = prescribingNumberUnit
  5695. }
  5696. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5697. advice_id := int64(json["advice_id"].(float64))
  5698. advice.ID = advice_id
  5699. if advice.ID > 0 {
  5700. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5701. if err == nil {
  5702. if hisAdvice.ID > 0 {
  5703. advice.ExecutionTime = hisAdvice.ExecutionTime
  5704. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5705. advice.ExecutionState = hisAdvice.ExecutionState
  5706. advice.CheckTime = hisAdvice.CheckTime
  5707. advice.Checker = hisAdvice.Checker
  5708. advice.CheckState = hisAdvice.CheckState
  5709. advice.StartTime = hisAdvice.StartTime
  5710. advice.HospApprFlag = hisAdvice.HospApprFlag
  5711. advice.IsMedicine = hisAdvice.IsMedicine
  5712. if hisAdvice.UserOrgId == 10028 {
  5713. 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 {
  5714. advice.ExecutionTime = 0
  5715. advice.ExecutionStaff = 0
  5716. advice.ExecutionState = 2
  5717. advice.CheckTime = 0
  5718. advice.Checker = 0
  5719. advice.CheckState = 2
  5720. }
  5721. } else {
  5722. 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 {
  5723. advice.ExecutionTime = 0
  5724. advice.ExecutionStaff = 0
  5725. advice.ExecutionState = 2
  5726. advice.CheckTime = 0
  5727. advice.Checker = 0
  5728. advice.CheckState = 2
  5729. }
  5730. }
  5731. //advice.Groupno = hisAdvice.Groupno
  5732. }
  5733. }
  5734. }
  5735. }
  5736. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5737. //
  5738. //if drugStockConfig.IsOpen == 1 {
  5739. //
  5740. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5741. // if advice.ID == 0 { //医嘱不存在
  5742. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5743. // drug.Total = drug.Total - advice.PrescribingNumber
  5744. // service.UpdateBaseDrugLib(&drug)
  5745. //
  5746. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5747. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5748. // drug.Total = drug.Total - num
  5749. // service.UpdateBaseDrugLib(&drug)
  5750. // }
  5751. //
  5752. // } else if advice.ID > 0 { //医嘱存在
  5753. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5754. // var num float64
  5755. //
  5756. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5757. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5758. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5759. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5760. // drug.Total = drug.Total + num
  5761. // service.UpdateBaseDrugLib(&drug)
  5762. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5763. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5764. // drug.Total = drug.Total - num
  5765. // service.UpdateBaseDrugLib(&drug)
  5766. // }
  5767. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5768. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5769. // if num2 > advice.PrescribingNumber {
  5770. // num = num2 - advice.PrescribingNumber
  5771. // drug.Total = drug.Total + num
  5772. // service.UpdateBaseDrugLib(&drug)
  5773. // } else if num2 < advice.PrescribingNumber {
  5774. // num = advice.PrescribingNumber - num2
  5775. // drug.Total = drug.Total - num
  5776. // service.UpdateBaseDrugLib(&drug)
  5777. // }
  5778. //
  5779. // }
  5780. //
  5781. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5782. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5783. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5784. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5785. // if num1 > num2 {
  5786. // num = num1 - num2
  5787. // drug.Total = drug.Total + num
  5788. // service.UpdateBaseDrugLib(&drug)
  5789. // } else if num1 < num2 {
  5790. // num = num2 - num1
  5791. // drug.Total = drug.Total - num
  5792. // service.UpdateBaseDrugLib(&drug)
  5793. // }
  5794. //
  5795. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5796. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5797. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5798. // if hisAdvice.PrescribingNumber > num2 {
  5799. // num = hisAdvice.PrescribingNumber - num2
  5800. // drug.Total = drug.Total + num
  5801. // service.UpdateBaseDrugLib(&drug)
  5802. // } else if num2 < advice.PrescribingNumber {
  5803. // num = num2 - hisAdvice.PrescribingNumber
  5804. // drug.Total = drug.Total - num
  5805. // service.UpdateBaseDrugLib(&drug)
  5806. // }
  5807. //
  5808. // }
  5809. // }
  5810. // }
  5811. //}
  5812. //
  5813. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5814. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5815. // advice.ExecutionTime = execution_time
  5816. //}
  5817. //
  5818. //
  5819. //
  5820. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5821. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5822. // advice.ExecutionStaff = execution_staff
  5823. //}
  5824. //
  5825. //
  5826. //
  5827. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5828. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5829. // advice.ExecutionState = execution_state
  5830. //}
  5831. //
  5832. //
  5833. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5834. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5835. // advice.CheckTime = check_time
  5836. //}
  5837. //
  5838. //
  5839. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5840. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5841. // advice.CheckState = check_state
  5842. //}
  5843. //
  5844. //
  5845. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5846. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5847. // advice.Checker = checker
  5848. //}
  5849. //
  5850. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5851. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5852. // advice.StartTime = start_time
  5853. //}
  5854. return 0
  5855. }
  5856. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5857. project.ExecutionStaff = 0
  5858. project.ExecutionState = 2
  5859. project.ExecutionTime = 0
  5860. project.Checker = 0
  5861. project.CheckState = 2
  5862. project.CheckTime = 0
  5863. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5864. id := int64(json["id"].(float64))
  5865. project.ID = id
  5866. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5867. project.ExecutionStaff = temp_project.ExecutionStaff
  5868. project.ExecutionState = temp_project.ExecutionState
  5869. project.ExecutionTime = temp_project.ExecutionTime
  5870. project.Checker = temp_project.Checker
  5871. project.CheckState = temp_project.CheckState
  5872. project.CheckTime = temp_project.CheckTime
  5873. project.TeamId = temp_project.TeamId
  5874. }
  5875. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5876. types := int64(json["type"].(float64))
  5877. project.Type = types
  5878. }
  5879. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5880. project_id := int64(json["project_id"].(float64))
  5881. project.ProjectId = project_id
  5882. }
  5883. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5884. team_id := int64(json["team_id"].(float64))
  5885. project.TeamId = team_id
  5886. }
  5887. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5888. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5889. project.Price = price
  5890. }
  5891. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5892. total, _ := json["total"].(string)
  5893. //totals, _ := strconv.ParseInt(total, 10, 64)
  5894. project.Count = total
  5895. }
  5896. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5897. medical_code, _ := json["medical_code"].(string)
  5898. project.MedListCodg = medical_code
  5899. }
  5900. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5901. single_dose, _ := json["single_dose"].(string)
  5902. project.SingleDose = single_dose
  5903. }
  5904. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5905. delivery_way, _ := json["delivery_way"].(string)
  5906. project.DeliveryWay = delivery_way
  5907. }
  5908. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5909. execution_frequency, _ := json["execution_frequency"].(string)
  5910. project.ExecutionFrequency = execution_frequency
  5911. }
  5912. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5913. remark, _ := json["remark"].(string)
  5914. project.Remark = remark
  5915. }
  5916. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5917. day, _ := json["number_days"].(string)
  5918. project.Day = day
  5919. }
  5920. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5921. unit, _ := json["unit"].(string)
  5922. project.Unit = unit
  5923. }
  5924. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5925. // frequency_type := int64(json["frequency_type"].(float64))
  5926. // project.FrequencyType = frequency_type
  5927. //}
  5928. //
  5929. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5930. // day_count := int64(json["day_count"].(float64))
  5931. // project.DayCount = day_count
  5932. //}
  5933. //
  5934. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5935. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5936. // week_day, _ := json["week_day"].(string)
  5937. // project.WeekDay = week_day
  5938. //}
  5939. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5940. //
  5941. //if project.ID == 0 {
  5942. // if stockConfig.IsOpen == 1 {
  5943. // if project.Type == 3 {
  5944. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5945. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5946. // good.Total = good.Total - f_count
  5947. // service.UpdateGoodInfo(&good)
  5948. // }
  5949. // }
  5950. //
  5951. //} else {
  5952. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5953. //
  5954. // if stockConfig.IsOpen == 1 {
  5955. // if project.Type == 3 {
  5956. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5957. // if project.Count < temp_project.Count {
  5958. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5959. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5960. //
  5961. // other_count := f_count_two - f_count_one
  5962. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5963. // good.Total = good.Total + other_count_two
  5964. // service.UpdateGoodInfo(&good)
  5965. // } else if project.Count > temp_project.Count {
  5966. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5967. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5968. //
  5969. // other_count := f_count_one - f_count_two
  5970. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5971. // good.Total = good.Total - other_count_two
  5972. // service.UpdateGoodInfo(&good)
  5973. // }
  5974. //
  5975. // }
  5976. // }
  5977. //
  5978. //}
  5979. return 0
  5980. }
  5981. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5982. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5983. id := int64(json["id"].(float64))
  5984. additionalCharge.ID = id
  5985. }
  5986. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5987. item_id := int64(json["item_id"].(float64))
  5988. additionalCharge.ItemId = item_id
  5989. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5990. if config.ID > 0 {
  5991. if len(config.Code) > 0 {
  5992. additionalCharge.MedListCodg = config.Code
  5993. }
  5994. }
  5995. }
  5996. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5997. // price := int64(json["price"].(float64))
  5998. // formatInt_price := strconv.FormatInt(price, 10)
  5999. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6000. // additionalCharge.Price = float_price
  6001. // }
  6002. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6003. // price := int64(json["price"].(float64))
  6004. // formatInt_price := strconv.FormatInt(price, 10)
  6005. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6006. // additionalCharge.Price = float_price
  6007. //}
  6008. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6009. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6010. additionalCharge.Price = price
  6011. }
  6012. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6013. count, _ := json["count"].(string)
  6014. counts, _ := strconv.ParseInt(count, 10, 64)
  6015. additionalCharge.Count = counts
  6016. }
  6017. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6018. item_name, _ := json["item_name"].(string)
  6019. additionalCharge.ItemName = item_name
  6020. }
  6021. return 0
  6022. }
  6023. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6024. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6025. utils.ErrorLog("drug_name")
  6026. return enums.ErrorCodeParamWrong
  6027. }
  6028. adviceName, _ := json["drug_name"].(string)
  6029. if len(adviceName) == 0 {
  6030. utils.ErrorLog("len(advice_name) == 0")
  6031. return enums.ErrorCodeParamWrong
  6032. }
  6033. advice.AdviceName = adviceName
  6034. adviceDesc, _ := json["advice_desc"].(string)
  6035. advice.AdviceDesc = adviceDesc
  6036. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6037. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6038. advice.DrugSpec = drugSpec
  6039. }
  6040. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6041. remark, _ := json["remark"].(string)
  6042. advice.Remark = remark
  6043. }
  6044. if json["id"] == nil {
  6045. advice.DrugId = 0
  6046. } else {
  6047. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6048. drug_id := int64(json["id"].(float64))
  6049. advice.DrugId = drug_id
  6050. }
  6051. }
  6052. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6053. groupno := int64(json["groupno"].(float64))
  6054. advice.Groupno = groupno
  6055. }
  6056. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6057. drugSpecUnit, _ := json["min_unit"].(string)
  6058. advice.DrugSpecUnit = drugSpecUnit
  6059. }
  6060. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6061. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6062. advice.SingleDose = singleDose
  6063. }
  6064. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6065. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6066. advice.SingleDoseUnit = singleDoseUnit
  6067. }
  6068. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6069. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6070. advice.PrescribingNumber = prescribingNumber
  6071. }
  6072. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6073. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6074. advice.PrescribingNumberUnit = prescribingNumberUnit
  6075. }
  6076. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6077. deliveryWay, _ := json["delivery_way"].(string)
  6078. advice.DeliveryWay = deliveryWay
  6079. }
  6080. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6081. executionFrequency, _ := json["execution_frequency"].(string)
  6082. advice.ExecutionFrequency = executionFrequency
  6083. }
  6084. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6085. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6086. advice.Price = price
  6087. }
  6088. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6089. med_list_codg, _ := json["medical_insurance_number"].(string)
  6090. advice.MedListCodg = med_list_codg
  6091. }
  6092. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6093. day := int64(json["day"].(float64))
  6094. advice.Day = day
  6095. }
  6096. advice.FrequencyType = 1
  6097. return 0
  6098. }
  6099. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6100. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6101. types := int64(json["type"].(float64))
  6102. project.Type = types
  6103. }
  6104. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6105. project_id := int64(json["project_id"].(float64))
  6106. project.ProjectId = project_id
  6107. }
  6108. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6109. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6110. project.Price = price
  6111. }
  6112. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6113. total, _ := json["total"].(string)
  6114. //totals, _ := strconv.ParseInt(total, 10, 64)
  6115. project.Count = total
  6116. }
  6117. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6118. medical_code, _ := json["medical_code"].(string)
  6119. project.MedListCodg = medical_code
  6120. }
  6121. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6122. single_dose, _ := json["single_dose"].(string)
  6123. project.SingleDose = single_dose
  6124. }
  6125. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6126. delivery_way, _ := json["delivery_way"].(string)
  6127. project.DeliveryWay = delivery_way
  6128. }
  6129. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6130. execution_frequency, _ := json["execution_frequency"].(string)
  6131. project.ExecutionFrequency = execution_frequency
  6132. }
  6133. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6134. remark, _ := json["remark"].(string)
  6135. project.Remark = remark
  6136. }
  6137. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6138. day, _ := json["number_days"].(string)
  6139. project.Day = day
  6140. }
  6141. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6142. unit, _ := json["unit"].(string)
  6143. project.Unit = unit
  6144. }
  6145. project.FrequencyType = 1
  6146. return 0
  6147. }
  6148. func (c *HisApiController) GetHisOrderListTwo() {
  6149. start_time := c.GetString("start_time")
  6150. end_time := c.GetString("end_time")
  6151. timeLayout := "2006-01-02"
  6152. loc, _ := time.LoadLocation("Local")
  6153. var startTime int64
  6154. if len(start_time) > 0 {
  6155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6156. if err != nil {
  6157. //fmt.Println(err)
  6158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6159. return
  6160. }
  6161. startTime = theTime.Unix()
  6162. }
  6163. var endTime int64
  6164. if len(end_time) > 0 {
  6165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6166. if err != nil {
  6167. utils.ErrorLog(err.Error())
  6168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6169. return
  6170. }
  6171. endTime = theTime.Unix()
  6172. }
  6173. adminUser := c.GetAdminUserInfo()
  6174. org_id := adminUser.CurrentOrgId
  6175. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  6176. if err == nil {
  6177. c.ServeSuccessJSON(map[string]interface{}{
  6178. "order2": order,
  6179. })
  6180. } else {
  6181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6182. return
  6183. }
  6184. }
  6185. func (c *HisApiController) GetHisOrderList() {
  6186. page, _ := c.GetInt64("page", -1)
  6187. limit, _ := c.GetInt64("limit", -1)
  6188. start_time := c.GetString("start_time")
  6189. end_time := c.GetString("end_time")
  6190. types, _ := c.GetInt64("type", 0)
  6191. keywords := c.GetString("keywords")
  6192. p_type, _ := c.GetInt64("p_type", 0)
  6193. sort_type, _ := c.GetInt64("sort_type", 0)
  6194. charge_type, _ := c.GetInt64("charge_type", 0)
  6195. sch_type, _ := c.GetInt64("sch_type", 0)
  6196. zone_type, _ := c.GetInt64("zone_type", 0)
  6197. med_type, _ := c.GetInt64("med_type", 0)
  6198. timeLayout := "2006-01-02"
  6199. loc, _ := time.LoadLocation("Local")
  6200. var startTime int64
  6201. if len(start_time) > 0 {
  6202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6203. if err != nil {
  6204. //fmt.Println(err)
  6205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6206. return
  6207. }
  6208. startTime = theTime.Unix()
  6209. }
  6210. var endTime int64
  6211. if len(end_time) > 0 {
  6212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6213. if err != nil {
  6214. utils.ErrorLog(err.Error())
  6215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6216. return
  6217. }
  6218. endTime = theTime.Unix()
  6219. }
  6220. adminUser := c.GetAdminUserInfo()
  6221. org_id := adminUser.CurrentOrgId
  6222. 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)
  6223. for _, item := range order {
  6224. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  6225. item.DoctorName = info.Doctor
  6226. item.DepartmentName = info.XtHisDepartment.Name
  6227. }
  6228. if err == nil {
  6229. c.ServeSuccessJSON(map[string]interface{}{
  6230. "order": order,
  6231. "total": total,
  6232. })
  6233. } else {
  6234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6235. return
  6236. }
  6237. }
  6238. func (c *HisApiController) GetHisOrder() {
  6239. patient_id, _ := c.GetInt64("patient_id", 0)
  6240. number := c.GetString("number")
  6241. adminInfo := c.GetAdminUserInfo()
  6242. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  6243. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  6244. if err == nil {
  6245. c.ServeSuccessJSON(map[string]interface{}{
  6246. "order": order,
  6247. "prescription": prescriptions,
  6248. })
  6249. } else {
  6250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6251. return
  6252. }
  6253. }
  6254. func (c *HisApiController) GetHisPrescriptionList() {
  6255. record_date := c.GetString("record_date")
  6256. keywords := c.GetString("keywords")
  6257. page, _ := c.GetInt64("page")
  6258. limit, _ := c.GetInt64("limit")
  6259. sch_type, _ := c.GetInt64("sch_type")
  6260. timeLayout := "2006-01-02"
  6261. loc, _ := time.LoadLocation("Local")
  6262. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6263. if err != nil {
  6264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6265. return
  6266. }
  6267. recordDateTime := theTime.Unix()
  6268. adminInfo := c.GetAdminUserInfo()
  6269. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  6270. //adminInfo := c.GetAdminUserInfo()
  6271. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  6272. //fmt.Println(prescriptionOrder)
  6273. if err == nil {
  6274. c.ServeSuccessJSON(map[string]interface{}{
  6275. "order": prescriptionOrder,
  6276. "total": total,
  6277. })
  6278. } else {
  6279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6280. return
  6281. }
  6282. }
  6283. func (c *HisApiController) GetHisPrescriptionInfo() {
  6284. id, _ := c.GetInt64("id")
  6285. adminInfo := c.GetAdminUserInfo()
  6286. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  6287. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  6288. if err == nil {
  6289. c.ServeSuccessJSON(map[string]interface{}{
  6290. "order": prescriptionOrder,
  6291. "prescription": prescription,
  6292. })
  6293. } else {
  6294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6295. return
  6296. }
  6297. }
  6298. func (c *HisApiController) GetMedicalInsuranceConfig() {
  6299. adminUser := c.GetAdminUserInfo()
  6300. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  6301. c.ServeSuccessJSON(map[string]interface{}{
  6302. "config": config,
  6303. })
  6304. }
  6305. type ResultTwo struct {
  6306. ErrMsg interface{} `json:"err_msg"`
  6307. InfRefmsgid string `json:"inf_refmsgid"`
  6308. Infcode int64 `json:"infcode"`
  6309. Output struct {
  6310. Baseinfo struct {
  6311. Age float64 `json:"age"`
  6312. Brdy string `json:"brdy"`
  6313. Certno string `json:"certno"`
  6314. Gend string `json:"gend"`
  6315. Naty string `json:"naty"`
  6316. PsnCertType string `json:"psn_cert_type"`
  6317. PsnName string `json:"psn_name"`
  6318. PsnNo string `json:"psn_no"`
  6319. } `json:"baseinfo"`
  6320. Idetinfo []interface{} `json:"idetinfo"`
  6321. Iinfo []struct {
  6322. Balc float64 `json:"balc"`
  6323. CvlservFlag string `json:"cvlserv_flag"`
  6324. EmpName string `json:"emp_name"`
  6325. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  6326. Insutype string `json:"insutype"`
  6327. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  6328. PausInsuDate interface{} `json:"paus_insu_date"`
  6329. PsnInsuDate string `json:"psn_insu_date"`
  6330. PsnInsuStas string `json:"psn_insu_stas"`
  6331. PsnType string `json:"psn_type"`
  6332. } `json:"insuinfo"`
  6333. } `json:"output"`
  6334. RefmsgTime string `json:"refmsg_time"`
  6335. RespondTime string `json:"respond_time"`
  6336. Signtype interface{} `json:"signtype"`
  6337. WarnInfo interface{} `json:"warn_info"`
  6338. }
  6339. type ResultThree struct {
  6340. Cainfo interface{} `json:"cainfo"`
  6341. ErrMsg interface{} `json:"err_msg"`
  6342. InfRefmsgid string `json:"inf_refmsgid"`
  6343. Infcode int64 `json:"infcode"`
  6344. Output struct {
  6345. Data struct {
  6346. IptOtpNo string `json:"ipt_otp_no"`
  6347. MdtrtID string `json:"mdtrt_id"`
  6348. PsnNo string `json:"psn_no"`
  6349. } `json:"data"`
  6350. } `json:"output"`
  6351. RefmsgTime string `json:"refmsg_time"`
  6352. RespondTime string `json:"respond_time"`
  6353. Signtype interface{} `json:"signtype"`
  6354. WarnMsg interface{} `json:"warn_msg"`
  6355. }
  6356. type ResultFour struct {
  6357. Cainfo string `json:"cainfo"`
  6358. ErrMsg string `json:"err_msg"`
  6359. InfRefmsgid string `json:"inf_refmsgid"`
  6360. Infcode int64 `json:"infcode"`
  6361. Output struct {
  6362. Result []struct {
  6363. BasMednFlag string `json:"bas_medn_flag"`
  6364. ChldMedcFlag string `json:"chld_medc_flag"`
  6365. ChrgitmLv string `json:"chrgitm_lv"`
  6366. Cnt float64 `json:"cnt"`
  6367. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  6368. DrtReimFlag string `json:"drt_reim_flag"`
  6369. FeedetlSn string `json:"feedetl_sn"`
  6370. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6371. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  6372. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6373. ListSpItemFlag string `json:"list_sp_item_flag"`
  6374. LmtUsedFlag string `json:"lmt_used_flag"`
  6375. MedChrgitmType string `json:"med_chrgitm_type"`
  6376. Memo string `json:"memo"`
  6377. OverlmtAmt float64 `json:"overlmt_amt"`
  6378. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6379. Pric float64 `json:"pric"`
  6380. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  6381. SelfpayProp float64 `json:"selfpay_prop"`
  6382. } `json:"result"`
  6383. } `json:"output"`
  6384. RefmsgTime string `json:"refmsg_time"`
  6385. RespondTime string `json:"respond_time"`
  6386. Signtype string `json:"signtype"`
  6387. WarnMsg string `json:"warn_msg"`
  6388. }
  6389. type ResultFive struct {
  6390. Insutype string `json:"insutype"`
  6391. }
  6392. type ResultSix struct {
  6393. Cainfo interface{} `json:"cainfo"`
  6394. ErrMsg interface{} `json:"err_msg"`
  6395. InfRefmsgid string `json:"inf_refmsgid"`
  6396. Infcode int64 `json:"infcode"`
  6397. Output struct {
  6398. } `json:"output"`
  6399. RefmsgTime string `json:"refmsg_time"`
  6400. RespondTime string `json:"respond_time"`
  6401. Signtype interface{} `json:"signtype"`
  6402. WarnMsg interface{} `json:"warn_msg"`
  6403. }
  6404. type ResultSeven struct {
  6405. Cainfo string `json:"cainfo"`
  6406. ErrMsg string `json:"err_msg"`
  6407. InfRefmsgid string `json:"inf_refmsgid"`
  6408. Infcode int64 `json:"infcode"`
  6409. Output struct {
  6410. Setldetail []interface{} `json:"setldetail"`
  6411. Setlinfo struct {
  6412. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6413. AcctPay float64 `json:"acct_pay"`
  6414. ActPayDedc float64 `json:"act_pay_dedc"`
  6415. Age float64 `json:"age"`
  6416. Balc float64 `json:"balc"`
  6417. Brdy string `json:"brdy"`
  6418. Certno string `json:"certno"`
  6419. ClrOptins string `json:"clr_optins"`
  6420. ClrType string `json:"clr_type"`
  6421. ClrWay string `json:"clr_way"`
  6422. CvlservFlag string `json:"cvlserv_flag"`
  6423. CvlservPay float64 `json:"cvlserv_pay"`
  6424. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6425. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6426. Gend string `json:"gend"`
  6427. HifesPay float64 `json:"hifes_pay"`
  6428. HifmiPay float64 `json:"hifmi_pay"`
  6429. HifobPay float64 `json:"hifob_pay"`
  6430. HifpPay float64 `json:"hifp_pay"`
  6431. HospPartAmt float64 `json:"hosp_part_amt"`
  6432. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6433. Insutype string `json:"insutype"`
  6434. MafPay float64 `json:"maf_pay"`
  6435. MdtrtCertType string `json:"mdtrt_cert_type"`
  6436. MdtrtID string `json:"mdtrt_id"`
  6437. MedType string `json:"med_type"`
  6438. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6439. MedinsSetlID string `json:"medins_setl_id"`
  6440. Naty string `json:"naty"`
  6441. OthPay float64 `json:"oth_pay"`
  6442. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6443. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6444. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6445. PsnCashPay float64 `json:"psn_cash_pay"`
  6446. PsnCertType string `json:"psn_cert_type"`
  6447. PsnName string `json:"psn_name"`
  6448. PsnNo string `json:"psn_no"`
  6449. PsnPartAmt float64 `json:"psn_part_amt"`
  6450. PsnType string `json:"psn_type"`
  6451. SetlID string `json:"setl_id"`
  6452. SetlTime string `json:"setl_time"`
  6453. } `json:"setlinfo"`
  6454. } `json:"output"`
  6455. RefmsgTime string `json:"refmsg_time"`
  6456. RespondTime string `json:"respond_time"`
  6457. Signtype interface{} `json:"signtype"`
  6458. WarnMsg interface{} `json:"warn_msg"`
  6459. }
  6460. type ResultEight struct {
  6461. Cainfo string `json:"cainfo"`
  6462. ErrMsg string `json:"err_msg"`
  6463. InfRefmsgid string `json:"inf_refmsgid"`
  6464. Infcode int64 `json:"infcode"`
  6465. Output struct {
  6466. Stmtinfo struct {
  6467. SetlOptins string `json:"setl_optins"`
  6468. StmtRslt string `json:"stmt_rslt"`
  6469. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6470. } `json:"stmtinfo"`
  6471. } `json:"output"`
  6472. RefmsgTime string `json:"refmsg_time"`
  6473. RespondTime string `json:"respond_time"`
  6474. Signtype interface{} `json:"signtype"`
  6475. WarnMsg interface{} `json:"warn_msg"`
  6476. }
  6477. type ResultNine struct {
  6478. Cainfo string `json:"cainfo"`
  6479. ErrMsg string `json:"err_msg"`
  6480. InfRefmsgid string `json:"inf_refmsgid"`
  6481. Infcode int64 `json:"infcode"`
  6482. Output struct {
  6483. FileQuryNo string `json:"file_qury_no"`
  6484. } `json:"output"`
  6485. RefmsgTime string `json:"refmsg_time"`
  6486. RespondTime string `json:"respond_time"`
  6487. Signtype interface{} `json:"signtype"`
  6488. WarnMsg interface{} `json:"warn_msg"`
  6489. }
  6490. type ResultTen struct {
  6491. Cainfo string `json:"cainfo"`
  6492. ErrMsg string `json:"err_msg"`
  6493. InfRefmsgid string `json:"inf_refmsgid"`
  6494. Infcode int64 `json:"infcode"`
  6495. Output struct {
  6496. DldEndtime string `json:"dld_endtime"`
  6497. FileQuryNo string `json:"file_qury_no"`
  6498. Filename string `json:"filename"`
  6499. } `json:"output"`
  6500. RefmsgTime string `json:"refmsg_time"`
  6501. RespondTime string `json:"respond_time"`
  6502. Signtype interface{} `json:"signtype"`
  6503. WarnMsg interface{} `json:"warn_msg"`
  6504. }
  6505. type ResultEleven struct {
  6506. Cainfo string `json:"cainfo"`
  6507. ErrMsg string `json:"err_msg"`
  6508. InfRefmsgid string `json:"inf_refmsgid"`
  6509. Infcode int64 `json:"infcode"`
  6510. Output struct {
  6511. Setlinfo struct {
  6512. FixmedinsName string `json:"fixmedins_name"`
  6513. FixmedinsCode string `json:"fixmedins_code"`
  6514. PsnNo string `json:"psn_no"`
  6515. PsnName string `json:"psn_name"`
  6516. HifobPay float64 `json:"hifob_pay"`
  6517. Gend string `json:"gend"`
  6518. Brdy string `json:"brdy"`
  6519. PsnCertType string `json:"psn_cert_type"`
  6520. PsnType string `json:"psn_type"`
  6521. EmpName string `json:"emp_name"`
  6522. Certno string `json:"certno"`
  6523. Insutype string `json:"insutype"`
  6524. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6525. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6526. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6527. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6528. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6529. ActPayDedc float64 `json:"act_pay_dedc"`
  6530. HifpPay float64 `json:"hifp_pay"`
  6531. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6532. CvlservPay float64 `json:"cvlserv_pay"`
  6533. HifesPay float64 `json:"hifes_pay"`
  6534. HifmiPay float64 `json:"hifmi_pay"`
  6535. MafPay float64 `json:"maf_pay"`
  6536. OthPay float64 `json:"oth_pay"`
  6537. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6538. PsnPay float64 `json:"psn_pay"`
  6539. AcctPay float64 `json:"acct_pay"`
  6540. CashPayamt float64 `json:"cash_payamt"`
  6541. Balc float64 `json:"balc"`
  6542. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6543. MedinsSetlId string `json:"medins_setl_id"`
  6544. RefdSetlFlag string `json:"refd_setl_flag"`
  6545. SetlTime string `json:"setl_time"`
  6546. MedType string `json:"med_type"`
  6547. } `json:"setlinfo"`
  6548. } `json:"output"`
  6549. RefmsgTime string `json:"refmsg_time"`
  6550. RespondTime string `json:"respond_time"`
  6551. Signtype interface{} `json:"signtype"`
  6552. WarnMsg interface{} `json:"warn_msg"`
  6553. }
  6554. type Custom struct {
  6555. DetItemFeeSumamt string
  6556. Cut string
  6557. FeedetlSn string
  6558. Price string
  6559. MedListCodg string
  6560. Type int64
  6561. AdviceId int64
  6562. ProjectId int64
  6563. ItemId int64
  6564. }
  6565. // 获取个人信息----挂号-----上传就诊信息
  6566. func (c *HisApiController) GetRegisterInfo() {
  6567. id, _ := c.GetInt64("id")
  6568. record_time := c.GetString("record_time")
  6569. settlementValue, _ := c.GetInt64("settlement_value")
  6570. medical_insurance_card := c.GetString("medical_insurance_card")
  6571. name := c.GetString("name")
  6572. id_card_type, _ := c.GetInt64("id_card_type")
  6573. certificates, _ := c.GetInt64("certificates")
  6574. medical_care, _ := c.GetInt64("medical_care")
  6575. birthday := c.GetString("birthday")
  6576. age, _ := c.GetInt64("age")
  6577. id_card := c.GetString("id_card")
  6578. register_type, _ := c.GetInt64("register")
  6579. doctor, _ := c.GetInt64("doctor")
  6580. department, _ := c.GetInt64("department")
  6581. gender, _ := c.GetInt64("sex")
  6582. phone := c.GetString("phone")
  6583. registration_fee, _ := c.GetFloat("registration_fee")
  6584. medical_expenses, _ := c.GetFloat("medical_expenses")
  6585. social_type, _ := c.GetInt64("social_type")
  6586. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6587. diagnosis_ids := c.GetString("diagnosis")
  6588. sick_type, _ := c.GetInt64("sick_type")
  6589. reg_type := c.GetString("p_type")
  6590. timeLayout := "2006-01-02"
  6591. loc, _ := time.LoadLocation("Local")
  6592. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6593. birthUnix := birthdays.Unix()
  6594. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6595. if err != nil {
  6596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6597. return
  6598. }
  6599. recordDateTime := theTime.Unix()
  6600. adminInfo := c.GetAdminUserInfo()
  6601. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6602. if tempPatient.ID == 0 {
  6603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6604. return
  6605. }
  6606. var patient service.Patients
  6607. if id == 0 {
  6608. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6609. } else {
  6610. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6611. }
  6612. if patient.ID == 0 {
  6613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6614. return
  6615. }
  6616. if len(patient.IdCardNo) == 0 {
  6617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6618. return
  6619. }
  6620. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6621. if len(his) >= 1 {
  6622. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6623. if len(his) >= 1 && order.ID == 0 {
  6624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6625. return
  6626. }
  6627. }
  6628. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6629. fmt.Println(timeStr)
  6630. timeArr := strings.Split(timeStr, " ")
  6631. fmt.Println(timeArr)
  6632. timeArrTwo := strings.Split(timeArr[0], "-")
  6633. timeArrThree := strings.Split(timeArr[1], ":")
  6634. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6635. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6636. if len(lists) == 0 {
  6637. var hisPatient models.XtHisPatient
  6638. hisPatient = models.XtHisPatient{
  6639. Name: name,
  6640. Age: age,
  6641. Gender: gender,
  6642. Birthday: birthUnix,
  6643. Phone: phone,
  6644. MedicalTreatmentType: medical_care,
  6645. IdType: certificates,
  6646. IdCardNo: id_card,
  6647. BalanceAccountsType: settlementValue,
  6648. SocialType: social_type,
  6649. MedicalInsuranceNumber: medical_insurance_card,
  6650. RegisterType: register_type,
  6651. RegisterCost: registration_fee,
  6652. TreatmentCost: medical_expenses,
  6653. AdminUserId: adminInfo.AdminUser.Id,
  6654. UserOrgId: adminInfo.CurrentOrgId,
  6655. Status: 1,
  6656. RecordDate: recordDateTime,
  6657. IsReturn: 1,
  6658. PatientId: patient.ID,
  6659. Ctime: time.Now().Unix(),
  6660. Mtime: time.Now().Unix(),
  6661. Number: str,
  6662. IdCardType: id_card_type,
  6663. Departments: department,
  6664. Doctor: doctor,
  6665. PType: reg_type,
  6666. Diagnosis: diagnosis_ids,
  6667. SickType: sick_type,
  6668. }
  6669. service.CreateHisPatient(&hisPatient)
  6670. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6671. c.ServeSuccessJSON(map[string]interface{}{
  6672. "his_info": hisPatient,
  6673. })
  6674. } else {
  6675. //chrgBchno := rand.Intn(1000000) + 10000
  6676. var hisPatient models.XtHisPatient
  6677. hisPatient = models.XtHisPatient{
  6678. Name: name,
  6679. Age: age,
  6680. Gender: gender,
  6681. Birthday: birthUnix,
  6682. Phone: phone,
  6683. MedicalTreatmentType: medical_care,
  6684. IdType: certificates,
  6685. IdCardNo: id_card,
  6686. BalanceAccountsType: settlementValue,
  6687. SocialType: social_type,
  6688. MedicalInsuranceNumber: medical_insurance_card,
  6689. RegisterType: register_type,
  6690. RegisterCost: registration_fee,
  6691. TreatmentCost: medical_expenses,
  6692. AdminUserId: adminInfo.AdminUser.Id,
  6693. UserOrgId: adminInfo.CurrentOrgId,
  6694. Status: 1,
  6695. RecordDate: recordDateTime,
  6696. IsReturn: 1,
  6697. PatientId: patient.ID,
  6698. Ctime: time.Now().Unix(),
  6699. Mtime: time.Now().Unix(),
  6700. Number: str,
  6701. IdCardType: id_card_type,
  6702. Departments: department,
  6703. Doctor: doctor,
  6704. PType: reg_type,
  6705. Diagnosis: diagnosis_ids,
  6706. SickType: sick_type,
  6707. }
  6708. service.CreateHisPatient(&hisPatient)
  6709. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6710. c.ServeSuccessJSON(map[string]interface{}{
  6711. "his_info": hisPatient,
  6712. })
  6713. }
  6714. }
  6715. // 上传明细----结算
  6716. func (c *HisApiController) GetUploadInfo() {
  6717. id, _ := c.GetInt64("id")
  6718. record_time := c.GetString("record_time")
  6719. his_patient_id, _ := c.GetInt64("his_patient_id")
  6720. oth_desc := c.GetString("oth_desc")
  6721. pay_way, _ := c.GetInt64("pay_way")
  6722. pay_ways := c.GetString("pay_ways")
  6723. pay_price, _ := c.GetFloat("pay_price")
  6724. pay_card_no := c.GetString("pay_card_no")
  6725. discount_price, _ := c.GetFloat("discount_price")
  6726. preferential_price, _ := c.GetFloat("preferential_price")
  6727. reality_price, _ := c.GetFloat("reality_price")
  6728. found_price, _ := c.GetFloat("found_price")
  6729. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6730. private_price, _ := c.GetFloat("private_price")
  6731. timeLayout := "2006-01-02"
  6732. loc, _ := time.LoadLocation("Local")
  6733. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6734. fapiao_code := c.GetString("fapiao_code")
  6735. fapiao_number := c.GetString("fapiao_number")
  6736. diagnosis_id := c.GetString("diagnosis")
  6737. sick_type, _ := c.GetInt64("sick_type")
  6738. reg_type, _ := c.GetInt64("p_type")
  6739. order_id, _ := c.GetInt64("order_id")
  6740. cash_pay := c.GetString("cash_pay")
  6741. wechat_pay := c.GetString("wechat_pay")
  6742. ali_pay := c.GetString("ali_pay")
  6743. jifen_pay := c.GetString("jifen_pay")
  6744. band_card_pay := c.GetString("band_card_pay")
  6745. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6746. tmp_decimal := c.GetString("tmp_decimal")
  6747. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6748. var decimal float64 //本次使用的押金
  6749. var errmsg error
  6750. tx := service.XTWriteDB().Begin() //开了事务
  6751. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6752. defer func() {
  6753. if errmsg != nil {
  6754. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6755. tx.Rollback()
  6756. } else {
  6757. tx.Commit()
  6758. }
  6759. }()
  6760. fmt.Println("dec_way", dec_way)
  6761. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6762. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6763. return
  6764. }
  6765. if len(tmp_decimal) > 0 {
  6766. if tmp_decimal[0] == 45 {
  6767. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6768. return
  6769. }
  6770. }
  6771. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6772. fmt.Println(errs)
  6773. decimal = tt
  6774. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6775. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6777. if err != nil {
  6778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6779. return
  6780. }
  6781. recordDateTime := theTime.Unix()
  6782. adminUser := c.GetAdminUserInfo()
  6783. var prescriptions []*models.HisPrescription
  6784. var prescriptionsOne []*models.HisPrescription
  6785. var start_time int64
  6786. var end_time int64
  6787. ids_str := c.GetString("ids")
  6788. ids_arr := strings.Split(ids_str, ",")
  6789. if tempOrder.ID == 0 {
  6790. if settle_accounts_type == 1 { //日结
  6791. fmt.Println(reg_type)
  6792. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6793. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6794. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6795. } else {
  6796. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6797. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6798. }
  6799. } else { //月结
  6800. start_time_str := c.GetString("start_time")
  6801. end_time_str := c.GetString("end_time")
  6802. timeLayout := "2006-01-02"
  6803. loc, _ := time.LoadLocation("Local")
  6804. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6805. if err != nil {
  6806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6807. return
  6808. }
  6809. recordStartTime := theStartTime.Unix()
  6810. start_time = recordStartTime
  6811. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6812. if err != nil {
  6813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6814. return
  6815. }
  6816. recordEndTime := theEndTime.Unix()
  6817. end_time = recordEndTime
  6818. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6819. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6820. }
  6821. var goods []*models.DialysisBeforePrepareGoods
  6822. var newGoods []*models.NewDialysisBeforePrepareGoods
  6823. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6824. var infos []*models.HisDoctorAdviceInfo
  6825. var infoList []*models.HisDoctorAdviceInfo
  6826. var hisAdvice []*models.HisDoctorAdviceInfo
  6827. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6828. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6829. //判断库存不足
  6830. //结算出库开关
  6831. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6832. if settConfig.IsOpen == 1 {
  6833. //判断库存的地方
  6834. for _, info := range prescriptions {
  6835. if info.Type == 1 {
  6836. infos = append(infos, info.HisDoctorAdviceInfo...)
  6837. }
  6838. if info.Type == 2 {
  6839. for _, sumItem := range info.HisPrescriptionProject {
  6840. if sumItem.Type == 3 {
  6841. var good models.DialysisBeforePrepareGoods
  6842. var newGood models.NewDialysisBeforePrepareGoods
  6843. good.GoodId = sumItem.GoodInfo.ID
  6844. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6845. count, _ := strconv.Atoi(sumItem.Count)
  6846. good.Count = int64(count)
  6847. good.StorehouseId = houseConfig.StorehouseOutInfo
  6848. good.ProjectId = sumItem.ID
  6849. goods = append(goods, &good)
  6850. newGood.GoodId = sumItem.GoodInfo.ID
  6851. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6852. count2, _ := strconv.Atoi(sumItem.Count)
  6853. newGood.Count = int64(count2)
  6854. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6855. newGood.ProjectId = sumItem.ID
  6856. newGoods = append(newGoods, &newGood)
  6857. }
  6858. }
  6859. }
  6860. }
  6861. for _, info := range prescriptionsOne {
  6862. if info.Type == 1 {
  6863. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6864. }
  6865. if info.Type == 2 {
  6866. for _, sumItem := range info.HisPrescriptionProject {
  6867. if sumItem.Type == 3 {
  6868. var newGood models.NewDialysisBeforePrepareGoods
  6869. newGood.GoodId = sumItem.GoodInfo.ID
  6870. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6871. count2, _ := strconv.Atoi(sumItem.Count)
  6872. newGood.Count = int64(count2)
  6873. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6874. newGood.ProjectId = sumItem.ID
  6875. newGoodOne = append(newGoodOne, &newGood)
  6876. }
  6877. }
  6878. }
  6879. }
  6880. //判断
  6881. for _, itemOne := range infos {
  6882. for _, itemTwo := range hisAdvice {
  6883. if itemOne.DrugId == itemTwo.DrugId {
  6884. itemTwo.Child = append(itemTwo.Child, itemOne)
  6885. }
  6886. }
  6887. }
  6888. for _, itemTwo := range hisAdvice {
  6889. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6890. var sum_out_count int64
  6891. for _, itemThree := range itemTwo.Child {
  6892. var prescribing_number int64
  6893. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6894. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6895. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6896. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6897. }
  6898. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6899. prescribing_number = parseIntPrescribingNumber
  6900. }
  6901. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6902. prescribing_number = parseIntPrescribingNumber
  6903. }
  6904. sum_out_count += prescribing_number
  6905. }
  6906. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6907. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6908. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6909. if sum_out_count > drugStockOut.FlushCount {
  6910. c.ServeSuccessJSON(map[string]interface{}{
  6911. "msg": "2",
  6912. "drug": medical,
  6913. })
  6914. return
  6915. }
  6916. }
  6917. fmt.Println("newGoods99999988882os", newGoods)
  6918. for _, itemOne := range newGoods {
  6919. for _, item := range newGoodOne {
  6920. if itemOne.GoodId == item.GoodId {
  6921. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6922. }
  6923. }
  6924. }
  6925. for _, item := range newGoodOne {
  6926. var sum_out_count_one int64
  6927. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6928. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6929. sum_out_count_one += itemOne.Count
  6930. }
  6931. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6932. fmt.Println("sum_out_count_one", sum_out_count_one)
  6933. fmt.Println("list.FlushCount", list.FlushCount)
  6934. if sum_out_count_one > list.FlushCount {
  6935. c.ServeSuccessJSON(map[string]interface{}{
  6936. "msg": "3",
  6937. "good": good,
  6938. })
  6939. return
  6940. }
  6941. }
  6942. }
  6943. timestamp := time.Now().Unix()
  6944. tempTime := time.Unix(timestamp, 0)
  6945. timeFormat := tempTime.Format("20060102150405")
  6946. chrgBchno := rand.Intn(100000) + 10000
  6947. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6948. strconv.FormatInt(his.PatientId, 10)
  6949. var ids []int64
  6950. for _, item := range prescriptions {
  6951. ids = append(ids, item.ID)
  6952. }
  6953. var total float64
  6954. for _, item := range prescriptions {
  6955. fmt.Println(item)
  6956. if item.Type == 1 { //药品
  6957. for _, subItem := range item.HisDoctorAdviceInfo {
  6958. total = total + (subItem.Price * subItem.PrescribingNumber)
  6959. }
  6960. }
  6961. if item.Type == 2 { //项目
  6962. for _, subItem := range item.HisPrescriptionProject {
  6963. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6964. total = total + (subItem.Price * cnt)
  6965. }
  6966. }
  6967. for _, subItem := range item.HisAdditionalCharge {
  6968. total = total + (subItem.Price * float64(subItem.Count))
  6969. }
  6970. }
  6971. if reg_type == 1111 || reg_type == 1112 {
  6972. reg_type = 11
  6973. }
  6974. tm := time.Unix(time.Now().Unix(), 0)
  6975. allTotal := fmt.Sprintf("%.4f", total)
  6976. totals, _ := strconv.ParseFloat(allTotal, 64)
  6977. order := &models.HisOrder{
  6978. UserOrgId: adminUser.CurrentOrgId,
  6979. HisPatientId: his.ID,
  6980. PatientId: id,
  6981. SettleAccountsDate: recordDateTime,
  6982. Ctime: time.Now().Unix(),
  6983. Mtime: time.Now().Unix(),
  6984. Status: 1,
  6985. OrderStatus: 2,
  6986. MdtrtId: his.Number,
  6987. Number: chrg_bchno,
  6988. MedfeeSumamt: totals,
  6989. PayWay: pay_way,
  6990. PayWays: pay_ways,
  6991. PayPrice: pay_price,
  6992. MedType: strconv.Itoa(int(reg_type)),
  6993. PayCardNo: pay_card_no,
  6994. DiscountPrice: discount_price,
  6995. PreferentialPrice: preferential_price,
  6996. RealityPrice: reality_price,
  6997. FoundPrice: found_price,
  6998. MedicalInsurancePrice: medical_insurance_price,
  6999. PrivatePrice: private_price,
  7000. SettleEndTime: end_time,
  7001. SettleStartTime: start_time,
  7002. PsnPartAmt: totals,
  7003. PsnCashPay: totals,
  7004. SettleType: settle_accounts_type,
  7005. FaPiaoCode: fapiao_code,
  7006. FaPiaoNumber: fapiao_number,
  7007. Diagnosis: diagnosis_id,
  7008. PType: 2,
  7009. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7010. Decimal: decimal,
  7011. OthDesc: oth_desc,
  7012. CashPay: cash_pay,
  7013. WechatPay: wechat_pay,
  7014. AliPay: ali_pay,
  7015. JifenPay: jifen_pay,
  7016. BandCardPay: band_card_pay,
  7017. Creator: adminUser.AdminUser.Id,
  7018. }
  7019. err = service.CreateOrderTX(order, tx)
  7020. if err != nil {
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7022. return
  7023. }
  7024. var customs []*Custom
  7025. for _, item := range prescriptions {
  7026. if item.Type == 1 { //药品a
  7027. for _, subItem := range item.HisDoctorAdviceInfo {
  7028. cus := &Custom{
  7029. AdviceId: subItem.ID,
  7030. ProjectId: 0,
  7031. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7032. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7033. FeedetlSn: subItem.FeedetlSn,
  7034. Price: fmt.Sprintf("%.4f", subItem.Price),
  7035. MedListCodg: subItem.MedListCodg,
  7036. Type: 1,
  7037. }
  7038. customs = append(customs, cus)
  7039. }
  7040. }
  7041. if item.Type == 2 { //项目
  7042. for _, subItem := range item.HisPrescriptionProject {
  7043. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7044. cus := &Custom{
  7045. AdviceId: 0,
  7046. ProjectId: subItem.ID,
  7047. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7048. Cut: fmt.Sprintf("%.4f", cnt),
  7049. FeedetlSn: subItem.FeedetlSn,
  7050. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7051. MedListCodg: subItem.MedListCodg,
  7052. Type: 2,
  7053. }
  7054. customs = append(customs, cus)
  7055. }
  7056. }
  7057. for _, item := range item.HisAdditionalCharge {
  7058. cus := &Custom{
  7059. ItemId: item.ID,
  7060. AdviceId: 0,
  7061. ProjectId: 0,
  7062. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7063. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7064. FeedetlSn: item.FeedetlSn,
  7065. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7066. MedListCodg: item.XtHisAddtionConfig.Code,
  7067. Type: 3,
  7068. }
  7069. customs = append(customs, cus)
  7070. }
  7071. }
  7072. for _, item := range customs {
  7073. var advice_id int64 = 0
  7074. var project_id int64 = 0
  7075. var item_id int64 = 0
  7076. var types int64 = 0
  7077. if item.Type == 1 {
  7078. advice_id = item.AdviceId
  7079. project_id = 0
  7080. item_id = 0
  7081. } else if item.Type == 2 {
  7082. advice_id = 0
  7083. item_id = 0
  7084. project_id = item.ProjectId
  7085. } else if item.Type == 3 {
  7086. advice_id = 0
  7087. item_id = item.ItemId
  7088. project_id = 0
  7089. }
  7090. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7091. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7092. pric, _ := strconv.ParseFloat(item.Price, 32)
  7093. info := &models.HisOrderInfo{
  7094. OrderNumber: order.Number,
  7095. UploadDate: time.Now().Unix(),
  7096. AdviceId: advice_id,
  7097. DetItemFeeSumamt: detItemFeeSumamt,
  7098. Cnt: cut,
  7099. Pric: pric,
  7100. PatientId: id,
  7101. Status: 1,
  7102. Mtime: time.Now().Unix(),
  7103. Ctime: time.Now().Unix(),
  7104. UserOrgId: adminUser.CurrentOrgId,
  7105. HisPatientId: his.ID,
  7106. OrderId: order.ID,
  7107. ProjectId: project_id,
  7108. Type: types,
  7109. ItemId: item_id,
  7110. }
  7111. service.CreateOrderInfoTX(info, tx)
  7112. }
  7113. his.Diagnosis = diagnosis_id
  7114. his.SickType = sick_type
  7115. his.RegisterType = reg_type
  7116. his.MedicalTreatmentType = reg_type
  7117. service.UpdataHisPateintTX(&his, tx)
  7118. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7119. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7120. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7121. //判断是否使用了押金
  7122. if dec_way == "true" {
  7123. tmpstring := strconv.FormatInt(order.ID, 10)
  7124. //扣押金
  7125. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7126. order.Decimal = decimal
  7127. service.UpDateOrderTwo(order, tx)
  7128. if errmsg != nil {
  7129. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7130. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7131. return
  7132. }
  7133. }
  7134. if err == nil {
  7135. for _, info := range prescriptions {
  7136. if info.Type == 1 {
  7137. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7138. }
  7139. if info.Type == 2 {
  7140. for _, sumItem := range info.HisPrescriptionProject {
  7141. if sumItem.Type == 3 {
  7142. var good models.DialysisBeforePrepareGoods
  7143. var newGood models.NewDialysisBeforePrepareGoods
  7144. var oldGood models.OldDialysisBeforePrepareGoods
  7145. good.GoodId = sumItem.GoodInfo.ID
  7146. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7147. count, _ := strconv.Atoi(sumItem.Count)
  7148. good.Count = int64(count)
  7149. good.StorehouseId = houseConfig.StorehouseOutInfo
  7150. good.ProjectId = sumItem.ID
  7151. good.PatientId = sumItem.PatientId
  7152. goods = append(goods, &good)
  7153. newGood.GoodId = sumItem.GoodInfo.ID
  7154. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7155. count2, _ := strconv.Atoi(sumItem.Count)
  7156. newGood.Count = int64(count2)
  7157. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7158. newGood.ProjectId = sumItem.ID
  7159. newGood.PatientId = sumItem.HisPatientId
  7160. newGoods = append(newGoods, &newGood)
  7161. oldGood.GoodId = sumItem.GoodInfo.ID
  7162. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7163. count3, _ := strconv.Atoi(sumItem.Count)
  7164. oldGood.Count = int64(count3)
  7165. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  7166. oldGood.ProjectId = sumItem.ID
  7167. oldGood.RecordDate = sumItem.RecordDate
  7168. oldGood.PatientId = sumItem.HisPatientId
  7169. oldGoods = append(oldGoods, &oldGood)
  7170. }
  7171. }
  7172. }
  7173. }
  7174. if settConfig.IsOpen == 1 {
  7175. for _, item := range infoList {
  7176. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7177. if medical.IsUse == 2 {
  7178. //药品出库
  7179. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  7180. //查询默认仓库
  7181. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  7182. //查询默认仓库剩余多少库存
  7183. var sum_count int64
  7184. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7185. for _, its := range stockInfo {
  7186. if its.MaxUnit == medical.MaxUnit {
  7187. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7188. }
  7189. sum_count += its.StockMaxNumber + its.StockMinNumber
  7190. }
  7191. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7192. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7193. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  7194. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  7195. }
  7196. }
  7197. orgId := c.GetAdminUserInfo().CurrentOrgId
  7198. if len(oldGoods) > 0 {
  7199. timeStr := time.Now().Format("2006-01-02")
  7200. timeArr := strings.Split(timeStr, "-")
  7201. total, _ := service.FindAllWarehouseOut(orgId)
  7202. total = total + 1
  7203. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7204. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7205. number = number + total
  7206. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7207. operation_time := time.Now().Unix()
  7208. creater := c.GetAdminUserInfo().AdminUser.Id
  7209. //查询默认出库仓库库存
  7210. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7211. recordDateStr := time.Now().Format("2006-01-02")
  7212. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7213. nowtime := recordDate.Unix()
  7214. warehouseOut := models.WarehouseOut{
  7215. WarehouseOutOrderNumber: warehousing_out_order,
  7216. OperationTime: operation_time,
  7217. OrgId: orgId,
  7218. Creater: creater,
  7219. Ctime: time.Now().Unix(),
  7220. Status: 1,
  7221. WarehouseOutTime: nowtime,
  7222. Type: 1,
  7223. StorehouseId: storeConfig.StorehouseOutInfo,
  7224. IsCheck: 1,
  7225. OrderId: order.ID,
  7226. IsSys: 5,
  7227. }
  7228. //查询是否生成出库单
  7229. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7230. if out.ID == 0 {
  7231. service.AddSigleWarehouseOut(&warehouseOut)
  7232. }
  7233. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7234. for _, item := range oldGoods {
  7235. dialyPrepareOne := models.DialysisBeforePrepare{
  7236. GoodTypeId: item.GoodTypeId,
  7237. GoodId: item.GoodId,
  7238. PatientId: his.PatientId,
  7239. RecordDate: item.RecordDate,
  7240. UserOrgId: adminUser.CurrentOrgId,
  7241. Count: item.Count,
  7242. Ctime: time.Now().Unix(),
  7243. Creater: adminUser.AdminUser.Id,
  7244. CommdityCode: item.CommdityCode,
  7245. Status: 1,
  7246. StorehouseId: houseConfig.StorehouseOutInfo,
  7247. }
  7248. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  7249. //非零用
  7250. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  7251. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7252. //查询剩余库存
  7253. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7254. var sum_count int64
  7255. for _, item := range goodList {
  7256. sum_count += item.StockCount
  7257. }
  7258. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7259. //耗材
  7260. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7261. }
  7262. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  7263. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7264. //查询剩余库存
  7265. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7266. var sum_count int64
  7267. for _, item := range goodList {
  7268. sum_count += item.StockCount
  7269. }
  7270. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7271. //耗材
  7272. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7273. }
  7274. }
  7275. }
  7276. }
  7277. c.ServeSuccessJSON(map[string]interface{}{
  7278. "msg": "结算成功",
  7279. })
  7280. }
  7281. }
  7282. }
  7283. // 退款
  7284. func (c *HisApiController) Refund() {
  7285. order_id, _ := c.GetInt64("order_id")
  7286. order, _ := service.GetHisOrderByID(order_id)
  7287. adminUser := c.GetAdminUserInfo()
  7288. orgid := c.GetAdminUserInfo().CurrentOrgId
  7289. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  7290. if err != nil {
  7291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7292. return
  7293. }
  7294. tmp := strconv.FormatInt(order.ID, 10)
  7295. //当押金不为零时产生退费记录
  7296. if order.Decimal != 0 {
  7297. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  7298. if err != nil {
  7299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7300. return
  7301. }
  7302. }
  7303. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  7304. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  7305. var goods []*models.DialysisBeforePrepareGoods
  7306. var newGoods []*models.NewDialysisBeforePrepareGoods
  7307. var infos []*models.HisDoctorAdviceInfo
  7308. for _, info := range orders {
  7309. if info.AdviceId > 0 && info.ProjectId == 0 {
  7310. infos = append(infos, &info.HisDoctorAdviceInfo)
  7311. }
  7312. if info.ProjectId > 0 && info.AdviceId == 0 {
  7313. if info.HisPrescriptionProject.Type == 3 {
  7314. var good models.DialysisBeforePrepareGoods
  7315. var newGood models.NewDialysisBeforePrepareGoods
  7316. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7317. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7318. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7319. good.Count = int64(count)
  7320. good.StorehouseId = houseConfig.StorehouseOutInfo
  7321. good.ProjectId = info.HisPrescriptionProject.ID
  7322. good.PatientId = info.PatientId
  7323. good.OrderId = order_id
  7324. goods = append(goods, &good)
  7325. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7326. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7327. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7328. newGood.Count = int64(count2)
  7329. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7330. newGood.ProjectId = info.HisPrescriptionProject.ID
  7331. newGood.RecordDate = order.SettleAccountsDate
  7332. newGood.UserOrgId = order.UserOrgId
  7333. newGood.PatientId = info.PatientId
  7334. newGood.OrderId = order_id
  7335. newGoods = append(newGoods, &newGood)
  7336. }
  7337. }
  7338. }
  7339. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7340. if settConfig.IsOpen == 1 {
  7341. for _, item := range infos {
  7342. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7343. }
  7344. for _, item := range newGoods {
  7345. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7346. }
  7347. }
  7348. c.ServeSuccessJSON(map[string]interface{}{
  7349. "msg": "退费成功",
  7350. })
  7351. }
  7352. func (c *HisApiController) RefundNumber() {
  7353. his_patient_id, _ := c.GetInt64("id")
  7354. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7355. info.Status = 0
  7356. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  7357. if count > 0 {
  7358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  7359. return
  7360. }
  7361. err := service.SaveHisPatient(info)
  7362. if err == nil {
  7363. c.ServeSuccessJSON(map[string]interface{}{
  7364. "msg": "退号成功",
  7365. })
  7366. } else {
  7367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7368. return
  7369. }
  7370. }
  7371. func (this *HisApiController) AdditionalCharge() {
  7372. dataBody := make(map[string]interface{}, 0)
  7373. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7374. fmt.Println(err)
  7375. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  7376. patient_id := int64(dataBody["patient_id"].(float64))
  7377. medicineData, _ := dataBody["medicineData"].([]interface{})
  7378. adminUserInfo := this.GetAdminUserInfo()
  7379. orgId := adminUserInfo.CurrentOrgId
  7380. admin_user_id := adminUserInfo.AdminUser.Id
  7381. timeStr := time.Now().Format("2006-01-02")
  7382. timeLayout := "2006-01-02 15:04:05"
  7383. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  7384. timenow := timeStringToTime.Unix()
  7385. var additionalCharges []*models.HisAdditionalCharge
  7386. for _, item := range medicineData {
  7387. var randNum int
  7388. randNum = rand.Intn(10000) + 1000
  7389. timestamp := time.Now().Unix()
  7390. tempTime := time.Unix(timestamp, 0)
  7391. timeFormat := tempTime.Format("20060102150405")
  7392. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  7393. items := item.(map[string]interface{})
  7394. money := items["price"].(string)
  7395. item_id_str := items["item_id"].(string)
  7396. name := items["name"].(string)
  7397. id_str := items["id"].(string)
  7398. moneys, _ := strconv.ParseInt(money, 10, 64)
  7399. monStr := strconv.FormatInt(moneys, 10)
  7400. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  7401. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  7402. id, _ := strconv.ParseInt(id_str, 10, 64)
  7403. additionalCharge := &models.HisAdditionalCharge{
  7404. ID: id,
  7405. HisPatientId: his_patient_id,
  7406. UserOrgId: orgId,
  7407. PatientId: patient_id,
  7408. RecordDate: timenow,
  7409. Price: monneyStr,
  7410. Status: 1,
  7411. ItemName: name,
  7412. ItemId: item_id,
  7413. AdminUserId: admin_user_id,
  7414. CreatedTime: time.Now().Unix(),
  7415. OrderStatus: 0,
  7416. PrescriptionNumber: "",
  7417. BatchNumber: "",
  7418. FeedetlSn: p_number,
  7419. }
  7420. service.CreateAdditionalCharge(additionalCharge)
  7421. additionalCharges = append(additionalCharges, additionalCharge)
  7422. }
  7423. this.ServeSuccessJSON(map[string]interface{}{
  7424. "msg": "添加成功",
  7425. "additional_charges": additionalCharges,
  7426. })
  7427. }
  7428. func (this *HisApiController) DeleteAddition() {
  7429. id, _ := this.GetInt64("id")
  7430. //TODO 需要判断是否已经结算
  7431. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7432. if err == nil {
  7433. this.ServeSuccessJSON(map[string]interface{}{
  7434. "msg": "删除成功",
  7435. })
  7436. return
  7437. } else {
  7438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7439. return
  7440. }
  7441. }
  7442. func (this *HisApiController) GetAdminUsers() {
  7443. adminUser := this.GetAdminUserInfo()
  7444. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7445. this.ServeSuccessJSON(map[string]interface{}{
  7446. "doctors": doctors,
  7447. })
  7448. }
  7449. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7450. change_type, _ := this.GetInt64("type", 0)
  7451. record_date := this.GetString("record_time")
  7452. patient_id, _ := this.GetInt64("patient_id", 0)
  7453. p_type, _ := this.GetInt64("p_type", 0)
  7454. timeLayout := "2006-01-02"
  7455. loc, _ := time.LoadLocation("Local")
  7456. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7457. record_time := theAdviceRecordTime.Unix()
  7458. adminUserInfo := this.GetAdminUserInfo()
  7459. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7460. if err == nil {
  7461. if len(prescriptions) == 0 {
  7462. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7463. return
  7464. } else {
  7465. this.ServeSuccessJSON(map[string]interface{}{
  7466. "prescriptions": prescriptions,
  7467. })
  7468. return
  7469. }
  7470. } else {
  7471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7472. return
  7473. }
  7474. }
  7475. func (this *HisApiController) GetCallHisPrescription() {
  7476. patient_id, _ := this.GetInt64("patient_id", 0)
  7477. timeLayout := "2006-01-02"
  7478. loc, _ := time.LoadLocation("Local")
  7479. start_time := this.GetString("start_time")
  7480. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7481. end_time := this.GetString("end_time")
  7482. p_type, _ := this.GetInt64("p_type")
  7483. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7484. adminUserInfo := this.GetAdminUserInfo()
  7485. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7486. if err == nil {
  7487. this.ServeSuccessJSON(map[string]interface{}{
  7488. "prescriptions": prescriptions,
  7489. })
  7490. return
  7491. } else {
  7492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7493. return
  7494. }
  7495. }
  7496. func (this *HisApiController) GetHisDayPrescription() {
  7497. timeLayout := "2006-01-02"
  7498. loc, _ := time.LoadLocation("Local")
  7499. start_time := this.GetString("start_time")
  7500. patient_id, _ := this.GetInt64("patient_id", 0)
  7501. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7502. end_time := this.GetString("end_time")
  7503. p_type, _ := this.GetInt64("p_type")
  7504. order_status, _ := this.GetInt64("type")
  7505. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7506. adminUserInfo := this.GetAdminUserInfo()
  7507. var dayHisPrescription []*models.HisPrescription
  7508. var err error
  7509. if order_status == 1 || order_status == 0 {
  7510. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7511. } else if order_status == 2 {
  7512. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7513. }
  7514. var settle_total float64
  7515. for _, item := range dayHisPrescription {
  7516. if len(item.HisPrescriptionProject) > 0 {
  7517. for _, subItem := range item.HisPrescriptionProject {
  7518. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7519. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7520. settle_total = settle_total + total
  7521. }
  7522. }
  7523. if len(item.HisDoctorAdviceInfo) > 0 {
  7524. for _, subItem := range item.HisDoctorAdviceInfo {
  7525. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7526. settle_total = settle_total + total
  7527. }
  7528. }
  7529. }
  7530. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7531. if err == nil {
  7532. this.ServeSuccessJSON(map[string]interface{}{
  7533. "day_prescription": dayHisPrescription,
  7534. "settle_total": settle_total,
  7535. })
  7536. return
  7537. } else {
  7538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7539. return
  7540. }
  7541. }
  7542. func (c *HisApiController) GetHisChargePatientList() {
  7543. record_date := c.GetString("record_date")
  7544. order_status, _ := c.GetInt64("type")
  7545. sch_type, _ := c.GetInt64("sch_type")
  7546. timeLayout := "2006-01-02"
  7547. loc, _ := time.LoadLocation("Local")
  7548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7549. if err != nil {
  7550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7551. return
  7552. }
  7553. recordDateTime := theTime.Unix()
  7554. adminInfo := c.GetAdminUserInfo()
  7555. var tempPatients []*service.NewTempPatients
  7556. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7557. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7558. if order_status != 2 {
  7559. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7560. } else {
  7561. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7562. }
  7563. } else {
  7564. if order_status != 2 {
  7565. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7566. } else {
  7567. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7568. }
  7569. }
  7570. var patients []*service.NewTempPatients
  7571. var patients_two []*service.NewTempPatients
  7572. for _, item := range tempPatients {
  7573. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7574. //过滤掉没挂号的和没开处方的
  7575. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7576. patients = append(patients, item)
  7577. }
  7578. //过滤掉没挂号的
  7579. if len(item.HisPatient) > 0 {
  7580. patients_two = append(patients_two, item)
  7581. }
  7582. } else {
  7583. if len(item.HisPrescription) > 0 {
  7584. patients = append(patients, item)
  7585. }
  7586. }
  7587. }
  7588. c.ServeSuccessJSON(map[string]interface{}{
  7589. "list": patients,
  7590. "list_two": patients_two,
  7591. })
  7592. }
  7593. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7594. record_date := c.GetString("record_date")
  7595. timeLayout := "2006-01-02"
  7596. loc, _ := time.LoadLocation("Local")
  7597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7598. if err != nil {
  7599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7600. return
  7601. }
  7602. recordDateTime := theTime.Unix()
  7603. adminUser := c.GetAdminUserInfo()
  7604. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7605. var patients []*service.Patients
  7606. for _, item := range tempPatients {
  7607. if item.HisPatient.ID == 0 {
  7608. patients = append(patients, item)
  7609. }
  7610. }
  7611. c.ServeSuccessJSON(map[string]interface{}{
  7612. "list": patients,
  7613. //"list_two": patients_two,
  7614. })
  7615. }
  7616. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7617. newArr = make([]*service.Patients, 0)
  7618. for i := 0; i < len(patient); i++ {
  7619. repeat := false
  7620. for j := i + 1; j < len(patient); j++ {
  7621. if patient[i].ID == patient[j].ID {
  7622. repeat = true
  7623. break
  7624. }
  7625. }
  7626. if !repeat {
  7627. newArr = append(newArr, patient[i])
  7628. }
  7629. }
  7630. return
  7631. }
  7632. func (c *HisApiController) GetHisChargePatientInfo() {
  7633. patient_id, _ := c.GetInt64("patient_id")
  7634. his_patient_id, _ := c.GetInt64("his_patient_id")
  7635. record_date := c.GetString("record_date")
  7636. //start_time := c.GetString("start_time")
  7637. //end_time := c.GetString("end_time")
  7638. order_status, _ := c.GetInt64("type", 0)
  7639. p_type, _ := c.GetInt64("p_type", 0)
  7640. order_id, _ := c.GetInt64("order_id", 0)
  7641. timeLayout := "2006-01-02"
  7642. loc, _ := time.LoadLocation("Local")
  7643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7644. if err != nil {
  7645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7646. return
  7647. }
  7648. recordDateTime := theTime.Unix()
  7649. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7650. //if err != nil {
  7651. //
  7652. //}
  7653. //startRecordDateTime := startTime.Unix()
  7654. //
  7655. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7656. //if err != nil {
  7657. //
  7658. //}
  7659. //endRecordDateTime := endTime.Unix()
  7660. admin := c.GetAdminUserInfo()
  7661. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7662. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7663. var prescriptions []*models.HisPrescription
  7664. //var unChargeMonthPrescriptions []*models.HisPrescription
  7665. order, _ := service.GetHisOrderByID(order_id)
  7666. if order_status == 1 || order_status == 0 {
  7667. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7668. } else if order_status == 2 {
  7669. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7670. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7671. }
  7672. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7673. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7674. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7675. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7676. //获取所有科室信息
  7677. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7678. c.ServeSuccessJSON(map[string]interface{}{
  7679. "his_info": his_patient_info,
  7680. "xt_info": xt_patient_info,
  7681. "prescription": prescriptions,
  7682. "case_history": case_history,
  7683. "info": patientPrescriptionInfo,
  7684. "last_info": lastPatientPrescriptionInfo,
  7685. "order": order,
  7686. "doctors": doctors,
  7687. "department": department,
  7688. })
  7689. return
  7690. }
  7691. func (c *HisApiController) GetAllOrderDetail() {
  7692. order_id, _ := c.GetInt64("id", 0)
  7693. order, _ := service.GetHisOrderByID(order_id)
  7694. if order.ID == 0 {
  7695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7696. return
  7697. }
  7698. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7699. org_id := c.GetAdminUserInfo().CurrentOrgId
  7700. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7701. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7702. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7703. c.ServeSuccessJSON(map[string]interface{}{
  7704. "order": order,
  7705. "order_info": order_info,
  7706. "patient": patient,
  7707. "admin_info": adminInfo,
  7708. "hospital_record": record,
  7709. })
  7710. return
  7711. }
  7712. func (c *HisApiController) GetAllOrderDetailCollect() {
  7713. order_id, _ := c.GetInt64("id", 0)
  7714. order, _ := service.GetHisOrderByID(order_id)
  7715. if order.ID == 0 {
  7716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7717. return
  7718. }
  7719. org_id := c.GetAdminUserInfo().CurrentOrgId
  7720. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7721. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7722. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7723. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7724. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7725. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7726. var bedCostTotal float64 = 0 //床位总费
  7727. //var bedCostSelfTotal float64 = 0 //床位自费
  7728. var operationCostTotal float64 = 0 //手术费
  7729. //var operationCostSelfTotal float64 = 0 //手术费
  7730. var otherCostTotal float64 = 0 //其他费用
  7731. //var otherCostSelfTotal float64 = 0 //其他费用
  7732. var materialCostTotal float64 = 0 //材料费
  7733. //var materialCostSelfTotal float64 = 0 //材料费
  7734. var westernMedicineCostTotal float64 = 0 //西药费
  7735. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7736. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7737. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7738. var checkCostTotal float64 = 0 //检查费
  7739. //var checkCostSelfTotal float64 = 0 //检查费
  7740. var laboratoryCostTotal float64 = 0 //化验费
  7741. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7742. var treatCostTotal float64 = 0 //治疗费用
  7743. //var treatCostSelfTotal float64 = 0 //治疗费用
  7744. var zhenChaCostTotal float64 = 0 //其他费用
  7745. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7746. decimal.DivisionPrecision = 2
  7747. var BalanceAccountsType int64
  7748. if his.ID > 0 {
  7749. BalanceAccountsType = his.BalanceAccountsType
  7750. } else {
  7751. BalanceAccountsType = record.BalanceAccountsType
  7752. }
  7753. if BalanceAccountsType != 2 {
  7754. for _, item := range order_info {
  7755. if org_id == 10215 {
  7756. if item.MedChrgitmType == "01" { //床位费
  7757. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7758. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7759. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7760. }
  7761. if item.MedChrgitmType == "02" { //诊察费
  7762. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7763. //zhenChaCostSelfTotal = zhenChaCostTotal
  7764. }
  7765. if item.MedChrgitmType == "03" { //检查费
  7766. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7767. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7768. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7769. }
  7770. //if item.MedChrgitmType == "02" { //检查费
  7771. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7772. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7773. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7774. //}
  7775. if item.MedChrgitmType == "04" { //化验费
  7776. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7777. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7778. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7779. }
  7780. if item.MedChrgitmType == "05" { //治疗费
  7781. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7782. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7783. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7784. }
  7785. if item.MedChrgitmType == "06" { //手术费
  7786. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7787. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7788. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7789. }
  7790. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7791. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7792. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7793. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7794. }
  7795. if item.MedChrgitmType == "09" { //西药费
  7796. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7797. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7798. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7799. }
  7800. if item.MedChrgitmType == "11" { //中成费
  7801. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7802. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7803. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7804. }
  7805. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7806. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7807. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7808. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7809. }
  7810. } else if org_id == 10188 || org_id == 10217 {
  7811. if item.MedChrgitmType == "01" { //床位费
  7812. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7813. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7814. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7815. }
  7816. if item.MedChrgitmType == "02" { //诊察费
  7817. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7818. //zhenChaCostSelfTotal = zhenChaCostTotal
  7819. }
  7820. if item.MedChrgitmType == "03" { //检查费
  7821. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7822. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7823. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7824. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7825. }
  7826. //if item.MedChrgitmType == "02" { //检查费
  7827. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7828. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7829. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7830. //}
  7831. if item.MedChrgitmType == "04" { //化验费
  7832. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7833. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7834. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7835. }
  7836. if item.MedChrgitmType == "05" { //治疗费
  7837. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7838. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7839. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7840. }
  7841. if item.MedChrgitmType == "06" { //手术费
  7842. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7843. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7844. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7845. }
  7846. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7847. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7848. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7849. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7850. }
  7851. if item.MedChrgitmType == "09" { //西药费
  7852. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7853. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7854. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7855. }
  7856. if item.MedChrgitmType == "11" { //中成费
  7857. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7858. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7859. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7860. }
  7861. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7862. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7863. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7864. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7865. }
  7866. } else {
  7867. if item.MedChrgitmType == "01" { //床位费
  7868. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7869. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7870. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7871. }
  7872. //if item.MedChrgitmType == "02" { //诊察费
  7873. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7874. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7875. //}
  7876. if item.MedChrgitmType == "03" { //检查费
  7877. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7878. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7879. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7880. }
  7881. //if item.MedChrgitmType == "02" { //检查费
  7882. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7883. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7884. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7885. //}
  7886. if item.MedChrgitmType == "04" { //化验费
  7887. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7888. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7889. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7890. }
  7891. if item.MedChrgitmType == "05" { //治疗费
  7892. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7893. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7894. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7895. }
  7896. if item.MedChrgitmType == "06" { //手术费
  7897. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7898. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7899. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7900. }
  7901. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7902. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7903. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7904. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7905. }
  7906. if item.MedChrgitmType == "09" { //西药费
  7907. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7908. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7909. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7910. }
  7911. if item.MedChrgitmType == "11" { //中成费
  7912. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7913. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7914. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7915. }
  7916. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7917. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7918. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7919. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7920. }
  7921. }
  7922. }
  7923. c.ServeSuccessJSON(map[string]interface{}{
  7924. "order": order,
  7925. "order_info": order_info,
  7926. "patient": patient,
  7927. "admin_info": adminInfo,
  7928. "his_hospital": record,
  7929. "bedCostTotal": bedCostTotal,
  7930. "operationCostTotal": operationCostTotal,
  7931. "otherCostTotal": otherCostTotal,
  7932. "materialCostTotal": materialCostTotal,
  7933. "westernMedicineCostTotal": westernMedicineCostTotal,
  7934. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7935. "checkCostTotal": checkCostTotal,
  7936. "zhenChaCostTotal": zhenChaCostTotal,
  7937. "laboratoryCostTotal": laboratoryCostTotal,
  7938. "treatCostTotal": treatCostTotal,
  7939. })
  7940. } else {
  7941. for _, item := range order_info {
  7942. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7943. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7944. item.MedChrgitmType = "09"
  7945. }
  7946. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7947. if item.HisPrescriptionProject.Type == 2 {
  7948. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7949. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7950. case 0:
  7951. item.MedChrgitmType = "0"
  7952. break
  7953. case 1:
  7954. item.MedChrgitmType = "14"
  7955. break
  7956. case 2:
  7957. item.MedChrgitmType = "05"
  7958. break
  7959. case 3:
  7960. item.MedChrgitmType = "03"
  7961. break
  7962. case 4:
  7963. item.MedChrgitmType = "03"
  7964. break
  7965. case 5:
  7966. item.MedChrgitmType = "08"
  7967. break
  7968. case 6:
  7969. item.MedChrgitmType = "14"
  7970. break
  7971. case 7:
  7972. item.MedChrgitmType = "14"
  7973. break
  7974. case 8:
  7975. item.MedChrgitmType = "03"
  7976. break
  7977. case 9:
  7978. item.MedChrgitmType = "14"
  7979. break
  7980. case 10:
  7981. item.MedChrgitmType = "14"
  7982. break
  7983. case 11:
  7984. item.MedChrgitmType = "06"
  7985. break
  7986. case 12:
  7987. item.MedChrgitmType = "12"
  7988. break
  7989. case 13:
  7990. item.MedChrgitmType = "01"
  7991. break
  7992. case 14:
  7993. item.MedChrgitmType = "04"
  7994. break
  7995. case 15:
  7996. item.MedChrgitmType = "14"
  7997. break
  7998. }
  7999. } else {
  8000. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8001. case 1:
  8002. item.MedChrgitmType = "14"
  8003. break
  8004. case 2:
  8005. item.MedChrgitmType = "05"
  8006. break
  8007. case 3:
  8008. item.MedChrgitmType = "04"
  8009. break
  8010. case 4:
  8011. item.MedChrgitmType = "14"
  8012. break
  8013. case 5:
  8014. item.MedChrgitmType = "08"
  8015. break
  8016. case 6:
  8017. item.MedChrgitmType = "14"
  8018. break
  8019. case 7:
  8020. item.MedChrgitmType = "14"
  8021. break
  8022. case 8:
  8023. item.MedChrgitmType = "03"
  8024. break
  8025. case 9:
  8026. item.MedChrgitmType = "14"
  8027. break
  8028. }
  8029. }
  8030. } else if item.HisPrescriptionProject.Type == 3 {
  8031. item.MedChrgitmType = "08"
  8032. }
  8033. }
  8034. }
  8035. for _, item := range order_info {
  8036. if org_id == 10215 {
  8037. if item.MedChrgitmType == "01" { //床位费
  8038. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8039. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8040. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8041. }
  8042. if item.MedChrgitmType == "02" { //诊察费
  8043. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8044. //zhenChaCostSelfTotal = zhenChaCostTotal
  8045. }
  8046. if item.MedChrgitmType == "03" { //检查费
  8047. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8048. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8049. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8050. }
  8051. //if item.MedChrgitmType == "02" { //检查费
  8052. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8053. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8054. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8055. //}
  8056. if item.MedChrgitmType == "04" { //化验费
  8057. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8058. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8059. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8060. }
  8061. if item.MedChrgitmType == "05" { //治疗费
  8062. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8063. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8064. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8065. }
  8066. if item.MedChrgitmType == "06" { //手术费
  8067. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8068. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8069. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8070. }
  8071. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8072. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8073. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8074. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8075. }
  8076. if item.MedChrgitmType == "09" { //西药费
  8077. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8078. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8079. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8080. }
  8081. if item.MedChrgitmType == "11" { //中成费
  8082. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8083. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8084. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8085. }
  8086. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8087. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8088. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8089. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8090. }
  8091. } else {
  8092. if item.MedChrgitmType == "01" { //床位费
  8093. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8094. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8095. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8096. }
  8097. //if item.MedChrgitmType == "02" { //诊察费
  8098. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8099. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8100. //}
  8101. if item.MedChrgitmType == "03" { //检查费
  8102. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8103. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8104. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8105. }
  8106. //if item.MedChrgitmType == "02" { //检查费
  8107. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8108. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8109. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8110. //}
  8111. if item.MedChrgitmType == "04" { //化验费
  8112. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8113. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8114. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8115. }
  8116. if item.MedChrgitmType == "05" { //治疗费
  8117. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8118. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8119. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8120. }
  8121. if item.MedChrgitmType == "06" { //手术费
  8122. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8123. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8124. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8125. }
  8126. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8127. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8128. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8129. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8130. }
  8131. if item.MedChrgitmType == "09" { //西药费
  8132. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8133. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8134. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8135. }
  8136. if item.MedChrgitmType == "11" { //中成费
  8137. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8138. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8139. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8140. }
  8141. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8142. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8143. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8144. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8145. }
  8146. }
  8147. }
  8148. c.ServeSuccessJSON(map[string]interface{}{
  8149. "order": order,
  8150. "order_info": order_info,
  8151. "patient": patient,
  8152. "admin_info": adminInfo,
  8153. "his_hospital": record,
  8154. "bedCostTotal": bedCostTotal,
  8155. "operationCostTotal": operationCostTotal,
  8156. "otherCostTotal": otherCostTotal,
  8157. "materialCostTotal": materialCostTotal,
  8158. "westernMedicineCostTotal": westernMedicineCostTotal,
  8159. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8160. "checkCostTotal": checkCostTotal,
  8161. "zhenChaCostTotal": zhenChaCostTotal,
  8162. "laboratoryCostTotal": laboratoryCostTotal,
  8163. "treatCostTotal": treatCostTotal,
  8164. })
  8165. }
  8166. }
  8167. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  8168. page, _ := c.GetInt64("page")
  8169. limit, _ := c.GetInt64("limit")
  8170. keywords := c.GetString("keywords")
  8171. start_time := c.GetString("start_time")
  8172. end_time := c.GetString("end_time")
  8173. //clr_type := c.GetString("clr_type")
  8174. insutype := c.GetString("insutype")
  8175. timeLayout := "2006-01-02"
  8176. loc, _ := time.LoadLocation("Local")
  8177. var theStartTIme int64
  8178. if len(start_time) > 0 {
  8179. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8180. theStartTIme = theTime.Unix()
  8181. }
  8182. var theEndtTIme int64
  8183. if len(end_time) > 0 {
  8184. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8185. theEndtTIme = theTime.Unix()
  8186. }
  8187. if page <= 0 {
  8188. page = 1
  8189. }
  8190. if limit <= 0 {
  8191. limit = 10
  8192. }
  8193. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  8194. c.ServeSuccessJSON(map[string]interface{}{
  8195. "total": total,
  8196. "list": list,
  8197. })
  8198. return
  8199. }
  8200. func (c *HisApiController) GetPutOnRecordList() {
  8201. page, _ := c.GetInt64("page")
  8202. limit, _ := c.GetInt64("limit")
  8203. keywords := c.GetString("keywords")
  8204. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  8205. if page <= 0 {
  8206. page = 1
  8207. }
  8208. if limit <= 0 {
  8209. limit = 10
  8210. }
  8211. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  8212. c.ServeSuccessJSON(map[string]interface{}{
  8213. "total": total,
  8214. "list": list,
  8215. })
  8216. return
  8217. }
  8218. func (c *HisApiController) GetCompareData() {
  8219. start_time := c.GetString("start_time")
  8220. end_time := c.GetString("end_time")
  8221. insutype := c.GetString("insutype")
  8222. clr_type := c.GetString("clr_type")
  8223. timeLayout := "2006-01-02"
  8224. loc, _ := time.LoadLocation("Local")
  8225. var theStartTIme int64
  8226. if len(start_time) > 0 {
  8227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8228. if err != nil {
  8229. theStartTIme = 0
  8230. }
  8231. theStartTIme = theTime.Unix()
  8232. }
  8233. var theEndtTIme int64
  8234. if len(end_time) > 0 {
  8235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8236. if err != nil {
  8237. theEndtTIme = 0
  8238. }
  8239. theEndtTIme = theTime.Unix()
  8240. }
  8241. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  8242. fmt.Println(err)
  8243. if err == nil {
  8244. c.ServeSuccessJSON(map[string]interface{}{
  8245. "list": formData,
  8246. })
  8247. } else {
  8248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8249. return
  8250. }
  8251. }
  8252. func (c *HisApiController) GetFaPiaoData() {
  8253. order_id, _ := c.GetInt64("order_id")
  8254. patient_id, _ := c.GetInt64("patient_id")
  8255. //number := c.GetString("number")
  8256. adminUser := c.GetAdminUserInfo()
  8257. order, _ := service.GetHisOrderByID(order_id)
  8258. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8259. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8260. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8261. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8262. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  8263. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  8264. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8265. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8266. var bedCostTotal float64 = 0 //床位总费
  8267. var bedCostSelfTotal float64 = 0 //床位自费
  8268. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8269. var operationCostTotal float64 = 0 //手术费
  8270. var operationCostSelfTotal float64 = 0 //手术费
  8271. var operationCostPartSelfTotal float64 = 0 //手术费
  8272. var otherCostTotal float64 = 0 //其他费用
  8273. var otherCostSelfTotal float64 = 0 //其他费用
  8274. var otherCostPartSelfTotal float64 = 0 //其他费用
  8275. var materialCostTotal float64 = 0 //材料费
  8276. var materialCostSelfTotal float64 = 0 //材料费
  8277. var materialCostPartSelfTotal float64 = 0 //材料费
  8278. var westernMedicineCostTotal float64 = 0 //西药费
  8279. var westernMedicineCostSelfTotal float64 = 0 //西药费
  8280. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8281. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8282. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8283. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8284. var checkCostTotal float64 = 0 //检查费
  8285. var checkCostSelfTotal float64 = 0 //检查费
  8286. var checkCostPartSelfTotal float64 = 0 //检查费
  8287. var hiliCostTotal float64 = 0 //护理费
  8288. var hiliCostSelfTotal float64 = 0 //护理费
  8289. var hiliCostPartSelfTotal float64 = 0 //护理费
  8290. var laboratoryCostTotal float64 = 0 //化验费
  8291. var laboratoryCostSelfTotal float64 = 0 //化验费
  8292. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8293. var treatCostTotal float64 = 0 //治疗费用
  8294. var treatCostSelfTotal float64 = 0 //治疗费用
  8295. var treatCostPartSelfTotal float64 = 0 //治疗费用
  8296. var zhenChaCostTotal float64 = 0 //其他费用
  8297. var zhenChaCostSelfTotal float64 = 0 //其他费用
  8298. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8299. decimal.DivisionPrecision = 2
  8300. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8301. var balanceAccountsType int64
  8302. if his.ID > 0 {
  8303. balanceAccountsType = his.BalanceAccountsType
  8304. } else {
  8305. balanceAccountsType = his_hospital_record.BalanceAccountsType
  8306. }
  8307. if balanceAccountsType == 2 {
  8308. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8309. for _, item := range orderInfos_two {
  8310. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8311. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8312. item.MedChrgitmType = "09"
  8313. }
  8314. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8315. if item.HisPrescriptionProject.Type == 2 {
  8316. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8317. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8318. case 0:
  8319. item.MedChrgitmType = "0"
  8320. break
  8321. case 1:
  8322. item.MedChrgitmType = "14"
  8323. break
  8324. case 2:
  8325. item.MedChrgitmType = "05"
  8326. break
  8327. case 3:
  8328. item.MedChrgitmType = "03"
  8329. break
  8330. case 4:
  8331. item.MedChrgitmType = "03"
  8332. break
  8333. case 5:
  8334. item.MedChrgitmType = "08"
  8335. break
  8336. case 6:
  8337. item.MedChrgitmType = "14"
  8338. break
  8339. case 7:
  8340. item.MedChrgitmType = "14"
  8341. break
  8342. case 8:
  8343. item.MedChrgitmType = "03"
  8344. break
  8345. case 9:
  8346. item.MedChrgitmType = "14"
  8347. break
  8348. case 10:
  8349. item.MedChrgitmType = "14"
  8350. break
  8351. case 11:
  8352. item.MedChrgitmType = "06"
  8353. break
  8354. case 12:
  8355. item.MedChrgitmType = "12"
  8356. break
  8357. case 13:
  8358. item.MedChrgitmType = "01"
  8359. break
  8360. case 14:
  8361. item.MedChrgitmType = "04"
  8362. break
  8363. case 15:
  8364. item.MedChrgitmType = "02"
  8365. break
  8366. }
  8367. } else {
  8368. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8369. case 1:
  8370. item.MedChrgitmType = "14"
  8371. break
  8372. case 2:
  8373. item.MedChrgitmType = "05"
  8374. break
  8375. case 3:
  8376. item.MedChrgitmType = "03"
  8377. break
  8378. case 4:
  8379. item.MedChrgitmType = "03"
  8380. break
  8381. case 5:
  8382. item.MedChrgitmType = "08"
  8383. break
  8384. case 6:
  8385. item.MedChrgitmType = "14"
  8386. break
  8387. case 7:
  8388. item.MedChrgitmType = "14"
  8389. break
  8390. case 8:
  8391. item.MedChrgitmType = "03"
  8392. break
  8393. case 9:
  8394. item.MedChrgitmType = "14"
  8395. break
  8396. }
  8397. }
  8398. } else if item.HisPrescriptionProject.Type == 3 {
  8399. item.MedChrgitmType = "08"
  8400. }
  8401. }
  8402. }
  8403. for _, item := range orderInfos_two {
  8404. fmt.Println(item.MedChrgitmType)
  8405. if item.MedChrgitmType == "07" { //床位费
  8406. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8407. hiliCostSelfTotal = hiliCostTotal
  8408. }
  8409. if item.MedChrgitmType == "01" { //床位费
  8410. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8411. bedCostSelfTotal = bedCostTotal
  8412. }
  8413. if item.MedChrgitmType == "02" { //诊察费
  8414. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8415. zhenChaCostSelfTotal = zhenChaCostTotal
  8416. }
  8417. if item.MedChrgitmType == "03" { //检查费
  8418. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8419. checkCostSelfTotal = checkCostTotal
  8420. }
  8421. if item.MedChrgitmType == "04" { //化验费
  8422. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8423. laboratoryCostSelfTotal = laboratoryCostTotal
  8424. }
  8425. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8426. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8427. treatCostSelfTotal = treatCostTotal
  8428. }
  8429. if item.MedChrgitmType == "06" { //手术费
  8430. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8431. operationCostSelfTotal = treatCostTotal
  8432. }
  8433. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8434. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8435. materialCostSelfTotal = materialCostTotal
  8436. }
  8437. if item.MedChrgitmType == "09" { //西药费
  8438. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8439. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8440. }
  8441. if item.MedChrgitmType == "11" { //中成费
  8442. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8443. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8444. }
  8445. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8446. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8447. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8448. otherCostSelfTotal = otherCostTotal
  8449. }
  8450. } else {
  8451. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8452. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8453. otherCostSelfTotal = otherCostTotal
  8454. }
  8455. }
  8456. }
  8457. } else {
  8458. for _, item := range orderInfos {
  8459. if item.MedChrgitmType == "01" { //床位费
  8460. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8461. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8462. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8463. }
  8464. if item.MedChrgitmType == "02" { //诊察费
  8465. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8466. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8467. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8468. }
  8469. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8470. if item.MedChrgitmType == "03" { //检查费
  8471. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8472. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8473. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8474. }
  8475. } else {
  8476. if item.MedChrgitmType == "03" { //检查费
  8477. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8478. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8479. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8480. }
  8481. }
  8482. if item.MedChrgitmType == "04" { //化验费
  8483. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8484. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8485. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8486. }
  8487. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8488. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8489. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8490. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8491. }
  8492. if item.MedChrgitmType == "06" { //手术费
  8493. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8494. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8495. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8496. }
  8497. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8498. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8499. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8500. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8501. }
  8502. if item.MedChrgitmType == "07" { //西药费
  8503. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8504. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8505. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8506. }
  8507. if item.MedChrgitmType == "09" { //西药费
  8508. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8509. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8510. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8511. }
  8512. if item.MedChrgitmType == "11" { //中成费
  8513. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8514. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8515. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8516. }
  8517. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8518. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8519. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8520. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8521. }
  8522. }
  8523. }
  8524. timeLayout := "2006-01-02"
  8525. loc, _ := time.LoadLocation("Local")
  8526. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8527. if err != nil {
  8528. }
  8529. startRecordDateTime := startTime.Unix()
  8530. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8531. if err != nil {
  8532. }
  8533. endRecordDateTime := endTime.Unix()
  8534. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8535. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8536. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8537. c.ServeSuccessJSON(map[string]interface{}{
  8538. "order_number": order.Number, //业务流水号
  8539. "id_card_no": his.IdCardNo, //社会保障号
  8540. "patient": patient,
  8541. "department_name": department.Name, //科室
  8542. "number": his.Number, //门诊号
  8543. "date": order.SettleAccountsDate, //结算日期
  8544. "name": order.PsnName, //姓名
  8545. "gender": patient.Gender, //性别
  8546. "psn_cash_money": order.PsnCashPay, //个人支付
  8547. "pay_way": "门诊", //结算方式
  8548. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8549. "admin_user_name": admin.UserName, //收款员
  8550. "order": order,
  8551. "order_info": orderInfos_two,
  8552. "his": his,
  8553. "bedCostTotal": bedCostTotal,
  8554. "bedCostSelfTotal": bedCostSelfTotal,
  8555. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8556. "operationCostTotal": operationCostTotal,
  8557. "operationCostSelfTotal": operationCostSelfTotal,
  8558. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8559. "otherCostTotal": otherCostTotal,
  8560. "otherCostSelfTotal": otherCostSelfTotal,
  8561. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8562. "materialCostTotal": materialCostTotal,
  8563. "materialCostSelfTotal": materialCostSelfTotal,
  8564. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8565. "westernMedicineCostTotal": westernMedicineCostTotal,
  8566. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8567. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8568. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8569. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8570. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8571. "checkCostTotal": checkCostTotal,
  8572. "checkCostSelfTotal": checkCostSelfTotal,
  8573. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8574. "laboratoryCostTotal": laboratoryCostTotal,
  8575. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8576. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8577. "treatCostTotal": treatCostTotal,
  8578. "treatCostSelfTotal": treatCostSelfTotal,
  8579. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8580. "zhenChaCostTotal": zhenChaCostTotal,
  8581. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8582. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8583. "his_hospital_record": his_hospital_record,
  8584. "pre_pay_money": pre_pay_money,
  8585. "refund_sum": sum,
  8586. "doctor_info": doctor_info,
  8587. "hiliCostTotal": hiliCostTotal,
  8588. "hiliCostSelfTotal": hiliCostSelfTotal,
  8589. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8590. })
  8591. }
  8592. //func (c *HisApiController) GetFaPiaoDatas() {
  8593. // order_ids := c.GetString("order_ids")
  8594. // patient_id, _ := c.GetInt64("patient_id")
  8595. // adminUser := c.GetAdminUserInfo()
  8596. //
  8597. // orders := strings.Split(order_ids, ",")
  8598. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8599. //
  8600. // for _, item := range orders {
  8601. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8602. // order, _ := service.GetHisOrderByID(order_id)
  8603. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8604. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8605. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8606. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8607. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8608. //
  8609. // }
  8610. //
  8611. // var bedCostTotal float64 = 0 //床位总费
  8612. // var bedCostSelfTotal float64 = 0 //床位自费
  8613. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8614. //
  8615. // var operationCostTotal float64 = 0 //手术费
  8616. // var operationCostSelfTotal float64 = 0 //手术费
  8617. // var operationCostPartSelfTotal float64 = 0 //手术费
  8618. //
  8619. // var otherCostTotal float64 = 0 //其他费用
  8620. // var otherCostSelfTotal float64 = 0 //其他费用
  8621. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8622. //
  8623. // var materialCostTotal float64 = 0 //材料费
  8624. // var materialCostSelfTotal float64 = 0 //材料费
  8625. // var materialCostPartSelfTotal float64 = 0 //材料费
  8626. //
  8627. // var westernMedicineCostTotal float64 = 0 //西药费
  8628. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8629. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8630. //
  8631. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8632. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8633. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8634. //
  8635. // var checkCostTotal float64 = 0 //检查费
  8636. // var checkCostSelfTotal float64 = 0 //检查费
  8637. // var checkCostPartSelfTotal float64 = 0 //检查费
  8638. //
  8639. // var laboratoryCostTotal float64 = 0 //化验费
  8640. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8641. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8642. //
  8643. // var treatCostTotal float64 = 0 //治疗费用
  8644. // var treatCostSelfTotal float64 = 0 //治疗费用
  8645. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8646. //
  8647. // var zhenChaCostTotal float64 = 0 //其他费用
  8648. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8649. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8650. //
  8651. // decimal.DivisionPrecision = 2
  8652. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8653. //
  8654. // var balanceAccountsType int64
  8655. // if his.ID > 0 {
  8656. // balanceAccountsType = his.BalanceAccountsType
  8657. // } else {
  8658. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8659. // }
  8660. // if balanceAccountsType == 2 {
  8661. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8662. // for _, item := range orderInfos_two {
  8663. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8664. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8665. // item.MedChrgitmType = "09"
  8666. // }
  8667. //
  8668. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8669. // if item.HisPrescriptionProject.Type == 2 {
  8670. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8671. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8672. // case 0:
  8673. // item.MedChrgitmType = "0"
  8674. // break
  8675. // case 1:
  8676. // item.MedChrgitmType = "14"
  8677. // break
  8678. // case 2:
  8679. // item.MedChrgitmType = "05"
  8680. //
  8681. // break
  8682. // case 3:
  8683. // item.MedChrgitmType = "03"
  8684. //
  8685. // break
  8686. // case 4:
  8687. // item.MedChrgitmType = "03"
  8688. //
  8689. // break
  8690. // case 5:
  8691. // item.MedChrgitmType = "08"
  8692. //
  8693. // break
  8694. // case 6:
  8695. // item.MedChrgitmType = "14"
  8696. //
  8697. // break
  8698. // case 7:
  8699. // item.MedChrgitmType = "14"
  8700. //
  8701. // break
  8702. // case 8:
  8703. // item.MedChrgitmType = "03"
  8704. // break
  8705. // case 9:
  8706. // item.MedChrgitmType = "14"
  8707. // break
  8708. // case 10:
  8709. // item.MedChrgitmType = "14"
  8710. // break
  8711. // case 11:
  8712. // item.MedChrgitmType = "06"
  8713. // break
  8714. // case 12:
  8715. // item.MedChrgitmType = "12"
  8716. // break
  8717. // case 13:
  8718. // item.MedChrgitmType = "01"
  8719. // break
  8720. // case 14:
  8721. // item.MedChrgitmType = "04"
  8722. // break
  8723. // case 15:
  8724. // item.MedChrgitmType = "02"
  8725. // break
  8726. //
  8727. // }
  8728. //
  8729. // } else {
  8730. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8731. //
  8732. // case 1:
  8733. // item.MedChrgitmType = "14"
  8734. // break
  8735. // case 2:
  8736. // item.MedChrgitmType = "05"
  8737. //
  8738. // break
  8739. // case 3:
  8740. // item.MedChrgitmType = "03"
  8741. //
  8742. // break
  8743. // case 4:
  8744. // item.MedChrgitmType = "03"
  8745. //
  8746. // break
  8747. // case 5:
  8748. // item.MedChrgitmType = "08"
  8749. //
  8750. // break
  8751. // case 6:
  8752. // item.MedChrgitmType = "14"
  8753. //
  8754. // break
  8755. // case 7:
  8756. // item.MedChrgitmType = "14"
  8757. //
  8758. // break
  8759. // case 8:
  8760. // item.MedChrgitmType = "03"
  8761. // break
  8762. // case 9:
  8763. // item.MedChrgitmType = "14"
  8764. // break
  8765. //
  8766. // }
  8767. //
  8768. // }
  8769. //
  8770. // } else if item.HisPrescriptionProject.Type == 3 {
  8771. // item.MedChrgitmType = "08"
  8772. // }
  8773. // }
  8774. // }
  8775. //
  8776. // for _, item := range orderInfos_two {
  8777. // fmt.Println(item.MedChrgitmType)
  8778. // if item.MedChrgitmType == "01" { //床位费
  8779. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8780. // bedCostSelfTotal = bedCostTotal
  8781. // }
  8782. //
  8783. // if item.MedChrgitmType == "02" { //诊察费
  8784. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8785. // zhenChaCostSelfTotal = zhenChaCostTotal
  8786. // }
  8787. //
  8788. // if item.MedChrgitmType == "03" { //检查费
  8789. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8790. // checkCostSelfTotal = checkCostTotal
  8791. // }
  8792. //
  8793. // if item.MedChrgitmType == "04" { //化验费
  8794. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. // laboratoryCostSelfTotal = laboratoryCostTotal
  8796. // }
  8797. //
  8798. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8799. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8800. // treatCostSelfTotal = treatCostTotal
  8801. // }
  8802. //
  8803. // if item.MedChrgitmType == "06" { //手术费
  8804. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8805. // operationCostSelfTotal = treatCostTotal
  8806. // }
  8807. //
  8808. // if item.MedChrgitmType == "08" { //材料费
  8809. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8810. // materialCostSelfTotal = materialCostTotal
  8811. // }
  8812. //
  8813. // if item.MedChrgitmType == "09" { //西药费
  8814. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8815. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8816. // }
  8817. //
  8818. // if item.MedChrgitmType == "11" { //中成费
  8819. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8820. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8821. // }
  8822. //
  8823. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8824. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8825. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8826. // otherCostSelfTotal = otherCostTotal
  8827. // }
  8828. // } else {
  8829. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8830. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8831. // otherCostSelfTotal = otherCostTotal
  8832. // }
  8833. //
  8834. // }
  8835. //
  8836. // }
  8837. //
  8838. // } else {
  8839. // for _, item := range orderInfos {
  8840. // if item.MedChrgitmType == "01" { //床位费
  8841. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8842. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8843. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8844. // }
  8845. //
  8846. // if item.MedChrgitmType == "02" { //诊察费
  8847. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8848. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8849. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8850. // }
  8851. //
  8852. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8853. // if item.MedChrgitmType == "03" { //检查费
  8854. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8856. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8857. //
  8858. // }
  8859. // } else {
  8860. // if item.MedChrgitmType == "03" { //检查费
  8861. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8862. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8863. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8864. // }
  8865. //
  8866. // }
  8867. //
  8868. // if item.MedChrgitmType == "04" { //化验费
  8869. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8870. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8871. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8872. //
  8873. // }
  8874. //
  8875. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8876. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8877. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8878. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8879. //
  8880. // }
  8881. //
  8882. // if item.MedChrgitmType == "06" { //手术费
  8883. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8884. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8885. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8886. // }
  8887. //
  8888. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8889. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8890. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8891. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8892. // }
  8893. //
  8894. // if item.MedChrgitmType == "09" { //西药费
  8895. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8896. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8897. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8898. // }
  8899. //
  8900. // if item.MedChrgitmType == "11" { //中成费
  8901. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8902. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8903. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8904. // }
  8905. //
  8906. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8907. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8908. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8909. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8910. // }
  8911. //
  8912. // }
  8913. // }
  8914. // timeLayout := "2006-01-02"
  8915. // loc, _ := time.LoadLocation("Local")
  8916. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8917. // if err != nil {
  8918. // }
  8919. // startRecordDateTime := startTime.Unix()
  8920. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8921. // if err != nil {
  8922. // }
  8923. // endRecordDateTime := endTime.Unix()
  8924. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8925. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8926. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8927. //
  8928. // c.ServeSuccessJSON(map[string]interface{}{
  8929. // "order_number": order.Number, //业务流水号
  8930. // "id_card_no": his.IdCardNo, //社会保障号
  8931. // "department_name": department.Name, //科室
  8932. // "number": his.Number, //门诊号
  8933. // "date": order.SettleAccountsDate, //结算日期
  8934. // "name": order.PsnName, //姓名
  8935. // "gender": patient.Gender, //性别
  8936. // "psn_cash_money": order.PsnCashPay, //个人支付
  8937. // "pay_way": "门诊", //结算方式
  8938. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8939. // "admin_user_name": admin.UserName, //收款员
  8940. // "order": order,
  8941. // "order_info": orderInfos_two,
  8942. // "his": his,
  8943. // "bedCostTotal": bedCostTotal,
  8944. // "bedCostSelfTotal": bedCostSelfTotal,
  8945. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8946. // "operationCostTotal": operationCostTotal,
  8947. // "operationCostSelfTotal": operationCostSelfTotal,
  8948. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8949. // "otherCostTotal": otherCostTotal,
  8950. // "otherCostSelfTotal": otherCostSelfTotal,
  8951. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8952. // "materialCostTotal": materialCostTotal,
  8953. // "materialCostSelfTotal": materialCostSelfTotal,
  8954. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8955. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8956. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8957. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8958. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8959. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8960. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8961. // "checkCostTotal": checkCostTotal,
  8962. // "checkCostSelfTotal": checkCostSelfTotal,
  8963. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8964. // "laboratoryCostTotal": laboratoryCostTotal,
  8965. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8966. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8967. // "treatCostTotal": treatCostTotal,
  8968. // "treatCostSelfTotal": treatCostSelfTotal,
  8969. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8970. // "zhenChaCostTotal": zhenChaCostTotal,
  8971. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8972. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8973. // "his_hospital_record": his_hospital_record,
  8974. // "pre_pay_money": pre_pay_money,
  8975. // "refund_sum": sum,
  8976. // })
  8977. //
  8978. //}
  8979. func (this *HisApiController) GetIncomeStatisticsData() {
  8980. start_time := this.GetString("start_time")
  8981. end_time := this.GetString("end_time")
  8982. key_words := this.GetString("key_words")
  8983. limit, _ := this.GetInt64("limit")
  8984. page, _ := this.GetInt64("page")
  8985. if page <= 0 {
  8986. page = 1
  8987. }
  8988. if limit <= 0 {
  8989. limit = 10
  8990. }
  8991. statistics_type, _ := this.GetInt64("statistics_type")
  8992. admin := this.GetAdminUserInfo()
  8993. timeLayout := "2006-01-02"
  8994. loc, _ := time.LoadLocation("Local")
  8995. var theStartTIme int64
  8996. if len(start_time) > 0 {
  8997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8998. if err != nil {
  8999. theStartTIme = 0
  9000. }
  9001. theStartTIme = theTime.Unix()
  9002. }
  9003. var theEndtTIme int64
  9004. if len(end_time) > 0 {
  9005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9006. if err != nil {
  9007. theEndtTIme = 0
  9008. }
  9009. theEndtTIme = theTime.Unix()
  9010. }
  9011. if statistics_type == 1 {
  9012. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9013. this.ServeSuccessJSON(map[string]interface{}{
  9014. "list": list,
  9015. "total": total,
  9016. })
  9017. } else {
  9018. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9019. this.ServeSuccessJSON(map[string]interface{}{
  9020. "list": list,
  9021. "total": total,
  9022. })
  9023. }
  9024. }
  9025. func (c *HisApiController) PostProjectInformation() {
  9026. adminUser := c.GetAdminUserInfo()
  9027. orgId := adminUser.CurrentOrgId
  9028. dataBody := make(map[string]interface{}, 0)
  9029. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9030. if err != nil {
  9031. utils.ErrorLog(err.Error())
  9032. return
  9033. }
  9034. utils.ErrorLog("%v", dataBody)
  9035. var projectList []*models.HisProject
  9036. var total_goods []interface{}
  9037. tempProjects := dataBody["projects"].([]interface{})
  9038. total_goods = tempProjects
  9039. for index, projectMap := range tempProjects {
  9040. projectM := projectMap.(map[string]interface{})
  9041. var project models.HisProject
  9042. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9043. utils.ErrorLog("project_name")
  9044. return
  9045. }
  9046. project_name, _ := projectM["project_name"].(string)
  9047. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9048. err_log := models.ExportErrLog{
  9049. LogType: 6,
  9050. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9051. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9052. Status: 1,
  9053. CreateTime: time.Now().Unix(),
  9054. UpdateTime: time.Now().Unix(),
  9055. ExportTime: time.Now().Unix(),
  9056. }
  9057. service.CreateExportErrLog(&err_log)
  9058. continue
  9059. }
  9060. project.ProjectName = project_name
  9061. prices := projectM["price"].(string)
  9062. price, _ := strconv.ParseFloat(prices, 64)
  9063. if price <= 0 { //名字为空则生成一条导入错误日志
  9064. err_log := models.ExportErrLog{
  9065. LogType: 6,
  9066. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9067. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9068. Status: 1,
  9069. CreateTime: time.Now().Unix(),
  9070. UpdateTime: time.Now().Unix(),
  9071. ExportTime: time.Now().Unix(),
  9072. }
  9073. service.CreateExportErrLog(&err_log)
  9074. continue
  9075. }
  9076. project.Price = price
  9077. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9078. utils.ErrorLog("unit_id")
  9079. return
  9080. }
  9081. unit := projectM["unit"].(string)
  9082. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9083. err_log := models.ExportErrLog{
  9084. LogType: 6,
  9085. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9086. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9087. Status: 1,
  9088. CreateTime: time.Now().Unix(),
  9089. UpdateTime: time.Now().Unix(),
  9090. ExportTime: time.Now().Unix(),
  9091. }
  9092. service.CreateExportErrLog(&err_log)
  9093. continue
  9094. }
  9095. project.Unit = unit
  9096. cost_classify := projectM["cost_classify"].(string)
  9097. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9098. err_log := models.ExportErrLog{
  9099. LogType: 6,
  9100. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9101. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9102. Status: 1,
  9103. CreateTime: time.Now().Unix(),
  9104. UpdateTime: time.Now().Unix(),
  9105. ExportTime: time.Now().Unix(),
  9106. }
  9107. service.CreateExportErrLog(&err_log)
  9108. continue
  9109. }
  9110. var costClassify = "费用类别"
  9111. var cost_classify_id int64
  9112. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9113. if len(cost_classify) != 0 {
  9114. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9115. if errcode == gorm.ErrRecordNotFound {
  9116. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9117. dataconfig := models.DictDataconfig{
  9118. ParentId: costClassifyConfig.ID,
  9119. Module: "system",
  9120. OrgId: orgId,
  9121. Name: cost_classify,
  9122. FieldName: "",
  9123. Value: costConfig.Value + 1,
  9124. CreatedTime: "",
  9125. UpdatedTime: "",
  9126. CreateUserId: adminUser.AdminUser.Id,
  9127. Status: 1,
  9128. Remark: "",
  9129. DeleteIdSystem: 0,
  9130. Title: "",
  9131. Content: "",
  9132. Order: 0,
  9133. Code: "",
  9134. }
  9135. service.CreatedDicConfig(&dataconfig)
  9136. }
  9137. }
  9138. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9139. for _, it := range costClassList {
  9140. if cost_classify == it.Name {
  9141. cost_classify_id = int64(it.Value)
  9142. }
  9143. }
  9144. project.CostClassify = cost_classify_id
  9145. executive_section := projectM["executive_section"].(string)
  9146. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9147. err_log := models.ExportErrLog{
  9148. LogType: 6,
  9149. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9150. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  9151. Status: 1,
  9152. CreateTime: time.Now().Unix(),
  9153. UpdateTime: time.Now().Unix(),
  9154. ExportTime: time.Now().Unix(),
  9155. }
  9156. service.CreateExportErrLog(&err_log)
  9157. continue
  9158. }
  9159. if len(executive_section) != 0 {
  9160. //查找科室是否有内容
  9161. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  9162. if errcodedepart == gorm.ErrRecordNotFound {
  9163. department := models.XtHisDepartment{
  9164. Name: executive_section,
  9165. Status: 1,
  9166. UserOrgId: adminUser.CurrentOrgId,
  9167. CreatedTime: time.Now().Unix(),
  9168. }
  9169. service.CreateDePartment(&department)
  9170. }
  9171. }
  9172. var executive_section_id int64
  9173. departMentList, _ := service.GetAllDepartMent(orgId)
  9174. for _, it := range departMentList {
  9175. if executive_section == it.Name {
  9176. executive_section_id = it.ID
  9177. }
  9178. }
  9179. project.ExecutiveSection = executive_section_id
  9180. medical_coverage := projectM["medical_coverage"].(string)
  9181. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  9182. err_log := models.ExportErrLog{
  9183. LogType: 6,
  9184. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9185. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9186. Status: 1,
  9187. CreateTime: time.Now().Unix(),
  9188. UpdateTime: time.Now().Unix(),
  9189. ExportTime: time.Now().Unix(),
  9190. }
  9191. service.CreateExportErrLog(&err_log)
  9192. continue
  9193. }
  9194. var medicalCoverage = "医保等级"
  9195. var medical_coverage_id int64
  9196. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  9197. if len(medical_coverage) != 0 {
  9198. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  9199. if errormedicalcoverage == gorm.ErrRecordNotFound {
  9200. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  9201. dataconfig := models.DictDataconfig{
  9202. ParentId: medicalCoverageConfig.ID,
  9203. Module: "system",
  9204. OrgId: orgId,
  9205. Name: medical_coverage,
  9206. FieldName: "",
  9207. Value: medicalCoverageConfig.Value + 1,
  9208. CreatedTime: "",
  9209. UpdatedTime: "",
  9210. CreateUserId: adminUser.AdminUser.Id,
  9211. Status: 1,
  9212. Remark: "",
  9213. DeleteIdSystem: 0,
  9214. Title: "",
  9215. Content: "",
  9216. Order: 0,
  9217. Code: "",
  9218. }
  9219. service.CreatedDicConfig(&dataconfig)
  9220. }
  9221. }
  9222. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  9223. for _, it := range medicalCoverageList {
  9224. if medical_coverage == it.Name {
  9225. medical_coverage_id = int64(it.Value)
  9226. }
  9227. }
  9228. project.MedicalCoverage = medical_coverage_id
  9229. pinyin := projectM["pinyin"].(string)
  9230. project.Pinyin = pinyin
  9231. wubi := projectM["wubi"].(string)
  9232. project.Wubi = wubi
  9233. statistical_classification := projectM["statistical_classification"].(string)
  9234. var statisticalClassification = "统计分类"
  9235. var statistical_classification_id int64
  9236. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  9237. if len(statistical_classification) != 0 {
  9238. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  9239. if classificationerrcodes == gorm.ErrRecordNotFound {
  9240. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  9241. dataconfig := models.DictDataconfig{
  9242. ParentId: classiFication.ID,
  9243. Module: "system",
  9244. OrgId: orgId,
  9245. Name: statistical_classification,
  9246. FieldName: "",
  9247. Value: classiFicationConfig.Value + 1,
  9248. CreatedTime: "",
  9249. UpdatedTime: "",
  9250. CreateUserId: adminUser.AdminUser.Id,
  9251. Status: 1,
  9252. Remark: "",
  9253. DeleteIdSystem: 0,
  9254. Title: "",
  9255. Content: "",
  9256. Order: 0,
  9257. Code: "",
  9258. }
  9259. service.CreatedDicConfig(&dataconfig)
  9260. }
  9261. }
  9262. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  9263. for _, it := range classiFicationList {
  9264. if statistical_classification == it.Name {
  9265. statistical_classification_id = int64(it.Value)
  9266. }
  9267. }
  9268. project.StatisticalClassification = statistical_classification_id
  9269. disease_directory := int64(projectM["disease_directory"].(float64))
  9270. project.DiseaseDirectory = disease_directory
  9271. is_record := int64(projectM["is_record"].(float64))
  9272. project.IsRecord = is_record
  9273. medical_code := projectM["medical_code"].(string)
  9274. project.MedicalCode = medical_code
  9275. tube_color := projectM["tube_color"].(string)
  9276. var tubeColor = "试管颜色"
  9277. var tube_color_id int64
  9278. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  9279. if len(tube_color) != 0 {
  9280. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  9281. if errcodetube == gorm.ErrRecordNotFound {
  9282. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  9283. dataconfig := models.DictDataconfig{
  9284. ParentId: tubeColorConfig.ID,
  9285. Module: "system",
  9286. OrgId: orgId,
  9287. Name: tube_color,
  9288. FieldName: "",
  9289. Value: tubeConfig.Value + 1,
  9290. CreatedTime: "",
  9291. UpdatedTime: "",
  9292. CreateUserId: adminUser.AdminUser.Id,
  9293. Status: 1,
  9294. Remark: "",
  9295. DeleteIdSystem: 0,
  9296. Title: "",
  9297. Content: "",
  9298. Order: 0,
  9299. Code: "",
  9300. }
  9301. service.CreatedDicConfig(&dataconfig)
  9302. }
  9303. }
  9304. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  9305. for _, it := range tubeColorList {
  9306. if tube_color == it.Name {
  9307. tube_color_id = int64(it.Value)
  9308. }
  9309. }
  9310. project.TubeColor = tube_color_id
  9311. single_dose := projectM["single_dose"].(string)
  9312. project.SingleDose = single_dose
  9313. execution_frequency := projectM["execution_frequency"].(string)
  9314. project.ExecutionFrequency = execution_frequency
  9315. delivery_way := projectM["delivery_way"].(string)
  9316. project.DeliveryWay = delivery_way
  9317. number_days := projectM["number_days"].(string)
  9318. project.NumberDays = number_days
  9319. total := projectM["total"].(string)
  9320. project.Total = total
  9321. medical_status := int64(projectM["medical_status"].(float64))
  9322. project.MedicalStatus = medical_status
  9323. category := int64(projectM["category"].(float64))
  9324. project.Category = category
  9325. specail_project := int64(projectM["specail_project"].(float64))
  9326. project.SpecailProject = specail_project
  9327. social_security_directory_code := projectM["social_security_directory_code"].(string)
  9328. project.SocialSecurityDirectoryCode = social_security_directory_code
  9329. remark := projectM["remark"].(string)
  9330. project.Remark = remark
  9331. record_date := projectM["record_date"].(string)
  9332. timeLayout := "2006-01-02"
  9333. loc, _ := time.LoadLocation("Local")
  9334. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9335. project.RecordDate = theTime.Unix()
  9336. projectList = append(projectList, &project)
  9337. }
  9338. export_time := time.Now().Unix()
  9339. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  9340. if len(projectList) > 0 {
  9341. for _, item := range projectList {
  9342. project := models.HisProject{
  9343. ProjectName: item.ProjectName,
  9344. Price: item.Price,
  9345. Unit: item.Unit,
  9346. CostClassify: item.CostClassify,
  9347. ExecutiveSection: item.ExecutiveSection,
  9348. MedicalCoverage: item.MedicalCoverage,
  9349. UserOrgId: orgId,
  9350. Status: 1,
  9351. CreatedTime: time.Now().Unix(),
  9352. Pinyin: item.Pinyin,
  9353. Wubi: item.Wubi,
  9354. StatisticalClassification: item.StatisticalClassification,
  9355. DiseaseDirectory: item.DiseaseDirectory,
  9356. IsRecord: item.IsRecord,
  9357. MedicalCode: item.MedicalCode,
  9358. TubeColor: item.TubeColor,
  9359. SingleDose: item.SingleDose,
  9360. DeliveryWay: item.DeliveryWay,
  9361. NumberDays: item.NumberDays,
  9362. Total: item.Total,
  9363. Category: item.Category,
  9364. MedicalStatus: item.MedicalStatus,
  9365. SpecailProject: item.SpecailProject,
  9366. RecordDate: item.RecordDate,
  9367. Remark: item.Remark,
  9368. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  9369. ExecutionFrequency: item.ExecutionFrequency,
  9370. }
  9371. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  9372. if errcodeproject == gorm.ErrRecordNotFound {
  9373. service.CreateProjectInfomation(&project)
  9374. } else if errcodeproject == nil {
  9375. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  9376. }
  9377. log := models.ExportLog{
  9378. LogType: 6,
  9379. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9380. TotalNum: int64(len(total_goods)),
  9381. FailNum: int64(len(errLogs)),
  9382. SuccessNum: int64(len(projectList)),
  9383. CreateTime: time.Now().Unix(),
  9384. UpdateTime: time.Now().Unix(),
  9385. ExportTime: export_time,
  9386. Status: 1,
  9387. }
  9388. service.CreateExportLog(&log)
  9389. c.ServeSuccessJSON(map[string]interface{}{
  9390. "msg": "导入成功",
  9391. "total_num": len(total_goods),
  9392. "success_num": len(projectList),
  9393. "fail_num": int64(len(errLogs)),
  9394. })
  9395. }
  9396. } else {
  9397. log := models.ExportLog{
  9398. LogType: 6,
  9399. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9400. TotalNum: int64(len(total_goods)),
  9401. FailNum: int64(len(errLogs)),
  9402. SuccessNum: int64(len(projectList)),
  9403. CreateTime: time.Now().Unix(),
  9404. UpdateTime: time.Now().Unix(),
  9405. ExportTime: export_time,
  9406. Status: 1,
  9407. }
  9408. service.CreateExportLog(&log)
  9409. c.ServeSuccessJSON(map[string]interface{}{
  9410. "msg": "导入成功",
  9411. "total_num": len(total_goods),
  9412. "success_num": len(projectList),
  9413. "fail_num": int64(len(errLogs)),
  9414. })
  9415. }
  9416. }
  9417. //func (this *HisApiController) EditProjectInformation(){
  9418. //
  9419. // id, _ := this.GetInt64("id")
  9420. // project_team := this.GetString("project_team")
  9421. // price := this.GetString("price")
  9422. // price_float, _ := strconv.ParseFloat(price, 64)
  9423. // pinyin := this.GetString("pinyin")
  9424. // wubi := this.GetString("wubi")
  9425. // tube_color, _ := this.GetInt64("tube_color")
  9426. // team_type, _ := this.GetInt64("team_type")
  9427. // remark := this.GetString("remark")
  9428. // ids := this.GetString("ids")
  9429. // item_id := this.GetString("item_id")
  9430. // projectTeam := models.XtHisProjectTeam{
  9431. // ProjectTeam: project_team,
  9432. // Price: price_float,
  9433. // Pinyin: pinyin,
  9434. // Wubi: wubi,
  9435. // TubeColor: tube_color,
  9436. // TeamType: team_type,
  9437. // Remark: remark,
  9438. // ProjectId: ids,
  9439. // ItemId: item_id,
  9440. // }
  9441. //
  9442. //
  9443. // dataBody := make(map[string]interface{}, 0)
  9444. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9445. // if err != nil {
  9446. // utils.ErrorLog(err.Error())
  9447. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9448. // return
  9449. // }
  9450. //
  9451. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9452. //
  9453. //
  9454. // if err != nil {
  9455. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9456. // return
  9457. // }
  9458. //
  9459. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9460. // infos, _ := dataBody["info"].([]interface{})
  9461. // if len(infos) > 0 {
  9462. // var ids []string
  9463. //
  9464. // for _, item := range infos {
  9465. // items := item.(map[string]interface{})
  9466. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9467. // utils.ErrorLog("id")
  9468. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9469. // return
  9470. // }
  9471. // id := int64(items["id"].(float64))
  9472. //
  9473. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9474. // utils.ErrorLog("type")
  9475. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9476. // return
  9477. // }
  9478. // types := int64(items["type"].(float64))
  9479. //
  9480. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9481. // utils.ErrorLog("number")
  9482. // }
  9483. //
  9484. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9485. //
  9486. // projectList := models.XtHisProjectList{
  9487. // Number: number,
  9488. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9489. // ProjectId: id,
  9490. // Status: 1,
  9491. // CreatedTime: time.Now().Unix(),
  9492. // UpdatedTime: time.Now().Unix(),
  9493. // TeamId: projectTeam.ID,
  9494. // Type: types,
  9495. // }
  9496. // list := projectList
  9497. //
  9498. // service.CreateProjectList(&list)
  9499. //
  9500. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9501. //
  9502. // }
  9503. // ids_str := strings.Join(ids, ",")
  9504. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9505. // service.SaveProjectTeam(&projectTeam)
  9506. // this.ServeSuccessJSON(map[string]interface{}{
  9507. // "projectTeam": projectTeam,
  9508. // })
  9509. // }
  9510. // }
  9511. //}
  9512. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9513. name := c.GetString("name")
  9514. mode_id, _ := c.GetInt64("mode", 0)
  9515. types, _ := c.GetInt64("type", 0)
  9516. patient_id, _ := c.GetInt64("patient_id", 0)
  9517. types = 1
  9518. adminInfo := c.GetAdminUserInfo()
  9519. template := &models.HisPrescriptionTemplate{
  9520. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9521. PatientId: patient_id,
  9522. Type: types,
  9523. Status: 1,
  9524. Ctime: time.Now().Unix(),
  9525. Mtime: time.Now().Unix(),
  9526. Name: name,
  9527. Mode: mode_id,
  9528. }
  9529. dataBody := make(map[string]interface{}, 0)
  9530. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9531. if err != nil {
  9532. utils.ErrorLog(err.Error())
  9533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9534. return
  9535. }
  9536. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9537. //如果已经存在记录则删除处方
  9538. if template_one.ID > 0 {
  9539. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9540. var ids []int64
  9541. var org_id int64
  9542. for _, item := range ps {
  9543. org_id = c.GetAdminUserInfo().CurrentOrgId
  9544. ids = append(ids, item.ID)
  9545. }
  9546. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9547. if err2 == nil {
  9548. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9549. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9550. if len(prescriptions) > 0 {
  9551. for _, item := range prescriptions {
  9552. items := item.(map[string]interface{})
  9553. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9554. utils.ErrorLog("type")
  9555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9556. return
  9557. }
  9558. types := int64(items["type"].(float64))
  9559. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9560. utils.ErrorLog("med_type")
  9561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9562. return
  9563. }
  9564. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9565. ctime := time.Now().Unix()
  9566. prescription := &models.HisPrescriptionInfoTemplate{
  9567. PatientId: patient_id,
  9568. UserOrgId: adminInfo.CurrentOrgId,
  9569. Ctime: ctime,
  9570. Mtime: ctime,
  9571. Type: types,
  9572. Modifier: adminInfo.AdminUser.Id,
  9573. Creator: adminInfo.AdminUser.Id,
  9574. Status: 1,
  9575. PTemplateId: template_one.ID,
  9576. MedType: med_type,
  9577. }
  9578. service.CreateHisPrescriptionInfoTemplate(prescription)
  9579. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9580. advices := items["advices"].([]interface{})
  9581. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9582. ctime := time.Now().Unix()
  9583. mtime := ctime
  9584. if len(advices) > 0 {
  9585. for _, advice := range advices {
  9586. var s models.HisPrescriptionAdviceTemplate
  9587. s.PrescriptionId = prescription.ID
  9588. s.AdviceType = 2
  9589. s.StopState = 2
  9590. s.ExecutionState = 2
  9591. s.Status = 1
  9592. s.UserOrgId = adminInfo.CurrentOrgId
  9593. s.CreatedTime = ctime
  9594. s.UpdatedTime = mtime
  9595. s.PatientId = patient_id
  9596. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9597. if errcode > 0 {
  9598. c.ServeFailJSONWithSGJErrorCode(errcode)
  9599. return
  9600. }
  9601. service.CreateHisPrescriptionAdviceTemplate(&s)
  9602. }
  9603. }
  9604. }
  9605. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9606. projects := items["project"].([]interface{})
  9607. if len(projects) > 0 {
  9608. for _, project := range projects {
  9609. var p models.HisPrescriptionProjectTemplate
  9610. p.PrescriptionId = prescription.ID
  9611. p.Ctime = time.Now().Unix()
  9612. p.Mtime = time.Now().Unix()
  9613. p.PatientId = patient_id
  9614. p.UserOrgId = adminInfo.CurrentOrgId
  9615. p.Status = 1
  9616. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9617. if errcode > 0 {
  9618. c.ServeFailJSONWithSGJErrorCode(errcode)
  9619. return
  9620. }
  9621. service.CreateHisPrescriptionProjectTemplate(&p)
  9622. }
  9623. }
  9624. }
  9625. }
  9626. c.ServeSuccessJSON(map[string]interface{}{
  9627. "msg": "创建成功",
  9628. })
  9629. }
  9630. }
  9631. } else {
  9632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9633. return
  9634. }
  9635. } else {
  9636. err3 := service.CreateHisPrescriptionTemplate(template)
  9637. if err3 == nil {
  9638. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9639. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9640. if len(prescriptions) > 0 {
  9641. for _, item := range prescriptions {
  9642. items := item.(map[string]interface{})
  9643. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9644. utils.ErrorLog("type")
  9645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9646. return
  9647. }
  9648. types := int64(items["type"].(float64))
  9649. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9650. utils.ErrorLog("med_type")
  9651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9652. return
  9653. }
  9654. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9655. ctime := time.Now().Unix()
  9656. prescription := &models.HisPrescriptionInfoTemplate{
  9657. PatientId: patient_id,
  9658. UserOrgId: adminInfo.CurrentOrgId,
  9659. Ctime: ctime,
  9660. Mtime: ctime,
  9661. Type: types,
  9662. Modifier: adminInfo.AdminUser.Id,
  9663. Creator: adminInfo.AdminUser.Id,
  9664. Status: 1,
  9665. PTemplateId: template.ID,
  9666. MedType: med_type,
  9667. }
  9668. service.CreateHisPrescriptionInfoTemplate(prescription)
  9669. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9670. advices := items["advices"].([]interface{})
  9671. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9672. ctime := time.Now().Unix()
  9673. mtime := ctime
  9674. if len(advices) > 0 {
  9675. for _, advice := range advices {
  9676. var s models.HisPrescriptionAdviceTemplate
  9677. s.PrescriptionId = prescription.ID
  9678. s.AdviceType = 2
  9679. s.StopState = 2
  9680. s.ExecutionState = 2
  9681. s.Status = 1
  9682. s.UserOrgId = adminInfo.CurrentOrgId
  9683. s.CreatedTime = ctime
  9684. s.UpdatedTime = mtime
  9685. s.PatientId = patient_id
  9686. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9687. if errcode > 0 {
  9688. c.ServeFailJSONWithSGJErrorCode(errcode)
  9689. return
  9690. }
  9691. service.CreateHisPrescriptionAdviceTemplate(&s)
  9692. }
  9693. }
  9694. }
  9695. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9696. projects := items["project"].([]interface{})
  9697. if len(projects) > 0 {
  9698. for _, project := range projects {
  9699. var p models.HisPrescriptionProjectTemplate
  9700. p.PrescriptionId = prescription.ID
  9701. p.Ctime = time.Now().Unix()
  9702. p.Mtime = time.Now().Unix()
  9703. p.PatientId = patient_id
  9704. p.UserOrgId = adminInfo.CurrentOrgId
  9705. p.Status = 1
  9706. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9707. if errcode > 0 {
  9708. c.ServeFailJSONWithSGJErrorCode(errcode)
  9709. return
  9710. }
  9711. service.CreateHisPrescriptionProjectTemplate(&p)
  9712. }
  9713. }
  9714. }
  9715. }
  9716. c.ServeSuccessJSON(map[string]interface{}{
  9717. "msg": "创建成功",
  9718. })
  9719. }
  9720. }
  9721. } else {
  9722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9723. return
  9724. }
  9725. }
  9726. }
  9727. func (c *HisApiController) PreSettle() {
  9728. id, _ := c.GetInt64("id")
  9729. record_time := c.GetString("record_time")
  9730. his_patient_id, _ := c.GetInt64("his_patient_id")
  9731. timeLayout := "2006-01-02"
  9732. loc, _ := time.LoadLocation("Local")
  9733. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9734. diagnosis_id := c.GetString("diagnosis")
  9735. sick_type, _ := c.GetInt64("sick_type")
  9736. reg_type, _ := c.GetInt64("p_type")
  9737. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9738. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9739. if err != nil {
  9740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9741. return
  9742. }
  9743. recordDateTime := theTime.Unix()
  9744. adminUser := c.GetAdminUserInfo()
  9745. var prescriptions []*models.HisPrescription
  9746. var start_time int64
  9747. var end_time int64
  9748. ids_str := c.GetString("ids")
  9749. ids_arr := strings.Split(ids_str, ",")
  9750. fmt.Println(reg_type)
  9751. if settle_accounts_type == 1 { //日结
  9752. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9753. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9754. } else {
  9755. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9756. }
  9757. fmt.Println(prescriptions)
  9758. } else { //月结
  9759. start_time_str := c.GetString("start_time")
  9760. end_time_str := c.GetString("end_time")
  9761. timeLayout := "2006-01-02"
  9762. loc, _ := time.LoadLocation("Local")
  9763. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9764. if err != nil {
  9765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9766. return
  9767. }
  9768. recordStartTime := theStartTime.Unix()
  9769. start_time = recordStartTime
  9770. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9771. if err != nil {
  9772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9773. return
  9774. }
  9775. recordEndTime := theEndTime.Unix()
  9776. end_time = recordEndTime
  9777. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9778. }
  9779. if reg_type == 1111 || reg_type == 1112 {
  9780. reg_type = 11
  9781. }
  9782. timestamp := time.Now().Unix()
  9783. tempTime := time.Unix(timestamp, 0)
  9784. timeFormat := tempTime.Format("20060102150405")
  9785. chrgBchno := rand.Intn(100000) + 10000
  9786. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9787. strconv.FormatInt(his.PatientId, 10)
  9788. var ids []int64
  9789. for _, item := range prescriptions {
  9790. ids = append(ids, item.ID)
  9791. }
  9792. fmt.Println(ids)
  9793. var total float64
  9794. for _, item := range prescriptions {
  9795. fmt.Println(item)
  9796. if item.Type == 1 { //药品
  9797. for _, subItem := range item.HisDoctorAdviceInfo {
  9798. total = total + (subItem.Price * subItem.PrescribingNumber)
  9799. }
  9800. }
  9801. if item.Type == 2 { //项目
  9802. for _, subItem := range item.HisPrescriptionProject {
  9803. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9804. total = total + (subItem.Price * cnt)
  9805. }
  9806. }
  9807. for _, subItem := range item.HisAdditionalCharge {
  9808. total = total + (subItem.Price * float64(subItem.Count))
  9809. }
  9810. }
  9811. allTotal := fmt.Sprintf("%.2f", total)
  9812. totals, _ := strconv.ParseFloat(allTotal, 64)
  9813. order := &models.HisOrder{
  9814. UserOrgId: adminUser.CurrentOrgId,
  9815. HisPatientId: his.ID,
  9816. PatientId: id,
  9817. SettleAccountsDate: recordDateTime,
  9818. Ctime: time.Now().Unix(),
  9819. Mtime: time.Now().Unix(),
  9820. Status: 1,
  9821. OrderStatus: 1,
  9822. MdtrtId: his.Number,
  9823. Number: chrg_bchno,
  9824. MedfeeSumamt: totals,
  9825. SettleEndTime: end_time,
  9826. SettleStartTime: start_time,
  9827. SettleType: settle_accounts_type,
  9828. PsnPartAmt: totals,
  9829. PsnCashPay: totals,
  9830. PType: 2,
  9831. IsPre: 1,
  9832. MedType: strconv.Itoa(int(reg_type)),
  9833. Diagnosis: diagnosis_id,
  9834. }
  9835. err = service.CreateOrder(order)
  9836. if err != nil {
  9837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9838. return
  9839. }
  9840. var customs []*Custom
  9841. for _, item := range prescriptions {
  9842. fmt.Println(item.Type)
  9843. if item.Type == 1 { //药品
  9844. for _, subItem := range item.HisDoctorAdviceInfo {
  9845. cus := &Custom{
  9846. AdviceId: subItem.ID,
  9847. ProjectId: 0,
  9848. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9849. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9850. FeedetlSn: subItem.FeedetlSn,
  9851. Price: fmt.Sprintf("%.2f", subItem.Price),
  9852. MedListCodg: subItem.MedListCodg,
  9853. Type: 1,
  9854. }
  9855. customs = append(customs, cus)
  9856. }
  9857. }
  9858. if item.Type == 2 { //项目
  9859. for _, subItem := range item.HisPrescriptionProject {
  9860. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9861. cus := &Custom{
  9862. AdviceId: 0,
  9863. ProjectId: subItem.ID,
  9864. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9865. Cut: fmt.Sprintf("%.2f", cnt),
  9866. FeedetlSn: subItem.FeedetlSn,
  9867. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9868. MedListCodg: subItem.MedListCodg,
  9869. Type: 2,
  9870. }
  9871. customs = append(customs, cus)
  9872. }
  9873. }
  9874. for _, item := range item.HisAdditionalCharge {
  9875. cus := &Custom{
  9876. ItemId: item.ID,
  9877. AdviceId: 0,
  9878. ProjectId: 0,
  9879. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9880. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9881. FeedetlSn: item.FeedetlSn,
  9882. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9883. MedListCodg: item.XtHisAddtionConfig.Code,
  9884. Type: 3,
  9885. }
  9886. customs = append(customs, cus)
  9887. }
  9888. }
  9889. fmt.Println(customs)
  9890. for _, item := range customs {
  9891. var advice_id int64 = 0
  9892. var project_id int64 = 0
  9893. var item_id int64 = 0
  9894. var types int64 = 0
  9895. if item.Type == 1 {
  9896. advice_id = item.AdviceId
  9897. project_id = 0
  9898. item_id = 0
  9899. } else if item.Type == 2 {
  9900. advice_id = 0
  9901. item_id = 0
  9902. project_id = item.ProjectId
  9903. } else if item.Type == 3 {
  9904. advice_id = 0
  9905. item_id = item.ItemId
  9906. project_id = 0
  9907. }
  9908. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9909. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9910. pric, _ := strconv.ParseFloat(item.Price, 32)
  9911. info := &models.HisOrderInfo{
  9912. OrderNumber: order.Number,
  9913. UploadDate: time.Now().Unix(),
  9914. AdviceId: advice_id,
  9915. DetItemFeeSumamt: detItemFeeSumamt,
  9916. Cnt: cut,
  9917. Pric: pric,
  9918. PatientId: id,
  9919. Status: 1,
  9920. Mtime: time.Now().Unix(),
  9921. Ctime: time.Now().Unix(),
  9922. UserOrgId: adminUser.CurrentOrgId,
  9923. HisPatientId: his.ID,
  9924. OrderId: order.ID,
  9925. ProjectId: project_id,
  9926. Type: types,
  9927. ItemId: item_id,
  9928. }
  9929. service.CreateOrderInfo(info)
  9930. }
  9931. his.SickType = sick_type
  9932. service.UpdataHisPateint(&his)
  9933. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9934. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9935. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9936. if err == nil {
  9937. c.ServeSuccessJSON(map[string]interface{}{
  9938. "msg": "结算成功",
  9939. })
  9940. }
  9941. }
  9942. type CustomOrderInfo struct {
  9943. Name string
  9944. Spec string
  9945. Unit string
  9946. Count float64
  9947. Price float64
  9948. Total float64
  9949. }
  9950. func (c *HisApiController) GetPrivateExpensesInfo() {
  9951. order_id, _ := c.GetInt64("id", 0)
  9952. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9953. order, _ := service.GetHisOrderByID(order_id)
  9954. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9955. if order.ID == 0 {
  9956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9957. return
  9958. }
  9959. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9960. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9961. org_id := c.GetAdminUserInfo().CurrentOrgId
  9962. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9963. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9964. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9965. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9966. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9967. //var orderInfos_four []*models.HisOrderInfoTwo
  9968. //for _, item := range orderInfos_three {
  9969. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9970. // item.HisPrescriptionProject.IsCheckTeam = 1
  9971. // orderInfos_four = append(orderInfos_four, item)
  9972. //
  9973. // }
  9974. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9975. // item.HisPrescriptionProject.IsCheckTeam = 2
  9976. // orderInfos_two = append(orderInfos_two, item)
  9977. // }
  9978. //}
  9979. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9980. //var cus_slice []CustomOrderInfo
  9981. //for _, item := range new_order_info {
  9982. // var cus CustomOrderInfo
  9983. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9984. // cus.Unit = ""
  9985. // cus.Spec = ""
  9986. // var total float64
  9987. // for _, subItem := range orderInfos_four {
  9988. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9989. // total = total + subItem.DetItemFeeSumamt
  9990. // fmt.Println(subItem.DetItemFeeSumamt)
  9991. // }
  9992. // }
  9993. // cus.Count = 1
  9994. // cus.Total = total
  9995. // cus_slice = append(cus_slice, cus)
  9996. //}
  9997. orderInfos = append(orderInfos, orderInfos_two...)
  9998. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9999. //orderInfos = append(orderInfos, orderInfos_three...)
  10000. //}/**/
  10001. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10002. c.ServeSuccessJSON(map[string]interface{}{
  10003. "order": order,
  10004. "order_info": orderInfos,
  10005. "patient": patient,
  10006. "admin_info": adminInfo,
  10007. "his": his,
  10008. "current_admin": role,
  10009. "org_config": miConfig,
  10010. //"new_order_info": cus_slice,
  10011. })
  10012. }
  10013. func (this *HisApiController) ChangeMedType() {
  10014. med_type := this.GetString("med_type")
  10015. old_med_type := this.GetString("old_med_type")
  10016. ids := this.GetString("ids")
  10017. settle_type, _ := this.GetInt64("settle_type")
  10018. start_time := this.GetString("start_time")
  10019. end_time := this.GetString("end_time")
  10020. ids_arr := strings.Split(ids, ",")
  10021. if settle_type == 1 { //日结
  10022. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10023. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10024. prescription.MedType = med_type
  10025. err := service.SaveHisPrescription(&prescription)
  10026. if err == nil {
  10027. this.ServeSuccessJSON(map[string]interface{}{
  10028. "msg": "修改成功",
  10029. })
  10030. } else {
  10031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10032. return
  10033. }
  10034. } else if settle_type == 2 {
  10035. timeLayout := "2006-01-02"
  10036. loc, _ := time.LoadLocation("Local")
  10037. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10038. if err != nil {
  10039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10040. return
  10041. }
  10042. recordStartTime := theStartTime.Unix()
  10043. start_time_timestamp := recordStartTime
  10044. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10045. if err != nil {
  10046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10047. return
  10048. }
  10049. recordEndTime := theEndTime.Unix()
  10050. end_time_timestamp := recordEndTime
  10051. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10052. if updateErr == nil {
  10053. this.ServeSuccessJSON(map[string]interface{}{
  10054. "msg": "修改成功",
  10055. })
  10056. } else {
  10057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10058. return
  10059. }
  10060. }
  10061. }
  10062. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10063. patient_id, _ := c.GetInt64("patient_id")
  10064. his_patient_id, _ := c.GetInt64("his_patient_id")
  10065. record_date := c.GetString("record_date")
  10066. start_time := c.GetString("start_time")
  10067. end_time := c.GetString("end_time")
  10068. order_status, _ := c.GetInt64("type", 0)
  10069. p_type, _ := c.GetInt64("p_type", 0)
  10070. order_id, _ := c.GetInt64("order_id", 0)
  10071. timeLayout := "2006-01-02"
  10072. loc, _ := time.LoadLocation("Local")
  10073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10074. if err != nil {
  10075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10076. return
  10077. }
  10078. recordDateTime := theTime.Unix()
  10079. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10080. if err != nil {
  10081. }
  10082. startRecordDateTime := startTime.Unix()
  10083. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10084. if err != nil {
  10085. }
  10086. endRecordDateTime := endTime.Unix()
  10087. admin := c.GetAdminUserInfo()
  10088. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10089. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10090. order, _ := service.GetHisOrderByID(order_id)
  10091. var monthPrescriptions []*models.HisPrescription
  10092. if order_status == 1 || order_status == 0 {
  10093. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10094. } else if order_status == 2 {
  10095. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10096. }
  10097. var settle_total float64
  10098. for _, item := range monthPrescriptions {
  10099. if len(item.HisPrescriptionProject) > 0 {
  10100. for _, subItem := range item.HisPrescriptionProject {
  10101. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10102. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10103. settle_total = settle_total + total
  10104. }
  10105. }
  10106. if len(item.HisDoctorAdviceInfo) > 0 {
  10107. for _, subItem := range item.HisDoctorAdviceInfo {
  10108. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10109. settle_total = settle_total + total
  10110. }
  10111. }
  10112. }
  10113. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10114. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10115. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10116. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10117. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10118. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10119. //获取所有科室信息
  10120. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10121. var dia string
  10122. for _, item := range month_p_info {
  10123. if len(dia) == 0 {
  10124. dia = item.Diagnosis
  10125. } else {
  10126. dia = dia + "," + item.Diagnosis
  10127. }
  10128. }
  10129. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10130. dia_arr = removeEmptyStrings(dia_arr)
  10131. c.ServeSuccessJSON(map[string]interface{}{
  10132. "his_info": his_patient_info,
  10133. "xt_info": xt_patient_info,
  10134. "case_history": case_history,
  10135. "info": patientPrescriptionInfo,
  10136. "last_info": lastPatientPrescriptionInfo,
  10137. "month_prescriptions": monthPrescriptions,
  10138. "order": order,
  10139. "doctors": doctors,
  10140. "department": department,
  10141. "settle_total": settle_total,
  10142. "dia_arr": dia_arr,
  10143. })
  10144. return
  10145. }
  10146. func removeEmptyStrings(input []string) []string {
  10147. var output []string
  10148. for _, s := range input {
  10149. if s != "" {
  10150. output = append(output, s)
  10151. }
  10152. }
  10153. return output
  10154. }
  10155. func removeDuplicates(input []string) []string {
  10156. seen := make(map[string]bool)
  10157. output := []string{}
  10158. for _, s := range input {
  10159. if _, exists := seen[s]; !exists {
  10160. seen[s] = true
  10161. output = append(output, s)
  10162. }
  10163. }
  10164. return output
  10165. }
  10166. func (c *HisApiController) GetHisMonthPatientInfo() {
  10167. patient_id, _ := c.GetInt64("patient_id")
  10168. his_patient_id, _ := c.GetInt64("his_patient_id")
  10169. record_date := c.GetString("record_date")
  10170. number := c.GetString("number")
  10171. start_time := c.GetString("start_time")
  10172. end_time := c.GetString("end_time")
  10173. p_type, _ := c.GetInt64("p_type")
  10174. timeLayout := "2006-01-02"
  10175. loc, _ := time.LoadLocation("Local")
  10176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10177. if err != nil {
  10178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10179. return
  10180. }
  10181. recordDateTime := theTime.Unix()
  10182. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10183. if err != nil {
  10184. }
  10185. startRecordDateTime := startTime.Unix()
  10186. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10187. if err != nil {
  10188. }
  10189. endRecordDateTime := endTime.Unix()
  10190. admin := c.GetAdminUserInfo()
  10191. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  10192. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10193. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  10194. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10195. var settle_total float64
  10196. for _, item := range monthPrescriptions {
  10197. if len(item.HisPrescriptionProject) > 0 {
  10198. for _, subItem := range item.HisPrescriptionProject {
  10199. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10200. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10201. settle_total = settle_total + total
  10202. }
  10203. }
  10204. if len(item.HisDoctorAdviceInfo) > 0 {
  10205. for _, subItem := range item.HisDoctorAdviceInfo {
  10206. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10207. settle_total = settle_total + total
  10208. }
  10209. }
  10210. }
  10211. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10212. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10213. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10214. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10215. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  10216. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10217. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  10218. //获取所有科室信息
  10219. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10220. c.ServeSuccessJSON(map[string]interface{}{
  10221. "his_info": his_patient_info,
  10222. "xt_info": xt_patient_info,
  10223. "case_history": case_history,
  10224. "info": patientPrescriptionInfo,
  10225. "month_prescriptions": monthPrescriptions,
  10226. "order": order,
  10227. "doctors": doctors,
  10228. "department": department,
  10229. "count": count,
  10230. "drugStockConfig": drugStockConfig,
  10231. "last_info": lastPatientPrescriptionInfo,
  10232. "settle_total": settle_total,
  10233. })
  10234. return
  10235. }
  10236. func (c *HisApiController) GetAllOrder() {
  10237. org_id := c.GetAdminUserInfo().CurrentOrgId
  10238. orders, _ := service.GetNewHisOrderList(org_id)
  10239. c.ServeSuccessJSON(map[string]interface{}{
  10240. "order": orders,
  10241. })
  10242. return
  10243. }
  10244. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  10245. newArr = make([]*models.HisOrderInfoTwo, 0)
  10246. for i := 0; i < len(arr); i++ {
  10247. repeat := false
  10248. for j := i + 1; j < len(arr); j++ {
  10249. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  10250. repeat = true
  10251. break
  10252. }
  10253. }
  10254. if !repeat {
  10255. newArr = append(newArr, arr[i])
  10256. }
  10257. }
  10258. return
  10259. }
  10260. // 修改处方退库操作 参数传修改之前的处方数据
  10261. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  10262. if advice.ExecutionState == 1 {
  10263. //查询该病人该药品是否有库存记录
  10264. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  10265. if errcode == gorm.ErrRecordNotFound {
  10266. } else {
  10267. //退库
  10268. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  10269. if advice.PrescribingNumberUnit == drug.MinUnit {
  10270. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10271. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10272. //退库
  10273. warehouseInfo := models.DrugWarehouseInfo{
  10274. StockMinNumber: prescribingNumber,
  10275. }
  10276. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  10277. operation_time := time.Now().Unix()
  10278. creater := advice.AdviceDoctor
  10279. ctime := time.Now().Unix()
  10280. timeStr := time.Now().Format("2006-01-02")
  10281. timeArr := strings.Split(timeStr, "-")
  10282. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10283. total = total + 1
  10284. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10285. cancelStock := models.DrugCancelStock{
  10286. OrderNumber: orderNumber,
  10287. OperaTime: operation_time,
  10288. OrgId: advice.UserOrgId,
  10289. Creater: creater,
  10290. Ctime: ctime,
  10291. Status: 1,
  10292. ReturnTime: advice.AdviceDate,
  10293. Dealer: info.Dealer,
  10294. Manufacturer: info.Manufacturer,
  10295. Type: 1,
  10296. }
  10297. service.AddSigleDrugCancelStock(&cancelStock)
  10298. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10299. dealer, _ := service.GetDealerById(info.Dealer)
  10300. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10301. cancelStockInfo := models.DrugCancelStockInfo{
  10302. OrderNumber: cancelInfo.OrderNumber,
  10303. CancelStockId: cancelInfo.ID,
  10304. DrugId: info.DrugId,
  10305. Count: info.Count,
  10306. Status: 1,
  10307. Ctime: ctime,
  10308. OrgId: advice.UserOrgId,
  10309. Type: 1,
  10310. Manufacturer: manufactureName.ManufacturerName,
  10311. Dealer: dealer.DealerName,
  10312. Total: 0,
  10313. RetailPrice: info.RetailPrice,
  10314. RetailTotalPrice: info.RetailTotalPrice,
  10315. Price: info.Price,
  10316. RegisterAccount: "",
  10317. Remark: info.Remark,
  10318. BatchNumber: info.BatchNumber,
  10319. MaxUnit: info.CountUnit,
  10320. ProductDate: info.ProductDate,
  10321. ExpiryDate: info.ExpiryDate,
  10322. BatchNumberId: info.WarehouseInfoId,
  10323. }
  10324. flow := models.DrugFlow{
  10325. WarehousingId: 0,
  10326. DrugId: info.DrugId,
  10327. Number: "",
  10328. BatchNumber: info.BatchNumber,
  10329. Count: info.Count,
  10330. UserOrgId: advice.UserOrgId,
  10331. PatientId: 0,
  10332. SystemTime: ctime,
  10333. ConsumableType: 4,
  10334. IsSys: 0,
  10335. WarehousingOrder: "",
  10336. WarehouseOutId: 0,
  10337. WarehouseOutOrderNumber: "",
  10338. IsEdit: 0,
  10339. CancelStockId: cancelStock.ID,
  10340. CancelOrderNumber: cancelStock.OrderNumber,
  10341. Manufacturer: info.Manufacturer,
  10342. Dealer: info.Dealer,
  10343. Creator: advice.UserOrgId,
  10344. UpdateCreator: 0,
  10345. Status: 1,
  10346. Ctime: time.Now().Unix(),
  10347. Mtime: 0,
  10348. Price: info.Price,
  10349. WarehousingDetailId: 0,
  10350. WarehouseOutDetailId: 0,
  10351. CancelOutDetailId: 0,
  10352. ExpireDate: info.ExpiryDate,
  10353. ProductDate: info.ProductDate,
  10354. MaxUnit: info.CountUnit,
  10355. MinUnit: "",
  10356. }
  10357. service.CreatedCancelStock(cancelStockInfo)
  10358. service.CreateDrugFlowOne(flow)
  10359. } else {
  10360. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10361. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10362. if advice.PrescribingNumberUnit == drug.MaxUnit {
  10363. warehouseInfo := models.DrugWarehouseInfo{
  10364. StockMinNumber: prescribingNumber,
  10365. }
  10366. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  10367. }
  10368. operation_time := time.Now().Unix()
  10369. creater := advice.AdviceDoctor
  10370. ctime := time.Now().Unix()
  10371. timeStr := time.Now().Format("2006-01-02")
  10372. timeArr := strings.Split(timeStr, "-")
  10373. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10374. total = total + 1
  10375. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10376. cancelStock := models.DrugCancelStock{
  10377. OrderNumber: orderNumber,
  10378. OperaTime: operation_time,
  10379. OrgId: advice.UserOrgId,
  10380. Creater: creater,
  10381. Ctime: ctime,
  10382. Status: 1,
  10383. ReturnTime: advice.AdviceDate,
  10384. Dealer: info.Dealer,
  10385. Manufacturer: info.Manufacturer,
  10386. Type: 1,
  10387. }
  10388. service.AddSigleDrugCancelStock(&cancelStock)
  10389. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10390. dealer, _ := service.GetDealerById(info.Dealer)
  10391. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10392. cancelStockInfo := models.DrugCancelStockInfo{
  10393. OrderNumber: cancelInfo.OrderNumber,
  10394. CancelStockId: cancelInfo.ID,
  10395. DrugId: info.DrugId,
  10396. Count: info.Count,
  10397. Status: 1,
  10398. Ctime: ctime,
  10399. OrgId: advice.UserOrgId,
  10400. Type: 1,
  10401. Manufacturer: manufactureName.ManufacturerName,
  10402. Dealer: dealer.DealerName,
  10403. Total: 0,
  10404. RetailPrice: info.RetailPrice,
  10405. RetailTotalPrice: info.RetailTotalPrice,
  10406. Price: info.Price,
  10407. RegisterAccount: "",
  10408. Remark: info.Remark,
  10409. BatchNumber: info.BatchNumber,
  10410. MaxUnit: info.CountUnit,
  10411. ProductDate: info.ProductDate,
  10412. ExpiryDate: info.ExpiryDate,
  10413. BatchNumberId: info.WarehouseInfoId,
  10414. }
  10415. flow := models.DrugFlow{
  10416. WarehousingId: 0,
  10417. DrugId: info.DrugId,
  10418. Number: "",
  10419. BatchNumber: info.BatchNumber,
  10420. Count: info.Count,
  10421. UserOrgId: advice.UserOrgId,
  10422. PatientId: 0,
  10423. SystemTime: ctime,
  10424. ConsumableType: 4,
  10425. IsSys: 0,
  10426. WarehousingOrder: "",
  10427. WarehouseOutId: 0,
  10428. WarehouseOutOrderNumber: "",
  10429. IsEdit: 0,
  10430. CancelStockId: cancelStock.ID,
  10431. CancelOrderNumber: cancelStock.OrderNumber,
  10432. Manufacturer: info.Manufacturer,
  10433. Dealer: info.Dealer,
  10434. Creator: advice.AdviceDoctor,
  10435. UpdateCreator: 0,
  10436. Status: 1,
  10437. Ctime: time.Now().Unix(),
  10438. Mtime: 0,
  10439. Price: info.Price,
  10440. WarehousingDetailId: 0,
  10441. WarehouseOutDetailId: 0,
  10442. CancelOutDetailId: 0,
  10443. ExpireDate: info.ExpiryDate,
  10444. ProductDate: info.ProductDate,
  10445. MaxUnit: info.CountUnit,
  10446. MinUnit: "",
  10447. }
  10448. service.CreatedCancelStock(cancelStockInfo)
  10449. service.CreateDrugFlowOne(flow)
  10450. }
  10451. }
  10452. }
  10453. return err
  10454. }
  10455. func (this *HisApiController) DeleteNCDS() {
  10456. id, _ := this.GetInt64("id", 0)
  10457. if id > 0 {
  10458. service.DeletePsnNCDSRecordById(id)
  10459. this.ServeSuccessJSON(map[string]interface{}{
  10460. "msg": "删除成功",
  10461. })
  10462. } else {
  10463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10464. return
  10465. }
  10466. }
  10467. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10468. id, _ := c.GetInt64("id")
  10469. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10470. c.ServeSuccessJSON(map[string]interface{}{
  10471. "advice": advice,
  10472. })
  10473. return
  10474. }
  10475. func (c *HisApiController) GetHisMonthChargePatientList() {
  10476. record_date := c.GetString("record_date")
  10477. start_time := c.GetString("start_time")
  10478. end_time := c.GetString("end_time")
  10479. timeLayout := "2006-01-02"
  10480. loc, _ := time.LoadLocation("Local")
  10481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10482. if err != nil {
  10483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10484. return
  10485. }
  10486. if err != nil {
  10487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10488. return
  10489. }
  10490. recordDateTime := theTime.Unix()
  10491. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10492. if err != nil {
  10493. }
  10494. startRecordDateTime := startTime.Unix()
  10495. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10496. if err != nil {
  10497. }
  10498. endRecordDateTime := endTime.Unix()
  10499. adminInfo := c.GetAdminUserInfo()
  10500. var tempMonthChargePatients []*service.MonthChargePatients
  10501. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10502. for _, item := range tempPatients {
  10503. //过滤没有处方的
  10504. if len(item.HisPrescription) == 0 {
  10505. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10506. }
  10507. }
  10508. c.ServeSuccessJSON(map[string]interface{}{
  10509. "list": tempMonthChargePatients,
  10510. })
  10511. }
  10512. // PrescriptionDifference 医嘱数量差值结构体
  10513. type PrescriptionDrugDifference struct {
  10514. DrugID int64 //基础库药品id
  10515. ID int64 //医嘱id
  10516. Difference float64 //差值
  10517. Unit string //单位
  10518. }
  10519. type PrescriptionGoodDifference struct {
  10520. GoodID int64 //基础库项目耗材id
  10521. ID int64 //医嘱id
  10522. Difference int64 //差值
  10523. Unit string //单位
  10524. Type int64 //类型
  10525. }
  10526. type EditCustomData struct {
  10527. adviceList []*models.HisDoctorAdviceInfo
  10528. projectList []*models.HisPrescriptionProject
  10529. }
  10530. type SrcCustomData struct {
  10531. adviceList []*models.HisDoctorAdviceInfo
  10532. projectList []*models.HisPrescriptionProject
  10533. }
  10534. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  10535. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  10536. differences := make([]*PrescriptionDrugDifference, 0)
  10537. // 创建一个 map 来存储第一个切片中的药品信息
  10538. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  10539. for _, advice := range firstPrescription {
  10540. firstMap[advice.DrugId] = advice
  10541. }
  10542. // 遍历第二个切片中的药品信息,并比较数量差值
  10543. for _, advice := range secondPrescription {
  10544. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  10545. diff := &PrescriptionDrugDifference{
  10546. DrugID: advice.DrugId,
  10547. ID: firstAdvice.ID,
  10548. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  10549. Unit: firstAdvice.PrescribingNumberUnit,
  10550. }
  10551. differences = append(differences, diff)
  10552. }
  10553. }
  10554. return differences
  10555. }
  10556. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  10557. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  10558. differences := make([]*PrescriptionGoodDifference, 0)
  10559. // 创建一个 map 来存储第一个切片中的耗材信息
  10560. firstMap := make(map[int64]*models.HisPrescriptionProject)
  10561. for _, good := range firstPrescription {
  10562. firstMap[good.ProjectId] = good
  10563. }
  10564. // 遍历第二个切片中的耗材信息,并比较数量差值
  10565. for _, good := range secondPrescription {
  10566. if firstGood, ok := firstMap[good.ProjectId]; ok {
  10567. count, _ := strconv.ParseInt(good.Count, 10, 64)
  10568. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  10569. diff := &PrescriptionGoodDifference{
  10570. GoodID: good.ProjectId,
  10571. ID: firstGood.ID,
  10572. Difference: count - firstCount,
  10573. Unit: firstGood.Unit,
  10574. Type: firstGood.Type,
  10575. }
  10576. differences = append(differences, diff)
  10577. }
  10578. }
  10579. return differences
  10580. }
  10581. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  10582. var adviceList []*models.HisDoctorAdviceInfo
  10583. var projectList []*models.HisPrescriptionProject
  10584. var advice_ids []int64
  10585. var project_ids []int64
  10586. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10587. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10588. //var tempPrescription *models.HisPrescriptionProjectscription
  10589. if len(prescriptions) > 0 {
  10590. for _, item := range prescriptions {
  10591. items := item.(map[string]interface{})
  10592. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10593. advices := items["advices"].([]interface{})
  10594. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10595. groupNo := int64(0)
  10596. ctime := time.Now().Unix()
  10597. mtime := ctime
  10598. if len(advices) > 0 {
  10599. for _, advice := range advices {
  10600. var s models.HisDoctorAdviceInfo
  10601. s.AdviceType = 2
  10602. s.StopState = 2
  10603. s.ExecutionState = 2
  10604. s.Status = 1
  10605. s.Groupno = groupNo
  10606. s.CreatedTime = ctime
  10607. s.UpdatedTime = mtime
  10608. s.IsSettle = 2
  10609. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  10610. //存储切片中
  10611. if s.ID > 0 {
  10612. advice_ids = append(advice_ids, s.ID)
  10613. adviceList = append(adviceList, &s)
  10614. }
  10615. }
  10616. }
  10617. }
  10618. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10619. projects := items["project"].([]interface{})
  10620. if len(projects) > 0 {
  10621. for _, project := range projects {
  10622. var p models.HisPrescriptionProject
  10623. p.Ctime = time.Now().Unix()
  10624. p.Mtime = time.Now().Unix()
  10625. p.Status = 1
  10626. SetProjectWithJSON(&p, project.(map[string]interface{}))
  10627. if p.ID > 0 {
  10628. project_ids = append(project_ids, p.ID)
  10629. projectList = append(projectList, &p)
  10630. }
  10631. }
  10632. }
  10633. }
  10634. }
  10635. }
  10636. }
  10637. editCustomData.projectList = projectList
  10638. editCustomData.adviceList = adviceList
  10639. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  10640. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  10641. srcCustomData.adviceList = list
  10642. srcCustomData.projectList = list2
  10643. return
  10644. }