his_api_controller.go 254KB

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