his_api_controller.go 244KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  70. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  71. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  72. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  73. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  74. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  75. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  76. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  77. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  78. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  79. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  80. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  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. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  146. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  147. //var config []*models.HisXtDiagnoseConfig
  148. var name string
  149. for _, item := range diagnosis_ids {
  150. id, _ := strconv.ParseInt(item, 10, 64)
  151. diagnosisConfig, _ := service.FindDiagnoseById(id)
  152. if len(name) == 0 {
  153. name = diagnosisConfig.ClassName
  154. } else {
  155. name = name + "," + diagnosisConfig.ClassName
  156. }
  157. }
  158. decimal.DivisionPrecision = 2
  159. for _, item := range orderInfos {
  160. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  161. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  162. item.MedChrgitmType = "09"
  163. }
  164. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  165. if item.HisPrescriptionProject.Type == 2 {
  166. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  167. case 1:
  168. item.MedChrgitmType = "14"
  169. break
  170. case 2:
  171. item.MedChrgitmType = "05"
  172. break
  173. case 3:
  174. item.MedChrgitmType = "04"
  175. break
  176. case 4:
  177. item.MedChrgitmType = "14"
  178. break
  179. case 5:
  180. item.MedChrgitmType = "08"
  181. break
  182. case 6:
  183. item.MedChrgitmType = "14"
  184. break
  185. case 7:
  186. item.MedChrgitmType = "14"
  187. break
  188. case 8:
  189. item.MedChrgitmType = "03"
  190. break
  191. case 9:
  192. item.MedChrgitmType = "14"
  193. break
  194. }
  195. } else if item.HisPrescriptionProject.Type == 3 {
  196. item.MedChrgitmType = "08"
  197. }
  198. }
  199. }
  200. order.PsnCashPay = order.MedfeeSumamt
  201. //var user_name string
  202. //role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  203. //if role.ID == 0 {
  204. // user_name = "管理员"
  205. //} else {
  206. // user_name = role.UserName
  207. //}
  208. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  209. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  210. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  211. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  212. c.ServeSuccessJSON(map[string]interface{}{
  213. "org_name": org.OrgName,
  214. "name": patient.Name,
  215. "order_infos": orderInfos,
  216. "number": order.MdtrtId,
  217. "date": order.SettleAccountsDate,
  218. "charge_admin": charge_admin,
  219. "printor_admin": printor_admin,
  220. "info": order,
  221. })
  222. }
  223. func (c *HisApiController) RefudDetail() {
  224. order_id, _ := c.GetInt64("order_id")
  225. order, _ := service.GetHisOrderByID(order_id)
  226. adminUser := c.GetAdminUserInfo()
  227. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "msg": "撤销成功",
  230. })
  231. }
  232. func (c *HisApiController) Sscard() {
  233. //r := CardInit()
  234. //if r == 0 {
  235. // GetBaseInfo()
  236. //}
  237. //c.ServeSuccessJSON(map[string]interface{}{
  238. // "list": "11",
  239. //})
  240. }
  241. func GetBaseInfo() error {
  242. //handle := syscall.MustLoadDLL("SSCard.dll")
  243. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  244. //
  245. //str := make([]byte, 256)
  246. //str1 := make([]byte, 256)
  247. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  248. //if ferr != nil {
  249. // fmt.Println("ReadCardBas 报错", ferr.Error())
  250. // return ferr
  251. //}
  252. //
  253. //fmt.Println(string(str))
  254. //
  255. //fmt.Println(r)
  256. return nil
  257. }
  258. func CardInit() int {
  259. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  260. //add := DllTestDef.MustFindProc("Init")
  261. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  262. //if err != nil {
  263. // fmt.Println("SSCard的运算结果为:", ret)
  264. //}
  265. //result := int(ret)
  266. return 0
  267. }
  268. func IntPtr(n int) uintptr {
  269. return uintptr(n)
  270. }
  271. func StrPtr(s string) uintptr {
  272. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  273. }
  274. func (c *HisApiController) GetHisPatientList() {
  275. //types, _ := c.GetInt64("type", 0)
  276. record_date := c.GetString("record_date")
  277. sch_type, _ := c.GetInt64("sch_type")
  278. timeLayout := "2006-01-02"
  279. loc, _ := time.LoadLocation("Local")
  280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  281. if err != nil {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. return
  284. }
  285. recordDateTime := theTime.Unix()
  286. adminInfo := c.GetAdminUserInfo()
  287. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  288. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  289. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  290. //获取当前用户的信息
  291. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  292. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  293. //获取所有科室信息
  294. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  295. c.ServeSuccessJSON(map[string]interface{}{
  296. "list": patients,
  297. "list_two": patients_two,
  298. "info": adminUserInfo,
  299. "doctors": doctors,
  300. "department": department,
  301. })
  302. }
  303. type CustomTemplate struct {
  304. ID int64 `gorm:"column:id" json:"id" form:"id"`
  305. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  306. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  307. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  308. Status int64 `gorm:"column:status" json:"status" form:"status"`
  309. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  310. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  311. Type int64 `gorm:"column:type" json:"type" form:"type"`
  312. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  313. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  314. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  315. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  316. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  317. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  318. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  319. }
  320. func (c *HisApiController) GetHisPatientInfo() {
  321. patient_id, _ := c.GetInt64("patient_id")
  322. his_patient_id, _ := c.GetInt64("his_patient_id")
  323. record_date := c.GetString("record_date")
  324. number := c.GetString("number")
  325. //start_time := c.GetString("start_time")
  326. //end_time := c.GetString("end_time")
  327. p_type, _ := c.GetInt64("p_type")
  328. timeLayout := "2006-01-02"
  329. loc, _ := time.LoadLocation("Local")
  330. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  331. if err != nil {
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. recordDateTime := theTime.Unix()
  336. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  337. //if err != nil {
  338. //
  339. //}
  340. //startRecordDateTime := startTime.Unix()
  341. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  342. //if err != nil {
  343. //
  344. //}
  345. //endRecordDateTime := endTime.Unix()
  346. admin := c.GetAdminUserInfo()
  347. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  348. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  349. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  350. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  351. var prescriptions []*models.HisPrescription
  352. var last_prescriptions []*models.HisPrescription
  353. var sch_prescriptions []CustomTemplate
  354. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  355. if p_type == 1 { //住院
  356. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  357. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  358. } else { //门诊
  359. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  360. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  361. }
  362. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  363. if sch.ID > 0 {
  364. var week string
  365. t := time.Now()
  366. switch t.Weekday().String() {
  367. case "Monday":
  368. week = "周一"
  369. break
  370. case "Tuesday":
  371. week = "周二"
  372. break
  373. case "Wednesday":
  374. week = "周三"
  375. break
  376. case "Thursday":
  377. week = "周四"
  378. break
  379. case "Friday":
  380. week = "周五"
  381. break
  382. case "Saturday":
  383. week = "周六"
  384. break
  385. case "Sunday":
  386. week = "周日"
  387. break
  388. }
  389. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  390. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  391. //根据推送频率组装新的数组
  392. for _, item := range temp_sch_prescriptions {
  393. var cus CustomTemplate
  394. cus.ID = item.ID
  395. cus.UserOrgId = item.UserOrgId
  396. cus.PatientId = item.PatientId
  397. cus.MedType = item.MedType
  398. cus.RecordDate = item.RecordDate
  399. cus.Type = item.Type
  400. cus.PType = item.PType
  401. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  402. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  403. if subItem.FrequencyType == 1 { //每次必推
  404. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  405. }
  406. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  407. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  408. }
  409. if subItem.FrequencyType == 2 { //按照天数频率
  410. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  411. now := p.Unix()
  412. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  413. dayStr2 := "-" + dayStr
  414. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  415. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  416. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  417. if len(advices) == 0 {
  418. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  419. }
  420. }
  421. }
  422. }
  423. for _, subItem := range item.HisPrescriptionProjectTemplate {
  424. if subItem.Type == 2 {
  425. if subItem.XtHisProject.MedicalStatus != 1 {
  426. if subItem.FrequencyType == 1 {
  427. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  428. }
  429. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  430. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  431. }
  432. if subItem.FrequencyType == 2 {
  433. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  434. now := p.Unix()
  435. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  436. dayStr2 := "-" + dayStr
  437. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  438. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  439. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  440. if len(projects) == 0 {
  441. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  442. }
  443. }
  444. }
  445. } else if subItem.Type == 3 {
  446. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  447. if subItem.FrequencyType == 1 {
  448. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  449. }
  450. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  451. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  452. }
  453. if subItem.FrequencyType == 2 {
  454. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  455. now := p.Unix()
  456. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  457. dayStr2 := "-" + dayStr
  458. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  459. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  460. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  461. if len(projects) == 0 {
  462. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  463. }
  464. }
  465. }
  466. }
  467. }
  468. sch_prescriptions = append(sch_prescriptions, cus)
  469. }
  470. for _, item := range sch_prescriptions {
  471. if len(item.HisPrescriptionProjectTemplate) == 0 {
  472. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  473. }
  474. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  475. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  476. }
  477. }
  478. }
  479. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  480. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  481. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  482. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  483. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  484. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  485. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  486. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  487. //获取所有科室信息
  488. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "his_info": his_patient_info,
  491. "xt_info": xt_patient_info,
  492. "prescription": prescriptions,
  493. "case_history": case_history,
  494. "info": patientPrescriptionInfo,
  495. //"month_prescriptions": monthPrescriptions,
  496. "order": order,
  497. "doctors": doctors,
  498. "department": department,
  499. "sch_prescriptions": sch_prescriptions,
  500. "last_prescriptions": last_prescriptions,
  501. "schedule": sch,
  502. "count": count,
  503. "drugStockConfig": drugStockConfig,
  504. "last_info": lastPatientPrescriptionInfo,
  505. })
  506. return
  507. }
  508. func (c *HisApiController) GetHisPrescriptionConfig() {
  509. adminInfo := c.GetAdminUserInfo()
  510. //获取医嘱模版
  511. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  512. //获取所有基础药
  513. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  514. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  515. if config.ID > 0 && config.IsOpen == 1 {
  516. for _, item := range drugs {
  517. var index = 0
  518. for _, subItem := range item.OtherDrugWarehouseInfo {
  519. if index == 0 {
  520. if subItem.StockMaxNumber*item.MinNumber+subItem.StockMinNumber > 0 {
  521. index = index + 1
  522. item.MinPrice = subItem.RetailPrice
  523. }
  524. }
  525. }
  526. }
  527. }
  528. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  529. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  530. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  531. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  532. //获取所有科室信息
  533. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  534. //获取诊断信息
  535. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  536. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  537. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "drugs": drugs,
  540. "advices_template": advices,
  541. "drugways": drugways,
  542. "efs": efs,
  543. "doctors": doctors,
  544. "department": department,
  545. "sick": sick,
  546. "additions": additions,
  547. "diagnose": diagnose,
  548. "manufacturers": manufacturers,
  549. })
  550. }
  551. func (c *HisApiController) CreateHisPrescription() {
  552. record_date := c.GetString("record_date")
  553. patient_id, _ := c.GetInt64("patient_id")
  554. reg_type, _ := c.GetInt64("reg_type")
  555. diagnose := c.GetString("diagnose")
  556. sick_type, _ := c.GetInt64("sick_type")
  557. sick_history := c.GetString("sick_history")
  558. doctor_id, _ := c.GetInt64("doctor", 0)
  559. department, _ := c.GetInt64("department", 0)
  560. his_patient_id, _ := c.GetInt64("his_patient_id")
  561. p_type, _ := c.GetInt64("p_type")
  562. dataBody := make(map[string]interface{}, 0)
  563. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  564. if err != nil {
  565. utils.ErrorLog(err.Error())
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. timeLayout := "2006-01-02"
  570. loc, _ := time.LoadLocation("Local")
  571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  572. if err != nil {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  574. return
  575. }
  576. adminInfo := c.GetAdminUserInfo()
  577. recordDateTime := theTime.Unix()
  578. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  579. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  580. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  581. if len(lists) == 1 {
  582. his_patient_id = lists[0].ID
  583. }
  584. }
  585. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  587. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  588. if drugStockConfig.IsOpen == 1 {
  589. //校验库存总量
  590. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  591. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  592. if len(prescriptions) > 0 {
  593. for _, item := range prescriptions {
  594. items := item.(map[string]interface{})
  595. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  596. advices := items["advices"].([]interface{})
  597. if len(advices) > 0 {
  598. for _, advice := range advices {
  599. var drug_id int64
  600. var prescribing_number float64
  601. var prescribingNumberUnit string
  602. var prescribingNumber string
  603. var adviceId int64
  604. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  605. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  606. }
  607. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  608. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  609. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  610. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  611. }
  612. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  613. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  614. }
  615. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  616. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  617. }
  618. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  619. if drug.ID == 0 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  621. return
  622. }
  623. //查询药品的所有库存
  624. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  625. var total_count int64
  626. for _, it := range list {
  627. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  628. }
  629. totals := strconv.FormatInt(total_count, 10)
  630. //查询该药品是否存在开药记录
  631. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  632. //新增处方
  633. if advicelist.ID == 0 {
  634. all_count, _ := strconv.ParseFloat(totals, 64)
  635. if prescribingNumberUnit == drug.MinUnit {
  636. if prescribing_number > all_count {
  637. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  638. return
  639. }
  640. } else {
  641. if prescribingNumberUnit == drug.MaxUnit {
  642. num := prescribing_number * float64(drug.MinNumber)
  643. if num > all_count {
  644. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  645. return
  646. }
  647. }
  648. }
  649. }
  650. //修改处方
  651. if advicelist.ID > 0 {
  652. var device_number int64
  653. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  654. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  655. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  656. device_number = prescribingNumberInt * drug.MinNumber
  657. }
  658. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  659. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  660. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  661. device_number = prescribingNumberInt
  662. }
  663. var number_count int64
  664. if prescribingNumberUnit == drug.MaxUnit {
  665. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  666. number_count = prescribingNumberInt * drug.MinNumber
  667. }
  668. if prescribingNumberUnit == drug.MinUnit {
  669. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  670. number_count = prescribingNumberInt
  671. }
  672. //如果修改的数量大于之前修改的数量
  673. if (number_count - device_number) > 0 {
  674. //如果修改的差数量 大于库存数量
  675. if (number_count - device_number) > total_count {
  676. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  677. return
  678. }
  679. }
  680. if device_number != number_count {
  681. // 查询该药品最后一次出库记录
  682. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  683. //回退库存
  684. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  685. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  686. }
  687. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  688. var stock_max_number int64
  689. var stock_min_number int64
  690. if number_count >= drug.MinNumber {
  691. stock_max_number = device_number / drug.MinNumber
  692. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  693. stock_min_number = device_number % drug.MinNumber
  694. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  695. } else {
  696. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  697. }
  698. }
  699. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  700. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  701. }
  702. //删除记录
  703. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  704. }
  705. }
  706. }
  707. }
  708. }
  709. }
  710. }
  711. }
  712. }
  713. if stockConfig.IsOpen == 1 {
  714. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  715. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  716. if len(prescriptions) > 0 {
  717. for _, item := range prescriptions {
  718. items := item.(map[string]interface{})
  719. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  720. projects := items["project"].([]interface{})
  721. if len(projects) > 0 {
  722. for _, project := range projects {
  723. var project_id int64
  724. var project_type int64
  725. var totals float64
  726. var project_name string
  727. var parsetotal int64
  728. var id int64
  729. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  730. id = int64(project.(map[string]interface{})["id"].(float64))
  731. }
  732. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  733. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  734. }
  735. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  736. project_type = int64(project.(map[string]interface{})["type"].(float64))
  737. }
  738. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  739. total, _ := project.(map[string]interface{})["total"].(string)
  740. totals, _ = strconv.ParseFloat(total, 64)
  741. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  742. }
  743. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  744. project_name = project.(map[string]interface{})["project_name"].(string)
  745. }
  746. if project_type == 3 {
  747. //查找该耗材的出库记录
  748. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  749. //var total_count int64
  750. //for _, it := range goodWarehouseInfo {
  751. // total_count += it.Count
  752. //}
  753. if len(goodWarehouseInfo) == 0 {
  754. //查询耗材库存
  755. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  756. var stock_count int64
  757. for _, it := range list {
  758. stock_count += it.StockCount
  759. }
  760. stock_counts := strconv.FormatInt(stock_count, 10)
  761. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  762. if totals > stock_total_count {
  763. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  764. return
  765. }
  766. //查找今日该患者已经出库的所有耗材
  767. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  768. for _, item := range goodList {
  769. //回退库存
  770. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  771. }
  772. //删除记录
  773. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  774. }
  775. if len(goodWarehouseInfo) > 0 {
  776. //查询该患者耗材的历史数据
  777. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  778. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  779. //数量发生改变
  780. if parsetotal != count {
  781. //查找今日该患者已经出库的所有耗材
  782. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  783. for _, item := range goodList {
  784. //回退库存
  785. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  786. }
  787. //删除记录
  788. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  789. }
  790. }
  791. }
  792. }
  793. }
  794. }
  795. }
  796. }
  797. }
  798. }
  799. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  800. var hpInfo models.HisPrescriptionInfo
  801. if info.ID == 0 {
  802. var randNum int
  803. randNum = rand.Intn(10000) + 1000
  804. timestamp := time.Now().Unix()
  805. tempTime := time.Unix(timestamp, 0)
  806. timeFormat := tempTime.Format("20060102150405")
  807. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  808. hpInfo = models.HisPrescriptionInfo{
  809. HisPatientId: his_patient_id,
  810. UserOrgId: adminInfo.CurrentOrgId,
  811. RecordDate: theTime.Unix(),
  812. PatientId: patient_id,
  813. Status: 1,
  814. Ctime: time.Now().Unix(),
  815. Mtime: time.Now().Unix(),
  816. Creator: adminInfo.AdminUser.Id,
  817. Modifier: adminInfo.AdminUser.Id,
  818. Diagnosis: diagnose,
  819. SickHistory: sick_history,
  820. Departments: department,
  821. RegisterType: reg_type,
  822. PrescriptionNumber: p_number,
  823. PrescriptionStatus: 1,
  824. Doctor: role.UserName,
  825. DoctorId: doctor_id,
  826. SickType: sick_type,
  827. PType: p_type,
  828. }
  829. service.SavePatientPrescriptionInfo(hpInfo)
  830. redis := service.RedisClient()
  831. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  832. redis.Set(key, "", time.Second)
  833. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  834. redis.Set(keyOne, "", time.Second)
  835. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  836. redis.Set(keySeven, "", time.Second)
  837. defer redis.Close()
  838. } else {
  839. hpInfo = models.HisPrescriptionInfo{
  840. ID: info.ID,
  841. UserOrgId: adminInfo.CurrentOrgId,
  842. RecordDate: info.RecordDate,
  843. PatientId: info.PatientId,
  844. Status: 1,
  845. Ctime: info.Ctime,
  846. Mtime: time.Now().Unix(),
  847. Creator: info.Creator,
  848. Modifier: adminInfo.AdminUser.Id,
  849. Diagnosis: diagnose,
  850. SickHistory: sick_history,
  851. Departments: department,
  852. RegisterType: reg_type,
  853. PrescriptionNumber: info.PrescriptionNumber,
  854. Doctor: role.UserName,
  855. PrescriptionStatus: info.PrescriptionStatus,
  856. DoctorId: doctor_id,
  857. SickType: sick_type,
  858. PType: info.PType,
  859. HisPatientId: info.HisPatientId,
  860. }
  861. service.SavePatientPrescriptionInfo(hpInfo)
  862. redis := service.RedisClient()
  863. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  864. redis.Set(key, "", time.Second)
  865. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  866. redis.Set(keyOne, "", time.Second)
  867. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  868. redis.Set(keySeven, "", time.Second)
  869. defer redis.Close()
  870. }
  871. //定义切片
  872. var adviceList []models.HisDoctorAdviceInfo
  873. var projectList []models.HisPrescriptionProject
  874. //var hisLis []models.HisList
  875. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  876. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  877. var tempPrescription *models.HisPrescription
  878. if len(prescriptions) > 0 {
  879. for _, item := range prescriptions {
  880. items := item.(map[string]interface{})
  881. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  882. utils.ErrorLog("id")
  883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. id := int64(items["id"].(float64))
  887. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  888. tempPrescription = &new_prescription
  889. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  890. utils.ErrorLog("type")
  891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  892. return
  893. }
  894. types := int64(items["type"].(float64))
  895. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  896. utils.ErrorLog("med_type")
  897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  898. return
  899. }
  900. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  901. if med_type == "0" {
  902. med_type = "14"
  903. }
  904. //if order_status == 0 {
  905. // order_status = 1
  906. //}
  907. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  908. utils.ErrorLog("pre_time")
  909. }
  910. preTime, _ := items["pre_time"].(string)
  911. timeLayout := "2006-01-02"
  912. loc, _ := time.LoadLocation("Local")
  913. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  914. if err != nil {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  916. return
  917. }
  918. pTime := theTime2.Unix()
  919. ctime := time.Now().Unix()
  920. if tempPrescription.ID == 0 {
  921. prescription := &models.HisPrescription{
  922. ID: 0,
  923. PatientId: patient_id,
  924. UserOrgId: adminInfo.CurrentOrgId,
  925. RecordDate: recordDateTime,
  926. Ctime: ctime,
  927. Mtime: ctime,
  928. Type: types,
  929. Modifier: adminInfo.AdminUser.Id,
  930. Creator: adminInfo.AdminUser.Id,
  931. Status: 1,
  932. Doctor: role.UserName,
  933. HisPatientId: his_patient_id,
  934. OrderStatus: 1,
  935. BatchNumber: "",
  936. PrescriptionNumber: hpInfo.PrescriptionNumber,
  937. PreTime: pTime,
  938. PType: p_type,
  939. MedType: med_type,
  940. }
  941. tempPrescription = prescription
  942. service.SaveHisPrescription(tempPrescription)
  943. redis := service.RedisClient()
  944. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  945. redis.Set(key, "", time.Second)
  946. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  947. redis.Set(keyOne, "", time.Second)
  948. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  949. redis.Set(keySeven, "", time.Second)
  950. defer redis.Close()
  951. } else {
  952. tempPrescription.ID = id
  953. tempPrescription.Type = types
  954. tempPrescription.Modifier = adminInfo.AdminUser.Id
  955. tempPrescription.Mtime = time.Now().Unix()
  956. tempPrescription.Doctor = role.UserName
  957. //tempPrescription.OrderStatus = order_status
  958. tempPrescription.PreTime = pTime
  959. tempPrescription.MedType = med_type
  960. service.SaveHisPrescription(tempPrescription)
  961. redis := service.RedisClient()
  962. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  963. redis.Set(key, "", time.Second)
  964. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  965. redis.Set(keyOne, "", time.Second)
  966. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  967. redis.Set(keySeven, "", time.Second)
  968. defer redis.Close()
  969. }
  970. //service.SaveHisPrescription(prescription)
  971. //更改患者挂号状态
  972. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  973. fmt.Println("更改失败", err2)
  974. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  975. advices := items["advices"].([]interface{})
  976. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  977. groupNo := int64(0)
  978. ctime := time.Now().Unix()
  979. mtime := ctime
  980. if len(advices) > 0 {
  981. for _, advice := range advices {
  982. var s models.HisDoctorAdviceInfo
  983. s.PrescriptionId = tempPrescription.ID
  984. s.AdviceType = 2
  985. s.AdviceDoctor = doctor_id
  986. s.StopState = 2
  987. s.ExecutionState = 2
  988. s.AdviceDate = recordDateTime
  989. s.Status = 1
  990. s.UserOrgId = adminInfo.CurrentOrgId
  991. s.RecordDate = recordDateTime
  992. s.StartTime = tempPrescription.PreTime
  993. s.Groupno = groupNo
  994. s.CreatedTime = ctime
  995. s.UpdatedTime = mtime
  996. s.PatientId = patient_id
  997. s.HisPatientId = his_patient_id
  998. s.StartTime = pTime
  999. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1000. if errcode > 0 {
  1001. c.ServeFailJSONWithSGJErrorCode(errcode)
  1002. return
  1003. }
  1004. s.StartTime = pTime
  1005. service.CreateHisDoctorAdvice(&s)
  1006. //存储切片中
  1007. adviceList = append(adviceList, s)
  1008. redis := service.RedisClient()
  1009. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1010. redis.Set(key, "", time.Second)
  1011. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1012. redis.Set(keyOne, "", time.Second)
  1013. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1014. redis.Set(keySeven, "", time.Second)
  1015. var randNum int
  1016. randNum = rand.Intn(10000) + 1000
  1017. timestamp := time.Now().Unix()
  1018. tempTime := time.Unix(timestamp, 0)
  1019. timeFormat := tempTime.Format("20060102150405")
  1020. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1021. service.CreateHisDoctorAdvice(&s)
  1022. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1023. redis.Set(keySix, "", time.Second)
  1024. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1025. redis.Set(keyFive, "", time.Second)
  1026. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1027. redis.Set(keyEight, "", time.Second)
  1028. defer redis.Close()
  1029. }
  1030. }
  1031. }
  1032. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1033. projects := items["project"].([]interface{})
  1034. if len(projects) > 0 {
  1035. for _, project := range projects {
  1036. var p models.HisPrescriptionProject
  1037. p.PrescriptionId = tempPrescription.ID
  1038. p.Ctime = time.Now().Unix()
  1039. p.Mtime = time.Now().Unix()
  1040. p.PatientId = patient_id
  1041. p.RecordDate = recordDateTime
  1042. p.Doctor = doctor_id
  1043. p.UserOrgId = adminInfo.CurrentOrgId
  1044. p.HisPatientId = his_patient_id
  1045. p.Status = 1
  1046. p.StartTime = pTime
  1047. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1048. if errcode > 0 {
  1049. c.ServeFailJSONWithSGJErrorCode(errcode)
  1050. return
  1051. }
  1052. service.CreateHisProjectTwo(&p)
  1053. projectList = append(projectList, p)
  1054. var randNum int
  1055. randNum = rand.Intn(10000) + 1000
  1056. timestamp := time.Now().Unix()
  1057. tempTime := time.Unix(timestamp, 0)
  1058. timeFormat := tempTime.Format("20060102150405")
  1059. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1060. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1061. //新增或者编辑项目,修改对应的标签数据
  1062. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1063. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1064. var label models.HisLabelPrintInfo
  1065. project, _ := service.GetProjectDetail(p.ProjectId)
  1066. if project.CostClassify == 3 { //类别为检验检查
  1067. if p.TeamId > 0 { //检验检查组套
  1068. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1069. if tempLabel.ID == 0 {
  1070. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1071. label.Number = tempPrescription.PrescriptionNumber
  1072. label.ProjectId = project.ID
  1073. label.Status = 1
  1074. label.IsPrint = 2
  1075. label.DoctorId = info.DoctorId
  1076. label.UserOrgId = p.UserOrgId
  1077. label.PatientId = patient_id
  1078. label.RecordDate = recordDateTime
  1079. label.Ctime = time.Now().Unix()
  1080. label.Mtime = time.Now().Unix()
  1081. label.ItemId = p.TeamId
  1082. label.FeedetlSn = p.FeedetlSn
  1083. label.PProjectId = p.ID
  1084. label.ProjectName = team.ProjectTeam
  1085. label.PatientName = patient.Name
  1086. service.CreateHisLabelRecord(&label)
  1087. }
  1088. } else { //单条检验检查项目
  1089. label.Number = tempPrescription.PrescriptionNumber
  1090. label.ProjectId = project.ID
  1091. label.Status = 1
  1092. label.DoctorId = info.DoctorId
  1093. label.UserOrgId = p.UserOrgId
  1094. label.PatientId = patient_id
  1095. label.RecordDate = recordDateTime
  1096. label.IsPrint = 2
  1097. label.Ctime = time.Now().Unix()
  1098. label.Mtime = time.Now().Unix()
  1099. label.FeedetlSn = p.FeedetlSn
  1100. label.PProjectId = p.ID
  1101. label.ItemId = p.TeamId
  1102. label.ProjectName = project.ProjectName
  1103. label.PatientName = patient.Name
  1104. service.CreateHisLabelRecord(&label)
  1105. }
  1106. }
  1107. }
  1108. }
  1109. service.SaveHisProjectTwo(&p)
  1110. //if p.Type == 3 { //处理透前准备耗材数量数据
  1111. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1112. // if consumables.ID > 0 {
  1113. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1114. // consumables.Count = cnt
  1115. // service.UpdateConsumables(&consumables)
  1116. // }
  1117. //}
  1118. }
  1119. }
  1120. }
  1121. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1122. // addition := items["addition"].([]interface{})
  1123. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1124. // ctime := time.Now().Unix()
  1125. // mtime := ctime
  1126. // if len(addition) > 0 {
  1127. // for _, item := range addition {
  1128. // var s models.HisAdditionalCharge
  1129. // s.PrescriptionId = tempPrescription.ID
  1130. // s.Status = 1
  1131. // s.UserOrgId = adminInfo.CurrentOrgId
  1132. // s.RecordDate = recordDateTime
  1133. // s.CreatedTime = ctime
  1134. // s.UpdatedTime = mtime
  1135. // s.PatientId = patient_id
  1136. // s.HisPatientId = his_patient_id
  1137. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1138. // if errcode > 0 {
  1139. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1140. // return
  1141. // }
  1142. // service.CreateAdditionalCharge(&s)
  1143. // var randNum int
  1144. // randNum = rand.Intn(10000) + 1000
  1145. // timestamp := time.Now().Unix()
  1146. // tempTime := time.Unix(timestamp, 0)
  1147. // timeFormat := tempTime.Format("20060102150405")
  1148. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1149. // service.CreateAdditionalCharge(&s)
  1150. //
  1151. // }
  1152. // }
  1153. //}
  1154. }
  1155. }
  1156. }
  1157. //redisClient := service.RedisClient()
  1158. //defer redisClient.Close()
  1159. //
  1160. //list := models.HisList{
  1161. // Patient_id: patient_id,
  1162. // Advice_id:0,
  1163. // Record_date: 0,
  1164. // Advice: adviceList,
  1165. // Project: nil,
  1166. //}
  1167. //hisLis = append(hisLis, list)
  1168. //
  1169. //advice_json, _ := json.Marshal(&hisLis)
  1170. //redisClient.RPush("111", advice_json).Result()
  1171. //result, _ := redisClient.RPop("111").Result()
  1172. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1173. //
  1174. //var dat []map[string]interface{}
  1175. //json.Unmarshal([]byte(result), &dat)
  1176. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1177. //
  1178. //for k,v:=range dat{
  1179. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1180. //}
  1181. //project_json, _ := json.Marshal(&projectList)
  1182. //redisClient.LPush("222", project_json).Result()
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "msg": "保存成功",
  1186. })
  1187. return
  1188. } else {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1190. return
  1191. }
  1192. }
  1193. func (c *HisApiController) EditHisPrescription() {
  1194. record_date := c.GetString("record_date")
  1195. patient_id, _ := c.GetInt64("patient_id")
  1196. reg_type, _ := c.GetInt64("reg_type")
  1197. //diagnose, _ := c.GetInt64("diagnose", 0)
  1198. diagnose := c.GetString("diagnose")
  1199. sick_type, _ := c.GetInt64("sick_type")
  1200. sick_history := c.GetString("sick_history")
  1201. doctor_id, _ := c.GetInt64("doctor", 0)
  1202. department, _ := c.GetInt64("department", 0)
  1203. his_patient_id, _ := c.GetInt64("his_patient_id")
  1204. p_type, _ := c.GetInt64("p_type")
  1205. dataBody := make(map[string]interface{}, 0)
  1206. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1207. if err != nil {
  1208. utils.ErrorLog(err.Error())
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. adminInfo := c.GetAdminUserInfo()
  1220. recordDateTime := theTime.Unix()
  1221. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1222. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1223. var hpInfo models.HisPrescriptionInfo
  1224. if info.ID == 0 {
  1225. var randNum int
  1226. randNum = rand.Intn(10000) + 1000
  1227. timestamp := time.Now().Unix()
  1228. tempTime := time.Unix(timestamp, 0)
  1229. timeFormat := tempTime.Format("20060102150405")
  1230. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1231. hpInfo = models.HisPrescriptionInfo{
  1232. UserOrgId: adminInfo.CurrentOrgId,
  1233. RecordDate: theTime.Unix(),
  1234. PatientId: patient_id,
  1235. Status: 1,
  1236. Ctime: time.Now().Unix(),
  1237. Mtime: time.Now().Unix(),
  1238. Creator: adminInfo.AdminUser.Id,
  1239. Modifier: adminInfo.AdminUser.Id,
  1240. Diagnosis: diagnose,
  1241. SickHistory: sick_history,
  1242. Departments: department,
  1243. RegisterType: reg_type,
  1244. PrescriptionNumber: p_number,
  1245. PrescriptionStatus: 1,
  1246. Doctor: role.UserName,
  1247. DoctorId: doctor_id,
  1248. SickType: sick_type,
  1249. PType: p_type,
  1250. }
  1251. service.SavePatientPrescriptionInfo(hpInfo)
  1252. } else {
  1253. hpInfo = models.HisPrescriptionInfo{
  1254. ID: info.ID,
  1255. UserOrgId: adminInfo.CurrentOrgId,
  1256. RecordDate: info.RecordDate,
  1257. PatientId: info.PatientId,
  1258. Status: 1,
  1259. Ctime: info.Ctime,
  1260. Mtime: time.Now().Unix(),
  1261. Creator: info.Creator,
  1262. Modifier: adminInfo.AdminUser.Id,
  1263. Diagnosis: diagnose,
  1264. SickHistory: sick_history,
  1265. Departments: department,
  1266. RegisterType: reg_type,
  1267. PrescriptionNumber: info.PrescriptionNumber,
  1268. Doctor: role.UserName,
  1269. PrescriptionStatus: info.PrescriptionStatus,
  1270. DoctorId: doctor_id,
  1271. SickType: sick_type,
  1272. PType: info.PType,
  1273. }
  1274. service.SavePatientPrescriptionInfo(hpInfo)
  1275. }
  1276. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1277. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1278. if len(prescriptions) > 0 {
  1279. for _, item := range prescriptions {
  1280. items := item.(map[string]interface{})
  1281. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1282. utils.ErrorLog("id")
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1284. return
  1285. }
  1286. id := int64(items["id"].(float64))
  1287. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1288. utils.ErrorLog("type")
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. types := int64(items["type"].(float64))
  1293. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1294. utils.ErrorLog("med_type")
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1296. return
  1297. }
  1298. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1299. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1300. ctime := time.Now().Unix()
  1301. prescription := &models.HisPrescription{
  1302. ID: id,
  1303. PatientId: patient_id,
  1304. UserOrgId: adminInfo.CurrentOrgId,
  1305. RecordDate: recordDateTime,
  1306. Ctime: ctime,
  1307. Mtime: ctime,
  1308. Type: types,
  1309. Modifier: adminInfo.AdminUser.Id,
  1310. Creator: adminInfo.AdminUser.Id,
  1311. Status: 1,
  1312. Doctor: role.UserName,
  1313. HisPatientId: his_patient_id,
  1314. OrderStatus: 1,
  1315. BatchNumber: "",
  1316. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1317. PType: hpInfo.PType,
  1318. MedType: med_type,
  1319. }
  1320. if historyPrescription.ID > 0 {
  1321. prescription.PreTime = historyPrescription.PreTime
  1322. }
  1323. service.SaveHisPrescription(prescription)
  1324. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1325. advices := items["advices"].([]interface{})
  1326. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1327. groupNo := int64(0)
  1328. ctime := time.Now().Unix()
  1329. mtime := ctime
  1330. if len(advices) > 0 {
  1331. for _, advice := range advices {
  1332. var s models.HisDoctorAdviceInfo
  1333. s.PrescriptionId = prescription.ID
  1334. s.AdviceType = 2
  1335. s.AdviceDoctor = adminInfo.AdminUser.Id
  1336. s.StopState = 2
  1337. s.ExecutionState = 2
  1338. s.AdviceDate = recordDateTime
  1339. s.Status = 1
  1340. s.UserOrgId = adminInfo.CurrentOrgId
  1341. s.RecordDate = recordDateTime
  1342. s.StartTime = prescription.PreTime
  1343. s.Groupno = groupNo
  1344. s.CreatedTime = ctime
  1345. s.UpdatedTime = mtime
  1346. s.PatientId = patient_id
  1347. s.HisPatientId = his_patient_id
  1348. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1349. if errcode > 0 {
  1350. c.ServeFailJSONWithSGJErrorCode(errcode)
  1351. return
  1352. }
  1353. service.CreateHisDoctorAdvice(&s)
  1354. redis := service.RedisClient()
  1355. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1358. fmt.Println("keyOne", keyOne)
  1359. redis.Set(keyOne, "", time.Second)
  1360. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1361. redis.Set(keySeven, "", time.Second)
  1362. redis.Close()
  1363. }
  1364. }
  1365. }
  1366. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1367. projects := items["project"].([]interface{})
  1368. if len(projects) > 0 {
  1369. for _, project := range projects {
  1370. var p models.HisPrescriptionProject
  1371. p.PrescriptionId = prescription.ID
  1372. p.Ctime = time.Now().Unix()
  1373. p.Mtime = time.Now().Unix()
  1374. p.PatientId = patient_id
  1375. p.RecordDate = recordDateTime
  1376. p.UserOrgId = adminInfo.CurrentOrgId
  1377. p.HisPatientId = his_patient_id
  1378. p.Status = 1
  1379. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1380. if errcode > 0 {
  1381. c.ServeFailJSONWithSGJErrorCode(errcode)
  1382. return
  1383. }
  1384. service.CreateHisProjectTwo(&p)
  1385. }
  1386. }
  1387. }
  1388. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1389. addition := items["addition"].([]interface{})
  1390. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1391. ctime := time.Now().Unix()
  1392. mtime := ctime
  1393. if len(addition) > 0 {
  1394. for _, item := range addition {
  1395. var s models.HisAdditionalCharge
  1396. s.PrescriptionId = prescription.ID
  1397. s.Status = 1
  1398. s.UserOrgId = adminInfo.CurrentOrgId
  1399. s.RecordDate = recordDateTime
  1400. s.CreatedTime = ctime
  1401. s.UpdatedTime = mtime
  1402. s.PatientId = patient_id
  1403. s.HisPatientId = his_patient_id
  1404. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1405. if errcode > 0 {
  1406. c.ServeFailJSONWithSGJErrorCode(errcode)
  1407. return
  1408. }
  1409. service.CreateAdditionalCharge(&s)
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. }
  1416. if err == nil {
  1417. c.ServeSuccessJSON(map[string]interface{}{
  1418. "msg": "保存成功",
  1419. })
  1420. return
  1421. } else {
  1422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1423. return
  1424. }
  1425. }
  1426. func (c *HisApiController) DeletePrescription() {
  1427. prescription_id, _ := c.GetInt64("id")
  1428. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1429. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1430. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1431. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1432. if len(projects) > 0 {
  1433. for _, item := range projects {
  1434. service.DeletePrintInfo(item.ID) //删除打印信息
  1435. if stockConfig.IsOpen == 1 {
  1436. if item.Type == 3 {
  1437. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1438. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1439. good.Total = good.Total + f_count
  1440. service.UpdateGoodInfo(&good)
  1441. operation_time := time.Now().Unix()
  1442. creater := c.GetAdminUserInfo().AdminUser.Id
  1443. //创建退库单
  1444. timeStr := time.Now().Format("2006-01-02")
  1445. timeArr := strings.Split(timeStr, "-")
  1446. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1447. total = total + 1
  1448. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1449. cancelStock := models.CancelStock{
  1450. OrderNumber: orderNumber,
  1451. OperaTime: operation_time,
  1452. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1453. Creater: creater,
  1454. Ctime: time.Now().Unix(),
  1455. Status: 1,
  1456. ReturnTime: item.RecordDate,
  1457. Type: 1,
  1458. }
  1459. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1460. if msgerrkonde == gorm.ErrRecordNotFound {
  1461. service.AddSigleCancelStock(&cancelStock)
  1462. }
  1463. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1464. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1465. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1466. //查询该耗材是否出库
  1467. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1468. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1469. deaerler, _ := service.GetDealerById(info.Dealer)
  1470. if info.ID > 0 {
  1471. cancelStockInfo := models.CancelStockInfo{
  1472. GoodId: item.ProjectId,
  1473. CancelStockId: cancel.ID,
  1474. GoodTypeId: info.GoodTypeId,
  1475. Count: prescribingNumber,
  1476. Price: info.Price,
  1477. Total: 0,
  1478. ProductDate: info.ProductDate,
  1479. ExpiryDate: info.ExpiryDate,
  1480. Ctime: time.Now().Unix(),
  1481. Status: 1,
  1482. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1483. OrderNumber: cancel.OrderNumber,
  1484. Type: 0,
  1485. Dealer: deaerler.DealerName,
  1486. Manufacturer: manufacturer.ManufacturerName,
  1487. Number: info.Number,
  1488. RegisterAccount: "",
  1489. Remark: "",
  1490. WarehouseInfoId: info.WarehouseInfotId,
  1491. PatientId: info.PatientId,
  1492. RecordDate: info.SysRecordTime,
  1493. }
  1494. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1495. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1496. flow := models.VmStockFlow{
  1497. WarehousingId: 0,
  1498. GoodId: item.ProjectId,
  1499. Number: info.Number,
  1500. LicenseNumber: info.LicenseNumber,
  1501. Count: prescribingNumber,
  1502. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1503. PatientId: item.PatientId,
  1504. SystemTime: info.SysRecordTime,
  1505. ConsumableType: 7,
  1506. IsSys: 0,
  1507. WarehousingOrder: "",
  1508. WarehouseOutId: 0,
  1509. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1510. IsEdit: 0,
  1511. CancelStockId: cancel.ID,
  1512. CancelOrderNumber: cancel.OrderNumber,
  1513. Manufacturer: manufacturer.ID,
  1514. Dealer: 0,
  1515. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1516. UpdateCreator: 0,
  1517. Status: 1,
  1518. Ctime: time.Now().Unix(),
  1519. Mtime: 0,
  1520. Price: info.Price,
  1521. WarehousingDetailId: info.WarehouseInfotId,
  1522. WarehouseOutDetailId: 0,
  1523. CancelOutDetailId: cancelInfo.ID,
  1524. ProductDate: info.ProductDate,
  1525. ExpireDate: info.ExpiryDate,
  1526. }
  1527. service.CreateStockFlowOne(flow)
  1528. //删除出库表
  1529. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1530. //查询今日该患者开了多少耗材
  1531. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1532. var total_count int64
  1533. var cha_count int64
  1534. for _, item := range projectList {
  1535. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1536. total_count += count
  1537. }
  1538. //回退库存
  1539. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1540. //查询今日该耗材退库数量
  1541. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1542. var cancel_Count int64
  1543. for _, items := range cancelInfoOne {
  1544. cancel_Count += items.Count
  1545. }
  1546. cha_count = total_count - cancel_Count
  1547. if total_count > cancel_Count {
  1548. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1549. if err == gorm.ErrRecordNotFound {
  1550. //没有记录,则创建出库单
  1551. timeStr := time.Now().Format("2006-01-02")
  1552. timeArr := strings.Split(timeStr, "-")
  1553. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1554. total = total + 1
  1555. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1556. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1557. number = number + total
  1558. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1559. warehouseOut := models.WarehouseOut{
  1560. WarehouseOutOrderNumber: warehousing_out_order,
  1561. OperationTime: time.Now().Unix(),
  1562. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1563. Creater: creater,
  1564. Ctime: time.Now().Unix(),
  1565. Status: 1,
  1566. WarehouseOutTime: info.SysRecordTime,
  1567. Dealer: 0,
  1568. Manufacturer: 0,
  1569. Type: 1,
  1570. IsSys: 1,
  1571. }
  1572. err := service.AddSigleWarehouseOut(&warehouseOut)
  1573. if err != nil {
  1574. utils.TraceLog("创建出库单失败 err = %v", err)
  1575. return
  1576. }
  1577. prepare := &models.DialysisBeforePrepare{
  1578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1579. PatientId: info.PatientId,
  1580. RecordDate: info.SysRecordTime,
  1581. GoodId: item.ProjectId,
  1582. GoodTypeId: info.GoodTypeId,
  1583. Count: cha_count,
  1584. }
  1585. //出库
  1586. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1587. } else if err == nil {
  1588. prepare := &models.DialysisBeforePrepare{
  1589. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1590. PatientId: info.PatientId,
  1591. RecordDate: info.SysRecordTime,
  1592. GoodId: item.ProjectId,
  1593. GoodTypeId: info.GoodTypeId,
  1594. Count: cha_count,
  1595. }
  1596. //出库
  1597. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1605. fmt.Println(err)
  1606. }
  1607. if drugStockConfig.IsOpen == 1 {
  1608. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1609. fmt.Println(err)
  1610. if len(advices) > 0 {
  1611. for _, item := range advices {
  1612. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1613. redis := service.RedisClient()
  1614. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1615. redis.Set(keyFive, "", time.Second)
  1616. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1617. redis.Set(keyOne, "", time.Second)
  1618. redis.Close()
  1619. //查询该药品是否存在出库记录
  1620. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1621. if errcode == gorm.ErrRecordNotFound {
  1622. } else if errcode == nil {
  1623. if item.PrescribingNumberUnit == drug.MinUnit {
  1624. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1625. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1626. //退库
  1627. warehouseInfo := models.DrugWarehouseInfo{
  1628. StockMinNumber: prescribingNumber,
  1629. }
  1630. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1631. adminUserInfo := c.GetAdminUserInfo()
  1632. operation_time := time.Now().Unix()
  1633. creater := adminUserInfo.AdminUser.Id
  1634. ctime := time.Now().Unix()
  1635. timeStr := time.Now().Format("2006-01-02")
  1636. timeArr := strings.Split(timeStr, "-")
  1637. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1638. total = total + 1
  1639. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1640. cancelStock := models.DrugCancelStock{
  1641. OrderNumber: orderNumber,
  1642. OperaTime: operation_time,
  1643. OrgId: adminUserInfo.CurrentOrgId,
  1644. Creater: creater,
  1645. Ctime: ctime,
  1646. Status: 1,
  1647. ReturnTime: item.AdviceDate,
  1648. Dealer: info.Dealer,
  1649. Manufacturer: info.Manufacturer,
  1650. Type: 1,
  1651. }
  1652. service.AddSigleDrugCancelStock(&cancelStock)
  1653. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1654. dealer, _ := service.GetDealerById(info.Dealer)
  1655. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1656. cancelStockInfo := models.DrugCancelStockInfo{
  1657. OrderNumber: cancelInfo.OrderNumber,
  1658. CancelStockId: cancelInfo.ID,
  1659. DrugId: info.DrugId,
  1660. Count: prescribingNumber,
  1661. Status: 1,
  1662. Ctime: ctime,
  1663. OrgId: adminUserInfo.CurrentOrgId,
  1664. Type: 1,
  1665. Manufacturer: manufactureName.ManufacturerName,
  1666. Dealer: dealer.DealerName,
  1667. Total: 0,
  1668. RetailPrice: info.RetailPrice,
  1669. RetailTotalPrice: info.RetailTotalPrice,
  1670. Price: info.Price,
  1671. RegisterAccount: "",
  1672. Remark: info.Remark,
  1673. BatchNumber: info.BatchNumber,
  1674. MaxUnit: info.CountUnit,
  1675. ProductDate: info.ProductDate,
  1676. ExpiryDate: info.ExpiryDate,
  1677. BatchNumberId: info.WarehouseInfoId,
  1678. }
  1679. flow := models.DrugFlow{
  1680. WarehousingId: 0,
  1681. DrugId: info.DrugId,
  1682. Number: "",
  1683. BatchNumber: info.BatchNumber,
  1684. Count: prescribingNumber,
  1685. UserOrgId: adminUserInfo.CurrentOrgId,
  1686. PatientId: 0,
  1687. SystemTime: info.SysRecordTime,
  1688. ConsumableType: 7,
  1689. IsSys: 0,
  1690. WarehousingOrder: "",
  1691. WarehouseOutId: 0,
  1692. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1693. IsEdit: 0,
  1694. CancelStockId: cancelStock.ID,
  1695. CancelOrderNumber: cancelStock.OrderNumber,
  1696. Manufacturer: info.Manufacturer,
  1697. Dealer: info.Dealer,
  1698. Creator: adminUserInfo.AdminUser.Id,
  1699. UpdateCreator: 0,
  1700. Status: 1,
  1701. Ctime: time.Now().Unix(),
  1702. Mtime: 0,
  1703. Price: info.Price,
  1704. WarehousingDetailId: 0,
  1705. WarehouseOutDetailId: 0,
  1706. CancelOutDetailId: 0,
  1707. ExpireDate: info.ExpiryDate,
  1708. ProductDate: info.ProductDate,
  1709. MaxUnit: info.CountUnit,
  1710. MinUnit: "",
  1711. AdviceId: info.AdviceId,
  1712. }
  1713. service.CreatedCancelStock(cancelStockInfo)
  1714. service.CreateDrugFlowOne(flow)
  1715. //删除出库记录
  1716. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1717. //删除流水
  1718. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1719. } else {
  1720. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1721. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1722. if item.PrescribingNumberUnit == drug.MaxUnit {
  1723. warehouseInfo := models.DrugWarehouseInfo{
  1724. StockMaxNumber: prescribingNumber,
  1725. }
  1726. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1727. }
  1728. adminUserInfo := c.GetAdminUserInfo()
  1729. operation_time := time.Now().Unix()
  1730. creater := adminUserInfo.AdminUser.Id
  1731. ctime := time.Now().Unix()
  1732. timeStr := time.Now().Format("2006-01-02")
  1733. timeArr := strings.Split(timeStr, "-")
  1734. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1735. total = total + 1
  1736. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1737. cancelStock := models.DrugCancelStock{
  1738. OrderNumber: orderNumber,
  1739. OperaTime: operation_time,
  1740. OrgId: adminUserInfo.CurrentOrgId,
  1741. Creater: creater,
  1742. Ctime: ctime,
  1743. Status: 1,
  1744. ReturnTime: item.AdviceDate,
  1745. Dealer: info.Dealer,
  1746. Manufacturer: info.Manufacturer,
  1747. Type: 1,
  1748. }
  1749. service.AddSigleDrugCancelStock(&cancelStock)
  1750. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1751. dealer, _ := service.GetDealerById(info.Dealer)
  1752. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1753. cancelStockInfo := models.DrugCancelStockInfo{
  1754. OrderNumber: cancelInfo.OrderNumber,
  1755. CancelStockId: cancelInfo.ID,
  1756. DrugId: info.DrugId,
  1757. // Count: info.Count,
  1758. Count: prescribingNumber,
  1759. Status: 1,
  1760. Ctime: ctime,
  1761. OrgId: adminUserInfo.CurrentOrgId,
  1762. Type: 1,
  1763. Manufacturer: manufactureName.ManufacturerName,
  1764. Dealer: dealer.DealerName,
  1765. Total: 0,
  1766. RetailPrice: info.RetailPrice,
  1767. RetailTotalPrice: info.RetailTotalPrice,
  1768. Price: info.Price,
  1769. RegisterAccount: "",
  1770. Remark: info.Remark,
  1771. BatchNumber: info.BatchNumber,
  1772. MaxUnit: info.CountUnit,
  1773. ProductDate: info.ProductDate,
  1774. ExpiryDate: info.ExpiryDate,
  1775. BatchNumberId: info.WarehouseInfoId,
  1776. }
  1777. flow := models.DrugFlow{
  1778. WarehousingId: 0,
  1779. DrugId: info.DrugId,
  1780. Number: "",
  1781. BatchNumber: info.BatchNumber,
  1782. //Count: info.Count,
  1783. Count: prescribingNumber,
  1784. UserOrgId: adminUserInfo.CurrentOrgId,
  1785. PatientId: 0,
  1786. SystemTime: info.SysRecordTime,
  1787. ConsumableType: 7,
  1788. IsSys: 0,
  1789. WarehousingOrder: "",
  1790. WarehouseOutId: 0,
  1791. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1792. IsEdit: 0,
  1793. CancelStockId: cancelStock.ID,
  1794. CancelOrderNumber: cancelStock.OrderNumber,
  1795. Manufacturer: info.Manufacturer,
  1796. Dealer: info.Dealer,
  1797. Creator: adminUserInfo.AdminUser.Id,
  1798. UpdateCreator: 0,
  1799. Status: 1,
  1800. Ctime: time.Now().Unix(),
  1801. Mtime: 0,
  1802. Price: info.Price,
  1803. WarehousingDetailId: 0,
  1804. WarehouseOutDetailId: 0,
  1805. CancelOutDetailId: 0,
  1806. ExpireDate: info.ExpiryDate,
  1807. ProductDate: info.ProductDate,
  1808. MaxUnit: info.CountUnit,
  1809. MinUnit: "",
  1810. AdviceId: info.AdviceId,
  1811. }
  1812. service.CreatedCancelStock(cancelStockInfo)
  1813. service.CreateDrugFlowOne(flow)
  1814. //删除出库记录
  1815. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1816. //删除流水
  1817. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1818. }
  1819. }
  1820. if item.PrescribingNumberUnit == drug.MinUnit {
  1821. drug.Total = drug.Total + item.PrescribingNumber
  1822. service.UpdateBaseDrugLib(&drug)
  1823. } else {
  1824. if item.PrescribingNumberUnit == drug.MaxUnit {
  1825. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  1826. drug.Total = drug.Total + item.PrescribingNumber
  1827. service.UpdateBaseDrugLib(&drug)
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. c.ServeSuccessJSON(map[string]interface{}{
  1834. "msg": "删除成功",
  1835. })
  1836. return
  1837. }
  1838. func (c *HisApiController) DeleteDoctorAdvice() {
  1839. id, _ := c.GetInt64("id")
  1840. advice, _ := service.GetHisDoctorAdvicesById(id)
  1841. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1842. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  1843. redis := service.RedisClient()
  1844. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1845. redis.Set(keyFive, "", time.Second)
  1846. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1847. redis.Set(keyOne, "", time.Second)
  1848. defer redis.Close()
  1849. if err == nil {
  1850. if drugStockConfig.IsOpen == 1 {
  1851. //判断该医嘱是否执行了
  1852. if advice.ExecutionState == 1 {
  1853. //查询该病人该药品是否有库存记录
  1854. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  1855. if errcode == gorm.ErrRecordNotFound {
  1856. } else {
  1857. //退库
  1858. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  1859. if advice.PrescribingNumberUnit == drug.MinUnit {
  1860. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1861. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1862. //退库
  1863. warehouseInfo := models.DrugWarehouseInfo{
  1864. StockMinNumber: prescribingNumber,
  1865. }
  1866. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1867. adminUserInfo := c.GetAdminUserInfo()
  1868. operation_time := time.Now().Unix()
  1869. creater := adminUserInfo.AdminUser.Id
  1870. ctime := time.Now().Unix()
  1871. timeStr := time.Now().Format("2006-01-02")
  1872. timeArr := strings.Split(timeStr, "-")
  1873. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1874. total = total + 1
  1875. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1876. cancelStock := models.DrugCancelStock{
  1877. OrderNumber: orderNumber,
  1878. OperaTime: operation_time,
  1879. OrgId: adminUserInfo.CurrentOrgId,
  1880. Creater: creater,
  1881. Ctime: ctime,
  1882. Status: 1,
  1883. ReturnTime: advice.AdviceDate,
  1884. Dealer: info.Dealer,
  1885. Manufacturer: info.Manufacturer,
  1886. Type: 1,
  1887. }
  1888. service.AddSigleDrugCancelStock(&cancelStock)
  1889. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1890. dealer, _ := service.GetDealerById(info.Dealer)
  1891. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1892. cancelStockInfo := models.DrugCancelStockInfo{
  1893. OrderNumber: cancelInfo.OrderNumber,
  1894. CancelStockId: cancelInfo.ID,
  1895. DrugId: info.DrugId,
  1896. Count: info.Count,
  1897. Status: 1,
  1898. Ctime: ctime,
  1899. OrgId: adminUserInfo.CurrentOrgId,
  1900. Type: 1,
  1901. Manufacturer: manufactureName.ManufacturerName,
  1902. Dealer: dealer.DealerName,
  1903. Total: 0,
  1904. RetailPrice: info.RetailPrice,
  1905. RetailTotalPrice: info.RetailTotalPrice,
  1906. Price: info.Price,
  1907. RegisterAccount: "",
  1908. Remark: info.Remark,
  1909. BatchNumber: info.BatchNumber,
  1910. MaxUnit: info.CountUnit,
  1911. ProductDate: info.ProductDate,
  1912. ExpiryDate: info.ExpiryDate,
  1913. BatchNumberId: info.WarehouseInfoId,
  1914. }
  1915. flow := models.DrugFlow{
  1916. WarehousingId: 0,
  1917. DrugId: info.DrugId,
  1918. Number: "",
  1919. BatchNumber: info.BatchNumber,
  1920. Count: info.Count,
  1921. UserOrgId: adminUserInfo.CurrentOrgId,
  1922. PatientId: 0,
  1923. SystemTime: info.SysRecordTime,
  1924. ConsumableType: 7,
  1925. IsSys: 0,
  1926. WarehousingOrder: "",
  1927. WarehouseOutId: 0,
  1928. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1929. IsEdit: 0,
  1930. CancelStockId: cancelStock.ID,
  1931. CancelOrderNumber: cancelStock.OrderNumber,
  1932. Manufacturer: info.Manufacturer,
  1933. Dealer: info.Dealer,
  1934. Creator: adminUserInfo.AdminUser.Id,
  1935. UpdateCreator: 0,
  1936. Status: 1,
  1937. Ctime: time.Now().Unix(),
  1938. Mtime: 0,
  1939. Price: info.Price,
  1940. WarehousingDetailId: 0,
  1941. WarehouseOutDetailId: 0,
  1942. CancelOutDetailId: 0,
  1943. ExpireDate: info.ExpiryDate,
  1944. ProductDate: info.ProductDate,
  1945. MaxUnit: info.CountUnit,
  1946. MinUnit: "",
  1947. AdviceId: info.AdviceId,
  1948. }
  1949. service.CreatedCancelStock(cancelStockInfo)
  1950. service.CreateDrugFlowOne(flow)
  1951. //删除出库记录
  1952. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  1953. //删除流水
  1954. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  1955. } else {
  1956. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1957. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1958. if advice.PrescribingNumberUnit == drug.MaxUnit {
  1959. warehouseInfo := models.DrugWarehouseInfo{
  1960. StockMaxNumber: prescribingNumber,
  1961. }
  1962. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1963. }
  1964. adminUserInfo := c.GetAdminUserInfo()
  1965. operation_time := time.Now().Unix()
  1966. creater := adminUserInfo.AdminUser.Id
  1967. ctime := time.Now().Unix()
  1968. timeStr := time.Now().Format("2006-01-02")
  1969. timeArr := strings.Split(timeStr, "-")
  1970. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1971. total = total + 1
  1972. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1973. cancelStock := models.DrugCancelStock{
  1974. OrderNumber: orderNumber,
  1975. OperaTime: operation_time,
  1976. OrgId: adminUserInfo.CurrentOrgId,
  1977. Creater: creater,
  1978. Ctime: ctime,
  1979. Status: 1,
  1980. ReturnTime: advice.AdviceDate,
  1981. Dealer: info.Dealer,
  1982. Manufacturer: info.Manufacturer,
  1983. Type: 1,
  1984. }
  1985. service.AddSigleDrugCancelStock(&cancelStock)
  1986. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1987. dealer, _ := service.GetDealerById(info.Dealer)
  1988. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1989. cancelStockInfo := models.DrugCancelStockInfo{
  1990. OrderNumber: cancelInfo.OrderNumber,
  1991. CancelStockId: cancelInfo.ID,
  1992. DrugId: info.DrugId,
  1993. Count: info.Count,
  1994. Status: 1,
  1995. Ctime: ctime,
  1996. OrgId: adminUserInfo.CurrentOrgId,
  1997. Type: 1,
  1998. Manufacturer: manufactureName.ManufacturerName,
  1999. Dealer: dealer.DealerName,
  2000. Total: 0,
  2001. RetailPrice: info.RetailPrice,
  2002. RetailTotalPrice: info.RetailTotalPrice,
  2003. Price: info.Price,
  2004. RegisterAccount: "",
  2005. Remark: info.Remark,
  2006. BatchNumber: info.BatchNumber,
  2007. MaxUnit: info.CountUnit,
  2008. ProductDate: info.ProductDate,
  2009. ExpiryDate: info.ExpiryDate,
  2010. BatchNumberId: info.WarehouseInfoId,
  2011. }
  2012. flow := models.DrugFlow{
  2013. WarehousingId: 0,
  2014. DrugId: info.DrugId,
  2015. Number: "",
  2016. BatchNumber: info.BatchNumber,
  2017. Count: info.Count,
  2018. UserOrgId: adminUserInfo.CurrentOrgId,
  2019. PatientId: 0,
  2020. SystemTime: info.SysRecordTime,
  2021. ConsumableType: 7,
  2022. IsSys: 0,
  2023. WarehousingOrder: "",
  2024. WarehouseOutId: 0,
  2025. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2026. IsEdit: 0,
  2027. CancelStockId: cancelStock.ID,
  2028. CancelOrderNumber: cancelStock.OrderNumber,
  2029. Manufacturer: info.Manufacturer,
  2030. Dealer: info.Dealer,
  2031. Creator: adminUserInfo.AdminUser.Id,
  2032. UpdateCreator: 0,
  2033. Status: 1,
  2034. Ctime: time.Now().Unix(),
  2035. Mtime: 0,
  2036. Price: info.Price,
  2037. WarehousingDetailId: 0,
  2038. WarehouseOutDetailId: 0,
  2039. CancelOutDetailId: 0,
  2040. ExpireDate: info.ExpiryDate,
  2041. ProductDate: info.ProductDate,
  2042. MaxUnit: info.CountUnit,
  2043. MinUnit: "",
  2044. AdviceId: info.AdviceId,
  2045. }
  2046. service.CreatedCancelStock(cancelStockInfo)
  2047. service.CreateDrugFlowOne(flow)
  2048. //删除出库记录
  2049. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2050. //删除流水
  2051. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2052. }
  2053. }
  2054. }
  2055. }
  2056. c.ServeSuccessJSON(map[string]interface{}{
  2057. "msg": "删除成功",
  2058. })
  2059. return
  2060. } else {
  2061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2062. return
  2063. }
  2064. }
  2065. func (c *HisApiController) DeleteProject() {
  2066. id, _ := c.GetInt64("id")
  2067. adminInfo := c.GetAdminUserInfo()
  2068. project, _ := service.GetHisProjectByID(id)
  2069. // var consumable models.DialysisBeforePrepare
  2070. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2071. service.DeletePrintInfo(id)
  2072. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2073. label.Status = 0
  2074. service.CreateHisLabelRecord(&label)
  2075. if stockConfig.IsOpen == 1 {
  2076. if project.Type == 2 {
  2077. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2078. fmt.Println(err)
  2079. }
  2080. if project.Type == 3 {
  2081. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2082. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2083. good.Total = good.Total + f_count
  2084. service.UpdateGoodInfo(&good)
  2085. operation_time := time.Now().Unix()
  2086. creater := adminInfo.AdminUser.Id
  2087. //创建退库单
  2088. timeStr := time.Now().Format("2006-01-02")
  2089. timeArr := strings.Split(timeStr, "-")
  2090. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2091. total = total + 1
  2092. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2093. cancelStock := models.CancelStock{
  2094. OrderNumber: orderNumber,
  2095. OperaTime: operation_time,
  2096. OrgId: adminInfo.CurrentOrgId,
  2097. Creater: creater,
  2098. Ctime: time.Now().Unix(),
  2099. Status: 1,
  2100. ReturnTime: project.RecordDate,
  2101. Type: 1,
  2102. }
  2103. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2104. if msgerrkonde == gorm.ErrRecordNotFound {
  2105. service.AddSigleCancelStock(&cancelStock)
  2106. }
  2107. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2108. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2109. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2110. //获取该耗材有库存的第一条数据
  2111. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2112. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2113. deaerler, _ := service.GetDealerById(info.Dealer)
  2114. if info.ID > 0 {
  2115. cancelStockInfo := models.CancelStockInfo{
  2116. GoodId: project.ProjectId,
  2117. CancelStockId: cancel.ID,
  2118. GoodTypeId: info.GoodTypeId,
  2119. Count: prescribingNumber,
  2120. Price: info.Price,
  2121. Total: 0,
  2122. ProductDate: info.ProductDate,
  2123. ExpiryDate: info.ExpiryDate,
  2124. Ctime: time.Now().Unix(),
  2125. Status: 1,
  2126. OrgId: adminInfo.CurrentOrgId,
  2127. OrderNumber: cancel.OrderNumber,
  2128. Type: 0,
  2129. Dealer: deaerler.DealerName,
  2130. Manufacturer: manufacturer.ManufacturerName,
  2131. Number: info.Number,
  2132. RegisterAccount: "",
  2133. Remark: "",
  2134. WarehouseInfoId: info.WarehouseInfotId,
  2135. PatientId: info.PatientId,
  2136. RecordDate: info.SysRecordTime,
  2137. }
  2138. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2139. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2140. flow := models.VmStockFlow{
  2141. WarehousingId: 0,
  2142. GoodId: project.ProjectId,
  2143. Number: info.Number,
  2144. LicenseNumber: info.LicenseNumber,
  2145. Count: prescribingNumber,
  2146. UserOrgId: adminInfo.CurrentOrgId,
  2147. PatientId: project.PatientId,
  2148. SystemTime: time.Now().Unix(),
  2149. ConsumableType: 7,
  2150. IsSys: 0,
  2151. WarehousingOrder: "",
  2152. WarehouseOutId: 0,
  2153. WarehouseOutOrderNumber: "",
  2154. IsEdit: 0,
  2155. CancelStockId: cancel.ID,
  2156. CancelOrderNumber: cancel.OrderNumber,
  2157. Manufacturer: manufacturer.ID,
  2158. Dealer: 0,
  2159. Creator: adminInfo.AdminUser.Id,
  2160. UpdateCreator: 0,
  2161. Status: 1,
  2162. Ctime: time.Now().Unix(),
  2163. Mtime: 0,
  2164. Price: info.Price,
  2165. WarehousingDetailId: info.WarehouseInfotId,
  2166. WarehouseOutDetailId: 0,
  2167. CancelOutDetailId: cancelInfo.ID,
  2168. ProductDate: info.ProductDate,
  2169. ExpireDate: info.ExpiryDate,
  2170. }
  2171. service.CreateStockFlowOne(flow)
  2172. //删除出库表
  2173. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2174. //查询今日该患者开了多少耗材
  2175. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2176. var total_count int64
  2177. var cha_count int64
  2178. for _, item := range projectList {
  2179. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2180. total_count += count
  2181. }
  2182. //回退库存
  2183. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2184. //查询今日该耗材退库数量
  2185. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2186. var cancel_count int64
  2187. for _, items := range cancelInfoOne {
  2188. cancel_count += items.Count
  2189. }
  2190. cha_count = total_count - cancel_count
  2191. if total_count > cancel_count {
  2192. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2193. if err == gorm.ErrRecordNotFound {
  2194. //没有记录,则创建出库单
  2195. timeStr := time.Now().Format("2006-01-02")
  2196. timeArr := strings.Split(timeStr, "-")
  2197. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2198. total = total + 1
  2199. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2200. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2201. number = number + total
  2202. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2203. warehouseOut := models.WarehouseOut{
  2204. WarehouseOutOrderNumber: warehousing_out_order,
  2205. OperationTime: time.Now().Unix(),
  2206. OrgId: adminInfo.CurrentOrgId,
  2207. Creater: creater,
  2208. Ctime: time.Now().Unix(),
  2209. Status: 1,
  2210. WarehouseOutTime: info.SysRecordTime,
  2211. Dealer: 0,
  2212. Manufacturer: 0,
  2213. Type: 1,
  2214. IsSys: 1,
  2215. }
  2216. err := service.AddSigleWarehouseOut(&warehouseOut)
  2217. if err != nil {
  2218. utils.TraceLog("创建出库单失败 err = %v", err)
  2219. return
  2220. }
  2221. prepare := &models.DialysisBeforePrepare{
  2222. UserOrgId: adminInfo.CurrentOrgId,
  2223. PatientId: info.PatientId,
  2224. RecordDate: info.SysRecordTime,
  2225. GoodId: project.ProjectId,
  2226. GoodTypeId: info.GoodTypeId,
  2227. Count: cha_count,
  2228. }
  2229. //出库
  2230. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2231. } else if err == nil {
  2232. prepare := &models.DialysisBeforePrepare{
  2233. UserOrgId: adminInfo.CurrentOrgId,
  2234. PatientId: info.PatientId,
  2235. RecordDate: info.SysRecordTime,
  2236. GoodId: project.ProjectId,
  2237. GoodTypeId: info.GoodTypeId,
  2238. Count: cha_count,
  2239. }
  2240. //出库
  2241. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2242. }
  2243. }
  2244. }
  2245. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2246. fmt.Println(err)
  2247. }
  2248. }
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "msg": "删除成功",
  2251. })
  2252. return
  2253. }
  2254. func (c *HisApiController) CreateHisAdditionalCharge() {
  2255. his_patient_id, _ := c.GetInt64("his_patient_id")
  2256. patient_id, _ := c.GetInt64("patient_id")
  2257. record_date := c.GetString("record_date")
  2258. timeLayout := "2006-01-02"
  2259. loc, _ := time.LoadLocation("Local")
  2260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2261. if err != nil {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. adminInfo := c.GetAdminUserInfo()
  2266. recordDateTime := theTime.Unix()
  2267. dataBody := make(map[string]interface{}, 0)
  2268. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2269. if err != nil {
  2270. utils.ErrorLog(err.Error())
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2272. return
  2273. }
  2274. var additions []*models.HisAdditionalCharge
  2275. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2276. additions, _ := dataBody["addition"].([]interface{})
  2277. if len(additions) > 0 {
  2278. for _, item := range additions {
  2279. items := item.(map[string]interface{})
  2280. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2281. utils.ErrorLog("item_id")
  2282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2283. return
  2284. }
  2285. item_id := int64(items["item_id"].(float64))
  2286. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2287. utils.ErrorLog("item_name")
  2288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2289. return
  2290. }
  2291. item_name := items["item_name"].(string)
  2292. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2293. utils.ErrorLog("price")
  2294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2295. return
  2296. }
  2297. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2298. ctime := time.Now().Unix()
  2299. additional := &models.HisAdditionalCharge{
  2300. PatientId: patient_id,
  2301. HisPatientId: his_patient_id,
  2302. UserOrgId: adminInfo.CurrentOrgId,
  2303. RecordDate: recordDateTime,
  2304. CreatedTime: ctime,
  2305. UpdatedTime: ctime,
  2306. Modifier: adminInfo.AdminUser.Id,
  2307. Creator: adminInfo.AdminUser.Id,
  2308. Price: price,
  2309. ItemName: item_name,
  2310. ItemId: item_id,
  2311. Status: 1,
  2312. }
  2313. additions = append(additions, additional)
  2314. }
  2315. }
  2316. }
  2317. for _, item := range additions {
  2318. service.CreateAddtionalCharge(item)
  2319. }
  2320. c.ServeSuccessJSON(map[string]interface{}{
  2321. "msg": "创建成功",
  2322. })
  2323. }
  2324. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2325. blood_fat := c.GetString("blood_fat")
  2326. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2327. blood_sugar := c.GetString("blood_sugar")
  2328. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2329. fmt.Println(bloodsugarfloat)
  2330. chief_conplaint := c.GetString("chief_conplaint")
  2331. dbp := c.GetString("dbp")
  2332. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2333. delivery_way, _ := c.GetInt64("delivery_way")
  2334. diagnostic := c.GetString("diagnostic")
  2335. family_history := c.GetString("family_history")
  2336. height := c.GetString("height")
  2337. history_of_present_illness := c.GetString("history_of_present_illness")
  2338. is_infect, _ := c.GetInt64("is_infect")
  2339. fmt.Println("is", is_infect)
  2340. past_history := c.GetString("past_history")
  2341. patient_id, _ := c.GetInt64("patient_id")
  2342. his_patient_id, _ := c.GetInt64("his_patient_id")
  2343. fmt.Println("patient_id", patient_id)
  2344. personal_history := c.GetString("personal_history")
  2345. pulse := c.GetString("pulse")
  2346. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2347. sbp := c.GetString("sbp")
  2348. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2349. heightfloat, _ := strconv.ParseFloat(height, 64)
  2350. sicktype := c.GetString("sick_type")
  2351. fmt.Println("sicketype", sicktype)
  2352. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2353. symptom := c.GetString("symptom")
  2354. sick_date := c.GetString("sick_date")
  2355. temperatures := c.GetString("temperature")
  2356. fmt.Println("temperatures", temperatures)
  2357. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2358. record_date := c.GetString("record_date")
  2359. breathing := c.GetString("breathing")
  2360. doctor_advice := c.GetString("doctor_advice")
  2361. remark := c.GetString("remark")
  2362. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2363. sick, _ := c.GetInt64("sick")
  2364. diagnose, _ := c.GetInt64("diagnose")
  2365. id, _ := c.GetInt64("id")
  2366. timeLayout := "2006-01-02"
  2367. loc, _ := time.LoadLocation("Local")
  2368. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2369. allergic_history := c.GetString("allergic_history")
  2370. if err != nil {
  2371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2372. return
  2373. }
  2374. recordDateTime := theTime.Unix()
  2375. fmt.Println("recordDataTime", recordDateTime)
  2376. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2377. if err != nil {
  2378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2379. return
  2380. }
  2381. sickTimes := sickTime.Unix()
  2382. ctime := time.Now().Unix()
  2383. caseHistory := models.HisPatientCaseHistory{
  2384. HisPatientId: his_patient_id,
  2385. PatientId: patient_id,
  2386. Temperature: temperature,
  2387. BloodSugar: bloodsugarfloat,
  2388. Pulse: pulsefloat,
  2389. Sbp: sbpfloat,
  2390. Dbp: dbpfloat,
  2391. Height: heightfloat,
  2392. BloodFat: bloodfatfloat,
  2393. SickType: sick_type,
  2394. Symptom: symptom,
  2395. SickDate: sickTimes,
  2396. IsInfect: is_infect,
  2397. HistoryOfPresentIllness: history_of_present_illness,
  2398. PastHistory: past_history,
  2399. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2400. ChiefConplaint: chief_conplaint,
  2401. PersonalHistory: personal_history,
  2402. FamilyHistory: family_history,
  2403. Diagnostic: diagnostic,
  2404. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2405. Status: 1,
  2406. Ctime: ctime,
  2407. Mtime: ctime,
  2408. RecordDate: recordDateTime,
  2409. DeliveryWay: delivery_way,
  2410. Breathing: breathingfloat,
  2411. DoctorAdvice: doctor_advice,
  2412. Remark: remark,
  2413. Sick: sick,
  2414. Diagnose: diagnose,
  2415. AllergicHistory: allergic_history,
  2416. }
  2417. //查询该患者是否有病历
  2418. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2419. if errcodes == gorm.ErrRecordNotFound {
  2420. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2421. if err != nil {
  2422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2423. return
  2424. }
  2425. c.ServeSuccessJSON(map[string]interface{}{
  2426. "caseHistory": caseHistory,
  2427. })
  2428. return
  2429. } else if errcodes == nil {
  2430. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2431. if err != nil {
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2433. return
  2434. }
  2435. c.ServeSuccessJSON(map[string]interface{}{
  2436. "caseHistory": caseHistory,
  2437. })
  2438. }
  2439. //查询该患者是否有病历
  2440. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2441. //if errcode == gorm.ErrRecordNotFound {
  2442. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2443. // if err != nil {
  2444. // c.ServeSuccessJSON(map[string]interface{}{
  2445. // "msg": "保存成功",
  2446. // })
  2447. // }
  2448. //} else if errcode == nil {
  2449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2450. // return
  2451. //}
  2452. }
  2453. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2454. patient_id, _ := c.GetInt64("patient_id", 0)
  2455. adminUser := c.GetAdminUserInfo()
  2456. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2457. c.ServeSuccessJSON(map[string]interface{}{
  2458. "list": caseHistorys,
  2459. })
  2460. }
  2461. func (c *HisApiController) GetHisPatientCaseHistory() {
  2462. record_date, _ := c.GetInt64("record_date", 0)
  2463. patient_id, _ := c.GetInt64("patient_id", 0)
  2464. admin := c.GetAdminUserInfo()
  2465. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2466. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2467. c.ServeSuccessJSON(map[string]interface{}{
  2468. "info": info,
  2469. "case_history": case_history,
  2470. })
  2471. }
  2472. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2473. template_name := c.GetString("template_name")
  2474. template_remark := c.GetString("template_remark")
  2475. doctor := c.GetAdminUserInfo().AdminUser.Id
  2476. diagnostic := c.GetString("diagnostic")
  2477. chief_conplaint := c.GetString("chief_conplain")
  2478. history_of_present_illness := c.GetString("history_of_present_illness")
  2479. past_history := c.GetString("past_history")
  2480. personal_history := c.GetString("personal_history")
  2481. family_history := c.GetString("family_history")
  2482. user_name := c.GetString("user_name")
  2483. doctor_advice := c.GetString("doctor_advice")
  2484. remark := c.GetString("remark")
  2485. //record_date := c.GetString("record_date")
  2486. //fmt.Println("record_date--------",record_date)
  2487. //timeLayout := "2006-01-02"
  2488. //loc, _ := time.LoadLocation("Local")
  2489. //
  2490. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2491. //if err != nil {
  2492. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2493. // return
  2494. //}
  2495. //recordDateTime := theTime.Unix()
  2496. ctime := time.Now().Unix()
  2497. template := models.HisCaseHistoryTemplate{
  2498. HistoryOfPresentIllness: history_of_present_illness,
  2499. PastHistory: past_history,
  2500. ChiefConplaint: chief_conplaint,
  2501. PersonalHistory: personal_history,
  2502. FamilyHistory: family_history,
  2503. Diagnostic: diagnostic,
  2504. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2505. Status: 1,
  2506. Ctime: ctime,
  2507. Mtime: ctime,
  2508. RecordDate: time.Now().Unix(),
  2509. TemplateName: template_name,
  2510. TemplateRemark: template_remark,
  2511. Creator: doctor,
  2512. Modifier: doctor,
  2513. UserName: user_name,
  2514. DoctorAdvice: doctor_advice,
  2515. Remark: remark,
  2516. }
  2517. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2518. if err == nil {
  2519. c.ServeSuccessJSON(map[string]interface{}{
  2520. "msg": "保存成功",
  2521. })
  2522. } else {
  2523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2524. return
  2525. }
  2526. }
  2527. func (c *HisApiController) GetCaseHistoryTemplate() {
  2528. timeLayout := "2006-01-02"
  2529. loc, _ := time.LoadLocation("Local")
  2530. keyword := c.GetString("keyword")
  2531. start_time := c.GetString("start_time")
  2532. end_time := c.GetString("end_time")
  2533. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2534. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2535. admin := c.GetAdminUserInfo()
  2536. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2537. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2538. c.ServeSuccessJSON(map[string]interface{}{
  2539. "template": template,
  2540. //"history": history,
  2541. })
  2542. }
  2543. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2544. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2545. utils.ErrorLog("drug_name")
  2546. return enums.ErrorCodeParamWrong
  2547. }
  2548. adviceName, _ := json["drug_name"].(string)
  2549. if len(adviceName) == 0 {
  2550. utils.ErrorLog("len(advice_name) == 0")
  2551. return enums.ErrorCodeParamWrong
  2552. }
  2553. advice.AdviceName = adviceName
  2554. adviceDesc, _ := json["advice_desc"].(string)
  2555. advice.AdviceDesc = adviceDesc
  2556. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2557. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2558. advice.DrugSpec = drugSpec
  2559. }
  2560. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2561. remark, _ := json["remark"].(string)
  2562. advice.Remark = remark
  2563. }
  2564. if json["id"] == nil {
  2565. advice.DrugId = 0
  2566. } else {
  2567. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2568. drug_id := int64(json["id"].(float64))
  2569. advice.DrugId = drug_id
  2570. }
  2571. }
  2572. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2573. advice_id := int64(json["advice_id"].(float64))
  2574. advice.ID = advice_id
  2575. if advice.ID > 0 {
  2576. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2577. if err == nil {
  2578. if hisAdvice.ID > 0 {
  2579. advice.ExecutionTime = hisAdvice.ExecutionTime
  2580. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2581. advice.ExecutionState = hisAdvice.ExecutionState
  2582. advice.CheckTime = hisAdvice.CheckTime
  2583. advice.Checker = hisAdvice.Checker
  2584. advice.CheckState = hisAdvice.CheckState
  2585. advice.StartTime = hisAdvice.StartTime
  2586. advice.FeedetlSn = hisAdvice.FeedetlSn
  2587. }
  2588. }
  2589. }
  2590. }
  2591. //
  2592. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2593. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2594. // advice.ExecutionTime = execution_time
  2595. //}
  2596. //
  2597. //
  2598. //
  2599. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2600. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2601. // advice.ExecutionStaff = execution_staff
  2602. //}
  2603. //
  2604. //
  2605. //
  2606. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2607. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2608. // advice.ExecutionState = execution_state
  2609. //}
  2610. //
  2611. //
  2612. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2613. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2614. // advice.CheckTime = check_time
  2615. //}
  2616. //
  2617. //
  2618. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2619. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2620. // advice.CheckState = check_state
  2621. //}
  2622. //
  2623. //
  2624. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2625. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2626. // advice.Checker = checker
  2627. //}
  2628. //
  2629. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2630. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2631. // advice.StartTime = start_time
  2632. //}
  2633. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2634. drugSpecUnit, _ := json["min_unit"].(string)
  2635. advice.DrugSpecUnit = drugSpecUnit
  2636. }
  2637. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2638. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2639. advice.SingleDose = singleDose
  2640. }
  2641. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2642. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2643. advice.SingleDoseUnit = singleDoseUnit
  2644. }
  2645. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2646. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2647. advice.PrescribingNumber = prescribingNumber
  2648. }
  2649. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2650. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2651. advice.PrescribingNumberUnit = prescribingNumberUnit
  2652. }
  2653. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2654. deliveryWay, _ := json["delivery_way"].(string)
  2655. advice.DeliveryWay = deliveryWay
  2656. }
  2657. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2658. executionFrequency, _ := json["execution_frequency"].(string)
  2659. advice.ExecutionFrequency = executionFrequency
  2660. }
  2661. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2662. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2663. advice.Price = price
  2664. }
  2665. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2666. med_list_codg, _ := json["medical_insurance_number"].(string)
  2667. advice.MedListCodg = med_list_codg
  2668. }
  2669. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2670. day := int64(json["day"].(float64))
  2671. advice.Day = day
  2672. }
  2673. return 0
  2674. }
  2675. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2676. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2677. id := int64(json["id"].(float64))
  2678. project.ID = id
  2679. historyProject, _ := service.GetHisProjectByID(id)
  2680. project.FeedetlSn = historyProject.FeedetlSn
  2681. }
  2682. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2683. project_id := int64(json["project_id"].(float64))
  2684. project.ProjectId = project_id
  2685. }
  2686. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2687. // price := int64(json["price"].(float64))
  2688. // formatInt_price := strconv.FormatInt(price, 10)
  2689. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2690. // project.Price = float_price
  2691. // }
  2692. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2693. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2694. project.Price = price
  2695. }
  2696. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2697. total, _ := json["total"].(string)
  2698. project.Count = total
  2699. }
  2700. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2701. medical_code, _ := json["medical_code"].(string)
  2702. project.MedListCodg = medical_code
  2703. }
  2704. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2705. single_dose, _ := json["single_dose"].(string)
  2706. project.SingleDose = single_dose
  2707. }
  2708. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2709. delivery_way, _ := json["delivery_way"].(string)
  2710. project.DeliveryWay = delivery_way
  2711. }
  2712. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2713. execution_frequency, _ := json["execution_frequency"].(string)
  2714. project.ExecutionFrequency = execution_frequency
  2715. }
  2716. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2717. remark, _ := json["remark"].(string)
  2718. project.Remark = remark
  2719. }
  2720. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2721. day, _ := json["number_days"].(string)
  2722. project.Day = day
  2723. }
  2724. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2725. unit, _ := json["unit"].(string)
  2726. project.Unit = unit
  2727. }
  2728. return 0
  2729. }
  2730. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2731. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2732. id := int64(json["id"].(float64))
  2733. historyAddtions, _ := service.GetHisAdditionByID(id)
  2734. additionalCharge.ID = id
  2735. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2736. }
  2737. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2738. item_id := int64(json["item_id"].(float64))
  2739. additionalCharge.ItemId = item_id
  2740. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2741. if config.ID > 0 {
  2742. if len(config.Code) > 0 {
  2743. additionalCharge.MedListCodg = config.Code
  2744. }
  2745. }
  2746. }
  2747. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2748. // price := int64(json["price"].(float64))
  2749. // formatInt_price := strconv.FormatInt(price, 10)
  2750. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2751. // additionalCharge.Price = float_price
  2752. // }
  2753. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2754. // price := int64(json["price"].(float64))
  2755. // formatInt_price := strconv.FormatInt(price, 10)
  2756. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2757. // additionalCharge.Price = float_price
  2758. //}
  2759. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2760. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2761. additionalCharge.Price = price
  2762. }
  2763. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2764. count, _ := json["count"].(string)
  2765. counts, _ := strconv.ParseInt(count, 10, 64)
  2766. additionalCharge.Count = counts
  2767. }
  2768. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2769. item_name, _ := json["item_name"].(string)
  2770. additionalCharge.ItemName = item_name
  2771. }
  2772. return 0
  2773. }
  2774. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2775. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2776. utils.ErrorLog("drug_name")
  2777. return enums.ErrorCodeParamWrong
  2778. }
  2779. adviceName, _ := json["drug_name"].(string)
  2780. if len(adviceName) == 0 {
  2781. utils.ErrorLog("len(advice_name) == 0")
  2782. return enums.ErrorCodeParamWrong
  2783. }
  2784. advice.AdviceName = adviceName
  2785. adviceDesc, _ := json["advice_desc"].(string)
  2786. advice.AdviceDesc = adviceDesc
  2787. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2788. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2789. advice.DrugSpec = drugSpec
  2790. }
  2791. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2792. remark, _ := json["remark"].(string)
  2793. advice.Remark = remark
  2794. }
  2795. if json["id"] == nil {
  2796. advice.DrugId = 0
  2797. } else {
  2798. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2799. drug_id := int64(json["id"].(float64))
  2800. advice.DrugId = drug_id
  2801. }
  2802. }
  2803. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  2804. groupno := int64(json["groupno"].(float64))
  2805. advice.Groupno = groupno
  2806. }
  2807. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  2808. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  2809. advice.HospApprFlag = hosp_appr_flag
  2810. }
  2811. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2812. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2813. advice.PrescribingNumber = prescribingNumber
  2814. }
  2815. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  2816. // frequency_type := int64(json["frequency_type"].(float64))
  2817. // advice.FrequencyType = frequency_type
  2818. //}
  2819. //
  2820. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  2821. // day_count := int64(json["day_count"].(float64))
  2822. // advice.DayCount = day_count
  2823. //}
  2824. //
  2825. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  2826. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  2827. // week_day, _ := json["week_day"].(string)
  2828. // advice.WeekDay = week_day
  2829. //}
  2830. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2831. drugSpecUnit, _ := json["min_unit"].(string)
  2832. advice.DrugSpecUnit = drugSpecUnit
  2833. }
  2834. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2835. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2836. advice.SingleDose = singleDose
  2837. }
  2838. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2839. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2840. advice.SingleDoseUnit = singleDoseUnit
  2841. }
  2842. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2843. deliveryWay, _ := json["delivery_way"].(string)
  2844. advice.DeliveryWay = deliveryWay
  2845. }
  2846. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2847. executionFrequency, _ := json["execution_frequency"].(string)
  2848. advice.ExecutionFrequency = executionFrequency
  2849. }
  2850. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2851. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2852. advice.Price = price
  2853. }
  2854. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2855. med_list_codg, _ := json["medical_insurance_number"].(string)
  2856. advice.MedListCodg = med_list_codg
  2857. }
  2858. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2859. day := int64(json["day"].(float64))
  2860. advice.Day = day
  2861. }
  2862. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2863. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2864. advice.PrescribingNumberUnit = prescribingNumberUnit
  2865. }
  2866. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2867. advice_id := int64(json["advice_id"].(float64))
  2868. advice.ID = advice_id
  2869. if advice.ID > 0 {
  2870. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2871. if err == nil {
  2872. if hisAdvice.ID > 0 {
  2873. advice.ExecutionTime = hisAdvice.ExecutionTime
  2874. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2875. advice.ExecutionState = hisAdvice.ExecutionState
  2876. advice.CheckTime = hisAdvice.CheckTime
  2877. advice.Checker = hisAdvice.Checker
  2878. advice.CheckState = hisAdvice.CheckState
  2879. advice.StartTime = hisAdvice.StartTime
  2880. advice.HospApprFlag = hisAdvice.HospApprFlag
  2881. if hisAdvice.UserOrgId == 10028 {
  2882. 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 {
  2883. advice.ExecutionTime = 0
  2884. advice.ExecutionStaff = 0
  2885. advice.ExecutionState = 2
  2886. advice.CheckTime = 0
  2887. advice.Checker = 0
  2888. advice.CheckState = 2
  2889. }
  2890. } else {
  2891. 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 {
  2892. advice.ExecutionTime = 0
  2893. advice.ExecutionStaff = 0
  2894. advice.ExecutionState = 2
  2895. advice.CheckTime = 0
  2896. advice.Checker = 0
  2897. advice.CheckState = 2
  2898. }
  2899. }
  2900. //advice.Groupno = hisAdvice.Groupno
  2901. }
  2902. }
  2903. }
  2904. }
  2905. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  2906. //
  2907. //if drugStockConfig.IsOpen == 1 {
  2908. //
  2909. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  2910. // if advice.ID == 0 { //医嘱不存在
  2911. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  2912. // drug.Total = drug.Total - advice.PrescribingNumber
  2913. // service.UpdateBaseDrugLib(&drug)
  2914. //
  2915. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  2916. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  2917. // drug.Total = drug.Total - num
  2918. // service.UpdateBaseDrugLib(&drug)
  2919. // }
  2920. //
  2921. // } else if advice.ID > 0 { //医嘱存在
  2922. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  2923. // var num float64
  2924. //
  2925. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  2926. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  2927. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  2928. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  2929. // drug.Total = drug.Total + num
  2930. // service.UpdateBaseDrugLib(&drug)
  2931. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  2932. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  2933. // drug.Total = drug.Total - num
  2934. // service.UpdateBaseDrugLib(&drug)
  2935. // }
  2936. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  2937. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2938. // if num2 > advice.PrescribingNumber {
  2939. // num = num2 - advice.PrescribingNumber
  2940. // drug.Total = drug.Total + num
  2941. // service.UpdateBaseDrugLib(&drug)
  2942. // } else if num2 < advice.PrescribingNumber {
  2943. // num = advice.PrescribingNumber - num2
  2944. // drug.Total = drug.Total - num
  2945. // service.UpdateBaseDrugLib(&drug)
  2946. // }
  2947. //
  2948. // }
  2949. //
  2950. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  2951. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  2952. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2953. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2954. // if num1 > num2 {
  2955. // num = num1 - num2
  2956. // drug.Total = drug.Total + num
  2957. // service.UpdateBaseDrugLib(&drug)
  2958. // } else if num1 < num2 {
  2959. // num = num2 - num1
  2960. // drug.Total = drug.Total - num
  2961. // service.UpdateBaseDrugLib(&drug)
  2962. // }
  2963. //
  2964. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  2965. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2966. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  2967. // if hisAdvice.PrescribingNumber > num2 {
  2968. // num = hisAdvice.PrescribingNumber - num2
  2969. // drug.Total = drug.Total + num
  2970. // service.UpdateBaseDrugLib(&drug)
  2971. // } else if num2 < advice.PrescribingNumber {
  2972. // num = num2 - hisAdvice.PrescribingNumber
  2973. // drug.Total = drug.Total - num
  2974. // service.UpdateBaseDrugLib(&drug)
  2975. // }
  2976. //
  2977. // }
  2978. // }
  2979. // }
  2980. //}
  2981. //
  2982. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2983. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2984. // advice.ExecutionTime = execution_time
  2985. //}
  2986. //
  2987. //
  2988. //
  2989. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2990. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2991. // advice.ExecutionStaff = execution_staff
  2992. //}
  2993. //
  2994. //
  2995. //
  2996. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2997. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2998. // advice.ExecutionState = execution_state
  2999. //}
  3000. //
  3001. //
  3002. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3003. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3004. // advice.CheckTime = check_time
  3005. //}
  3006. //
  3007. //
  3008. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3009. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3010. // advice.CheckState = check_state
  3011. //}
  3012. //
  3013. //
  3014. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3015. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3016. // advice.Checker = checker
  3017. //}
  3018. //
  3019. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3020. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3021. // advice.StartTime = start_time
  3022. //}
  3023. return 0
  3024. }
  3025. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3026. project.ExecutionStaff = 0
  3027. project.ExecutionState = 2
  3028. project.ExecutionTime = 0
  3029. project.Checker = 0
  3030. project.CheckState = 2
  3031. project.CheckTime = 0
  3032. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3033. id := int64(json["id"].(float64))
  3034. project.ID = id
  3035. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3036. project.ExecutionStaff = temp_project.ExecutionStaff
  3037. project.ExecutionState = temp_project.ExecutionState
  3038. project.ExecutionTime = temp_project.ExecutionTime
  3039. project.Checker = temp_project.Checker
  3040. project.CheckState = temp_project.CheckState
  3041. project.CheckTime = temp_project.CheckTime
  3042. project.TeamId = temp_project.TeamId
  3043. }
  3044. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3045. types := int64(json["type"].(float64))
  3046. project.Type = types
  3047. }
  3048. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3049. project_id := int64(json["project_id"].(float64))
  3050. project.ProjectId = project_id
  3051. fmt.Println(project_id)
  3052. fmt.Println(project.ProjectId)
  3053. }
  3054. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3055. team_id := int64(json["team_id"].(float64))
  3056. project.TeamId = team_id
  3057. }
  3058. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3059. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3060. project.Price = price
  3061. }
  3062. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3063. total, _ := json["total"].(string)
  3064. //totals, _ := strconv.ParseInt(total, 10, 64)
  3065. project.Count = total
  3066. }
  3067. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3068. medical_code, _ := json["medical_code"].(string)
  3069. project.MedListCodg = medical_code
  3070. }
  3071. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3072. single_dose, _ := json["single_dose"].(string)
  3073. project.SingleDose = single_dose
  3074. }
  3075. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3076. delivery_way, _ := json["delivery_way"].(string)
  3077. project.DeliveryWay = delivery_way
  3078. }
  3079. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3080. execution_frequency, _ := json["execution_frequency"].(string)
  3081. project.ExecutionFrequency = execution_frequency
  3082. }
  3083. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3084. remark, _ := json["remark"].(string)
  3085. project.Remark = remark
  3086. }
  3087. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3088. day, _ := json["number_days"].(string)
  3089. project.Day = day
  3090. }
  3091. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3092. unit, _ := json["unit"].(string)
  3093. project.Unit = unit
  3094. }
  3095. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3096. // frequency_type := int64(json["frequency_type"].(float64))
  3097. // project.FrequencyType = frequency_type
  3098. //}
  3099. //
  3100. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3101. // day_count := int64(json["day_count"].(float64))
  3102. // project.DayCount = day_count
  3103. //}
  3104. //
  3105. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3106. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3107. // week_day, _ := json["week_day"].(string)
  3108. // project.WeekDay = week_day
  3109. //}
  3110. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3111. //
  3112. //if project.ID == 0 {
  3113. // if stockConfig.IsOpen == 1 {
  3114. // if project.Type == 3 {
  3115. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3116. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3117. // good.Total = good.Total - f_count
  3118. // service.UpdateGoodInfo(&good)
  3119. // }
  3120. // }
  3121. //
  3122. //} else {
  3123. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3124. //
  3125. // if stockConfig.IsOpen == 1 {
  3126. // if project.Type == 3 {
  3127. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3128. // if project.Count < temp_project.Count {
  3129. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3130. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3131. //
  3132. // other_count := f_count_two - f_count_one
  3133. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3134. // good.Total = good.Total + other_count_two
  3135. // service.UpdateGoodInfo(&good)
  3136. // } else if project.Count > temp_project.Count {
  3137. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3138. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3139. //
  3140. // other_count := f_count_one - f_count_two
  3141. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3142. // good.Total = good.Total - other_count_two
  3143. // service.UpdateGoodInfo(&good)
  3144. // }
  3145. //
  3146. // }
  3147. // }
  3148. //
  3149. //}
  3150. return 0
  3151. }
  3152. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3153. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3154. id := int64(json["id"].(float64))
  3155. additionalCharge.ID = id
  3156. }
  3157. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3158. item_id := int64(json["item_id"].(float64))
  3159. additionalCharge.ItemId = item_id
  3160. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3161. if config.ID > 0 {
  3162. if len(config.Code) > 0 {
  3163. additionalCharge.MedListCodg = config.Code
  3164. }
  3165. }
  3166. }
  3167. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3168. // price := int64(json["price"].(float64))
  3169. // formatInt_price := strconv.FormatInt(price, 10)
  3170. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3171. // additionalCharge.Price = float_price
  3172. // }
  3173. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3174. // price := int64(json["price"].(float64))
  3175. // formatInt_price := strconv.FormatInt(price, 10)
  3176. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3177. // additionalCharge.Price = float_price
  3178. //}
  3179. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3180. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3181. additionalCharge.Price = price
  3182. }
  3183. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3184. count, _ := json["count"].(string)
  3185. counts, _ := strconv.ParseInt(count, 10, 64)
  3186. additionalCharge.Count = counts
  3187. }
  3188. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3189. item_name, _ := json["item_name"].(string)
  3190. additionalCharge.ItemName = item_name
  3191. }
  3192. return 0
  3193. }
  3194. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3195. fmt.Println("~~~~~~")
  3196. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3197. utils.ErrorLog("drug_name")
  3198. return enums.ErrorCodeParamWrong
  3199. }
  3200. adviceName, _ := json["drug_name"].(string)
  3201. if len(adviceName) == 0 {
  3202. utils.ErrorLog("len(advice_name) == 0")
  3203. return enums.ErrorCodeParamWrong
  3204. }
  3205. advice.AdviceName = adviceName
  3206. adviceDesc, _ := json["advice_desc"].(string)
  3207. advice.AdviceDesc = adviceDesc
  3208. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3209. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3210. advice.DrugSpec = drugSpec
  3211. }
  3212. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3213. remark, _ := json["remark"].(string)
  3214. advice.Remark = remark
  3215. }
  3216. if json["id"] == nil {
  3217. advice.DrugId = 0
  3218. } else {
  3219. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3220. drug_id := int64(json["id"].(float64))
  3221. advice.DrugId = drug_id
  3222. }
  3223. }
  3224. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3225. drugSpecUnit, _ := json["min_unit"].(string)
  3226. advice.DrugSpecUnit = drugSpecUnit
  3227. }
  3228. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3229. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3230. advice.SingleDose = singleDose
  3231. }
  3232. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3233. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3234. advice.SingleDoseUnit = singleDoseUnit
  3235. }
  3236. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3237. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3238. advice.PrescribingNumber = prescribingNumber
  3239. }
  3240. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3241. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3242. advice.PrescribingNumberUnit = prescribingNumberUnit
  3243. }
  3244. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3245. deliveryWay, _ := json["delivery_way"].(string)
  3246. advice.DeliveryWay = deliveryWay
  3247. }
  3248. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3249. executionFrequency, _ := json["execution_frequency"].(string)
  3250. advice.ExecutionFrequency = executionFrequency
  3251. }
  3252. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3253. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3254. advice.Price = price
  3255. }
  3256. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3257. med_list_codg, _ := json["medical_insurance_number"].(string)
  3258. advice.MedListCodg = med_list_codg
  3259. }
  3260. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3261. day := int64(json["day"].(float64))
  3262. advice.Day = day
  3263. }
  3264. return 0
  3265. }
  3266. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3267. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3268. types := int64(json["type"].(float64))
  3269. project.Type = types
  3270. }
  3271. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3272. project_id := int64(json["project_id"].(float64))
  3273. project.ProjectId = project_id
  3274. }
  3275. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3276. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3277. project.Price = price
  3278. }
  3279. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3280. total, _ := json["total"].(string)
  3281. //totals, _ := strconv.ParseInt(total, 10, 64)
  3282. project.Count = total
  3283. }
  3284. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3285. medical_code, _ := json["medical_code"].(string)
  3286. project.MedListCodg = medical_code
  3287. }
  3288. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3289. single_dose, _ := json["single_dose"].(string)
  3290. project.SingleDose = single_dose
  3291. }
  3292. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3293. delivery_way, _ := json["delivery_way"].(string)
  3294. project.DeliveryWay = delivery_way
  3295. }
  3296. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3297. execution_frequency, _ := json["execution_frequency"].(string)
  3298. project.ExecutionFrequency = execution_frequency
  3299. }
  3300. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3301. remark, _ := json["remark"].(string)
  3302. project.Remark = remark
  3303. }
  3304. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3305. day, _ := json["number_days"].(string)
  3306. project.Day = day
  3307. }
  3308. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3309. unit, _ := json["unit"].(string)
  3310. project.Unit = unit
  3311. }
  3312. return 0
  3313. }
  3314. func (c *HisApiController) GetHisOrderList() {
  3315. page, _ := c.GetInt64("page", -1)
  3316. limit, _ := c.GetInt64("limit", -1)
  3317. start_time := c.GetString("start_time")
  3318. end_time := c.GetString("end_time")
  3319. types, _ := c.GetInt64("type", 0)
  3320. keywords := c.GetString("keywords")
  3321. p_type, _ := c.GetInt64("p_type", 0)
  3322. timeLayout := "2006-01-02"
  3323. loc, _ := time.LoadLocation("Local")
  3324. var startTime int64
  3325. if len(start_time) > 0 {
  3326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3327. if err != nil {
  3328. fmt.Println(err)
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3330. return
  3331. }
  3332. startTime = theTime.Unix()
  3333. }
  3334. var endTime int64
  3335. if len(end_time) > 0 {
  3336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3337. if err != nil {
  3338. utils.ErrorLog(err.Error())
  3339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3340. return
  3341. }
  3342. endTime = theTime.Unix()
  3343. }
  3344. adminUser := c.GetAdminUserInfo()
  3345. org_id := adminUser.CurrentOrgId
  3346. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  3347. for _, item := range order {
  3348. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3349. item.DoctorName = info.Doctor
  3350. item.DepartmentName = info.XtHisDepartment.Name
  3351. }
  3352. if err == nil {
  3353. c.ServeSuccessJSON(map[string]interface{}{
  3354. "order": order,
  3355. "total": total,
  3356. })
  3357. } else {
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3359. return
  3360. }
  3361. }
  3362. func (c *HisApiController) GetHisOrder() {
  3363. patient_id, _ := c.GetInt64("patient_id", 0)
  3364. number := c.GetString("number")
  3365. adminInfo := c.GetAdminUserInfo()
  3366. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3367. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3368. if err == nil {
  3369. c.ServeSuccessJSON(map[string]interface{}{
  3370. "order": order,
  3371. "prescription": prescriptions,
  3372. })
  3373. } else {
  3374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3375. return
  3376. }
  3377. }
  3378. func (c *HisApiController) GetHisPrescriptionList() {
  3379. record_date := c.GetString("record_date")
  3380. keywords := c.GetString("keywords")
  3381. page, _ := c.GetInt64("page")
  3382. limit, _ := c.GetInt64("limit")
  3383. timeLayout := "2006-01-02"
  3384. loc, _ := time.LoadLocation("Local")
  3385. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3386. if err != nil {
  3387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3388. return
  3389. }
  3390. recordDateTime := theTime.Unix()
  3391. adminInfo := c.GetAdminUserInfo()
  3392. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3393. //adminInfo := c.GetAdminUserInfo()
  3394. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3395. //fmt.Println(prescriptionOrder)
  3396. if err == nil {
  3397. c.ServeSuccessJSON(map[string]interface{}{
  3398. "order": prescriptionOrder,
  3399. "total": total,
  3400. })
  3401. } else {
  3402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3403. return
  3404. }
  3405. }
  3406. func (c *HisApiController) GetHisPrescriptionInfo() {
  3407. id, _ := c.GetInt64("id")
  3408. adminInfo := c.GetAdminUserInfo()
  3409. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3410. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3411. if err == nil {
  3412. c.ServeSuccessJSON(map[string]interface{}{
  3413. "order": prescriptionOrder,
  3414. "prescription": prescription,
  3415. })
  3416. } else {
  3417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3418. return
  3419. }
  3420. }
  3421. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3422. adminUser := c.GetAdminUserInfo()
  3423. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3424. c.ServeSuccessJSON(map[string]interface{}{
  3425. "config": config,
  3426. })
  3427. }
  3428. type ResultTwo struct {
  3429. ErrMsg interface{} `json:"err_msg"`
  3430. InfRefmsgid string `json:"inf_refmsgid"`
  3431. Infcode int64 `json:"infcode"`
  3432. Output struct {
  3433. Baseinfo struct {
  3434. Age float64 `json:"age"`
  3435. Brdy string `json:"brdy"`
  3436. Certno string `json:"certno"`
  3437. Gend string `json:"gend"`
  3438. Naty string `json:"naty"`
  3439. PsnCertType string `json:"psn_cert_type"`
  3440. PsnName string `json:"psn_name"`
  3441. PsnNo string `json:"psn_no"`
  3442. } `json:"baseinfo"`
  3443. Idetinfo []interface{} `json:"idetinfo"`
  3444. Iinfo []struct {
  3445. Balc float64 `json:"balc"`
  3446. CvlservFlag string `json:"cvlserv_flag"`
  3447. EmpName string `json:"emp_name"`
  3448. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3449. Insutype string `json:"insutype"`
  3450. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3451. PausInsuDate interface{} `json:"paus_insu_date"`
  3452. PsnInsuDate string `json:"psn_insu_date"`
  3453. PsnInsuStas string `json:"psn_insu_stas"`
  3454. PsnType string `json:"psn_type"`
  3455. } `json:"insuinfo"`
  3456. } `json:"output"`
  3457. RefmsgTime string `json:"refmsg_time"`
  3458. RespondTime string `json:"respond_time"`
  3459. Signtype interface{} `json:"signtype"`
  3460. WarnInfo interface{} `json:"warn_info"`
  3461. }
  3462. type ResultThree struct {
  3463. Cainfo interface{} `json:"cainfo"`
  3464. ErrMsg interface{} `json:"err_msg"`
  3465. InfRefmsgid string `json:"inf_refmsgid"`
  3466. Infcode int64 `json:"infcode"`
  3467. Output struct {
  3468. Data struct {
  3469. IptOtpNo string `json:"ipt_otp_no"`
  3470. MdtrtID string `json:"mdtrt_id"`
  3471. PsnNo string `json:"psn_no"`
  3472. } `json:"data"`
  3473. } `json:"output"`
  3474. RefmsgTime string `json:"refmsg_time"`
  3475. RespondTime string `json:"respond_time"`
  3476. Signtype interface{} `json:"signtype"`
  3477. WarnMsg interface{} `json:"warn_msg"`
  3478. }
  3479. type ResultFour struct {
  3480. Cainfo string `json:"cainfo"`
  3481. ErrMsg string `json:"err_msg"`
  3482. InfRefmsgid string `json:"inf_refmsgid"`
  3483. Infcode int64 `json:"infcode"`
  3484. Output struct {
  3485. Result []struct {
  3486. BasMednFlag string `json:"bas_medn_flag"`
  3487. ChldMedcFlag string `json:"chld_medc_flag"`
  3488. ChrgitmLv string `json:"chrgitm_lv"`
  3489. Cnt float64 `json:"cnt"`
  3490. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3491. DrtReimFlag string `json:"drt_reim_flag"`
  3492. FeedetlSn string `json:"feedetl_sn"`
  3493. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3494. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3495. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3496. ListSpItemFlag string `json:"list_sp_item_flag"`
  3497. LmtUsedFlag string `json:"lmt_used_flag"`
  3498. MedChrgitmType string `json:"med_chrgitm_type"`
  3499. Memo string `json:"memo"`
  3500. OverlmtAmt float64 `json:"overlmt_amt"`
  3501. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3502. Pric float64 `json:"pric"`
  3503. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3504. SelfpayProp float64 `json:"selfpay_prop"`
  3505. } `json:"result"`
  3506. } `json:"output"`
  3507. RefmsgTime string `json:"refmsg_time"`
  3508. RespondTime string `json:"respond_time"`
  3509. Signtype string `json:"signtype"`
  3510. WarnMsg string `json:"warn_msg"`
  3511. }
  3512. type ResultFive struct {
  3513. Insutype string `json:"insutype"`
  3514. }
  3515. type ResultSix struct {
  3516. Cainfo interface{} `json:"cainfo"`
  3517. ErrMsg interface{} `json:"err_msg"`
  3518. InfRefmsgid string `json:"inf_refmsgid"`
  3519. Infcode int64 `json:"infcode"`
  3520. Output struct {
  3521. } `json:"output"`
  3522. RefmsgTime string `json:"refmsg_time"`
  3523. RespondTime string `json:"respond_time"`
  3524. Signtype interface{} `json:"signtype"`
  3525. WarnMsg interface{} `json:"warn_msg"`
  3526. }
  3527. type ResultSeven struct {
  3528. Cainfo string `json:"cainfo"`
  3529. ErrMsg string `json:"err_msg"`
  3530. InfRefmsgid string `json:"inf_refmsgid"`
  3531. Infcode int64 `json:"infcode"`
  3532. Output struct {
  3533. Setldetail []interface{} `json:"setldetail"`
  3534. Setlinfo struct {
  3535. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3536. AcctPay float64 `json:"acct_pay"`
  3537. ActPayDedc float64 `json:"act_pay_dedc"`
  3538. Age float64 `json:"age"`
  3539. Balc float64 `json:"balc"`
  3540. Brdy string `json:"brdy"`
  3541. Certno string `json:"certno"`
  3542. ClrOptins string `json:"clr_optins"`
  3543. ClrType string `json:"clr_type"`
  3544. ClrWay string `json:"clr_way"`
  3545. CvlservFlag string `json:"cvlserv_flag"`
  3546. CvlservPay float64 `json:"cvlserv_pay"`
  3547. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3548. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3549. Gend string `json:"gend"`
  3550. HifesPay float64 `json:"hifes_pay"`
  3551. HifmiPay float64 `json:"hifmi_pay"`
  3552. HifobPay float64 `json:"hifob_pay"`
  3553. HifpPay float64 `json:"hifp_pay"`
  3554. HospPartAmt float64 `json:"hosp_part_amt"`
  3555. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3556. Insutype string `json:"insutype"`
  3557. MafPay float64 `json:"maf_pay"`
  3558. MdtrtCertType string `json:"mdtrt_cert_type"`
  3559. MdtrtID string `json:"mdtrt_id"`
  3560. MedType string `json:"med_type"`
  3561. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3562. MedinsSetlID string `json:"medins_setl_id"`
  3563. Naty string `json:"naty"`
  3564. OthPay float64 `json:"oth_pay"`
  3565. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3566. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3567. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3568. PsnCashPay float64 `json:"psn_cash_pay"`
  3569. PsnCertType string `json:"psn_cert_type"`
  3570. PsnName string `json:"psn_name"`
  3571. PsnNo string `json:"psn_no"`
  3572. PsnPartAmt float64 `json:"psn_part_amt"`
  3573. PsnType string `json:"psn_type"`
  3574. SetlID string `json:"setl_id"`
  3575. SetlTime string `json:"setl_time"`
  3576. } `json:"setlinfo"`
  3577. } `json:"output"`
  3578. RefmsgTime string `json:"refmsg_time"`
  3579. RespondTime string `json:"respond_time"`
  3580. Signtype interface{} `json:"signtype"`
  3581. WarnMsg interface{} `json:"warn_msg"`
  3582. }
  3583. type ResultEight struct {
  3584. Cainfo string `json:"cainfo"`
  3585. ErrMsg string `json:"err_msg"`
  3586. InfRefmsgid string `json:"inf_refmsgid"`
  3587. Infcode int64 `json:"infcode"`
  3588. Output struct {
  3589. Stmtinfo struct {
  3590. SetlOptins string `json:"setl_optins"`
  3591. StmtRslt string `json:"stmt_rslt"`
  3592. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3593. } `json:"stmtinfo"`
  3594. } `json:"output"`
  3595. RefmsgTime string `json:"refmsg_time"`
  3596. RespondTime string `json:"respond_time"`
  3597. Signtype interface{} `json:"signtype"`
  3598. WarnMsg interface{} `json:"warn_msg"`
  3599. }
  3600. type ResultNine struct {
  3601. Cainfo string `json:"cainfo"`
  3602. ErrMsg string `json:"err_msg"`
  3603. InfRefmsgid string `json:"inf_refmsgid"`
  3604. Infcode int64 `json:"infcode"`
  3605. Output struct {
  3606. FileQuryNo string `json:"file_qury_no"`
  3607. } `json:"output"`
  3608. RefmsgTime string `json:"refmsg_time"`
  3609. RespondTime string `json:"respond_time"`
  3610. Signtype interface{} `json:"signtype"`
  3611. WarnMsg interface{} `json:"warn_msg"`
  3612. }
  3613. type ResultTen struct {
  3614. Cainfo string `json:"cainfo"`
  3615. ErrMsg string `json:"err_msg"`
  3616. InfRefmsgid string `json:"inf_refmsgid"`
  3617. Infcode int64 `json:"infcode"`
  3618. Output struct {
  3619. DldEndtime string `json:"dld_endtime"`
  3620. FileQuryNo string `json:"file_qury_no"`
  3621. Filename string `json:"filename"`
  3622. } `json:"output"`
  3623. RefmsgTime string `json:"refmsg_time"`
  3624. RespondTime string `json:"respond_time"`
  3625. Signtype interface{} `json:"signtype"`
  3626. WarnMsg interface{} `json:"warn_msg"`
  3627. }
  3628. type ResultEleven struct {
  3629. Cainfo string `json:"cainfo"`
  3630. ErrMsg string `json:"err_msg"`
  3631. InfRefmsgid string `json:"inf_refmsgid"`
  3632. Infcode int64 `json:"infcode"`
  3633. Output struct {
  3634. Setlinfo struct {
  3635. FixmedinsName string `json:"fixmedins_name"`
  3636. FixmedinsCode string `json:"fixmedins_code"`
  3637. PsnNo string `json:"psn_no"`
  3638. PsnName string `json:"psn_name"`
  3639. HifobPay float64 `json:"hifob_pay"`
  3640. Gend string `json:"gend"`
  3641. Brdy string `json:"brdy"`
  3642. PsnCertType string `json:"psn_cert_type"`
  3643. PsnType string `json:"psn_type"`
  3644. EmpName string `json:"emp_name"`
  3645. Certno string `json:"certno"`
  3646. Insutype string `json:"insutype"`
  3647. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3648. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3649. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3650. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3651. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3652. ActPayDedc float64 `json:"act_pay_dedc"`
  3653. HifpPay float64 `json:"hifp_pay"`
  3654. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3655. CvlservPay float64 `json:"cvlserv_pay"`
  3656. HifesPay float64 `json:"hifes_pay"`
  3657. HifmiPay float64 `json:"hifmi_pay"`
  3658. MafPay float64 `json:"maf_pay"`
  3659. OthPay float64 `json:"oth_pay"`
  3660. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3661. PsnPay float64 `json:"psn_pay"`
  3662. AcctPay float64 `json:"acct_pay"`
  3663. CashPayamt float64 `json:"cash_payamt"`
  3664. Balc float64 `json:"balc"`
  3665. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3666. MedinsSetlId string `json:"medins_setl_id"`
  3667. RefdSetlFlag string `json:"refd_setl_flag"`
  3668. SetlTime string `json:"setl_time"`
  3669. MedType string `json:"med_type"`
  3670. } `json:"setlinfo"`
  3671. } `json:"output"`
  3672. RefmsgTime string `json:"refmsg_time"`
  3673. RespondTime string `json:"respond_time"`
  3674. Signtype interface{} `json:"signtype"`
  3675. WarnMsg interface{} `json:"warn_msg"`
  3676. }
  3677. type Custom struct {
  3678. DetItemFeeSumamt string
  3679. Cut string
  3680. FeedetlSn string
  3681. Price string
  3682. MedListCodg string
  3683. Type int64
  3684. AdviceId int64
  3685. ProjectId int64
  3686. ItemId int64
  3687. }
  3688. //获取个人信息----挂号-----上传就诊信息
  3689. func (c *HisApiController) GetRegisterInfo() {
  3690. id, _ := c.GetInt64("id")
  3691. record_time := c.GetString("record_time")
  3692. settlementValue, _ := c.GetInt64("settlement_value")
  3693. medical_insurance_card := c.GetString("medical_insurance_card")
  3694. name := c.GetString("name")
  3695. id_card_type, _ := c.GetInt64("id_card_type")
  3696. certificates, _ := c.GetInt64("certificates")
  3697. medical_care, _ := c.GetInt64("medical_care")
  3698. birthday := c.GetString("birthday")
  3699. age, _ := c.GetInt64("age")
  3700. id_card := c.GetString("id_card")
  3701. register_type, _ := c.GetInt64("register")
  3702. doctor, _ := c.GetInt64("doctor")
  3703. department, _ := c.GetInt64("department")
  3704. gender, _ := c.GetInt64("sex")
  3705. phone := c.GetString("phone")
  3706. registration_fee, _ := c.GetFloat("registration_fee")
  3707. medical_expenses, _ := c.GetFloat("medical_expenses")
  3708. social_type, _ := c.GetInt64("social_type")
  3709. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3710. diagnosis_ids := c.GetString("diagnosis")
  3711. sick_type, _ := c.GetInt64("sick_type")
  3712. reg_type := c.GetString("p_type")
  3713. timeLayout := "2006-01-02"
  3714. loc, _ := time.LoadLocation("Local")
  3715. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3716. birthUnix := birthdays.Unix()
  3717. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3718. if err != nil {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3720. return
  3721. }
  3722. recordDateTime := theTime.Unix()
  3723. adminInfo := c.GetAdminUserInfo()
  3724. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3725. if tempPatient.ID == 0 {
  3726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3727. return
  3728. }
  3729. var patient service.Patients
  3730. if id == 0 {
  3731. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3732. } else {
  3733. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3734. }
  3735. if patient.ID == 0 {
  3736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3737. return
  3738. }
  3739. if len(patient.IdCardNo) == 0 {
  3740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3741. return
  3742. }
  3743. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3744. if len(his) >= 1 {
  3745. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3746. if len(his) >= 1 && order.ID == 0 {
  3747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3748. return
  3749. }
  3750. }
  3751. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3752. fmt.Println(timeStr)
  3753. timeArr := strings.Split(timeStr, " ")
  3754. fmt.Println(timeArr)
  3755. timeArrTwo := strings.Split(timeArr[0], "-")
  3756. timeArrThree := strings.Split(timeArr[1], ":")
  3757. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3758. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3759. if len(lists) == 0 {
  3760. var hisPatient models.XtHisPatient
  3761. hisPatient = models.XtHisPatient{
  3762. Name: name,
  3763. Age: age,
  3764. Gender: gender,
  3765. Birthday: birthUnix,
  3766. Phone: phone,
  3767. MedicalTreatmentType: medical_care,
  3768. IdType: certificates,
  3769. IdCardNo: id_card,
  3770. BalanceAccountsType: settlementValue,
  3771. SocialType: social_type,
  3772. MedicalInsuranceNumber: medical_insurance_card,
  3773. RegisterType: register_type,
  3774. RegisterCost: registration_fee,
  3775. TreatmentCost: medical_expenses,
  3776. AdminUserId: adminInfo.AdminUser.Id,
  3777. UserOrgId: adminInfo.CurrentOrgId,
  3778. Status: 1,
  3779. RecordDate: recordDateTime,
  3780. IsReturn: 1,
  3781. PatientId: patient.ID,
  3782. Ctime: time.Now().Unix(),
  3783. Mtime: time.Now().Unix(),
  3784. Number: str,
  3785. IdCardType: id_card_type,
  3786. Departments: department,
  3787. Doctor: doctor,
  3788. PType: reg_type,
  3789. Diagnosis: diagnosis_ids,
  3790. SickType: sick_type,
  3791. }
  3792. service.CreateHisPatient(&hisPatient)
  3793. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3794. c.ServeSuccessJSON(map[string]interface{}{
  3795. "his_info": hisPatient,
  3796. })
  3797. } else {
  3798. //chrgBchno := rand.Intn(1000000) + 10000
  3799. var hisPatient models.XtHisPatient
  3800. hisPatient = models.XtHisPatient{
  3801. Name: name,
  3802. Age: age,
  3803. Gender: gender,
  3804. Birthday: birthUnix,
  3805. Phone: phone,
  3806. MedicalTreatmentType: medical_care,
  3807. IdType: certificates,
  3808. IdCardNo: id_card,
  3809. BalanceAccountsType: settlementValue,
  3810. SocialType: social_type,
  3811. MedicalInsuranceNumber: medical_insurance_card,
  3812. RegisterType: register_type,
  3813. RegisterCost: registration_fee,
  3814. TreatmentCost: medical_expenses,
  3815. AdminUserId: adminInfo.AdminUser.Id,
  3816. UserOrgId: adminInfo.CurrentOrgId,
  3817. Status: 1,
  3818. RecordDate: recordDateTime,
  3819. IsReturn: 1,
  3820. PatientId: patient.ID,
  3821. Ctime: time.Now().Unix(),
  3822. Mtime: time.Now().Unix(),
  3823. Number: str,
  3824. IdCardType: id_card_type,
  3825. Departments: department,
  3826. Doctor: doctor,
  3827. PType: reg_type,
  3828. Diagnosis: diagnosis_ids,
  3829. SickType: sick_type,
  3830. }
  3831. service.CreateHisPatient(&hisPatient)
  3832. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3833. c.ServeSuccessJSON(map[string]interface{}{
  3834. "his_info": hisPatient,
  3835. })
  3836. }
  3837. }
  3838. //上传明细----结算
  3839. func (c *HisApiController) GetUploadInfo() {
  3840. id, _ := c.GetInt64("id")
  3841. record_time := c.GetString("record_time")
  3842. his_patient_id, _ := c.GetInt64("his_patient_id")
  3843. pay_way, _ := c.GetInt64("pay_way")
  3844. pay_price, _ := c.GetFloat("pay_price")
  3845. pay_card_no := c.GetString("pay_card_no")
  3846. discount_price, _ := c.GetFloat("discount_price")
  3847. preferential_price, _ := c.GetFloat("preferential_price")
  3848. reality_price, _ := c.GetFloat("reality_price")
  3849. found_price, _ := c.GetFloat("found_price")
  3850. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3851. private_price, _ := c.GetFloat("private_price")
  3852. timeLayout := "2006-01-02"
  3853. loc, _ := time.LoadLocation("Local")
  3854. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3855. fapiao_code := c.GetString("fapiao_code")
  3856. fapiao_number := c.GetString("fapiao_number")
  3857. diagnosis_id := c.GetString("diagnosis")
  3858. sick_type, _ := c.GetInt64("sick_type")
  3859. reg_type, _ := c.GetInt64("p_type")
  3860. order_id, _ := c.GetInt64("order_id")
  3861. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  3862. tempOrder, _ := service.GetHisOrderByID(order_id)
  3863. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3864. if err != nil {
  3865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3866. return
  3867. }
  3868. recordDateTime := theTime.Unix()
  3869. adminUser := c.GetAdminUserInfo()
  3870. var prescriptions []*models.HisPrescription
  3871. var start_time int64
  3872. var end_time int64
  3873. ids_str := c.GetString("ids")
  3874. ids_arr := strings.Split(ids_str, ",")
  3875. if tempOrder.ID == 0 {
  3876. if settle_accounts_type == 1 { //日结
  3877. fmt.Println(reg_type)
  3878. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  3879. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3880. } else {
  3881. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  3882. }
  3883. } else { //月结
  3884. start_time_str := c.GetString("start_time")
  3885. end_time_str := c.GetString("end_time")
  3886. timeLayout := "2006-01-02"
  3887. loc, _ := time.LoadLocation("Local")
  3888. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3889. if err != nil {
  3890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3891. return
  3892. }
  3893. recordStartTime := theStartTime.Unix()
  3894. start_time = recordStartTime
  3895. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3896. if err != nil {
  3897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3898. return
  3899. }
  3900. recordEndTime := theEndTime.Unix()
  3901. end_time = recordEndTime
  3902. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3903. }
  3904. timestamp := time.Now().Unix()
  3905. tempTime := time.Unix(timestamp, 0)
  3906. timeFormat := tempTime.Format("20060102150405")
  3907. chrgBchno := rand.Intn(100000) + 10000
  3908. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3909. strconv.FormatInt(his.PatientId, 10)
  3910. var ids []int64
  3911. fmt.Println(prescriptions)
  3912. for _, item := range prescriptions {
  3913. ids = append(ids, item.ID)
  3914. }
  3915. var total float64
  3916. fmt.Println(prescriptions)
  3917. for _, item := range prescriptions {
  3918. fmt.Println(item)
  3919. if item.Type == 1 { //药品
  3920. for _, subItem := range item.HisDoctorAdviceInfo {
  3921. total = total + (subItem.Price * subItem.PrescribingNumber)
  3922. }
  3923. }
  3924. if item.Type == 2 { //项目
  3925. for _, subItem := range item.HisPrescriptionProject {
  3926. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3927. total = total + (subItem.Price * cnt)
  3928. }
  3929. }
  3930. for _, subItem := range item.HisAdditionalCharge {
  3931. total = total + (subItem.Price * float64(subItem.Count))
  3932. }
  3933. }
  3934. if reg_type == 1111 || reg_type == 1112 {
  3935. reg_type = 11
  3936. }
  3937. allTotal := fmt.Sprintf("%.4f", total)
  3938. totals, _ := strconv.ParseFloat(allTotal, 64)
  3939. order := &models.HisOrder{
  3940. UserOrgId: adminUser.CurrentOrgId,
  3941. HisPatientId: his.ID,
  3942. PatientId: id,
  3943. SettleAccountsDate: recordDateTime,
  3944. Ctime: time.Now().Unix(),
  3945. Mtime: time.Now().Unix(),
  3946. Status: 1,
  3947. OrderStatus: 2,
  3948. MdtrtId: his.Number,
  3949. Number: chrg_bchno,
  3950. MedfeeSumamt: totals,
  3951. PayWay: pay_way,
  3952. PayPrice: pay_price,
  3953. MedType: strconv.Itoa(int(reg_type)),
  3954. PayCardNo: pay_card_no,
  3955. DiscountPrice: discount_price,
  3956. PreferentialPrice: preferential_price,
  3957. RealityPrice: reality_price,
  3958. FoundPrice: found_price,
  3959. MedicalInsurancePrice: medical_insurance_price,
  3960. PrivatePrice: private_price,
  3961. SettleEndTime: end_time,
  3962. SettleStartTime: start_time,
  3963. SettleType: settle_accounts_type,
  3964. FaPiaoCode: fapiao_code,
  3965. FaPiaoNumber: fapiao_number,
  3966. Diagnosis: diagnosis_id,
  3967. PType: 2,
  3968. }
  3969. err = service.CreateOrder(order)
  3970. if err != nil {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3972. return
  3973. }
  3974. var customs []*Custom
  3975. for _, item := range prescriptions {
  3976. if item.Type == 1 { //药品
  3977. for _, subItem := range item.HisDoctorAdviceInfo {
  3978. cus := &Custom{
  3979. AdviceId: subItem.ID,
  3980. ProjectId: 0,
  3981. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3982. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3983. FeedetlSn: subItem.FeedetlSn,
  3984. Price: fmt.Sprintf("%.2f", subItem.Price),
  3985. MedListCodg: subItem.MedListCodg,
  3986. Type: 1,
  3987. }
  3988. customs = append(customs, cus)
  3989. }
  3990. }
  3991. if item.Type == 2 { //项目
  3992. for _, subItem := range item.HisPrescriptionProject {
  3993. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3994. cus := &Custom{
  3995. AdviceId: 0,
  3996. ProjectId: subItem.ID,
  3997. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3998. Cut: fmt.Sprintf("%.4f", cnt),
  3999. FeedetlSn: subItem.FeedetlSn,
  4000. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4001. MedListCodg: subItem.MedListCodg,
  4002. Type: 2,
  4003. }
  4004. customs = append(customs, cus)
  4005. }
  4006. }
  4007. for _, item := range item.HisAdditionalCharge {
  4008. cus := &Custom{
  4009. ItemId: item.ID,
  4010. AdviceId: 0,
  4011. ProjectId: 0,
  4012. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4013. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4014. FeedetlSn: item.FeedetlSn,
  4015. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4016. MedListCodg: item.XtHisAddtionConfig.Code,
  4017. Type: 3,
  4018. }
  4019. customs = append(customs, cus)
  4020. }
  4021. }
  4022. for _, item := range customs {
  4023. var advice_id int64 = 0
  4024. var project_id int64 = 0
  4025. var item_id int64 = 0
  4026. var types int64 = 0
  4027. if item.Type == 1 {
  4028. advice_id = item.AdviceId
  4029. project_id = 0
  4030. item_id = 0
  4031. } else if item.Type == 2 {
  4032. advice_id = 0
  4033. item_id = 0
  4034. project_id = item.ProjectId
  4035. } else if item.Type == 3 {
  4036. advice_id = 0
  4037. item_id = item.ItemId
  4038. project_id = 0
  4039. }
  4040. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4041. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4042. pric, _ := strconv.ParseFloat(item.Price, 32)
  4043. info := &models.HisOrderInfo{
  4044. OrderNumber: order.Number,
  4045. UploadDate: time.Now().Unix(),
  4046. AdviceId: advice_id,
  4047. DetItemFeeSumamt: detItemFeeSumamt,
  4048. Cnt: cut,
  4049. Pric: pric,
  4050. PatientId: id,
  4051. Status: 1,
  4052. Mtime: time.Now().Unix(),
  4053. Ctime: time.Now().Unix(),
  4054. UserOrgId: adminUser.CurrentOrgId,
  4055. HisPatientId: his.ID,
  4056. OrderId: order.ID,
  4057. ProjectId: project_id,
  4058. Type: types,
  4059. ItemId: item_id,
  4060. }
  4061. service.CreateOrderInfo(info)
  4062. }
  4063. his.Diagnosis = diagnosis_id
  4064. his.SickType = sick_type
  4065. his.RegisterType = reg_type
  4066. his.MedicalTreatmentType = reg_type
  4067. service.UpdataHisPateint(&his)
  4068. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4069. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4070. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4071. if err == nil {
  4072. c.ServeSuccessJSON(map[string]interface{}{
  4073. "msg": "结算成功",
  4074. })
  4075. }
  4076. } else {
  4077. if tempOrder.IsPre > 0 {
  4078. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4079. totals, _ := strconv.ParseFloat(allTotal, 64)
  4080. tempOrder.OrderStatus = 2
  4081. tempOrder.PayWay = pay_way
  4082. tempOrder.PayPrice = pay_price
  4083. tempOrder.PayCardNo = pay_card_no
  4084. tempOrder.DiscountPrice = discount_price
  4085. tempOrder.PreferentialPrice = preferential_price
  4086. tempOrder.RealityPrice = reality_price
  4087. tempOrder.FoundPrice = found_price
  4088. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4089. tempOrder.PrivatePrice = private_price
  4090. tempOrder.FaPiaoCode = fapiao_code
  4091. tempOrder.FaPiaoNumber = fapiao_number
  4092. tempOrder.PType = 2
  4093. tempOrder.MedfeeSumamt = totals
  4094. tempOrder.Diagnosis = diagnosis_id
  4095. err = service.SaveHisOrder(&tempOrder)
  4096. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4097. if err != nil {
  4098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4099. return
  4100. }
  4101. if err == nil {
  4102. c.ServeSuccessJSON(map[string]interface{}{
  4103. "msg": "结算成功",
  4104. })
  4105. }
  4106. }
  4107. }
  4108. }
  4109. //退款
  4110. func (c *HisApiController) Refund() {
  4111. order_id, _ := c.GetInt64("order_id")
  4112. order, _ := service.GetHisOrderByID(order_id)
  4113. adminUser := c.GetAdminUserInfo()
  4114. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4115. if err == nil {
  4116. c.ServeSuccessJSON(map[string]interface{}{
  4117. "msg": "退费成功",
  4118. })
  4119. } else {
  4120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4121. return
  4122. }
  4123. }
  4124. func (c *HisApiController) RefundNumber() {
  4125. his_patient_id, _ := c.GetInt64("id")
  4126. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4127. info.Status = 0
  4128. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4129. if count > 0 {
  4130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4131. return
  4132. }
  4133. err := service.SaveHisPatient(info)
  4134. if err == nil {
  4135. c.ServeSuccessJSON(map[string]interface{}{
  4136. "msg": "退号成功",
  4137. })
  4138. } else {
  4139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4140. return
  4141. }
  4142. }
  4143. func (this *HisApiController) AdditionalCharge() {
  4144. dataBody := make(map[string]interface{}, 0)
  4145. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4146. fmt.Println(err)
  4147. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4148. patient_id := int64(dataBody["patient_id"].(float64))
  4149. medicineData, _ := dataBody["medicineData"].([]interface{})
  4150. adminUserInfo := this.GetAdminUserInfo()
  4151. orgId := adminUserInfo.CurrentOrgId
  4152. admin_user_id := adminUserInfo.AdminUser.Id
  4153. timeStr := time.Now().Format("2006-01-02")
  4154. timeLayout := "2006-01-02 15:04:05"
  4155. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4156. timenow := timeStringToTime.Unix()
  4157. var additionalCharges []*models.HisAdditionalCharge
  4158. for _, item := range medicineData {
  4159. var randNum int
  4160. randNum = rand.Intn(10000) + 1000
  4161. timestamp := time.Now().Unix()
  4162. tempTime := time.Unix(timestamp, 0)
  4163. timeFormat := tempTime.Format("20060102150405")
  4164. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4165. items := item.(map[string]interface{})
  4166. money := items["price"].(string)
  4167. item_id_str := items["item_id"].(string)
  4168. name := items["name"].(string)
  4169. id_str := items["id"].(string)
  4170. moneys, _ := strconv.ParseInt(money, 10, 64)
  4171. monStr := strconv.FormatInt(moneys, 10)
  4172. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4173. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4174. id, _ := strconv.ParseInt(id_str, 10, 64)
  4175. additionalCharge := &models.HisAdditionalCharge{
  4176. ID: id,
  4177. HisPatientId: his_patient_id,
  4178. UserOrgId: orgId,
  4179. PatientId: patient_id,
  4180. RecordDate: timenow,
  4181. Price: monneyStr,
  4182. Status: 1,
  4183. ItemName: name,
  4184. ItemId: item_id,
  4185. AdminUserId: admin_user_id,
  4186. CreatedTime: time.Now().Unix(),
  4187. OrderStatus: 0,
  4188. PrescriptionNumber: "",
  4189. BatchNumber: "",
  4190. FeedetlSn: p_number,
  4191. }
  4192. service.CreateAdditionalCharge(additionalCharge)
  4193. additionalCharges = append(additionalCharges, additionalCharge)
  4194. }
  4195. this.ServeSuccessJSON(map[string]interface{}{
  4196. "msg": "添加成功",
  4197. "additional_charges": additionalCharges,
  4198. })
  4199. }
  4200. func (this *HisApiController) DeleteAddition() {
  4201. id, _ := this.GetInt64("id")
  4202. //TODO 需要判断是否已经结算
  4203. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4204. if err == nil {
  4205. this.ServeSuccessJSON(map[string]interface{}{
  4206. "msg": "删除成功",
  4207. })
  4208. return
  4209. } else {
  4210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4211. return
  4212. }
  4213. }
  4214. func (this *HisApiController) GetAdminUsers() {
  4215. adminUser := this.GetAdminUserInfo()
  4216. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4217. this.ServeSuccessJSON(map[string]interface{}{
  4218. "doctors": doctors,
  4219. })
  4220. }
  4221. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4222. change_type, _ := this.GetInt64("type", 0)
  4223. record_date := this.GetString("record_time")
  4224. patient_id, _ := this.GetInt64("patient_id", 0)
  4225. p_type, _ := this.GetInt64("p_type", 0)
  4226. timeLayout := "2006-01-02"
  4227. loc, _ := time.LoadLocation("Local")
  4228. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4229. record_time := theAdviceRecordTime.Unix()
  4230. adminUserInfo := this.GetAdminUserInfo()
  4231. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4232. if err == nil {
  4233. if len(prescriptions) == 0 {
  4234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4235. return
  4236. } else {
  4237. this.ServeSuccessJSON(map[string]interface{}{
  4238. "prescriptions": prescriptions,
  4239. })
  4240. return
  4241. }
  4242. } else {
  4243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4244. return
  4245. }
  4246. }
  4247. func (this *HisApiController) GetCallHisPrescription() {
  4248. patient_id, _ := this.GetInt64("patient_id", 0)
  4249. timeLayout := "2006-01-02"
  4250. loc, _ := time.LoadLocation("Local")
  4251. start_time := this.GetString("start_time")
  4252. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4253. end_time := this.GetString("end_time")
  4254. p_type, _ := this.GetInt64("p_type")
  4255. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4256. adminUserInfo := this.GetAdminUserInfo()
  4257. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4258. if err == nil {
  4259. this.ServeSuccessJSON(map[string]interface{}{
  4260. "prescriptions": prescriptions,
  4261. })
  4262. return
  4263. } else {
  4264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4265. return
  4266. }
  4267. }
  4268. func (this *HisApiController) GetHisDayPrescription() {
  4269. timeLayout := "2006-01-02"
  4270. loc, _ := time.LoadLocation("Local")
  4271. start_time := this.GetString("start_time")
  4272. patient_id, _ := this.GetInt64("patient_id", 0)
  4273. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4274. end_time := this.GetString("end_time")
  4275. p_type, _ := this.GetInt64("p_type")
  4276. order_status, _ := this.GetInt64("type")
  4277. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4278. adminUserInfo := this.GetAdminUserInfo()
  4279. var dayHisPrescription []*models.HisPrescription
  4280. var err error
  4281. if order_status == 1 || order_status == 0 {
  4282. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4283. } else if order_status == 2 {
  4284. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4285. }
  4286. if err == nil {
  4287. this.ServeSuccessJSON(map[string]interface{}{
  4288. "day_prescription": dayHisPrescription,
  4289. })
  4290. return
  4291. } else {
  4292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4293. return
  4294. }
  4295. }
  4296. func (c *HisApiController) GetHisChargePatientList() {
  4297. record_date := c.GetString("record_date")
  4298. order_status, _ := c.GetInt64("type")
  4299. timeLayout := "2006-01-02"
  4300. loc, _ := time.LoadLocation("Local")
  4301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4302. if err != nil {
  4303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4304. return
  4305. }
  4306. recordDateTime := theTime.Unix()
  4307. adminInfo := c.GetAdminUserInfo()
  4308. var tempPatients []*service.NewTempPatients
  4309. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4310. if order_status != 2 {
  4311. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4312. } else {
  4313. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4314. }
  4315. var patients []*service.NewTempPatients
  4316. var patients_two []*service.NewTempPatients
  4317. for _, item := range tempPatients {
  4318. //过滤掉没挂号的和没开处方的
  4319. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4320. patients = append(patients, item)
  4321. }
  4322. //过滤掉没挂号的
  4323. if len(item.HisPatient) > 0 {
  4324. patients_two = append(patients_two, item)
  4325. }
  4326. }
  4327. c.ServeSuccessJSON(map[string]interface{}{
  4328. "list": patients,
  4329. "list_two": patients_two,
  4330. })
  4331. }
  4332. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4333. record_date := c.GetString("record_date")
  4334. timeLayout := "2006-01-02"
  4335. loc, _ := time.LoadLocation("Local")
  4336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4337. if err != nil {
  4338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4339. return
  4340. }
  4341. recordDateTime := theTime.Unix()
  4342. adminUser := c.GetAdminUserInfo()
  4343. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4344. var patients []*service.Patients
  4345. for _, item := range tempPatients {
  4346. if item.HisPatient.ID == 0 {
  4347. patients = append(patients, item)
  4348. }
  4349. }
  4350. c.ServeSuccessJSON(map[string]interface{}{
  4351. "list": patients,
  4352. //"list_two": patients_two,
  4353. })
  4354. }
  4355. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4356. newArr = make([]*service.Patients, 0)
  4357. for i := 0; i < len(patient); i++ {
  4358. repeat := false
  4359. for j := i + 1; j < len(patient); j++ {
  4360. if patient[i].ID == patient[j].ID {
  4361. repeat = true
  4362. break
  4363. }
  4364. }
  4365. if !repeat {
  4366. newArr = append(newArr, patient[i])
  4367. }
  4368. }
  4369. return
  4370. }
  4371. func (c *HisApiController) GetHisChargePatientInfo() {
  4372. patient_id, _ := c.GetInt64("patient_id")
  4373. his_patient_id, _ := c.GetInt64("his_patient_id")
  4374. record_date := c.GetString("record_date")
  4375. //start_time := c.GetString("start_time")
  4376. //end_time := c.GetString("end_time")
  4377. order_status, _ := c.GetInt64("type", 0)
  4378. p_type, _ := c.GetInt64("p_type", 0)
  4379. order_id, _ := c.GetInt64("order_id", 0)
  4380. timeLayout := "2006-01-02"
  4381. loc, _ := time.LoadLocation("Local")
  4382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4383. if err != nil {
  4384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4385. return
  4386. }
  4387. recordDateTime := theTime.Unix()
  4388. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4389. //if err != nil {
  4390. //
  4391. //}
  4392. //startRecordDateTime := startTime.Unix()
  4393. //
  4394. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4395. //if err != nil {
  4396. //
  4397. //}
  4398. //endRecordDateTime := endTime.Unix()
  4399. admin := c.GetAdminUserInfo()
  4400. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4401. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4402. var prescriptions []*models.HisPrescription
  4403. order, _ := service.GetHisOrderByID(order_id)
  4404. if order_status == 1 || order_status == 0 {
  4405. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4406. } else if order_status == 2 {
  4407. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4408. }
  4409. //var monthPrescriptions []*models.HisPrescription
  4410. //if order_status == 1 || order_status == 0 {
  4411. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4412. //} else if order_status == 2 {
  4413. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4414. //}
  4415. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4416. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4417. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4418. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4419. //获取所有科室信息
  4420. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4421. c.ServeSuccessJSON(map[string]interface{}{
  4422. "his_info": his_patient_info,
  4423. "xt_info": xt_patient_info,
  4424. "prescription": prescriptions,
  4425. "case_history": case_history,
  4426. "info": patientPrescriptionInfo,
  4427. "last_info": lastPatientPrescriptionInfo,
  4428. //"month_prescriptions": monthPrescriptions,
  4429. "order": order,
  4430. "doctors": doctors,
  4431. "department": department,
  4432. })
  4433. return
  4434. }
  4435. func (c *HisApiController) GetAllOrderDetail() {
  4436. order_id, _ := c.GetInt64("id", 0)
  4437. order, _ := service.GetHisOrderByID(order_id)
  4438. if order.ID == 0 {
  4439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4440. return
  4441. }
  4442. org_id := c.GetAdminUserInfo().CurrentOrgId
  4443. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4444. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4445. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4446. c.ServeSuccessJSON(map[string]interface{}{
  4447. "order": order,
  4448. "order_info": order_info,
  4449. "patient": patient,
  4450. "admin_info": adminInfo,
  4451. })
  4452. return
  4453. }
  4454. func (c *HisApiController) GetAllOrderDetailCollect() {
  4455. order_id, _ := c.GetInt64("id", 0)
  4456. order, _ := service.GetHisOrderByID(order_id)
  4457. if order.ID == 0 {
  4458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4459. return
  4460. }
  4461. org_id := c.GetAdminUserInfo().CurrentOrgId
  4462. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4463. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4464. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4465. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4466. if his.BalanceAccountsType != 2 {
  4467. c.ServeSuccessJSON(map[string]interface{}{
  4468. "order": order,
  4469. "order_info": order_info,
  4470. "patient": patient,
  4471. "admin_info": adminInfo,
  4472. })
  4473. } else {
  4474. for _, item := range order_info {
  4475. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4476. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4477. item.MedChrgitmType = "09"
  4478. }
  4479. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4480. if item.HisPrescriptionProject.Type == 2 {
  4481. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4482. case 1:
  4483. item.MedChrgitmType = "14"
  4484. break
  4485. case 2:
  4486. item.MedChrgitmType = "05"
  4487. break
  4488. case 3:
  4489. item.MedChrgitmType = "04"
  4490. break
  4491. case 4:
  4492. item.MedChrgitmType = "14"
  4493. break
  4494. case 5:
  4495. item.MedChrgitmType = "08"
  4496. break
  4497. case 6:
  4498. item.MedChrgitmType = "14"
  4499. break
  4500. case 7:
  4501. item.MedChrgitmType = "14"
  4502. break
  4503. case 8:
  4504. item.MedChrgitmType = "03"
  4505. break
  4506. case 9:
  4507. item.MedChrgitmType = "14"
  4508. break
  4509. }
  4510. } else if item.HisPrescriptionProject.Type == 3 {
  4511. item.MedChrgitmType = "08"
  4512. }
  4513. }
  4514. }
  4515. c.ServeSuccessJSON(map[string]interface{}{
  4516. "order": order,
  4517. "order_info": order_info,
  4518. "patient": patient,
  4519. "admin_info": adminInfo,
  4520. })
  4521. }
  4522. return
  4523. }
  4524. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  4525. page, _ := c.GetInt64("page")
  4526. limit, _ := c.GetInt64("limit")
  4527. keywords := c.GetString("keywords")
  4528. start_time := c.GetString("start_time")
  4529. end_time := c.GetString("end_time")
  4530. //clr_type := c.GetString("clr_type")
  4531. insutype := c.GetString("insutype")
  4532. timeLayout := "2006-01-02"
  4533. loc, _ := time.LoadLocation("Local")
  4534. var theStartTIme int64
  4535. if len(start_time) > 0 {
  4536. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4537. theStartTIme = theTime.Unix()
  4538. }
  4539. var theEndtTIme int64
  4540. if len(end_time) > 0 {
  4541. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4542. theEndtTIme = theTime.Unix()
  4543. }
  4544. if page <= 0 {
  4545. page = 1
  4546. }
  4547. if limit <= 0 {
  4548. limit = 10
  4549. }
  4550. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  4551. c.ServeSuccessJSON(map[string]interface{}{
  4552. "total": total,
  4553. "list": list,
  4554. })
  4555. return
  4556. }
  4557. func (c *HisApiController) GetPutOnRecordList() {
  4558. page, _ := c.GetInt64("page")
  4559. limit, _ := c.GetInt64("limit")
  4560. keywords := c.GetString("keywords")
  4561. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  4562. if page <= 0 {
  4563. page = 1
  4564. }
  4565. if limit <= 0 {
  4566. limit = 10
  4567. }
  4568. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  4569. c.ServeSuccessJSON(map[string]interface{}{
  4570. "total": total,
  4571. "list": list,
  4572. })
  4573. return
  4574. }
  4575. func (c *HisApiController) GetCompareData() {
  4576. start_time := c.GetString("start_time")
  4577. end_time := c.GetString("end_time")
  4578. insutype := c.GetString("insutype")
  4579. timeLayout := "2006-01-02"
  4580. loc, _ := time.LoadLocation("Local")
  4581. var theStartTIme int64
  4582. if len(start_time) > 0 {
  4583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4584. if err != nil {
  4585. theStartTIme = 0
  4586. }
  4587. theStartTIme = theTime.Unix()
  4588. }
  4589. var theEndtTIme int64
  4590. if len(end_time) > 0 {
  4591. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4592. if err != nil {
  4593. theEndtTIme = 0
  4594. }
  4595. theEndtTIme = theTime.Unix()
  4596. }
  4597. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  4598. fmt.Println(err)
  4599. if err == nil {
  4600. c.ServeSuccessJSON(map[string]interface{}{
  4601. "list": formData,
  4602. })
  4603. } else {
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4605. return
  4606. }
  4607. }
  4608. func (c *HisApiController) GetFaPiaoData() {
  4609. order_id, _ := c.GetInt64("order_id")
  4610. patient_id, _ := c.GetInt64("patient_id")
  4611. number := c.GetString("number")
  4612. adminUser := c.GetAdminUserInfo()
  4613. order, _ := service.GetHisOrderByID(order_id)
  4614. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4615. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4616. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4617. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  4618. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  4619. var bedCostTotal float64 = 0 //床位总费
  4620. var bedCostSelfTotal float64 = 0 //床位自费
  4621. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4622. var operationCostTotal float64 = 0 //手术费
  4623. var operationCostSelfTotal float64 = 0 //手术费
  4624. var operationCostPartSelfTotal float64 = 0 //手术费
  4625. var otherCostTotal float64 = 0 //其他费用
  4626. var otherCostSelfTotal float64 = 0 //其他费用
  4627. var otherCostPartSelfTotal float64 = 0 //其他费用
  4628. var materialCostTotal float64 = 0 //材料费
  4629. var materialCostSelfTotal float64 = 0 //材料费
  4630. var materialCostPartSelfTotal float64 = 0 //材料费
  4631. var westernMedicineCostTotal float64 = 0 //西药费
  4632. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4633. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4634. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4635. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4636. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4637. var checkCostTotal float64 = 0 //检查费
  4638. var checkCostSelfTotal float64 = 0 //检查费
  4639. var checkCostPartSelfTotal float64 = 0 //检查费
  4640. var laboratoryCostTotal float64 = 0 //化验费
  4641. var laboratoryCostSelfTotal float64 = 0 //化验费
  4642. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4643. var treatCostTotal float64 = 0 //治疗费用
  4644. var treatCostSelfTotal float64 = 0 //治疗费用
  4645. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4646. decimal.DivisionPrecision = 2
  4647. if his.BalanceAccountsType == 2 {
  4648. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4649. for _, item := range orderInfos_two {
  4650. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4651. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4652. item.MedChrgitmType = "09"
  4653. }
  4654. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4655. if item.HisPrescriptionProject.Type == 2 {
  4656. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4657. case 1:
  4658. item.MedChrgitmType = "14"
  4659. break
  4660. case 2:
  4661. item.MedChrgitmType = "05"
  4662. break
  4663. case 3:
  4664. item.MedChrgitmType = "04"
  4665. break
  4666. case 4:
  4667. item.MedChrgitmType = "14"
  4668. break
  4669. case 5:
  4670. item.MedChrgitmType = "08"
  4671. break
  4672. case 6:
  4673. item.MedChrgitmType = "14"
  4674. break
  4675. case 7:
  4676. item.MedChrgitmType = "14"
  4677. break
  4678. case 8:
  4679. item.MedChrgitmType = "03"
  4680. break
  4681. case 9:
  4682. item.MedChrgitmType = "14"
  4683. break
  4684. }
  4685. } else if item.HisPrescriptionProject.Type == 3 {
  4686. item.MedChrgitmType = "08"
  4687. }
  4688. }
  4689. }
  4690. for _, item := range orderInfos_two {
  4691. if item.MedChrgitmType == "01" { //床位费
  4692. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4693. bedCostSelfTotal = bedCostTotal
  4694. }
  4695. if item.MedChrgitmType == "03" { //检查费
  4696. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4697. checkCostSelfTotal = checkCostTotal
  4698. }
  4699. if item.MedChrgitmType == "04" { //化验费
  4700. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4701. laboratoryCostSelfTotal = laboratoryCostTotal
  4702. }
  4703. if item.MedChrgitmType == "05" { //治疗费
  4704. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4705. treatCostSelfTotal = treatCostTotal
  4706. }
  4707. if item.MedChrgitmType == "06" { //手术费
  4708. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4709. operationCostSelfTotal = treatCostTotal
  4710. }
  4711. if item.MedChrgitmType == "08" { //材料费
  4712. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4713. materialCostSelfTotal = materialCostTotal
  4714. }
  4715. if item.MedChrgitmType == "09" { //西药费
  4716. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4717. westernMedicineCostSelfTotal = westernMedicineCostTotal
  4718. }
  4719. if item.MedChrgitmType == "11" { //中成费
  4720. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4721. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  4722. }
  4723. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4724. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4725. otherCostSelfTotal = otherCostTotal
  4726. }
  4727. }
  4728. } else {
  4729. for _, item := range orderInfos {
  4730. if item.MedChrgitmType == "01" { //床位费
  4731. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4732. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4733. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4734. }
  4735. if item.MedChrgitmType == "03" { //检查费
  4736. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4737. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4738. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4739. }
  4740. if item.MedChrgitmType == "04" { //化验费
  4741. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4742. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4743. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4744. }
  4745. if item.MedChrgitmType == "05" { //治疗费
  4746. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4747. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4748. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4749. }
  4750. if item.MedChrgitmType == "06" { //手术费
  4751. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4752. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4753. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4754. }
  4755. if item.MedChrgitmType == "08" { //材料费
  4756. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4757. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4758. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4759. }
  4760. if item.MedChrgitmType == "09" { //西药费
  4761. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4762. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4763. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4764. }
  4765. if item.MedChrgitmType == "11" { //中成费
  4766. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4767. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4768. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4769. }
  4770. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4771. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4772. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4773. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4774. }
  4775. }
  4776. }
  4777. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4778. c.ServeSuccessJSON(map[string]interface{}{
  4779. "order_number": order.Number, //业务流水号
  4780. "id_card_no": his.IdCardNo, //社会保障号
  4781. "department_name": department.Name, //科室
  4782. "number": his.Number, //门诊号
  4783. "date": order.SettleAccountsDate, //结算日期
  4784. "name": order.PsnName, //姓名
  4785. "gender": order.Gend, //性别
  4786. "psn_cash_money": order.PsnCashPay, //个人支付
  4787. "pay_way": "门诊", //结算方式
  4788. "medfee_sumamt": order.MedfeeSumamt, //总费用
  4789. "admin_user_name": admin.UserName, //收款员
  4790. "bedCostTotal": bedCostTotal,
  4791. "bedCostSelfTotal": bedCostSelfTotal,
  4792. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4793. "operationCostTotal": operationCostTotal,
  4794. "operationCostSelfTotal": operationCostSelfTotal,
  4795. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4796. "otherCostTotal": otherCostTotal,
  4797. "otherCostSelfTotal": otherCostSelfTotal,
  4798. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4799. "materialCostTotal": materialCostTotal,
  4800. "materialCostSelfTotal": materialCostSelfTotal,
  4801. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4802. "westernMedicineCostTotal": westernMedicineCostTotal,
  4803. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4804. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4805. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4806. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4807. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4808. "checkCostTotal": checkCostTotal,
  4809. "checkCostSelfTotal": checkCostSelfTotal,
  4810. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4811. "laboratoryCostTotal": laboratoryCostTotal,
  4812. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4813. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4814. "treatCostTotal": treatCostTotal,
  4815. "treatCostSelfTotal": treatCostSelfTotal,
  4816. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4817. })
  4818. }
  4819. func (this *HisApiController) GetIncomeStatisticsData() {
  4820. start_time := this.GetString("start_time")
  4821. end_time := this.GetString("end_time")
  4822. key_words := this.GetString("key_words")
  4823. limit, _ := this.GetInt64("limit")
  4824. page, _ := this.GetInt64("page")
  4825. if page <= 0 {
  4826. page = 1
  4827. }
  4828. if limit <= 0 {
  4829. limit = 10
  4830. }
  4831. statistics_type, _ := this.GetInt64("statistics_type")
  4832. admin := this.GetAdminUserInfo()
  4833. timeLayout := "2006-01-02"
  4834. loc, _ := time.LoadLocation("Local")
  4835. var theStartTIme int64
  4836. if len(start_time) > 0 {
  4837. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4838. if err != nil {
  4839. theStartTIme = 0
  4840. }
  4841. theStartTIme = theTime.Unix()
  4842. }
  4843. var theEndtTIme int64
  4844. if len(end_time) > 0 {
  4845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4846. if err != nil {
  4847. theEndtTIme = 0
  4848. }
  4849. theEndtTIme = theTime.Unix()
  4850. }
  4851. if statistics_type == 1 {
  4852. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4853. this.ServeSuccessJSON(map[string]interface{}{
  4854. "list": list,
  4855. "total": total,
  4856. })
  4857. } else {
  4858. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4859. this.ServeSuccessJSON(map[string]interface{}{
  4860. "list": list,
  4861. "total": total,
  4862. })
  4863. }
  4864. }
  4865. func (c *HisApiController) PostProjectInformation() {
  4866. adminUser := c.GetAdminUserInfo()
  4867. orgId := adminUser.CurrentOrgId
  4868. dataBody := make(map[string]interface{}, 0)
  4869. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4870. if err != nil {
  4871. utils.ErrorLog(err.Error())
  4872. return
  4873. }
  4874. utils.ErrorLog("%v", dataBody)
  4875. var projectList []*models.HisProject
  4876. var total_goods []interface{}
  4877. tempProjects := dataBody["projects"].([]interface{})
  4878. total_goods = tempProjects
  4879. for index, projectMap := range tempProjects {
  4880. projectM := projectMap.(map[string]interface{})
  4881. var project models.HisProject
  4882. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  4883. utils.ErrorLog("project_name")
  4884. return
  4885. }
  4886. project_name, _ := projectM["project_name"].(string)
  4887. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  4888. err_log := models.ExportErrLog{
  4889. LogType: 6,
  4890. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4891. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  4892. Status: 1,
  4893. CreateTime: time.Now().Unix(),
  4894. UpdateTime: time.Now().Unix(),
  4895. ExportTime: time.Now().Unix(),
  4896. }
  4897. service.CreateExportErrLog(&err_log)
  4898. continue
  4899. }
  4900. project.ProjectName = project_name
  4901. prices := projectM["price"].(string)
  4902. price, _ := strconv.ParseFloat(prices, 64)
  4903. if price <= 0 { //名字为空则生成一条导入错误日志
  4904. err_log := models.ExportErrLog{
  4905. LogType: 6,
  4906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  4908. Status: 1,
  4909. CreateTime: time.Now().Unix(),
  4910. UpdateTime: time.Now().Unix(),
  4911. ExportTime: time.Now().Unix(),
  4912. }
  4913. service.CreateExportErrLog(&err_log)
  4914. continue
  4915. }
  4916. project.Price = price
  4917. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  4918. utils.ErrorLog("unit_id")
  4919. return
  4920. }
  4921. unit := projectM["unit"].(string)
  4922. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  4923. err_log := models.ExportErrLog{
  4924. LogType: 6,
  4925. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4926. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  4927. Status: 1,
  4928. CreateTime: time.Now().Unix(),
  4929. UpdateTime: time.Now().Unix(),
  4930. ExportTime: time.Now().Unix(),
  4931. }
  4932. service.CreateExportErrLog(&err_log)
  4933. continue
  4934. }
  4935. project.Unit = unit
  4936. cost_classify := projectM["cost_classify"].(string)
  4937. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  4938. err_log := models.ExportErrLog{
  4939. LogType: 6,
  4940. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4941. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  4942. Status: 1,
  4943. CreateTime: time.Now().Unix(),
  4944. UpdateTime: time.Now().Unix(),
  4945. ExportTime: time.Now().Unix(),
  4946. }
  4947. service.CreateExportErrLog(&err_log)
  4948. continue
  4949. }
  4950. var costClassify = "费用类别"
  4951. var cost_classify_id int64
  4952. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  4953. if len(cost_classify) != 0 {
  4954. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  4955. if errcode == gorm.ErrRecordNotFound {
  4956. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  4957. dataconfig := models.DictDataconfig{
  4958. ParentId: costClassifyConfig.ID,
  4959. Module: "system",
  4960. OrgId: orgId,
  4961. Name: cost_classify,
  4962. FieldName: "",
  4963. Value: costConfig.Value + 1,
  4964. CreatedTime: "",
  4965. UpdatedTime: "",
  4966. CreateUserId: adminUser.AdminUser.Id,
  4967. Status: 1,
  4968. Remark: "",
  4969. DeleteIdSystem: 0,
  4970. Title: "",
  4971. Content: "",
  4972. Order: 0,
  4973. Code: "",
  4974. }
  4975. service.CreatedDicConfig(&dataconfig)
  4976. }
  4977. }
  4978. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  4979. for _, it := range costClassList {
  4980. if cost_classify == it.Name {
  4981. cost_classify_id = int64(it.Value)
  4982. }
  4983. }
  4984. project.CostClassify = cost_classify_id
  4985. executive_section := projectM["executive_section"].(string)
  4986. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  4987. err_log := models.ExportErrLog{
  4988. LogType: 6,
  4989. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4990. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  4991. Status: 1,
  4992. CreateTime: time.Now().Unix(),
  4993. UpdateTime: time.Now().Unix(),
  4994. ExportTime: time.Now().Unix(),
  4995. }
  4996. service.CreateExportErrLog(&err_log)
  4997. continue
  4998. }
  4999. if len(executive_section) != 0 {
  5000. //查找科室是否有内容
  5001. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5002. if errcodedepart == gorm.ErrRecordNotFound {
  5003. department := models.XtHisDepartment{
  5004. Name: executive_section,
  5005. Status: 1,
  5006. UserOrgId: adminUser.CurrentOrgId,
  5007. CreatedTime: time.Now().Unix(),
  5008. }
  5009. service.CreateDePartment(&department)
  5010. }
  5011. }
  5012. var executive_section_id int64
  5013. departMentList, _ := service.GetAllDepartMent(orgId)
  5014. for _, it := range departMentList {
  5015. if executive_section == it.Name {
  5016. executive_section_id = it.ID
  5017. }
  5018. }
  5019. project.ExecutiveSection = executive_section_id
  5020. medical_coverage := projectM["medical_coverage"].(string)
  5021. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5022. err_log := models.ExportErrLog{
  5023. LogType: 6,
  5024. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5025. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5026. Status: 1,
  5027. CreateTime: time.Now().Unix(),
  5028. UpdateTime: time.Now().Unix(),
  5029. ExportTime: time.Now().Unix(),
  5030. }
  5031. service.CreateExportErrLog(&err_log)
  5032. continue
  5033. }
  5034. var medicalCoverage = "医保等级"
  5035. var medical_coverage_id int64
  5036. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5037. if len(medical_coverage) != 0 {
  5038. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5039. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5040. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5041. dataconfig := models.DictDataconfig{
  5042. ParentId: medicalCoverageConfig.ID,
  5043. Module: "system",
  5044. OrgId: orgId,
  5045. Name: medical_coverage,
  5046. FieldName: "",
  5047. Value: medicalCoverageConfig.Value + 1,
  5048. CreatedTime: "",
  5049. UpdatedTime: "",
  5050. CreateUserId: adminUser.AdminUser.Id,
  5051. Status: 1,
  5052. Remark: "",
  5053. DeleteIdSystem: 0,
  5054. Title: "",
  5055. Content: "",
  5056. Order: 0,
  5057. Code: "",
  5058. }
  5059. service.CreatedDicConfig(&dataconfig)
  5060. }
  5061. }
  5062. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5063. for _, it := range medicalCoverageList {
  5064. if medical_coverage == it.Name {
  5065. medical_coverage_id = int64(it.Value)
  5066. }
  5067. }
  5068. project.MedicalCoverage = medical_coverage_id
  5069. pinyin := projectM["pinyin"].(string)
  5070. project.Pinyin = pinyin
  5071. wubi := projectM["wubi"].(string)
  5072. project.Wubi = wubi
  5073. statistical_classification := projectM["statistical_classification"].(string)
  5074. var statisticalClassification = "统计分类"
  5075. var statistical_classification_id int64
  5076. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5077. if len(statistical_classification) != 0 {
  5078. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5079. if classificationerrcodes == gorm.ErrRecordNotFound {
  5080. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5081. dataconfig := models.DictDataconfig{
  5082. ParentId: classiFication.ID,
  5083. Module: "system",
  5084. OrgId: orgId,
  5085. Name: statistical_classification,
  5086. FieldName: "",
  5087. Value: classiFicationConfig.Value + 1,
  5088. CreatedTime: "",
  5089. UpdatedTime: "",
  5090. CreateUserId: adminUser.AdminUser.Id,
  5091. Status: 1,
  5092. Remark: "",
  5093. DeleteIdSystem: 0,
  5094. Title: "",
  5095. Content: "",
  5096. Order: 0,
  5097. Code: "",
  5098. }
  5099. service.CreatedDicConfig(&dataconfig)
  5100. }
  5101. }
  5102. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5103. for _, it := range classiFicationList {
  5104. if statistical_classification == it.Name {
  5105. statistical_classification_id = int64(it.Value)
  5106. }
  5107. }
  5108. project.StatisticalClassification = statistical_classification_id
  5109. disease_directory := int64(projectM["disease_directory"].(float64))
  5110. project.DiseaseDirectory = disease_directory
  5111. is_record := int64(projectM["is_record"].(float64))
  5112. project.IsRecord = is_record
  5113. medical_code := projectM["medical_code"].(string)
  5114. project.MedicalCode = medical_code
  5115. tube_color := projectM["tube_color"].(string)
  5116. var tubeColor = "试管颜色"
  5117. var tube_color_id int64
  5118. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5119. if len(tube_color) != 0 {
  5120. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5121. if errcodetube == gorm.ErrRecordNotFound {
  5122. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5123. dataconfig := models.DictDataconfig{
  5124. ParentId: tubeColorConfig.ID,
  5125. Module: "system",
  5126. OrgId: orgId,
  5127. Name: tube_color,
  5128. FieldName: "",
  5129. Value: tubeConfig.Value + 1,
  5130. CreatedTime: "",
  5131. UpdatedTime: "",
  5132. CreateUserId: adminUser.AdminUser.Id,
  5133. Status: 1,
  5134. Remark: "",
  5135. DeleteIdSystem: 0,
  5136. Title: "",
  5137. Content: "",
  5138. Order: 0,
  5139. Code: "",
  5140. }
  5141. service.CreatedDicConfig(&dataconfig)
  5142. }
  5143. }
  5144. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5145. for _, it := range tubeColorList {
  5146. if tube_color == it.Name {
  5147. tube_color_id = int64(it.Value)
  5148. }
  5149. }
  5150. project.TubeColor = tube_color_id
  5151. single_dose := projectM["single_dose"].(string)
  5152. project.SingleDose = single_dose
  5153. execution_frequency := projectM["execution_frequency"].(string)
  5154. project.ExecutionFrequency = execution_frequency
  5155. delivery_way := projectM["delivery_way"].(string)
  5156. project.DeliveryWay = delivery_way
  5157. number_days := projectM["number_days"].(string)
  5158. project.NumberDays = number_days
  5159. total := projectM["total"].(string)
  5160. project.Total = total
  5161. medical_status := int64(projectM["medical_status"].(float64))
  5162. project.MedicalStatus = medical_status
  5163. category := int64(projectM["category"].(float64))
  5164. project.Category = category
  5165. specail_project := int64(projectM["specail_project"].(float64))
  5166. project.SpecailProject = specail_project
  5167. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5168. project.SocialSecurityDirectoryCode = social_security_directory_code
  5169. remark := projectM["remark"].(string)
  5170. project.Remark = remark
  5171. record_date := projectM["record_date"].(string)
  5172. timeLayout := "2006-01-02"
  5173. loc, _ := time.LoadLocation("Local")
  5174. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5175. project.RecordDate = theTime.Unix()
  5176. projectList = append(projectList, &project)
  5177. }
  5178. export_time := time.Now().Unix()
  5179. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5180. if len(projectList) > 0 {
  5181. for _, item := range projectList {
  5182. project := models.HisProject{
  5183. ProjectName: item.ProjectName,
  5184. Price: item.Price,
  5185. Unit: item.Unit,
  5186. CostClassify: item.CostClassify,
  5187. ExecutiveSection: item.ExecutiveSection,
  5188. MedicalCoverage: item.MedicalCoverage,
  5189. UserOrgId: orgId,
  5190. Status: 1,
  5191. CreatedTime: time.Now().Unix(),
  5192. Pinyin: item.Pinyin,
  5193. Wubi: item.Wubi,
  5194. StatisticalClassification: item.StatisticalClassification,
  5195. DiseaseDirectory: item.DiseaseDirectory,
  5196. IsRecord: item.IsRecord,
  5197. MedicalCode: item.MedicalCode,
  5198. TubeColor: item.TubeColor,
  5199. SingleDose: item.SingleDose,
  5200. DeliveryWay: item.DeliveryWay,
  5201. NumberDays: item.NumberDays,
  5202. Total: item.Total,
  5203. Category: item.Category,
  5204. MedicalStatus: item.MedicalStatus,
  5205. SpecailProject: item.SpecailProject,
  5206. RecordDate: item.RecordDate,
  5207. Remark: item.Remark,
  5208. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5209. ExecutionFrequency: item.ExecutionFrequency,
  5210. }
  5211. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5212. if errcodeproject == gorm.ErrRecordNotFound {
  5213. service.CreateProjectInfomation(&project)
  5214. } else if errcodeproject == nil {
  5215. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5216. }
  5217. log := models.ExportLog{
  5218. LogType: 6,
  5219. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5220. TotalNum: int64(len(total_goods)),
  5221. FailNum: int64(len(errLogs)),
  5222. SuccessNum: int64(len(projectList)),
  5223. CreateTime: time.Now().Unix(),
  5224. UpdateTime: time.Now().Unix(),
  5225. ExportTime: export_time,
  5226. Status: 1,
  5227. }
  5228. service.CreateExportLog(&log)
  5229. c.ServeSuccessJSON(map[string]interface{}{
  5230. "msg": "导入成功",
  5231. "total_num": len(total_goods),
  5232. "success_num": len(projectList),
  5233. "fail_num": int64(len(errLogs)),
  5234. })
  5235. }
  5236. } else {
  5237. log := models.ExportLog{
  5238. LogType: 6,
  5239. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5240. TotalNum: int64(len(total_goods)),
  5241. FailNum: int64(len(errLogs)),
  5242. SuccessNum: int64(len(projectList)),
  5243. CreateTime: time.Now().Unix(),
  5244. UpdateTime: time.Now().Unix(),
  5245. ExportTime: export_time,
  5246. Status: 1,
  5247. }
  5248. service.CreateExportLog(&log)
  5249. c.ServeSuccessJSON(map[string]interface{}{
  5250. "msg": "导入成功",
  5251. "total_num": len(total_goods),
  5252. "success_num": len(projectList),
  5253. "fail_num": int64(len(errLogs)),
  5254. })
  5255. }
  5256. }
  5257. //func (this *HisApiController) EditProjectInformation(){
  5258. //
  5259. // id, _ := this.GetInt64("id")
  5260. // project_team := this.GetString("project_team")
  5261. // price := this.GetString("price")
  5262. // price_float, _ := strconv.ParseFloat(price, 64)
  5263. // pinyin := this.GetString("pinyin")
  5264. // wubi := this.GetString("wubi")
  5265. // tube_color, _ := this.GetInt64("tube_color")
  5266. // team_type, _ := this.GetInt64("team_type")
  5267. // remark := this.GetString("remark")
  5268. // ids := this.GetString("ids")
  5269. // item_id := this.GetString("item_id")
  5270. // projectTeam := models.XtHisProjectTeam{
  5271. // ProjectTeam: project_team,
  5272. // Price: price_float,
  5273. // Pinyin: pinyin,
  5274. // Wubi: wubi,
  5275. // TubeColor: tube_color,
  5276. // TeamType: team_type,
  5277. // Remark: remark,
  5278. // ProjectId: ids,
  5279. // ItemId: item_id,
  5280. // }
  5281. //
  5282. //
  5283. // dataBody := make(map[string]interface{}, 0)
  5284. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5285. // if err != nil {
  5286. // utils.ErrorLog(err.Error())
  5287. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5288. // return
  5289. // }
  5290. //
  5291. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5292. //
  5293. //
  5294. // if err != nil {
  5295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5296. // return
  5297. // }
  5298. //
  5299. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5300. // infos, _ := dataBody["info"].([]interface{})
  5301. // if len(infos) > 0 {
  5302. // var ids []string
  5303. //
  5304. // for _, item := range infos {
  5305. // items := item.(map[string]interface{})
  5306. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5307. // utils.ErrorLog("id")
  5308. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5309. // return
  5310. // }
  5311. // id := int64(items["id"].(float64))
  5312. //
  5313. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5314. // utils.ErrorLog("type")
  5315. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5316. // return
  5317. // }
  5318. // types := int64(items["type"].(float64))
  5319. //
  5320. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5321. // utils.ErrorLog("number")
  5322. // }
  5323. //
  5324. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5325. //
  5326. // projectList := models.XtHisProjectList{
  5327. // Number: number,
  5328. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5329. // ProjectId: id,
  5330. // Status: 1,
  5331. // CreatedTime: time.Now().Unix(),
  5332. // UpdatedTime: time.Now().Unix(),
  5333. // TeamId: projectTeam.ID,
  5334. // Type: types,
  5335. // }
  5336. // list := projectList
  5337. //
  5338. // service.CreateProjectList(&list)
  5339. //
  5340. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5341. //
  5342. // }
  5343. // ids_str := strings.Join(ids, ",")
  5344. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5345. // service.SaveProjectTeam(&projectTeam)
  5346. // this.ServeSuccessJSON(map[string]interface{}{
  5347. // "projectTeam": projectTeam,
  5348. // })
  5349. // }
  5350. // }
  5351. //}
  5352. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5353. name := c.GetString("name")
  5354. mode_id, _ := c.GetInt64("mode", 0)
  5355. types, _ := c.GetInt64("type", 0)
  5356. patient_id, _ := c.GetInt64("patient_id", 0)
  5357. types = 1
  5358. adminInfo := c.GetAdminUserInfo()
  5359. template := &models.HisPrescriptionTemplate{
  5360. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5361. PatientId: patient_id,
  5362. Type: types,
  5363. Status: 1,
  5364. Ctime: time.Now().Unix(),
  5365. Mtime: time.Now().Unix(),
  5366. Name: name,
  5367. Mode: mode_id,
  5368. }
  5369. dataBody := make(map[string]interface{}, 0)
  5370. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5371. if err != nil {
  5372. utils.ErrorLog(err.Error())
  5373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5374. return
  5375. }
  5376. err = service.CreateHisPrescriptionTemplate(template)
  5377. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5378. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5379. if len(prescriptions) > 0 {
  5380. for _, item := range prescriptions {
  5381. items := item.(map[string]interface{})
  5382. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5383. utils.ErrorLog("type")
  5384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5385. return
  5386. }
  5387. types := int64(items["type"].(float64))
  5388. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5389. utils.ErrorLog("med_type")
  5390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5391. return
  5392. }
  5393. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5394. ctime := time.Now().Unix()
  5395. prescription := &models.HisPrescriptionInfoTemplate{
  5396. PatientId: patient_id,
  5397. UserOrgId: adminInfo.CurrentOrgId,
  5398. Ctime: ctime,
  5399. Mtime: ctime,
  5400. Type: types,
  5401. Modifier: adminInfo.AdminUser.Id,
  5402. Creator: adminInfo.AdminUser.Id,
  5403. Status: 1,
  5404. PTemplateId: template.ID,
  5405. MedType: med_type,
  5406. }
  5407. service.CreateHisPrescriptionInfoTemplate(prescription)
  5408. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5409. advices := items["advices"].([]interface{})
  5410. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5411. ctime := time.Now().Unix()
  5412. mtime := ctime
  5413. if len(advices) > 0 {
  5414. for _, advice := range advices {
  5415. var s models.HisPrescriptionAdviceTemplate
  5416. s.PrescriptionId = prescription.ID
  5417. s.AdviceType = 2
  5418. s.StopState = 2
  5419. s.ExecutionState = 2
  5420. s.Status = 1
  5421. s.UserOrgId = adminInfo.CurrentOrgId
  5422. s.CreatedTime = ctime
  5423. s.UpdatedTime = mtime
  5424. s.PatientId = patient_id
  5425. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  5426. if errcode > 0 {
  5427. c.ServeFailJSONWithSGJErrorCode(errcode)
  5428. return
  5429. }
  5430. service.CreateHisPrescriptionAdviceTemplate(&s)
  5431. }
  5432. }
  5433. }
  5434. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5435. projects := items["project"].([]interface{})
  5436. if len(projects) > 0 {
  5437. for _, project := range projects {
  5438. var p models.HisPrescriptionProjectTemplate
  5439. p.PrescriptionId = prescription.ID
  5440. p.Ctime = time.Now().Unix()
  5441. p.Mtime = time.Now().Unix()
  5442. p.PatientId = patient_id
  5443. p.UserOrgId = adminInfo.CurrentOrgId
  5444. p.Status = 1
  5445. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  5446. if errcode > 0 {
  5447. c.ServeFailJSONWithSGJErrorCode(errcode)
  5448. return
  5449. }
  5450. service.CreateHisPrescriptionProjectTemplate(&p)
  5451. }
  5452. }
  5453. }
  5454. }
  5455. c.ServeSuccessJSON(map[string]interface{}{
  5456. "msg": "创建成功",
  5457. })
  5458. }
  5459. }
  5460. }
  5461. func (c *HisApiController) PreSettle() {
  5462. id, _ := c.GetInt64("id")
  5463. record_time := c.GetString("record_time")
  5464. his_patient_id, _ := c.GetInt64("his_patient_id")
  5465. timeLayout := "2006-01-02"
  5466. loc, _ := time.LoadLocation("Local")
  5467. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5468. diagnosis_id := c.GetString("diagnosis")
  5469. sick_type, _ := c.GetInt64("sick_type")
  5470. reg_type, _ := c.GetInt64("p_type")
  5471. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5472. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5473. if err != nil {
  5474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5475. return
  5476. }
  5477. recordDateTime := theTime.Unix()
  5478. adminUser := c.GetAdminUserInfo()
  5479. var prescriptions []*models.HisPrescription
  5480. var start_time int64
  5481. var end_time int64
  5482. ids_str := c.GetString("ids")
  5483. ids_arr := strings.Split(ids_str, ",")
  5484. fmt.Println(reg_type)
  5485. if settle_accounts_type == 1 { //日结
  5486. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5487. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  5488. } else {
  5489. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  5490. }
  5491. fmt.Println(prescriptions)
  5492. } else { //月结
  5493. start_time_str := c.GetString("start_time")
  5494. end_time_str := c.GetString("end_time")
  5495. timeLayout := "2006-01-02"
  5496. loc, _ := time.LoadLocation("Local")
  5497. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5498. if err != nil {
  5499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5500. return
  5501. }
  5502. recordStartTime := theStartTime.Unix()
  5503. start_time = recordStartTime
  5504. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5505. if err != nil {
  5506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5507. return
  5508. }
  5509. recordEndTime := theEndTime.Unix()
  5510. end_time = recordEndTime
  5511. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  5512. }
  5513. if reg_type == 1111 || reg_type == 1112 {
  5514. reg_type = 11
  5515. }
  5516. timestamp := time.Now().Unix()
  5517. tempTime := time.Unix(timestamp, 0)
  5518. timeFormat := tempTime.Format("20060102150405")
  5519. chrgBchno := rand.Intn(100000) + 10000
  5520. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5521. strconv.FormatInt(his.PatientId, 10)
  5522. var ids []int64
  5523. for _, item := range prescriptions {
  5524. ids = append(ids, item.ID)
  5525. }
  5526. fmt.Println(ids)
  5527. var total float64
  5528. for _, item := range prescriptions {
  5529. fmt.Println(item)
  5530. if item.Type == 1 { //药品
  5531. for _, subItem := range item.HisDoctorAdviceInfo {
  5532. total = total + (subItem.Price * subItem.PrescribingNumber)
  5533. }
  5534. }
  5535. if item.Type == 2 { //项目
  5536. for _, subItem := range item.HisPrescriptionProject {
  5537. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5538. total = total + (subItem.Price * cnt)
  5539. }
  5540. }
  5541. for _, subItem := range item.HisAdditionalCharge {
  5542. total = total + (subItem.Price * float64(subItem.Count))
  5543. }
  5544. }
  5545. allTotal := fmt.Sprintf("%.2f", total)
  5546. totals, _ := strconv.ParseFloat(allTotal, 64)
  5547. order := &models.HisOrder{
  5548. UserOrgId: adminUser.CurrentOrgId,
  5549. HisPatientId: his.ID,
  5550. PatientId: id,
  5551. SettleAccountsDate: recordDateTime,
  5552. Ctime: time.Now().Unix(),
  5553. Mtime: time.Now().Unix(),
  5554. Status: 1,
  5555. OrderStatus: 1,
  5556. MdtrtId: his.Number,
  5557. Number: chrg_bchno,
  5558. MedfeeSumamt: totals,
  5559. SettleEndTime: end_time,
  5560. SettleStartTime: start_time,
  5561. SettleType: settle_accounts_type,
  5562. PType: 2,
  5563. IsPre: 1,
  5564. MedType: strconv.Itoa(int(reg_type)),
  5565. Diagnosis: diagnosis_id,
  5566. }
  5567. err = service.CreateOrder(order)
  5568. if err != nil {
  5569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5570. return
  5571. }
  5572. var customs []*Custom
  5573. for _, item := range prescriptions {
  5574. fmt.Println(item.Type)
  5575. if item.Type == 1 { //药品
  5576. for _, subItem := range item.HisDoctorAdviceInfo {
  5577. cus := &Custom{
  5578. AdviceId: subItem.ID,
  5579. ProjectId: 0,
  5580. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  5581. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  5582. FeedetlSn: subItem.FeedetlSn,
  5583. Price: fmt.Sprintf("%.2f", subItem.Price),
  5584. MedListCodg: subItem.MedListCodg,
  5585. Type: 1,
  5586. }
  5587. customs = append(customs, cus)
  5588. }
  5589. }
  5590. if item.Type == 2 { //项目
  5591. for _, subItem := range item.HisPrescriptionProject {
  5592. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5593. cus := &Custom{
  5594. AdviceId: 0,
  5595. ProjectId: subItem.ID,
  5596. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  5597. Cut: fmt.Sprintf("%.2f", cnt),
  5598. FeedetlSn: subItem.FeedetlSn,
  5599. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  5600. MedListCodg: subItem.MedListCodg,
  5601. Type: 2,
  5602. }
  5603. customs = append(customs, cus)
  5604. }
  5605. }
  5606. for _, item := range item.HisAdditionalCharge {
  5607. cus := &Custom{
  5608. ItemId: item.ID,
  5609. AdviceId: 0,
  5610. ProjectId: 0,
  5611. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  5612. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  5613. FeedetlSn: item.FeedetlSn,
  5614. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  5615. MedListCodg: item.XtHisAddtionConfig.Code,
  5616. Type: 3,
  5617. }
  5618. customs = append(customs, cus)
  5619. }
  5620. }
  5621. fmt.Println(customs)
  5622. for _, item := range customs {
  5623. var advice_id int64 = 0
  5624. var project_id int64 = 0
  5625. var item_id int64 = 0
  5626. var types int64 = 0
  5627. if item.Type == 1 {
  5628. advice_id = item.AdviceId
  5629. project_id = 0
  5630. item_id = 0
  5631. } else if item.Type == 2 {
  5632. advice_id = 0
  5633. item_id = 0
  5634. project_id = item.ProjectId
  5635. } else if item.Type == 3 {
  5636. advice_id = 0
  5637. item_id = item.ItemId
  5638. project_id = 0
  5639. }
  5640. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5641. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5642. pric, _ := strconv.ParseFloat(item.Price, 32)
  5643. info := &models.HisOrderInfo{
  5644. OrderNumber: order.Number,
  5645. UploadDate: time.Now().Unix(),
  5646. AdviceId: advice_id,
  5647. DetItemFeeSumamt: detItemFeeSumamt,
  5648. Cnt: cut,
  5649. Pric: pric,
  5650. PatientId: id,
  5651. Status: 1,
  5652. Mtime: time.Now().Unix(),
  5653. Ctime: time.Now().Unix(),
  5654. UserOrgId: adminUser.CurrentOrgId,
  5655. HisPatientId: his.ID,
  5656. OrderId: order.ID,
  5657. ProjectId: project_id,
  5658. Type: types,
  5659. ItemId: item_id,
  5660. }
  5661. service.CreateOrderInfo(info)
  5662. }
  5663. his.SickType = sick_type
  5664. service.UpdataHisPateint(&his)
  5665. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  5666. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  5667. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  5668. if err == nil {
  5669. c.ServeSuccessJSON(map[string]interface{}{
  5670. "msg": "结算成功",
  5671. })
  5672. }
  5673. }
  5674. type CustomOrderInfo struct {
  5675. Name string
  5676. Spec string
  5677. Unit string
  5678. Count float64
  5679. Price float64
  5680. Total float64
  5681. }
  5682. func (c *HisApiController) GetPrivateExpensesInfo() {
  5683. order_id, _ := c.GetInt64("id", 0)
  5684. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  5685. order, _ := service.GetHisOrderByID(order_id)
  5686. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  5687. if order.ID == 0 {
  5688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5689. return
  5690. }
  5691. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5692. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5693. org_id := c.GetAdminUserInfo().CurrentOrgId
  5694. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5695. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5696. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  5697. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  5698. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  5699. var orderInfos_four []*models.HisOrderInfoTwo
  5700. for _, item := range orderInfos_three {
  5701. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  5702. item.HisPrescriptionProject.IsCheckTeam = 1
  5703. orderInfos_four = append(orderInfos_four, item)
  5704. }
  5705. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  5706. item.HisPrescriptionProject.IsCheckTeam = 2
  5707. orderInfos_two = append(orderInfos_two, item)
  5708. }
  5709. }
  5710. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  5711. var cus_slice []CustomOrderInfo
  5712. for _, item := range new_order_info {
  5713. var cus CustomOrderInfo
  5714. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  5715. cus.Unit = ""
  5716. cus.Spec = ""
  5717. var total float64
  5718. for _, subItem := range orderInfos_four {
  5719. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  5720. total = total + subItem.DetItemFeeSumamt
  5721. fmt.Println(subItem.DetItemFeeSumamt)
  5722. }
  5723. }
  5724. cus.Count = 1
  5725. cus.Total = total
  5726. cus_slice = append(cus_slice, cus)
  5727. }
  5728. orderInfos = append(orderInfos, orderInfos_two...)
  5729. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  5730. orderInfos = append(orderInfos, orderInfos_three...)
  5731. }
  5732. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5733. c.ServeSuccessJSON(map[string]interface{}{
  5734. "order": order,
  5735. "order_info": orderInfos,
  5736. "patient": patient,
  5737. "admin_info": adminInfo,
  5738. "his": his,
  5739. "current_admin": role,
  5740. "org_config": miConfig,
  5741. "new_order_info": cus_slice,
  5742. })
  5743. }
  5744. func (this *HisApiController) ChangeMedType() {
  5745. med_type := this.GetString("med_type")
  5746. id, _ := this.GetInt64("id")
  5747. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  5748. prescription.MedType = med_type
  5749. err := service.SaveHisPrescription(&prescription)
  5750. if err == nil {
  5751. this.ServeSuccessJSON(map[string]interface{}{
  5752. "msg": "修改成功",
  5753. })
  5754. } else {
  5755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5756. return
  5757. }
  5758. }
  5759. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  5760. patient_id, _ := c.GetInt64("patient_id")
  5761. his_patient_id, _ := c.GetInt64("his_patient_id")
  5762. record_date := c.GetString("record_date")
  5763. start_time := c.GetString("start_time")
  5764. end_time := c.GetString("end_time")
  5765. order_status, _ := c.GetInt64("type", 0)
  5766. p_type, _ := c.GetInt64("p_type", 0)
  5767. order_id, _ := c.GetInt64("order_id", 0)
  5768. timeLayout := "2006-01-02"
  5769. loc, _ := time.LoadLocation("Local")
  5770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5771. if err != nil {
  5772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5773. return
  5774. }
  5775. recordDateTime := theTime.Unix()
  5776. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5777. if err != nil {
  5778. }
  5779. startRecordDateTime := startTime.Unix()
  5780. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5781. if err != nil {
  5782. }
  5783. endRecordDateTime := endTime.Unix()
  5784. admin := c.GetAdminUserInfo()
  5785. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5786. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5787. order, _ := service.GetHisOrderByID(order_id)
  5788. var monthPrescriptions []*models.HisPrescription
  5789. if order_status == 1 || order_status == 0 {
  5790. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5791. } else if order_status == 2 {
  5792. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5793. }
  5794. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5795. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5796. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5797. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5798. //获取所有科室信息
  5799. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5800. c.ServeSuccessJSON(map[string]interface{}{
  5801. "his_info": his_patient_info,
  5802. "xt_info": xt_patient_info,
  5803. "case_history": case_history,
  5804. "info": patientPrescriptionInfo,
  5805. "last_info": lastPatientPrescriptionInfo,
  5806. "month_prescriptions": monthPrescriptions,
  5807. "order": order,
  5808. "doctors": doctors,
  5809. "department": department,
  5810. })
  5811. return
  5812. }
  5813. func (c *HisApiController) GetHisMonthPatientInfo() {
  5814. patient_id, _ := c.GetInt64("patient_id")
  5815. his_patient_id, _ := c.GetInt64("his_patient_id")
  5816. record_date := c.GetString("record_date")
  5817. number := c.GetString("number")
  5818. start_time := c.GetString("start_time")
  5819. end_time := c.GetString("end_time")
  5820. p_type, _ := c.GetInt64("p_type")
  5821. timeLayout := "2006-01-02"
  5822. loc, _ := time.LoadLocation("Local")
  5823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5824. if err != nil {
  5825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5826. return
  5827. }
  5828. recordDateTime := theTime.Unix()
  5829. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5830. if err != nil {
  5831. }
  5832. startRecordDateTime := startTime.Unix()
  5833. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5834. if err != nil {
  5835. }
  5836. endRecordDateTime := endTime.Unix()
  5837. admin := c.GetAdminUserInfo()
  5838. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  5839. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5840. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  5841. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5842. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5843. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5844. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5845. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  5846. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5847. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  5848. //获取所有科室信息
  5849. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5850. c.ServeSuccessJSON(map[string]interface{}{
  5851. "his_info": his_patient_info,
  5852. "xt_info": xt_patient_info,
  5853. "case_history": case_history,
  5854. "info": patientPrescriptionInfo,
  5855. "month_prescriptions": monthPrescriptions,
  5856. "order": order,
  5857. "doctors": doctors,
  5858. "department": department,
  5859. "count": count,
  5860. "drugStockConfig": drugStockConfig,
  5861. "last_info": lastPatientPrescriptionInfo,
  5862. })
  5863. return
  5864. }
  5865. func (c *HisApiController) GetAllOrder() {
  5866. org_id := c.GetAdminUserInfo().CurrentOrgId
  5867. orders, _ := service.GetNewHisOrderList(org_id)
  5868. c.ServeSuccessJSON(map[string]interface{}{
  5869. "order": orders,
  5870. })
  5871. return
  5872. }
  5873. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  5874. newArr = make([]*models.HisOrderInfoTwo, 0)
  5875. for i := 0; i < len(arr); i++ {
  5876. repeat := false
  5877. for j := i + 1; j < len(arr); j++ {
  5878. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  5879. repeat = true
  5880. break
  5881. }
  5882. }
  5883. if !repeat {
  5884. newArr = append(newArr, arr[i])
  5885. }
  5886. }
  5887. return
  5888. }
  5889. //修改处方退库操作 参数传修改之前的处方数据
  5890. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  5891. if advice.ExecutionState == 1 {
  5892. //查询该病人该药品是否有库存记录
  5893. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  5894. if errcode == gorm.ErrRecordNotFound {
  5895. } else {
  5896. //退库
  5897. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5898. if advice.PrescribingNumberUnit == drug.MinUnit {
  5899. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5900. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5901. //退库
  5902. warehouseInfo := models.DrugWarehouseInfo{
  5903. StockMinNumber: prescribingNumber,
  5904. }
  5905. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  5906. operation_time := time.Now().Unix()
  5907. creater := advice.AdviceDoctor
  5908. ctime := time.Now().Unix()
  5909. timeStr := time.Now().Format("2006-01-02")
  5910. timeArr := strings.Split(timeStr, "-")
  5911. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5912. total = total + 1
  5913. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5914. cancelStock := models.DrugCancelStock{
  5915. OrderNumber: orderNumber,
  5916. OperaTime: operation_time,
  5917. OrgId: advice.UserOrgId,
  5918. Creater: creater,
  5919. Ctime: ctime,
  5920. Status: 1,
  5921. ReturnTime: advice.AdviceDate,
  5922. Dealer: info.Dealer,
  5923. Manufacturer: info.Manufacturer,
  5924. Type: 1,
  5925. }
  5926. service.AddSigleDrugCancelStock(&cancelStock)
  5927. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  5928. dealer, _ := service.GetDealerById(info.Dealer)
  5929. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  5930. cancelStockInfo := models.DrugCancelStockInfo{
  5931. OrderNumber: cancelInfo.OrderNumber,
  5932. CancelStockId: cancelInfo.ID,
  5933. DrugId: info.DrugId,
  5934. Count: info.Count,
  5935. Status: 1,
  5936. Ctime: ctime,
  5937. OrgId: advice.UserOrgId,
  5938. Type: 1,
  5939. Manufacturer: manufactureName.ManufacturerName,
  5940. Dealer: dealer.DealerName,
  5941. Total: 0,
  5942. RetailPrice: info.RetailPrice,
  5943. RetailTotalPrice: info.RetailTotalPrice,
  5944. Price: info.Price,
  5945. RegisterAccount: "",
  5946. Remark: info.Remark,
  5947. BatchNumber: info.BatchNumber,
  5948. MaxUnit: info.CountUnit,
  5949. ProductDate: info.ProductDate,
  5950. ExpiryDate: info.ExpiryDate,
  5951. BatchNumberId: info.WarehouseInfoId,
  5952. }
  5953. flow := models.DrugFlow{
  5954. WarehousingId: 0,
  5955. DrugId: info.DrugId,
  5956. Number: "",
  5957. BatchNumber: info.BatchNumber,
  5958. Count: info.Count,
  5959. UserOrgId: advice.UserOrgId,
  5960. PatientId: 0,
  5961. SystemTime: ctime,
  5962. ConsumableType: 4,
  5963. IsSys: 0,
  5964. WarehousingOrder: "",
  5965. WarehouseOutId: 0,
  5966. WarehouseOutOrderNumber: "",
  5967. IsEdit: 0,
  5968. CancelStockId: cancelStock.ID,
  5969. CancelOrderNumber: cancelStock.OrderNumber,
  5970. Manufacturer: info.Manufacturer,
  5971. Dealer: info.Dealer,
  5972. Creator: advice.UserOrgId,
  5973. UpdateCreator: 0,
  5974. Status: 1,
  5975. Ctime: time.Now().Unix(),
  5976. Mtime: 0,
  5977. Price: info.Price,
  5978. WarehousingDetailId: 0,
  5979. WarehouseOutDetailId: 0,
  5980. CancelOutDetailId: 0,
  5981. ExpireDate: info.ExpiryDate,
  5982. ProductDate: info.ProductDate,
  5983. MaxUnit: info.CountUnit,
  5984. MinUnit: "",
  5985. }
  5986. service.CreatedCancelStock(cancelStockInfo)
  5987. service.CreateDrugFlowOne(flow)
  5988. } else {
  5989. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5990. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5991. fmt.Println("PrescribingNumber", prescribingNumber)
  5992. if advice.PrescribingNumberUnit == drug.MaxUnit {
  5993. warehouseInfo := models.DrugWarehouseInfo{
  5994. StockMinNumber: prescribingNumber,
  5995. }
  5996. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  5997. }
  5998. operation_time := time.Now().Unix()
  5999. creater := advice.AdviceDoctor
  6000. ctime := time.Now().Unix()
  6001. timeStr := time.Now().Format("2006-01-02")
  6002. timeArr := strings.Split(timeStr, "-")
  6003. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6004. total = total + 1
  6005. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6006. cancelStock := models.DrugCancelStock{
  6007. OrderNumber: orderNumber,
  6008. OperaTime: operation_time,
  6009. OrgId: advice.UserOrgId,
  6010. Creater: creater,
  6011. Ctime: ctime,
  6012. Status: 1,
  6013. ReturnTime: advice.AdviceDate,
  6014. Dealer: info.Dealer,
  6015. Manufacturer: info.Manufacturer,
  6016. Type: 1,
  6017. }
  6018. service.AddSigleDrugCancelStock(&cancelStock)
  6019. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6020. dealer, _ := service.GetDealerById(info.Dealer)
  6021. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6022. cancelStockInfo := models.DrugCancelStockInfo{
  6023. OrderNumber: cancelInfo.OrderNumber,
  6024. CancelStockId: cancelInfo.ID,
  6025. DrugId: info.DrugId,
  6026. Count: info.Count,
  6027. Status: 1,
  6028. Ctime: ctime,
  6029. OrgId: advice.UserOrgId,
  6030. Type: 1,
  6031. Manufacturer: manufactureName.ManufacturerName,
  6032. Dealer: dealer.DealerName,
  6033. Total: 0,
  6034. RetailPrice: info.RetailPrice,
  6035. RetailTotalPrice: info.RetailTotalPrice,
  6036. Price: info.Price,
  6037. RegisterAccount: "",
  6038. Remark: info.Remark,
  6039. BatchNumber: info.BatchNumber,
  6040. MaxUnit: info.CountUnit,
  6041. ProductDate: info.ProductDate,
  6042. ExpiryDate: info.ExpiryDate,
  6043. BatchNumberId: info.WarehouseInfoId,
  6044. }
  6045. flow := models.DrugFlow{
  6046. WarehousingId: 0,
  6047. DrugId: info.DrugId,
  6048. Number: "",
  6049. BatchNumber: info.BatchNumber,
  6050. Count: info.Count,
  6051. UserOrgId: advice.UserOrgId,
  6052. PatientId: 0,
  6053. SystemTime: ctime,
  6054. ConsumableType: 4,
  6055. IsSys: 0,
  6056. WarehousingOrder: "",
  6057. WarehouseOutId: 0,
  6058. WarehouseOutOrderNumber: "",
  6059. IsEdit: 0,
  6060. CancelStockId: cancelStock.ID,
  6061. CancelOrderNumber: cancelStock.OrderNumber,
  6062. Manufacturer: info.Manufacturer,
  6063. Dealer: info.Dealer,
  6064. Creator: advice.AdviceDoctor,
  6065. UpdateCreator: 0,
  6066. Status: 1,
  6067. Ctime: time.Now().Unix(),
  6068. Mtime: 0,
  6069. Price: info.Price,
  6070. WarehousingDetailId: 0,
  6071. WarehouseOutDetailId: 0,
  6072. CancelOutDetailId: 0,
  6073. ExpireDate: info.ExpiryDate,
  6074. ProductDate: info.ProductDate,
  6075. MaxUnit: info.CountUnit,
  6076. MinUnit: "",
  6077. }
  6078. service.CreatedCancelStock(cancelStockInfo)
  6079. service.CreateDrugFlowOne(flow)
  6080. }
  6081. }
  6082. }
  6083. return err
  6084. }
  6085. func (this *HisApiController) DeleteNCDS() {
  6086. id, _ := this.GetInt64("id", 0)
  6087. if id > 0 {
  6088. service.DeletePsnNCDSRecordById(id)
  6089. this.ServeSuccessJSON(map[string]interface{}{
  6090. "msg": "删除成功",
  6091. })
  6092. } else {
  6093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6094. return
  6095. }
  6096. }
  6097. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6098. id, _ := c.GetInt64("id")
  6099. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6100. c.ServeSuccessJSON(map[string]interface{}{
  6101. "advice": advice,
  6102. })
  6103. return
  6104. }