his_api_controller.go 325KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "drugs": drugs,
  763. "advices_template": advices,
  764. "drugways": drugways,
  765. "efs": efs,
  766. "doctors": doctors,
  767. "department": department,
  768. "sick": sick,
  769. "additions": additions,
  770. "diagnose": diagnose,
  771. "manufacturers": manufacturers,
  772. })
  773. }
  774. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  775. //获取所有基础药
  776. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  777. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  778. if config.ID > 0 && config.IsOpen == 1 {
  779. for _, item := range drugs {
  780. var index = 0
  781. for _, subItem := range item.OtherDrugWarehouseInfo {
  782. if index == 0 {
  783. index = index + 1
  784. if subItem.RetailPrice > 0 {
  785. item.MinPrice = subItem.RetailPrice
  786. }
  787. }
  788. }
  789. }
  790. }
  791. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  792. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  793. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  794. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  795. //获取所有科室信息
  796. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  797. //获取诊断信息
  798. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  799. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  800. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "drugs": drugs,
  803. "advices_template": advices,
  804. "drugways": drugways,
  805. "efs": efs,
  806. "doctors": doctors,
  807. "department": department,
  808. "sick": sick,
  809. "additions": additions,
  810. "diagnose": diagnose,
  811. "manufacturers": manufacturers,
  812. })
  813. }
  814. }
  815. func (c *HisApiController) CreateHisPrescription() {
  816. record_date := c.GetString("record_date")
  817. patient_id, _ := c.GetInt64("patient_id")
  818. reg_type, _ := c.GetInt64("reg_type")
  819. diagnose := c.GetString("diagnose")
  820. sick_type, _ := c.GetInt64("sick_type")
  821. sick_history := c.GetString("sick_history")
  822. doctor_id, _ := c.GetInt64("doctor", 0)
  823. department, _ := c.GetInt64("department", 0)
  824. his_patient_id, _ := c.GetInt64("his_patient_id")
  825. p_type, _ := c.GetInt64("p_type")
  826. dataBody := make(map[string]interface{}, 0)
  827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  828. if err != nil {
  829. utils.ErrorLog(err.Error())
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. adminInfo := c.GetAdminUserInfo()
  841. recordDateTime := theTime.Unix()
  842. //查询默认出库仓库库存
  843. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  844. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  845. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  847. if len(lists) == 1 {
  848. his_patient_id = lists[0].ID
  849. }
  850. }
  851. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  852. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  853. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  854. //已发药和已收费限制逻辑
  855. isMidicine := false
  856. isCharge := false
  857. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  858. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  859. if len(prescriptions) > 0 {
  860. for _, item := range prescriptions {
  861. items := item.(map[string]interface{})
  862. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  863. utils.ErrorLog("id")
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. id := int64(items["id"].(float64))
  868. if id > 0 {
  869. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  870. if err != nil {
  871. if new_prescription.OrderStatus == 4 {
  872. isCharge = true
  873. }
  874. }
  875. }
  876. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  877. advices := items["advices"].([]interface{})
  878. if len(advices) > 0 {
  879. for _, advice := range advices {
  880. var adviceId int64
  881. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  882. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  883. }
  884. if adviceId > 0 {
  885. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  886. if err == nil {
  887. if his_advice_info.IsMedicine == 1 {
  888. isMidicine = true
  889. }
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. }
  897. }
  898. if isMidicine == true {
  899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  900. return
  901. }
  902. if isCharge == true {
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  904. return
  905. }
  906. //已发药和已收费限制逻辑
  907. if drugStockConfig.IsOpen == 1 {
  908. //校验库存总量
  909. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  910. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  911. if len(prescriptions) > 0 {
  912. for _, item := range prescriptions {
  913. items := item.(map[string]interface{})
  914. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  915. advices := items["advices"].([]interface{})
  916. if len(advices) > 0 {
  917. for _, advice := range advices {
  918. var drug_id int64
  919. var prescribing_number float64
  920. var prescribingNumberUnit string
  921. var adviceId int64
  922. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  923. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  924. }
  925. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  926. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  927. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  928. }
  929. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  930. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  931. }
  932. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  933. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  934. }
  935. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  936. if drug.ID == 0 {
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. //查询药品的所有库存
  941. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  942. var total_count int64
  943. for _, it := range list {
  944. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  945. }
  946. totals := strconv.FormatInt(total_count, 10)
  947. //查询该药品是否存在开药记录
  948. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  949. //查询最新批次库存
  950. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  951. var batch_number_count int64
  952. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  953. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  954. //新增处方
  955. if advicelist.ID == 0 {
  956. all_count, _ := strconv.ParseFloat(totals, 64)
  957. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  958. if prescribingNumberUnit == drug.MinUnit {
  959. if drug.IsUse != 1 {
  960. if prescribing_number > all_count {
  961. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  962. return
  963. }
  964. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  965. if prescribing_number > batch_number_all_count {
  966. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  967. return
  968. }
  969. }
  970. }
  971. }
  972. if prescribingNumberUnit == drug.MaxUnit {
  973. num := prescribing_number * float64(drug.MinNumber)
  974. if drug.IsUse != 1 {
  975. if num > all_count {
  976. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  977. return
  978. }
  979. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  980. if num > batch_number_all_count {
  981. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  982. return
  983. }
  984. }
  985. }
  986. }
  987. }
  988. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  989. if drugOutConfig.IsOpen != 1 {
  990. //修改处方
  991. for _, advice := range advices {
  992. var drug_id int64
  993. var prescribing_number float64
  994. var prescribingNumberUnit string
  995. var prescribingNumber string
  996. var adviceId int64
  997. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  998. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  999. }
  1000. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1001. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1002. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1003. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1004. }
  1005. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1006. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1007. }
  1008. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1009. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1010. }
  1011. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1012. if drug.ID == 0 {
  1013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1014. return
  1015. }
  1016. //查询药品的所有库存
  1017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1018. var total_count int64
  1019. for _, it := range list {
  1020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1021. }
  1022. totals := strconv.FormatInt(total_count, 10)
  1023. //查询该药品是否存在开药记录
  1024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1025. //新增处方
  1026. if advicelist.ID == 0 {
  1027. //查询最新批次库存
  1028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1029. var batch_number_count int64
  1030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1032. all_count, _ := strconv.ParseFloat(totals, 64)
  1033. if prescribingNumberUnit == drug.MinUnit {
  1034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1035. if drug.IsUse != 1 {
  1036. if prescribing_number > all_count {
  1037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1038. return
  1039. }
  1040. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1041. if prescribing_number > batch_number_all_count {
  1042. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1043. return
  1044. }
  1045. }
  1046. }
  1047. } else {
  1048. if prescribingNumberUnit == drug.MaxUnit {
  1049. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1050. num := prescribing_number * float64(drug.MinNumber)
  1051. if drug.IsUse != 1 {
  1052. if num > all_count {
  1053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1054. return
  1055. }
  1056. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1057. if prescribing_number > batch_number_all_count {
  1058. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1059. return
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. //修改处方
  1067. if advicelist.ID > 0 {
  1068. //查询最新批次库存
  1069. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1070. var batch_number_count int64
  1071. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1072. var device_number int64
  1073. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1074. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1075. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1076. device_number = prescribingNumberInt * drug.MinNumber
  1077. }
  1078. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1079. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1080. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1081. device_number = prescribingNumberInt
  1082. }
  1083. var number_count int64
  1084. if prescribingNumberUnit == drug.MaxUnit {
  1085. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1086. number_count = prescribingNumberInt * drug.MinNumber
  1087. }
  1088. if prescribingNumberUnit == drug.MinUnit {
  1089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1090. number_count = prescribingNumberInt
  1091. }
  1092. //如果修改的数量大于之前修改的数量
  1093. if (number_count - device_number) > 0 {
  1094. //如果修改的差数量 大于库存数量
  1095. if drug.IsUse != 1 {
  1096. if (number_count - device_number) > total_count {
  1097. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1098. return
  1099. }
  1100. if (number_count - device_number) > batch_number_count {
  1101. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1102. return
  1103. }
  1104. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
  1105. // 查询该药品最后一次出库记录
  1106. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1107. var out_count int64
  1108. var in_count int64
  1109. var stock_max_number int64
  1110. var stock_min_number int64
  1111. for _, it := range outInfo {
  1112. if it.CountUnit == drug.MaxUnit {
  1113. it.Count = it.Count * drug.MinNumber
  1114. }
  1115. out_count += it.Count
  1116. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1117. stock_max_number = warehouseInfoList.StockMaxNumber
  1118. stock_min_number = warehouseInfoList.StockMinNumber
  1119. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1120. }
  1121. if out_count > 0 {
  1122. if (number_count - device_number) > in_count {
  1123. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1124. return
  1125. }
  1126. }
  1127. // 未出库
  1128. if out_count == 0 {
  1129. var sum_in_count int64
  1130. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1131. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1132. fmt.Println("sum_in_count", sum_in_count)
  1133. //如果修改的数量大于有库存的第一个批次
  1134. if number_count > sum_in_count {
  1135. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1136. return
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1143. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1144. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1145. if pharmacyConfig.IsOpen != 1 {
  1146. if device_number != number_count {
  1147. // 查询该药品最后一次出库记录
  1148. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1149. //回退库存
  1150. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1151. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1152. }
  1153. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1154. var stock_max_number int64
  1155. var stock_min_number int64
  1156. if number_count >= drug.MinNumber {
  1157. stock_max_number = device_number / drug.MinNumber
  1158. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1159. stock_min_number = device_number % drug.MinNumber
  1160. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1161. } else {
  1162. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1163. }
  1164. }
  1165. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1166. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1167. }
  1168. //删除记录
  1169. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1170. //查询默认仓库剩余多少库存
  1171. var sum_count int64
  1172. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1173. for _, its := range stockInfo {
  1174. if its.MaxUnit == drug.MaxUnit {
  1175. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1176. }
  1177. sum_count += its.StockMaxNumber + its.StockMinNumber
  1178. }
  1179. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. //保存处方开药
  1186. if drugOutConfig.IsOpen == 1 {
  1187. //修改处方
  1188. for _, advice := range advices {
  1189. var drug_id int64
  1190. var prescribing_number float64
  1191. var prescribingNumberUnit string
  1192. var prescribingNumber string
  1193. var adviceId int64
  1194. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1195. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1196. }
  1197. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1198. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1199. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1200. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1201. }
  1202. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1203. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1204. }
  1205. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1206. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1207. }
  1208. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1209. if drug.ID == 0 {
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1211. return
  1212. }
  1213. //查询药品的所有库存
  1214. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1215. var total_count int64
  1216. for _, it := range list {
  1217. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1218. }
  1219. totals := strconv.FormatInt(total_count, 10)
  1220. //查询该药品是否存在开药记录
  1221. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1222. //新增处方
  1223. if advicelist.ID == 0 {
  1224. //查询最新批次库存
  1225. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1226. var batch_number_count int64
  1227. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1228. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1229. all_count, _ := strconv.ParseFloat(totals, 64)
  1230. if prescribingNumberUnit == drug.MinUnit {
  1231. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1232. if drug.IsUse != 1 {
  1233. if prescribing_number > all_count {
  1234. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1235. return
  1236. }
  1237. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1238. if prescribing_number > batch_number_all_count {
  1239. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1240. return
  1241. }
  1242. }
  1243. }
  1244. } else {
  1245. if prescribingNumberUnit == drug.MaxUnit {
  1246. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1247. num := prescribing_number * float64(drug.MinNumber)
  1248. if drug.IsUse != 1 {
  1249. if num > all_count {
  1250. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1251. return
  1252. }
  1253. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1254. if prescribing_number > batch_number_all_count {
  1255. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1256. return
  1257. }
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. //修改处方
  1264. if advicelist.ID > 0 {
  1265. //查询最新批次库存
  1266. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1267. var batch_number_count int64
  1268. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1269. var device_number int64
  1270. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1271. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1272. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1273. device_number = prescribingNumberInt * drug.MinNumber
  1274. }
  1275. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1276. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1277. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1278. device_number = prescribingNumberInt
  1279. }
  1280. var number_count int64
  1281. if prescribingNumberUnit == drug.MaxUnit {
  1282. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1283. number_count = prescribingNumberInt * drug.MinNumber
  1284. }
  1285. if prescribingNumberUnit == drug.MinUnit {
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1287. number_count = prescribingNumberInt
  1288. }
  1289. //如果修改的数量大于之前修改的数量
  1290. if (number_count - device_number) > 0 {
  1291. //如果修改的差数量 大于库存数量
  1292. if drug.IsUse != 1 {
  1293. if (number_count - device_number) > total_count {
  1294. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1295. return
  1296. }
  1297. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1298. if (number_count - device_number) > batch_number_count {
  1299. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1300. return
  1301. }
  1302. }
  1303. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1304. //查询历史出库数据总批次
  1305. // 查询该药品最后一次出库记录
  1306. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1307. var out_count int64
  1308. var in_count int64
  1309. var stock_max_number int64
  1310. var stock_min_number int64
  1311. for _, it := range outInfo {
  1312. if it.CountUnit == drug.MaxUnit {
  1313. it.Count = it.Count * drug.MinNumber
  1314. }
  1315. out_count += it.Count
  1316. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1317. stock_max_number = warehouseInfoList.StockMaxNumber
  1318. stock_min_number = warehouseInfoList.StockMinNumber
  1319. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1320. }
  1321. if out_count > 0 {
  1322. if (number_count - device_number) > in_count {
  1323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1324. return
  1325. }
  1326. }
  1327. // 未出库
  1328. if out_count == 0 {
  1329. var sum_in_count int64
  1330. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1331. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1332. //如果修改的数量大于有库存的第一个批次
  1333. if number_count > sum_in_count {
  1334. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1335. return
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. if stockConfig.IsOpen == 1 {
  1352. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1353. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1354. if len(prescriptions) > 0 {
  1355. for _, item := range prescriptions {
  1356. items := item.(map[string]interface{})
  1357. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1358. projects := items["project"].([]interface{})
  1359. if len(projects) > 0 {
  1360. for _, project := range projects {
  1361. var project_id int64
  1362. var project_type int64
  1363. var totals float64
  1364. var project_name string
  1365. var parsetotal int64
  1366. var id int64
  1367. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1368. id = int64(project.(map[string]interface{})["id"].(float64))
  1369. }
  1370. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1371. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1372. }
  1373. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1374. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1375. }
  1376. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1377. total, _ := project.(map[string]interface{})["total"].(string)
  1378. totals, _ = strconv.ParseFloat(total, 64)
  1379. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1380. }
  1381. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1382. project_name = project.(map[string]interface{})["project_name"].(string)
  1383. }
  1384. if project_type == 3 {
  1385. //查找该耗材的出库记录
  1386. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1387. if len(goodWarehouseInfo) == 0 {
  1388. //查询耗材库存
  1389. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1390. var stock_count int64
  1391. for _, it := range list {
  1392. stock_count += it.StockCount
  1393. }
  1394. stock_counts := strconv.FormatInt(stock_count, 10)
  1395. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1396. if totals > stock_total_count {
  1397. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1398. return
  1399. }
  1400. //查找今日该患者已经出库的所有耗材
  1401. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1402. for _, item := range goodList {
  1403. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1404. var flush_count int64
  1405. for _, it := range goodListSix {
  1406. flush_count += it.StockCount
  1407. }
  1408. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1409. creater := adminInfo.AdminUser.Id
  1410. if errs != nil {
  1411. goodErrcode := models.XtGoodErrcode{
  1412. UserOrgId: item.OrgId,
  1413. Errcode: "手动出库更新剩余出库失败",
  1414. GoodId: item.GoodId,
  1415. Status: 1,
  1416. Ctime: time.Now().Unix(),
  1417. Mtime: 0,
  1418. Count: 0,
  1419. StockCount: 0,
  1420. Creater: creater,
  1421. BatchNumberId: 0,
  1422. WarehouseOutId: 0,
  1423. }
  1424. service.CreateGoodErrcode(goodErrcode)
  1425. }
  1426. }
  1427. //删除记录
  1428. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1429. }
  1430. if len(goodWarehouseInfo) > 0 {
  1431. //查询该患者耗材的历史数据
  1432. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1433. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1434. //数量发生改变
  1435. if parsetotal != count {
  1436. //查找今日该患者已经出库的所有耗材
  1437. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1438. for _, item := range goodList {
  1439. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1440. var flush_count int64
  1441. for _, it := range goodListSix {
  1442. flush_count += it.StockCount
  1443. }
  1444. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1445. //减少出库数量
  1446. creater := adminInfo.AdminUser.Id
  1447. if errs != nil {
  1448. goodErrcode := models.XtGoodErrcode{
  1449. UserOrgId: item.OrgId,
  1450. Errcode: "手动出库更新剩余出库失败",
  1451. GoodId: item.GoodId,
  1452. Status: 1,
  1453. Ctime: time.Now().Unix(),
  1454. Mtime: 0,
  1455. Count: 0,
  1456. StockCount: 0,
  1457. Creater: creater,
  1458. BatchNumberId: 0,
  1459. WarehouseOutId: 0,
  1460. }
  1461. service.CreateGoodErrcode(goodErrcode)
  1462. }
  1463. //查询默认仓库
  1464. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1465. var total_count int64
  1466. for _, it := range stockList {
  1467. total_count += it.StockCount
  1468. }
  1469. //基础库插入数据
  1470. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1471. }
  1472. //删除记录
  1473. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1474. }
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1485. var hpInfo models.HisPrescriptionInfo
  1486. if info.ID == 0 {
  1487. var randNum int
  1488. randNum = rand.Intn(10000) + 1000
  1489. timestamp := time.Now().Unix()
  1490. tempTime := time.Unix(timestamp, 0)
  1491. timeFormat := tempTime.Format("20060102150405")
  1492. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1493. hpInfo = models.HisPrescriptionInfo{
  1494. HisPatientId: his_patient_id,
  1495. UserOrgId: adminInfo.CurrentOrgId,
  1496. RecordDate: theTime.Unix(),
  1497. PatientId: patient_id,
  1498. Status: 1,
  1499. Ctime: time.Now().Unix(),
  1500. Mtime: time.Now().Unix(),
  1501. Creator: adminInfo.AdminUser.Id,
  1502. Modifier: adminInfo.AdminUser.Id,
  1503. Diagnosis: diagnose,
  1504. SickHistory: sick_history,
  1505. Departments: department,
  1506. RegisterType: reg_type,
  1507. PrescriptionNumber: p_number,
  1508. PrescriptionStatus: 1,
  1509. Doctor: role.UserName,
  1510. DoctorId: doctor_id,
  1511. SickType: sick_type,
  1512. PType: p_type,
  1513. }
  1514. service.SavePatientPrescriptionInfo(hpInfo)
  1515. redis := service.RedisClient()
  1516. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1517. redis.Set(key, "", time.Second)
  1518. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1519. redis.Set(keyOne, "", time.Second)
  1520. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1521. redis.Set(keySeven, "", time.Second)
  1522. defer redis.Close()
  1523. } else {
  1524. hpInfo = models.HisPrescriptionInfo{
  1525. ID: info.ID,
  1526. UserOrgId: adminInfo.CurrentOrgId,
  1527. RecordDate: info.RecordDate,
  1528. PatientId: info.PatientId,
  1529. Status: 1,
  1530. Ctime: info.Ctime,
  1531. Mtime: time.Now().Unix(),
  1532. Creator: info.Creator,
  1533. Modifier: adminInfo.AdminUser.Id,
  1534. Diagnosis: diagnose,
  1535. SickHistory: sick_history,
  1536. Departments: department,
  1537. RegisterType: reg_type,
  1538. PrescriptionNumber: info.PrescriptionNumber,
  1539. Doctor: role.UserName,
  1540. PrescriptionStatus: info.PrescriptionStatus,
  1541. DoctorId: doctor_id,
  1542. SickType: sick_type,
  1543. PType: info.PType,
  1544. HisPatientId: info.HisPatientId,
  1545. }
  1546. service.SavePatientPrescriptionInfo(hpInfo)
  1547. redis := service.RedisClient()
  1548. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1549. redis.Set(key, "", time.Second)
  1550. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1551. redis.Set(keyOne, "", time.Second)
  1552. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1553. redis.Set(keySeven, "", time.Second)
  1554. defer redis.Close()
  1555. }
  1556. //定义切片
  1557. var adviceList []models.HisDoctorAdviceInfo
  1558. var projectList []models.HisPrescriptionProject
  1559. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1560. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1561. var tempPrescription *models.HisPrescription
  1562. if len(prescriptions) > 0 {
  1563. for _, item := range prescriptions {
  1564. items := item.(map[string]interface{})
  1565. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1566. utils.ErrorLog("id")
  1567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1568. return
  1569. }
  1570. id := int64(items["id"].(float64))
  1571. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1572. tempPrescription = &new_prescription
  1573. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1574. utils.ErrorLog("type")
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1576. return
  1577. }
  1578. types := int64(items["type"].(float64))
  1579. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1580. utils.ErrorLog("med_type")
  1581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1582. return
  1583. }
  1584. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1585. if med_type == "0" {
  1586. med_type = "14"
  1587. }
  1588. //if order_status == 0 {
  1589. // order_status = 1
  1590. //}
  1591. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1592. utils.ErrorLog("pre_time")
  1593. }
  1594. preTime, _ := items["pre_time"].(string)
  1595. timeLayout := "2006-01-02"
  1596. loc, _ := time.LoadLocation("Local")
  1597. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1598. if err != nil {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. pTime := theTime2.Unix()
  1603. ctime := time.Now().Unix()
  1604. if tempPrescription.ID == 0 {
  1605. prescription := &models.HisPrescription{
  1606. ID: 0,
  1607. PatientId: patient_id,
  1608. UserOrgId: adminInfo.CurrentOrgId,
  1609. RecordDate: recordDateTime,
  1610. Ctime: ctime,
  1611. Mtime: ctime,
  1612. Type: types,
  1613. Modifier: adminInfo.AdminUser.Id,
  1614. Creator: adminInfo.AdminUser.Id,
  1615. Status: 1,
  1616. Doctor: role.UserName,
  1617. HisPatientId: his_patient_id,
  1618. OrderStatus: 1,
  1619. BatchNumber: "",
  1620. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1621. PreTime: pTime,
  1622. PType: p_type,
  1623. MedType: med_type,
  1624. }
  1625. tempPrescription = prescription
  1626. service.SaveHisPrescription(tempPrescription)
  1627. redis := service.RedisClient()
  1628. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1629. redis.Set(key, "", time.Second)
  1630. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1631. redis.Set(keyOne, "", time.Second)
  1632. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1633. redis.Set(keySeven, "", time.Second)
  1634. defer redis.Close()
  1635. } else {
  1636. tempPrescription.ID = id
  1637. tempPrescription.Type = types
  1638. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1639. tempPrescription.Mtime = time.Now().Unix()
  1640. tempPrescription.Doctor = role.UserName
  1641. //tempPrescription.OrderStatus = order_status
  1642. tempPrescription.PreTime = pTime
  1643. tempPrescription.MedType = med_type
  1644. service.SaveHisPrescription(tempPrescription)
  1645. redis := service.RedisClient()
  1646. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1647. redis.Set(key, "", time.Second)
  1648. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1649. redis.Set(keyOne, "", time.Second)
  1650. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1651. redis.Set(keySeven, "", time.Second)
  1652. defer redis.Close()
  1653. }
  1654. //service.SaveHisPrescription(prescription)
  1655. //更改患者挂号状态
  1656. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1657. fmt.Println("更改失败", err2)
  1658. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1659. advices := items["advices"].([]interface{})
  1660. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1661. groupNo := int64(0)
  1662. ctime := time.Now().Unix()
  1663. mtime := ctime
  1664. if len(advices) > 0 {
  1665. for _, advice := range advices {
  1666. var s models.HisDoctorAdviceInfo
  1667. s.PrescriptionId = tempPrescription.ID
  1668. s.AdviceType = 2
  1669. s.AdviceDoctor = doctor_id
  1670. s.StopState = 2
  1671. s.ExecutionState = 2
  1672. s.AdviceDate = recordDateTime
  1673. s.Status = 1
  1674. s.UserOrgId = adminInfo.CurrentOrgId
  1675. s.RecordDate = recordDateTime
  1676. s.StartTime = tempPrescription.PreTime
  1677. s.Groupno = groupNo
  1678. s.CreatedTime = ctime
  1679. s.UpdatedTime = mtime
  1680. s.PatientId = patient_id
  1681. s.HisPatientId = his_patient_id
  1682. s.StartTime = pTime
  1683. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1684. if errcode > 0 {
  1685. c.ServeFailJSONWithSGJErrorCode(errcode)
  1686. return
  1687. }
  1688. s.StartTime = pTime
  1689. var total_count int64 //处方总库存
  1690. //查询改药品信息
  1691. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1692. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1693. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1694. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1695. total_count += prescribingNumberSeven * medical.MinNumber
  1696. }
  1697. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1698. total_count += prescribingNumberSeven
  1699. }
  1700. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1701. total_count += prescribingNumberSeven
  1702. }
  1703. service.CreateHisDoctorAdvice(&s)
  1704. //存储切片中
  1705. adviceList = append(adviceList, s)
  1706. redis := service.RedisClient()
  1707. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1708. redis.Set(key, "", time.Second)
  1709. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1710. redis.Set(keyOne, "", time.Second)
  1711. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1712. redis.Set(keySeven, "", time.Second)
  1713. var randNum int
  1714. randNum = rand.Intn(10000) + 1000
  1715. timestamp := time.Now().Unix()
  1716. tempTime := time.Unix(timestamp, 0)
  1717. timeFormat := tempTime.Format("20060102150405")
  1718. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1719. service.CreateHisDoctorAdvice(&s)
  1720. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1721. redis.Set(keySix, "", time.Second)
  1722. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1723. redis.Set(keyFive, "", time.Second)
  1724. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1725. redis.Set(keyEight, "", time.Second)
  1726. defer redis.Close()
  1727. }
  1728. }
  1729. }
  1730. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1731. projects := items["project"].([]interface{})
  1732. if len(projects) > 0 {
  1733. for _, project := range projects {
  1734. var p models.HisPrescriptionProject
  1735. p.PrescriptionId = tempPrescription.ID
  1736. p.Ctime = time.Now().Unix()
  1737. p.Mtime = time.Now().Unix()
  1738. p.PatientId = patient_id
  1739. p.RecordDate = recordDateTime
  1740. p.Doctor = doctor_id
  1741. p.UserOrgId = adminInfo.CurrentOrgId
  1742. p.HisPatientId = his_patient_id
  1743. p.Status = 1
  1744. p.StartTime = pTime
  1745. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1746. if errcode > 0 {
  1747. c.ServeFailJSONWithSGJErrorCode(errcode)
  1748. return
  1749. }
  1750. fmt.Println("projext22222222222222", p.ID)
  1751. if p.ID == 0 {
  1752. p.IsOut = 2
  1753. }
  1754. if p.ID > 0 {
  1755. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  1756. p.IsOut = projectDetail.IsOut
  1757. }
  1758. service.CreateHisProjectTwo(&p)
  1759. projectList = append(projectList, p)
  1760. var randNum int
  1761. randNum = rand.Intn(10000) + 1000
  1762. timestamp := time.Now().Unix()
  1763. tempTime := time.Unix(timestamp, 0)
  1764. timeFormat := tempTime.Format("20060102150405")
  1765. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1766. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1767. //新增或者编辑项目,修改对应的标签数据
  1768. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1769. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1770. var label models.HisLabelPrintInfo
  1771. project, _ := service.GetProjectDetail(p.ProjectId)
  1772. if project.CostClassify == 3 { //类别为检验检查
  1773. if p.TeamId > 0 { //检验检查组套
  1774. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1775. if tempLabel.ID == 0 {
  1776. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1777. label.Number = tempPrescription.PrescriptionNumber
  1778. label.ProjectId = project.ID
  1779. label.Status = 1
  1780. label.IsPrint = 2
  1781. label.DoctorId = info.DoctorId
  1782. label.UserOrgId = p.UserOrgId
  1783. label.PatientId = patient_id
  1784. label.RecordDate = recordDateTime
  1785. label.Ctime = time.Now().Unix()
  1786. label.Mtime = time.Now().Unix()
  1787. label.ItemId = p.TeamId
  1788. label.FeedetlSn = p.FeedetlSn
  1789. label.PProjectId = p.ID
  1790. label.ProjectName = team.ProjectTeam
  1791. label.PatientName = patient.Name
  1792. service.CreateHisLabelRecord(&label)
  1793. }
  1794. } else { //单条检验检查项目
  1795. label.Number = tempPrescription.PrescriptionNumber
  1796. label.ProjectId = project.ID
  1797. label.Status = 1
  1798. label.DoctorId = info.DoctorId
  1799. label.UserOrgId = p.UserOrgId
  1800. label.PatientId = patient_id
  1801. label.RecordDate = recordDateTime
  1802. label.IsPrint = 2
  1803. label.Ctime = time.Now().Unix()
  1804. label.Mtime = time.Now().Unix()
  1805. label.FeedetlSn = p.FeedetlSn
  1806. label.PProjectId = p.ID
  1807. label.ItemId = p.TeamId
  1808. label.ProjectName = project.ProjectName
  1809. label.PatientName = patient.Name
  1810. service.CreateHisLabelRecord(&label)
  1811. }
  1812. }
  1813. }
  1814. }
  1815. service.SaveHisProjectTwo(&p)
  1816. }
  1817. }
  1818. }
  1819. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1820. // addition := items["addition"].([]interface{})
  1821. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1822. // ctime := time.Now().Unix()
  1823. // mtime := ctime
  1824. // if len(addition) > 0 {
  1825. // for _, item := range addition {
  1826. // var s models.HisAdditionalCharge
  1827. // s.PrescriptionId = tempPrescription.ID
  1828. // s.Status = 1
  1829. // s.UserOrgId = adminInfo.CurrentOrgId
  1830. // s.RecordDate = recordDateTime
  1831. // s.CreatedTime = ctime
  1832. // s.UpdatedTime = mtime
  1833. // s.PatientId = patient_id
  1834. // s.HisPatientId = his_patient_id
  1835. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1836. // if errcode > 0 {
  1837. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1838. // return
  1839. // }
  1840. // service.CreateAdditionalCharge(&s)
  1841. // var randNum int
  1842. // randNum = rand.Intn(10000) + 1000
  1843. // timestamp := time.Now().Unix()
  1844. // tempTime := time.Unix(timestamp, 0)
  1845. // timeFormat := tempTime.Format("20060102150405")
  1846. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1847. // service.CreateAdditionalCharge(&s)
  1848. //
  1849. // }
  1850. // }
  1851. //}
  1852. }
  1853. }
  1854. //查询今日该患者开的药品处方
  1855. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1856. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1857. if drugOutConfig.IsOpen == 1 {
  1858. for _, item := range hisdoctorlist {
  1859. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1860. // 查询该药品最后一次出库记录
  1861. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1862. if len(druginfo) > 0 {
  1863. //回退库存
  1864. for _, it := range druginfo {
  1865. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1866. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1867. }
  1868. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1869. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1870. }
  1871. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1872. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1873. }
  1874. }
  1875. }
  1876. //删除记录
  1877. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1878. //查询最后一次数据
  1879. if drugOutConfig.IsOpen == 1 {
  1880. //出库
  1881. if drug.IsUse == 2 {
  1882. creater := adminInfo.AdminUser.Id
  1883. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1884. }
  1885. //更新字典里面的库存
  1886. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1887. var sum_count int64
  1888. for _, its := range stockInfo {
  1889. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1890. if its.MaxUnit == baseDrug.MaxUnit {
  1891. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1892. }
  1893. sum_count += its.StockMaxNumber + its.StockMinNumber
  1894. }
  1895. //更新基础库存
  1896. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1897. //剩余库存
  1898. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1899. }
  1900. }
  1901. }
  1902. }
  1903. //redisClient := service.RedisClient()
  1904. //defer redisClient.Close()
  1905. //
  1906. //list := models.HisList{
  1907. // Patient_id: patient_id,
  1908. // Advice_id:0,
  1909. // Record_date: 0,
  1910. // Advice: adviceList,
  1911. // Project: nil,
  1912. //}
  1913. //hisLis = append(hisLis, list)
  1914. //
  1915. //advice_json, _ := json.Marshal(&hisLis)
  1916. //redisClient.RPush("111", advice_json).Result()
  1917. //result, _ := redisClient.RPop("111").Result()
  1918. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1919. //
  1920. //var dat []map[string]interface{}
  1921. //json.Unmarshal([]byte(result), &dat)
  1922. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1923. //
  1924. //for k,v:=range dat{
  1925. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1926. //}
  1927. //project_json, _ := json.Marshal(&projectList)
  1928. //redisClient.LPush("222", project_json).Result()
  1929. if err == nil {
  1930. c.ServeSuccessJSON(map[string]interface{}{
  1931. "msg": "保存成功",
  1932. })
  1933. return
  1934. } else {
  1935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1936. return
  1937. }
  1938. }
  1939. func (c *HisApiController) EditHisPrescription() {
  1940. record_date := c.GetString("record_date")
  1941. patient_id, _ := c.GetInt64("patient_id")
  1942. reg_type, _ := c.GetInt64("reg_type")
  1943. //diagnose, _ := c.GetInt64("diagnose", 0)
  1944. diagnose := c.GetString("diagnose")
  1945. sick_type, _ := c.GetInt64("sick_type")
  1946. sick_history := c.GetString("sick_history")
  1947. doctor_id, _ := c.GetInt64("doctor", 0)
  1948. department, _ := c.GetInt64("department", 0)
  1949. his_patient_id, _ := c.GetInt64("his_patient_id")
  1950. p_type, _ := c.GetInt64("p_type")
  1951. dataBody := make(map[string]interface{}, 0)
  1952. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1953. if err != nil {
  1954. utils.ErrorLog(err.Error())
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1956. return
  1957. }
  1958. timeLayout := "2006-01-02"
  1959. loc, _ := time.LoadLocation("Local")
  1960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1961. if err != nil {
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1963. return
  1964. }
  1965. adminInfo := c.GetAdminUserInfo()
  1966. recordDateTime := theTime.Unix()
  1967. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1968. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1969. var hpInfo models.HisPrescriptionInfo
  1970. if info.ID == 0 {
  1971. var randNum int
  1972. randNum = rand.Intn(10000) + 1000
  1973. timestamp := time.Now().Unix()
  1974. tempTime := time.Unix(timestamp, 0)
  1975. timeFormat := tempTime.Format("20060102150405")
  1976. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1977. hpInfo = models.HisPrescriptionInfo{
  1978. UserOrgId: adminInfo.CurrentOrgId,
  1979. RecordDate: theTime.Unix(),
  1980. PatientId: patient_id,
  1981. Status: 1,
  1982. Ctime: time.Now().Unix(),
  1983. Mtime: time.Now().Unix(),
  1984. Creator: adminInfo.AdminUser.Id,
  1985. Modifier: adminInfo.AdminUser.Id,
  1986. Diagnosis: diagnose,
  1987. SickHistory: sick_history,
  1988. Departments: department,
  1989. RegisterType: reg_type,
  1990. PrescriptionNumber: p_number,
  1991. PrescriptionStatus: 1,
  1992. Doctor: role.UserName,
  1993. DoctorId: doctor_id,
  1994. SickType: sick_type,
  1995. PType: p_type,
  1996. }
  1997. service.SavePatientPrescriptionInfo(hpInfo)
  1998. } else {
  1999. hpInfo = models.HisPrescriptionInfo{
  2000. ID: info.ID,
  2001. UserOrgId: adminInfo.CurrentOrgId,
  2002. RecordDate: info.RecordDate,
  2003. PatientId: info.PatientId,
  2004. Status: 1,
  2005. Ctime: info.Ctime,
  2006. Mtime: time.Now().Unix(),
  2007. Creator: info.Creator,
  2008. Modifier: adminInfo.AdminUser.Id,
  2009. Diagnosis: diagnose,
  2010. SickHistory: sick_history,
  2011. Departments: department,
  2012. RegisterType: reg_type,
  2013. PrescriptionNumber: info.PrescriptionNumber,
  2014. Doctor: role.UserName,
  2015. PrescriptionStatus: info.PrescriptionStatus,
  2016. DoctorId: doctor_id,
  2017. SickType: sick_type,
  2018. PType: info.PType,
  2019. }
  2020. service.SavePatientPrescriptionInfo(hpInfo)
  2021. }
  2022. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2023. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2024. if len(prescriptions) > 0 {
  2025. for _, item := range prescriptions {
  2026. items := item.(map[string]interface{})
  2027. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2028. utils.ErrorLog("id")
  2029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2030. return
  2031. }
  2032. id := int64(items["id"].(float64))
  2033. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2034. utils.ErrorLog("type")
  2035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2036. return
  2037. }
  2038. types := int64(items["type"].(float64))
  2039. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2040. utils.ErrorLog("med_type")
  2041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2042. return
  2043. }
  2044. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2045. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2046. ctime := time.Now().Unix()
  2047. prescription := &models.HisPrescription{
  2048. ID: id,
  2049. PatientId: patient_id,
  2050. UserOrgId: adminInfo.CurrentOrgId,
  2051. RecordDate: recordDateTime,
  2052. Ctime: ctime,
  2053. Mtime: ctime,
  2054. Type: types,
  2055. Modifier: adminInfo.AdminUser.Id,
  2056. Creator: adminInfo.AdminUser.Id,
  2057. Status: 1,
  2058. Doctor: role.UserName,
  2059. HisPatientId: his_patient_id,
  2060. OrderStatus: 1,
  2061. BatchNumber: "",
  2062. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2063. PType: hpInfo.PType,
  2064. MedType: med_type,
  2065. }
  2066. if historyPrescription.ID > 0 {
  2067. prescription.PreTime = historyPrescription.PreTime
  2068. }
  2069. service.SaveHisPrescription(prescription)
  2070. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2071. advices := items["advices"].([]interface{})
  2072. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2073. groupNo := int64(0)
  2074. ctime := time.Now().Unix()
  2075. mtime := ctime
  2076. if len(advices) > 0 {
  2077. for _, advice := range advices {
  2078. var s models.HisDoctorAdviceInfo
  2079. s.PrescriptionId = prescription.ID
  2080. s.AdviceType = 2
  2081. s.AdviceDoctor = adminInfo.AdminUser.Id
  2082. s.StopState = 2
  2083. s.ExecutionState = 2
  2084. s.AdviceDate = recordDateTime
  2085. s.Status = 1
  2086. s.UserOrgId = adminInfo.CurrentOrgId
  2087. s.RecordDate = recordDateTime
  2088. s.StartTime = prescription.PreTime
  2089. s.Groupno = groupNo
  2090. s.CreatedTime = ctime
  2091. s.UpdatedTime = mtime
  2092. s.PatientId = patient_id
  2093. s.HisPatientId = his_patient_id
  2094. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2095. if errcode > 0 {
  2096. c.ServeFailJSONWithSGJErrorCode(errcode)
  2097. return
  2098. }
  2099. service.CreateHisDoctorAdvice(&s)
  2100. redis := service.RedisClient()
  2101. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2102. redis.Set(key, "", time.Second)
  2103. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2104. fmt.Println("keyOne", keyOne)
  2105. redis.Set(keyOne, "", time.Second)
  2106. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2107. redis.Set(keySeven, "", time.Second)
  2108. redis.Close()
  2109. }
  2110. }
  2111. }
  2112. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2113. projects := items["project"].([]interface{})
  2114. if len(projects) > 0 {
  2115. for _, project := range projects {
  2116. var p models.HisPrescriptionProject
  2117. p.PrescriptionId = prescription.ID
  2118. p.Ctime = time.Now().Unix()
  2119. p.Mtime = time.Now().Unix()
  2120. p.PatientId = patient_id
  2121. p.RecordDate = recordDateTime
  2122. p.UserOrgId = adminInfo.CurrentOrgId
  2123. p.HisPatientId = his_patient_id
  2124. p.Status = 1
  2125. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2126. if errcode > 0 {
  2127. c.ServeFailJSONWithSGJErrorCode(errcode)
  2128. return
  2129. }
  2130. service.CreateHisProjectTwo(&p)
  2131. }
  2132. }
  2133. }
  2134. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2135. addition := items["addition"].([]interface{})
  2136. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2137. ctime := time.Now().Unix()
  2138. mtime := ctime
  2139. if len(addition) > 0 {
  2140. for _, item := range addition {
  2141. var s models.HisAdditionalCharge
  2142. s.PrescriptionId = prescription.ID
  2143. s.Status = 1
  2144. s.UserOrgId = adminInfo.CurrentOrgId
  2145. s.RecordDate = recordDateTime
  2146. s.CreatedTime = ctime
  2147. s.UpdatedTime = mtime
  2148. s.PatientId = patient_id
  2149. s.HisPatientId = his_patient_id
  2150. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2151. if errcode > 0 {
  2152. c.ServeFailJSONWithSGJErrorCode(errcode)
  2153. return
  2154. }
  2155. service.CreateAdditionalCharge(&s)
  2156. }
  2157. }
  2158. }
  2159. }
  2160. }
  2161. }
  2162. if err == nil {
  2163. c.ServeSuccessJSON(map[string]interface{}{
  2164. "msg": "保存成功",
  2165. })
  2166. return
  2167. } else {
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2169. return
  2170. }
  2171. }
  2172. func (c *HisApiController) DeletePrescription() {
  2173. prescription_id, _ := c.GetInt64("id")
  2174. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2175. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2176. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2177. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2178. //已收费和已发药限制逻辑
  2179. isCharge := false
  2180. isMedicine := false
  2181. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2182. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2183. for _, item := range new_prescriptions {
  2184. if item.IsMedicine == 1 {
  2185. isMedicine = true
  2186. }
  2187. }
  2188. for _, item := range new_prescriptions {
  2189. if item.OrderStatus == 4 {
  2190. isCharge = true
  2191. }
  2192. }
  2193. if p_err != nil {
  2194. if new_prescription.ID > 0 {
  2195. if new_prescription.OrderStatus == 2 {
  2196. isCharge = true
  2197. }
  2198. }
  2199. }
  2200. for _, item := range advices {
  2201. if item.IsMedicine == 1 {
  2202. isMedicine = true
  2203. }
  2204. }
  2205. if isCharge {
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2207. return
  2208. }
  2209. if isMedicine {
  2210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2211. return
  2212. }
  2213. //已收费和已发药限制逻辑
  2214. if len(projects) > 0 {
  2215. for _, item := range projects {
  2216. service.DeletePrintInfo(item.ID) //删除打印信息
  2217. if stockConfig.IsOpen == 1 {
  2218. if item.Type == 3 && item.IsOut == 1 {
  2219. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2220. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2221. good.Total = good.Total + f_count
  2222. service.UpdateGoodInfo(&good)
  2223. operation_time := time.Now().Unix()
  2224. creater := c.GetAdminUserInfo().AdminUser.Id
  2225. //创建退库单
  2226. timeStr := time.Now().Format("2006-01-02")
  2227. timeArr := strings.Split(timeStr, "-")
  2228. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2229. total = total + 1
  2230. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2231. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2232. cancelStock := models.CancelStock{
  2233. OrderNumber: orderNumber,
  2234. OperaTime: operation_time,
  2235. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2236. Creater: creater,
  2237. Ctime: time.Now().Unix(),
  2238. Status: 1,
  2239. ReturnTime: item.RecordDate,
  2240. Type: 1,
  2241. StorehouseId: houseConfig.StorehouseOutInfo,
  2242. IsCheck: 1,
  2243. }
  2244. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2245. if msgerrkonde == gorm.ErrRecordNotFound {
  2246. service.AddSigleCancelStock(&cancelStock)
  2247. }
  2248. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2249. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2250. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2251. //查询该耗材是否出库
  2252. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2253. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2254. deaerler, _ := service.GetDealerById(info.Dealer)
  2255. var total_count int64
  2256. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2257. total_count += count
  2258. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2259. var flush_count int64
  2260. for _, it := range goodList {
  2261. flush_count += it.StockCount
  2262. }
  2263. if info.ID > 0 {
  2264. if info.Count >= total_count {
  2265. //回退库存
  2266. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2267. cancelStockInfo := models.CancelStockInfo{
  2268. GoodId: item.ProjectId,
  2269. CancelStockId: cancel.ID,
  2270. GoodTypeId: good.GoodTypeId,
  2271. Count: prescribingNumber,
  2272. Price: info.Price,
  2273. Total: 0,
  2274. ProductDate: info.ProductDate,
  2275. ExpiryDate: info.ExpiryDate,
  2276. Ctime: time.Now().Unix(),
  2277. Status: 1,
  2278. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2279. OrderNumber: cancel.OrderNumber,
  2280. Type: 0,
  2281. Dealer: deaerler.DealerName,
  2282. Manufacturer: manufacturer.ManufacturerName,
  2283. Number: info.Number,
  2284. RegisterAccount: "",
  2285. Remark: "",
  2286. WarehouseInfoId: info.WarehouseInfotId,
  2287. PatientId: info.PatientId,
  2288. RecordDate: info.SysRecordTime,
  2289. StorehouseId: houseConfig.StorehouseOutInfo,
  2290. IsCheck: 1,
  2291. }
  2292. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2293. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2294. flow := models.VmStockFlow{
  2295. WarehousingId: info.WarehouseInfotId,
  2296. GoodId: item.ProjectId,
  2297. Number: info.Number,
  2298. LicenseNumber: info.LicenseNumber,
  2299. Count: prescribingNumber,
  2300. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2301. PatientId: item.PatientId,
  2302. SystemTime: info.SysRecordTime,
  2303. ConsumableType: 7,
  2304. IsSys: 0,
  2305. WarehousingOrder: "",
  2306. WarehouseOutId: info.WarehouseOutId,
  2307. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2308. IsEdit: 0,
  2309. CancelStockId: cancel.ID,
  2310. CancelOrderNumber: cancel.OrderNumber,
  2311. Manufacturer: manufacturer.ID,
  2312. Dealer: 0,
  2313. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2314. UpdateCreator: 0,
  2315. Status: 1,
  2316. Ctime: time.Now().Unix(),
  2317. Mtime: 0,
  2318. Price: info.Price,
  2319. WarehousingDetailId: info.WarehouseInfotId,
  2320. WarehouseOutDetailId: info.ID,
  2321. CancelOutDetailId: cancelInfo.ID,
  2322. ProductDate: info.ProductDate,
  2323. ExpireDate: info.ExpiryDate,
  2324. StorehouseId: houseConfig.StorehouseOutInfo,
  2325. OverCount: flush_count,
  2326. }
  2327. service.CreateStockFlowOne(flow)
  2328. //退库数量增加
  2329. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2330. //出库数量减少
  2331. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2332. }
  2333. if info.Count < total_count {
  2334. //回退库存
  2335. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2336. cancelStockInfo := models.CancelStockInfo{
  2337. GoodId: item.ProjectId,
  2338. CancelStockId: cancel.ID,
  2339. GoodTypeId: good.GoodTypeId,
  2340. Count: info.Count,
  2341. Price: info.Price,
  2342. Total: 0,
  2343. ProductDate: info.ProductDate,
  2344. ExpiryDate: info.ExpiryDate,
  2345. Ctime: time.Now().Unix(),
  2346. Status: 1,
  2347. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2348. OrderNumber: cancel.OrderNumber,
  2349. Type: 0,
  2350. Dealer: deaerler.DealerName,
  2351. Manufacturer: manufacturer.ManufacturerName,
  2352. Number: info.Number,
  2353. RegisterAccount: "",
  2354. Remark: "",
  2355. WarehouseInfoId: info.WarehouseInfotId,
  2356. PatientId: info.PatientId,
  2357. RecordDate: info.SysRecordTime,
  2358. StorehouseId: houseConfig.StorehouseOutInfo,
  2359. IsCheck: 1,
  2360. }
  2361. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2362. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2363. flow := models.VmStockFlow{
  2364. WarehousingId: info.WarehouseInfotId,
  2365. GoodId: item.ProjectId,
  2366. Number: info.Number,
  2367. LicenseNumber: info.LicenseNumber,
  2368. Count: info.Count,
  2369. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2370. PatientId: item.PatientId,
  2371. SystemTime: info.SysRecordTime,
  2372. ConsumableType: 7,
  2373. IsSys: 0,
  2374. WarehousingOrder: "",
  2375. WarehouseOutId: info.WarehouseOutId,
  2376. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2377. IsEdit: 0,
  2378. CancelStockId: cancel.ID,
  2379. CancelOrderNumber: cancel.OrderNumber,
  2380. Manufacturer: manufacturer.ID,
  2381. Dealer: 0,
  2382. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2383. UpdateCreator: 0,
  2384. Status: 1,
  2385. Ctime: time.Now().Unix(),
  2386. Mtime: 0,
  2387. Price: info.Price,
  2388. WarehousingDetailId: info.WarehouseInfotId,
  2389. WarehouseOutDetailId: info.ID,
  2390. CancelOutDetailId: cancelInfo.ID,
  2391. ProductDate: info.ProductDate,
  2392. ExpireDate: info.ExpiryDate,
  2393. StorehouseId: houseConfig.StorehouseOutInfo,
  2394. OverCount: flush_count,
  2395. }
  2396. service.CreateStockFlowOne(flow)
  2397. //退库数量增加
  2398. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2399. //出库数量减少
  2400. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2401. }
  2402. //查询已出库数量
  2403. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2404. if prescribingNumber < dialysisInfo.Count {
  2405. //改变数量
  2406. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2407. }
  2408. if prescribingNumber >= dialysisInfo.Count {
  2409. //删除出库表
  2410. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2411. }
  2412. //更新库存
  2413. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2414. //更新基础库库存
  2415. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  2416. //查询今日该耗材退库数量
  2417. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2418. //var cancel_Count int64
  2419. //for _, items := range cancelInfoOne {
  2420. // cancel_Count += items.Count
  2421. //}
  2422. //
  2423. //cha_count = total_count - cancel_Count
  2424. //
  2425. //if total_count > cancel_Count {
  2426. //
  2427. // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2428. // if err == gorm.ErrRecordNotFound {
  2429. // //没有记录,则创建出库单
  2430. // timeStr := time.Now().Format("2006-01-02")
  2431. // timeArr := strings.Split(timeStr, "-")
  2432. // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2433. // total = total + 1
  2434. // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2435. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2436. // number = number + total
  2437. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2438. // warehouseOut := models.WarehouseOut{
  2439. // WarehouseOutOrderNumber: warehousing_out_order,
  2440. // OperationTime: time.Now().Unix(),
  2441. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2442. // Creater: creater,
  2443. // Ctime: time.Now().Unix(),
  2444. // Status: 1,
  2445. // WarehouseOutTime: info.SysRecordTime,
  2446. // Dealer: 0,
  2447. // Manufacturer: 0,
  2448. // Type: 1,
  2449. // IsSys: 1,
  2450. // StorehouseId: houseConfig.StorehouseOutInfo,
  2451. // IsCheck: 1,
  2452. // }
  2453. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2454. // if err != nil {
  2455. // utils.TraceLog("创建出库单失败 err = %v", err)
  2456. // return
  2457. // }
  2458. // prepare := &models.DialysisBeforePrepare{
  2459. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2460. // PatientId: info.PatientId,
  2461. // RecordDate: info.SysRecordTime,
  2462. // GoodId: item.ProjectId,
  2463. // GoodTypeId: info.GoodTypeId,
  2464. // Count: cha_count,
  2465. // StorehouseId: houseConfig.StorehouseOutInfo,
  2466. // }
  2467. // //出库
  2468. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2469. // } else if err == nil {
  2470. //
  2471. // prepare := &models.DialysisBeforePrepare{
  2472. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2473. // PatientId: info.PatientId,
  2474. // RecordDate: info.SysRecordTime,
  2475. // GoodId: item.ProjectId,
  2476. // GoodTypeId: info.GoodTypeId,
  2477. // Count: cha_count,
  2478. // StorehouseId: houseConfig.StorehouseOutInfo,
  2479. // }
  2480. // //出库
  2481. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2482. // }
  2483. //
  2484. //}
  2485. }
  2486. }
  2487. }
  2488. }
  2489. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2490. fmt.Println(err)
  2491. }
  2492. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2493. fmt.Println(err)
  2494. if len(advices) > 0 {
  2495. for _, item := range advices {
  2496. redis := service.RedisClient()
  2497. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2498. redis.Set(keyFive, "", time.Second)
  2499. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2500. redis.Set(keyOne, "", time.Second)
  2501. redis.Close()
  2502. }
  2503. }
  2504. if drugStockConfig.IsOpen == 1 {
  2505. if len(advices) > 0 {
  2506. for _, item := range advices {
  2507. creater := c.GetAdminUserInfo().AdminUser.Id
  2508. service.DrugAutoAddCancelInfo(item, creater)
  2509. }
  2510. }
  2511. }
  2512. c.ServeSuccessJSON(map[string]interface{}{
  2513. "msg": "删除成功",
  2514. })
  2515. return
  2516. }
  2517. func (c *HisApiController) DeleteDoctorAdvice() {
  2518. id, _ := c.GetInt64("id")
  2519. advice, _ := service.GetHisDoctorAdvicesById(id)
  2520. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2521. //已收费和已发药的限制逻辑
  2522. isCharge := false
  2523. isMedicine := false
  2524. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2525. //获取今天该患者所有处方,判断是否发药或者收费
  2526. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2527. for _, item := range new_prescriptions {
  2528. if item.IsMedicine == 1 {
  2529. isMedicine = true
  2530. }
  2531. }
  2532. for _, item := range new_prescriptions {
  2533. if item.OrderStatus == 4 {
  2534. isCharge = true
  2535. }
  2536. }
  2537. if isMedicine {
  2538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2539. return
  2540. }
  2541. if isCharge {
  2542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2543. return
  2544. }
  2545. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2546. for _, item := range advices {
  2547. if item.IsMedicine == 1 {
  2548. isMedicine = true
  2549. }
  2550. }
  2551. if isMedicine {
  2552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2553. return
  2554. }
  2555. if new_prescription.ID > 0 {
  2556. if new_prescription.OrderStatus == 2 {
  2557. isCharge = true
  2558. }
  2559. }
  2560. if isCharge {
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2562. return
  2563. }
  2564. //已收费和已发药的限制逻辑
  2565. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2566. redis := service.RedisClient()
  2567. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2568. redis.Set(keyFive, "", time.Second)
  2569. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2570. redis.Set(keyOne, "", time.Second)
  2571. defer redis.Close()
  2572. if err == nil {
  2573. if drugStockConfig.IsOpen == 1 {
  2574. //查询是否在处方中出库
  2575. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2576. if openConfig.IsOpen != 1 {
  2577. //判断该医嘱是否执行了
  2578. if advice.ExecutionState == 1 {
  2579. creater := c.GetAdminUserInfo().AdminUser.Id
  2580. service.DrugAutoAddCancelInfo(&advice, creater)
  2581. }
  2582. }
  2583. //开启保存处方扣减功能
  2584. if openConfig.IsOpen == 1 {
  2585. creater := c.GetAdminUserInfo().AdminUser.Id
  2586. service.DrugAutoAddCancelInfo(&advice, creater)
  2587. }
  2588. }
  2589. c.ServeSuccessJSON(map[string]interface{}{
  2590. "msg": "删除成功",
  2591. })
  2592. return
  2593. } else {
  2594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2595. return
  2596. }
  2597. }
  2598. func (c *HisApiController) DeleteProject() {
  2599. id, _ := c.GetInt64("id")
  2600. adminInfo := c.GetAdminUserInfo()
  2601. project, _ := service.GetHisProjectByID(id)
  2602. // var consumable models.DialysisBeforePrepare
  2603. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2604. isCharge := false
  2605. isMedicine := false
  2606. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2607. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2608. for _, item := range new_prescriptions {
  2609. if item.IsMedicine == 1 {
  2610. isMedicine = true
  2611. }
  2612. }
  2613. for _, item := range new_prescriptions {
  2614. if item.OrderStatus == 4 {
  2615. isCharge = true
  2616. }
  2617. }
  2618. if isMedicine {
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2620. return
  2621. }
  2622. if isCharge {
  2623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2624. return
  2625. }
  2626. if new_prescription.ID > 0 {
  2627. if new_prescription.OrderStatus == 2 {
  2628. isCharge = true
  2629. }
  2630. }
  2631. if isCharge {
  2632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2633. return
  2634. }
  2635. service.DeletePrintInfo(id)
  2636. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2637. label.Status = 0
  2638. service.CreateHisLabelRecord(&label)
  2639. if stockConfig.IsOpen == 1 {
  2640. if project.Type == 2 {
  2641. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2642. fmt.Println(err)
  2643. }
  2644. if project.Type == 3 && project.IsOut == 1 {
  2645. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2646. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2647. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2648. operation_time := time.Now().Unix()
  2649. creater := adminInfo.AdminUser.Id
  2650. //创建退库单
  2651. timeStr := time.Now().Format("2006-01-02")
  2652. timeArr := strings.Split(timeStr, "-")
  2653. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2654. total = total + 1
  2655. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2656. cancelStock := models.CancelStock{
  2657. OrderNumber: orderNumber,
  2658. OperaTime: operation_time,
  2659. OrgId: adminInfo.CurrentOrgId,
  2660. Creater: creater,
  2661. Ctime: time.Now().Unix(),
  2662. Status: 1,
  2663. ReturnTime: project.RecordDate,
  2664. Type: 1,
  2665. StorehouseId: houseConfig.StorehouseOutInfo,
  2666. IsCheck: 1,
  2667. }
  2668. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2669. if msgerrkonde == gorm.ErrRecordNotFound {
  2670. service.AddSigleCancelStock(&cancelStock)
  2671. }
  2672. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2673. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2674. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2675. //获取出库数据
  2676. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2677. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2678. deaerler, _ := service.GetDealerById(info.Dealer)
  2679. if info.ID > 0 {
  2680. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2681. if info.Count >= prescribingNumber {
  2682. cancelStockInfo := models.CancelStockInfo{
  2683. GoodId: project.ProjectId,
  2684. CancelStockId: cancel.ID,
  2685. GoodTypeId: good.GoodTypeId,
  2686. Count: prescribingNumber,
  2687. Price: info.Price,
  2688. Total: 0,
  2689. ProductDate: info.ProductDate,
  2690. ExpiryDate: info.ExpiryDate,
  2691. Ctime: time.Now().Unix(),
  2692. Status: 1,
  2693. OrgId: adminInfo.CurrentOrgId,
  2694. OrderNumber: cancel.OrderNumber,
  2695. Type: 0,
  2696. Dealer: deaerler.DealerName,
  2697. Manufacturer: manufacturer.ManufacturerName,
  2698. Number: info.Number,
  2699. RegisterAccount: "",
  2700. Remark: "",
  2701. WarehouseInfoId: info.WarehouseInfotId,
  2702. PatientId: info.PatientId,
  2703. RecordDate: info.SysRecordTime,
  2704. StorehouseId: houseConfig.StorehouseOutInfo,
  2705. IsCheck: 1,
  2706. }
  2707. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2708. //回退库存
  2709. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  2710. //退库数量增加
  2711. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  2712. //出库数量减少
  2713. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  2714. }
  2715. if info.Count < prescribingNumber {
  2716. cancelStockInfo := models.CancelStockInfo{
  2717. GoodId: project.ProjectId,
  2718. CancelStockId: cancel.ID,
  2719. GoodTypeId: good.GoodTypeId,
  2720. Count: info.Count,
  2721. Price: info.Price,
  2722. Total: 0,
  2723. ProductDate: info.ProductDate,
  2724. ExpiryDate: info.ExpiryDate,
  2725. Ctime: time.Now().Unix(),
  2726. Status: 1,
  2727. OrgId: adminInfo.CurrentOrgId,
  2728. OrderNumber: cancel.OrderNumber,
  2729. Type: 0,
  2730. Dealer: deaerler.DealerName,
  2731. Manufacturer: manufacturer.ManufacturerName,
  2732. Number: info.Number,
  2733. RegisterAccount: "",
  2734. Remark: "",
  2735. WarehouseInfoId: info.WarehouseInfotId,
  2736. PatientId: info.PatientId,
  2737. RecordDate: info.SysRecordTime,
  2738. StorehouseId: houseConfig.StorehouseOutInfo,
  2739. IsCheck: 1,
  2740. }
  2741. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2742. //回退库存
  2743. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  2744. //退库数量增加
  2745. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2746. //出库数量减少
  2747. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  2748. }
  2749. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  2750. var over_count int64
  2751. for _, it := range goodList {
  2752. over_count += it.StockCount
  2753. }
  2754. if info.Count >= prescribingNumber {
  2755. flow := models.VmStockFlow{
  2756. WarehousingId: info.WarehouseInfotId,
  2757. GoodId: project.ProjectId,
  2758. Number: info.Number,
  2759. LicenseNumber: info.LicenseNumber,
  2760. Count: prescribingNumber,
  2761. UserOrgId: adminInfo.CurrentOrgId,
  2762. PatientId: project.PatientId,
  2763. SystemTime: info.SysRecordTime,
  2764. ConsumableType: 7,
  2765. IsSys: 0,
  2766. WarehousingOrder: "",
  2767. WarehouseOutId: info.WarehouseOutId,
  2768. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2769. IsEdit: 0,
  2770. CancelStockId: cancel.ID,
  2771. CancelOrderNumber: cancel.OrderNumber,
  2772. Manufacturer: manufacturer.ID,
  2773. Dealer: 0,
  2774. Creator: adminInfo.AdminUser.Id,
  2775. UpdateCreator: 0,
  2776. Status: 1,
  2777. Ctime: time.Now().Unix(),
  2778. Mtime: 0,
  2779. Price: info.Price,
  2780. WarehousingDetailId: info.WarehouseInfotId,
  2781. WarehouseOutDetailId: info.ID,
  2782. CancelOutDetailId: cancelInfo.ID,
  2783. ProductDate: info.ProductDate,
  2784. ExpireDate: info.ExpiryDate,
  2785. StorehouseId: houseConfig.StorehouseOutInfo,
  2786. OverCount: over_count,
  2787. }
  2788. service.CreateStockFlowOne(flow)
  2789. }
  2790. if info.Count < prescribingNumber {
  2791. flow := models.VmStockFlow{
  2792. WarehousingId: info.WarehouseInfotId,
  2793. GoodId: project.ProjectId,
  2794. Number: info.Number,
  2795. LicenseNumber: info.LicenseNumber,
  2796. Count: info.Count,
  2797. UserOrgId: adminInfo.CurrentOrgId,
  2798. PatientId: project.PatientId,
  2799. SystemTime: info.SysRecordTime,
  2800. ConsumableType: 7,
  2801. IsSys: 0,
  2802. WarehousingOrder: "",
  2803. WarehouseOutId: info.WarehouseOutId,
  2804. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2805. IsEdit: 0,
  2806. CancelStockId: cancel.ID,
  2807. CancelOrderNumber: cancel.OrderNumber,
  2808. Manufacturer: manufacturer.ID,
  2809. Dealer: 0,
  2810. Creator: adminInfo.AdminUser.Id,
  2811. UpdateCreator: 0,
  2812. Status: 1,
  2813. Ctime: time.Now().Unix(),
  2814. Mtime: 0,
  2815. Price: info.Price,
  2816. WarehousingDetailId: info.WarehouseInfotId,
  2817. WarehouseOutDetailId: info.ID,
  2818. CancelOutDetailId: cancelInfo.ID,
  2819. ProductDate: info.ProductDate,
  2820. ExpireDate: info.ExpiryDate,
  2821. StorehouseId: houseConfig.StorehouseOutInfo,
  2822. OverCount: over_count,
  2823. }
  2824. service.CreateStockFlowOne(flow)
  2825. }
  2826. //查询已出库数量
  2827. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2828. if prescribingNumber < dialysisInfo.Count {
  2829. //改变数量
  2830. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  2831. }
  2832. if prescribingNumber >= dialysisInfo.Count {
  2833. //删除出库表
  2834. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2835. }
  2836. //更新剩余库存
  2837. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  2838. //查询今日该患者开了多少耗材
  2839. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2840. //
  2841. //var total_count int64
  2842. //var cha_count int64
  2843. //for _, item := range projectList {
  2844. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  2845. // total_count += count
  2846. //}
  2847. //
  2848. ////查询今日该耗材退库数量
  2849. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2850. //var cancel_count int64
  2851. //for _, items := range cancelInfoOne {
  2852. // cancel_count += items.Count
  2853. //}
  2854. //
  2855. //cha_count = total_count - cancel_count
  2856. //
  2857. //if total_count > cancel_count {
  2858. //
  2859. // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2860. // if err == gorm.ErrRecordNotFound {
  2861. // //没有记录,则创建出库单
  2862. // timeStr := time.Now().Format("2006-01-02")
  2863. // timeArr := strings.Split(timeStr, "-")
  2864. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2865. // total = total + 1
  2866. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2867. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2868. // number = number + total
  2869. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2870. // warehouseOut := models.WarehouseOut{
  2871. // WarehouseOutOrderNumber: warehousing_out_order,
  2872. // OperationTime: time.Now().Unix(),
  2873. // OrgId: adminInfo.CurrentOrgId,
  2874. // Creater: creater,
  2875. // Ctime: time.Now().Unix(),
  2876. // Status: 1,
  2877. // WarehouseOutTime: info.SysRecordTime,
  2878. // Dealer: 0,
  2879. // Manufacturer: 0,
  2880. // Type: 1,
  2881. // IsSys: 1,
  2882. // StorehouseId: houseConfig.StorehouseOutInfo,
  2883. // }
  2884. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2885. // if err != nil {
  2886. // utils.TraceLog("创建出库单失败 err = %v", err)
  2887. // return
  2888. // }
  2889. // prepare := &models.DialysisBeforePrepare{
  2890. // UserOrgId: adminInfo.CurrentOrgId,
  2891. // PatientId: info.PatientId,
  2892. // RecordDate: info.SysRecordTime,
  2893. // GoodId: project.ProjectId,
  2894. // GoodTypeId: info.GoodTypeId,
  2895. // Count: cha_count,
  2896. // StorehouseId: houseConfig.StorehouseOutInfo,
  2897. // }
  2898. // //出库
  2899. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2900. // } else if err == nil {
  2901. // prepare := &models.DialysisBeforePrepare{
  2902. // UserOrgId: adminInfo.CurrentOrgId,
  2903. // PatientId: info.PatientId,
  2904. // RecordDate: info.SysRecordTime,
  2905. // GoodId: project.ProjectId,
  2906. // GoodTypeId: info.GoodTypeId,
  2907. // Count: cha_count,
  2908. // StorehouseId: houseConfig.StorehouseOutInfo,
  2909. // }
  2910. // //出库
  2911. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2912. // }
  2913. //
  2914. //}
  2915. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  2916. var total_count_one int64
  2917. for _, it := range stockList {
  2918. total_count_one += it.StockCount
  2919. }
  2920. //基础库插入数据
  2921. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  2922. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  2923. var flush_count int64
  2924. for _, it := range goodListOne {
  2925. flush_count += it.StockCount
  2926. }
  2927. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  2928. if errs != nil {
  2929. goodErrcode := models.XtGoodErrcode{
  2930. UserOrgId: project.UserOrgId,
  2931. Errcode: "手动出库更新剩余出库失败",
  2932. GoodId: project.ProjectId,
  2933. Status: 1,
  2934. Ctime: time.Now().Unix(),
  2935. Mtime: 0,
  2936. Count: 0,
  2937. StockCount: 0,
  2938. Creater: creater,
  2939. BatchNumberId: 0,
  2940. WarehouseOutId: 0,
  2941. }
  2942. service.CreateGoodErrcode(goodErrcode)
  2943. }
  2944. }
  2945. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2946. fmt.Println(err)
  2947. } else {
  2948. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2949. fmt.Println(err)
  2950. }
  2951. }
  2952. c.ServeSuccessJSON(map[string]interface{}{
  2953. "msg": "删除成功",
  2954. })
  2955. return
  2956. }
  2957. func (c *HisApiController) CreateHisAdditionalCharge() {
  2958. his_patient_id, _ := c.GetInt64("his_patient_id")
  2959. patient_id, _ := c.GetInt64("patient_id")
  2960. record_date := c.GetString("record_date")
  2961. timeLayout := "2006-01-02"
  2962. loc, _ := time.LoadLocation("Local")
  2963. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2964. if err != nil {
  2965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2966. return
  2967. }
  2968. adminInfo := c.GetAdminUserInfo()
  2969. recordDateTime := theTime.Unix()
  2970. dataBody := make(map[string]interface{}, 0)
  2971. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2972. if err != nil {
  2973. utils.ErrorLog(err.Error())
  2974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2975. return
  2976. }
  2977. var additions []*models.HisAdditionalCharge
  2978. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2979. additions, _ := dataBody["addition"].([]interface{})
  2980. if len(additions) > 0 {
  2981. for _, item := range additions {
  2982. items := item.(map[string]interface{})
  2983. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2984. utils.ErrorLog("item_id")
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. item_id := int64(items["item_id"].(float64))
  2989. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2990. utils.ErrorLog("item_name")
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2992. return
  2993. }
  2994. item_name := items["item_name"].(string)
  2995. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2996. utils.ErrorLog("price")
  2997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2998. return
  2999. }
  3000. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3001. ctime := time.Now().Unix()
  3002. additional := &models.HisAdditionalCharge{
  3003. PatientId: patient_id,
  3004. HisPatientId: his_patient_id,
  3005. UserOrgId: adminInfo.CurrentOrgId,
  3006. RecordDate: recordDateTime,
  3007. CreatedTime: ctime,
  3008. UpdatedTime: ctime,
  3009. Modifier: adminInfo.AdminUser.Id,
  3010. Creator: adminInfo.AdminUser.Id,
  3011. Price: price,
  3012. ItemName: item_name,
  3013. ItemId: item_id,
  3014. Status: 1,
  3015. }
  3016. additions = append(additions, additional)
  3017. }
  3018. }
  3019. }
  3020. for _, item := range additions {
  3021. service.CreateAddtionalCharge(item)
  3022. }
  3023. c.ServeSuccessJSON(map[string]interface{}{
  3024. "msg": "创建成功",
  3025. })
  3026. }
  3027. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3028. blood_fat := c.GetString("blood_fat")
  3029. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3030. blood_sugar := c.GetString("blood_sugar")
  3031. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  3032. chief_conplaint := c.GetString("chief_conplaint")
  3033. dbp := c.GetString("dbp")
  3034. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  3035. delivery_way, _ := c.GetInt64("delivery_way")
  3036. diagnostic := c.GetString("diagnostic")
  3037. family_history := c.GetString("family_history")
  3038. height := c.GetString("height")
  3039. history_of_present_illness := c.GetString("history_of_present_illness")
  3040. is_infect, _ := c.GetInt64("is_infect")
  3041. past_history := c.GetString("past_history")
  3042. patient_id, _ := c.GetInt64("patient_id")
  3043. his_patient_id, _ := c.GetInt64("his_patient_id")
  3044. personal_history := c.GetString("personal_history")
  3045. pulse := c.GetString("pulse")
  3046. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  3047. sbp := c.GetString("sbp")
  3048. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  3049. heightfloat, _ := strconv.ParseFloat(height, 64)
  3050. sicktype := c.GetString("sick_type")
  3051. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  3052. symptom := c.GetString("symptom")
  3053. sick_date := c.GetString("sick_date")
  3054. temperatures := c.GetString("temperature")
  3055. temperature, _ := strconv.ParseFloat(temperatures, 64)
  3056. record_date := c.GetString("record_date")
  3057. breathing := c.GetString("breathing")
  3058. doctor_advice := c.GetString("doctor_advice")
  3059. remark := c.GetString("remark")
  3060. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  3061. sick, _ := c.GetInt64("sick")
  3062. diagnose, _ := c.GetInt64("diagnose")
  3063. //id, _ := c.GetInt64("id")
  3064. timeLayout := "2006-01-02"
  3065. loc, _ := time.LoadLocation("Local")
  3066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3067. allergic_history := c.GetString("allergic_history")
  3068. if err != nil {
  3069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. recordDateTime := theTime.Unix()
  3073. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  3074. if err != nil {
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3076. return
  3077. }
  3078. sickTimes := sickTime.Unix()
  3079. ctime := time.Now().Unix()
  3080. primary_disease := c.GetString("primary_disease")
  3081. confirm_failure_date := c.GetString("confirm_failure_date")
  3082. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  3083. drug_allergy_history := c.GetString("drug_allergy_history")
  3084. physical_examination := c.GetString("physical_examination")
  3085. special_inspection := c.GetString("special_inspection")
  3086. lab_apparatus := c.GetString("lab_apparatus")
  3087. caseHistory := models.HisPatientCaseHistory{
  3088. HisPatientId: his_patient_id,
  3089. PatientId: patient_id,
  3090. Temperature: temperature,
  3091. BloodSugar: bloodsugarfloat,
  3092. Pulse: pulsefloat,
  3093. Sbp: sbpfloat,
  3094. Dbp: dbpfloat,
  3095. Height: heightfloat,
  3096. BloodFat: bloodfatfloat,
  3097. SickType: sick_type,
  3098. Symptom: symptom,
  3099. SickDate: sickTimes,
  3100. IsInfect: is_infect,
  3101. HistoryOfPresentIllness: history_of_present_illness,
  3102. PastHistory: past_history,
  3103. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  3104. ChiefConplaint: chief_conplaint,
  3105. PersonalHistory: personal_history,
  3106. FamilyHistory: family_history,
  3107. Diagnostic: diagnostic,
  3108. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3109. Status: 1,
  3110. Ctime: ctime,
  3111. Mtime: ctime,
  3112. RecordDate: recordDateTime,
  3113. DeliveryWay: delivery_way,
  3114. Breathing: breathingfloat,
  3115. DoctorAdvice: doctor_advice,
  3116. Remark: remark,
  3117. Sick: sick,
  3118. Diagnose: diagnose,
  3119. AllergicHistory: allergic_history,
  3120. PrimaryDisease: primary_disease,
  3121. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  3122. DrugAllergyHistory: drug_allergy_history,
  3123. PhysicalExamination: physical_examination,
  3124. SpecialInspection: special_inspection,
  3125. LabApparatus: lab_apparatus,
  3126. }
  3127. //查询该患者是否有病历
  3128. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  3129. if errcodes == gorm.ErrRecordNotFound {
  3130. err = service.SaveHisPatientCaseHistory(&caseHistory)
  3131. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3132. if err != nil {
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3134. return
  3135. }
  3136. c.ServeSuccessJSON(map[string]interface{}{
  3137. "caseHistory": caseHistory,
  3138. "historyInfo": historyInfo,
  3139. })
  3140. return
  3141. } else if errcodes == nil {
  3142. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  3143. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3144. if err != nil {
  3145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3146. return
  3147. }
  3148. c.ServeSuccessJSON(map[string]interface{}{
  3149. "caseHistory": caseHistory,
  3150. "historyInfo": historyInfo,
  3151. })
  3152. }
  3153. //查询该患者是否有病历
  3154. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3155. //if errcode == gorm.ErrRecordNotFound {
  3156. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3157. // if err != nil {
  3158. // c.ServeSuccessJSON(map[string]interface{}{
  3159. // "msg": "保存成功",
  3160. // })
  3161. // }
  3162. //} else if errcode == nil {
  3163. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3164. // return
  3165. //}
  3166. }
  3167. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3168. patient_id, _ := c.GetInt64("patient_id", 0)
  3169. adminUser := c.GetAdminUserInfo()
  3170. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3171. c.ServeSuccessJSON(map[string]interface{}{
  3172. "list": caseHistorys,
  3173. })
  3174. }
  3175. func (c *HisApiController) GetHisPatientCaseHistory() {
  3176. record_date, _ := c.GetInt64("record_date", 0)
  3177. patient_id, _ := c.GetInt64("patient_id", 0)
  3178. admin := c.GetAdminUserInfo()
  3179. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3180. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3181. c.ServeSuccessJSON(map[string]interface{}{
  3182. "info": info,
  3183. "case_history": case_history,
  3184. })
  3185. }
  3186. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3187. template_name := c.GetString("template_name")
  3188. template_remark := c.GetString("template_remark")
  3189. doctor := c.GetAdminUserInfo().AdminUser.Id
  3190. diagnostic := c.GetString("diagnostic")
  3191. chief_conplaint := c.GetString("chief_conplain")
  3192. history_of_present_illness := c.GetString("history_of_present_illness")
  3193. past_history := c.GetString("past_history")
  3194. personal_history := c.GetString("personal_history")
  3195. family_history := c.GetString("family_history")
  3196. user_name := c.GetString("user_name")
  3197. doctor_advice := c.GetString("doctor_advice")
  3198. remark := c.GetString("remark")
  3199. //record_date := c.GetString("record_date")
  3200. //fmt.Println("record_date--------",record_date)
  3201. //timeLayout := "2006-01-02"
  3202. //loc, _ := time.LoadLocation("Local")
  3203. //
  3204. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3205. //if err != nil {
  3206. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3207. // return
  3208. //}
  3209. //recordDateTime := theTime.Unix()
  3210. ctime := time.Now().Unix()
  3211. template := models.HisCaseHistoryTemplate{
  3212. HistoryOfPresentIllness: history_of_present_illness,
  3213. PastHistory: past_history,
  3214. ChiefConplaint: chief_conplaint,
  3215. PersonalHistory: personal_history,
  3216. FamilyHistory: family_history,
  3217. Diagnostic: diagnostic,
  3218. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3219. Status: 1,
  3220. Ctime: ctime,
  3221. Mtime: ctime,
  3222. RecordDate: time.Now().Unix(),
  3223. TemplateName: template_name,
  3224. TemplateRemark: template_remark,
  3225. Creator: doctor,
  3226. Modifier: doctor,
  3227. UserName: user_name,
  3228. DoctorAdvice: doctor_advice,
  3229. Remark: remark,
  3230. }
  3231. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3232. if err == nil {
  3233. c.ServeSuccessJSON(map[string]interface{}{
  3234. "msg": "保存成功",
  3235. })
  3236. } else {
  3237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3238. return
  3239. }
  3240. }
  3241. func (c *HisApiController) GetCaseHistoryTemplate() {
  3242. timeLayout := "2006-01-02"
  3243. loc, _ := time.LoadLocation("Local")
  3244. keyword := c.GetString("keyword")
  3245. start_time := c.GetString("start_time")
  3246. end_time := c.GetString("end_time")
  3247. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3248. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3249. admin := c.GetAdminUserInfo()
  3250. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3251. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3252. c.ServeSuccessJSON(map[string]interface{}{
  3253. "template": template,
  3254. //"history": history,
  3255. })
  3256. }
  3257. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3258. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3259. utils.ErrorLog("drug_name")
  3260. return enums.ErrorCodeParamWrong
  3261. }
  3262. adviceName, _ := json["drug_name"].(string)
  3263. if len(adviceName) == 0 {
  3264. utils.ErrorLog("len(advice_name) == 0")
  3265. return enums.ErrorCodeParamWrong
  3266. }
  3267. advice.AdviceName = adviceName
  3268. adviceDesc, _ := json["advice_desc"].(string)
  3269. advice.AdviceDesc = adviceDesc
  3270. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3271. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3272. advice.DrugSpec = drugSpec
  3273. }
  3274. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3275. remark, _ := json["remark"].(string)
  3276. advice.Remark = remark
  3277. }
  3278. if json["id"] == nil {
  3279. advice.DrugId = 0
  3280. } else {
  3281. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3282. drug_id := int64(json["id"].(float64))
  3283. advice.DrugId = drug_id
  3284. }
  3285. }
  3286. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3287. advice_id := int64(json["advice_id"].(float64))
  3288. advice.ID = advice_id
  3289. if advice.ID > 0 {
  3290. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3291. if err == nil {
  3292. if hisAdvice.ID > 0 {
  3293. advice.ExecutionTime = hisAdvice.ExecutionTime
  3294. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3295. advice.ExecutionState = hisAdvice.ExecutionState
  3296. advice.CheckTime = hisAdvice.CheckTime
  3297. advice.Checker = hisAdvice.Checker
  3298. advice.CheckState = hisAdvice.CheckState
  3299. advice.StartTime = hisAdvice.StartTime
  3300. advice.FeedetlSn = hisAdvice.FeedetlSn
  3301. }
  3302. }
  3303. }
  3304. }
  3305. //
  3306. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3307. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3308. // advice.ExecutionTime = execution_time
  3309. //}
  3310. //
  3311. //
  3312. //
  3313. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3314. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3315. // advice.ExecutionStaff = execution_staff
  3316. //}
  3317. //
  3318. //
  3319. //
  3320. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3321. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3322. // advice.ExecutionState = execution_state
  3323. //}
  3324. //
  3325. //
  3326. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3327. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3328. // advice.CheckTime = check_time
  3329. //}
  3330. //
  3331. //
  3332. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3333. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3334. // advice.CheckState = check_state
  3335. //}
  3336. //
  3337. //
  3338. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3339. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3340. // advice.Checker = checker
  3341. //}
  3342. //
  3343. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3344. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3345. // advice.StartTime = start_time
  3346. //}
  3347. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3348. drugSpecUnit, _ := json["min_unit"].(string)
  3349. advice.DrugSpecUnit = drugSpecUnit
  3350. }
  3351. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3352. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3353. advice.SingleDose = singleDose
  3354. }
  3355. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3356. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3357. advice.SingleDoseUnit = singleDoseUnit
  3358. }
  3359. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3360. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3361. advice.PrescribingNumber = prescribingNumber
  3362. }
  3363. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3364. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3365. advice.PrescribingNumberUnit = prescribingNumberUnit
  3366. }
  3367. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3368. deliveryWay, _ := json["delivery_way"].(string)
  3369. advice.DeliveryWay = deliveryWay
  3370. }
  3371. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3372. executionFrequency, _ := json["execution_frequency"].(string)
  3373. advice.ExecutionFrequency = executionFrequency
  3374. }
  3375. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3376. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3377. advice.Price = price
  3378. }
  3379. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3380. med_list_codg, _ := json["medical_insurance_number"].(string)
  3381. advice.MedListCodg = med_list_codg
  3382. }
  3383. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3384. day := int64(json["day"].(float64))
  3385. advice.Day = day
  3386. }
  3387. return 0
  3388. }
  3389. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3390. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3391. id := int64(json["id"].(float64))
  3392. project.ID = id
  3393. historyProject, _ := service.GetHisProjectByID(id)
  3394. project.FeedetlSn = historyProject.FeedetlSn
  3395. }
  3396. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3397. project_id := int64(json["project_id"].(float64))
  3398. project.ProjectId = project_id
  3399. }
  3400. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3401. // price := int64(json["price"].(float64))
  3402. // formatInt_price := strconv.FormatInt(price, 10)
  3403. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3404. // project.Price = float_price
  3405. // }
  3406. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3407. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3408. project.Price = price
  3409. }
  3410. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3411. total, _ := json["total"].(string)
  3412. project.Count = total
  3413. }
  3414. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3415. medical_code, _ := json["medical_code"].(string)
  3416. project.MedListCodg = medical_code
  3417. }
  3418. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3419. single_dose, _ := json["single_dose"].(string)
  3420. project.SingleDose = single_dose
  3421. }
  3422. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3423. delivery_way, _ := json["delivery_way"].(string)
  3424. project.DeliveryWay = delivery_way
  3425. }
  3426. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3427. execution_frequency, _ := json["execution_frequency"].(string)
  3428. project.ExecutionFrequency = execution_frequency
  3429. }
  3430. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3431. remark, _ := json["remark"].(string)
  3432. project.Remark = remark
  3433. }
  3434. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3435. day, _ := json["number_days"].(string)
  3436. project.Day = day
  3437. }
  3438. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3439. unit, _ := json["unit"].(string)
  3440. project.Unit = unit
  3441. }
  3442. return 0
  3443. }
  3444. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3445. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3446. id := int64(json["id"].(float64))
  3447. historyAddtions, _ := service.GetHisAdditionByID(id)
  3448. additionalCharge.ID = id
  3449. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  3450. }
  3451. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3452. item_id := int64(json["item_id"].(float64))
  3453. additionalCharge.ItemId = item_id
  3454. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3455. if config.ID > 0 {
  3456. if len(config.Code) > 0 {
  3457. additionalCharge.MedListCodg = config.Code
  3458. }
  3459. }
  3460. }
  3461. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3462. // price := int64(json["price"].(float64))
  3463. // formatInt_price := strconv.FormatInt(price, 10)
  3464. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3465. // additionalCharge.Price = float_price
  3466. // }
  3467. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3468. // price := int64(json["price"].(float64))
  3469. // formatInt_price := strconv.FormatInt(price, 10)
  3470. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3471. // additionalCharge.Price = float_price
  3472. //}
  3473. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3474. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3475. additionalCharge.Price = price
  3476. }
  3477. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3478. count, _ := json["count"].(string)
  3479. counts, _ := strconv.ParseInt(count, 10, 64)
  3480. additionalCharge.Count = counts
  3481. }
  3482. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3483. item_name, _ := json["item_name"].(string)
  3484. additionalCharge.ItemName = item_name
  3485. }
  3486. return 0
  3487. }
  3488. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3489. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3490. utils.ErrorLog("drug_name")
  3491. return enums.ErrorCodeParamWrong
  3492. }
  3493. adviceName, _ := json["drug_name"].(string)
  3494. if len(adviceName) == 0 {
  3495. utils.ErrorLog("len(advice_name) == 0")
  3496. return enums.ErrorCodeParamWrong
  3497. }
  3498. advice.AdviceName = adviceName
  3499. adviceDesc, _ := json["advice_desc"].(string)
  3500. advice.AdviceDesc = adviceDesc
  3501. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3502. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3503. advice.DrugSpec = drugSpec
  3504. }
  3505. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3506. remark, _ := json["remark"].(string)
  3507. advice.Remark = remark
  3508. }
  3509. if json["id"] == nil {
  3510. advice.DrugId = 0
  3511. } else {
  3512. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3513. drug_id := int64(json["id"].(float64))
  3514. advice.DrugId = drug_id
  3515. }
  3516. }
  3517. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3518. groupno := int64(json["groupno"].(float64))
  3519. advice.Groupno = groupno
  3520. }
  3521. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3522. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3523. advice.HospApprFlag = hosp_appr_flag
  3524. }
  3525. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3526. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3527. advice.PrescribingNumber = prescribingNumber
  3528. }
  3529. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3530. // frequency_type := int64(json["frequency_type"].(float64))
  3531. // advice.FrequencyType = frequency_type
  3532. //}
  3533. //
  3534. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3535. // day_count := int64(json["day_count"].(float64))
  3536. // advice.DayCount = day_count
  3537. //}
  3538. //
  3539. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3540. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3541. // week_day, _ := json["week_day"].(string)
  3542. // advice.WeekDay = week_day
  3543. //}
  3544. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3545. drugSpecUnit, _ := json["min_unit"].(string)
  3546. advice.DrugSpecUnit = drugSpecUnit
  3547. }
  3548. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3549. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3550. advice.SingleDose = singleDose
  3551. }
  3552. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3553. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3554. advice.SingleDoseUnit = singleDoseUnit
  3555. }
  3556. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3557. deliveryWay, _ := json["delivery_way"].(string)
  3558. advice.DeliveryWay = deliveryWay
  3559. }
  3560. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3561. executionFrequency, _ := json["execution_frequency"].(string)
  3562. advice.ExecutionFrequency = executionFrequency
  3563. }
  3564. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3565. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3566. advice.Price = price
  3567. }
  3568. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3569. med_list_codg, _ := json["medical_insurance_number"].(string)
  3570. advice.MedListCodg = med_list_codg
  3571. }
  3572. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3573. day := int64(json["day"].(float64))
  3574. advice.Day = day
  3575. }
  3576. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3577. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3578. advice.PrescribingNumberUnit = prescribingNumberUnit
  3579. }
  3580. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3581. advice_id := int64(json["advice_id"].(float64))
  3582. advice.ID = advice_id
  3583. if advice.ID > 0 {
  3584. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3585. if err == nil {
  3586. if hisAdvice.ID > 0 {
  3587. advice.ExecutionTime = hisAdvice.ExecutionTime
  3588. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3589. advice.ExecutionState = hisAdvice.ExecutionState
  3590. advice.CheckTime = hisAdvice.CheckTime
  3591. advice.Checker = hisAdvice.Checker
  3592. advice.CheckState = hisAdvice.CheckState
  3593. advice.StartTime = hisAdvice.StartTime
  3594. advice.HospApprFlag = hisAdvice.HospApprFlag
  3595. advice.IsMedicine = hisAdvice.IsMedicine
  3596. if hisAdvice.UserOrgId == 10028 {
  3597. 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 {
  3598. advice.ExecutionTime = 0
  3599. advice.ExecutionStaff = 0
  3600. advice.ExecutionState = 2
  3601. advice.CheckTime = 0
  3602. advice.Checker = 0
  3603. advice.CheckState = 2
  3604. }
  3605. } else {
  3606. 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 {
  3607. advice.ExecutionTime = 0
  3608. advice.ExecutionStaff = 0
  3609. advice.ExecutionState = 2
  3610. advice.CheckTime = 0
  3611. advice.Checker = 0
  3612. advice.CheckState = 2
  3613. }
  3614. }
  3615. //advice.Groupno = hisAdvice.Groupno
  3616. }
  3617. }
  3618. }
  3619. }
  3620. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3621. //
  3622. //if drugStockConfig.IsOpen == 1 {
  3623. //
  3624. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3625. // if advice.ID == 0 { //医嘱不存在
  3626. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3627. // drug.Total = drug.Total - advice.PrescribingNumber
  3628. // service.UpdateBaseDrugLib(&drug)
  3629. //
  3630. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3631. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3632. // drug.Total = drug.Total - num
  3633. // service.UpdateBaseDrugLib(&drug)
  3634. // }
  3635. //
  3636. // } else if advice.ID > 0 { //医嘱存在
  3637. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3638. // var num float64
  3639. //
  3640. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3641. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3642. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3643. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3644. // drug.Total = drug.Total + num
  3645. // service.UpdateBaseDrugLib(&drug)
  3646. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3647. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3648. // drug.Total = drug.Total - num
  3649. // service.UpdateBaseDrugLib(&drug)
  3650. // }
  3651. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3652. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3653. // if num2 > advice.PrescribingNumber {
  3654. // num = num2 - advice.PrescribingNumber
  3655. // drug.Total = drug.Total + num
  3656. // service.UpdateBaseDrugLib(&drug)
  3657. // } else if num2 < advice.PrescribingNumber {
  3658. // num = advice.PrescribingNumber - num2
  3659. // drug.Total = drug.Total - num
  3660. // service.UpdateBaseDrugLib(&drug)
  3661. // }
  3662. //
  3663. // }
  3664. //
  3665. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3666. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3667. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3668. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3669. // if num1 > num2 {
  3670. // num = num1 - num2
  3671. // drug.Total = drug.Total + num
  3672. // service.UpdateBaseDrugLib(&drug)
  3673. // } else if num1 < num2 {
  3674. // num = num2 - num1
  3675. // drug.Total = drug.Total - num
  3676. // service.UpdateBaseDrugLib(&drug)
  3677. // }
  3678. //
  3679. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3680. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3681. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3682. // if hisAdvice.PrescribingNumber > num2 {
  3683. // num = hisAdvice.PrescribingNumber - num2
  3684. // drug.Total = drug.Total + num
  3685. // service.UpdateBaseDrugLib(&drug)
  3686. // } else if num2 < advice.PrescribingNumber {
  3687. // num = num2 - hisAdvice.PrescribingNumber
  3688. // drug.Total = drug.Total - num
  3689. // service.UpdateBaseDrugLib(&drug)
  3690. // }
  3691. //
  3692. // }
  3693. // }
  3694. // }
  3695. //}
  3696. //
  3697. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3698. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3699. // advice.ExecutionTime = execution_time
  3700. //}
  3701. //
  3702. //
  3703. //
  3704. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3705. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3706. // advice.ExecutionStaff = execution_staff
  3707. //}
  3708. //
  3709. //
  3710. //
  3711. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3712. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3713. // advice.ExecutionState = execution_state
  3714. //}
  3715. //
  3716. //
  3717. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3718. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3719. // advice.CheckTime = check_time
  3720. //}
  3721. //
  3722. //
  3723. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3724. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3725. // advice.CheckState = check_state
  3726. //}
  3727. //
  3728. //
  3729. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3730. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3731. // advice.Checker = checker
  3732. //}
  3733. //
  3734. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3735. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3736. // advice.StartTime = start_time
  3737. //}
  3738. return 0
  3739. }
  3740. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3741. project.ExecutionStaff = 0
  3742. project.ExecutionState = 2
  3743. project.ExecutionTime = 0
  3744. project.Checker = 0
  3745. project.CheckState = 2
  3746. project.CheckTime = 0
  3747. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3748. id := int64(json["id"].(float64))
  3749. project.ID = id
  3750. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3751. project.ExecutionStaff = temp_project.ExecutionStaff
  3752. project.ExecutionState = temp_project.ExecutionState
  3753. project.ExecutionTime = temp_project.ExecutionTime
  3754. project.Checker = temp_project.Checker
  3755. project.CheckState = temp_project.CheckState
  3756. project.CheckTime = temp_project.CheckTime
  3757. project.TeamId = temp_project.TeamId
  3758. }
  3759. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3760. types := int64(json["type"].(float64))
  3761. project.Type = types
  3762. }
  3763. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3764. project_id := int64(json["project_id"].(float64))
  3765. project.ProjectId = project_id
  3766. }
  3767. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3768. team_id := int64(json["team_id"].(float64))
  3769. project.TeamId = team_id
  3770. }
  3771. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3772. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3773. project.Price = price
  3774. }
  3775. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3776. total, _ := json["total"].(string)
  3777. //totals, _ := strconv.ParseInt(total, 10, 64)
  3778. project.Count = total
  3779. }
  3780. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3781. medical_code, _ := json["medical_code"].(string)
  3782. project.MedListCodg = medical_code
  3783. }
  3784. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3785. single_dose, _ := json["single_dose"].(string)
  3786. project.SingleDose = single_dose
  3787. }
  3788. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3789. delivery_way, _ := json["delivery_way"].(string)
  3790. project.DeliveryWay = delivery_way
  3791. }
  3792. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3793. execution_frequency, _ := json["execution_frequency"].(string)
  3794. project.ExecutionFrequency = execution_frequency
  3795. }
  3796. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3797. remark, _ := json["remark"].(string)
  3798. project.Remark = remark
  3799. }
  3800. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3801. day, _ := json["number_days"].(string)
  3802. project.Day = day
  3803. }
  3804. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3805. unit, _ := json["unit"].(string)
  3806. project.Unit = unit
  3807. }
  3808. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3809. // frequency_type := int64(json["frequency_type"].(float64))
  3810. // project.FrequencyType = frequency_type
  3811. //}
  3812. //
  3813. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3814. // day_count := int64(json["day_count"].(float64))
  3815. // project.DayCount = day_count
  3816. //}
  3817. //
  3818. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3819. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3820. // week_day, _ := json["week_day"].(string)
  3821. // project.WeekDay = week_day
  3822. //}
  3823. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3824. //
  3825. //if project.ID == 0 {
  3826. // if stockConfig.IsOpen == 1 {
  3827. // if project.Type == 3 {
  3828. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3829. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3830. // good.Total = good.Total - f_count
  3831. // service.UpdateGoodInfo(&good)
  3832. // }
  3833. // }
  3834. //
  3835. //} else {
  3836. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3837. //
  3838. // if stockConfig.IsOpen == 1 {
  3839. // if project.Type == 3 {
  3840. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3841. // if project.Count < temp_project.Count {
  3842. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3843. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3844. //
  3845. // other_count := f_count_two - f_count_one
  3846. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3847. // good.Total = good.Total + other_count_two
  3848. // service.UpdateGoodInfo(&good)
  3849. // } else if project.Count > temp_project.Count {
  3850. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3851. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3852. //
  3853. // other_count := f_count_one - f_count_two
  3854. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3855. // good.Total = good.Total - other_count_two
  3856. // service.UpdateGoodInfo(&good)
  3857. // }
  3858. //
  3859. // }
  3860. // }
  3861. //
  3862. //}
  3863. return 0
  3864. }
  3865. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3866. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3867. id := int64(json["id"].(float64))
  3868. additionalCharge.ID = id
  3869. }
  3870. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3871. item_id := int64(json["item_id"].(float64))
  3872. additionalCharge.ItemId = item_id
  3873. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3874. if config.ID > 0 {
  3875. if len(config.Code) > 0 {
  3876. additionalCharge.MedListCodg = config.Code
  3877. }
  3878. }
  3879. }
  3880. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3881. // price := int64(json["price"].(float64))
  3882. // formatInt_price := strconv.FormatInt(price, 10)
  3883. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3884. // additionalCharge.Price = float_price
  3885. // }
  3886. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3887. // price := int64(json["price"].(float64))
  3888. // formatInt_price := strconv.FormatInt(price, 10)
  3889. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3890. // additionalCharge.Price = float_price
  3891. //}
  3892. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3893. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3894. additionalCharge.Price = price
  3895. }
  3896. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3897. count, _ := json["count"].(string)
  3898. counts, _ := strconv.ParseInt(count, 10, 64)
  3899. additionalCharge.Count = counts
  3900. }
  3901. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3902. item_name, _ := json["item_name"].(string)
  3903. additionalCharge.ItemName = item_name
  3904. }
  3905. return 0
  3906. }
  3907. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3908. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3909. utils.ErrorLog("drug_name")
  3910. return enums.ErrorCodeParamWrong
  3911. }
  3912. adviceName, _ := json["drug_name"].(string)
  3913. if len(adviceName) == 0 {
  3914. utils.ErrorLog("len(advice_name) == 0")
  3915. return enums.ErrorCodeParamWrong
  3916. }
  3917. advice.AdviceName = adviceName
  3918. adviceDesc, _ := json["advice_desc"].(string)
  3919. advice.AdviceDesc = adviceDesc
  3920. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3921. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3922. advice.DrugSpec = drugSpec
  3923. }
  3924. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3925. remark, _ := json["remark"].(string)
  3926. advice.Remark = remark
  3927. }
  3928. if json["id"] == nil {
  3929. advice.DrugId = 0
  3930. } else {
  3931. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3932. drug_id := int64(json["id"].(float64))
  3933. advice.DrugId = drug_id
  3934. }
  3935. }
  3936. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3937. drugSpecUnit, _ := json["min_unit"].(string)
  3938. advice.DrugSpecUnit = drugSpecUnit
  3939. }
  3940. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3941. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3942. advice.SingleDose = singleDose
  3943. }
  3944. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3945. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3946. advice.SingleDoseUnit = singleDoseUnit
  3947. }
  3948. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3949. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3950. advice.PrescribingNumber = prescribingNumber
  3951. }
  3952. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3953. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3954. advice.PrescribingNumberUnit = prescribingNumberUnit
  3955. }
  3956. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3957. deliveryWay, _ := json["delivery_way"].(string)
  3958. advice.DeliveryWay = deliveryWay
  3959. }
  3960. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3961. executionFrequency, _ := json["execution_frequency"].(string)
  3962. advice.ExecutionFrequency = executionFrequency
  3963. }
  3964. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3965. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3966. advice.Price = price
  3967. }
  3968. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3969. med_list_codg, _ := json["medical_insurance_number"].(string)
  3970. advice.MedListCodg = med_list_codg
  3971. }
  3972. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3973. day := int64(json["day"].(float64))
  3974. advice.Day = day
  3975. }
  3976. return 0
  3977. }
  3978. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3979. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3980. types := int64(json["type"].(float64))
  3981. project.Type = types
  3982. }
  3983. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3984. project_id := int64(json["project_id"].(float64))
  3985. project.ProjectId = project_id
  3986. }
  3987. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3988. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3989. project.Price = price
  3990. }
  3991. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3992. total, _ := json["total"].(string)
  3993. //totals, _ := strconv.ParseInt(total, 10, 64)
  3994. project.Count = total
  3995. }
  3996. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3997. medical_code, _ := json["medical_code"].(string)
  3998. project.MedListCodg = medical_code
  3999. }
  4000. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4001. single_dose, _ := json["single_dose"].(string)
  4002. project.SingleDose = single_dose
  4003. }
  4004. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4005. delivery_way, _ := json["delivery_way"].(string)
  4006. project.DeliveryWay = delivery_way
  4007. }
  4008. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4009. execution_frequency, _ := json["execution_frequency"].(string)
  4010. project.ExecutionFrequency = execution_frequency
  4011. }
  4012. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4013. remark, _ := json["remark"].(string)
  4014. project.Remark = remark
  4015. }
  4016. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4017. day, _ := json["number_days"].(string)
  4018. project.Day = day
  4019. }
  4020. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4021. unit, _ := json["unit"].(string)
  4022. project.Unit = unit
  4023. }
  4024. return 0
  4025. }
  4026. func (c *HisApiController) GetHisOrderList() {
  4027. page, _ := c.GetInt64("page", -1)
  4028. limit, _ := c.GetInt64("limit", -1)
  4029. start_time := c.GetString("start_time")
  4030. end_time := c.GetString("end_time")
  4031. types, _ := c.GetInt64("type", 0)
  4032. keywords := c.GetString("keywords")
  4033. p_type, _ := c.GetInt64("p_type", 0)
  4034. sort_type, _ := c.GetInt64("sort_type", 0)
  4035. charge_type, _ := c.GetInt64("charge_type", 0)
  4036. timeLayout := "2006-01-02"
  4037. loc, _ := time.LoadLocation("Local")
  4038. var startTime int64
  4039. if len(start_time) > 0 {
  4040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4041. if err != nil {
  4042. //fmt.Println(err)
  4043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. startTime = theTime.Unix()
  4047. }
  4048. var endTime int64
  4049. if len(end_time) > 0 {
  4050. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4051. if err != nil {
  4052. utils.ErrorLog(err.Error())
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4054. return
  4055. }
  4056. endTime = theTime.Unix()
  4057. }
  4058. adminUser := c.GetAdminUserInfo()
  4059. org_id := adminUser.CurrentOrgId
  4060. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  4061. for _, item := range order {
  4062. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  4063. item.DoctorName = info.Doctor
  4064. item.DepartmentName = info.XtHisDepartment.Name
  4065. }
  4066. if err == nil {
  4067. c.ServeSuccessJSON(map[string]interface{}{
  4068. "order": order,
  4069. "total": total,
  4070. })
  4071. } else {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4073. return
  4074. }
  4075. }
  4076. func (c *HisApiController) GetHisOrder() {
  4077. patient_id, _ := c.GetInt64("patient_id", 0)
  4078. number := c.GetString("number")
  4079. adminInfo := c.GetAdminUserInfo()
  4080. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  4081. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  4082. if err == nil {
  4083. c.ServeSuccessJSON(map[string]interface{}{
  4084. "order": order,
  4085. "prescription": prescriptions,
  4086. })
  4087. } else {
  4088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4089. return
  4090. }
  4091. }
  4092. func (c *HisApiController) GetHisPrescriptionList() {
  4093. record_date := c.GetString("record_date")
  4094. keywords := c.GetString("keywords")
  4095. page, _ := c.GetInt64("page")
  4096. limit, _ := c.GetInt64("limit")
  4097. timeLayout := "2006-01-02"
  4098. loc, _ := time.LoadLocation("Local")
  4099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4100. if err != nil {
  4101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4102. return
  4103. }
  4104. recordDateTime := theTime.Unix()
  4105. adminInfo := c.GetAdminUserInfo()
  4106. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  4107. //adminInfo := c.GetAdminUserInfo()
  4108. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  4109. //fmt.Println(prescriptionOrder)
  4110. if err == nil {
  4111. c.ServeSuccessJSON(map[string]interface{}{
  4112. "order": prescriptionOrder,
  4113. "total": total,
  4114. })
  4115. } else {
  4116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4117. return
  4118. }
  4119. }
  4120. func (c *HisApiController) GetHisPrescriptionInfo() {
  4121. id, _ := c.GetInt64("id")
  4122. adminInfo := c.GetAdminUserInfo()
  4123. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  4124. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  4125. if err == nil {
  4126. c.ServeSuccessJSON(map[string]interface{}{
  4127. "order": prescriptionOrder,
  4128. "prescription": prescription,
  4129. })
  4130. } else {
  4131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4132. return
  4133. }
  4134. }
  4135. func (c *HisApiController) GetMedicalInsuranceConfig() {
  4136. adminUser := c.GetAdminUserInfo()
  4137. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4138. c.ServeSuccessJSON(map[string]interface{}{
  4139. "config": config,
  4140. })
  4141. }
  4142. type ResultTwo struct {
  4143. ErrMsg interface{} `json:"err_msg"`
  4144. InfRefmsgid string `json:"inf_refmsgid"`
  4145. Infcode int64 `json:"infcode"`
  4146. Output struct {
  4147. Baseinfo struct {
  4148. Age float64 `json:"age"`
  4149. Brdy string `json:"brdy"`
  4150. Certno string `json:"certno"`
  4151. Gend string `json:"gend"`
  4152. Naty string `json:"naty"`
  4153. PsnCertType string `json:"psn_cert_type"`
  4154. PsnName string `json:"psn_name"`
  4155. PsnNo string `json:"psn_no"`
  4156. } `json:"baseinfo"`
  4157. Idetinfo []interface{} `json:"idetinfo"`
  4158. Iinfo []struct {
  4159. Balc float64 `json:"balc"`
  4160. CvlservFlag string `json:"cvlserv_flag"`
  4161. EmpName string `json:"emp_name"`
  4162. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4163. Insutype string `json:"insutype"`
  4164. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4165. PausInsuDate interface{} `json:"paus_insu_date"`
  4166. PsnInsuDate string `json:"psn_insu_date"`
  4167. PsnInsuStas string `json:"psn_insu_stas"`
  4168. PsnType string `json:"psn_type"`
  4169. } `json:"insuinfo"`
  4170. } `json:"output"`
  4171. RefmsgTime string `json:"refmsg_time"`
  4172. RespondTime string `json:"respond_time"`
  4173. Signtype interface{} `json:"signtype"`
  4174. WarnInfo interface{} `json:"warn_info"`
  4175. }
  4176. type ResultThree struct {
  4177. Cainfo interface{} `json:"cainfo"`
  4178. ErrMsg interface{} `json:"err_msg"`
  4179. InfRefmsgid string `json:"inf_refmsgid"`
  4180. Infcode int64 `json:"infcode"`
  4181. Output struct {
  4182. Data struct {
  4183. IptOtpNo string `json:"ipt_otp_no"`
  4184. MdtrtID string `json:"mdtrt_id"`
  4185. PsnNo string `json:"psn_no"`
  4186. } `json:"data"`
  4187. } `json:"output"`
  4188. RefmsgTime string `json:"refmsg_time"`
  4189. RespondTime string `json:"respond_time"`
  4190. Signtype interface{} `json:"signtype"`
  4191. WarnMsg interface{} `json:"warn_msg"`
  4192. }
  4193. type ResultFour struct {
  4194. Cainfo string `json:"cainfo"`
  4195. ErrMsg string `json:"err_msg"`
  4196. InfRefmsgid string `json:"inf_refmsgid"`
  4197. Infcode int64 `json:"infcode"`
  4198. Output struct {
  4199. Result []struct {
  4200. BasMednFlag string `json:"bas_medn_flag"`
  4201. ChldMedcFlag string `json:"chld_medc_flag"`
  4202. ChrgitmLv string `json:"chrgitm_lv"`
  4203. Cnt float64 `json:"cnt"`
  4204. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4205. DrtReimFlag string `json:"drt_reim_flag"`
  4206. FeedetlSn string `json:"feedetl_sn"`
  4207. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4208. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4209. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4210. ListSpItemFlag string `json:"list_sp_item_flag"`
  4211. LmtUsedFlag string `json:"lmt_used_flag"`
  4212. MedChrgitmType string `json:"med_chrgitm_type"`
  4213. Memo string `json:"memo"`
  4214. OverlmtAmt float64 `json:"overlmt_amt"`
  4215. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4216. Pric float64 `json:"pric"`
  4217. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4218. SelfpayProp float64 `json:"selfpay_prop"`
  4219. } `json:"result"`
  4220. } `json:"output"`
  4221. RefmsgTime string `json:"refmsg_time"`
  4222. RespondTime string `json:"respond_time"`
  4223. Signtype string `json:"signtype"`
  4224. WarnMsg string `json:"warn_msg"`
  4225. }
  4226. type ResultFive struct {
  4227. Insutype string `json:"insutype"`
  4228. }
  4229. type ResultSix struct {
  4230. Cainfo interface{} `json:"cainfo"`
  4231. ErrMsg interface{} `json:"err_msg"`
  4232. InfRefmsgid string `json:"inf_refmsgid"`
  4233. Infcode int64 `json:"infcode"`
  4234. Output struct {
  4235. } `json:"output"`
  4236. RefmsgTime string `json:"refmsg_time"`
  4237. RespondTime string `json:"respond_time"`
  4238. Signtype interface{} `json:"signtype"`
  4239. WarnMsg interface{} `json:"warn_msg"`
  4240. }
  4241. type ResultSeven struct {
  4242. Cainfo string `json:"cainfo"`
  4243. ErrMsg string `json:"err_msg"`
  4244. InfRefmsgid string `json:"inf_refmsgid"`
  4245. Infcode int64 `json:"infcode"`
  4246. Output struct {
  4247. Setldetail []interface{} `json:"setldetail"`
  4248. Setlinfo struct {
  4249. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4250. AcctPay float64 `json:"acct_pay"`
  4251. ActPayDedc float64 `json:"act_pay_dedc"`
  4252. Age float64 `json:"age"`
  4253. Balc float64 `json:"balc"`
  4254. Brdy string `json:"brdy"`
  4255. Certno string `json:"certno"`
  4256. ClrOptins string `json:"clr_optins"`
  4257. ClrType string `json:"clr_type"`
  4258. ClrWay string `json:"clr_way"`
  4259. CvlservFlag string `json:"cvlserv_flag"`
  4260. CvlservPay float64 `json:"cvlserv_pay"`
  4261. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4262. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4263. Gend string `json:"gend"`
  4264. HifesPay float64 `json:"hifes_pay"`
  4265. HifmiPay float64 `json:"hifmi_pay"`
  4266. HifobPay float64 `json:"hifob_pay"`
  4267. HifpPay float64 `json:"hifp_pay"`
  4268. HospPartAmt float64 `json:"hosp_part_amt"`
  4269. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4270. Insutype string `json:"insutype"`
  4271. MafPay float64 `json:"maf_pay"`
  4272. MdtrtCertType string `json:"mdtrt_cert_type"`
  4273. MdtrtID string `json:"mdtrt_id"`
  4274. MedType string `json:"med_type"`
  4275. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4276. MedinsSetlID string `json:"medins_setl_id"`
  4277. Naty string `json:"naty"`
  4278. OthPay float64 `json:"oth_pay"`
  4279. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4280. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4281. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4282. PsnCashPay float64 `json:"psn_cash_pay"`
  4283. PsnCertType string `json:"psn_cert_type"`
  4284. PsnName string `json:"psn_name"`
  4285. PsnNo string `json:"psn_no"`
  4286. PsnPartAmt float64 `json:"psn_part_amt"`
  4287. PsnType string `json:"psn_type"`
  4288. SetlID string `json:"setl_id"`
  4289. SetlTime string `json:"setl_time"`
  4290. } `json:"setlinfo"`
  4291. } `json:"output"`
  4292. RefmsgTime string `json:"refmsg_time"`
  4293. RespondTime string `json:"respond_time"`
  4294. Signtype interface{} `json:"signtype"`
  4295. WarnMsg interface{} `json:"warn_msg"`
  4296. }
  4297. type ResultEight struct {
  4298. Cainfo string `json:"cainfo"`
  4299. ErrMsg string `json:"err_msg"`
  4300. InfRefmsgid string `json:"inf_refmsgid"`
  4301. Infcode int64 `json:"infcode"`
  4302. Output struct {
  4303. Stmtinfo struct {
  4304. SetlOptins string `json:"setl_optins"`
  4305. StmtRslt string `json:"stmt_rslt"`
  4306. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4307. } `json:"stmtinfo"`
  4308. } `json:"output"`
  4309. RefmsgTime string `json:"refmsg_time"`
  4310. RespondTime string `json:"respond_time"`
  4311. Signtype interface{} `json:"signtype"`
  4312. WarnMsg interface{} `json:"warn_msg"`
  4313. }
  4314. type ResultNine struct {
  4315. Cainfo string `json:"cainfo"`
  4316. ErrMsg string `json:"err_msg"`
  4317. InfRefmsgid string `json:"inf_refmsgid"`
  4318. Infcode int64 `json:"infcode"`
  4319. Output struct {
  4320. FileQuryNo string `json:"file_qury_no"`
  4321. } `json:"output"`
  4322. RefmsgTime string `json:"refmsg_time"`
  4323. RespondTime string `json:"respond_time"`
  4324. Signtype interface{} `json:"signtype"`
  4325. WarnMsg interface{} `json:"warn_msg"`
  4326. }
  4327. type ResultTen struct {
  4328. Cainfo string `json:"cainfo"`
  4329. ErrMsg string `json:"err_msg"`
  4330. InfRefmsgid string `json:"inf_refmsgid"`
  4331. Infcode int64 `json:"infcode"`
  4332. Output struct {
  4333. DldEndtime string `json:"dld_endtime"`
  4334. FileQuryNo string `json:"file_qury_no"`
  4335. Filename string `json:"filename"`
  4336. } `json:"output"`
  4337. RefmsgTime string `json:"refmsg_time"`
  4338. RespondTime string `json:"respond_time"`
  4339. Signtype interface{} `json:"signtype"`
  4340. WarnMsg interface{} `json:"warn_msg"`
  4341. }
  4342. type ResultEleven struct {
  4343. Cainfo string `json:"cainfo"`
  4344. ErrMsg string `json:"err_msg"`
  4345. InfRefmsgid string `json:"inf_refmsgid"`
  4346. Infcode int64 `json:"infcode"`
  4347. Output struct {
  4348. Setlinfo struct {
  4349. FixmedinsName string `json:"fixmedins_name"`
  4350. FixmedinsCode string `json:"fixmedins_code"`
  4351. PsnNo string `json:"psn_no"`
  4352. PsnName string `json:"psn_name"`
  4353. HifobPay float64 `json:"hifob_pay"`
  4354. Gend string `json:"gend"`
  4355. Brdy string `json:"brdy"`
  4356. PsnCertType string `json:"psn_cert_type"`
  4357. PsnType string `json:"psn_type"`
  4358. EmpName string `json:"emp_name"`
  4359. Certno string `json:"certno"`
  4360. Insutype string `json:"insutype"`
  4361. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4362. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4363. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4364. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4365. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4366. ActPayDedc float64 `json:"act_pay_dedc"`
  4367. HifpPay float64 `json:"hifp_pay"`
  4368. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4369. CvlservPay float64 `json:"cvlserv_pay"`
  4370. HifesPay float64 `json:"hifes_pay"`
  4371. HifmiPay float64 `json:"hifmi_pay"`
  4372. MafPay float64 `json:"maf_pay"`
  4373. OthPay float64 `json:"oth_pay"`
  4374. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4375. PsnPay float64 `json:"psn_pay"`
  4376. AcctPay float64 `json:"acct_pay"`
  4377. CashPayamt float64 `json:"cash_payamt"`
  4378. Balc float64 `json:"balc"`
  4379. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4380. MedinsSetlId string `json:"medins_setl_id"`
  4381. RefdSetlFlag string `json:"refd_setl_flag"`
  4382. SetlTime string `json:"setl_time"`
  4383. MedType string `json:"med_type"`
  4384. } `json:"setlinfo"`
  4385. } `json:"output"`
  4386. RefmsgTime string `json:"refmsg_time"`
  4387. RespondTime string `json:"respond_time"`
  4388. Signtype interface{} `json:"signtype"`
  4389. WarnMsg interface{} `json:"warn_msg"`
  4390. }
  4391. type Custom struct {
  4392. DetItemFeeSumamt string
  4393. Cut string
  4394. FeedetlSn string
  4395. Price string
  4396. MedListCodg string
  4397. Type int64
  4398. AdviceId int64
  4399. ProjectId int64
  4400. ItemId int64
  4401. }
  4402. //获取个人信息----挂号-----上传就诊信息
  4403. func (c *HisApiController) GetRegisterInfo() {
  4404. id, _ := c.GetInt64("id")
  4405. record_time := c.GetString("record_time")
  4406. settlementValue, _ := c.GetInt64("settlement_value")
  4407. medical_insurance_card := c.GetString("medical_insurance_card")
  4408. name := c.GetString("name")
  4409. id_card_type, _ := c.GetInt64("id_card_type")
  4410. certificates, _ := c.GetInt64("certificates")
  4411. medical_care, _ := c.GetInt64("medical_care")
  4412. birthday := c.GetString("birthday")
  4413. age, _ := c.GetInt64("age")
  4414. id_card := c.GetString("id_card")
  4415. register_type, _ := c.GetInt64("register")
  4416. doctor, _ := c.GetInt64("doctor")
  4417. department, _ := c.GetInt64("department")
  4418. gender, _ := c.GetInt64("sex")
  4419. phone := c.GetString("phone")
  4420. registration_fee, _ := c.GetFloat("registration_fee")
  4421. medical_expenses, _ := c.GetFloat("medical_expenses")
  4422. social_type, _ := c.GetInt64("social_type")
  4423. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4424. diagnosis_ids := c.GetString("diagnosis")
  4425. sick_type, _ := c.GetInt64("sick_type")
  4426. reg_type := c.GetString("p_type")
  4427. timeLayout := "2006-01-02"
  4428. loc, _ := time.LoadLocation("Local")
  4429. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4430. birthUnix := birthdays.Unix()
  4431. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4432. if err != nil {
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4434. return
  4435. }
  4436. recordDateTime := theTime.Unix()
  4437. adminInfo := c.GetAdminUserInfo()
  4438. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  4439. if tempPatient.ID == 0 {
  4440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  4441. return
  4442. }
  4443. var patient service.Patients
  4444. if id == 0 {
  4445. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  4446. } else {
  4447. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  4448. }
  4449. if patient.ID == 0 {
  4450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4451. return
  4452. }
  4453. if len(patient.IdCardNo) == 0 {
  4454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4455. return
  4456. }
  4457. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4458. if len(his) >= 1 {
  4459. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  4460. if len(his) >= 1 && order.ID == 0 {
  4461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  4462. return
  4463. }
  4464. }
  4465. timeStr := time.Now().Format("2006-01-02 15:04:05")
  4466. fmt.Println(timeStr)
  4467. timeArr := strings.Split(timeStr, " ")
  4468. fmt.Println(timeArr)
  4469. timeArrTwo := strings.Split(timeArr[0], "-")
  4470. timeArrThree := strings.Split(timeArr[1], ":")
  4471. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4472. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4473. if len(lists) == 0 {
  4474. var hisPatient models.XtHisPatient
  4475. hisPatient = models.XtHisPatient{
  4476. Name: name,
  4477. Age: age,
  4478. Gender: gender,
  4479. Birthday: birthUnix,
  4480. Phone: phone,
  4481. MedicalTreatmentType: medical_care,
  4482. IdType: certificates,
  4483. IdCardNo: id_card,
  4484. BalanceAccountsType: settlementValue,
  4485. SocialType: social_type,
  4486. MedicalInsuranceNumber: medical_insurance_card,
  4487. RegisterType: register_type,
  4488. RegisterCost: registration_fee,
  4489. TreatmentCost: medical_expenses,
  4490. AdminUserId: adminInfo.AdminUser.Id,
  4491. UserOrgId: adminInfo.CurrentOrgId,
  4492. Status: 1,
  4493. RecordDate: recordDateTime,
  4494. IsReturn: 1,
  4495. PatientId: patient.ID,
  4496. Ctime: time.Now().Unix(),
  4497. Mtime: time.Now().Unix(),
  4498. Number: str,
  4499. IdCardType: id_card_type,
  4500. Departments: department,
  4501. Doctor: doctor,
  4502. PType: reg_type,
  4503. Diagnosis: diagnosis_ids,
  4504. SickType: sick_type,
  4505. }
  4506. service.CreateHisPatient(&hisPatient)
  4507. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4508. c.ServeSuccessJSON(map[string]interface{}{
  4509. "his_info": hisPatient,
  4510. })
  4511. } else {
  4512. //chrgBchno := rand.Intn(1000000) + 10000
  4513. var hisPatient models.XtHisPatient
  4514. hisPatient = models.XtHisPatient{
  4515. Name: name,
  4516. Age: age,
  4517. Gender: gender,
  4518. Birthday: birthUnix,
  4519. Phone: phone,
  4520. MedicalTreatmentType: medical_care,
  4521. IdType: certificates,
  4522. IdCardNo: id_card,
  4523. BalanceAccountsType: settlementValue,
  4524. SocialType: social_type,
  4525. MedicalInsuranceNumber: medical_insurance_card,
  4526. RegisterType: register_type,
  4527. RegisterCost: registration_fee,
  4528. TreatmentCost: medical_expenses,
  4529. AdminUserId: adminInfo.AdminUser.Id,
  4530. UserOrgId: adminInfo.CurrentOrgId,
  4531. Status: 1,
  4532. RecordDate: recordDateTime,
  4533. IsReturn: 1,
  4534. PatientId: patient.ID,
  4535. Ctime: time.Now().Unix(),
  4536. Mtime: time.Now().Unix(),
  4537. Number: str,
  4538. IdCardType: id_card_type,
  4539. Departments: department,
  4540. Doctor: doctor,
  4541. PType: reg_type,
  4542. Diagnosis: diagnosis_ids,
  4543. SickType: sick_type,
  4544. }
  4545. service.CreateHisPatient(&hisPatient)
  4546. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4547. c.ServeSuccessJSON(map[string]interface{}{
  4548. "his_info": hisPatient,
  4549. })
  4550. }
  4551. }
  4552. //上传明细----结算
  4553. func (c *HisApiController) GetUploadInfo() {
  4554. id, _ := c.GetInt64("id")
  4555. record_time := c.GetString("record_time")
  4556. his_patient_id, _ := c.GetInt64("his_patient_id")
  4557. pay_way, _ := c.GetInt64("pay_way")
  4558. pay_price, _ := c.GetFloat("pay_price")
  4559. pay_card_no := c.GetString("pay_card_no")
  4560. discount_price, _ := c.GetFloat("discount_price")
  4561. preferential_price, _ := c.GetFloat("preferential_price")
  4562. reality_price, _ := c.GetFloat("reality_price")
  4563. found_price, _ := c.GetFloat("found_price")
  4564. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4565. private_price, _ := c.GetFloat("private_price")
  4566. timeLayout := "2006-01-02"
  4567. loc, _ := time.LoadLocation("Local")
  4568. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4569. fapiao_code := c.GetString("fapiao_code")
  4570. fapiao_number := c.GetString("fapiao_number")
  4571. diagnosis_id := c.GetString("diagnosis")
  4572. sick_type, _ := c.GetInt64("sick_type")
  4573. reg_type, _ := c.GetInt64("p_type")
  4574. order_id, _ := c.GetInt64("order_id")
  4575. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4576. tmp_decimal := c.GetString("tmp_decimal")
  4577. var decimal float64 //本次使用的押金
  4578. var errmsg error
  4579. tx := service.XTWriteDB().Begin() //开了事务
  4580. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4581. defer func() {
  4582. if errmsg != nil {
  4583. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4584. tx.Rollback()
  4585. } else {
  4586. tx.Commit()
  4587. }
  4588. }()
  4589. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  4590. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4591. return
  4592. }
  4593. if len(tmp_decimal) > 0 {
  4594. if tmp_decimal[0] == 45 {
  4595. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4596. return
  4597. }
  4598. }
  4599. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4600. fmt.Println(errs)
  4601. //if errs != nil {
  4602. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4603. // return
  4604. //}
  4605. decimal = tt
  4606. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4607. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4609. if err != nil {
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4611. return
  4612. }
  4613. recordDateTime := theTime.Unix()
  4614. adminUser := c.GetAdminUserInfo()
  4615. var prescriptions []*models.HisPrescription
  4616. var start_time int64
  4617. var end_time int64
  4618. ids_str := c.GetString("ids")
  4619. ids_arr := strings.Split(ids_str, ",")
  4620. if tempOrder.ID == 0 {
  4621. if settle_accounts_type == 1 { //日结
  4622. fmt.Println(reg_type)
  4623. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4624. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  4625. } else {
  4626. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  4627. }
  4628. } else { //月结
  4629. start_time_str := c.GetString("start_time")
  4630. end_time_str := c.GetString("end_time")
  4631. timeLayout := "2006-01-02"
  4632. loc, _ := time.LoadLocation("Local")
  4633. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4634. if err != nil {
  4635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4636. return
  4637. }
  4638. recordStartTime := theStartTime.Unix()
  4639. start_time = recordStartTime
  4640. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4641. if err != nil {
  4642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4643. return
  4644. }
  4645. recordEndTime := theEndTime.Unix()
  4646. end_time = recordEndTime
  4647. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  4648. }
  4649. timestamp := time.Now().Unix()
  4650. tempTime := time.Unix(timestamp, 0)
  4651. timeFormat := tempTime.Format("20060102150405")
  4652. chrgBchno := rand.Intn(100000) + 10000
  4653. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4654. strconv.FormatInt(his.PatientId, 10)
  4655. var ids []int64
  4656. for _, item := range prescriptions {
  4657. ids = append(ids, item.ID)
  4658. }
  4659. var total float64
  4660. for _, item := range prescriptions {
  4661. fmt.Println(item)
  4662. if item.Type == 1 { //药品
  4663. for _, subItem := range item.HisDoctorAdviceInfo {
  4664. total = total + (subItem.Price * subItem.PrescribingNumber)
  4665. }
  4666. }
  4667. if item.Type == 2 { //项目
  4668. for _, subItem := range item.HisPrescriptionProject {
  4669. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4670. total = total + (subItem.Price * cnt)
  4671. }
  4672. }
  4673. for _, subItem := range item.HisAdditionalCharge {
  4674. total = total + (subItem.Price * float64(subItem.Count))
  4675. }
  4676. }
  4677. if reg_type == 1111 || reg_type == 1112 {
  4678. reg_type = 11
  4679. }
  4680. tm := time.Unix(time.Now().Unix(), 0)
  4681. allTotal := fmt.Sprintf("%.4f", total)
  4682. totals, _ := strconv.ParseFloat(allTotal, 64)
  4683. order := &models.HisOrder{
  4684. UserOrgId: adminUser.CurrentOrgId,
  4685. HisPatientId: his.ID,
  4686. PatientId: id,
  4687. SettleAccountsDate: recordDateTime,
  4688. Ctime: time.Now().Unix(),
  4689. Mtime: time.Now().Unix(),
  4690. Status: 1,
  4691. OrderStatus: 2,
  4692. MdtrtId: his.Number,
  4693. Number: chrg_bchno,
  4694. MedfeeSumamt: totals,
  4695. PayWay: pay_way,
  4696. PayPrice: pay_price,
  4697. MedType: strconv.Itoa(int(reg_type)),
  4698. PayCardNo: pay_card_no,
  4699. DiscountPrice: discount_price,
  4700. PreferentialPrice: preferential_price,
  4701. RealityPrice: reality_price,
  4702. FoundPrice: found_price,
  4703. MedicalInsurancePrice: medical_insurance_price,
  4704. PrivatePrice: private_price,
  4705. SettleEndTime: end_time,
  4706. SettleStartTime: start_time,
  4707. PsnPartAmt: totals,
  4708. PsnCashPay: totals,
  4709. SettleType: settle_accounts_type,
  4710. FaPiaoCode: fapiao_code,
  4711. FaPiaoNumber: fapiao_number,
  4712. Diagnosis: diagnosis_id,
  4713. PType: 2,
  4714. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4715. Decimal: decimal,
  4716. }
  4717. err = service.CreateOrderTX(order, tx)
  4718. if err != nil {
  4719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4720. return
  4721. }
  4722. var customs []*Custom
  4723. for _, item := range prescriptions {
  4724. if item.Type == 1 { //药品a
  4725. for _, subItem := range item.HisDoctorAdviceInfo {
  4726. cus := &Custom{
  4727. AdviceId: subItem.ID,
  4728. ProjectId: 0,
  4729. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4730. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4731. FeedetlSn: subItem.FeedetlSn,
  4732. Price: fmt.Sprintf("%.4f", subItem.Price),
  4733. MedListCodg: subItem.MedListCodg,
  4734. Type: 1,
  4735. }
  4736. customs = append(customs, cus)
  4737. }
  4738. }
  4739. if item.Type == 2 { //项目
  4740. for _, subItem := range item.HisPrescriptionProject {
  4741. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4742. cus := &Custom{
  4743. AdviceId: 0,
  4744. ProjectId: subItem.ID,
  4745. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4746. Cut: fmt.Sprintf("%.4f", cnt),
  4747. FeedetlSn: subItem.FeedetlSn,
  4748. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4749. MedListCodg: subItem.MedListCodg,
  4750. Type: 2,
  4751. }
  4752. customs = append(customs, cus)
  4753. }
  4754. }
  4755. for _, item := range item.HisAdditionalCharge {
  4756. cus := &Custom{
  4757. ItemId: item.ID,
  4758. AdviceId: 0,
  4759. ProjectId: 0,
  4760. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4761. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4762. FeedetlSn: item.FeedetlSn,
  4763. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4764. MedListCodg: item.XtHisAddtionConfig.Code,
  4765. Type: 3,
  4766. }
  4767. customs = append(customs, cus)
  4768. }
  4769. }
  4770. for _, item := range customs {
  4771. var advice_id int64 = 0
  4772. var project_id int64 = 0
  4773. var item_id int64 = 0
  4774. var types int64 = 0
  4775. if item.Type == 1 {
  4776. advice_id = item.AdviceId
  4777. project_id = 0
  4778. item_id = 0
  4779. } else if item.Type == 2 {
  4780. advice_id = 0
  4781. item_id = 0
  4782. project_id = item.ProjectId
  4783. } else if item.Type == 3 {
  4784. advice_id = 0
  4785. item_id = item.ItemId
  4786. project_id = 0
  4787. }
  4788. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4789. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4790. pric, _ := strconv.ParseFloat(item.Price, 32)
  4791. info := &models.HisOrderInfo{
  4792. OrderNumber: order.Number,
  4793. UploadDate: time.Now().Unix(),
  4794. AdviceId: advice_id,
  4795. DetItemFeeSumamt: detItemFeeSumamt,
  4796. Cnt: cut,
  4797. Pric: pric,
  4798. PatientId: id,
  4799. Status: 1,
  4800. Mtime: time.Now().Unix(),
  4801. Ctime: time.Now().Unix(),
  4802. UserOrgId: adminUser.CurrentOrgId,
  4803. HisPatientId: his.ID,
  4804. OrderId: order.ID,
  4805. ProjectId: project_id,
  4806. Type: types,
  4807. ItemId: item_id,
  4808. }
  4809. service.CreateOrderInfoTX(info, tx)
  4810. }
  4811. his.Diagnosis = diagnosis_id
  4812. his.SickType = sick_type
  4813. his.RegisterType = reg_type
  4814. his.MedicalTreatmentType = reg_type
  4815. service.UpdataHisPateintTX(&his, tx)
  4816. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4817. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4818. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4819. //判断是否使用了押金
  4820. if dec_way == "true" {
  4821. tmpstring := strconv.FormatInt(order.ID, 10)
  4822. //扣押金
  4823. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4824. order.Decimal = decimal
  4825. service.UpDateOrderTwo(order)
  4826. if errmsg != nil {
  4827. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4828. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4829. return
  4830. }
  4831. }
  4832. if err == nil {
  4833. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  4834. var goods []*models.DialysisBeforePrepareGoods
  4835. var newGoods []*models.NewDialysisBeforePrepareGoods
  4836. var infos []*models.HisDoctorAdviceInfo
  4837. for _, info := range prescriptions {
  4838. if info.Type == 1 {
  4839. infos = append(infos, info.HisDoctorAdviceInfo...)
  4840. }
  4841. if info.Type == 2 {
  4842. for _, sumItem := range info.HisPrescriptionProject {
  4843. if sumItem.Type == 3 {
  4844. var good models.DialysisBeforePrepareGoods
  4845. var newGood models.NewDialysisBeforePrepareGoods
  4846. good.GoodId = sumItem.GoodInfo.ID
  4847. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  4848. count, _ := strconv.Atoi(sumItem.Count)
  4849. good.Count = int64(count)
  4850. good.StorehouseId = houseConfig.StorehouseOutInfo
  4851. good.ProjectId = sumItem.ID
  4852. goods = append(goods, &good)
  4853. newGood.GoodId = sumItem.GoodInfo.ID
  4854. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  4855. count2, _ := strconv.Atoi(sumItem.Count)
  4856. newGood.Count = int64(count2)
  4857. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  4858. newGood.ProjectId = sumItem.ID
  4859. newGoods = append(newGoods, &newGood)
  4860. }
  4861. }
  4862. }
  4863. }
  4864. for _, item := range infos {
  4865. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  4866. //service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  4867. }
  4868. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "msg": "结算成功",
  4871. })
  4872. }
  4873. } else {
  4874. if tempOrder.IsPre > 0 {
  4875. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4876. totals, _ := strconv.ParseFloat(allTotal, 64)
  4877. tempOrder.OrderStatus = 2
  4878. tempOrder.PayWay = pay_way
  4879. tempOrder.PayPrice = pay_price
  4880. tempOrder.PayCardNo = pay_card_no
  4881. tempOrder.DiscountPrice = discount_price
  4882. tempOrder.PreferentialPrice = preferential_price
  4883. tempOrder.RealityPrice = reality_price
  4884. tempOrder.FoundPrice = found_price
  4885. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4886. tempOrder.PrivatePrice = private_price
  4887. tempOrder.FaPiaoCode = fapiao_code
  4888. tempOrder.FaPiaoNumber = fapiao_number
  4889. tempOrder.PType = 2
  4890. tempOrder.MedfeeSumamt = totals
  4891. tempOrder.Diagnosis = diagnosis_id
  4892. err = service.SaveHisOrder(&tempOrder)
  4893. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4894. if err != nil {
  4895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4896. return
  4897. }
  4898. if err == nil {
  4899. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  4900. var goods []*models.DialysisBeforePrepareGoods
  4901. var newGoods []*models.NewDialysisBeforePrepareGoods
  4902. var infos []*models.HisDoctorAdviceInfo
  4903. for _, info := range prescriptions {
  4904. if info.Type == 1 {
  4905. infos = append(infos, info.HisDoctorAdviceInfo...)
  4906. }
  4907. if info.Type == 2 {
  4908. for _, sumItem := range info.HisPrescriptionProject {
  4909. if sumItem.Type == 3 {
  4910. var good models.DialysisBeforePrepareGoods
  4911. var newGood models.NewDialysisBeforePrepareGoods
  4912. good.GoodId = sumItem.GoodInfo.ID
  4913. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  4914. count, _ := strconv.Atoi(sumItem.Count)
  4915. good.Count = int64(count)
  4916. good.StorehouseId = houseConfig.StorehouseOutInfo
  4917. good.ProjectId = sumItem.ID
  4918. goods = append(goods, &good)
  4919. newGood.GoodId = sumItem.GoodInfo.ID
  4920. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  4921. count2, _ := strconv.Atoi(sumItem.Count)
  4922. newGood.Count = int64(count2)
  4923. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  4924. newGood.ProjectId = sumItem.ID
  4925. newGoods = append(newGoods, &newGood)
  4926. }
  4927. }
  4928. }
  4929. }
  4930. for _, item := range infos {
  4931. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  4932. }
  4933. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  4934. c.ServeSuccessJSON(map[string]interface{}{
  4935. "msg": "结算成功",
  4936. })
  4937. }
  4938. }
  4939. }
  4940. }
  4941. //退款
  4942. func (c *HisApiController) Refund() {
  4943. order_id, _ := c.GetInt64("order_id")
  4944. order, _ := service.GetHisOrderByID(order_id)
  4945. adminUser := c.GetAdminUserInfo()
  4946. orgid := c.GetAdminUserInfo().CurrentOrgId
  4947. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4948. if err != nil {
  4949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4950. return
  4951. }
  4952. tmp := strconv.FormatInt(order.ID, 10)
  4953. //当押金不为零时产生退费记录
  4954. if order.Decimal != 0 {
  4955. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  4956. if err != nil {
  4957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4958. return
  4959. }
  4960. }
  4961. if order.ID == 0 {
  4962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4963. return
  4964. }
  4965. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  4966. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  4967. var goods []*models.DialysisBeforePrepareGoods
  4968. var newGoods []*models.NewDialysisBeforePrepareGoods
  4969. var infos []*models.HisDoctorAdviceInfo
  4970. for _, info := range orders {
  4971. if info.AdviceId > 0 && info.ProjectId == 0 {
  4972. infos = append(infos, &info.HisDoctorAdviceInfo)
  4973. }
  4974. if info.ProjectId > 0 && info.AdviceId == 0 {
  4975. if info.HisPrescriptionProject.Type == 3 {
  4976. var good models.DialysisBeforePrepareGoods
  4977. var newGood models.NewDialysisBeforePrepareGoods
  4978. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  4979. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  4980. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  4981. good.Count = int64(count)
  4982. good.StorehouseId = houseConfig.StorehouseOutInfo
  4983. good.ProjectId = info.HisPrescriptionProject.ID
  4984. goods = append(goods, &good)
  4985. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  4986. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  4987. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  4988. newGood.Count = int64(count2)
  4989. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  4990. newGood.ProjectId = info.HisPrescriptionProject.ID
  4991. newGoods = append(newGoods, &newGood)
  4992. }
  4993. }
  4994. }
  4995. for _, item := range infos {
  4996. service.DrugAutoAddCancelInfo(item, order.Creator)
  4997. }
  4998. c.ServeSuccessJSON(map[string]interface{}{
  4999. "msg": "退费成功",
  5000. })
  5001. }
  5002. func (c *HisApiController) RefundNumber() {
  5003. his_patient_id, _ := c.GetInt64("id")
  5004. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5005. info.Status = 0
  5006. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  5007. if count > 0 {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  5009. return
  5010. }
  5011. err := service.SaveHisPatient(info)
  5012. if err == nil {
  5013. c.ServeSuccessJSON(map[string]interface{}{
  5014. "msg": "退号成功",
  5015. })
  5016. } else {
  5017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5018. return
  5019. }
  5020. }
  5021. func (this *HisApiController) AdditionalCharge() {
  5022. dataBody := make(map[string]interface{}, 0)
  5023. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5024. fmt.Println(err)
  5025. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  5026. patient_id := int64(dataBody["patient_id"].(float64))
  5027. medicineData, _ := dataBody["medicineData"].([]interface{})
  5028. adminUserInfo := this.GetAdminUserInfo()
  5029. orgId := adminUserInfo.CurrentOrgId
  5030. admin_user_id := adminUserInfo.AdminUser.Id
  5031. timeStr := time.Now().Format("2006-01-02")
  5032. timeLayout := "2006-01-02 15:04:05"
  5033. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  5034. timenow := timeStringToTime.Unix()
  5035. var additionalCharges []*models.HisAdditionalCharge
  5036. for _, item := range medicineData {
  5037. var randNum int
  5038. randNum = rand.Intn(10000) + 1000
  5039. timestamp := time.Now().Unix()
  5040. tempTime := time.Unix(timestamp, 0)
  5041. timeFormat := tempTime.Format("20060102150405")
  5042. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5043. items := item.(map[string]interface{})
  5044. money := items["price"].(string)
  5045. item_id_str := items["item_id"].(string)
  5046. name := items["name"].(string)
  5047. id_str := items["id"].(string)
  5048. moneys, _ := strconv.ParseInt(money, 10, 64)
  5049. monStr := strconv.FormatInt(moneys, 10)
  5050. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  5051. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  5052. id, _ := strconv.ParseInt(id_str, 10, 64)
  5053. additionalCharge := &models.HisAdditionalCharge{
  5054. ID: id,
  5055. HisPatientId: his_patient_id,
  5056. UserOrgId: orgId,
  5057. PatientId: patient_id,
  5058. RecordDate: timenow,
  5059. Price: monneyStr,
  5060. Status: 1,
  5061. ItemName: name,
  5062. ItemId: item_id,
  5063. AdminUserId: admin_user_id,
  5064. CreatedTime: time.Now().Unix(),
  5065. OrderStatus: 0,
  5066. PrescriptionNumber: "",
  5067. BatchNumber: "",
  5068. FeedetlSn: p_number,
  5069. }
  5070. service.CreateAdditionalCharge(additionalCharge)
  5071. additionalCharges = append(additionalCharges, additionalCharge)
  5072. }
  5073. this.ServeSuccessJSON(map[string]interface{}{
  5074. "msg": "添加成功",
  5075. "additional_charges": additionalCharges,
  5076. })
  5077. }
  5078. func (this *HisApiController) DeleteAddition() {
  5079. id, _ := this.GetInt64("id")
  5080. //TODO 需要判断是否已经结算
  5081. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  5082. if err == nil {
  5083. this.ServeSuccessJSON(map[string]interface{}{
  5084. "msg": "删除成功",
  5085. })
  5086. return
  5087. } else {
  5088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5089. return
  5090. }
  5091. }
  5092. func (this *HisApiController) GetAdminUsers() {
  5093. adminUser := this.GetAdminUserInfo()
  5094. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  5095. this.ServeSuccessJSON(map[string]interface{}{
  5096. "doctors": doctors,
  5097. })
  5098. }
  5099. func (this *HisApiController) GetLastOrNextHisPrescription() {
  5100. change_type, _ := this.GetInt64("type", 0)
  5101. record_date := this.GetString("record_time")
  5102. patient_id, _ := this.GetInt64("patient_id", 0)
  5103. p_type, _ := this.GetInt64("p_type", 0)
  5104. timeLayout := "2006-01-02"
  5105. loc, _ := time.LoadLocation("Local")
  5106. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5107. record_time := theAdviceRecordTime.Unix()
  5108. adminUserInfo := this.GetAdminUserInfo()
  5109. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  5110. if err == nil {
  5111. if len(prescriptions) == 0 {
  5112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5113. return
  5114. } else {
  5115. this.ServeSuccessJSON(map[string]interface{}{
  5116. "prescriptions": prescriptions,
  5117. })
  5118. return
  5119. }
  5120. } else {
  5121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5122. return
  5123. }
  5124. }
  5125. func (this *HisApiController) GetCallHisPrescription() {
  5126. patient_id, _ := this.GetInt64("patient_id", 0)
  5127. timeLayout := "2006-01-02"
  5128. loc, _ := time.LoadLocation("Local")
  5129. start_time := this.GetString("start_time")
  5130. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5131. end_time := this.GetString("end_time")
  5132. p_type, _ := this.GetInt64("p_type")
  5133. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5134. adminUserInfo := this.GetAdminUserInfo()
  5135. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  5136. if err == nil {
  5137. this.ServeSuccessJSON(map[string]interface{}{
  5138. "prescriptions": prescriptions,
  5139. })
  5140. return
  5141. } else {
  5142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5143. return
  5144. }
  5145. }
  5146. func (this *HisApiController) GetHisDayPrescription() {
  5147. timeLayout := "2006-01-02"
  5148. loc, _ := time.LoadLocation("Local")
  5149. start_time := this.GetString("start_time")
  5150. patient_id, _ := this.GetInt64("patient_id", 0)
  5151. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5152. end_time := this.GetString("end_time")
  5153. p_type, _ := this.GetInt64("p_type")
  5154. order_status, _ := this.GetInt64("type")
  5155. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5156. adminUserInfo := this.GetAdminUserInfo()
  5157. var dayHisPrescription []*models.HisPrescription
  5158. var err error
  5159. if order_status == 1 || order_status == 0 {
  5160. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  5161. } else if order_status == 2 {
  5162. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  5163. }
  5164. var settle_total float64
  5165. for _, item := range dayHisPrescription {
  5166. if len(item.HisPrescriptionProject) > 0 {
  5167. for _, subItem := range item.HisPrescriptionProject {
  5168. count, _ := strconv.ParseFloat(subItem.Count, 64)
  5169. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  5170. settle_total = settle_total + total
  5171. }
  5172. }
  5173. if len(item.HisDoctorAdviceInfo) > 0 {
  5174. for _, subItem := range item.HisDoctorAdviceInfo {
  5175. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  5176. settle_total = settle_total + total
  5177. }
  5178. }
  5179. }
  5180. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  5181. if err == nil {
  5182. this.ServeSuccessJSON(map[string]interface{}{
  5183. "day_prescription": dayHisPrescription,
  5184. "settle_total": settle_total,
  5185. })
  5186. return
  5187. } else {
  5188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5189. return
  5190. }
  5191. }
  5192. func (c *HisApiController) GetHisChargePatientList() {
  5193. record_date := c.GetString("record_date")
  5194. order_status, _ := c.GetInt64("type")
  5195. timeLayout := "2006-01-02"
  5196. loc, _ := time.LoadLocation("Local")
  5197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5198. if err != nil {
  5199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5200. return
  5201. }
  5202. recordDateTime := theTime.Unix()
  5203. adminInfo := c.GetAdminUserInfo()
  5204. var tempPatients []*service.NewTempPatients
  5205. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  5206. if order_status != 2 {
  5207. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  5208. } else {
  5209. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  5210. }
  5211. var patients []*service.NewTempPatients
  5212. var patients_two []*service.NewTempPatients
  5213. for _, item := range tempPatients {
  5214. //过滤掉没挂号的和没开处方的
  5215. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  5216. patients = append(patients, item)
  5217. }
  5218. //过滤掉没挂号的
  5219. if len(item.HisPatient) > 0 {
  5220. patients_two = append(patients_two, item)
  5221. }
  5222. }
  5223. c.ServeSuccessJSON(map[string]interface{}{
  5224. "list": patients,
  5225. "list_two": patients_two,
  5226. })
  5227. }
  5228. func (c *HisApiController) GetHisUnRegisterPatientList() {
  5229. record_date := c.GetString("record_date")
  5230. timeLayout := "2006-01-02"
  5231. loc, _ := time.LoadLocation("Local")
  5232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5233. if err != nil {
  5234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5235. return
  5236. }
  5237. recordDateTime := theTime.Unix()
  5238. adminUser := c.GetAdminUserInfo()
  5239. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  5240. var patients []*service.Patients
  5241. for _, item := range tempPatients {
  5242. if item.HisPatient.ID == 0 {
  5243. patients = append(patients, item)
  5244. }
  5245. }
  5246. c.ServeSuccessJSON(map[string]interface{}{
  5247. "list": patients,
  5248. //"list_two": patients_two,
  5249. })
  5250. }
  5251. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  5252. newArr = make([]*service.Patients, 0)
  5253. for i := 0; i < len(patient); i++ {
  5254. repeat := false
  5255. for j := i + 1; j < len(patient); j++ {
  5256. if patient[i].ID == patient[j].ID {
  5257. repeat = true
  5258. break
  5259. }
  5260. }
  5261. if !repeat {
  5262. newArr = append(newArr, patient[i])
  5263. }
  5264. }
  5265. return
  5266. }
  5267. func (c *HisApiController) GetHisChargePatientInfo() {
  5268. patient_id, _ := c.GetInt64("patient_id")
  5269. his_patient_id, _ := c.GetInt64("his_patient_id")
  5270. record_date := c.GetString("record_date")
  5271. //start_time := c.GetString("start_time")
  5272. //end_time := c.GetString("end_time")
  5273. order_status, _ := c.GetInt64("type", 0)
  5274. p_type, _ := c.GetInt64("p_type", 0)
  5275. order_id, _ := c.GetInt64("order_id", 0)
  5276. timeLayout := "2006-01-02"
  5277. loc, _ := time.LoadLocation("Local")
  5278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5279. if err != nil {
  5280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5281. return
  5282. }
  5283. recordDateTime := theTime.Unix()
  5284. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5285. //if err != nil {
  5286. //
  5287. //}
  5288. //startRecordDateTime := startTime.Unix()
  5289. //
  5290. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5291. //if err != nil {
  5292. //
  5293. //}
  5294. //endRecordDateTime := endTime.Unix()
  5295. admin := c.GetAdminUserInfo()
  5296. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5297. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5298. var prescriptions []*models.HisPrescription
  5299. //var unChargeMonthPrescriptions []*models.HisPrescription
  5300. order, _ := service.GetHisOrderByID(order_id)
  5301. if order_status == 1 || order_status == 0 {
  5302. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  5303. } else if order_status == 2 {
  5304. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5305. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5306. }
  5307. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5308. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5309. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5310. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5311. //获取所有科室信息
  5312. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5313. c.ServeSuccessJSON(map[string]interface{}{
  5314. "his_info": his_patient_info,
  5315. "xt_info": xt_patient_info,
  5316. "prescription": prescriptions,
  5317. "case_history": case_history,
  5318. "info": patientPrescriptionInfo,
  5319. "last_info": lastPatientPrescriptionInfo,
  5320. "order": order,
  5321. "doctors": doctors,
  5322. "department": department,
  5323. })
  5324. return
  5325. }
  5326. func (c *HisApiController) GetAllOrderDetail() {
  5327. order_id, _ := c.GetInt64("id", 0)
  5328. order, _ := service.GetHisOrderByID(order_id)
  5329. if order.ID == 0 {
  5330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5331. return
  5332. }
  5333. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5334. org_id := c.GetAdminUserInfo().CurrentOrgId
  5335. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5336. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5337. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5338. c.ServeSuccessJSON(map[string]interface{}{
  5339. "order": order,
  5340. "order_info": order_info,
  5341. "patient": patient,
  5342. "admin_info": adminInfo,
  5343. "hospital_record": record,
  5344. })
  5345. return
  5346. }
  5347. func (c *HisApiController) GetAllOrderDetailCollect() {
  5348. order_id, _ := c.GetInt64("id", 0)
  5349. order, _ := service.GetHisOrderByID(order_id)
  5350. if order.ID == 0 {
  5351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5352. return
  5353. }
  5354. org_id := c.GetAdminUserInfo().CurrentOrgId
  5355. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5356. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5357. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5358. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  5359. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  5360. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5361. var bedCostTotal float64 = 0 //床位总费
  5362. //var bedCostSelfTotal float64 = 0 //床位自费
  5363. var operationCostTotal float64 = 0 //手术费
  5364. //var operationCostSelfTotal float64 = 0 //手术费
  5365. var otherCostTotal float64 = 0 //其他费用
  5366. //var otherCostSelfTotal float64 = 0 //其他费用
  5367. var materialCostTotal float64 = 0 //材料费
  5368. //var materialCostSelfTotal float64 = 0 //材料费
  5369. var westernMedicineCostTotal float64 = 0 //西药费
  5370. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  5371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5372. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5373. var checkCostTotal float64 = 0 //检查费
  5374. //var checkCostSelfTotal float64 = 0 //检查费
  5375. var laboratoryCostTotal float64 = 0 //化验费
  5376. //var laboratoryCostSelfTotal float64 = 0 //化验费
  5377. var treatCostTotal float64 = 0 //治疗费用
  5378. //var treatCostSelfTotal float64 = 0 //治疗费用
  5379. var zhenChaCostTotal float64 = 0 //其他费用
  5380. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5381. decimal.DivisionPrecision = 2
  5382. var BalanceAccountsType int64
  5383. if his.ID > 0 {
  5384. BalanceAccountsType = his.BalanceAccountsType
  5385. } else {
  5386. BalanceAccountsType = record.BalanceAccountsType
  5387. }
  5388. if BalanceAccountsType != 2 {
  5389. for _, item := range order_info {
  5390. if org_id == 10215 {
  5391. if item.MedChrgitmType == "01" { //床位费
  5392. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5393. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5394. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5395. }
  5396. if item.MedChrgitmType == "02" { //诊察费
  5397. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5398. //zhenChaCostSelfTotal = zhenChaCostTotal
  5399. }
  5400. if item.MedChrgitmType == "03" { //检查费
  5401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5402. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5403. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5404. }
  5405. //if item.MedChrgitmType == "02" { //检查费
  5406. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5407. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5408. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5409. //}
  5410. if item.MedChrgitmType == "04" { //化验费
  5411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5412. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5413. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5414. }
  5415. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5417. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5418. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5419. }
  5420. if item.MedChrgitmType == "06" { //手术费
  5421. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5422. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5423. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5424. }
  5425. if item.MedChrgitmType == "08" { //材料费
  5426. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5427. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5428. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5429. }
  5430. if item.MedChrgitmType == "09" { //西药费
  5431. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5432. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5433. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5434. }
  5435. if item.MedChrgitmType == "11" { //中成费
  5436. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5437. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5438. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5439. }
  5440. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5441. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5442. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5443. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5444. }
  5445. } else if org_id == 10188 || org_id == 10217 {
  5446. if item.MedChrgitmType == "01" { //床位费
  5447. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5448. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5449. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5450. }
  5451. if item.MedChrgitmType == "02" { //诊察费
  5452. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5453. //zhenChaCostSelfTotal = zhenChaCostTotal
  5454. }
  5455. if item.MedChrgitmType == "03" { //检查费
  5456. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5457. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5458. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5459. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5460. }
  5461. //if item.MedChrgitmType == "02" { //检查费
  5462. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5463. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5464. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5465. //}
  5466. if item.MedChrgitmType == "04" { //化验费
  5467. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5468. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5469. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5470. }
  5471. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5472. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5473. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5474. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5475. }
  5476. if item.MedChrgitmType == "06" { //手术费
  5477. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5478. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5479. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5480. }
  5481. if item.MedChrgitmType == "08" { //材料费
  5482. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5483. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5484. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5485. }
  5486. if item.MedChrgitmType == "09" { //西药费
  5487. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5488. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5489. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5490. }
  5491. if item.MedChrgitmType == "11" { //中成费
  5492. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5493. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5494. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5495. }
  5496. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5497. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5498. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5499. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5500. }
  5501. } else {
  5502. if item.MedChrgitmType == "01" { //床位费
  5503. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5504. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5505. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5506. }
  5507. //if item.MedChrgitmType == "02" { //诊察费
  5508. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5509. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5510. //}
  5511. if item.MedChrgitmType == "03" { //检查费
  5512. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5513. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5514. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5515. }
  5516. //if item.MedChrgitmType == "02" { //检查费
  5517. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5518. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5519. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5520. //}
  5521. if item.MedChrgitmType == "04" { //化验费
  5522. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5523. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5524. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5525. }
  5526. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5527. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5528. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5529. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5530. }
  5531. if item.MedChrgitmType == "06" { //手术费
  5532. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5533. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5534. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5535. }
  5536. if item.MedChrgitmType == "08" { //材料费
  5537. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5538. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5539. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5540. }
  5541. if item.MedChrgitmType == "09" { //西药费
  5542. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5543. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5544. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5545. }
  5546. if item.MedChrgitmType == "11" { //中成费
  5547. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5548. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5549. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5550. }
  5551. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5552. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5553. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5554. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5555. }
  5556. }
  5557. }
  5558. c.ServeSuccessJSON(map[string]interface{}{
  5559. "order": order,
  5560. "order_info": order_info,
  5561. "patient": patient,
  5562. "admin_info": adminInfo,
  5563. "his_hospital": record,
  5564. "bedCostTotal": bedCostTotal,
  5565. "operationCostTotal": operationCostTotal,
  5566. "otherCostTotal": otherCostTotal,
  5567. "materialCostTotal": materialCostTotal,
  5568. "westernMedicineCostTotal": westernMedicineCostTotal,
  5569. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5570. "checkCostTotal": checkCostTotal,
  5571. "zhenChaCostTotal": zhenChaCostTotal,
  5572. "laboratoryCostTotal": laboratoryCostTotal,
  5573. "treatCostTotal": treatCostTotal,
  5574. })
  5575. } else {
  5576. for _, item := range order_info {
  5577. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5578. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5579. item.MedChrgitmType = "09"
  5580. }
  5581. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5582. if item.HisPrescriptionProject.Type == 2 {
  5583. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5584. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5585. case 0:
  5586. item.MedChrgitmType = "0"
  5587. break
  5588. case 1:
  5589. item.MedChrgitmType = "14"
  5590. break
  5591. case 2:
  5592. item.MedChrgitmType = "05"
  5593. break
  5594. case 3:
  5595. item.MedChrgitmType = "03"
  5596. break
  5597. case 4:
  5598. item.MedChrgitmType = "03"
  5599. break
  5600. case 5:
  5601. item.MedChrgitmType = "08"
  5602. break
  5603. case 6:
  5604. item.MedChrgitmType = "14"
  5605. break
  5606. case 7:
  5607. item.MedChrgitmType = "14"
  5608. break
  5609. case 8:
  5610. item.MedChrgitmType = "03"
  5611. break
  5612. case 9:
  5613. item.MedChrgitmType = "14"
  5614. break
  5615. case 10:
  5616. item.MedChrgitmType = "14"
  5617. break
  5618. case 11:
  5619. item.MedChrgitmType = "06"
  5620. break
  5621. case 12:
  5622. item.MedChrgitmType = "12"
  5623. break
  5624. case 13:
  5625. item.MedChrgitmType = "01"
  5626. break
  5627. case 14:
  5628. item.MedChrgitmType = "04"
  5629. break
  5630. case 15:
  5631. item.MedChrgitmType = "14"
  5632. break
  5633. }
  5634. } else {
  5635. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5636. case 1:
  5637. item.MedChrgitmType = "14"
  5638. break
  5639. case 2:
  5640. item.MedChrgitmType = "05"
  5641. break
  5642. case 3:
  5643. item.MedChrgitmType = "04"
  5644. break
  5645. case 4:
  5646. item.MedChrgitmType = "14"
  5647. break
  5648. case 5:
  5649. item.MedChrgitmType = "08"
  5650. break
  5651. case 6:
  5652. item.MedChrgitmType = "14"
  5653. break
  5654. case 7:
  5655. item.MedChrgitmType = "14"
  5656. break
  5657. case 8:
  5658. item.MedChrgitmType = "03"
  5659. break
  5660. case 9:
  5661. item.MedChrgitmType = "14"
  5662. break
  5663. }
  5664. }
  5665. } else if item.HisPrescriptionProject.Type == 3 {
  5666. item.MedChrgitmType = "08"
  5667. }
  5668. }
  5669. }
  5670. for _, item := range order_info {
  5671. if org_id == 10215 {
  5672. if item.MedChrgitmType == "01" { //床位费
  5673. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5674. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5675. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5676. }
  5677. if item.MedChrgitmType == "02" { //诊察费
  5678. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5679. //zhenChaCostSelfTotal = zhenChaCostTotal
  5680. }
  5681. if item.MedChrgitmType == "03" { //检查费
  5682. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5683. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5684. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5685. }
  5686. //if item.MedChrgitmType == "02" { //检查费
  5687. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5688. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5689. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5690. //}
  5691. if item.MedChrgitmType == "04" { //化验费
  5692. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5693. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5694. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5695. }
  5696. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5697. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5698. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5699. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5700. }
  5701. if item.MedChrgitmType == "06" { //手术费
  5702. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5703. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5704. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5705. }
  5706. if item.MedChrgitmType == "08" { //材料费
  5707. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5708. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5709. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5710. }
  5711. if item.MedChrgitmType == "09" { //西药费
  5712. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5713. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5714. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5715. }
  5716. if item.MedChrgitmType == "11" { //中成费
  5717. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5718. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5719. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5720. }
  5721. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5722. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5723. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5724. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5725. }
  5726. } else {
  5727. if item.MedChrgitmType == "01" { //床位费
  5728. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5729. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5730. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5731. }
  5732. //if item.MedChrgitmType == "02" { //诊察费
  5733. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5734. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5735. //}
  5736. if item.MedChrgitmType == "03" { //检查费
  5737. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5738. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5739. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5740. }
  5741. //if item.MedChrgitmType == "02" { //检查费
  5742. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5743. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5744. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5745. //}
  5746. if item.MedChrgitmType == "04" { //化验费
  5747. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5748. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5749. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5750. }
  5751. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5752. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5753. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5754. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5755. }
  5756. if item.MedChrgitmType == "06" { //手术费
  5757. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5758. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5759. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5760. }
  5761. if item.MedChrgitmType == "08" { //材料费
  5762. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5763. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5764. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5765. }
  5766. if item.MedChrgitmType == "09" { //西药费
  5767. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5768. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5769. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5770. }
  5771. if item.MedChrgitmType == "11" { //中成费
  5772. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5773. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5774. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5775. }
  5776. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5777. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5778. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5779. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5780. }
  5781. }
  5782. }
  5783. c.ServeSuccessJSON(map[string]interface{}{
  5784. "order": order,
  5785. "order_info": order_info,
  5786. "patient": patient,
  5787. "admin_info": adminInfo,
  5788. "his_hospital": record,
  5789. "bedCostTotal": bedCostTotal,
  5790. "operationCostTotal": operationCostTotal,
  5791. "otherCostTotal": otherCostTotal,
  5792. "materialCostTotal": materialCostTotal,
  5793. "westernMedicineCostTotal": westernMedicineCostTotal,
  5794. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5795. "checkCostTotal": checkCostTotal,
  5796. "zhenChaCostTotal": zhenChaCostTotal,
  5797. "laboratoryCostTotal": laboratoryCostTotal,
  5798. "treatCostTotal": treatCostTotal,
  5799. })
  5800. }
  5801. }
  5802. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5803. page, _ := c.GetInt64("page")
  5804. limit, _ := c.GetInt64("limit")
  5805. keywords := c.GetString("keywords")
  5806. start_time := c.GetString("start_time")
  5807. end_time := c.GetString("end_time")
  5808. //clr_type := c.GetString("clr_type")
  5809. insutype := c.GetString("insutype")
  5810. timeLayout := "2006-01-02"
  5811. loc, _ := time.LoadLocation("Local")
  5812. var theStartTIme int64
  5813. if len(start_time) > 0 {
  5814. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5815. theStartTIme = theTime.Unix()
  5816. }
  5817. var theEndtTIme int64
  5818. if len(end_time) > 0 {
  5819. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5820. theEndtTIme = theTime.Unix()
  5821. }
  5822. if page <= 0 {
  5823. page = 1
  5824. }
  5825. if limit <= 0 {
  5826. limit = 10
  5827. }
  5828. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5829. c.ServeSuccessJSON(map[string]interface{}{
  5830. "total": total,
  5831. "list": list,
  5832. })
  5833. return
  5834. }
  5835. func (c *HisApiController) GetPutOnRecordList() {
  5836. page, _ := c.GetInt64("page")
  5837. limit, _ := c.GetInt64("limit")
  5838. keywords := c.GetString("keywords")
  5839. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5840. if page <= 0 {
  5841. page = 1
  5842. }
  5843. if limit <= 0 {
  5844. limit = 10
  5845. }
  5846. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5847. c.ServeSuccessJSON(map[string]interface{}{
  5848. "total": total,
  5849. "list": list,
  5850. })
  5851. return
  5852. }
  5853. func (c *HisApiController) GetCompareData() {
  5854. start_time := c.GetString("start_time")
  5855. end_time := c.GetString("end_time")
  5856. insutype := c.GetString("insutype")
  5857. clr_type := c.GetString("clr_type")
  5858. timeLayout := "2006-01-02"
  5859. loc, _ := time.LoadLocation("Local")
  5860. var theStartTIme int64
  5861. if len(start_time) > 0 {
  5862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5863. if err != nil {
  5864. theStartTIme = 0
  5865. }
  5866. theStartTIme = theTime.Unix()
  5867. }
  5868. var theEndtTIme int64
  5869. if len(end_time) > 0 {
  5870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5871. if err != nil {
  5872. theEndtTIme = 0
  5873. }
  5874. theEndtTIme = theTime.Unix()
  5875. }
  5876. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5877. fmt.Println(err)
  5878. if err == nil {
  5879. c.ServeSuccessJSON(map[string]interface{}{
  5880. "list": formData,
  5881. })
  5882. } else {
  5883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5884. return
  5885. }
  5886. }
  5887. func (c *HisApiController) GetFaPiaoData() {
  5888. order_id, _ := c.GetInt64("order_id")
  5889. patient_id, _ := c.GetInt64("patient_id")
  5890. number := c.GetString("number")
  5891. adminUser := c.GetAdminUserInfo()
  5892. order, _ := service.GetHisOrderByID(order_id)
  5893. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5894. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5895. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5896. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5897. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5898. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5899. var bedCostTotal float64 = 0 //床位总费
  5900. var bedCostSelfTotal float64 = 0 //床位自费
  5901. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5902. var operationCostTotal float64 = 0 //手术费
  5903. var operationCostSelfTotal float64 = 0 //手术费
  5904. var operationCostPartSelfTotal float64 = 0 //手术费
  5905. var otherCostTotal float64 = 0 //其他费用
  5906. var otherCostSelfTotal float64 = 0 //其他费用
  5907. var otherCostPartSelfTotal float64 = 0 //其他费用
  5908. var materialCostTotal float64 = 0 //材料费
  5909. var materialCostSelfTotal float64 = 0 //材料费
  5910. var materialCostPartSelfTotal float64 = 0 //材料费
  5911. var westernMedicineCostTotal float64 = 0 //西药费
  5912. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5913. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5914. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5915. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5916. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5917. var checkCostTotal float64 = 0 //检查费
  5918. var checkCostSelfTotal float64 = 0 //检查费
  5919. var checkCostPartSelfTotal float64 = 0 //检查费
  5920. var laboratoryCostTotal float64 = 0 //化验费
  5921. var laboratoryCostSelfTotal float64 = 0 //化验费
  5922. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5923. var treatCostTotal float64 = 0 //治疗费用
  5924. var treatCostSelfTotal float64 = 0 //治疗费用
  5925. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5926. var zhenChaCostTotal float64 = 0 //其他费用
  5927. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5928. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5929. decimal.DivisionPrecision = 2
  5930. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5931. var balanceAccountsType int64
  5932. if his.ID > 0 {
  5933. balanceAccountsType = his.BalanceAccountsType
  5934. } else {
  5935. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5936. }
  5937. if balanceAccountsType == 2 {
  5938. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5939. for _, item := range orderInfos_two {
  5940. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5941. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5942. item.MedChrgitmType = "09"
  5943. }
  5944. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5945. if item.HisPrescriptionProject.Type == 2 {
  5946. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5947. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5948. case 0:
  5949. item.MedChrgitmType = "0"
  5950. break
  5951. case 1:
  5952. item.MedChrgitmType = "14"
  5953. break
  5954. case 2:
  5955. item.MedChrgitmType = "05"
  5956. break
  5957. case 3:
  5958. item.MedChrgitmType = "03"
  5959. break
  5960. case 4:
  5961. item.MedChrgitmType = "03"
  5962. break
  5963. case 5:
  5964. item.MedChrgitmType = "08"
  5965. break
  5966. case 6:
  5967. item.MedChrgitmType = "14"
  5968. break
  5969. case 7:
  5970. item.MedChrgitmType = "14"
  5971. break
  5972. case 8:
  5973. item.MedChrgitmType = "03"
  5974. break
  5975. case 9:
  5976. item.MedChrgitmType = "14"
  5977. break
  5978. case 10:
  5979. item.MedChrgitmType = "14"
  5980. break
  5981. case 11:
  5982. item.MedChrgitmType = "06"
  5983. break
  5984. case 12:
  5985. item.MedChrgitmType = "12"
  5986. break
  5987. case 13:
  5988. item.MedChrgitmType = "01"
  5989. break
  5990. case 14:
  5991. item.MedChrgitmType = "04"
  5992. break
  5993. case 15:
  5994. item.MedChrgitmType = "02"
  5995. break
  5996. }
  5997. } else {
  5998. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5999. case 1:
  6000. item.MedChrgitmType = "14"
  6001. break
  6002. case 2:
  6003. item.MedChrgitmType = "05"
  6004. break
  6005. case 3:
  6006. item.MedChrgitmType = "03"
  6007. break
  6008. case 4:
  6009. item.MedChrgitmType = "03"
  6010. break
  6011. case 5:
  6012. item.MedChrgitmType = "08"
  6013. break
  6014. case 6:
  6015. item.MedChrgitmType = "14"
  6016. break
  6017. case 7:
  6018. item.MedChrgitmType = "14"
  6019. break
  6020. case 8:
  6021. item.MedChrgitmType = "03"
  6022. break
  6023. case 9:
  6024. item.MedChrgitmType = "14"
  6025. break
  6026. }
  6027. }
  6028. } else if item.HisPrescriptionProject.Type == 3 {
  6029. item.MedChrgitmType = "08"
  6030. }
  6031. }
  6032. }
  6033. for _, item := range orderInfos_two {
  6034. fmt.Println(item.MedChrgitmType)
  6035. if item.MedChrgitmType == "01" { //床位费
  6036. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6037. bedCostSelfTotal = bedCostTotal
  6038. }
  6039. if item.MedChrgitmType == "02" { //诊察费
  6040. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6041. zhenChaCostSelfTotal = zhenChaCostTotal
  6042. }
  6043. if item.MedChrgitmType == "03" { //检查费
  6044. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6045. checkCostSelfTotal = checkCostTotal
  6046. }
  6047. if item.MedChrgitmType == "04" { //化验费
  6048. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6049. laboratoryCostSelfTotal = laboratoryCostTotal
  6050. }
  6051. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  6052. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6053. treatCostSelfTotal = treatCostTotal
  6054. }
  6055. if item.MedChrgitmType == "06" { //手术费
  6056. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6057. operationCostSelfTotal = treatCostTotal
  6058. }
  6059. if item.MedChrgitmType == "08" { //材料费
  6060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6061. materialCostSelfTotal = materialCostTotal
  6062. }
  6063. if item.MedChrgitmType == "09" { //西药费
  6064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6065. westernMedicineCostSelfTotal = westernMedicineCostTotal
  6066. }
  6067. if item.MedChrgitmType == "11" { //中成费
  6068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6069. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  6070. }
  6071. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  6072. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6074. otherCostSelfTotal = otherCostTotal
  6075. }
  6076. } else {
  6077. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6078. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6079. otherCostSelfTotal = otherCostTotal
  6080. }
  6081. }
  6082. }
  6083. } else {
  6084. for _, item := range orderInfos {
  6085. if item.MedChrgitmType == "01" { //床位费
  6086. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6087. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6088. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6089. }
  6090. if item.MedChrgitmType == "02" { //诊察费
  6091. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6092. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6093. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6094. }
  6095. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  6096. if item.MedChrgitmType == "03" { //检查费
  6097. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6098. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6099. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6100. }
  6101. } else {
  6102. if item.MedChrgitmType == "03" { //检查费
  6103. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6104. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6105. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6106. }
  6107. }
  6108. if item.MedChrgitmType == "04" { //化验费
  6109. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6110. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6111. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6112. }
  6113. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6114. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6115. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6116. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6117. }
  6118. if item.MedChrgitmType == "06" { //手术费
  6119. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6120. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6121. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6122. }
  6123. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  6124. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6125. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6126. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6127. }
  6128. if item.MedChrgitmType == "09" { //西药费
  6129. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6130. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6131. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6132. }
  6133. if item.MedChrgitmType == "11" { //中成费
  6134. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6135. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6136. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6137. }
  6138. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6139. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6140. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6141. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6142. }
  6143. }
  6144. }
  6145. timeLayout := "2006-01-02"
  6146. loc, _ := time.LoadLocation("Local")
  6147. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  6148. if err != nil {
  6149. }
  6150. startRecordDateTime := startTime.Unix()
  6151. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  6152. if err != nil {
  6153. }
  6154. endRecordDateTime := endTime.Unix()
  6155. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  6156. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  6157. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  6158. c.ServeSuccessJSON(map[string]interface{}{
  6159. "order_number": order.Number, //业务流水号
  6160. "id_card_no": his.IdCardNo, //社会保障号
  6161. "department_name": department.Name, //科室
  6162. "number": his.Number, //门诊号
  6163. "date": order.SettleAccountsDate, //结算日期
  6164. "name": order.PsnName, //姓名
  6165. "gender": patient.Gender, //性别
  6166. "psn_cash_money": order.PsnCashPay, //个人支付
  6167. "pay_way": "门诊", //结算方式
  6168. "medfee_sumamt": order.MedfeeSumamt, //总费用
  6169. "admin_user_name": admin.UserName, //收款员
  6170. "order": order,
  6171. "order_info": orderInfos_two,
  6172. "his": his,
  6173. "bedCostTotal": bedCostTotal,
  6174. "bedCostSelfTotal": bedCostSelfTotal,
  6175. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  6176. "operationCostTotal": operationCostTotal,
  6177. "operationCostSelfTotal": operationCostSelfTotal,
  6178. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  6179. "otherCostTotal": otherCostTotal,
  6180. "otherCostSelfTotal": otherCostSelfTotal,
  6181. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  6182. "materialCostTotal": materialCostTotal,
  6183. "materialCostSelfTotal": materialCostSelfTotal,
  6184. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  6185. "westernMedicineCostTotal": westernMedicineCostTotal,
  6186. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  6187. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  6188. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6189. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  6190. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  6191. "checkCostTotal": checkCostTotal,
  6192. "checkCostSelfTotal": checkCostSelfTotal,
  6193. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  6194. "laboratoryCostTotal": laboratoryCostTotal,
  6195. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  6196. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  6197. "treatCostTotal": treatCostTotal,
  6198. "treatCostSelfTotal": treatCostSelfTotal,
  6199. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  6200. "zhenChaCostTotal": zhenChaCostTotal,
  6201. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  6202. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  6203. "his_hospital_record": his_hospital_record,
  6204. "pre_pay_money": pre_pay_money,
  6205. "refund_sum": sum,
  6206. })
  6207. }
  6208. func (this *HisApiController) GetIncomeStatisticsData() {
  6209. start_time := this.GetString("start_time")
  6210. end_time := this.GetString("end_time")
  6211. key_words := this.GetString("key_words")
  6212. limit, _ := this.GetInt64("limit")
  6213. page, _ := this.GetInt64("page")
  6214. if page <= 0 {
  6215. page = 1
  6216. }
  6217. if limit <= 0 {
  6218. limit = 10
  6219. }
  6220. statistics_type, _ := this.GetInt64("statistics_type")
  6221. admin := this.GetAdminUserInfo()
  6222. timeLayout := "2006-01-02"
  6223. loc, _ := time.LoadLocation("Local")
  6224. var theStartTIme int64
  6225. if len(start_time) > 0 {
  6226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6227. if err != nil {
  6228. theStartTIme = 0
  6229. }
  6230. theStartTIme = theTime.Unix()
  6231. }
  6232. var theEndtTIme int64
  6233. if len(end_time) > 0 {
  6234. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6235. if err != nil {
  6236. theEndtTIme = 0
  6237. }
  6238. theEndtTIme = theTime.Unix()
  6239. }
  6240. if statistics_type == 1 {
  6241. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  6242. this.ServeSuccessJSON(map[string]interface{}{
  6243. "list": list,
  6244. "total": total,
  6245. })
  6246. } else {
  6247. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  6248. this.ServeSuccessJSON(map[string]interface{}{
  6249. "list": list,
  6250. "total": total,
  6251. })
  6252. }
  6253. }
  6254. func (c *HisApiController) PostProjectInformation() {
  6255. adminUser := c.GetAdminUserInfo()
  6256. orgId := adminUser.CurrentOrgId
  6257. dataBody := make(map[string]interface{}, 0)
  6258. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6259. if err != nil {
  6260. utils.ErrorLog(err.Error())
  6261. return
  6262. }
  6263. utils.ErrorLog("%v", dataBody)
  6264. var projectList []*models.HisProject
  6265. var total_goods []interface{}
  6266. tempProjects := dataBody["projects"].([]interface{})
  6267. total_goods = tempProjects
  6268. for index, projectMap := range tempProjects {
  6269. projectM := projectMap.(map[string]interface{})
  6270. var project models.HisProject
  6271. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  6272. utils.ErrorLog("project_name")
  6273. return
  6274. }
  6275. project_name, _ := projectM["project_name"].(string)
  6276. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  6277. err_log := models.ExportErrLog{
  6278. LogType: 6,
  6279. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6280. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  6281. Status: 1,
  6282. CreateTime: time.Now().Unix(),
  6283. UpdateTime: time.Now().Unix(),
  6284. ExportTime: time.Now().Unix(),
  6285. }
  6286. service.CreateExportErrLog(&err_log)
  6287. continue
  6288. }
  6289. project.ProjectName = project_name
  6290. prices := projectM["price"].(string)
  6291. price, _ := strconv.ParseFloat(prices, 64)
  6292. if price <= 0 { //名字为空则生成一条导入错误日志
  6293. err_log := models.ExportErrLog{
  6294. LogType: 6,
  6295. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6296. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  6297. Status: 1,
  6298. CreateTime: time.Now().Unix(),
  6299. UpdateTime: time.Now().Unix(),
  6300. ExportTime: time.Now().Unix(),
  6301. }
  6302. service.CreateExportErrLog(&err_log)
  6303. continue
  6304. }
  6305. project.Price = price
  6306. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  6307. utils.ErrorLog("unit_id")
  6308. return
  6309. }
  6310. unit := projectM["unit"].(string)
  6311. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  6312. err_log := models.ExportErrLog{
  6313. LogType: 6,
  6314. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6315. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  6316. Status: 1,
  6317. CreateTime: time.Now().Unix(),
  6318. UpdateTime: time.Now().Unix(),
  6319. ExportTime: time.Now().Unix(),
  6320. }
  6321. service.CreateExportErrLog(&err_log)
  6322. continue
  6323. }
  6324. project.Unit = unit
  6325. cost_classify := projectM["cost_classify"].(string)
  6326. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  6327. err_log := models.ExportErrLog{
  6328. LogType: 6,
  6329. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6330. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  6331. Status: 1,
  6332. CreateTime: time.Now().Unix(),
  6333. UpdateTime: time.Now().Unix(),
  6334. ExportTime: time.Now().Unix(),
  6335. }
  6336. service.CreateExportErrLog(&err_log)
  6337. continue
  6338. }
  6339. var costClassify = "费用类别"
  6340. var cost_classify_id int64
  6341. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  6342. if len(cost_classify) != 0 {
  6343. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  6344. if errcode == gorm.ErrRecordNotFound {
  6345. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  6346. dataconfig := models.DictDataconfig{
  6347. ParentId: costClassifyConfig.ID,
  6348. Module: "system",
  6349. OrgId: orgId,
  6350. Name: cost_classify,
  6351. FieldName: "",
  6352. Value: costConfig.Value + 1,
  6353. CreatedTime: "",
  6354. UpdatedTime: "",
  6355. CreateUserId: adminUser.AdminUser.Id,
  6356. Status: 1,
  6357. Remark: "",
  6358. DeleteIdSystem: 0,
  6359. Title: "",
  6360. Content: "",
  6361. Order: 0,
  6362. Code: "",
  6363. }
  6364. service.CreatedDicConfig(&dataconfig)
  6365. }
  6366. }
  6367. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  6368. for _, it := range costClassList {
  6369. if cost_classify == it.Name {
  6370. cost_classify_id = int64(it.Value)
  6371. }
  6372. }
  6373. project.CostClassify = cost_classify_id
  6374. executive_section := projectM["executive_section"].(string)
  6375. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  6376. err_log := models.ExportErrLog{
  6377. LogType: 6,
  6378. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6379. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  6380. Status: 1,
  6381. CreateTime: time.Now().Unix(),
  6382. UpdateTime: time.Now().Unix(),
  6383. ExportTime: time.Now().Unix(),
  6384. }
  6385. service.CreateExportErrLog(&err_log)
  6386. continue
  6387. }
  6388. if len(executive_section) != 0 {
  6389. //查找科室是否有内容
  6390. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  6391. if errcodedepart == gorm.ErrRecordNotFound {
  6392. department := models.XtHisDepartment{
  6393. Name: executive_section,
  6394. Status: 1,
  6395. UserOrgId: adminUser.CurrentOrgId,
  6396. CreatedTime: time.Now().Unix(),
  6397. }
  6398. service.CreateDePartment(&department)
  6399. }
  6400. }
  6401. var executive_section_id int64
  6402. departMentList, _ := service.GetAllDepartMent(orgId)
  6403. for _, it := range departMentList {
  6404. if executive_section == it.Name {
  6405. executive_section_id = it.ID
  6406. }
  6407. }
  6408. project.ExecutiveSection = executive_section_id
  6409. medical_coverage := projectM["medical_coverage"].(string)
  6410. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  6411. err_log := models.ExportErrLog{
  6412. LogType: 6,
  6413. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6414. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  6415. Status: 1,
  6416. CreateTime: time.Now().Unix(),
  6417. UpdateTime: time.Now().Unix(),
  6418. ExportTime: time.Now().Unix(),
  6419. }
  6420. service.CreateExportErrLog(&err_log)
  6421. continue
  6422. }
  6423. var medicalCoverage = "医保等级"
  6424. var medical_coverage_id int64
  6425. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  6426. if len(medical_coverage) != 0 {
  6427. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  6428. if errormedicalcoverage == gorm.ErrRecordNotFound {
  6429. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  6430. dataconfig := models.DictDataconfig{
  6431. ParentId: medicalCoverageConfig.ID,
  6432. Module: "system",
  6433. OrgId: orgId,
  6434. Name: medical_coverage,
  6435. FieldName: "",
  6436. Value: medicalCoverageConfig.Value + 1,
  6437. CreatedTime: "",
  6438. UpdatedTime: "",
  6439. CreateUserId: adminUser.AdminUser.Id,
  6440. Status: 1,
  6441. Remark: "",
  6442. DeleteIdSystem: 0,
  6443. Title: "",
  6444. Content: "",
  6445. Order: 0,
  6446. Code: "",
  6447. }
  6448. service.CreatedDicConfig(&dataconfig)
  6449. }
  6450. }
  6451. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  6452. for _, it := range medicalCoverageList {
  6453. if medical_coverage == it.Name {
  6454. medical_coverage_id = int64(it.Value)
  6455. }
  6456. }
  6457. project.MedicalCoverage = medical_coverage_id
  6458. pinyin := projectM["pinyin"].(string)
  6459. project.Pinyin = pinyin
  6460. wubi := projectM["wubi"].(string)
  6461. project.Wubi = wubi
  6462. statistical_classification := projectM["statistical_classification"].(string)
  6463. var statisticalClassification = "统计分类"
  6464. var statistical_classification_id int64
  6465. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  6466. if len(statistical_classification) != 0 {
  6467. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  6468. if classificationerrcodes == gorm.ErrRecordNotFound {
  6469. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  6470. dataconfig := models.DictDataconfig{
  6471. ParentId: classiFication.ID,
  6472. Module: "system",
  6473. OrgId: orgId,
  6474. Name: statistical_classification,
  6475. FieldName: "",
  6476. Value: classiFicationConfig.Value + 1,
  6477. CreatedTime: "",
  6478. UpdatedTime: "",
  6479. CreateUserId: adminUser.AdminUser.Id,
  6480. Status: 1,
  6481. Remark: "",
  6482. DeleteIdSystem: 0,
  6483. Title: "",
  6484. Content: "",
  6485. Order: 0,
  6486. Code: "",
  6487. }
  6488. service.CreatedDicConfig(&dataconfig)
  6489. }
  6490. }
  6491. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  6492. for _, it := range classiFicationList {
  6493. if statistical_classification == it.Name {
  6494. statistical_classification_id = int64(it.Value)
  6495. }
  6496. }
  6497. project.StatisticalClassification = statistical_classification_id
  6498. disease_directory := int64(projectM["disease_directory"].(float64))
  6499. project.DiseaseDirectory = disease_directory
  6500. is_record := int64(projectM["is_record"].(float64))
  6501. project.IsRecord = is_record
  6502. medical_code := projectM["medical_code"].(string)
  6503. project.MedicalCode = medical_code
  6504. tube_color := projectM["tube_color"].(string)
  6505. var tubeColor = "试管颜色"
  6506. var tube_color_id int64
  6507. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  6508. if len(tube_color) != 0 {
  6509. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  6510. if errcodetube == gorm.ErrRecordNotFound {
  6511. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  6512. dataconfig := models.DictDataconfig{
  6513. ParentId: tubeColorConfig.ID,
  6514. Module: "system",
  6515. OrgId: orgId,
  6516. Name: tube_color,
  6517. FieldName: "",
  6518. Value: tubeConfig.Value + 1,
  6519. CreatedTime: "",
  6520. UpdatedTime: "",
  6521. CreateUserId: adminUser.AdminUser.Id,
  6522. Status: 1,
  6523. Remark: "",
  6524. DeleteIdSystem: 0,
  6525. Title: "",
  6526. Content: "",
  6527. Order: 0,
  6528. Code: "",
  6529. }
  6530. service.CreatedDicConfig(&dataconfig)
  6531. }
  6532. }
  6533. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  6534. for _, it := range tubeColorList {
  6535. if tube_color == it.Name {
  6536. tube_color_id = int64(it.Value)
  6537. }
  6538. }
  6539. project.TubeColor = tube_color_id
  6540. single_dose := projectM["single_dose"].(string)
  6541. project.SingleDose = single_dose
  6542. execution_frequency := projectM["execution_frequency"].(string)
  6543. project.ExecutionFrequency = execution_frequency
  6544. delivery_way := projectM["delivery_way"].(string)
  6545. project.DeliveryWay = delivery_way
  6546. number_days := projectM["number_days"].(string)
  6547. project.NumberDays = number_days
  6548. total := projectM["total"].(string)
  6549. project.Total = total
  6550. medical_status := int64(projectM["medical_status"].(float64))
  6551. project.MedicalStatus = medical_status
  6552. category := int64(projectM["category"].(float64))
  6553. project.Category = category
  6554. specail_project := int64(projectM["specail_project"].(float64))
  6555. project.SpecailProject = specail_project
  6556. social_security_directory_code := projectM["social_security_directory_code"].(string)
  6557. project.SocialSecurityDirectoryCode = social_security_directory_code
  6558. remark := projectM["remark"].(string)
  6559. project.Remark = remark
  6560. record_date := projectM["record_date"].(string)
  6561. timeLayout := "2006-01-02"
  6562. loc, _ := time.LoadLocation("Local")
  6563. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6564. project.RecordDate = theTime.Unix()
  6565. projectList = append(projectList, &project)
  6566. }
  6567. export_time := time.Now().Unix()
  6568. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  6569. if len(projectList) > 0 {
  6570. for _, item := range projectList {
  6571. project := models.HisProject{
  6572. ProjectName: item.ProjectName,
  6573. Price: item.Price,
  6574. Unit: item.Unit,
  6575. CostClassify: item.CostClassify,
  6576. ExecutiveSection: item.ExecutiveSection,
  6577. MedicalCoverage: item.MedicalCoverage,
  6578. UserOrgId: orgId,
  6579. Status: 1,
  6580. CreatedTime: time.Now().Unix(),
  6581. Pinyin: item.Pinyin,
  6582. Wubi: item.Wubi,
  6583. StatisticalClassification: item.StatisticalClassification,
  6584. DiseaseDirectory: item.DiseaseDirectory,
  6585. IsRecord: item.IsRecord,
  6586. MedicalCode: item.MedicalCode,
  6587. TubeColor: item.TubeColor,
  6588. SingleDose: item.SingleDose,
  6589. DeliveryWay: item.DeliveryWay,
  6590. NumberDays: item.NumberDays,
  6591. Total: item.Total,
  6592. Category: item.Category,
  6593. MedicalStatus: item.MedicalStatus,
  6594. SpecailProject: item.SpecailProject,
  6595. RecordDate: item.RecordDate,
  6596. Remark: item.Remark,
  6597. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  6598. ExecutionFrequency: item.ExecutionFrequency,
  6599. }
  6600. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  6601. if errcodeproject == gorm.ErrRecordNotFound {
  6602. service.CreateProjectInfomation(&project)
  6603. } else if errcodeproject == nil {
  6604. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  6605. }
  6606. log := models.ExportLog{
  6607. LogType: 6,
  6608. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6609. TotalNum: int64(len(total_goods)),
  6610. FailNum: int64(len(errLogs)),
  6611. SuccessNum: int64(len(projectList)),
  6612. CreateTime: time.Now().Unix(),
  6613. UpdateTime: time.Now().Unix(),
  6614. ExportTime: export_time,
  6615. Status: 1,
  6616. }
  6617. service.CreateExportLog(&log)
  6618. c.ServeSuccessJSON(map[string]interface{}{
  6619. "msg": "导入成功",
  6620. "total_num": len(total_goods),
  6621. "success_num": len(projectList),
  6622. "fail_num": int64(len(errLogs)),
  6623. })
  6624. }
  6625. } else {
  6626. log := models.ExportLog{
  6627. LogType: 6,
  6628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6629. TotalNum: int64(len(total_goods)),
  6630. FailNum: int64(len(errLogs)),
  6631. SuccessNum: int64(len(projectList)),
  6632. CreateTime: time.Now().Unix(),
  6633. UpdateTime: time.Now().Unix(),
  6634. ExportTime: export_time,
  6635. Status: 1,
  6636. }
  6637. service.CreateExportLog(&log)
  6638. c.ServeSuccessJSON(map[string]interface{}{
  6639. "msg": "导入成功",
  6640. "total_num": len(total_goods),
  6641. "success_num": len(projectList),
  6642. "fail_num": int64(len(errLogs)),
  6643. })
  6644. }
  6645. }
  6646. //func (this *HisApiController) EditProjectInformation(){
  6647. //
  6648. // id, _ := this.GetInt64("id")
  6649. // project_team := this.GetString("project_team")
  6650. // price := this.GetString("price")
  6651. // price_float, _ := strconv.ParseFloat(price, 64)
  6652. // pinyin := this.GetString("pinyin")
  6653. // wubi := this.GetString("wubi")
  6654. // tube_color, _ := this.GetInt64("tube_color")
  6655. // team_type, _ := this.GetInt64("team_type")
  6656. // remark := this.GetString("remark")
  6657. // ids := this.GetString("ids")
  6658. // item_id := this.GetString("item_id")
  6659. // projectTeam := models.XtHisProjectTeam{
  6660. // ProjectTeam: project_team,
  6661. // Price: price_float,
  6662. // Pinyin: pinyin,
  6663. // Wubi: wubi,
  6664. // TubeColor: tube_color,
  6665. // TeamType: team_type,
  6666. // Remark: remark,
  6667. // ProjectId: ids,
  6668. // ItemId: item_id,
  6669. // }
  6670. //
  6671. //
  6672. // dataBody := make(map[string]interface{}, 0)
  6673. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6674. // if err != nil {
  6675. // utils.ErrorLog(err.Error())
  6676. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6677. // return
  6678. // }
  6679. //
  6680. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6681. //
  6682. //
  6683. // if err != nil {
  6684. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6685. // return
  6686. // }
  6687. //
  6688. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6689. // infos, _ := dataBody["info"].([]interface{})
  6690. // if len(infos) > 0 {
  6691. // var ids []string
  6692. //
  6693. // for _, item := range infos {
  6694. // items := item.(map[string]interface{})
  6695. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6696. // utils.ErrorLog("id")
  6697. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6698. // return
  6699. // }
  6700. // id := int64(items["id"].(float64))
  6701. //
  6702. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6703. // utils.ErrorLog("type")
  6704. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6705. // return
  6706. // }
  6707. // types := int64(items["type"].(float64))
  6708. //
  6709. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6710. // utils.ErrorLog("number")
  6711. // }
  6712. //
  6713. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6714. //
  6715. // projectList := models.XtHisProjectList{
  6716. // Number: number,
  6717. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6718. // ProjectId: id,
  6719. // Status: 1,
  6720. // CreatedTime: time.Now().Unix(),
  6721. // UpdatedTime: time.Now().Unix(),
  6722. // TeamId: projectTeam.ID,
  6723. // Type: types,
  6724. // }
  6725. // list := projectList
  6726. //
  6727. // service.CreateProjectList(&list)
  6728. //
  6729. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6730. //
  6731. // }
  6732. // ids_str := strings.Join(ids, ",")
  6733. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6734. // service.SaveProjectTeam(&projectTeam)
  6735. // this.ServeSuccessJSON(map[string]interface{}{
  6736. // "projectTeam": projectTeam,
  6737. // })
  6738. // }
  6739. // }
  6740. //}
  6741. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6742. name := c.GetString("name")
  6743. mode_id, _ := c.GetInt64("mode", 0)
  6744. types, _ := c.GetInt64("type", 0)
  6745. patient_id, _ := c.GetInt64("patient_id", 0)
  6746. types = 1
  6747. adminInfo := c.GetAdminUserInfo()
  6748. template := &models.HisPrescriptionTemplate{
  6749. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6750. PatientId: patient_id,
  6751. Type: types,
  6752. Status: 1,
  6753. Ctime: time.Now().Unix(),
  6754. Mtime: time.Now().Unix(),
  6755. Name: name,
  6756. Mode: mode_id,
  6757. }
  6758. dataBody := make(map[string]interface{}, 0)
  6759. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6760. if err != nil {
  6761. utils.ErrorLog(err.Error())
  6762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6763. return
  6764. }
  6765. err = service.CreateHisPrescriptionTemplate(template)
  6766. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6767. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6768. if len(prescriptions) > 0 {
  6769. for _, item := range prescriptions {
  6770. items := item.(map[string]interface{})
  6771. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6772. utils.ErrorLog("type")
  6773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6774. return
  6775. }
  6776. types := int64(items["type"].(float64))
  6777. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6778. utils.ErrorLog("med_type")
  6779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6780. return
  6781. }
  6782. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6783. ctime := time.Now().Unix()
  6784. prescription := &models.HisPrescriptionInfoTemplate{
  6785. PatientId: patient_id,
  6786. UserOrgId: adminInfo.CurrentOrgId,
  6787. Ctime: ctime,
  6788. Mtime: ctime,
  6789. Type: types,
  6790. Modifier: adminInfo.AdminUser.Id,
  6791. Creator: adminInfo.AdminUser.Id,
  6792. Status: 1,
  6793. PTemplateId: template.ID,
  6794. MedType: med_type,
  6795. }
  6796. service.CreateHisPrescriptionInfoTemplate(prescription)
  6797. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6798. advices := items["advices"].([]interface{})
  6799. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6800. ctime := time.Now().Unix()
  6801. mtime := ctime
  6802. if len(advices) > 0 {
  6803. for _, advice := range advices {
  6804. var s models.HisPrescriptionAdviceTemplate
  6805. s.PrescriptionId = prescription.ID
  6806. s.AdviceType = 2
  6807. s.StopState = 2
  6808. s.ExecutionState = 2
  6809. s.Status = 1
  6810. s.UserOrgId = adminInfo.CurrentOrgId
  6811. s.CreatedTime = ctime
  6812. s.UpdatedTime = mtime
  6813. s.PatientId = patient_id
  6814. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6815. if errcode > 0 {
  6816. c.ServeFailJSONWithSGJErrorCode(errcode)
  6817. return
  6818. }
  6819. service.CreateHisPrescriptionAdviceTemplate(&s)
  6820. }
  6821. }
  6822. }
  6823. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6824. projects := items["project"].([]interface{})
  6825. if len(projects) > 0 {
  6826. for _, project := range projects {
  6827. var p models.HisPrescriptionProjectTemplate
  6828. p.PrescriptionId = prescription.ID
  6829. p.Ctime = time.Now().Unix()
  6830. p.Mtime = time.Now().Unix()
  6831. p.PatientId = patient_id
  6832. p.UserOrgId = adminInfo.CurrentOrgId
  6833. p.Status = 1
  6834. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6835. if errcode > 0 {
  6836. c.ServeFailJSONWithSGJErrorCode(errcode)
  6837. return
  6838. }
  6839. service.CreateHisPrescriptionProjectTemplate(&p)
  6840. }
  6841. }
  6842. }
  6843. }
  6844. c.ServeSuccessJSON(map[string]interface{}{
  6845. "msg": "创建成功",
  6846. })
  6847. }
  6848. }
  6849. }
  6850. func (c *HisApiController) PreSettle() {
  6851. id, _ := c.GetInt64("id")
  6852. record_time := c.GetString("record_time")
  6853. his_patient_id, _ := c.GetInt64("his_patient_id")
  6854. timeLayout := "2006-01-02"
  6855. loc, _ := time.LoadLocation("Local")
  6856. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6857. diagnosis_id := c.GetString("diagnosis")
  6858. sick_type, _ := c.GetInt64("sick_type")
  6859. reg_type, _ := c.GetInt64("p_type")
  6860. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6862. if err != nil {
  6863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6864. return
  6865. }
  6866. recordDateTime := theTime.Unix()
  6867. adminUser := c.GetAdminUserInfo()
  6868. var prescriptions []*models.HisPrescription
  6869. var start_time int64
  6870. var end_time int64
  6871. ids_str := c.GetString("ids")
  6872. ids_arr := strings.Split(ids_str, ",")
  6873. fmt.Println(reg_type)
  6874. if settle_accounts_type == 1 { //日结
  6875. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6876. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6877. } else {
  6878. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6879. }
  6880. fmt.Println(prescriptions)
  6881. } else { //月结
  6882. start_time_str := c.GetString("start_time")
  6883. end_time_str := c.GetString("end_time")
  6884. timeLayout := "2006-01-02"
  6885. loc, _ := time.LoadLocation("Local")
  6886. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6887. if err != nil {
  6888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6889. return
  6890. }
  6891. recordStartTime := theStartTime.Unix()
  6892. start_time = recordStartTime
  6893. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6894. if err != nil {
  6895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6896. return
  6897. }
  6898. recordEndTime := theEndTime.Unix()
  6899. end_time = recordEndTime
  6900. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6901. }
  6902. if reg_type == 1111 || reg_type == 1112 {
  6903. reg_type = 11
  6904. }
  6905. timestamp := time.Now().Unix()
  6906. tempTime := time.Unix(timestamp, 0)
  6907. timeFormat := tempTime.Format("20060102150405")
  6908. chrgBchno := rand.Intn(100000) + 10000
  6909. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6910. strconv.FormatInt(his.PatientId, 10)
  6911. var ids []int64
  6912. for _, item := range prescriptions {
  6913. ids = append(ids, item.ID)
  6914. }
  6915. fmt.Println(ids)
  6916. var total float64
  6917. for _, item := range prescriptions {
  6918. fmt.Println(item)
  6919. if item.Type == 1 { //药品
  6920. for _, subItem := range item.HisDoctorAdviceInfo {
  6921. total = total + (subItem.Price * subItem.PrescribingNumber)
  6922. }
  6923. }
  6924. if item.Type == 2 { //项目
  6925. for _, subItem := range item.HisPrescriptionProject {
  6926. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6927. total = total + (subItem.Price * cnt)
  6928. }
  6929. }
  6930. for _, subItem := range item.HisAdditionalCharge {
  6931. total = total + (subItem.Price * float64(subItem.Count))
  6932. }
  6933. }
  6934. allTotal := fmt.Sprintf("%.2f", total)
  6935. totals, _ := strconv.ParseFloat(allTotal, 64)
  6936. order := &models.HisOrder{
  6937. UserOrgId: adminUser.CurrentOrgId,
  6938. HisPatientId: his.ID,
  6939. PatientId: id,
  6940. SettleAccountsDate: recordDateTime,
  6941. Ctime: time.Now().Unix(),
  6942. Mtime: time.Now().Unix(),
  6943. Status: 1,
  6944. OrderStatus: 1,
  6945. MdtrtId: his.Number,
  6946. Number: chrg_bchno,
  6947. MedfeeSumamt: totals,
  6948. SettleEndTime: end_time,
  6949. SettleStartTime: start_time,
  6950. SettleType: settle_accounts_type,
  6951. PsnPartAmt: totals,
  6952. PsnCashPay: totals,
  6953. PType: 2,
  6954. IsPre: 1,
  6955. MedType: strconv.Itoa(int(reg_type)),
  6956. Diagnosis: diagnosis_id,
  6957. }
  6958. err = service.CreateOrder(order)
  6959. if err != nil {
  6960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6961. return
  6962. }
  6963. var customs []*Custom
  6964. for _, item := range prescriptions {
  6965. fmt.Println(item.Type)
  6966. if item.Type == 1 { //药品
  6967. for _, subItem := range item.HisDoctorAdviceInfo {
  6968. cus := &Custom{
  6969. AdviceId: subItem.ID,
  6970. ProjectId: 0,
  6971. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6972. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6973. FeedetlSn: subItem.FeedetlSn,
  6974. Price: fmt.Sprintf("%.2f", subItem.Price),
  6975. MedListCodg: subItem.MedListCodg,
  6976. Type: 1,
  6977. }
  6978. customs = append(customs, cus)
  6979. }
  6980. }
  6981. if item.Type == 2 { //项目
  6982. for _, subItem := range item.HisPrescriptionProject {
  6983. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6984. cus := &Custom{
  6985. AdviceId: 0,
  6986. ProjectId: subItem.ID,
  6987. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6988. Cut: fmt.Sprintf("%.2f", cnt),
  6989. FeedetlSn: subItem.FeedetlSn,
  6990. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6991. MedListCodg: subItem.MedListCodg,
  6992. Type: 2,
  6993. }
  6994. customs = append(customs, cus)
  6995. }
  6996. }
  6997. for _, item := range item.HisAdditionalCharge {
  6998. cus := &Custom{
  6999. ItemId: item.ID,
  7000. AdviceId: 0,
  7001. ProjectId: 0,
  7002. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  7003. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  7004. FeedetlSn: item.FeedetlSn,
  7005. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  7006. MedListCodg: item.XtHisAddtionConfig.Code,
  7007. Type: 3,
  7008. }
  7009. customs = append(customs, cus)
  7010. }
  7011. }
  7012. fmt.Println(customs)
  7013. for _, item := range customs {
  7014. var advice_id int64 = 0
  7015. var project_id int64 = 0
  7016. var item_id int64 = 0
  7017. var types int64 = 0
  7018. if item.Type == 1 {
  7019. advice_id = item.AdviceId
  7020. project_id = 0
  7021. item_id = 0
  7022. } else if item.Type == 2 {
  7023. advice_id = 0
  7024. item_id = 0
  7025. project_id = item.ProjectId
  7026. } else if item.Type == 3 {
  7027. advice_id = 0
  7028. item_id = item.ItemId
  7029. project_id = 0
  7030. }
  7031. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7032. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7033. pric, _ := strconv.ParseFloat(item.Price, 32)
  7034. info := &models.HisOrderInfo{
  7035. OrderNumber: order.Number,
  7036. UploadDate: time.Now().Unix(),
  7037. AdviceId: advice_id,
  7038. DetItemFeeSumamt: detItemFeeSumamt,
  7039. Cnt: cut,
  7040. Pric: pric,
  7041. PatientId: id,
  7042. Status: 1,
  7043. Mtime: time.Now().Unix(),
  7044. Ctime: time.Now().Unix(),
  7045. UserOrgId: adminUser.CurrentOrgId,
  7046. HisPatientId: his.ID,
  7047. OrderId: order.ID,
  7048. ProjectId: project_id,
  7049. Type: types,
  7050. ItemId: item_id,
  7051. }
  7052. service.CreateOrderInfo(info)
  7053. }
  7054. his.SickType = sick_type
  7055. service.UpdataHisPateint(&his)
  7056. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  7057. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  7058. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  7059. if err == nil {
  7060. c.ServeSuccessJSON(map[string]interface{}{
  7061. "msg": "结算成功",
  7062. })
  7063. }
  7064. }
  7065. type CustomOrderInfo struct {
  7066. Name string
  7067. Spec string
  7068. Unit string
  7069. Count float64
  7070. Price float64
  7071. Total float64
  7072. }
  7073. func (c *HisApiController) GetPrivateExpensesInfo() {
  7074. order_id, _ := c.GetInt64("id", 0)
  7075. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  7076. order, _ := service.GetHisOrderByID(order_id)
  7077. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  7078. if order.ID == 0 {
  7079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7080. return
  7081. }
  7082. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  7083. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  7084. org_id := c.GetAdminUserInfo().CurrentOrgId
  7085. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7086. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7087. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  7088. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  7089. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  7090. var orderInfos_four []*models.HisOrderInfoTwo
  7091. for _, item := range orderInfos_three {
  7092. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  7093. item.HisPrescriptionProject.IsCheckTeam = 1
  7094. orderInfos_four = append(orderInfos_four, item)
  7095. }
  7096. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  7097. item.HisPrescriptionProject.IsCheckTeam = 2
  7098. orderInfos_two = append(orderInfos_two, item)
  7099. }
  7100. }
  7101. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  7102. var cus_slice []CustomOrderInfo
  7103. for _, item := range new_order_info {
  7104. var cus CustomOrderInfo
  7105. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  7106. cus.Unit = ""
  7107. cus.Spec = ""
  7108. var total float64
  7109. for _, subItem := range orderInfos_four {
  7110. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  7111. total = total + subItem.DetItemFeeSumamt
  7112. fmt.Println(subItem.DetItemFeeSumamt)
  7113. }
  7114. }
  7115. cus.Count = 1
  7116. cus.Total = total
  7117. cus_slice = append(cus_slice, cus)
  7118. }
  7119. orderInfos = append(orderInfos, orderInfos_two...)
  7120. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  7121. orderInfos = append(orderInfos, orderInfos_three...)
  7122. }
  7123. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  7124. c.ServeSuccessJSON(map[string]interface{}{
  7125. "order": order,
  7126. "order_info": orderInfos,
  7127. "patient": patient,
  7128. "admin_info": adminInfo,
  7129. "his": his,
  7130. "current_admin": role,
  7131. "org_config": miConfig,
  7132. "new_order_info": cus_slice,
  7133. })
  7134. }
  7135. func (this *HisApiController) ChangeMedType() {
  7136. med_type := this.GetString("med_type")
  7137. old_med_type := this.GetString("old_med_type")
  7138. ids := this.GetString("ids")
  7139. settle_type, _ := this.GetInt64("settle_type")
  7140. start_time := this.GetString("start_time")
  7141. end_time := this.GetString("end_time")
  7142. ids_arr := strings.Split(ids, ",")
  7143. if settle_type == 1 { //日结
  7144. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  7145. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  7146. prescription.MedType = med_type
  7147. err := service.SaveHisPrescription(&prescription)
  7148. if err == nil {
  7149. this.ServeSuccessJSON(map[string]interface{}{
  7150. "msg": "修改成功",
  7151. })
  7152. } else {
  7153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7154. return
  7155. }
  7156. } else if settle_type == 2 {
  7157. timeLayout := "2006-01-02"
  7158. loc, _ := time.LoadLocation("Local")
  7159. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7160. if err != nil {
  7161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7162. return
  7163. }
  7164. recordStartTime := theStartTime.Unix()
  7165. start_time_timestamp := recordStartTime
  7166. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7167. if err != nil {
  7168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7169. return
  7170. }
  7171. recordEndTime := theEndTime.Unix()
  7172. end_time_timestamp := recordEndTime
  7173. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  7174. if updateErr == nil {
  7175. this.ServeSuccessJSON(map[string]interface{}{
  7176. "msg": "修改成功",
  7177. })
  7178. } else {
  7179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7180. return
  7181. }
  7182. }
  7183. }
  7184. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  7185. patient_id, _ := c.GetInt64("patient_id")
  7186. his_patient_id, _ := c.GetInt64("his_patient_id")
  7187. record_date := c.GetString("record_date")
  7188. start_time := c.GetString("start_time")
  7189. end_time := c.GetString("end_time")
  7190. order_status, _ := c.GetInt64("type", 0)
  7191. p_type, _ := c.GetInt64("p_type", 0)
  7192. order_id, _ := c.GetInt64("order_id", 0)
  7193. timeLayout := "2006-01-02"
  7194. loc, _ := time.LoadLocation("Local")
  7195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7196. if err != nil {
  7197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7198. return
  7199. }
  7200. recordDateTime := theTime.Unix()
  7201. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7202. if err != nil {
  7203. }
  7204. startRecordDateTime := startTime.Unix()
  7205. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7206. if err != nil {
  7207. }
  7208. endRecordDateTime := endTime.Unix()
  7209. admin := c.GetAdminUserInfo()
  7210. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7211. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7212. order, _ := service.GetHisOrderByID(order_id)
  7213. var monthPrescriptions []*models.HisPrescription
  7214. if order_status == 1 || order_status == 0 {
  7215. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7216. } else if order_status == 2 {
  7217. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7218. }
  7219. var settle_total float64
  7220. for _, item := range monthPrescriptions {
  7221. if len(item.HisPrescriptionProject) > 0 {
  7222. for _, subItem := range item.HisPrescriptionProject {
  7223. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7224. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7225. settle_total = settle_total + total
  7226. }
  7227. }
  7228. if len(item.HisDoctorAdviceInfo) > 0 {
  7229. for _, subItem := range item.HisDoctorAdviceInfo {
  7230. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7231. settle_total = settle_total + total
  7232. }
  7233. }
  7234. }
  7235. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7236. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7237. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7238. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7239. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7240. //获取所有科室信息
  7241. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7242. c.ServeSuccessJSON(map[string]interface{}{
  7243. "his_info": his_patient_info,
  7244. "xt_info": xt_patient_info,
  7245. "case_history": case_history,
  7246. "info": patientPrescriptionInfo,
  7247. "last_info": lastPatientPrescriptionInfo,
  7248. "month_prescriptions": monthPrescriptions,
  7249. "order": order,
  7250. "doctors": doctors,
  7251. "department": department,
  7252. "settle_total": settle_total,
  7253. })
  7254. return
  7255. }
  7256. func (c *HisApiController) GetHisMonthPatientInfo() {
  7257. patient_id, _ := c.GetInt64("patient_id")
  7258. his_patient_id, _ := c.GetInt64("his_patient_id")
  7259. record_date := c.GetString("record_date")
  7260. number := c.GetString("number")
  7261. start_time := c.GetString("start_time")
  7262. end_time := c.GetString("end_time")
  7263. p_type, _ := c.GetInt64("p_type")
  7264. timeLayout := "2006-01-02"
  7265. loc, _ := time.LoadLocation("Local")
  7266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7267. if err != nil {
  7268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7269. return
  7270. }
  7271. recordDateTime := theTime.Unix()
  7272. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7273. if err != nil {
  7274. }
  7275. startRecordDateTime := startTime.Unix()
  7276. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7277. if err != nil {
  7278. }
  7279. endRecordDateTime := endTime.Unix()
  7280. admin := c.GetAdminUserInfo()
  7281. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  7282. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7283. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  7284. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7285. var settle_total float64
  7286. for _, item := range monthPrescriptions {
  7287. if len(item.HisPrescriptionProject) > 0 {
  7288. for _, subItem := range item.HisPrescriptionProject {
  7289. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7290. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7291. settle_total = settle_total + total
  7292. }
  7293. }
  7294. if len(item.HisDoctorAdviceInfo) > 0 {
  7295. for _, subItem := range item.HisDoctorAdviceInfo {
  7296. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7297. settle_total = settle_total + total
  7298. }
  7299. }
  7300. }
  7301. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7302. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7303. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7304. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7305. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  7306. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7307. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  7308. //获取所有科室信息
  7309. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7310. c.ServeSuccessJSON(map[string]interface{}{
  7311. "his_info": his_patient_info,
  7312. "xt_info": xt_patient_info,
  7313. "case_history": case_history,
  7314. "info": patientPrescriptionInfo,
  7315. "month_prescriptions": monthPrescriptions,
  7316. "order": order,
  7317. "doctors": doctors,
  7318. "department": department,
  7319. "count": count,
  7320. "drugStockConfig": drugStockConfig,
  7321. "last_info": lastPatientPrescriptionInfo,
  7322. "settle_total": settle_total,
  7323. })
  7324. return
  7325. }
  7326. func (c *HisApiController) GetAllOrder() {
  7327. org_id := c.GetAdminUserInfo().CurrentOrgId
  7328. orders, _ := service.GetNewHisOrderList(org_id)
  7329. c.ServeSuccessJSON(map[string]interface{}{
  7330. "order": orders,
  7331. })
  7332. return
  7333. }
  7334. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  7335. newArr = make([]*models.HisOrderInfoTwo, 0)
  7336. for i := 0; i < len(arr); i++ {
  7337. repeat := false
  7338. for j := i + 1; j < len(arr); j++ {
  7339. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  7340. repeat = true
  7341. break
  7342. }
  7343. }
  7344. if !repeat {
  7345. newArr = append(newArr, arr[i])
  7346. }
  7347. }
  7348. return
  7349. }
  7350. //修改处方退库操作 参数传修改之前的处方数据
  7351. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  7352. if advice.ExecutionState == 1 {
  7353. //查询该病人该药品是否有库存记录
  7354. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  7355. if errcode == gorm.ErrRecordNotFound {
  7356. } else {
  7357. //退库
  7358. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7359. if advice.PrescribingNumberUnit == drug.MinUnit {
  7360. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  7361. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7362. //退库
  7363. warehouseInfo := models.DrugWarehouseInfo{
  7364. StockMinNumber: prescribingNumber,
  7365. }
  7366. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  7367. operation_time := time.Now().Unix()
  7368. creater := advice.AdviceDoctor
  7369. ctime := time.Now().Unix()
  7370. timeStr := time.Now().Format("2006-01-02")
  7371. timeArr := strings.Split(timeStr, "-")
  7372. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  7373. total = total + 1
  7374. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7375. cancelStock := models.DrugCancelStock{
  7376. OrderNumber: orderNumber,
  7377. OperaTime: operation_time,
  7378. OrgId: advice.UserOrgId,
  7379. Creater: creater,
  7380. Ctime: ctime,
  7381. Status: 1,
  7382. ReturnTime: advice.AdviceDate,
  7383. Dealer: info.Dealer,
  7384. Manufacturer: info.Manufacturer,
  7385. Type: 1,
  7386. }
  7387. service.AddSigleDrugCancelStock(&cancelStock)
  7388. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  7389. dealer, _ := service.GetDealerById(info.Dealer)
  7390. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  7391. cancelStockInfo := models.DrugCancelStockInfo{
  7392. OrderNumber: cancelInfo.OrderNumber,
  7393. CancelStockId: cancelInfo.ID,
  7394. DrugId: info.DrugId,
  7395. Count: info.Count,
  7396. Status: 1,
  7397. Ctime: ctime,
  7398. OrgId: advice.UserOrgId,
  7399. Type: 1,
  7400. Manufacturer: manufactureName.ManufacturerName,
  7401. Dealer: dealer.DealerName,
  7402. Total: 0,
  7403. RetailPrice: info.RetailPrice,
  7404. RetailTotalPrice: info.RetailTotalPrice,
  7405. Price: info.Price,
  7406. RegisterAccount: "",
  7407. Remark: info.Remark,
  7408. BatchNumber: info.BatchNumber,
  7409. MaxUnit: info.CountUnit,
  7410. ProductDate: info.ProductDate,
  7411. ExpiryDate: info.ExpiryDate,
  7412. BatchNumberId: info.WarehouseInfoId,
  7413. }
  7414. flow := models.DrugFlow{
  7415. WarehousingId: 0,
  7416. DrugId: info.DrugId,
  7417. Number: "",
  7418. BatchNumber: info.BatchNumber,
  7419. Count: info.Count,
  7420. UserOrgId: advice.UserOrgId,
  7421. PatientId: 0,
  7422. SystemTime: ctime,
  7423. ConsumableType: 4,
  7424. IsSys: 0,
  7425. WarehousingOrder: "",
  7426. WarehouseOutId: 0,
  7427. WarehouseOutOrderNumber: "",
  7428. IsEdit: 0,
  7429. CancelStockId: cancelStock.ID,
  7430. CancelOrderNumber: cancelStock.OrderNumber,
  7431. Manufacturer: info.Manufacturer,
  7432. Dealer: info.Dealer,
  7433. Creator: advice.UserOrgId,
  7434. UpdateCreator: 0,
  7435. Status: 1,
  7436. Ctime: time.Now().Unix(),
  7437. Mtime: 0,
  7438. Price: info.Price,
  7439. WarehousingDetailId: 0,
  7440. WarehouseOutDetailId: 0,
  7441. CancelOutDetailId: 0,
  7442. ExpireDate: info.ExpiryDate,
  7443. ProductDate: info.ProductDate,
  7444. MaxUnit: info.CountUnit,
  7445. MinUnit: "",
  7446. }
  7447. service.CreatedCancelStock(cancelStockInfo)
  7448. service.CreateDrugFlowOne(flow)
  7449. } else {
  7450. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  7451. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7452. if advice.PrescribingNumberUnit == drug.MaxUnit {
  7453. warehouseInfo := models.DrugWarehouseInfo{
  7454. StockMinNumber: prescribingNumber,
  7455. }
  7456. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  7457. }
  7458. operation_time := time.Now().Unix()
  7459. creater := advice.AdviceDoctor
  7460. ctime := time.Now().Unix()
  7461. timeStr := time.Now().Format("2006-01-02")
  7462. timeArr := strings.Split(timeStr, "-")
  7463. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  7464. total = total + 1
  7465. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7466. cancelStock := models.DrugCancelStock{
  7467. OrderNumber: orderNumber,
  7468. OperaTime: operation_time,
  7469. OrgId: advice.UserOrgId,
  7470. Creater: creater,
  7471. Ctime: ctime,
  7472. Status: 1,
  7473. ReturnTime: advice.AdviceDate,
  7474. Dealer: info.Dealer,
  7475. Manufacturer: info.Manufacturer,
  7476. Type: 1,
  7477. }
  7478. service.AddSigleDrugCancelStock(&cancelStock)
  7479. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  7480. dealer, _ := service.GetDealerById(info.Dealer)
  7481. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  7482. cancelStockInfo := models.DrugCancelStockInfo{
  7483. OrderNumber: cancelInfo.OrderNumber,
  7484. CancelStockId: cancelInfo.ID,
  7485. DrugId: info.DrugId,
  7486. Count: info.Count,
  7487. Status: 1,
  7488. Ctime: ctime,
  7489. OrgId: advice.UserOrgId,
  7490. Type: 1,
  7491. Manufacturer: manufactureName.ManufacturerName,
  7492. Dealer: dealer.DealerName,
  7493. Total: 0,
  7494. RetailPrice: info.RetailPrice,
  7495. RetailTotalPrice: info.RetailTotalPrice,
  7496. Price: info.Price,
  7497. RegisterAccount: "",
  7498. Remark: info.Remark,
  7499. BatchNumber: info.BatchNumber,
  7500. MaxUnit: info.CountUnit,
  7501. ProductDate: info.ProductDate,
  7502. ExpiryDate: info.ExpiryDate,
  7503. BatchNumberId: info.WarehouseInfoId,
  7504. }
  7505. flow := models.DrugFlow{
  7506. WarehousingId: 0,
  7507. DrugId: info.DrugId,
  7508. Number: "",
  7509. BatchNumber: info.BatchNumber,
  7510. Count: info.Count,
  7511. UserOrgId: advice.UserOrgId,
  7512. PatientId: 0,
  7513. SystemTime: ctime,
  7514. ConsumableType: 4,
  7515. IsSys: 0,
  7516. WarehousingOrder: "",
  7517. WarehouseOutId: 0,
  7518. WarehouseOutOrderNumber: "",
  7519. IsEdit: 0,
  7520. CancelStockId: cancelStock.ID,
  7521. CancelOrderNumber: cancelStock.OrderNumber,
  7522. Manufacturer: info.Manufacturer,
  7523. Dealer: info.Dealer,
  7524. Creator: advice.AdviceDoctor,
  7525. UpdateCreator: 0,
  7526. Status: 1,
  7527. Ctime: time.Now().Unix(),
  7528. Mtime: 0,
  7529. Price: info.Price,
  7530. WarehousingDetailId: 0,
  7531. WarehouseOutDetailId: 0,
  7532. CancelOutDetailId: 0,
  7533. ExpireDate: info.ExpiryDate,
  7534. ProductDate: info.ProductDate,
  7535. MaxUnit: info.CountUnit,
  7536. MinUnit: "",
  7537. }
  7538. service.CreatedCancelStock(cancelStockInfo)
  7539. service.CreateDrugFlowOne(flow)
  7540. }
  7541. }
  7542. }
  7543. return err
  7544. }
  7545. func (this *HisApiController) DeleteNCDS() {
  7546. id, _ := this.GetInt64("id", 0)
  7547. if id > 0 {
  7548. service.DeletePsnNCDSRecordById(id)
  7549. this.ServeSuccessJSON(map[string]interface{}{
  7550. "msg": "删除成功",
  7551. })
  7552. } else {
  7553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  7554. return
  7555. }
  7556. }
  7557. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  7558. id, _ := c.GetInt64("id")
  7559. advice, _ := service.GetHisDoctorAdviceInfo(id)
  7560. c.ServeSuccessJSON(map[string]interface{}{
  7561. "advice": advice,
  7562. })
  7563. return
  7564. }
  7565. func (c *HisApiController) GetHisMonthChargePatientList() {
  7566. record_date := c.GetString("record_date")
  7567. start_time := c.GetString("start_time")
  7568. end_time := c.GetString("end_time")
  7569. timeLayout := "2006-01-02"
  7570. loc, _ := time.LoadLocation("Local")
  7571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7572. if err != nil {
  7573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7574. return
  7575. }
  7576. if err != nil {
  7577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7578. return
  7579. }
  7580. recordDateTime := theTime.Unix()
  7581. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7582. if err != nil {
  7583. }
  7584. startRecordDateTime := startTime.Unix()
  7585. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7586. if err != nil {
  7587. }
  7588. endRecordDateTime := endTime.Unix()
  7589. adminInfo := c.GetAdminUserInfo()
  7590. var tempMonthChargePatients []*service.MonthChargePatients
  7591. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  7592. for _, item := range tempPatients {
  7593. //过滤没有处方的
  7594. if len(item.HisPrescription) == 0 {
  7595. tempMonthChargePatients = append(tempMonthChargePatients, item)
  7596. }
  7597. }
  7598. c.ServeSuccessJSON(map[string]interface{}{
  7599. "list": tempMonthChargePatients,
  7600. })
  7601. }