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. index = index + 1
  521. if subItem.RetailPrice > 0 {
  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: good.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: good.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. chief_conplaint := c.GetString("chief_conplaint")
  2330. dbp := c.GetString("dbp")
  2331. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2332. delivery_way, _ := c.GetInt64("delivery_way")
  2333. diagnostic := c.GetString("diagnostic")
  2334. family_history := c.GetString("family_history")
  2335. height := c.GetString("height")
  2336. history_of_present_illness := c.GetString("history_of_present_illness")
  2337. is_infect, _ := c.GetInt64("is_infect")
  2338. past_history := c.GetString("past_history")
  2339. patient_id, _ := c.GetInt64("patient_id")
  2340. his_patient_id, _ := c.GetInt64("his_patient_id")
  2341. personal_history := c.GetString("personal_history")
  2342. pulse := c.GetString("pulse")
  2343. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2344. sbp := c.GetString("sbp")
  2345. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2346. heightfloat, _ := strconv.ParseFloat(height, 64)
  2347. sicktype := c.GetString("sick_type")
  2348. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2349. symptom := c.GetString("symptom")
  2350. sick_date := c.GetString("sick_date")
  2351. temperatures := c.GetString("temperature")
  2352. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2353. record_date := c.GetString("record_date")
  2354. breathing := c.GetString("breathing")
  2355. doctor_advice := c.GetString("doctor_advice")
  2356. remark := c.GetString("remark")
  2357. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2358. sick, _ := c.GetInt64("sick")
  2359. diagnose, _ := c.GetInt64("diagnose")
  2360. id, _ := c.GetInt64("id")
  2361. timeLayout := "2006-01-02"
  2362. loc, _ := time.LoadLocation("Local")
  2363. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2364. allergic_history := c.GetString("allergic_history")
  2365. if err != nil {
  2366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2367. return
  2368. }
  2369. recordDateTime := theTime.Unix()
  2370. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2371. if err != nil {
  2372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2373. return
  2374. }
  2375. sickTimes := sickTime.Unix()
  2376. ctime := time.Now().Unix()
  2377. caseHistory := models.HisPatientCaseHistory{
  2378. HisPatientId: his_patient_id,
  2379. PatientId: patient_id,
  2380. Temperature: temperature,
  2381. BloodSugar: bloodsugarfloat,
  2382. Pulse: pulsefloat,
  2383. Sbp: sbpfloat,
  2384. Dbp: dbpfloat,
  2385. Height: heightfloat,
  2386. BloodFat: bloodfatfloat,
  2387. SickType: sick_type,
  2388. Symptom: symptom,
  2389. SickDate: sickTimes,
  2390. IsInfect: is_infect,
  2391. HistoryOfPresentIllness: history_of_present_illness,
  2392. PastHistory: past_history,
  2393. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2394. ChiefConplaint: chief_conplaint,
  2395. PersonalHistory: personal_history,
  2396. FamilyHistory: family_history,
  2397. Diagnostic: diagnostic,
  2398. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2399. Status: 1,
  2400. Ctime: ctime,
  2401. Mtime: ctime,
  2402. RecordDate: recordDateTime,
  2403. DeliveryWay: delivery_way,
  2404. Breathing: breathingfloat,
  2405. DoctorAdvice: doctor_advice,
  2406. Remark: remark,
  2407. Sick: sick,
  2408. Diagnose: diagnose,
  2409. AllergicHistory: allergic_history,
  2410. }
  2411. //查询该患者是否有病历
  2412. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2413. if errcodes == gorm.ErrRecordNotFound {
  2414. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2415. if err != nil {
  2416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2417. return
  2418. }
  2419. c.ServeSuccessJSON(map[string]interface{}{
  2420. "caseHistory": caseHistory,
  2421. })
  2422. return
  2423. } else if errcodes == nil {
  2424. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2425. if err != nil {
  2426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2427. return
  2428. }
  2429. c.ServeSuccessJSON(map[string]interface{}{
  2430. "caseHistory": caseHistory,
  2431. })
  2432. }
  2433. //查询该患者是否有病历
  2434. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2435. //if errcode == gorm.ErrRecordNotFound {
  2436. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2437. // if err != nil {
  2438. // c.ServeSuccessJSON(map[string]interface{}{
  2439. // "msg": "保存成功",
  2440. // })
  2441. // }
  2442. //} else if errcode == nil {
  2443. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2444. // return
  2445. //}
  2446. }
  2447. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2448. patient_id, _ := c.GetInt64("patient_id", 0)
  2449. adminUser := c.GetAdminUserInfo()
  2450. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2451. c.ServeSuccessJSON(map[string]interface{}{
  2452. "list": caseHistorys,
  2453. })
  2454. }
  2455. func (c *HisApiController) GetHisPatientCaseHistory() {
  2456. record_date, _ := c.GetInt64("record_date", 0)
  2457. patient_id, _ := c.GetInt64("patient_id", 0)
  2458. admin := c.GetAdminUserInfo()
  2459. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2460. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2461. c.ServeSuccessJSON(map[string]interface{}{
  2462. "info": info,
  2463. "case_history": case_history,
  2464. })
  2465. }
  2466. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2467. template_name := c.GetString("template_name")
  2468. template_remark := c.GetString("template_remark")
  2469. doctor := c.GetAdminUserInfo().AdminUser.Id
  2470. diagnostic := c.GetString("diagnostic")
  2471. chief_conplaint := c.GetString("chief_conplain")
  2472. history_of_present_illness := c.GetString("history_of_present_illness")
  2473. past_history := c.GetString("past_history")
  2474. personal_history := c.GetString("personal_history")
  2475. family_history := c.GetString("family_history")
  2476. user_name := c.GetString("user_name")
  2477. doctor_advice := c.GetString("doctor_advice")
  2478. remark := c.GetString("remark")
  2479. //record_date := c.GetString("record_date")
  2480. //fmt.Println("record_date--------",record_date)
  2481. //timeLayout := "2006-01-02"
  2482. //loc, _ := time.LoadLocation("Local")
  2483. //
  2484. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2485. //if err != nil {
  2486. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2487. // return
  2488. //}
  2489. //recordDateTime := theTime.Unix()
  2490. ctime := time.Now().Unix()
  2491. template := models.HisCaseHistoryTemplate{
  2492. HistoryOfPresentIllness: history_of_present_illness,
  2493. PastHistory: past_history,
  2494. ChiefConplaint: chief_conplaint,
  2495. PersonalHistory: personal_history,
  2496. FamilyHistory: family_history,
  2497. Diagnostic: diagnostic,
  2498. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2499. Status: 1,
  2500. Ctime: ctime,
  2501. Mtime: ctime,
  2502. RecordDate: time.Now().Unix(),
  2503. TemplateName: template_name,
  2504. TemplateRemark: template_remark,
  2505. Creator: doctor,
  2506. Modifier: doctor,
  2507. UserName: user_name,
  2508. DoctorAdvice: doctor_advice,
  2509. Remark: remark,
  2510. }
  2511. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2512. if err == nil {
  2513. c.ServeSuccessJSON(map[string]interface{}{
  2514. "msg": "保存成功",
  2515. })
  2516. } else {
  2517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2518. return
  2519. }
  2520. }
  2521. func (c *HisApiController) GetCaseHistoryTemplate() {
  2522. timeLayout := "2006-01-02"
  2523. loc, _ := time.LoadLocation("Local")
  2524. keyword := c.GetString("keyword")
  2525. start_time := c.GetString("start_time")
  2526. end_time := c.GetString("end_time")
  2527. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2528. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2529. admin := c.GetAdminUserInfo()
  2530. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2531. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "template": template,
  2534. //"history": history,
  2535. })
  2536. }
  2537. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2538. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2539. utils.ErrorLog("drug_name")
  2540. return enums.ErrorCodeParamWrong
  2541. }
  2542. adviceName, _ := json["drug_name"].(string)
  2543. if len(adviceName) == 0 {
  2544. utils.ErrorLog("len(advice_name) == 0")
  2545. return enums.ErrorCodeParamWrong
  2546. }
  2547. advice.AdviceName = adviceName
  2548. adviceDesc, _ := json["advice_desc"].(string)
  2549. advice.AdviceDesc = adviceDesc
  2550. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2551. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2552. advice.DrugSpec = drugSpec
  2553. }
  2554. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2555. remark, _ := json["remark"].(string)
  2556. advice.Remark = remark
  2557. }
  2558. if json["id"] == nil {
  2559. advice.DrugId = 0
  2560. } else {
  2561. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2562. drug_id := int64(json["id"].(float64))
  2563. advice.DrugId = drug_id
  2564. }
  2565. }
  2566. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2567. advice_id := int64(json["advice_id"].(float64))
  2568. advice.ID = advice_id
  2569. if advice.ID > 0 {
  2570. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2571. if err == nil {
  2572. if hisAdvice.ID > 0 {
  2573. advice.ExecutionTime = hisAdvice.ExecutionTime
  2574. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2575. advice.ExecutionState = hisAdvice.ExecutionState
  2576. advice.CheckTime = hisAdvice.CheckTime
  2577. advice.Checker = hisAdvice.Checker
  2578. advice.CheckState = hisAdvice.CheckState
  2579. advice.StartTime = hisAdvice.StartTime
  2580. advice.FeedetlSn = hisAdvice.FeedetlSn
  2581. }
  2582. }
  2583. }
  2584. }
  2585. //
  2586. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2587. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2588. // advice.ExecutionTime = execution_time
  2589. //}
  2590. //
  2591. //
  2592. //
  2593. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2594. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2595. // advice.ExecutionStaff = execution_staff
  2596. //}
  2597. //
  2598. //
  2599. //
  2600. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2601. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2602. // advice.ExecutionState = execution_state
  2603. //}
  2604. //
  2605. //
  2606. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2607. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2608. // advice.CheckTime = check_time
  2609. //}
  2610. //
  2611. //
  2612. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2613. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2614. // advice.CheckState = check_state
  2615. //}
  2616. //
  2617. //
  2618. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2619. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2620. // advice.Checker = checker
  2621. //}
  2622. //
  2623. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2624. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2625. // advice.StartTime = start_time
  2626. //}
  2627. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2628. drugSpecUnit, _ := json["min_unit"].(string)
  2629. advice.DrugSpecUnit = drugSpecUnit
  2630. }
  2631. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2632. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2633. advice.SingleDose = singleDose
  2634. }
  2635. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2636. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2637. advice.SingleDoseUnit = singleDoseUnit
  2638. }
  2639. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2640. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2641. advice.PrescribingNumber = prescribingNumber
  2642. }
  2643. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2644. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2645. advice.PrescribingNumberUnit = prescribingNumberUnit
  2646. }
  2647. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2648. deliveryWay, _ := json["delivery_way"].(string)
  2649. advice.DeliveryWay = deliveryWay
  2650. }
  2651. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2652. executionFrequency, _ := json["execution_frequency"].(string)
  2653. advice.ExecutionFrequency = executionFrequency
  2654. }
  2655. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2656. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2657. advice.Price = price
  2658. }
  2659. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2660. med_list_codg, _ := json["medical_insurance_number"].(string)
  2661. advice.MedListCodg = med_list_codg
  2662. }
  2663. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2664. day := int64(json["day"].(float64))
  2665. advice.Day = day
  2666. }
  2667. return 0
  2668. }
  2669. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2670. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2671. id := int64(json["id"].(float64))
  2672. project.ID = id
  2673. historyProject, _ := service.GetHisProjectByID(id)
  2674. project.FeedetlSn = historyProject.FeedetlSn
  2675. }
  2676. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2677. project_id := int64(json["project_id"].(float64))
  2678. project.ProjectId = project_id
  2679. }
  2680. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2681. // price := int64(json["price"].(float64))
  2682. // formatInt_price := strconv.FormatInt(price, 10)
  2683. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2684. // project.Price = float_price
  2685. // }
  2686. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2687. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2688. project.Price = price
  2689. }
  2690. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2691. total, _ := json["total"].(string)
  2692. project.Count = total
  2693. }
  2694. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2695. medical_code, _ := json["medical_code"].(string)
  2696. project.MedListCodg = medical_code
  2697. }
  2698. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2699. single_dose, _ := json["single_dose"].(string)
  2700. project.SingleDose = single_dose
  2701. }
  2702. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2703. delivery_way, _ := json["delivery_way"].(string)
  2704. project.DeliveryWay = delivery_way
  2705. }
  2706. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2707. execution_frequency, _ := json["execution_frequency"].(string)
  2708. project.ExecutionFrequency = execution_frequency
  2709. }
  2710. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2711. remark, _ := json["remark"].(string)
  2712. project.Remark = remark
  2713. }
  2714. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2715. day, _ := json["number_days"].(string)
  2716. project.Day = day
  2717. }
  2718. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2719. unit, _ := json["unit"].(string)
  2720. project.Unit = unit
  2721. }
  2722. return 0
  2723. }
  2724. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2725. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2726. id := int64(json["id"].(float64))
  2727. historyAddtions, _ := service.GetHisAdditionByID(id)
  2728. additionalCharge.ID = id
  2729. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2730. }
  2731. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2732. item_id := int64(json["item_id"].(float64))
  2733. additionalCharge.ItemId = item_id
  2734. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2735. if config.ID > 0 {
  2736. if len(config.Code) > 0 {
  2737. additionalCharge.MedListCodg = config.Code
  2738. }
  2739. }
  2740. }
  2741. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2742. // price := int64(json["price"].(float64))
  2743. // formatInt_price := strconv.FormatInt(price, 10)
  2744. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2745. // additionalCharge.Price = float_price
  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() == "string" {
  2754. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2755. additionalCharge.Price = price
  2756. }
  2757. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2758. count, _ := json["count"].(string)
  2759. counts, _ := strconv.ParseInt(count, 10, 64)
  2760. additionalCharge.Count = counts
  2761. }
  2762. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2763. item_name, _ := json["item_name"].(string)
  2764. additionalCharge.ItemName = item_name
  2765. }
  2766. return 0
  2767. }
  2768. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2769. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2770. utils.ErrorLog("drug_name")
  2771. return enums.ErrorCodeParamWrong
  2772. }
  2773. adviceName, _ := json["drug_name"].(string)
  2774. if len(adviceName) == 0 {
  2775. utils.ErrorLog("len(advice_name) == 0")
  2776. return enums.ErrorCodeParamWrong
  2777. }
  2778. advice.AdviceName = adviceName
  2779. adviceDesc, _ := json["advice_desc"].(string)
  2780. advice.AdviceDesc = adviceDesc
  2781. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2782. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2783. advice.DrugSpec = drugSpec
  2784. }
  2785. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2786. remark, _ := json["remark"].(string)
  2787. advice.Remark = remark
  2788. }
  2789. if json["id"] == nil {
  2790. advice.DrugId = 0
  2791. } else {
  2792. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2793. drug_id := int64(json["id"].(float64))
  2794. advice.DrugId = drug_id
  2795. }
  2796. }
  2797. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  2798. groupno := int64(json["groupno"].(float64))
  2799. advice.Groupno = groupno
  2800. }
  2801. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  2802. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  2803. advice.HospApprFlag = hosp_appr_flag
  2804. }
  2805. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2806. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2807. advice.PrescribingNumber = prescribingNumber
  2808. }
  2809. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  2810. // frequency_type := int64(json["frequency_type"].(float64))
  2811. // advice.FrequencyType = frequency_type
  2812. //}
  2813. //
  2814. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  2815. // day_count := int64(json["day_count"].(float64))
  2816. // advice.DayCount = day_count
  2817. //}
  2818. //
  2819. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  2820. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  2821. // week_day, _ := json["week_day"].(string)
  2822. // advice.WeekDay = week_day
  2823. //}
  2824. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2825. drugSpecUnit, _ := json["min_unit"].(string)
  2826. advice.DrugSpecUnit = drugSpecUnit
  2827. }
  2828. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2829. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2830. advice.SingleDose = singleDose
  2831. }
  2832. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2833. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2834. advice.SingleDoseUnit = singleDoseUnit
  2835. }
  2836. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2837. deliveryWay, _ := json["delivery_way"].(string)
  2838. advice.DeliveryWay = deliveryWay
  2839. }
  2840. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2841. executionFrequency, _ := json["execution_frequency"].(string)
  2842. advice.ExecutionFrequency = executionFrequency
  2843. }
  2844. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2845. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2846. advice.Price = price
  2847. }
  2848. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2849. med_list_codg, _ := json["medical_insurance_number"].(string)
  2850. advice.MedListCodg = med_list_codg
  2851. }
  2852. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2853. day := int64(json["day"].(float64))
  2854. advice.Day = day
  2855. }
  2856. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2857. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2858. advice.PrescribingNumberUnit = prescribingNumberUnit
  2859. }
  2860. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2861. advice_id := int64(json["advice_id"].(float64))
  2862. advice.ID = advice_id
  2863. if advice.ID > 0 {
  2864. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2865. if err == nil {
  2866. if hisAdvice.ID > 0 {
  2867. advice.ExecutionTime = hisAdvice.ExecutionTime
  2868. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2869. advice.ExecutionState = hisAdvice.ExecutionState
  2870. advice.CheckTime = hisAdvice.CheckTime
  2871. advice.Checker = hisAdvice.Checker
  2872. advice.CheckState = hisAdvice.CheckState
  2873. advice.StartTime = hisAdvice.StartTime
  2874. advice.HospApprFlag = hisAdvice.HospApprFlag
  2875. if hisAdvice.UserOrgId == 10028 {
  2876. 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 {
  2877. advice.ExecutionTime = 0
  2878. advice.ExecutionStaff = 0
  2879. advice.ExecutionState = 2
  2880. advice.CheckTime = 0
  2881. advice.Checker = 0
  2882. advice.CheckState = 2
  2883. }
  2884. } else {
  2885. 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 {
  2886. advice.ExecutionTime = 0
  2887. advice.ExecutionStaff = 0
  2888. advice.ExecutionState = 2
  2889. advice.CheckTime = 0
  2890. advice.Checker = 0
  2891. advice.CheckState = 2
  2892. }
  2893. }
  2894. //advice.Groupno = hisAdvice.Groupno
  2895. }
  2896. }
  2897. }
  2898. }
  2899. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  2900. //
  2901. //if drugStockConfig.IsOpen == 1 {
  2902. //
  2903. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  2904. // if advice.ID == 0 { //医嘱不存在
  2905. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  2906. // drug.Total = drug.Total - advice.PrescribingNumber
  2907. // service.UpdateBaseDrugLib(&drug)
  2908. //
  2909. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  2910. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  2911. // drug.Total = drug.Total - num
  2912. // service.UpdateBaseDrugLib(&drug)
  2913. // }
  2914. //
  2915. // } else if advice.ID > 0 { //医嘱存在
  2916. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  2917. // var num float64
  2918. //
  2919. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  2920. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  2921. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  2922. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  2923. // drug.Total = drug.Total + num
  2924. // service.UpdateBaseDrugLib(&drug)
  2925. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  2926. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  2927. // drug.Total = drug.Total - num
  2928. // service.UpdateBaseDrugLib(&drug)
  2929. // }
  2930. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  2931. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2932. // if num2 > advice.PrescribingNumber {
  2933. // num = num2 - advice.PrescribingNumber
  2934. // drug.Total = drug.Total + num
  2935. // service.UpdateBaseDrugLib(&drug)
  2936. // } else if num2 < advice.PrescribingNumber {
  2937. // num = advice.PrescribingNumber - num2
  2938. // drug.Total = drug.Total - num
  2939. // service.UpdateBaseDrugLib(&drug)
  2940. // }
  2941. //
  2942. // }
  2943. //
  2944. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  2945. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  2946. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2947. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2948. // if num1 > num2 {
  2949. // num = num1 - num2
  2950. // drug.Total = drug.Total + num
  2951. // service.UpdateBaseDrugLib(&drug)
  2952. // } else if num1 < num2 {
  2953. // num = num2 - num1
  2954. // drug.Total = drug.Total - num
  2955. // service.UpdateBaseDrugLib(&drug)
  2956. // }
  2957. //
  2958. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  2959. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2960. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  2961. // if hisAdvice.PrescribingNumber > num2 {
  2962. // num = hisAdvice.PrescribingNumber - num2
  2963. // drug.Total = drug.Total + num
  2964. // service.UpdateBaseDrugLib(&drug)
  2965. // } else if num2 < advice.PrescribingNumber {
  2966. // num = num2 - hisAdvice.PrescribingNumber
  2967. // drug.Total = drug.Total - num
  2968. // service.UpdateBaseDrugLib(&drug)
  2969. // }
  2970. //
  2971. // }
  2972. // }
  2973. // }
  2974. //}
  2975. //
  2976. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2977. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2978. // advice.ExecutionTime = execution_time
  2979. //}
  2980. //
  2981. //
  2982. //
  2983. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2984. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2985. // advice.ExecutionStaff = execution_staff
  2986. //}
  2987. //
  2988. //
  2989. //
  2990. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2991. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2992. // advice.ExecutionState = execution_state
  2993. //}
  2994. //
  2995. //
  2996. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2997. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2998. // advice.CheckTime = check_time
  2999. //}
  3000. //
  3001. //
  3002. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3003. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3004. // advice.CheckState = check_state
  3005. //}
  3006. //
  3007. //
  3008. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3009. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3010. // advice.Checker = checker
  3011. //}
  3012. //
  3013. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3014. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3015. // advice.StartTime = start_time
  3016. //}
  3017. return 0
  3018. }
  3019. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3020. project.ExecutionStaff = 0
  3021. project.ExecutionState = 2
  3022. project.ExecutionTime = 0
  3023. project.Checker = 0
  3024. project.CheckState = 2
  3025. project.CheckTime = 0
  3026. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3027. id := int64(json["id"].(float64))
  3028. project.ID = id
  3029. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3030. project.ExecutionStaff = temp_project.ExecutionStaff
  3031. project.ExecutionState = temp_project.ExecutionState
  3032. project.ExecutionTime = temp_project.ExecutionTime
  3033. project.Checker = temp_project.Checker
  3034. project.CheckState = temp_project.CheckState
  3035. project.CheckTime = temp_project.CheckTime
  3036. project.TeamId = temp_project.TeamId
  3037. }
  3038. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3039. types := int64(json["type"].(float64))
  3040. project.Type = types
  3041. }
  3042. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3043. project_id := int64(json["project_id"].(float64))
  3044. project.ProjectId = project_id
  3045. }
  3046. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3047. team_id := int64(json["team_id"].(float64))
  3048. project.TeamId = team_id
  3049. }
  3050. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3051. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3052. project.Price = price
  3053. }
  3054. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3055. total, _ := json["total"].(string)
  3056. //totals, _ := strconv.ParseInt(total, 10, 64)
  3057. project.Count = total
  3058. }
  3059. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3060. medical_code, _ := json["medical_code"].(string)
  3061. project.MedListCodg = medical_code
  3062. }
  3063. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3064. single_dose, _ := json["single_dose"].(string)
  3065. project.SingleDose = single_dose
  3066. }
  3067. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3068. delivery_way, _ := json["delivery_way"].(string)
  3069. project.DeliveryWay = delivery_way
  3070. }
  3071. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3072. execution_frequency, _ := json["execution_frequency"].(string)
  3073. project.ExecutionFrequency = execution_frequency
  3074. }
  3075. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3076. remark, _ := json["remark"].(string)
  3077. project.Remark = remark
  3078. }
  3079. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3080. day, _ := json["number_days"].(string)
  3081. project.Day = day
  3082. }
  3083. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3084. unit, _ := json["unit"].(string)
  3085. project.Unit = unit
  3086. }
  3087. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3088. // frequency_type := int64(json["frequency_type"].(float64))
  3089. // project.FrequencyType = frequency_type
  3090. //}
  3091. //
  3092. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3093. // day_count := int64(json["day_count"].(float64))
  3094. // project.DayCount = day_count
  3095. //}
  3096. //
  3097. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3098. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3099. // week_day, _ := json["week_day"].(string)
  3100. // project.WeekDay = week_day
  3101. //}
  3102. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3103. //
  3104. //if project.ID == 0 {
  3105. // if stockConfig.IsOpen == 1 {
  3106. // if project.Type == 3 {
  3107. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3108. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3109. // good.Total = good.Total - f_count
  3110. // service.UpdateGoodInfo(&good)
  3111. // }
  3112. // }
  3113. //
  3114. //} else {
  3115. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3116. //
  3117. // if stockConfig.IsOpen == 1 {
  3118. // if project.Type == 3 {
  3119. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3120. // if project.Count < temp_project.Count {
  3121. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3122. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3123. //
  3124. // other_count := f_count_two - f_count_one
  3125. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3126. // good.Total = good.Total + other_count_two
  3127. // service.UpdateGoodInfo(&good)
  3128. // } else 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_one - f_count_two
  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. // }
  3137. //
  3138. // }
  3139. // }
  3140. //
  3141. //}
  3142. return 0
  3143. }
  3144. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3145. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3146. id := int64(json["id"].(float64))
  3147. additionalCharge.ID = id
  3148. }
  3149. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3150. item_id := int64(json["item_id"].(float64))
  3151. additionalCharge.ItemId = item_id
  3152. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3153. if config.ID > 0 {
  3154. if len(config.Code) > 0 {
  3155. additionalCharge.MedListCodg = config.Code
  3156. }
  3157. }
  3158. }
  3159. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3160. // price := int64(json["price"].(float64))
  3161. // formatInt_price := strconv.FormatInt(price, 10)
  3162. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3163. // additionalCharge.Price = float_price
  3164. // }
  3165. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3166. // price := int64(json["price"].(float64))
  3167. // formatInt_price := strconv.FormatInt(price, 10)
  3168. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3169. // additionalCharge.Price = float_price
  3170. //}
  3171. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3172. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3173. additionalCharge.Price = price
  3174. }
  3175. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3176. count, _ := json["count"].(string)
  3177. counts, _ := strconv.ParseInt(count, 10, 64)
  3178. additionalCharge.Count = counts
  3179. }
  3180. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3181. item_name, _ := json["item_name"].(string)
  3182. additionalCharge.ItemName = item_name
  3183. }
  3184. return 0
  3185. }
  3186. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3187. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3188. utils.ErrorLog("drug_name")
  3189. return enums.ErrorCodeParamWrong
  3190. }
  3191. adviceName, _ := json["drug_name"].(string)
  3192. if len(adviceName) == 0 {
  3193. utils.ErrorLog("len(advice_name) == 0")
  3194. return enums.ErrorCodeParamWrong
  3195. }
  3196. advice.AdviceName = adviceName
  3197. adviceDesc, _ := json["advice_desc"].(string)
  3198. advice.AdviceDesc = adviceDesc
  3199. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3200. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3201. advice.DrugSpec = drugSpec
  3202. }
  3203. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3204. remark, _ := json["remark"].(string)
  3205. advice.Remark = remark
  3206. }
  3207. if json["id"] == nil {
  3208. advice.DrugId = 0
  3209. } else {
  3210. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3211. drug_id := int64(json["id"].(float64))
  3212. advice.DrugId = drug_id
  3213. }
  3214. }
  3215. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3216. drugSpecUnit, _ := json["min_unit"].(string)
  3217. advice.DrugSpecUnit = drugSpecUnit
  3218. }
  3219. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3220. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3221. advice.SingleDose = singleDose
  3222. }
  3223. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3224. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3225. advice.SingleDoseUnit = singleDoseUnit
  3226. }
  3227. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3228. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3229. advice.PrescribingNumber = prescribingNumber
  3230. }
  3231. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3232. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3233. advice.PrescribingNumberUnit = prescribingNumberUnit
  3234. }
  3235. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3236. deliveryWay, _ := json["delivery_way"].(string)
  3237. advice.DeliveryWay = deliveryWay
  3238. }
  3239. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3240. executionFrequency, _ := json["execution_frequency"].(string)
  3241. advice.ExecutionFrequency = executionFrequency
  3242. }
  3243. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3244. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3245. advice.Price = price
  3246. }
  3247. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3248. med_list_codg, _ := json["medical_insurance_number"].(string)
  3249. advice.MedListCodg = med_list_codg
  3250. }
  3251. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3252. day := int64(json["day"].(float64))
  3253. advice.Day = day
  3254. }
  3255. return 0
  3256. }
  3257. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3258. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3259. types := int64(json["type"].(float64))
  3260. project.Type = types
  3261. }
  3262. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3263. project_id := int64(json["project_id"].(float64))
  3264. project.ProjectId = project_id
  3265. }
  3266. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3267. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3268. project.Price = price
  3269. }
  3270. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3271. total, _ := json["total"].(string)
  3272. //totals, _ := strconv.ParseInt(total, 10, 64)
  3273. project.Count = total
  3274. }
  3275. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3276. medical_code, _ := json["medical_code"].(string)
  3277. project.MedListCodg = medical_code
  3278. }
  3279. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3280. single_dose, _ := json["single_dose"].(string)
  3281. project.SingleDose = single_dose
  3282. }
  3283. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3284. delivery_way, _ := json["delivery_way"].(string)
  3285. project.DeliveryWay = delivery_way
  3286. }
  3287. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3288. execution_frequency, _ := json["execution_frequency"].(string)
  3289. project.ExecutionFrequency = execution_frequency
  3290. }
  3291. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3292. remark, _ := json["remark"].(string)
  3293. project.Remark = remark
  3294. }
  3295. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3296. day, _ := json["number_days"].(string)
  3297. project.Day = day
  3298. }
  3299. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3300. unit, _ := json["unit"].(string)
  3301. project.Unit = unit
  3302. }
  3303. return 0
  3304. }
  3305. func (c *HisApiController) GetHisOrderList() {
  3306. page, _ := c.GetInt64("page", -1)
  3307. limit, _ := c.GetInt64("limit", -1)
  3308. start_time := c.GetString("start_time")
  3309. end_time := c.GetString("end_time")
  3310. types, _ := c.GetInt64("type", 0)
  3311. keywords := c.GetString("keywords")
  3312. p_type, _ := c.GetInt64("p_type", 0)
  3313. sort_type, _ := c.GetInt64("sort_type", 0)
  3314. timeLayout := "2006-01-02"
  3315. loc, _ := time.LoadLocation("Local")
  3316. var startTime int64
  3317. if len(start_time) > 0 {
  3318. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3319. if err != nil {
  3320. fmt.Println(err)
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3322. return
  3323. }
  3324. startTime = theTime.Unix()
  3325. }
  3326. var endTime int64
  3327. if len(end_time) > 0 {
  3328. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3329. if err != nil {
  3330. utils.ErrorLog(err.Error())
  3331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3332. return
  3333. }
  3334. endTime = theTime.Unix()
  3335. }
  3336. adminUser := c.GetAdminUserInfo()
  3337. org_id := adminUser.CurrentOrgId
  3338. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type)
  3339. for _, item := range order {
  3340. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3341. item.DoctorName = info.Doctor
  3342. item.DepartmentName = info.XtHisDepartment.Name
  3343. }
  3344. if err == nil {
  3345. c.ServeSuccessJSON(map[string]interface{}{
  3346. "order": order,
  3347. "total": total,
  3348. })
  3349. } else {
  3350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3351. return
  3352. }
  3353. }
  3354. func (c *HisApiController) GetHisOrder() {
  3355. patient_id, _ := c.GetInt64("patient_id", 0)
  3356. number := c.GetString("number")
  3357. adminInfo := c.GetAdminUserInfo()
  3358. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3359. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3360. if err == nil {
  3361. c.ServeSuccessJSON(map[string]interface{}{
  3362. "order": order,
  3363. "prescription": prescriptions,
  3364. })
  3365. } else {
  3366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3367. return
  3368. }
  3369. }
  3370. func (c *HisApiController) GetHisPrescriptionList() {
  3371. record_date := c.GetString("record_date")
  3372. keywords := c.GetString("keywords")
  3373. page, _ := c.GetInt64("page")
  3374. limit, _ := c.GetInt64("limit")
  3375. timeLayout := "2006-01-02"
  3376. loc, _ := time.LoadLocation("Local")
  3377. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3378. if err != nil {
  3379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3380. return
  3381. }
  3382. recordDateTime := theTime.Unix()
  3383. adminInfo := c.GetAdminUserInfo()
  3384. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3385. //adminInfo := c.GetAdminUserInfo()
  3386. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3387. //fmt.Println(prescriptionOrder)
  3388. if err == nil {
  3389. c.ServeSuccessJSON(map[string]interface{}{
  3390. "order": prescriptionOrder,
  3391. "total": total,
  3392. })
  3393. } else {
  3394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3395. return
  3396. }
  3397. }
  3398. func (c *HisApiController) GetHisPrescriptionInfo() {
  3399. id, _ := c.GetInt64("id")
  3400. adminInfo := c.GetAdminUserInfo()
  3401. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3402. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3403. if err == nil {
  3404. c.ServeSuccessJSON(map[string]interface{}{
  3405. "order": prescriptionOrder,
  3406. "prescription": prescription,
  3407. })
  3408. } else {
  3409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3410. return
  3411. }
  3412. }
  3413. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3414. adminUser := c.GetAdminUserInfo()
  3415. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3416. c.ServeSuccessJSON(map[string]interface{}{
  3417. "config": config,
  3418. })
  3419. }
  3420. type ResultTwo struct {
  3421. ErrMsg interface{} `json:"err_msg"`
  3422. InfRefmsgid string `json:"inf_refmsgid"`
  3423. Infcode int64 `json:"infcode"`
  3424. Output struct {
  3425. Baseinfo struct {
  3426. Age float64 `json:"age"`
  3427. Brdy string `json:"brdy"`
  3428. Certno string `json:"certno"`
  3429. Gend string `json:"gend"`
  3430. Naty string `json:"naty"`
  3431. PsnCertType string `json:"psn_cert_type"`
  3432. PsnName string `json:"psn_name"`
  3433. PsnNo string `json:"psn_no"`
  3434. } `json:"baseinfo"`
  3435. Idetinfo []interface{} `json:"idetinfo"`
  3436. Iinfo []struct {
  3437. Balc float64 `json:"balc"`
  3438. CvlservFlag string `json:"cvlserv_flag"`
  3439. EmpName string `json:"emp_name"`
  3440. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3441. Insutype string `json:"insutype"`
  3442. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3443. PausInsuDate interface{} `json:"paus_insu_date"`
  3444. PsnInsuDate string `json:"psn_insu_date"`
  3445. PsnInsuStas string `json:"psn_insu_stas"`
  3446. PsnType string `json:"psn_type"`
  3447. } `json:"insuinfo"`
  3448. } `json:"output"`
  3449. RefmsgTime string `json:"refmsg_time"`
  3450. RespondTime string `json:"respond_time"`
  3451. Signtype interface{} `json:"signtype"`
  3452. WarnInfo interface{} `json:"warn_info"`
  3453. }
  3454. type ResultThree struct {
  3455. Cainfo interface{} `json:"cainfo"`
  3456. ErrMsg interface{} `json:"err_msg"`
  3457. InfRefmsgid string `json:"inf_refmsgid"`
  3458. Infcode int64 `json:"infcode"`
  3459. Output struct {
  3460. Data struct {
  3461. IptOtpNo string `json:"ipt_otp_no"`
  3462. MdtrtID string `json:"mdtrt_id"`
  3463. PsnNo string `json:"psn_no"`
  3464. } `json:"data"`
  3465. } `json:"output"`
  3466. RefmsgTime string `json:"refmsg_time"`
  3467. RespondTime string `json:"respond_time"`
  3468. Signtype interface{} `json:"signtype"`
  3469. WarnMsg interface{} `json:"warn_msg"`
  3470. }
  3471. type ResultFour struct {
  3472. Cainfo string `json:"cainfo"`
  3473. ErrMsg string `json:"err_msg"`
  3474. InfRefmsgid string `json:"inf_refmsgid"`
  3475. Infcode int64 `json:"infcode"`
  3476. Output struct {
  3477. Result []struct {
  3478. BasMednFlag string `json:"bas_medn_flag"`
  3479. ChldMedcFlag string `json:"chld_medc_flag"`
  3480. ChrgitmLv string `json:"chrgitm_lv"`
  3481. Cnt float64 `json:"cnt"`
  3482. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3483. DrtReimFlag string `json:"drt_reim_flag"`
  3484. FeedetlSn string `json:"feedetl_sn"`
  3485. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3486. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3487. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3488. ListSpItemFlag string `json:"list_sp_item_flag"`
  3489. LmtUsedFlag string `json:"lmt_used_flag"`
  3490. MedChrgitmType string `json:"med_chrgitm_type"`
  3491. Memo string `json:"memo"`
  3492. OverlmtAmt float64 `json:"overlmt_amt"`
  3493. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3494. Pric float64 `json:"pric"`
  3495. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3496. SelfpayProp float64 `json:"selfpay_prop"`
  3497. } `json:"result"`
  3498. } `json:"output"`
  3499. RefmsgTime string `json:"refmsg_time"`
  3500. RespondTime string `json:"respond_time"`
  3501. Signtype string `json:"signtype"`
  3502. WarnMsg string `json:"warn_msg"`
  3503. }
  3504. type ResultFive struct {
  3505. Insutype string `json:"insutype"`
  3506. }
  3507. type ResultSix struct {
  3508. Cainfo interface{} `json:"cainfo"`
  3509. ErrMsg interface{} `json:"err_msg"`
  3510. InfRefmsgid string `json:"inf_refmsgid"`
  3511. Infcode int64 `json:"infcode"`
  3512. Output struct {
  3513. } `json:"output"`
  3514. RefmsgTime string `json:"refmsg_time"`
  3515. RespondTime string `json:"respond_time"`
  3516. Signtype interface{} `json:"signtype"`
  3517. WarnMsg interface{} `json:"warn_msg"`
  3518. }
  3519. type ResultSeven struct {
  3520. Cainfo string `json:"cainfo"`
  3521. ErrMsg string `json:"err_msg"`
  3522. InfRefmsgid string `json:"inf_refmsgid"`
  3523. Infcode int64 `json:"infcode"`
  3524. Output struct {
  3525. Setldetail []interface{} `json:"setldetail"`
  3526. Setlinfo struct {
  3527. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3528. AcctPay float64 `json:"acct_pay"`
  3529. ActPayDedc float64 `json:"act_pay_dedc"`
  3530. Age float64 `json:"age"`
  3531. Balc float64 `json:"balc"`
  3532. Brdy string `json:"brdy"`
  3533. Certno string `json:"certno"`
  3534. ClrOptins string `json:"clr_optins"`
  3535. ClrType string `json:"clr_type"`
  3536. ClrWay string `json:"clr_way"`
  3537. CvlservFlag string `json:"cvlserv_flag"`
  3538. CvlservPay float64 `json:"cvlserv_pay"`
  3539. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3540. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3541. Gend string `json:"gend"`
  3542. HifesPay float64 `json:"hifes_pay"`
  3543. HifmiPay float64 `json:"hifmi_pay"`
  3544. HifobPay float64 `json:"hifob_pay"`
  3545. HifpPay float64 `json:"hifp_pay"`
  3546. HospPartAmt float64 `json:"hosp_part_amt"`
  3547. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3548. Insutype string `json:"insutype"`
  3549. MafPay float64 `json:"maf_pay"`
  3550. MdtrtCertType string `json:"mdtrt_cert_type"`
  3551. MdtrtID string `json:"mdtrt_id"`
  3552. MedType string `json:"med_type"`
  3553. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3554. MedinsSetlID string `json:"medins_setl_id"`
  3555. Naty string `json:"naty"`
  3556. OthPay float64 `json:"oth_pay"`
  3557. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3558. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3559. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3560. PsnCashPay float64 `json:"psn_cash_pay"`
  3561. PsnCertType string `json:"psn_cert_type"`
  3562. PsnName string `json:"psn_name"`
  3563. PsnNo string `json:"psn_no"`
  3564. PsnPartAmt float64 `json:"psn_part_amt"`
  3565. PsnType string `json:"psn_type"`
  3566. SetlID string `json:"setl_id"`
  3567. SetlTime string `json:"setl_time"`
  3568. } `json:"setlinfo"`
  3569. } `json:"output"`
  3570. RefmsgTime string `json:"refmsg_time"`
  3571. RespondTime string `json:"respond_time"`
  3572. Signtype interface{} `json:"signtype"`
  3573. WarnMsg interface{} `json:"warn_msg"`
  3574. }
  3575. type ResultEight struct {
  3576. Cainfo string `json:"cainfo"`
  3577. ErrMsg string `json:"err_msg"`
  3578. InfRefmsgid string `json:"inf_refmsgid"`
  3579. Infcode int64 `json:"infcode"`
  3580. Output struct {
  3581. Stmtinfo struct {
  3582. SetlOptins string `json:"setl_optins"`
  3583. StmtRslt string `json:"stmt_rslt"`
  3584. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3585. } `json:"stmtinfo"`
  3586. } `json:"output"`
  3587. RefmsgTime string `json:"refmsg_time"`
  3588. RespondTime string `json:"respond_time"`
  3589. Signtype interface{} `json:"signtype"`
  3590. WarnMsg interface{} `json:"warn_msg"`
  3591. }
  3592. type ResultNine struct {
  3593. Cainfo string `json:"cainfo"`
  3594. ErrMsg string `json:"err_msg"`
  3595. InfRefmsgid string `json:"inf_refmsgid"`
  3596. Infcode int64 `json:"infcode"`
  3597. Output struct {
  3598. FileQuryNo string `json:"file_qury_no"`
  3599. } `json:"output"`
  3600. RefmsgTime string `json:"refmsg_time"`
  3601. RespondTime string `json:"respond_time"`
  3602. Signtype interface{} `json:"signtype"`
  3603. WarnMsg interface{} `json:"warn_msg"`
  3604. }
  3605. type ResultTen struct {
  3606. Cainfo string `json:"cainfo"`
  3607. ErrMsg string `json:"err_msg"`
  3608. InfRefmsgid string `json:"inf_refmsgid"`
  3609. Infcode int64 `json:"infcode"`
  3610. Output struct {
  3611. DldEndtime string `json:"dld_endtime"`
  3612. FileQuryNo string `json:"file_qury_no"`
  3613. Filename string `json:"filename"`
  3614. } `json:"output"`
  3615. RefmsgTime string `json:"refmsg_time"`
  3616. RespondTime string `json:"respond_time"`
  3617. Signtype interface{} `json:"signtype"`
  3618. WarnMsg interface{} `json:"warn_msg"`
  3619. }
  3620. type ResultEleven struct {
  3621. Cainfo string `json:"cainfo"`
  3622. ErrMsg string `json:"err_msg"`
  3623. InfRefmsgid string `json:"inf_refmsgid"`
  3624. Infcode int64 `json:"infcode"`
  3625. Output struct {
  3626. Setlinfo struct {
  3627. FixmedinsName string `json:"fixmedins_name"`
  3628. FixmedinsCode string `json:"fixmedins_code"`
  3629. PsnNo string `json:"psn_no"`
  3630. PsnName string `json:"psn_name"`
  3631. HifobPay float64 `json:"hifob_pay"`
  3632. Gend string `json:"gend"`
  3633. Brdy string `json:"brdy"`
  3634. PsnCertType string `json:"psn_cert_type"`
  3635. PsnType string `json:"psn_type"`
  3636. EmpName string `json:"emp_name"`
  3637. Certno string `json:"certno"`
  3638. Insutype string `json:"insutype"`
  3639. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3640. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3641. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3642. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3643. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3644. ActPayDedc float64 `json:"act_pay_dedc"`
  3645. HifpPay float64 `json:"hifp_pay"`
  3646. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3647. CvlservPay float64 `json:"cvlserv_pay"`
  3648. HifesPay float64 `json:"hifes_pay"`
  3649. HifmiPay float64 `json:"hifmi_pay"`
  3650. MafPay float64 `json:"maf_pay"`
  3651. OthPay float64 `json:"oth_pay"`
  3652. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3653. PsnPay float64 `json:"psn_pay"`
  3654. AcctPay float64 `json:"acct_pay"`
  3655. CashPayamt float64 `json:"cash_payamt"`
  3656. Balc float64 `json:"balc"`
  3657. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3658. MedinsSetlId string `json:"medins_setl_id"`
  3659. RefdSetlFlag string `json:"refd_setl_flag"`
  3660. SetlTime string `json:"setl_time"`
  3661. MedType string `json:"med_type"`
  3662. } `json:"setlinfo"`
  3663. } `json:"output"`
  3664. RefmsgTime string `json:"refmsg_time"`
  3665. RespondTime string `json:"respond_time"`
  3666. Signtype interface{} `json:"signtype"`
  3667. WarnMsg interface{} `json:"warn_msg"`
  3668. }
  3669. type Custom struct {
  3670. DetItemFeeSumamt string
  3671. Cut string
  3672. FeedetlSn string
  3673. Price string
  3674. MedListCodg string
  3675. Type int64
  3676. AdviceId int64
  3677. ProjectId int64
  3678. ItemId int64
  3679. }
  3680. //获取个人信息----挂号-----上传就诊信息
  3681. func (c *HisApiController) GetRegisterInfo() {
  3682. id, _ := c.GetInt64("id")
  3683. record_time := c.GetString("record_time")
  3684. settlementValue, _ := c.GetInt64("settlement_value")
  3685. medical_insurance_card := c.GetString("medical_insurance_card")
  3686. name := c.GetString("name")
  3687. id_card_type, _ := c.GetInt64("id_card_type")
  3688. certificates, _ := c.GetInt64("certificates")
  3689. medical_care, _ := c.GetInt64("medical_care")
  3690. birthday := c.GetString("birthday")
  3691. age, _ := c.GetInt64("age")
  3692. id_card := c.GetString("id_card")
  3693. register_type, _ := c.GetInt64("register")
  3694. doctor, _ := c.GetInt64("doctor")
  3695. department, _ := c.GetInt64("department")
  3696. gender, _ := c.GetInt64("sex")
  3697. phone := c.GetString("phone")
  3698. registration_fee, _ := c.GetFloat("registration_fee")
  3699. medical_expenses, _ := c.GetFloat("medical_expenses")
  3700. social_type, _ := c.GetInt64("social_type")
  3701. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3702. diagnosis_ids := c.GetString("diagnosis")
  3703. sick_type, _ := c.GetInt64("sick_type")
  3704. reg_type := c.GetString("p_type")
  3705. timeLayout := "2006-01-02"
  3706. loc, _ := time.LoadLocation("Local")
  3707. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3708. birthUnix := birthdays.Unix()
  3709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3710. if err != nil {
  3711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3712. return
  3713. }
  3714. recordDateTime := theTime.Unix()
  3715. adminInfo := c.GetAdminUserInfo()
  3716. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3717. if tempPatient.ID == 0 {
  3718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3719. return
  3720. }
  3721. var patient service.Patients
  3722. if id == 0 {
  3723. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3724. } else {
  3725. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3726. }
  3727. if patient.ID == 0 {
  3728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3729. return
  3730. }
  3731. if len(patient.IdCardNo) == 0 {
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3733. return
  3734. }
  3735. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3736. if len(his) >= 1 {
  3737. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3738. if len(his) >= 1 && order.ID == 0 {
  3739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3740. return
  3741. }
  3742. }
  3743. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3744. fmt.Println(timeStr)
  3745. timeArr := strings.Split(timeStr, " ")
  3746. fmt.Println(timeArr)
  3747. timeArrTwo := strings.Split(timeArr[0], "-")
  3748. timeArrThree := strings.Split(timeArr[1], ":")
  3749. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3750. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3751. if len(lists) == 0 {
  3752. var hisPatient models.XtHisPatient
  3753. hisPatient = models.XtHisPatient{
  3754. Name: name,
  3755. Age: age,
  3756. Gender: gender,
  3757. Birthday: birthUnix,
  3758. Phone: phone,
  3759. MedicalTreatmentType: medical_care,
  3760. IdType: certificates,
  3761. IdCardNo: id_card,
  3762. BalanceAccountsType: settlementValue,
  3763. SocialType: social_type,
  3764. MedicalInsuranceNumber: medical_insurance_card,
  3765. RegisterType: register_type,
  3766. RegisterCost: registration_fee,
  3767. TreatmentCost: medical_expenses,
  3768. AdminUserId: adminInfo.AdminUser.Id,
  3769. UserOrgId: adminInfo.CurrentOrgId,
  3770. Status: 1,
  3771. RecordDate: recordDateTime,
  3772. IsReturn: 1,
  3773. PatientId: patient.ID,
  3774. Ctime: time.Now().Unix(),
  3775. Mtime: time.Now().Unix(),
  3776. Number: str,
  3777. IdCardType: id_card_type,
  3778. Departments: department,
  3779. Doctor: doctor,
  3780. PType: reg_type,
  3781. Diagnosis: diagnosis_ids,
  3782. SickType: sick_type,
  3783. }
  3784. service.CreateHisPatient(&hisPatient)
  3785. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3786. c.ServeSuccessJSON(map[string]interface{}{
  3787. "his_info": hisPatient,
  3788. })
  3789. } else {
  3790. //chrgBchno := rand.Intn(1000000) + 10000
  3791. var hisPatient models.XtHisPatient
  3792. hisPatient = models.XtHisPatient{
  3793. Name: name,
  3794. Age: age,
  3795. Gender: gender,
  3796. Birthday: birthUnix,
  3797. Phone: phone,
  3798. MedicalTreatmentType: medical_care,
  3799. IdType: certificates,
  3800. IdCardNo: id_card,
  3801. BalanceAccountsType: settlementValue,
  3802. SocialType: social_type,
  3803. MedicalInsuranceNumber: medical_insurance_card,
  3804. RegisterType: register_type,
  3805. RegisterCost: registration_fee,
  3806. TreatmentCost: medical_expenses,
  3807. AdminUserId: adminInfo.AdminUser.Id,
  3808. UserOrgId: adminInfo.CurrentOrgId,
  3809. Status: 1,
  3810. RecordDate: recordDateTime,
  3811. IsReturn: 1,
  3812. PatientId: patient.ID,
  3813. Ctime: time.Now().Unix(),
  3814. Mtime: time.Now().Unix(),
  3815. Number: str,
  3816. IdCardType: id_card_type,
  3817. Departments: department,
  3818. Doctor: doctor,
  3819. PType: reg_type,
  3820. Diagnosis: diagnosis_ids,
  3821. SickType: sick_type,
  3822. }
  3823. service.CreateHisPatient(&hisPatient)
  3824. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3825. c.ServeSuccessJSON(map[string]interface{}{
  3826. "his_info": hisPatient,
  3827. })
  3828. }
  3829. }
  3830. //上传明细----结算
  3831. func (c *HisApiController) GetUploadInfo() {
  3832. id, _ := c.GetInt64("id")
  3833. record_time := c.GetString("record_time")
  3834. his_patient_id, _ := c.GetInt64("his_patient_id")
  3835. pay_way, _ := c.GetInt64("pay_way")
  3836. pay_price, _ := c.GetFloat("pay_price")
  3837. pay_card_no := c.GetString("pay_card_no")
  3838. discount_price, _ := c.GetFloat("discount_price")
  3839. preferential_price, _ := c.GetFloat("preferential_price")
  3840. reality_price, _ := c.GetFloat("reality_price")
  3841. found_price, _ := c.GetFloat("found_price")
  3842. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3843. private_price, _ := c.GetFloat("private_price")
  3844. timeLayout := "2006-01-02"
  3845. loc, _ := time.LoadLocation("Local")
  3846. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3847. fapiao_code := c.GetString("fapiao_code")
  3848. fapiao_number := c.GetString("fapiao_number")
  3849. diagnosis_id := c.GetString("diagnosis")
  3850. sick_type, _ := c.GetInt64("sick_type")
  3851. reg_type, _ := c.GetInt64("p_type")
  3852. order_id, _ := c.GetInt64("order_id")
  3853. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  3854. tempOrder, _ := service.GetHisOrderByID(order_id)
  3855. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3856. if err != nil {
  3857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3858. return
  3859. }
  3860. recordDateTime := theTime.Unix()
  3861. adminUser := c.GetAdminUserInfo()
  3862. var prescriptions []*models.HisPrescription
  3863. var start_time int64
  3864. var end_time int64
  3865. ids_str := c.GetString("ids")
  3866. ids_arr := strings.Split(ids_str, ",")
  3867. if tempOrder.ID == 0 {
  3868. if settle_accounts_type == 1 { //日结
  3869. fmt.Println(reg_type)
  3870. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  3871. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3872. } else {
  3873. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  3874. }
  3875. } else { //月结
  3876. start_time_str := c.GetString("start_time")
  3877. end_time_str := c.GetString("end_time")
  3878. timeLayout := "2006-01-02"
  3879. loc, _ := time.LoadLocation("Local")
  3880. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3881. if err != nil {
  3882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3883. return
  3884. }
  3885. recordStartTime := theStartTime.Unix()
  3886. start_time = recordStartTime
  3887. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3888. if err != nil {
  3889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3890. return
  3891. }
  3892. recordEndTime := theEndTime.Unix()
  3893. end_time = recordEndTime
  3894. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3895. }
  3896. timestamp := time.Now().Unix()
  3897. tempTime := time.Unix(timestamp, 0)
  3898. timeFormat := tempTime.Format("20060102150405")
  3899. chrgBchno := rand.Intn(100000) + 10000
  3900. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3901. strconv.FormatInt(his.PatientId, 10)
  3902. var ids []int64
  3903. for _, item := range prescriptions {
  3904. ids = append(ids, item.ID)
  3905. }
  3906. var total float64
  3907. for _, item := range prescriptions {
  3908. fmt.Println(item)
  3909. if item.Type == 1 { //药品
  3910. for _, subItem := range item.HisDoctorAdviceInfo {
  3911. total = total + (subItem.Price * subItem.PrescribingNumber)
  3912. }
  3913. }
  3914. if item.Type == 2 { //项目
  3915. for _, subItem := range item.HisPrescriptionProject {
  3916. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3917. total = total + (subItem.Price * cnt)
  3918. }
  3919. }
  3920. for _, subItem := range item.HisAdditionalCharge {
  3921. total = total + (subItem.Price * float64(subItem.Count))
  3922. }
  3923. }
  3924. if reg_type == 1111 || reg_type == 1112 {
  3925. reg_type = 11
  3926. }
  3927. allTotal := fmt.Sprintf("%.4f", total)
  3928. totals, _ := strconv.ParseFloat(allTotal, 64)
  3929. order := &models.HisOrder{
  3930. UserOrgId: adminUser.CurrentOrgId,
  3931. HisPatientId: his.ID,
  3932. PatientId: id,
  3933. SettleAccountsDate: recordDateTime,
  3934. Ctime: time.Now().Unix(),
  3935. Mtime: time.Now().Unix(),
  3936. Status: 1,
  3937. OrderStatus: 2,
  3938. MdtrtId: his.Number,
  3939. Number: chrg_bchno,
  3940. MedfeeSumamt: totals,
  3941. PayWay: pay_way,
  3942. PayPrice: pay_price,
  3943. MedType: strconv.Itoa(int(reg_type)),
  3944. PayCardNo: pay_card_no,
  3945. DiscountPrice: discount_price,
  3946. PreferentialPrice: preferential_price,
  3947. RealityPrice: reality_price,
  3948. FoundPrice: found_price,
  3949. MedicalInsurancePrice: medical_insurance_price,
  3950. PrivatePrice: private_price,
  3951. SettleEndTime: end_time,
  3952. SettleStartTime: start_time,
  3953. SettleType: settle_accounts_type,
  3954. FaPiaoCode: fapiao_code,
  3955. FaPiaoNumber: fapiao_number,
  3956. Diagnosis: diagnosis_id,
  3957. PType: 2,
  3958. }
  3959. err = service.CreateOrder(order)
  3960. if err != nil {
  3961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3962. return
  3963. }
  3964. var customs []*Custom
  3965. for _, item := range prescriptions {
  3966. if item.Type == 1 { //药品
  3967. for _, subItem := range item.HisDoctorAdviceInfo {
  3968. cus := &Custom{
  3969. AdviceId: subItem.ID,
  3970. ProjectId: 0,
  3971. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3972. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3973. FeedetlSn: subItem.FeedetlSn,
  3974. Price: fmt.Sprintf("%.2f", subItem.Price),
  3975. MedListCodg: subItem.MedListCodg,
  3976. Type: 1,
  3977. }
  3978. customs = append(customs, cus)
  3979. }
  3980. }
  3981. if item.Type == 2 { //项目
  3982. for _, subItem := range item.HisPrescriptionProject {
  3983. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3984. cus := &Custom{
  3985. AdviceId: 0,
  3986. ProjectId: subItem.ID,
  3987. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3988. Cut: fmt.Sprintf("%.4f", cnt),
  3989. FeedetlSn: subItem.FeedetlSn,
  3990. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3991. MedListCodg: subItem.MedListCodg,
  3992. Type: 2,
  3993. }
  3994. customs = append(customs, cus)
  3995. }
  3996. }
  3997. for _, item := range item.HisAdditionalCharge {
  3998. cus := &Custom{
  3999. ItemId: item.ID,
  4000. AdviceId: 0,
  4001. ProjectId: 0,
  4002. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4003. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4004. FeedetlSn: item.FeedetlSn,
  4005. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4006. MedListCodg: item.XtHisAddtionConfig.Code,
  4007. Type: 3,
  4008. }
  4009. customs = append(customs, cus)
  4010. }
  4011. }
  4012. for _, item := range customs {
  4013. var advice_id int64 = 0
  4014. var project_id int64 = 0
  4015. var item_id int64 = 0
  4016. var types int64 = 0
  4017. if item.Type == 1 {
  4018. advice_id = item.AdviceId
  4019. project_id = 0
  4020. item_id = 0
  4021. } else if item.Type == 2 {
  4022. advice_id = 0
  4023. item_id = 0
  4024. project_id = item.ProjectId
  4025. } else if item.Type == 3 {
  4026. advice_id = 0
  4027. item_id = item.ItemId
  4028. project_id = 0
  4029. }
  4030. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4031. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4032. pric, _ := strconv.ParseFloat(item.Price, 32)
  4033. info := &models.HisOrderInfo{
  4034. OrderNumber: order.Number,
  4035. UploadDate: time.Now().Unix(),
  4036. AdviceId: advice_id,
  4037. DetItemFeeSumamt: detItemFeeSumamt,
  4038. Cnt: cut,
  4039. Pric: pric,
  4040. PatientId: id,
  4041. Status: 1,
  4042. Mtime: time.Now().Unix(),
  4043. Ctime: time.Now().Unix(),
  4044. UserOrgId: adminUser.CurrentOrgId,
  4045. HisPatientId: his.ID,
  4046. OrderId: order.ID,
  4047. ProjectId: project_id,
  4048. Type: types,
  4049. ItemId: item_id,
  4050. }
  4051. service.CreateOrderInfo(info)
  4052. }
  4053. his.Diagnosis = diagnosis_id
  4054. his.SickType = sick_type
  4055. his.RegisterType = reg_type
  4056. his.MedicalTreatmentType = reg_type
  4057. service.UpdataHisPateint(&his)
  4058. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4059. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4060. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4061. if err == nil {
  4062. c.ServeSuccessJSON(map[string]interface{}{
  4063. "msg": "结算成功",
  4064. })
  4065. }
  4066. } else {
  4067. if tempOrder.IsPre > 0 {
  4068. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4069. totals, _ := strconv.ParseFloat(allTotal, 64)
  4070. tempOrder.OrderStatus = 2
  4071. tempOrder.PayWay = pay_way
  4072. tempOrder.PayPrice = pay_price
  4073. tempOrder.PayCardNo = pay_card_no
  4074. tempOrder.DiscountPrice = discount_price
  4075. tempOrder.PreferentialPrice = preferential_price
  4076. tempOrder.RealityPrice = reality_price
  4077. tempOrder.FoundPrice = found_price
  4078. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4079. tempOrder.PrivatePrice = private_price
  4080. tempOrder.FaPiaoCode = fapiao_code
  4081. tempOrder.FaPiaoNumber = fapiao_number
  4082. tempOrder.PType = 2
  4083. tempOrder.MedfeeSumamt = totals
  4084. tempOrder.Diagnosis = diagnosis_id
  4085. err = service.SaveHisOrder(&tempOrder)
  4086. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4087. if err != nil {
  4088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4089. return
  4090. }
  4091. if err == nil {
  4092. c.ServeSuccessJSON(map[string]interface{}{
  4093. "msg": "结算成功",
  4094. })
  4095. }
  4096. }
  4097. }
  4098. }
  4099. //退款
  4100. func (c *HisApiController) Refund() {
  4101. order_id, _ := c.GetInt64("order_id")
  4102. order, _ := service.GetHisOrderByID(order_id)
  4103. adminUser := c.GetAdminUserInfo()
  4104. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4105. if err == nil {
  4106. c.ServeSuccessJSON(map[string]interface{}{
  4107. "msg": "退费成功",
  4108. })
  4109. } else {
  4110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4111. return
  4112. }
  4113. }
  4114. func (c *HisApiController) RefundNumber() {
  4115. his_patient_id, _ := c.GetInt64("id")
  4116. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4117. info.Status = 0
  4118. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4119. if count > 0 {
  4120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4121. return
  4122. }
  4123. err := service.SaveHisPatient(info)
  4124. if err == nil {
  4125. c.ServeSuccessJSON(map[string]interface{}{
  4126. "msg": "退号成功",
  4127. })
  4128. } else {
  4129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4130. return
  4131. }
  4132. }
  4133. func (this *HisApiController) AdditionalCharge() {
  4134. dataBody := make(map[string]interface{}, 0)
  4135. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4136. fmt.Println(err)
  4137. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4138. patient_id := int64(dataBody["patient_id"].(float64))
  4139. medicineData, _ := dataBody["medicineData"].([]interface{})
  4140. adminUserInfo := this.GetAdminUserInfo()
  4141. orgId := adminUserInfo.CurrentOrgId
  4142. admin_user_id := adminUserInfo.AdminUser.Id
  4143. timeStr := time.Now().Format("2006-01-02")
  4144. timeLayout := "2006-01-02 15:04:05"
  4145. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4146. timenow := timeStringToTime.Unix()
  4147. var additionalCharges []*models.HisAdditionalCharge
  4148. for _, item := range medicineData {
  4149. var randNum int
  4150. randNum = rand.Intn(10000) + 1000
  4151. timestamp := time.Now().Unix()
  4152. tempTime := time.Unix(timestamp, 0)
  4153. timeFormat := tempTime.Format("20060102150405")
  4154. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4155. items := item.(map[string]interface{})
  4156. money := items["price"].(string)
  4157. item_id_str := items["item_id"].(string)
  4158. name := items["name"].(string)
  4159. id_str := items["id"].(string)
  4160. moneys, _ := strconv.ParseInt(money, 10, 64)
  4161. monStr := strconv.FormatInt(moneys, 10)
  4162. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4163. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4164. id, _ := strconv.ParseInt(id_str, 10, 64)
  4165. additionalCharge := &models.HisAdditionalCharge{
  4166. ID: id,
  4167. HisPatientId: his_patient_id,
  4168. UserOrgId: orgId,
  4169. PatientId: patient_id,
  4170. RecordDate: timenow,
  4171. Price: monneyStr,
  4172. Status: 1,
  4173. ItemName: name,
  4174. ItemId: item_id,
  4175. AdminUserId: admin_user_id,
  4176. CreatedTime: time.Now().Unix(),
  4177. OrderStatus: 0,
  4178. PrescriptionNumber: "",
  4179. BatchNumber: "",
  4180. FeedetlSn: p_number,
  4181. }
  4182. service.CreateAdditionalCharge(additionalCharge)
  4183. additionalCharges = append(additionalCharges, additionalCharge)
  4184. }
  4185. this.ServeSuccessJSON(map[string]interface{}{
  4186. "msg": "添加成功",
  4187. "additional_charges": additionalCharges,
  4188. })
  4189. }
  4190. func (this *HisApiController) DeleteAddition() {
  4191. id, _ := this.GetInt64("id")
  4192. //TODO 需要判断是否已经结算
  4193. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4194. if err == nil {
  4195. this.ServeSuccessJSON(map[string]interface{}{
  4196. "msg": "删除成功",
  4197. })
  4198. return
  4199. } else {
  4200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4201. return
  4202. }
  4203. }
  4204. func (this *HisApiController) GetAdminUsers() {
  4205. adminUser := this.GetAdminUserInfo()
  4206. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4207. this.ServeSuccessJSON(map[string]interface{}{
  4208. "doctors": doctors,
  4209. })
  4210. }
  4211. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4212. change_type, _ := this.GetInt64("type", 0)
  4213. record_date := this.GetString("record_time")
  4214. patient_id, _ := this.GetInt64("patient_id", 0)
  4215. p_type, _ := this.GetInt64("p_type", 0)
  4216. timeLayout := "2006-01-02"
  4217. loc, _ := time.LoadLocation("Local")
  4218. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4219. record_time := theAdviceRecordTime.Unix()
  4220. adminUserInfo := this.GetAdminUserInfo()
  4221. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4222. if err == nil {
  4223. if len(prescriptions) == 0 {
  4224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4225. return
  4226. } else {
  4227. this.ServeSuccessJSON(map[string]interface{}{
  4228. "prescriptions": prescriptions,
  4229. })
  4230. return
  4231. }
  4232. } else {
  4233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4234. return
  4235. }
  4236. }
  4237. func (this *HisApiController) GetCallHisPrescription() {
  4238. patient_id, _ := this.GetInt64("patient_id", 0)
  4239. timeLayout := "2006-01-02"
  4240. loc, _ := time.LoadLocation("Local")
  4241. start_time := this.GetString("start_time")
  4242. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4243. end_time := this.GetString("end_time")
  4244. p_type, _ := this.GetInt64("p_type")
  4245. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4246. adminUserInfo := this.GetAdminUserInfo()
  4247. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4248. if err == nil {
  4249. this.ServeSuccessJSON(map[string]interface{}{
  4250. "prescriptions": prescriptions,
  4251. })
  4252. return
  4253. } else {
  4254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4255. return
  4256. }
  4257. }
  4258. func (this *HisApiController) GetHisDayPrescription() {
  4259. timeLayout := "2006-01-02"
  4260. loc, _ := time.LoadLocation("Local")
  4261. start_time := this.GetString("start_time")
  4262. patient_id, _ := this.GetInt64("patient_id", 0)
  4263. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4264. end_time := this.GetString("end_time")
  4265. p_type, _ := this.GetInt64("p_type")
  4266. order_status, _ := this.GetInt64("type")
  4267. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4268. adminUserInfo := this.GetAdminUserInfo()
  4269. var dayHisPrescription []*models.HisPrescription
  4270. var err error
  4271. if order_status == 1 || order_status == 0 {
  4272. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4273. } else if order_status == 2 {
  4274. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4275. }
  4276. if err == nil {
  4277. this.ServeSuccessJSON(map[string]interface{}{
  4278. "day_prescription": dayHisPrescription,
  4279. })
  4280. return
  4281. } else {
  4282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4283. return
  4284. }
  4285. }
  4286. func (c *HisApiController) GetHisChargePatientList() {
  4287. record_date := c.GetString("record_date")
  4288. order_status, _ := c.GetInt64("type")
  4289. timeLayout := "2006-01-02"
  4290. loc, _ := time.LoadLocation("Local")
  4291. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4292. if err != nil {
  4293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4294. return
  4295. }
  4296. recordDateTime := theTime.Unix()
  4297. adminInfo := c.GetAdminUserInfo()
  4298. var tempPatients []*service.NewTempPatients
  4299. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4300. if order_status != 2 {
  4301. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4302. } else {
  4303. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4304. }
  4305. var patients []*service.NewTempPatients
  4306. var patients_two []*service.NewTempPatients
  4307. for _, item := range tempPatients {
  4308. //过滤掉没挂号的和没开处方的
  4309. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4310. patients = append(patients, item)
  4311. }
  4312. //过滤掉没挂号的
  4313. if len(item.HisPatient) > 0 {
  4314. patients_two = append(patients_two, item)
  4315. }
  4316. }
  4317. c.ServeSuccessJSON(map[string]interface{}{
  4318. "list": patients,
  4319. "list_two": patients_two,
  4320. })
  4321. }
  4322. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4323. record_date := c.GetString("record_date")
  4324. timeLayout := "2006-01-02"
  4325. loc, _ := time.LoadLocation("Local")
  4326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4327. if err != nil {
  4328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4329. return
  4330. }
  4331. recordDateTime := theTime.Unix()
  4332. adminUser := c.GetAdminUserInfo()
  4333. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4334. var patients []*service.Patients
  4335. for _, item := range tempPatients {
  4336. if item.HisPatient.ID == 0 {
  4337. patients = append(patients, item)
  4338. }
  4339. }
  4340. c.ServeSuccessJSON(map[string]interface{}{
  4341. "list": patients,
  4342. //"list_two": patients_two,
  4343. })
  4344. }
  4345. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4346. newArr = make([]*service.Patients, 0)
  4347. for i := 0; i < len(patient); i++ {
  4348. repeat := false
  4349. for j := i + 1; j < len(patient); j++ {
  4350. if patient[i].ID == patient[j].ID {
  4351. repeat = true
  4352. break
  4353. }
  4354. }
  4355. if !repeat {
  4356. newArr = append(newArr, patient[i])
  4357. }
  4358. }
  4359. return
  4360. }
  4361. func (c *HisApiController) GetHisChargePatientInfo() {
  4362. patient_id, _ := c.GetInt64("patient_id")
  4363. his_patient_id, _ := c.GetInt64("his_patient_id")
  4364. record_date := c.GetString("record_date")
  4365. //start_time := c.GetString("start_time")
  4366. //end_time := c.GetString("end_time")
  4367. order_status, _ := c.GetInt64("type", 0)
  4368. p_type, _ := c.GetInt64("p_type", 0)
  4369. order_id, _ := c.GetInt64("order_id", 0)
  4370. timeLayout := "2006-01-02"
  4371. loc, _ := time.LoadLocation("Local")
  4372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4373. if err != nil {
  4374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4375. return
  4376. }
  4377. recordDateTime := theTime.Unix()
  4378. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4379. //if err != nil {
  4380. //
  4381. //}
  4382. //startRecordDateTime := startTime.Unix()
  4383. //
  4384. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4385. //if err != nil {
  4386. //
  4387. //}
  4388. //endRecordDateTime := endTime.Unix()
  4389. admin := c.GetAdminUserInfo()
  4390. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4391. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4392. var prescriptions []*models.HisPrescription
  4393. order, _ := service.GetHisOrderByID(order_id)
  4394. if order_status == 1 || order_status == 0 {
  4395. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4396. } else if order_status == 2 {
  4397. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4398. }
  4399. //var monthPrescriptions []*models.HisPrescription
  4400. //if order_status == 1 || order_status == 0 {
  4401. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4402. //} else if order_status == 2 {
  4403. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4404. //}
  4405. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4406. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4407. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4408. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4409. //获取所有科室信息
  4410. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4411. c.ServeSuccessJSON(map[string]interface{}{
  4412. "his_info": his_patient_info,
  4413. "xt_info": xt_patient_info,
  4414. "prescription": prescriptions,
  4415. "case_history": case_history,
  4416. "info": patientPrescriptionInfo,
  4417. "last_info": lastPatientPrescriptionInfo,
  4418. //"month_prescriptions": monthPrescriptions,
  4419. "order": order,
  4420. "doctors": doctors,
  4421. "department": department,
  4422. })
  4423. return
  4424. }
  4425. func (c *HisApiController) GetAllOrderDetail() {
  4426. order_id, _ := c.GetInt64("id", 0)
  4427. order, _ := service.GetHisOrderByID(order_id)
  4428. if order.ID == 0 {
  4429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4430. return
  4431. }
  4432. org_id := c.GetAdminUserInfo().CurrentOrgId
  4433. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4434. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4435. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4436. c.ServeSuccessJSON(map[string]interface{}{
  4437. "order": order,
  4438. "order_info": order_info,
  4439. "patient": patient,
  4440. "admin_info": adminInfo,
  4441. })
  4442. return
  4443. }
  4444. func (c *HisApiController) GetAllOrderDetailCollect() {
  4445. order_id, _ := c.GetInt64("id", 0)
  4446. order, _ := service.GetHisOrderByID(order_id)
  4447. if order.ID == 0 {
  4448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4449. return
  4450. }
  4451. org_id := c.GetAdminUserInfo().CurrentOrgId
  4452. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4453. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4454. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4455. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4456. if his.BalanceAccountsType != 2 {
  4457. c.ServeSuccessJSON(map[string]interface{}{
  4458. "order": order,
  4459. "order_info": order_info,
  4460. "patient": patient,
  4461. "admin_info": adminInfo,
  4462. })
  4463. } else {
  4464. for _, item := range order_info {
  4465. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4466. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4467. item.MedChrgitmType = "09"
  4468. }
  4469. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4470. if item.HisPrescriptionProject.Type == 2 {
  4471. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4472. case 1:
  4473. item.MedChrgitmType = "14"
  4474. break
  4475. case 2:
  4476. item.MedChrgitmType = "05"
  4477. break
  4478. case 3:
  4479. item.MedChrgitmType = "04"
  4480. break
  4481. case 4:
  4482. item.MedChrgitmType = "14"
  4483. break
  4484. case 5:
  4485. item.MedChrgitmType = "08"
  4486. break
  4487. case 6:
  4488. item.MedChrgitmType = "14"
  4489. break
  4490. case 7:
  4491. item.MedChrgitmType = "14"
  4492. break
  4493. case 8:
  4494. item.MedChrgitmType = "03"
  4495. break
  4496. case 9:
  4497. item.MedChrgitmType = "14"
  4498. break
  4499. }
  4500. } else if item.HisPrescriptionProject.Type == 3 {
  4501. item.MedChrgitmType = "08"
  4502. }
  4503. }
  4504. }
  4505. c.ServeSuccessJSON(map[string]interface{}{
  4506. "order": order,
  4507. "order_info": order_info,
  4508. "patient": patient,
  4509. "admin_info": adminInfo,
  4510. })
  4511. }
  4512. return
  4513. }
  4514. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  4515. page, _ := c.GetInt64("page")
  4516. limit, _ := c.GetInt64("limit")
  4517. keywords := c.GetString("keywords")
  4518. start_time := c.GetString("start_time")
  4519. end_time := c.GetString("end_time")
  4520. //clr_type := c.GetString("clr_type")
  4521. insutype := c.GetString("insutype")
  4522. timeLayout := "2006-01-02"
  4523. loc, _ := time.LoadLocation("Local")
  4524. var theStartTIme int64
  4525. if len(start_time) > 0 {
  4526. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4527. theStartTIme = theTime.Unix()
  4528. }
  4529. var theEndtTIme int64
  4530. if len(end_time) > 0 {
  4531. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4532. theEndtTIme = theTime.Unix()
  4533. }
  4534. if page <= 0 {
  4535. page = 1
  4536. }
  4537. if limit <= 0 {
  4538. limit = 10
  4539. }
  4540. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  4541. c.ServeSuccessJSON(map[string]interface{}{
  4542. "total": total,
  4543. "list": list,
  4544. })
  4545. return
  4546. }
  4547. func (c *HisApiController) GetPutOnRecordList() {
  4548. page, _ := c.GetInt64("page")
  4549. limit, _ := c.GetInt64("limit")
  4550. keywords := c.GetString("keywords")
  4551. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  4552. if page <= 0 {
  4553. page = 1
  4554. }
  4555. if limit <= 0 {
  4556. limit = 10
  4557. }
  4558. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  4559. c.ServeSuccessJSON(map[string]interface{}{
  4560. "total": total,
  4561. "list": list,
  4562. })
  4563. return
  4564. }
  4565. func (c *HisApiController) GetCompareData() {
  4566. start_time := c.GetString("start_time")
  4567. end_time := c.GetString("end_time")
  4568. insutype := c.GetString("insutype")
  4569. timeLayout := "2006-01-02"
  4570. loc, _ := time.LoadLocation("Local")
  4571. var theStartTIme int64
  4572. if len(start_time) > 0 {
  4573. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4574. if err != nil {
  4575. theStartTIme = 0
  4576. }
  4577. theStartTIme = theTime.Unix()
  4578. }
  4579. var theEndtTIme int64
  4580. if len(end_time) > 0 {
  4581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4582. if err != nil {
  4583. theEndtTIme = 0
  4584. }
  4585. theEndtTIme = theTime.Unix()
  4586. }
  4587. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  4588. fmt.Println(err)
  4589. if err == nil {
  4590. c.ServeSuccessJSON(map[string]interface{}{
  4591. "list": formData,
  4592. })
  4593. } else {
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4595. return
  4596. }
  4597. }
  4598. func (c *HisApiController) GetFaPiaoData() {
  4599. order_id, _ := c.GetInt64("order_id")
  4600. patient_id, _ := c.GetInt64("patient_id")
  4601. number := c.GetString("number")
  4602. adminUser := c.GetAdminUserInfo()
  4603. order, _ := service.GetHisOrderByID(order_id)
  4604. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4605. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4606. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4607. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  4608. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  4609. var bedCostTotal float64 = 0 //床位总费
  4610. var bedCostSelfTotal float64 = 0 //床位自费
  4611. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4612. var operationCostTotal float64 = 0 //手术费
  4613. var operationCostSelfTotal float64 = 0 //手术费
  4614. var operationCostPartSelfTotal float64 = 0 //手术费
  4615. var otherCostTotal float64 = 0 //其他费用
  4616. var otherCostSelfTotal float64 = 0 //其他费用
  4617. var otherCostPartSelfTotal float64 = 0 //其他费用
  4618. var materialCostTotal float64 = 0 //材料费
  4619. var materialCostSelfTotal float64 = 0 //材料费
  4620. var materialCostPartSelfTotal float64 = 0 //材料费
  4621. var westernMedicineCostTotal float64 = 0 //西药费
  4622. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4623. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4624. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4625. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4626. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4627. var checkCostTotal float64 = 0 //检查费
  4628. var checkCostSelfTotal float64 = 0 //检查费
  4629. var checkCostPartSelfTotal float64 = 0 //检查费
  4630. var laboratoryCostTotal float64 = 0 //化验费
  4631. var laboratoryCostSelfTotal float64 = 0 //化验费
  4632. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4633. var treatCostTotal float64 = 0 //治疗费用
  4634. var treatCostSelfTotal float64 = 0 //治疗费用
  4635. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4636. decimal.DivisionPrecision = 2
  4637. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4638. if his.BalanceAccountsType == 2 {
  4639. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4640. for _, item := range orderInfos_two {
  4641. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4642. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4643. item.MedChrgitmType = "09"
  4644. }
  4645. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4646. if item.HisPrescriptionProject.Type == 2 {
  4647. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4648. case 1:
  4649. item.MedChrgitmType = "14"
  4650. break
  4651. case 2:
  4652. item.MedChrgitmType = "05"
  4653. break
  4654. case 3:
  4655. item.MedChrgitmType = "04"
  4656. break
  4657. case 4:
  4658. item.MedChrgitmType = "14"
  4659. break
  4660. case 5:
  4661. item.MedChrgitmType = "08"
  4662. break
  4663. case 6:
  4664. item.MedChrgitmType = "14"
  4665. break
  4666. case 7:
  4667. item.MedChrgitmType = "14"
  4668. break
  4669. case 8:
  4670. item.MedChrgitmType = "03"
  4671. break
  4672. case 9:
  4673. item.MedChrgitmType = "14"
  4674. break
  4675. }
  4676. } else if item.HisPrescriptionProject.Type == 3 {
  4677. item.MedChrgitmType = "08"
  4678. }
  4679. }
  4680. }
  4681. for _, item := range orderInfos_two {
  4682. if item.MedChrgitmType == "01" { //床位费
  4683. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4684. bedCostSelfTotal = bedCostTotal
  4685. }
  4686. if item.MedChrgitmType == "03" { //检查费
  4687. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4688. checkCostSelfTotal = checkCostTotal
  4689. }
  4690. if item.MedChrgitmType == "04" { //化验费
  4691. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4692. laboratoryCostSelfTotal = laboratoryCostTotal
  4693. }
  4694. if item.MedChrgitmType == "05" { //治疗费
  4695. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4696. treatCostSelfTotal = treatCostTotal
  4697. }
  4698. if item.MedChrgitmType == "06" { //手术费
  4699. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4700. operationCostSelfTotal = treatCostTotal
  4701. }
  4702. if item.MedChrgitmType == "08" { //材料费
  4703. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4704. materialCostSelfTotal = materialCostTotal
  4705. }
  4706. if item.MedChrgitmType == "09" { //西药费
  4707. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4708. westernMedicineCostSelfTotal = westernMedicineCostTotal
  4709. }
  4710. if item.MedChrgitmType == "11" { //中成费
  4711. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4712. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  4713. }
  4714. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4715. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4716. otherCostSelfTotal = otherCostTotal
  4717. }
  4718. }
  4719. } else {
  4720. for _, item := range orderInfos {
  4721. if item.MedChrgitmType == "01" { //床位费
  4722. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4723. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4724. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4725. }
  4726. if item.MedChrgitmType == "03" { //检查费
  4727. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4728. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4729. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4730. }
  4731. if item.MedChrgitmType == "04" { //化验费
  4732. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4733. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4734. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4735. }
  4736. if item.MedChrgitmType == "05" { //治疗费
  4737. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4738. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4739. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4740. }
  4741. if item.MedChrgitmType == "06" { //手术费
  4742. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4743. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4744. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4745. }
  4746. if item.MedChrgitmType == "08" { //材料费
  4747. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4748. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4749. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4750. }
  4751. if item.MedChrgitmType == "09" { //西药费
  4752. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4753. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4754. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4755. }
  4756. if item.MedChrgitmType == "11" { //中成费
  4757. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4758. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4759. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4760. }
  4761. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4762. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4763. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4764. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4765. }
  4766. }
  4767. }
  4768. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4769. c.ServeSuccessJSON(map[string]interface{}{
  4770. "order_number": order.Number, //业务流水号
  4771. "id_card_no": his.IdCardNo, //社会保障号
  4772. "department_name": department.Name, //科室
  4773. "number": his.Number, //门诊号
  4774. "date": order.SettleAccountsDate, //结算日期
  4775. "name": order.PsnName, //姓名
  4776. "gender": order.Gend, //性别
  4777. "psn_cash_money": order.PsnCashPay, //个人支付
  4778. "pay_way": "门诊", //结算方式
  4779. "medfee_sumamt": order.MedfeeSumamt, //总费用
  4780. "admin_user_name": admin.UserName, //收款员
  4781. "order": order,
  4782. "order_info": orderInfos_two,
  4783. "his": his,
  4784. "bedCostTotal": bedCostTotal,
  4785. "bedCostSelfTotal": bedCostSelfTotal,
  4786. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4787. "operationCostTotal": operationCostTotal,
  4788. "operationCostSelfTotal": operationCostSelfTotal,
  4789. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4790. "otherCostTotal": otherCostTotal,
  4791. "otherCostSelfTotal": otherCostSelfTotal,
  4792. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4793. "materialCostTotal": materialCostTotal,
  4794. "materialCostSelfTotal": materialCostSelfTotal,
  4795. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4796. "westernMedicineCostTotal": westernMedicineCostTotal,
  4797. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4798. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4799. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4800. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4801. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4802. "checkCostTotal": checkCostTotal,
  4803. "checkCostSelfTotal": checkCostSelfTotal,
  4804. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4805. "laboratoryCostTotal": laboratoryCostTotal,
  4806. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4807. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4808. "treatCostTotal": treatCostTotal,
  4809. "treatCostSelfTotal": treatCostSelfTotal,
  4810. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4811. })
  4812. }
  4813. func (this *HisApiController) GetIncomeStatisticsData() {
  4814. start_time := this.GetString("start_time")
  4815. end_time := this.GetString("end_time")
  4816. key_words := this.GetString("key_words")
  4817. limit, _ := this.GetInt64("limit")
  4818. page, _ := this.GetInt64("page")
  4819. if page <= 0 {
  4820. page = 1
  4821. }
  4822. if limit <= 0 {
  4823. limit = 10
  4824. }
  4825. statistics_type, _ := this.GetInt64("statistics_type")
  4826. admin := this.GetAdminUserInfo()
  4827. timeLayout := "2006-01-02"
  4828. loc, _ := time.LoadLocation("Local")
  4829. var theStartTIme int64
  4830. if len(start_time) > 0 {
  4831. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4832. if err != nil {
  4833. theStartTIme = 0
  4834. }
  4835. theStartTIme = theTime.Unix()
  4836. }
  4837. var theEndtTIme int64
  4838. if len(end_time) > 0 {
  4839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4840. if err != nil {
  4841. theEndtTIme = 0
  4842. }
  4843. theEndtTIme = theTime.Unix()
  4844. }
  4845. if statistics_type == 1 {
  4846. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4847. this.ServeSuccessJSON(map[string]interface{}{
  4848. "list": list,
  4849. "total": total,
  4850. })
  4851. } else {
  4852. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4853. this.ServeSuccessJSON(map[string]interface{}{
  4854. "list": list,
  4855. "total": total,
  4856. })
  4857. }
  4858. }
  4859. func (c *HisApiController) PostProjectInformation() {
  4860. adminUser := c.GetAdminUserInfo()
  4861. orgId := adminUser.CurrentOrgId
  4862. dataBody := make(map[string]interface{}, 0)
  4863. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4864. if err != nil {
  4865. utils.ErrorLog(err.Error())
  4866. return
  4867. }
  4868. utils.ErrorLog("%v", dataBody)
  4869. var projectList []*models.HisProject
  4870. var total_goods []interface{}
  4871. tempProjects := dataBody["projects"].([]interface{})
  4872. total_goods = tempProjects
  4873. for index, projectMap := range tempProjects {
  4874. projectM := projectMap.(map[string]interface{})
  4875. var project models.HisProject
  4876. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  4877. utils.ErrorLog("project_name")
  4878. return
  4879. }
  4880. project_name, _ := projectM["project_name"].(string)
  4881. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  4882. err_log := models.ExportErrLog{
  4883. LogType: 6,
  4884. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4885. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  4886. Status: 1,
  4887. CreateTime: time.Now().Unix(),
  4888. UpdateTime: time.Now().Unix(),
  4889. ExportTime: time.Now().Unix(),
  4890. }
  4891. service.CreateExportErrLog(&err_log)
  4892. continue
  4893. }
  4894. project.ProjectName = project_name
  4895. prices := projectM["price"].(string)
  4896. price, _ := strconv.ParseFloat(prices, 64)
  4897. if price <= 0 { //名字为空则生成一条导入错误日志
  4898. err_log := models.ExportErrLog{
  4899. LogType: 6,
  4900. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4901. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  4902. Status: 1,
  4903. CreateTime: time.Now().Unix(),
  4904. UpdateTime: time.Now().Unix(),
  4905. ExportTime: time.Now().Unix(),
  4906. }
  4907. service.CreateExportErrLog(&err_log)
  4908. continue
  4909. }
  4910. project.Price = price
  4911. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  4912. utils.ErrorLog("unit_id")
  4913. return
  4914. }
  4915. unit := projectM["unit"].(string)
  4916. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  4917. err_log := models.ExportErrLog{
  4918. LogType: 6,
  4919. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4920. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  4921. Status: 1,
  4922. CreateTime: time.Now().Unix(),
  4923. UpdateTime: time.Now().Unix(),
  4924. ExportTime: time.Now().Unix(),
  4925. }
  4926. service.CreateExportErrLog(&err_log)
  4927. continue
  4928. }
  4929. project.Unit = unit
  4930. cost_classify := projectM["cost_classify"].(string)
  4931. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  4932. err_log := models.ExportErrLog{
  4933. LogType: 6,
  4934. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4935. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  4936. Status: 1,
  4937. CreateTime: time.Now().Unix(),
  4938. UpdateTime: time.Now().Unix(),
  4939. ExportTime: time.Now().Unix(),
  4940. }
  4941. service.CreateExportErrLog(&err_log)
  4942. continue
  4943. }
  4944. var costClassify = "费用类别"
  4945. var cost_classify_id int64
  4946. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  4947. if len(cost_classify) != 0 {
  4948. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  4949. if errcode == gorm.ErrRecordNotFound {
  4950. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  4951. dataconfig := models.DictDataconfig{
  4952. ParentId: costClassifyConfig.ID,
  4953. Module: "system",
  4954. OrgId: orgId,
  4955. Name: cost_classify,
  4956. FieldName: "",
  4957. Value: costConfig.Value + 1,
  4958. CreatedTime: "",
  4959. UpdatedTime: "",
  4960. CreateUserId: adminUser.AdminUser.Id,
  4961. Status: 1,
  4962. Remark: "",
  4963. DeleteIdSystem: 0,
  4964. Title: "",
  4965. Content: "",
  4966. Order: 0,
  4967. Code: "",
  4968. }
  4969. service.CreatedDicConfig(&dataconfig)
  4970. }
  4971. }
  4972. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  4973. for _, it := range costClassList {
  4974. if cost_classify == it.Name {
  4975. cost_classify_id = int64(it.Value)
  4976. }
  4977. }
  4978. project.CostClassify = cost_classify_id
  4979. executive_section := projectM["executive_section"].(string)
  4980. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  4981. err_log := models.ExportErrLog{
  4982. LogType: 6,
  4983. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4984. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  4985. Status: 1,
  4986. CreateTime: time.Now().Unix(),
  4987. UpdateTime: time.Now().Unix(),
  4988. ExportTime: time.Now().Unix(),
  4989. }
  4990. service.CreateExportErrLog(&err_log)
  4991. continue
  4992. }
  4993. if len(executive_section) != 0 {
  4994. //查找科室是否有内容
  4995. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  4996. if errcodedepart == gorm.ErrRecordNotFound {
  4997. department := models.XtHisDepartment{
  4998. Name: executive_section,
  4999. Status: 1,
  5000. UserOrgId: adminUser.CurrentOrgId,
  5001. CreatedTime: time.Now().Unix(),
  5002. }
  5003. service.CreateDePartment(&department)
  5004. }
  5005. }
  5006. var executive_section_id int64
  5007. departMentList, _ := service.GetAllDepartMent(orgId)
  5008. for _, it := range departMentList {
  5009. if executive_section == it.Name {
  5010. executive_section_id = it.ID
  5011. }
  5012. }
  5013. project.ExecutiveSection = executive_section_id
  5014. medical_coverage := projectM["medical_coverage"].(string)
  5015. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5016. err_log := models.ExportErrLog{
  5017. LogType: 6,
  5018. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5019. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5020. Status: 1,
  5021. CreateTime: time.Now().Unix(),
  5022. UpdateTime: time.Now().Unix(),
  5023. ExportTime: time.Now().Unix(),
  5024. }
  5025. service.CreateExportErrLog(&err_log)
  5026. continue
  5027. }
  5028. var medicalCoverage = "医保等级"
  5029. var medical_coverage_id int64
  5030. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5031. if len(medical_coverage) != 0 {
  5032. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5033. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5034. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5035. dataconfig := models.DictDataconfig{
  5036. ParentId: medicalCoverageConfig.ID,
  5037. Module: "system",
  5038. OrgId: orgId,
  5039. Name: medical_coverage,
  5040. FieldName: "",
  5041. Value: medicalCoverageConfig.Value + 1,
  5042. CreatedTime: "",
  5043. UpdatedTime: "",
  5044. CreateUserId: adminUser.AdminUser.Id,
  5045. Status: 1,
  5046. Remark: "",
  5047. DeleteIdSystem: 0,
  5048. Title: "",
  5049. Content: "",
  5050. Order: 0,
  5051. Code: "",
  5052. }
  5053. service.CreatedDicConfig(&dataconfig)
  5054. }
  5055. }
  5056. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5057. for _, it := range medicalCoverageList {
  5058. if medical_coverage == it.Name {
  5059. medical_coverage_id = int64(it.Value)
  5060. }
  5061. }
  5062. project.MedicalCoverage = medical_coverage_id
  5063. pinyin := projectM["pinyin"].(string)
  5064. project.Pinyin = pinyin
  5065. wubi := projectM["wubi"].(string)
  5066. project.Wubi = wubi
  5067. statistical_classification := projectM["statistical_classification"].(string)
  5068. var statisticalClassification = "统计分类"
  5069. var statistical_classification_id int64
  5070. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5071. if len(statistical_classification) != 0 {
  5072. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5073. if classificationerrcodes == gorm.ErrRecordNotFound {
  5074. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5075. dataconfig := models.DictDataconfig{
  5076. ParentId: classiFication.ID,
  5077. Module: "system",
  5078. OrgId: orgId,
  5079. Name: statistical_classification,
  5080. FieldName: "",
  5081. Value: classiFicationConfig.Value + 1,
  5082. CreatedTime: "",
  5083. UpdatedTime: "",
  5084. CreateUserId: adminUser.AdminUser.Id,
  5085. Status: 1,
  5086. Remark: "",
  5087. DeleteIdSystem: 0,
  5088. Title: "",
  5089. Content: "",
  5090. Order: 0,
  5091. Code: "",
  5092. }
  5093. service.CreatedDicConfig(&dataconfig)
  5094. }
  5095. }
  5096. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5097. for _, it := range classiFicationList {
  5098. if statistical_classification == it.Name {
  5099. statistical_classification_id = int64(it.Value)
  5100. }
  5101. }
  5102. project.StatisticalClassification = statistical_classification_id
  5103. disease_directory := int64(projectM["disease_directory"].(float64))
  5104. project.DiseaseDirectory = disease_directory
  5105. is_record := int64(projectM["is_record"].(float64))
  5106. project.IsRecord = is_record
  5107. medical_code := projectM["medical_code"].(string)
  5108. project.MedicalCode = medical_code
  5109. tube_color := projectM["tube_color"].(string)
  5110. var tubeColor = "试管颜色"
  5111. var tube_color_id int64
  5112. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5113. if len(tube_color) != 0 {
  5114. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5115. if errcodetube == gorm.ErrRecordNotFound {
  5116. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5117. dataconfig := models.DictDataconfig{
  5118. ParentId: tubeColorConfig.ID,
  5119. Module: "system",
  5120. OrgId: orgId,
  5121. Name: tube_color,
  5122. FieldName: "",
  5123. Value: tubeConfig.Value + 1,
  5124. CreatedTime: "",
  5125. UpdatedTime: "",
  5126. CreateUserId: adminUser.AdminUser.Id,
  5127. Status: 1,
  5128. Remark: "",
  5129. DeleteIdSystem: 0,
  5130. Title: "",
  5131. Content: "",
  5132. Order: 0,
  5133. Code: "",
  5134. }
  5135. service.CreatedDicConfig(&dataconfig)
  5136. }
  5137. }
  5138. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5139. for _, it := range tubeColorList {
  5140. if tube_color == it.Name {
  5141. tube_color_id = int64(it.Value)
  5142. }
  5143. }
  5144. project.TubeColor = tube_color_id
  5145. single_dose := projectM["single_dose"].(string)
  5146. project.SingleDose = single_dose
  5147. execution_frequency := projectM["execution_frequency"].(string)
  5148. project.ExecutionFrequency = execution_frequency
  5149. delivery_way := projectM["delivery_way"].(string)
  5150. project.DeliveryWay = delivery_way
  5151. number_days := projectM["number_days"].(string)
  5152. project.NumberDays = number_days
  5153. total := projectM["total"].(string)
  5154. project.Total = total
  5155. medical_status := int64(projectM["medical_status"].(float64))
  5156. project.MedicalStatus = medical_status
  5157. category := int64(projectM["category"].(float64))
  5158. project.Category = category
  5159. specail_project := int64(projectM["specail_project"].(float64))
  5160. project.SpecailProject = specail_project
  5161. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5162. project.SocialSecurityDirectoryCode = social_security_directory_code
  5163. remark := projectM["remark"].(string)
  5164. project.Remark = remark
  5165. record_date := projectM["record_date"].(string)
  5166. timeLayout := "2006-01-02"
  5167. loc, _ := time.LoadLocation("Local")
  5168. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5169. project.RecordDate = theTime.Unix()
  5170. projectList = append(projectList, &project)
  5171. }
  5172. export_time := time.Now().Unix()
  5173. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5174. if len(projectList) > 0 {
  5175. for _, item := range projectList {
  5176. project := models.HisProject{
  5177. ProjectName: item.ProjectName,
  5178. Price: item.Price,
  5179. Unit: item.Unit,
  5180. CostClassify: item.CostClassify,
  5181. ExecutiveSection: item.ExecutiveSection,
  5182. MedicalCoverage: item.MedicalCoverage,
  5183. UserOrgId: orgId,
  5184. Status: 1,
  5185. CreatedTime: time.Now().Unix(),
  5186. Pinyin: item.Pinyin,
  5187. Wubi: item.Wubi,
  5188. StatisticalClassification: item.StatisticalClassification,
  5189. DiseaseDirectory: item.DiseaseDirectory,
  5190. IsRecord: item.IsRecord,
  5191. MedicalCode: item.MedicalCode,
  5192. TubeColor: item.TubeColor,
  5193. SingleDose: item.SingleDose,
  5194. DeliveryWay: item.DeliveryWay,
  5195. NumberDays: item.NumberDays,
  5196. Total: item.Total,
  5197. Category: item.Category,
  5198. MedicalStatus: item.MedicalStatus,
  5199. SpecailProject: item.SpecailProject,
  5200. RecordDate: item.RecordDate,
  5201. Remark: item.Remark,
  5202. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5203. ExecutionFrequency: item.ExecutionFrequency,
  5204. }
  5205. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5206. if errcodeproject == gorm.ErrRecordNotFound {
  5207. service.CreateProjectInfomation(&project)
  5208. } else if errcodeproject == nil {
  5209. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5210. }
  5211. log := models.ExportLog{
  5212. LogType: 6,
  5213. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5214. TotalNum: int64(len(total_goods)),
  5215. FailNum: int64(len(errLogs)),
  5216. SuccessNum: int64(len(projectList)),
  5217. CreateTime: time.Now().Unix(),
  5218. UpdateTime: time.Now().Unix(),
  5219. ExportTime: export_time,
  5220. Status: 1,
  5221. }
  5222. service.CreateExportLog(&log)
  5223. c.ServeSuccessJSON(map[string]interface{}{
  5224. "msg": "导入成功",
  5225. "total_num": len(total_goods),
  5226. "success_num": len(projectList),
  5227. "fail_num": int64(len(errLogs)),
  5228. })
  5229. }
  5230. } else {
  5231. log := models.ExportLog{
  5232. LogType: 6,
  5233. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5234. TotalNum: int64(len(total_goods)),
  5235. FailNum: int64(len(errLogs)),
  5236. SuccessNum: int64(len(projectList)),
  5237. CreateTime: time.Now().Unix(),
  5238. UpdateTime: time.Now().Unix(),
  5239. ExportTime: export_time,
  5240. Status: 1,
  5241. }
  5242. service.CreateExportLog(&log)
  5243. c.ServeSuccessJSON(map[string]interface{}{
  5244. "msg": "导入成功",
  5245. "total_num": len(total_goods),
  5246. "success_num": len(projectList),
  5247. "fail_num": int64(len(errLogs)),
  5248. })
  5249. }
  5250. }
  5251. //func (this *HisApiController) EditProjectInformation(){
  5252. //
  5253. // id, _ := this.GetInt64("id")
  5254. // project_team := this.GetString("project_team")
  5255. // price := this.GetString("price")
  5256. // price_float, _ := strconv.ParseFloat(price, 64)
  5257. // pinyin := this.GetString("pinyin")
  5258. // wubi := this.GetString("wubi")
  5259. // tube_color, _ := this.GetInt64("tube_color")
  5260. // team_type, _ := this.GetInt64("team_type")
  5261. // remark := this.GetString("remark")
  5262. // ids := this.GetString("ids")
  5263. // item_id := this.GetString("item_id")
  5264. // projectTeam := models.XtHisProjectTeam{
  5265. // ProjectTeam: project_team,
  5266. // Price: price_float,
  5267. // Pinyin: pinyin,
  5268. // Wubi: wubi,
  5269. // TubeColor: tube_color,
  5270. // TeamType: team_type,
  5271. // Remark: remark,
  5272. // ProjectId: ids,
  5273. // ItemId: item_id,
  5274. // }
  5275. //
  5276. //
  5277. // dataBody := make(map[string]interface{}, 0)
  5278. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5279. // if err != nil {
  5280. // utils.ErrorLog(err.Error())
  5281. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5282. // return
  5283. // }
  5284. //
  5285. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5286. //
  5287. //
  5288. // if err != nil {
  5289. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5290. // return
  5291. // }
  5292. //
  5293. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5294. // infos, _ := dataBody["info"].([]interface{})
  5295. // if len(infos) > 0 {
  5296. // var ids []string
  5297. //
  5298. // for _, item := range infos {
  5299. // items := item.(map[string]interface{})
  5300. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5301. // utils.ErrorLog("id")
  5302. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5303. // return
  5304. // }
  5305. // id := int64(items["id"].(float64))
  5306. //
  5307. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5308. // utils.ErrorLog("type")
  5309. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5310. // return
  5311. // }
  5312. // types := int64(items["type"].(float64))
  5313. //
  5314. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5315. // utils.ErrorLog("number")
  5316. // }
  5317. //
  5318. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5319. //
  5320. // projectList := models.XtHisProjectList{
  5321. // Number: number,
  5322. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5323. // ProjectId: id,
  5324. // Status: 1,
  5325. // CreatedTime: time.Now().Unix(),
  5326. // UpdatedTime: time.Now().Unix(),
  5327. // TeamId: projectTeam.ID,
  5328. // Type: types,
  5329. // }
  5330. // list := projectList
  5331. //
  5332. // service.CreateProjectList(&list)
  5333. //
  5334. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5335. //
  5336. // }
  5337. // ids_str := strings.Join(ids, ",")
  5338. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5339. // service.SaveProjectTeam(&projectTeam)
  5340. // this.ServeSuccessJSON(map[string]interface{}{
  5341. // "projectTeam": projectTeam,
  5342. // })
  5343. // }
  5344. // }
  5345. //}
  5346. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5347. name := c.GetString("name")
  5348. mode_id, _ := c.GetInt64("mode", 0)
  5349. types, _ := c.GetInt64("type", 0)
  5350. patient_id, _ := c.GetInt64("patient_id", 0)
  5351. types = 1
  5352. adminInfo := c.GetAdminUserInfo()
  5353. template := &models.HisPrescriptionTemplate{
  5354. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5355. PatientId: patient_id,
  5356. Type: types,
  5357. Status: 1,
  5358. Ctime: time.Now().Unix(),
  5359. Mtime: time.Now().Unix(),
  5360. Name: name,
  5361. Mode: mode_id,
  5362. }
  5363. dataBody := make(map[string]interface{}, 0)
  5364. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5365. if err != nil {
  5366. utils.ErrorLog(err.Error())
  5367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5368. return
  5369. }
  5370. err = service.CreateHisPrescriptionTemplate(template)
  5371. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5372. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5373. if len(prescriptions) > 0 {
  5374. for _, item := range prescriptions {
  5375. items := item.(map[string]interface{})
  5376. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5377. utils.ErrorLog("type")
  5378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5379. return
  5380. }
  5381. types := int64(items["type"].(float64))
  5382. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5383. utils.ErrorLog("med_type")
  5384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5385. return
  5386. }
  5387. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5388. ctime := time.Now().Unix()
  5389. prescription := &models.HisPrescriptionInfoTemplate{
  5390. PatientId: patient_id,
  5391. UserOrgId: adminInfo.CurrentOrgId,
  5392. Ctime: ctime,
  5393. Mtime: ctime,
  5394. Type: types,
  5395. Modifier: adminInfo.AdminUser.Id,
  5396. Creator: adminInfo.AdminUser.Id,
  5397. Status: 1,
  5398. PTemplateId: template.ID,
  5399. MedType: med_type,
  5400. }
  5401. service.CreateHisPrescriptionInfoTemplate(prescription)
  5402. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5403. advices := items["advices"].([]interface{})
  5404. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5405. ctime := time.Now().Unix()
  5406. mtime := ctime
  5407. if len(advices) > 0 {
  5408. for _, advice := range advices {
  5409. var s models.HisPrescriptionAdviceTemplate
  5410. s.PrescriptionId = prescription.ID
  5411. s.AdviceType = 2
  5412. s.StopState = 2
  5413. s.ExecutionState = 2
  5414. s.Status = 1
  5415. s.UserOrgId = adminInfo.CurrentOrgId
  5416. s.CreatedTime = ctime
  5417. s.UpdatedTime = mtime
  5418. s.PatientId = patient_id
  5419. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  5420. if errcode > 0 {
  5421. c.ServeFailJSONWithSGJErrorCode(errcode)
  5422. return
  5423. }
  5424. service.CreateHisPrescriptionAdviceTemplate(&s)
  5425. }
  5426. }
  5427. }
  5428. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5429. projects := items["project"].([]interface{})
  5430. if len(projects) > 0 {
  5431. for _, project := range projects {
  5432. var p models.HisPrescriptionProjectTemplate
  5433. p.PrescriptionId = prescription.ID
  5434. p.Ctime = time.Now().Unix()
  5435. p.Mtime = time.Now().Unix()
  5436. p.PatientId = patient_id
  5437. p.UserOrgId = adminInfo.CurrentOrgId
  5438. p.Status = 1
  5439. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  5440. if errcode > 0 {
  5441. c.ServeFailJSONWithSGJErrorCode(errcode)
  5442. return
  5443. }
  5444. service.CreateHisPrescriptionProjectTemplate(&p)
  5445. }
  5446. }
  5447. }
  5448. }
  5449. c.ServeSuccessJSON(map[string]interface{}{
  5450. "msg": "创建成功",
  5451. })
  5452. }
  5453. }
  5454. }
  5455. func (c *HisApiController) PreSettle() {
  5456. id, _ := c.GetInt64("id")
  5457. record_time := c.GetString("record_time")
  5458. his_patient_id, _ := c.GetInt64("his_patient_id")
  5459. timeLayout := "2006-01-02"
  5460. loc, _ := time.LoadLocation("Local")
  5461. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5462. diagnosis_id := c.GetString("diagnosis")
  5463. sick_type, _ := c.GetInt64("sick_type")
  5464. reg_type, _ := c.GetInt64("p_type")
  5465. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5467. if err != nil {
  5468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5469. return
  5470. }
  5471. recordDateTime := theTime.Unix()
  5472. adminUser := c.GetAdminUserInfo()
  5473. var prescriptions []*models.HisPrescription
  5474. var start_time int64
  5475. var end_time int64
  5476. ids_str := c.GetString("ids")
  5477. ids_arr := strings.Split(ids_str, ",")
  5478. fmt.Println(reg_type)
  5479. if settle_accounts_type == 1 { //日结
  5480. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5481. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  5482. } else {
  5483. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  5484. }
  5485. fmt.Println(prescriptions)
  5486. } else { //月结
  5487. start_time_str := c.GetString("start_time")
  5488. end_time_str := c.GetString("end_time")
  5489. timeLayout := "2006-01-02"
  5490. loc, _ := time.LoadLocation("Local")
  5491. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5492. if err != nil {
  5493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5494. return
  5495. }
  5496. recordStartTime := theStartTime.Unix()
  5497. start_time = recordStartTime
  5498. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5499. if err != nil {
  5500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5501. return
  5502. }
  5503. recordEndTime := theEndTime.Unix()
  5504. end_time = recordEndTime
  5505. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  5506. }
  5507. if reg_type == 1111 || reg_type == 1112 {
  5508. reg_type = 11
  5509. }
  5510. timestamp := time.Now().Unix()
  5511. tempTime := time.Unix(timestamp, 0)
  5512. timeFormat := tempTime.Format("20060102150405")
  5513. chrgBchno := rand.Intn(100000) + 10000
  5514. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5515. strconv.FormatInt(his.PatientId, 10)
  5516. var ids []int64
  5517. for _, item := range prescriptions {
  5518. ids = append(ids, item.ID)
  5519. }
  5520. fmt.Println(ids)
  5521. var total float64
  5522. for _, item := range prescriptions {
  5523. fmt.Println(item)
  5524. if item.Type == 1 { //药品
  5525. for _, subItem := range item.HisDoctorAdviceInfo {
  5526. total = total + (subItem.Price * subItem.PrescribingNumber)
  5527. }
  5528. }
  5529. if item.Type == 2 { //项目
  5530. for _, subItem := range item.HisPrescriptionProject {
  5531. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5532. total = total + (subItem.Price * cnt)
  5533. }
  5534. }
  5535. for _, subItem := range item.HisAdditionalCharge {
  5536. total = total + (subItem.Price * float64(subItem.Count))
  5537. }
  5538. }
  5539. allTotal := fmt.Sprintf("%.2f", total)
  5540. totals, _ := strconv.ParseFloat(allTotal, 64)
  5541. order := &models.HisOrder{
  5542. UserOrgId: adminUser.CurrentOrgId,
  5543. HisPatientId: his.ID,
  5544. PatientId: id,
  5545. SettleAccountsDate: recordDateTime,
  5546. Ctime: time.Now().Unix(),
  5547. Mtime: time.Now().Unix(),
  5548. Status: 1,
  5549. OrderStatus: 1,
  5550. MdtrtId: his.Number,
  5551. Number: chrg_bchno,
  5552. MedfeeSumamt: totals,
  5553. SettleEndTime: end_time,
  5554. SettleStartTime: start_time,
  5555. SettleType: settle_accounts_type,
  5556. PType: 2,
  5557. IsPre: 1,
  5558. MedType: strconv.Itoa(int(reg_type)),
  5559. Diagnosis: diagnosis_id,
  5560. }
  5561. err = service.CreateOrder(order)
  5562. if err != nil {
  5563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5564. return
  5565. }
  5566. var customs []*Custom
  5567. for _, item := range prescriptions {
  5568. fmt.Println(item.Type)
  5569. if item.Type == 1 { //药品
  5570. for _, subItem := range item.HisDoctorAdviceInfo {
  5571. cus := &Custom{
  5572. AdviceId: subItem.ID,
  5573. ProjectId: 0,
  5574. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  5575. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  5576. FeedetlSn: subItem.FeedetlSn,
  5577. Price: fmt.Sprintf("%.2f", subItem.Price),
  5578. MedListCodg: subItem.MedListCodg,
  5579. Type: 1,
  5580. }
  5581. customs = append(customs, cus)
  5582. }
  5583. }
  5584. if item.Type == 2 { //项目
  5585. for _, subItem := range item.HisPrescriptionProject {
  5586. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5587. cus := &Custom{
  5588. AdviceId: 0,
  5589. ProjectId: subItem.ID,
  5590. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  5591. Cut: fmt.Sprintf("%.2f", cnt),
  5592. FeedetlSn: subItem.FeedetlSn,
  5593. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  5594. MedListCodg: subItem.MedListCodg,
  5595. Type: 2,
  5596. }
  5597. customs = append(customs, cus)
  5598. }
  5599. }
  5600. for _, item := range item.HisAdditionalCharge {
  5601. cus := &Custom{
  5602. ItemId: item.ID,
  5603. AdviceId: 0,
  5604. ProjectId: 0,
  5605. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  5606. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  5607. FeedetlSn: item.FeedetlSn,
  5608. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  5609. MedListCodg: item.XtHisAddtionConfig.Code,
  5610. Type: 3,
  5611. }
  5612. customs = append(customs, cus)
  5613. }
  5614. }
  5615. fmt.Println(customs)
  5616. for _, item := range customs {
  5617. var advice_id int64 = 0
  5618. var project_id int64 = 0
  5619. var item_id int64 = 0
  5620. var types int64 = 0
  5621. if item.Type == 1 {
  5622. advice_id = item.AdviceId
  5623. project_id = 0
  5624. item_id = 0
  5625. } else if item.Type == 2 {
  5626. advice_id = 0
  5627. item_id = 0
  5628. project_id = item.ProjectId
  5629. } else if item.Type == 3 {
  5630. advice_id = 0
  5631. item_id = item.ItemId
  5632. project_id = 0
  5633. }
  5634. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5635. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5636. pric, _ := strconv.ParseFloat(item.Price, 32)
  5637. info := &models.HisOrderInfo{
  5638. OrderNumber: order.Number,
  5639. UploadDate: time.Now().Unix(),
  5640. AdviceId: advice_id,
  5641. DetItemFeeSumamt: detItemFeeSumamt,
  5642. Cnt: cut,
  5643. Pric: pric,
  5644. PatientId: id,
  5645. Status: 1,
  5646. Mtime: time.Now().Unix(),
  5647. Ctime: time.Now().Unix(),
  5648. UserOrgId: adminUser.CurrentOrgId,
  5649. HisPatientId: his.ID,
  5650. OrderId: order.ID,
  5651. ProjectId: project_id,
  5652. Type: types,
  5653. ItemId: item_id,
  5654. }
  5655. service.CreateOrderInfo(info)
  5656. }
  5657. his.SickType = sick_type
  5658. service.UpdataHisPateint(&his)
  5659. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  5660. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  5661. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  5662. if err == nil {
  5663. c.ServeSuccessJSON(map[string]interface{}{
  5664. "msg": "结算成功",
  5665. })
  5666. }
  5667. }
  5668. type CustomOrderInfo struct {
  5669. Name string
  5670. Spec string
  5671. Unit string
  5672. Count float64
  5673. Price float64
  5674. Total float64
  5675. }
  5676. func (c *HisApiController) GetPrivateExpensesInfo() {
  5677. order_id, _ := c.GetInt64("id", 0)
  5678. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  5679. order, _ := service.GetHisOrderByID(order_id)
  5680. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  5681. if order.ID == 0 {
  5682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5683. return
  5684. }
  5685. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5686. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5687. org_id := c.GetAdminUserInfo().CurrentOrgId
  5688. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5689. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5690. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  5691. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  5692. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  5693. var orderInfos_four []*models.HisOrderInfoTwo
  5694. for _, item := range orderInfos_three {
  5695. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  5696. item.HisPrescriptionProject.IsCheckTeam = 1
  5697. orderInfos_four = append(orderInfos_four, item)
  5698. }
  5699. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  5700. item.HisPrescriptionProject.IsCheckTeam = 2
  5701. orderInfos_two = append(orderInfos_two, item)
  5702. }
  5703. }
  5704. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  5705. var cus_slice []CustomOrderInfo
  5706. for _, item := range new_order_info {
  5707. var cus CustomOrderInfo
  5708. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  5709. cus.Unit = ""
  5710. cus.Spec = ""
  5711. var total float64
  5712. for _, subItem := range orderInfos_four {
  5713. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  5714. total = total + subItem.DetItemFeeSumamt
  5715. fmt.Println(subItem.DetItemFeeSumamt)
  5716. }
  5717. }
  5718. cus.Count = 1
  5719. cus.Total = total
  5720. cus_slice = append(cus_slice, cus)
  5721. }
  5722. orderInfos = append(orderInfos, orderInfos_two...)
  5723. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  5724. orderInfos = append(orderInfos, orderInfos_three...)
  5725. }
  5726. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5727. c.ServeSuccessJSON(map[string]interface{}{
  5728. "order": order,
  5729. "order_info": orderInfos,
  5730. "patient": patient,
  5731. "admin_info": adminInfo,
  5732. "his": his,
  5733. "current_admin": role,
  5734. "org_config": miConfig,
  5735. "new_order_info": cus_slice,
  5736. })
  5737. }
  5738. func (this *HisApiController) ChangeMedType() {
  5739. med_type := this.GetString("med_type")
  5740. id, _ := this.GetInt64("id")
  5741. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  5742. prescription.MedType = med_type
  5743. err := service.SaveHisPrescription(&prescription)
  5744. if err == nil {
  5745. this.ServeSuccessJSON(map[string]interface{}{
  5746. "msg": "修改成功",
  5747. })
  5748. } else {
  5749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5750. return
  5751. }
  5752. }
  5753. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  5754. patient_id, _ := c.GetInt64("patient_id")
  5755. his_patient_id, _ := c.GetInt64("his_patient_id")
  5756. record_date := c.GetString("record_date")
  5757. start_time := c.GetString("start_time")
  5758. end_time := c.GetString("end_time")
  5759. order_status, _ := c.GetInt64("type", 0)
  5760. p_type, _ := c.GetInt64("p_type", 0)
  5761. order_id, _ := c.GetInt64("order_id", 0)
  5762. timeLayout := "2006-01-02"
  5763. loc, _ := time.LoadLocation("Local")
  5764. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5765. if err != nil {
  5766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5767. return
  5768. }
  5769. recordDateTime := theTime.Unix()
  5770. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5771. if err != nil {
  5772. }
  5773. startRecordDateTime := startTime.Unix()
  5774. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5775. if err != nil {
  5776. }
  5777. endRecordDateTime := endTime.Unix()
  5778. admin := c.GetAdminUserInfo()
  5779. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5780. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5781. order, _ := service.GetHisOrderByID(order_id)
  5782. var monthPrescriptions []*models.HisPrescription
  5783. if order_status == 1 || order_status == 0 {
  5784. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5785. } else if order_status == 2 {
  5786. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5787. }
  5788. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5789. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5790. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5791. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5792. //获取所有科室信息
  5793. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5794. c.ServeSuccessJSON(map[string]interface{}{
  5795. "his_info": his_patient_info,
  5796. "xt_info": xt_patient_info,
  5797. "case_history": case_history,
  5798. "info": patientPrescriptionInfo,
  5799. "last_info": lastPatientPrescriptionInfo,
  5800. "month_prescriptions": monthPrescriptions,
  5801. "order": order,
  5802. "doctors": doctors,
  5803. "department": department,
  5804. })
  5805. return
  5806. }
  5807. func (c *HisApiController) GetHisMonthPatientInfo() {
  5808. patient_id, _ := c.GetInt64("patient_id")
  5809. his_patient_id, _ := c.GetInt64("his_patient_id")
  5810. record_date := c.GetString("record_date")
  5811. number := c.GetString("number")
  5812. start_time := c.GetString("start_time")
  5813. end_time := c.GetString("end_time")
  5814. p_type, _ := c.GetInt64("p_type")
  5815. timeLayout := "2006-01-02"
  5816. loc, _ := time.LoadLocation("Local")
  5817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5818. if err != nil {
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5820. return
  5821. }
  5822. recordDateTime := theTime.Unix()
  5823. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5824. if err != nil {
  5825. }
  5826. startRecordDateTime := startTime.Unix()
  5827. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5828. if err != nil {
  5829. }
  5830. endRecordDateTime := endTime.Unix()
  5831. admin := c.GetAdminUserInfo()
  5832. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  5833. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5834. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  5835. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5836. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5837. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5838. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5839. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  5840. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5841. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  5842. //获取所有科室信息
  5843. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5844. c.ServeSuccessJSON(map[string]interface{}{
  5845. "his_info": his_patient_info,
  5846. "xt_info": xt_patient_info,
  5847. "case_history": case_history,
  5848. "info": patientPrescriptionInfo,
  5849. "month_prescriptions": monthPrescriptions,
  5850. "order": order,
  5851. "doctors": doctors,
  5852. "department": department,
  5853. "count": count,
  5854. "drugStockConfig": drugStockConfig,
  5855. "last_info": lastPatientPrescriptionInfo,
  5856. })
  5857. return
  5858. }
  5859. func (c *HisApiController) GetAllOrder() {
  5860. org_id := c.GetAdminUserInfo().CurrentOrgId
  5861. orders, _ := service.GetNewHisOrderList(org_id)
  5862. c.ServeSuccessJSON(map[string]interface{}{
  5863. "order": orders,
  5864. })
  5865. return
  5866. }
  5867. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  5868. newArr = make([]*models.HisOrderInfoTwo, 0)
  5869. for i := 0; i < len(arr); i++ {
  5870. repeat := false
  5871. for j := i + 1; j < len(arr); j++ {
  5872. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  5873. repeat = true
  5874. break
  5875. }
  5876. }
  5877. if !repeat {
  5878. newArr = append(newArr, arr[i])
  5879. }
  5880. }
  5881. return
  5882. }
  5883. //修改处方退库操作 参数传修改之前的处方数据
  5884. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  5885. if advice.ExecutionState == 1 {
  5886. //查询该病人该药品是否有库存记录
  5887. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  5888. if errcode == gorm.ErrRecordNotFound {
  5889. } else {
  5890. //退库
  5891. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5892. if advice.PrescribingNumberUnit == drug.MinUnit {
  5893. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5894. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5895. //退库
  5896. warehouseInfo := models.DrugWarehouseInfo{
  5897. StockMinNumber: prescribingNumber,
  5898. }
  5899. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  5900. operation_time := time.Now().Unix()
  5901. creater := advice.AdviceDoctor
  5902. ctime := time.Now().Unix()
  5903. timeStr := time.Now().Format("2006-01-02")
  5904. timeArr := strings.Split(timeStr, "-")
  5905. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5906. total = total + 1
  5907. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5908. cancelStock := models.DrugCancelStock{
  5909. OrderNumber: orderNumber,
  5910. OperaTime: operation_time,
  5911. OrgId: advice.UserOrgId,
  5912. Creater: creater,
  5913. Ctime: ctime,
  5914. Status: 1,
  5915. ReturnTime: advice.AdviceDate,
  5916. Dealer: info.Dealer,
  5917. Manufacturer: info.Manufacturer,
  5918. Type: 1,
  5919. }
  5920. service.AddSigleDrugCancelStock(&cancelStock)
  5921. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  5922. dealer, _ := service.GetDealerById(info.Dealer)
  5923. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  5924. cancelStockInfo := models.DrugCancelStockInfo{
  5925. OrderNumber: cancelInfo.OrderNumber,
  5926. CancelStockId: cancelInfo.ID,
  5927. DrugId: info.DrugId,
  5928. Count: info.Count,
  5929. Status: 1,
  5930. Ctime: ctime,
  5931. OrgId: advice.UserOrgId,
  5932. Type: 1,
  5933. Manufacturer: manufactureName.ManufacturerName,
  5934. Dealer: dealer.DealerName,
  5935. Total: 0,
  5936. RetailPrice: info.RetailPrice,
  5937. RetailTotalPrice: info.RetailTotalPrice,
  5938. Price: info.Price,
  5939. RegisterAccount: "",
  5940. Remark: info.Remark,
  5941. BatchNumber: info.BatchNumber,
  5942. MaxUnit: info.CountUnit,
  5943. ProductDate: info.ProductDate,
  5944. ExpiryDate: info.ExpiryDate,
  5945. BatchNumberId: info.WarehouseInfoId,
  5946. }
  5947. flow := models.DrugFlow{
  5948. WarehousingId: 0,
  5949. DrugId: info.DrugId,
  5950. Number: "",
  5951. BatchNumber: info.BatchNumber,
  5952. Count: info.Count,
  5953. UserOrgId: advice.UserOrgId,
  5954. PatientId: 0,
  5955. SystemTime: ctime,
  5956. ConsumableType: 4,
  5957. IsSys: 0,
  5958. WarehousingOrder: "",
  5959. WarehouseOutId: 0,
  5960. WarehouseOutOrderNumber: "",
  5961. IsEdit: 0,
  5962. CancelStockId: cancelStock.ID,
  5963. CancelOrderNumber: cancelStock.OrderNumber,
  5964. Manufacturer: info.Manufacturer,
  5965. Dealer: info.Dealer,
  5966. Creator: advice.UserOrgId,
  5967. UpdateCreator: 0,
  5968. Status: 1,
  5969. Ctime: time.Now().Unix(),
  5970. Mtime: 0,
  5971. Price: info.Price,
  5972. WarehousingDetailId: 0,
  5973. WarehouseOutDetailId: 0,
  5974. CancelOutDetailId: 0,
  5975. ExpireDate: info.ExpiryDate,
  5976. ProductDate: info.ProductDate,
  5977. MaxUnit: info.CountUnit,
  5978. MinUnit: "",
  5979. }
  5980. service.CreatedCancelStock(cancelStockInfo)
  5981. service.CreateDrugFlowOne(flow)
  5982. } else {
  5983. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5984. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5985. if advice.PrescribingNumberUnit == drug.MaxUnit {
  5986. warehouseInfo := models.DrugWarehouseInfo{
  5987. StockMinNumber: prescribingNumber,
  5988. }
  5989. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  5990. }
  5991. operation_time := time.Now().Unix()
  5992. creater := advice.AdviceDoctor
  5993. ctime := time.Now().Unix()
  5994. timeStr := time.Now().Format("2006-01-02")
  5995. timeArr := strings.Split(timeStr, "-")
  5996. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5997. total = total + 1
  5998. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5999. cancelStock := models.DrugCancelStock{
  6000. OrderNumber: orderNumber,
  6001. OperaTime: operation_time,
  6002. OrgId: advice.UserOrgId,
  6003. Creater: creater,
  6004. Ctime: ctime,
  6005. Status: 1,
  6006. ReturnTime: advice.AdviceDate,
  6007. Dealer: info.Dealer,
  6008. Manufacturer: info.Manufacturer,
  6009. Type: 1,
  6010. }
  6011. service.AddSigleDrugCancelStock(&cancelStock)
  6012. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6013. dealer, _ := service.GetDealerById(info.Dealer)
  6014. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6015. cancelStockInfo := models.DrugCancelStockInfo{
  6016. OrderNumber: cancelInfo.OrderNumber,
  6017. CancelStockId: cancelInfo.ID,
  6018. DrugId: info.DrugId,
  6019. Count: info.Count,
  6020. Status: 1,
  6021. Ctime: ctime,
  6022. OrgId: advice.UserOrgId,
  6023. Type: 1,
  6024. Manufacturer: manufactureName.ManufacturerName,
  6025. Dealer: dealer.DealerName,
  6026. Total: 0,
  6027. RetailPrice: info.RetailPrice,
  6028. RetailTotalPrice: info.RetailTotalPrice,
  6029. Price: info.Price,
  6030. RegisterAccount: "",
  6031. Remark: info.Remark,
  6032. BatchNumber: info.BatchNumber,
  6033. MaxUnit: info.CountUnit,
  6034. ProductDate: info.ProductDate,
  6035. ExpiryDate: info.ExpiryDate,
  6036. BatchNumberId: info.WarehouseInfoId,
  6037. }
  6038. flow := models.DrugFlow{
  6039. WarehousingId: 0,
  6040. DrugId: info.DrugId,
  6041. Number: "",
  6042. BatchNumber: info.BatchNumber,
  6043. Count: info.Count,
  6044. UserOrgId: advice.UserOrgId,
  6045. PatientId: 0,
  6046. SystemTime: ctime,
  6047. ConsumableType: 4,
  6048. IsSys: 0,
  6049. WarehousingOrder: "",
  6050. WarehouseOutId: 0,
  6051. WarehouseOutOrderNumber: "",
  6052. IsEdit: 0,
  6053. CancelStockId: cancelStock.ID,
  6054. CancelOrderNumber: cancelStock.OrderNumber,
  6055. Manufacturer: info.Manufacturer,
  6056. Dealer: info.Dealer,
  6057. Creator: advice.AdviceDoctor,
  6058. UpdateCreator: 0,
  6059. Status: 1,
  6060. Ctime: time.Now().Unix(),
  6061. Mtime: 0,
  6062. Price: info.Price,
  6063. WarehousingDetailId: 0,
  6064. WarehouseOutDetailId: 0,
  6065. CancelOutDetailId: 0,
  6066. ExpireDate: info.ExpiryDate,
  6067. ProductDate: info.ProductDate,
  6068. MaxUnit: info.CountUnit,
  6069. MinUnit: "",
  6070. }
  6071. service.CreatedCancelStock(cancelStockInfo)
  6072. service.CreateDrugFlowOne(flow)
  6073. }
  6074. }
  6075. }
  6076. return err
  6077. }
  6078. func (this *HisApiController) DeleteNCDS() {
  6079. id, _ := this.GetInt64("id", 0)
  6080. if id > 0 {
  6081. service.DeletePsnNCDSRecordById(id)
  6082. this.ServeSuccessJSON(map[string]interface{}{
  6083. "msg": "删除成功",
  6084. })
  6085. } else {
  6086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6087. return
  6088. }
  6089. }
  6090. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6091. id, _ := c.GetInt64("id")
  6092. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6093. c.ServeSuccessJSON(map[string]interface{}{
  6094. "advice": advice,
  6095. })
  6096. return
  6097. }