his_api_controller.go 190KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  70. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  71. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  72. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  73. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  74. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  75. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  76. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  77. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  78. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  79. }
  80. func (c *HisApiController) GetHisUnChargePatientList() {
  81. record_date := c.GetString("record_date")
  82. timeLayout := "2006-01-02"
  83. loc, _ := time.LoadLocation("Local")
  84. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  85. if err != nil {
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. recordDateTime := theTime.Unix()
  90. adminInfo := c.GetAdminUserInfo()
  91. var tempPatients []*service.NewTempPatients
  92. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  93. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  94. var patients []*service.NewTempPatients
  95. var patients_two []*service.NewTempPatients
  96. for _, item := range tempPatients {
  97. //过滤掉没挂号的和没开处方的
  98. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  99. patients = append(patients, item)
  100. }
  101. //过滤掉没挂号的
  102. if len(item.HisPatient) > 0 {
  103. patients_two = append(patients_two, item)
  104. }
  105. }
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "list": patients,
  108. "list_two": patients_two,
  109. })
  110. }
  111. func (c *HisApiController) GetPrivateExpensesOrder() {
  112. //id, _ := c.GetInt64("id")
  113. //record_time := c.GetString("record_time")
  114. order_id, _ := c.GetInt64("order_id")
  115. admin_user_id, _ := c.GetInt64("admin_user_id")
  116. //timeLayout := "2006-01-02"
  117. //loc, _ := time.LoadLocation("Local")
  118. //
  119. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  120. //if err != nil {
  121. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. // return
  123. //}
  124. //recordDateTime := theTime.Unix()
  125. adminUser := c.GetAdminUserInfo()
  126. order, _ := service.GetHisOrderByID(order_id)
  127. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  128. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  129. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  130. //var config []*models.HisXtDiagnoseConfig
  131. var name string
  132. for _, item := range diagnosis_ids {
  133. id, _ := strconv.ParseInt(item, 10, 64)
  134. diagnosisConfig, _ := service.FindDiagnoseById(id)
  135. if len(name) == 0 {
  136. name = diagnosisConfig.ClassName
  137. } else {
  138. name = name + "," + diagnosisConfig.ClassName
  139. }
  140. }
  141. decimal.DivisionPrecision = 2
  142. for _, item := range orderInfos {
  143. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  144. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  145. item.MedChrgitmType = "09"
  146. }
  147. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  148. if item.HisPrescriptionProject.Type == 2 {
  149. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  150. case 1:
  151. item.MedChrgitmType = "14"
  152. break
  153. case 2:
  154. item.MedChrgitmType = "05"
  155. break
  156. case 3:
  157. item.MedChrgitmType = "04"
  158. break
  159. case 4:
  160. item.MedChrgitmType = "14"
  161. break
  162. case 5:
  163. item.MedChrgitmType = "08"
  164. break
  165. case 6:
  166. item.MedChrgitmType = "14"
  167. break
  168. case 7:
  169. item.MedChrgitmType = "14"
  170. break
  171. case 8:
  172. item.MedChrgitmType = "03"
  173. break
  174. case 9:
  175. item.MedChrgitmType = "14"
  176. break
  177. }
  178. } else if item.HisPrescriptionProject.Type == 3 {
  179. item.MedChrgitmType = "08"
  180. }
  181. }
  182. }
  183. order.PsnCashPay = order.MedfeeSumamt
  184. //var user_name string
  185. //role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  186. //if role.ID == 0 {
  187. // user_name = "管理员"
  188. //} else {
  189. // user_name = role.UserName
  190. //}
  191. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  192. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  193. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  194. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  195. c.ServeSuccessJSON(map[string]interface{}{
  196. "org_name": org.OrgName,
  197. "name": patient.Name,
  198. "order_infos": orderInfos,
  199. "number": order.MdtrtId,
  200. "date": order.SettleAccountsDate,
  201. "charge_admin": charge_admin,
  202. "printor_admin": printor_admin,
  203. "info": order,
  204. })
  205. }
  206. func (c *HisApiController) RefudDetail() {
  207. order_id, _ := c.GetInt64("order_id")
  208. order, _ := service.GetHisOrderByID(order_id)
  209. adminUser := c.GetAdminUserInfo()
  210. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  211. c.ServeSuccessJSON(map[string]interface{}{
  212. "msg": "撤销成功",
  213. })
  214. }
  215. func (c *HisApiController) Sscard() {
  216. //r := CardInit()
  217. //if r == 0 {
  218. // GetBaseInfo()
  219. //}
  220. //c.ServeSuccessJSON(map[string]interface{}{
  221. // "list": "11",
  222. //})
  223. }
  224. func GetBaseInfo() error {
  225. //handle := syscall.MustLoadDLL("SSCard.dll")
  226. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  227. //
  228. //str := make([]byte, 256)
  229. //str1 := make([]byte, 256)
  230. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  231. //if ferr != nil {
  232. // fmt.Println("ReadCardBas 报错", ferr.Error())
  233. // return ferr
  234. //}
  235. //
  236. //fmt.Println(string(str))
  237. //
  238. //fmt.Println(r)
  239. return nil
  240. }
  241. func CardInit() int {
  242. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  243. //add := DllTestDef.MustFindProc("Init")
  244. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  245. //if err != nil {
  246. // fmt.Println("SSCard的运算结果为:", ret)
  247. //}
  248. //result := int(ret)
  249. return 0
  250. }
  251. func IntPtr(n int) uintptr {
  252. return uintptr(n)
  253. }
  254. func StrPtr(s string) uintptr {
  255. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  256. }
  257. func (c *HisApiController) GetHisPatientList() {
  258. //types, _ := c.GetInt64("type", 0)
  259. record_date := c.GetString("record_date")
  260. sch_type, _ := c.GetInt64("sch_type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  271. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  273. //获取当前用户的信息
  274. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  275. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  276. //获取所有科室信息
  277. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  278. c.ServeSuccessJSON(map[string]interface{}{
  279. "list": patients,
  280. "list_two": patients_two,
  281. "info": adminUserInfo,
  282. "doctors": doctors,
  283. "department": department,
  284. })
  285. }
  286. type CustomTemplate struct {
  287. ID int64 `gorm:"column:id" json:"id" form:"id"`
  288. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  289. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  290. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  291. Status int64 `gorm:"column:status" json:"status" form:"status"`
  292. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  293. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  294. Type int64 `gorm:"column:type" json:"type" form:"type"`
  295. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  296. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  297. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  298. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  299. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  300. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  301. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  302. }
  303. func (c *HisApiController) GetHisPatientInfo() {
  304. patient_id, _ := c.GetInt64("patient_id")
  305. his_patient_id, _ := c.GetInt64("his_patient_id")
  306. record_date := c.GetString("record_date")
  307. number := c.GetString("number")
  308. //start_time := c.GetString("start_time")
  309. //end_time := c.GetString("end_time")
  310. p_type, _ := c.GetInt64("p_type")
  311. timeLayout := "2006-01-02"
  312. loc, _ := time.LoadLocation("Local")
  313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  314. if err != nil {
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  316. return
  317. }
  318. recordDateTime := theTime.Unix()
  319. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  320. //if err != nil {
  321. //
  322. //}
  323. //startRecordDateTime := startTime.Unix()
  324. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  325. //if err != nil {
  326. //
  327. //}
  328. //endRecordDateTime := endTime.Unix()
  329. admin := c.GetAdminUserInfo()
  330. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  331. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  332. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  333. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  334. var prescriptions []*models.HisPrescription
  335. var last_prescriptions []*models.HisPrescription
  336. var sch_prescriptions []CustomTemplate
  337. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  338. if p_type == 1 { //住院
  339. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  340. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  341. } else { //门诊
  342. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  343. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  344. }
  345. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  346. if sch.ID > 0 {
  347. var week string
  348. t := time.Now()
  349. switch t.Weekday().String() {
  350. case "Monday":
  351. week = "周一"
  352. break
  353. case "Tuesday":
  354. week = "周二"
  355. break
  356. case "Wednesday":
  357. week = "周三"
  358. break
  359. case "Thursday":
  360. week = "周四"
  361. break
  362. case "Friday":
  363. week = "周五"
  364. break
  365. case "Saturday":
  366. week = "周六"
  367. break
  368. case "Sunday":
  369. week = "周日"
  370. break
  371. }
  372. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  373. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  374. //根据推送频率组装新的数组
  375. for _, item := range temp_sch_prescriptions {
  376. var cus CustomTemplate
  377. cus.ID = item.ID
  378. cus.UserOrgId = item.UserOrgId
  379. cus.PatientId = item.PatientId
  380. cus.MedType = item.MedType
  381. cus.RecordDate = item.RecordDate
  382. cus.Type = item.Type
  383. cus.PType = item.PType
  384. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  385. if subItem.FrequencyType == 1 { //每次必推
  386. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  387. }
  388. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  389. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  390. }
  391. if subItem.FrequencyType == 2 { //按照天数频率
  392. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  393. now := p.Unix()
  394. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  395. dayStr2 := "-" + dayStr
  396. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  397. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  398. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  399. if len(advices) == 0 {
  400. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  401. }
  402. }
  403. }
  404. for _, subItem := range item.HisPrescriptionProjectTemplate {
  405. if subItem.FrequencyType == 1 {
  406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  407. }
  408. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  409. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  410. }
  411. if subItem.FrequencyType == 2 {
  412. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  413. now := p.Unix()
  414. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  415. dayStr2 := "-" + dayStr
  416. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  417. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  418. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  419. if len(projects) == 0 {
  420. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  421. }
  422. }
  423. }
  424. sch_prescriptions = append(sch_prescriptions, cus)
  425. }
  426. for _, item := range sch_prescriptions {
  427. if len(item.HisPrescriptionProjectTemplate) == 0 {
  428. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  429. }
  430. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  431. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  432. }
  433. }
  434. }
  435. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  436. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  437. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  438. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  439. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  440. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  441. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  443. //获取所有科室信息
  444. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  445. c.ServeSuccessJSON(map[string]interface{}{
  446. "his_info": his_patient_info,
  447. "xt_info": xt_patient_info,
  448. "prescription": prescriptions,
  449. "case_history": case_history,
  450. "info": patientPrescriptionInfo,
  451. //"month_prescriptions": monthPrescriptions,
  452. "order": order,
  453. "doctors": doctors,
  454. "department": department,
  455. "sch_prescriptions": sch_prescriptions,
  456. "last_prescriptions": last_prescriptions,
  457. "schedule": sch,
  458. "count": count,
  459. "drugStockConfig": drugStockConfig,
  460. "last_info": lastPatientPrescriptionInfo,
  461. })
  462. return
  463. }
  464. func (c *HisApiController) GetHisPrescriptionConfig() {
  465. adminInfo := c.GetAdminUserInfo()
  466. //获取医嘱模版
  467. //advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  468. //获取所有基础药
  469. drugways_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_drugways"
  470. efs_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_efs"
  471. doctors_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_doctors"
  472. department_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_department"
  473. sick_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_sick"
  474. diagnose_keys := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + "_diagnose"
  475. redis := service.RedisClient()
  476. defer redis.Close()
  477. drugways_str, _ := redis.Get(drugways_keys).Result()
  478. efs_str, _ := redis.Get(efs_keys).Result()
  479. doctors_str, _ := redis.Get(doctors_keys).Result()
  480. department_str, _ := redis.Get(department_keys).Result()
  481. sick_str, _ := redis.Get(sick_keys).Result()
  482. diagnose_str, _ := redis.Get(diagnose_keys).Result()
  483. var drugways []*models.DrugwayDic
  484. var efs []*models.ExecutionFrequencyDic
  485. var roles []*models.UserAdminRole
  486. var departments []*models.XtHisDepartment
  487. var sicks []*models.OutpatientServiceSick
  488. var diagnose []*models.HisXtDiagnoseConfig
  489. if len(drugways_str) == 0 {
  490. drugways, _, _ = service.GetDrugWayDics(adminInfo.CurrentOrgId)
  491. drugways_str, err := json.Marshal(drugways)
  492. if err == nil {
  493. redis.Set(drugways_keys, string(drugways_str), time.Second*60*60*18)
  494. } else {
  495. redis.Set(drugways_keys, "", time.Second*60*60*18)
  496. }
  497. } else {
  498. err := json.Unmarshal([]byte(drugways_str), &drugways)
  499. if err != nil {
  500. drugways, _, _ = service.GetDrugWayDics(adminInfo.CurrentOrgId)
  501. drugways_str, err := json.Marshal(drugways)
  502. if err == nil {
  503. redis.Set(drugways_keys, string(drugways_str), time.Second*60*60*18)
  504. } else {
  505. redis.Set(drugways_keys, "", time.Second*60*60*18)
  506. }
  507. }
  508. }
  509. if len(efs_str) == 0 {
  510. efs, _, _ = service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  511. efs_str, err := json.Marshal(efs)
  512. if err == nil {
  513. redis.Set(efs_keys, string(efs_str), time.Second*60*60*18)
  514. } else {
  515. redis.Set(efs_keys, "", time.Second*60*60*18)
  516. }
  517. } else {
  518. err := json.Unmarshal([]byte(efs_str), &efs)
  519. if err != nil {
  520. efs, _, _ = service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  521. efs_str, err := json.Marshal(efs)
  522. if err == nil {
  523. redis.Set(efs_keys, string(efs_str), time.Second*60*60*18)
  524. } else {
  525. redis.Set(efs_keys, "", time.Second*60*60*18)
  526. }
  527. }
  528. }
  529. if len(doctors_str) == 0 {
  530. roles, _ = service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  531. doctors_str, err := json.Marshal(roles)
  532. if err == nil {
  533. redis.Set(doctors_keys, string(doctors_str), time.Second*60*60*18)
  534. } else {
  535. redis.Set(doctors_keys, "", time.Second*60*60*18)
  536. }
  537. } else {
  538. err := json.Unmarshal([]byte(doctors_str), &efs)
  539. if err != nil {
  540. roles, _ = service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  541. doctors_str, err := json.Marshal(roles)
  542. if err == nil {
  543. redis.Set(doctors_keys, string(doctors_str), time.Second*60*60*18)
  544. } else {
  545. redis.Set(doctors_keys, "", time.Second*60*60*18)
  546. }
  547. }
  548. }
  549. if len(department_str) == 0 {
  550. departments, _ = service.GetAllDepartMent(adminInfo.CurrentOrgId)
  551. department_str, err := json.Marshal(departments)
  552. if err == nil {
  553. redis.Set(department_keys, string(department_str), time.Second*60*60*18)
  554. } else {
  555. redis.Set(department_keys, "", time.Second*60*60*18)
  556. }
  557. } else {
  558. err := json.Unmarshal([]byte(department_str), &departments)
  559. if err != nil {
  560. departments, _ = service.GetAllDepartMent(adminInfo.CurrentOrgId)
  561. department_str, _ := json.Marshal(departments)
  562. redis.Set(department_keys, string(department_str), time.Second*60*60*18)
  563. }
  564. }
  565. if len(sick_str) == 0 {
  566. sicks, _ = service.FindAllSick(adminInfo.CurrentOrgId)
  567. sick_str, err := json.Marshal(sicks)
  568. if err == nil {
  569. redis.Set(sick_keys, string(sick_str), time.Second*60*60*18)
  570. } else {
  571. redis.Set(sick_keys, "", time.Second*60*60*18)
  572. }
  573. } else {
  574. err := json.Unmarshal([]byte(sick_str), &sicks)
  575. if err != nil {
  576. sicks, _ = service.FindAllSick(adminInfo.CurrentOrgId)
  577. sick_str, _ := json.Marshal(sicks)
  578. redis.Set(sick_keys, string(sick_str), time.Second*60*60*18)
  579. }
  580. }
  581. if len(diagnose_str) == 0 {
  582. diagnose, _ = service.FindAllDiagnose(adminInfo.CurrentOrgId)
  583. diagnose_str, err := json.Marshal(diagnose)
  584. if err == nil {
  585. redis.Set(diagnose_keys, string(diagnose_str), time.Second*60*60*18)
  586. } else {
  587. redis.Set(diagnose_keys, "", time.Second*60*60*18)
  588. }
  589. } else {
  590. err := json.Unmarshal([]byte(diagnose_str), &sicks)
  591. if err != nil {
  592. diagnose, _ = service.FindAllDiagnose(adminInfo.CurrentOrgId)
  593. diagnose_str, err := json.Marshal(diagnose)
  594. if err == nil {
  595. redis.Set(diagnose_keys, string(diagnose_str), time.Second*60*60*18)
  596. } else {
  597. redis.Set(diagnose_keys, "", time.Second*60*60*18)
  598. }
  599. }
  600. }
  601. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  602. //获取所有科室信息
  603. //获取诊断信息
  604. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  605. c.ServeSuccessJSON(map[string]interface{}{
  606. "drugs": drugs,
  607. //"advices_template": advices,
  608. "drugways": drugways,
  609. "efs": efs,
  610. "doctors": roles,
  611. "department": departments,
  612. "sick": sicks,
  613. "additions": additions,
  614. "diagnose": diagnose,
  615. })
  616. }
  617. func (c *HisApiController) CreateHisPrescription() {
  618. record_date := c.GetString("record_date")
  619. patient_id, _ := c.GetInt64("patient_id")
  620. reg_type, _ := c.GetInt64("reg_type")
  621. diagnose := c.GetString("diagnose")
  622. sick_type, _ := c.GetInt64("sick_type")
  623. sick_history := c.GetString("sick_history")
  624. doctor_id, _ := c.GetInt64("doctor", 0)
  625. department, _ := c.GetInt64("department", 0)
  626. his_patient_id, _ := c.GetInt64("his_patient_id")
  627. p_type, _ := c.GetInt64("p_type")
  628. dataBody := make(map[string]interface{}, 0)
  629. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  630. if err != nil {
  631. utils.ErrorLog(err.Error())
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. timeLayout := "2006-01-02"
  636. loc, _ := time.LoadLocation("Local")
  637. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  638. if err != nil {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. adminInfo := c.GetAdminUserInfo()
  643. recordDateTime := theTime.Unix()
  644. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  645. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  646. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  647. if len(lists) == 1 {
  648. his_patient_id = lists[0].ID
  649. }
  650. }
  651. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  652. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  653. if drugStockConfig.IsOpen == 1 {
  654. //校验库存总量
  655. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  656. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  657. if len(prescriptions) > 0 {
  658. for _, item := range prescriptions {
  659. items := item.(map[string]interface{})
  660. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  661. advices := items["advices"].([]interface{})
  662. if len(advices) > 0 {
  663. for _, advice := range advices {
  664. var drug_id int64
  665. var prescribing_number float64
  666. var prescribingNumberUnit string
  667. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  668. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  669. }
  670. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  671. //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
  672. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  673. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  674. }
  675. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  676. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  677. }
  678. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
  679. if drug.ID == 0 {
  680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  681. return
  682. }
  683. if prescribingNumberUnit == drug.MinUnit {
  684. if prescribing_number > drug.Total {
  685. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  686. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  687. return
  688. }
  689. } else {
  690. if prescribingNumberUnit == drug.MaxUnit {
  691. num := prescribing_number * float64(drug.MinNumber)
  692. if num > drug.Total {
  693. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  694. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  695. return
  696. }
  697. }
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. }
  705. }
  706. if stockConfig.IsOpen == 1 {
  707. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  708. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  709. if len(prescriptions) > 0 {
  710. for _, item := range prescriptions {
  711. items := item.(map[string]interface{})
  712. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  713. projects := items["project"].([]interface{})
  714. if len(projects) > 0 {
  715. for _, project := range projects {
  716. var project_id int64
  717. var project_type int64
  718. var totals float64
  719. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  720. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  721. }
  722. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  723. project_type = int64(project.(map[string]interface{})["type"].(float64))
  724. }
  725. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  726. total, _ := project.(map[string]interface{})["total"].(string)
  727. totals, _ = strconv.ParseFloat(total, 64)
  728. }
  729. if project_type == 3 {
  730. good, _ := service.FindGoodInfoByIdTwo(project_id)
  731. if good.ID == 0 {
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  733. return
  734. }
  735. if totals > good.Total {
  736. c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
  737. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  738. return
  739. }
  740. }
  741. }
  742. }
  743. }
  744. }
  745. }
  746. }
  747. }
  748. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  749. var hpInfo models.HisPrescriptionInfo
  750. if info.ID == 0 {
  751. var randNum int
  752. randNum = rand.Intn(10000) + 1000
  753. timestamp := time.Now().Unix()
  754. tempTime := time.Unix(timestamp, 0)
  755. timeFormat := tempTime.Format("20060102150405")
  756. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  757. hpInfo = models.HisPrescriptionInfo{
  758. HisPatientId: his_patient_id,
  759. UserOrgId: adminInfo.CurrentOrgId,
  760. RecordDate: theTime.Unix(),
  761. PatientId: patient_id,
  762. Status: 1,
  763. Ctime: time.Now().Unix(),
  764. Mtime: time.Now().Unix(),
  765. Creator: adminInfo.AdminUser.Id,
  766. Modifier: adminInfo.AdminUser.Id,
  767. Diagnosis: diagnose,
  768. SickHistory: sick_history,
  769. Departments: department,
  770. RegisterType: reg_type,
  771. PrescriptionNumber: p_number,
  772. PrescriptionStatus: 1,
  773. Doctor: role.UserName,
  774. DoctorId: doctor_id,
  775. SickType: sick_type,
  776. PType: p_type,
  777. }
  778. service.SavePatientPrescriptionInfo(hpInfo)
  779. } else {
  780. hpInfo = models.HisPrescriptionInfo{
  781. ID: info.ID,
  782. UserOrgId: adminInfo.CurrentOrgId,
  783. RecordDate: info.RecordDate,
  784. PatientId: info.PatientId,
  785. Status: 1,
  786. Ctime: info.Ctime,
  787. Mtime: time.Now().Unix(),
  788. Creator: info.Creator,
  789. Modifier: adminInfo.AdminUser.Id,
  790. Diagnosis: diagnose,
  791. SickHistory: sick_history,
  792. Departments: department,
  793. RegisterType: reg_type,
  794. PrescriptionNumber: info.PrescriptionNumber,
  795. Doctor: role.UserName,
  796. PrescriptionStatus: info.PrescriptionStatus,
  797. DoctorId: doctor_id,
  798. SickType: sick_type,
  799. PType: info.PType,
  800. HisPatientId: info.HisPatientId,
  801. }
  802. service.SavePatientPrescriptionInfo(hpInfo)
  803. }
  804. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  805. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  806. var tempPrescription *models.HisPrescription
  807. if len(prescriptions) > 0 {
  808. for _, item := range prescriptions {
  809. items := item.(map[string]interface{})
  810. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  811. utils.ErrorLog("id")
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. id := int64(items["id"].(float64))
  816. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  817. tempPrescription = &new_prescription
  818. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  819. utils.ErrorLog("type")
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  821. return
  822. }
  823. types := int64(items["type"].(float64))
  824. if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
  825. utils.ErrorLog("order_status")
  826. }
  827. order_status := int64(items["order_status"].(float64))
  828. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  829. utils.ErrorLog("med_type")
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  834. if med_type == "0" {
  835. med_type = "14"
  836. }
  837. if order_status == 0 {
  838. order_status = 1
  839. }
  840. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  841. utils.ErrorLog("pre_time")
  842. }
  843. preTime, _ := items["pre_time"].(string)
  844. timeLayout := "2006-01-02"
  845. loc, _ := time.LoadLocation("Local")
  846. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  847. if err != nil {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  849. return
  850. }
  851. pTime := theTime2.Unix()
  852. ctime := time.Now().Unix()
  853. if tempPrescription.ID == 0 {
  854. prescription := &models.HisPrescription{
  855. ID: 0,
  856. PatientId: patient_id,
  857. UserOrgId: adminInfo.CurrentOrgId,
  858. RecordDate: recordDateTime,
  859. Ctime: ctime,
  860. Mtime: ctime,
  861. Type: types,
  862. Modifier: adminInfo.AdminUser.Id,
  863. Creator: adminInfo.AdminUser.Id,
  864. Status: 1,
  865. Doctor: role.UserName,
  866. HisPatientId: his_patient_id,
  867. OrderStatus: order_status,
  868. BatchNumber: "",
  869. PrescriptionNumber: hpInfo.PrescriptionNumber,
  870. PreTime: pTime,
  871. PType: p_type,
  872. MedType: med_type,
  873. }
  874. tempPrescription = prescription
  875. service.SaveHisPrescription(tempPrescription)
  876. } else {
  877. tempPrescription.ID = id
  878. tempPrescription.Type = types
  879. tempPrescription.Modifier = adminInfo.AdminUser.Id
  880. tempPrescription.Mtime = time.Now().Unix()
  881. tempPrescription.Doctor = role.UserName
  882. tempPrescription.OrderStatus = order_status
  883. tempPrescription.PreTime = pTime
  884. tempPrescription.MedType = med_type
  885. service.SaveHisPrescription(tempPrescription)
  886. }
  887. //service.SaveHisPrescription(prescription)
  888. //更改患者挂号状态
  889. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  890. fmt.Println("更改失败", err2)
  891. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  892. advices := items["advices"].([]interface{})
  893. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  894. groupNo := int64(0)
  895. ctime := time.Now().Unix()
  896. mtime := ctime
  897. if len(advices) > 0 {
  898. for _, advice := range advices {
  899. var s models.HisDoctorAdviceInfo
  900. s.PrescriptionId = tempPrescription.ID
  901. s.AdviceType = 2
  902. s.AdviceDoctor = doctor_id
  903. s.StopState = 2
  904. s.ExecutionState = 2
  905. s.AdviceDate = recordDateTime
  906. s.Status = 1
  907. s.UserOrgId = adminInfo.CurrentOrgId
  908. s.RecordDate = recordDateTime
  909. s.StartTime = tempPrescription.PreTime
  910. s.Groupno = groupNo
  911. s.CreatedTime = ctime
  912. s.UpdatedTime = mtime
  913. s.PatientId = patient_id
  914. s.HisPatientId = his_patient_id
  915. s.StartTime = pTime
  916. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  917. if errcode > 0 {
  918. c.ServeFailJSONWithSGJErrorCode(errcode)
  919. return
  920. }
  921. s.StartTime = pTime
  922. service.CreateHisDoctorAdvice(&s)
  923. var randNum int
  924. randNum = rand.Intn(10000) + 1000
  925. timestamp := time.Now().Unix()
  926. tempTime := time.Unix(timestamp, 0)
  927. timeFormat := tempTime.Format("20060102150405")
  928. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  929. service.CreateHisDoctorAdvice(&s)
  930. }
  931. }
  932. }
  933. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  934. projects := items["project"].([]interface{})
  935. if len(projects) > 0 {
  936. for _, project := range projects {
  937. var p models.HisPrescriptionProject
  938. p.PrescriptionId = tempPrescription.ID
  939. p.Ctime = time.Now().Unix()
  940. p.Mtime = time.Now().Unix()
  941. p.PatientId = patient_id
  942. p.RecordDate = recordDateTime
  943. p.Doctor = doctor_id
  944. p.UserOrgId = adminInfo.CurrentOrgId
  945. p.HisPatientId = his_patient_id
  946. p.Status = 1
  947. p.StartTime = pTime
  948. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  949. if errcode > 0 {
  950. c.ServeFailJSONWithSGJErrorCode(errcode)
  951. return
  952. }
  953. service.CreateHisProjectTwo(&p)
  954. var randNum int
  955. randNum = rand.Intn(10000) + 1000
  956. timestamp := time.Now().Unix()
  957. tempTime := time.Unix(timestamp, 0)
  958. timeFormat := tempTime.Format("20060102150405")
  959. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  960. service.SaveHisProjectTwo(&p)
  961. if p.Type == 3 { //处理透前准备耗材数量数据
  962. consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  963. if consumables.ID > 0 {
  964. consumables.Count = int64(p.Count)
  965. service.UpdateConsumables(&consumables)
  966. }
  967. }
  968. }
  969. }
  970. }
  971. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  972. addition := items["addition"].([]interface{})
  973. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  974. ctime := time.Now().Unix()
  975. mtime := ctime
  976. if len(addition) > 0 {
  977. for _, item := range addition {
  978. var s models.HisAdditionalCharge
  979. s.PrescriptionId = tempPrescription.ID
  980. s.Status = 1
  981. s.UserOrgId = adminInfo.CurrentOrgId
  982. s.RecordDate = recordDateTime
  983. s.CreatedTime = ctime
  984. s.UpdatedTime = mtime
  985. s.PatientId = patient_id
  986. s.HisPatientId = his_patient_id
  987. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  988. if errcode > 0 {
  989. c.ServeFailJSONWithSGJErrorCode(errcode)
  990. return
  991. }
  992. service.CreateAdditionalCharge(&s)
  993. var randNum int
  994. randNum = rand.Intn(10000) + 1000
  995. timestamp := time.Now().Unix()
  996. tempTime := time.Unix(timestamp, 0)
  997. timeFormat := tempTime.Format("20060102150405")
  998. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  999. service.CreateAdditionalCharge(&s)
  1000. }
  1001. }
  1002. }
  1003. }
  1004. }
  1005. }
  1006. if err == nil {
  1007. c.ServeSuccessJSON(map[string]interface{}{
  1008. "msg": "保存成功",
  1009. })
  1010. return
  1011. } else {
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1013. return
  1014. }
  1015. }
  1016. func (c *HisApiController) EditHisPrescription() {
  1017. record_date := c.GetString("record_date")
  1018. patient_id, _ := c.GetInt64("patient_id")
  1019. reg_type, _ := c.GetInt64("reg_type")
  1020. //diagnose, _ := c.GetInt64("diagnose", 0)
  1021. diagnose := c.GetString("diagnose")
  1022. sick_type, _ := c.GetInt64("sick_type")
  1023. sick_history := c.GetString("sick_history")
  1024. doctor_id, _ := c.GetInt64("doctor", 0)
  1025. department, _ := c.GetInt64("department", 0)
  1026. his_patient_id, _ := c.GetInt64("his_patient_id")
  1027. p_type, _ := c.GetInt64("p_type")
  1028. dataBody := make(map[string]interface{}, 0)
  1029. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1030. if err != nil {
  1031. utils.ErrorLog(err.Error())
  1032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1033. return
  1034. }
  1035. timeLayout := "2006-01-02"
  1036. loc, _ := time.LoadLocation("Local")
  1037. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1038. if err != nil {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1040. return
  1041. }
  1042. adminInfo := c.GetAdminUserInfo()
  1043. recordDateTime := theTime.Unix()
  1044. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1045. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
  1046. var hpInfo models.HisPrescriptionInfo
  1047. if info.ID == 0 {
  1048. var randNum int
  1049. randNum = rand.Intn(10000) + 1000
  1050. timestamp := time.Now().Unix()
  1051. tempTime := time.Unix(timestamp, 0)
  1052. timeFormat := tempTime.Format("20060102150405")
  1053. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1054. hpInfo = models.HisPrescriptionInfo{
  1055. UserOrgId: adminInfo.CurrentOrgId,
  1056. RecordDate: theTime.Unix(),
  1057. PatientId: patient_id,
  1058. Status: 1,
  1059. Ctime: time.Now().Unix(),
  1060. Mtime: time.Now().Unix(),
  1061. Creator: adminInfo.AdminUser.Id,
  1062. Modifier: adminInfo.AdminUser.Id,
  1063. Diagnosis: diagnose,
  1064. SickHistory: sick_history,
  1065. Departments: department,
  1066. RegisterType: reg_type,
  1067. PrescriptionNumber: p_number,
  1068. PrescriptionStatus: 1,
  1069. Doctor: role.UserName,
  1070. DoctorId: doctor_id,
  1071. SickType: sick_type,
  1072. PType: p_type,
  1073. }
  1074. service.SavePatientPrescriptionInfo(hpInfo)
  1075. } else {
  1076. hpInfo = models.HisPrescriptionInfo{
  1077. ID: info.ID,
  1078. UserOrgId: adminInfo.CurrentOrgId,
  1079. RecordDate: info.RecordDate,
  1080. PatientId: info.PatientId,
  1081. Status: 1,
  1082. Ctime: info.Ctime,
  1083. Mtime: time.Now().Unix(),
  1084. Creator: info.Creator,
  1085. Modifier: adminInfo.AdminUser.Id,
  1086. Diagnosis: diagnose,
  1087. SickHistory: sick_history,
  1088. Departments: department,
  1089. RegisterType: reg_type,
  1090. PrescriptionNumber: info.PrescriptionNumber,
  1091. Doctor: role.UserName,
  1092. PrescriptionStatus: info.PrescriptionStatus,
  1093. DoctorId: doctor_id,
  1094. SickType: sick_type,
  1095. PType: info.PType,
  1096. }
  1097. service.SavePatientPrescriptionInfo(hpInfo)
  1098. }
  1099. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1100. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1101. if len(prescriptions) > 0 {
  1102. for _, item := range prescriptions {
  1103. items := item.(map[string]interface{})
  1104. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1105. utils.ErrorLog("id")
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1107. return
  1108. }
  1109. id := int64(items["id"].(float64))
  1110. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1111. utils.ErrorLog("type")
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1113. return
  1114. }
  1115. types := int64(items["type"].(float64))
  1116. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1117. utils.ErrorLog("med_type")
  1118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1119. return
  1120. }
  1121. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1122. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1123. ctime := time.Now().Unix()
  1124. prescription := &models.HisPrescription{
  1125. ID: id,
  1126. PatientId: patient_id,
  1127. UserOrgId: adminInfo.CurrentOrgId,
  1128. RecordDate: recordDateTime,
  1129. Ctime: ctime,
  1130. Mtime: ctime,
  1131. Type: types,
  1132. Modifier: adminInfo.AdminUser.Id,
  1133. Creator: adminInfo.AdminUser.Id,
  1134. Status: 1,
  1135. Doctor: role.UserName,
  1136. HisPatientId: his_patient_id,
  1137. OrderStatus: 1,
  1138. BatchNumber: "",
  1139. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1140. PType: hpInfo.PType,
  1141. MedType: med_type,
  1142. }
  1143. if historyPrescription.ID > 0 {
  1144. prescription.PreTime = historyPrescription.PreTime
  1145. }
  1146. service.SaveHisPrescription(prescription)
  1147. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1148. advices := items["advices"].([]interface{})
  1149. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1150. groupNo := int64(0)
  1151. ctime := time.Now().Unix()
  1152. mtime := ctime
  1153. if len(advices) > 0 {
  1154. for _, advice := range advices {
  1155. var s models.HisDoctorAdviceInfo
  1156. s.PrescriptionId = prescription.ID
  1157. s.AdviceType = 2
  1158. s.AdviceDoctor = adminInfo.AdminUser.Id
  1159. s.StopState = 2
  1160. s.ExecutionState = 2
  1161. s.AdviceDate = recordDateTime
  1162. s.Status = 1
  1163. s.UserOrgId = adminInfo.CurrentOrgId
  1164. s.RecordDate = recordDateTime
  1165. s.StartTime = prescription.PreTime
  1166. s.Groupno = groupNo
  1167. s.CreatedTime = ctime
  1168. s.UpdatedTime = mtime
  1169. s.PatientId = patient_id
  1170. s.HisPatientId = his_patient_id
  1171. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1172. if errcode > 0 {
  1173. c.ServeFailJSONWithSGJErrorCode(errcode)
  1174. return
  1175. }
  1176. service.CreateHisDoctorAdvice(&s)
  1177. }
  1178. }
  1179. }
  1180. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1181. projects := items["project"].([]interface{})
  1182. if len(projects) > 0 {
  1183. for _, project := range projects {
  1184. var p models.HisPrescriptionProject
  1185. p.PrescriptionId = prescription.ID
  1186. p.Ctime = time.Now().Unix()
  1187. p.Mtime = time.Now().Unix()
  1188. p.PatientId = patient_id
  1189. p.RecordDate = recordDateTime
  1190. p.UserOrgId = adminInfo.CurrentOrgId
  1191. p.HisPatientId = his_patient_id
  1192. p.Status = 1
  1193. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1194. if errcode > 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(errcode)
  1196. return
  1197. }
  1198. service.CreateHisProjectTwo(&p)
  1199. }
  1200. }
  1201. }
  1202. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1203. addition := items["addition"].([]interface{})
  1204. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1205. ctime := time.Now().Unix()
  1206. mtime := ctime
  1207. if len(addition) > 0 {
  1208. for _, item := range addition {
  1209. var s models.HisAdditionalCharge
  1210. s.PrescriptionId = prescription.ID
  1211. s.Status = 1
  1212. s.UserOrgId = adminInfo.CurrentOrgId
  1213. s.RecordDate = recordDateTime
  1214. s.CreatedTime = ctime
  1215. s.UpdatedTime = mtime
  1216. s.PatientId = patient_id
  1217. s.HisPatientId = his_patient_id
  1218. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1219. if errcode > 0 {
  1220. c.ServeFailJSONWithSGJErrorCode(errcode)
  1221. return
  1222. }
  1223. service.CreateAdditionalCharge(&s)
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. if err == nil {
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "msg": "保存成功",
  1233. })
  1234. return
  1235. } else {
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1237. return
  1238. }
  1239. }
  1240. func (c *HisApiController) DeletePrescription() {
  1241. prescription_id, _ := c.GetInt64("id")
  1242. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1243. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1244. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1245. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1246. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1247. if err == nil {
  1248. if len(projects) > 0 {
  1249. for _, item := range projects {
  1250. if stockConfig.IsOpen == 1 {
  1251. if item.Type == 3 {
  1252. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1253. f_count, _ := strconv.ParseFloat(strconv.FormatInt(int64(item.Count), 10), 64)
  1254. good.Total = good.Total + f_count
  1255. service.UpdateGoodInfo(&good)
  1256. }
  1257. }
  1258. if item.Type == 3 { //处理透前准备耗材数量数据
  1259. consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
  1260. if consumables.ID > 0 {
  1261. consumables.Count = 0
  1262. service.UpdateConsumables(&consumables)
  1263. }
  1264. }
  1265. }
  1266. }
  1267. if drugStockConfig.IsOpen == 1 {
  1268. if len(advices) > 0 {
  1269. for _, item := range advices {
  1270. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1271. if item.PrescribingNumberUnit == drug.MinUnit {
  1272. drug.Total = drug.Total + item.PrescribingNumber
  1273. service.UpdateBaseDrugLib(&drug)
  1274. } else {
  1275. if item.PrescribingNumberUnit == drug.MaxUnit {
  1276. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  1277. drug.Total = drug.Total + item.PrescribingNumber
  1278. service.UpdateBaseDrugLib(&drug)
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. c.ServeSuccessJSON(map[string]interface{}{
  1285. "msg": "删除成功",
  1286. })
  1287. return
  1288. } else {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1290. return
  1291. }
  1292. }
  1293. func (c *HisApiController) DeleteDoctorAdvice() {
  1294. id, _ := c.GetInt64("id")
  1295. advice, _ := service.GetHisDoctorAdvicesById(id)
  1296. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1297. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  1298. if err == nil {
  1299. if drugStockConfig.IsOpen == 1 {
  1300. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  1301. if advice.PrescribingNumberUnit == drug.MinUnit {
  1302. drug.Total = drug.Total + advice.PrescribingNumber
  1303. service.UpdateBaseDrugLib(&drug)
  1304. } else {
  1305. if advice.PrescribingNumberUnit == drug.MaxUnit {
  1306. advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
  1307. drug.Total = drug.Total + advice.PrescribingNumber
  1308. service.UpdateBaseDrugLib(&drug)
  1309. }
  1310. }
  1311. }
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "msg": "删除成功",
  1314. })
  1315. return
  1316. } else {
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1318. return
  1319. }
  1320. }
  1321. func (c *HisApiController) DeleteProject() {
  1322. id, _ := c.GetInt64("id")
  1323. adminInfo := c.GetAdminUserInfo()
  1324. project, _ := service.GetHisProjectByID(id)
  1325. var consumable models.DialysisBeforePrepare
  1326. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1327. if project.ID > 0 && project.Type == 3 {
  1328. consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
  1329. }
  1330. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  1331. if err == nil {
  1332. if stockConfig.IsOpen == 1 {
  1333. if project.Type == 3 {
  1334. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1335. f_count, _ := strconv.ParseFloat(strconv.FormatInt(int64(project.Count), 10), 64)
  1336. good.Total = good.Total + f_count
  1337. service.UpdateGoodInfo(&good)
  1338. }
  1339. }
  1340. if consumable.ID > 0 {
  1341. consumable.Count = 0
  1342. service.UpdateConsumables(&consumable)
  1343. }
  1344. c.ServeSuccessJSON(map[string]interface{}{
  1345. "msg": "删除成功",
  1346. })
  1347. return
  1348. } else {
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1350. return
  1351. }
  1352. }
  1353. func (c *HisApiController) CreateHisAdditionalCharge() {
  1354. his_patient_id, _ := c.GetInt64("his_patient_id")
  1355. patient_id, _ := c.GetInt64("patient_id")
  1356. record_date := c.GetString("record_date")
  1357. timeLayout := "2006-01-02"
  1358. loc, _ := time.LoadLocation("Local")
  1359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1360. if err != nil {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. adminInfo := c.GetAdminUserInfo()
  1365. recordDateTime := theTime.Unix()
  1366. dataBody := make(map[string]interface{}, 0)
  1367. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1368. if err != nil {
  1369. utils.ErrorLog(err.Error())
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1371. return
  1372. }
  1373. var additions []*models.HisAdditionalCharge
  1374. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  1375. additions, _ := dataBody["addition"].([]interface{})
  1376. if len(additions) > 0 {
  1377. for _, item := range additions {
  1378. items := item.(map[string]interface{})
  1379. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  1380. utils.ErrorLog("item_id")
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1382. return
  1383. }
  1384. item_id := int64(items["item_id"].(float64))
  1385. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  1386. utils.ErrorLog("item_name")
  1387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1388. return
  1389. }
  1390. item_name := items["item_name"].(string)
  1391. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1392. utils.ErrorLog("price")
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1394. return
  1395. }
  1396. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1397. ctime := time.Now().Unix()
  1398. additional := &models.HisAdditionalCharge{
  1399. PatientId: patient_id,
  1400. HisPatientId: his_patient_id,
  1401. UserOrgId: adminInfo.CurrentOrgId,
  1402. RecordDate: recordDateTime,
  1403. CreatedTime: ctime,
  1404. UpdatedTime: ctime,
  1405. Modifier: adminInfo.AdminUser.Id,
  1406. Creator: adminInfo.AdminUser.Id,
  1407. Price: price,
  1408. ItemName: item_name,
  1409. ItemId: item_id,
  1410. Status: 1,
  1411. }
  1412. additions = append(additions, additional)
  1413. }
  1414. }
  1415. }
  1416. for _, item := range additions {
  1417. service.CreateAddtionalCharge(item)
  1418. }
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "msg": "创建成功",
  1421. })
  1422. }
  1423. func (c *HisApiController) CreateHisPatientCaseHistory() {
  1424. blood_fat := c.GetString("blood_fat")
  1425. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  1426. blood_sugar := c.GetString("blood_sugar")
  1427. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  1428. fmt.Println(bloodsugarfloat)
  1429. chief_conplaint := c.GetString("chief_conplaint")
  1430. dbp := c.GetString("dbp")
  1431. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  1432. delivery_way, _ := c.GetInt64("delivery_way")
  1433. diagnostic := c.GetString("diagnostic")
  1434. family_history := c.GetString("family_history")
  1435. height := c.GetString("height")
  1436. history_of_present_illness := c.GetString("history_of_present_illness")
  1437. is_infect, _ := c.GetInt64("is_infect")
  1438. fmt.Println("is", is_infect)
  1439. past_history := c.GetString("past_history")
  1440. patient_id, _ := c.GetInt64("patient_id")
  1441. his_patient_id, _ := c.GetInt64("his_patient_id")
  1442. fmt.Println("patient_id", patient_id)
  1443. personal_history := c.GetString("personal_history")
  1444. pulse := c.GetString("pulse")
  1445. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  1446. sbp := c.GetString("sbp")
  1447. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  1448. heightfloat, _ := strconv.ParseFloat(height, 64)
  1449. sicktype := c.GetString("sick_type")
  1450. fmt.Println("sicketype", sicktype)
  1451. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  1452. symptom := c.GetString("symptom")
  1453. sick_date := c.GetString("sick_date")
  1454. temperatures := c.GetString("temperature")
  1455. fmt.Println("temperatures", temperatures)
  1456. temperature, _ := strconv.ParseFloat(temperatures, 64)
  1457. record_date := c.GetString("record_date")
  1458. breathing := c.GetString("breathing")
  1459. doctor_advice := c.GetString("doctor_advice")
  1460. remark := c.GetString("remark")
  1461. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  1462. sick, _ := c.GetInt64("sick")
  1463. diagnose, _ := c.GetInt64("diagnose")
  1464. id, _ := c.GetInt64("id")
  1465. timeLayout := "2006-01-02"
  1466. loc, _ := time.LoadLocation("Local")
  1467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1468. allergic_history := c.GetString("allergic_history")
  1469. if err != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1471. return
  1472. }
  1473. recordDateTime := theTime.Unix()
  1474. fmt.Println("recordDataTime", recordDateTime)
  1475. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  1476. if err != nil {
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1478. return
  1479. }
  1480. sickTimes := sickTime.Unix()
  1481. ctime := time.Now().Unix()
  1482. caseHistory := models.HisPatientCaseHistory{
  1483. HisPatientId: his_patient_id,
  1484. PatientId: patient_id,
  1485. Temperature: temperature,
  1486. BloodSugar: bloodsugarfloat,
  1487. Pulse: pulsefloat,
  1488. Sbp: sbpfloat,
  1489. Dbp: dbpfloat,
  1490. Height: heightfloat,
  1491. BloodFat: bloodfatfloat,
  1492. SickType: sick_type,
  1493. Symptom: symptom,
  1494. SickDate: sickTimes,
  1495. IsInfect: is_infect,
  1496. HistoryOfPresentIllness: history_of_present_illness,
  1497. PastHistory: past_history,
  1498. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  1499. ChiefConplaint: chief_conplaint,
  1500. PersonalHistory: personal_history,
  1501. FamilyHistory: family_history,
  1502. Diagnostic: diagnostic,
  1503. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1504. Status: 1,
  1505. Ctime: ctime,
  1506. Mtime: ctime,
  1507. RecordDate: recordDateTime,
  1508. DeliveryWay: delivery_way,
  1509. Breathing: breathingfloat,
  1510. DoctorAdvice: doctor_advice,
  1511. Remark: remark,
  1512. Sick: sick,
  1513. Diagnose: diagnose,
  1514. AllergicHistory: allergic_history,
  1515. }
  1516. //查询该患者是否有病历
  1517. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  1518. if errcodes == gorm.ErrRecordNotFound {
  1519. err = service.SaveHisPatientCaseHistory(&caseHistory)
  1520. if err != nil {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1522. return
  1523. }
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "caseHistory": caseHistory,
  1526. })
  1527. return
  1528. } else if errcodes == nil {
  1529. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  1530. if err != nil {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1532. return
  1533. }
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "caseHistory": caseHistory,
  1536. })
  1537. }
  1538. //查询该患者是否有病历
  1539. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  1540. //if errcode == gorm.ErrRecordNotFound {
  1541. // err = service.SaveHisPatientCaseHistory(caseHistory)
  1542. // if err != nil {
  1543. // c.ServeSuccessJSON(map[string]interface{}{
  1544. // "msg": "保存成功",
  1545. // })
  1546. // }
  1547. //} else if errcode == nil {
  1548. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1549. // return
  1550. //}
  1551. }
  1552. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  1553. patient_id, _ := c.GetInt64("patient_id", 0)
  1554. adminUser := c.GetAdminUserInfo()
  1555. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  1556. c.ServeSuccessJSON(map[string]interface{}{
  1557. "list": caseHistorys,
  1558. })
  1559. }
  1560. func (c *HisApiController) GetHisPatientCaseHistory() {
  1561. record_date, _ := c.GetInt64("record_date", 0)
  1562. patient_id, _ := c.GetInt64("patient_id", 0)
  1563. admin := c.GetAdminUserInfo()
  1564. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  1565. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "info": info,
  1568. "case_history": case_history,
  1569. })
  1570. }
  1571. func (c *HisApiController) CreateCaseHistoryTemplate() {
  1572. template_name := c.GetString("template_name")
  1573. template_remark := c.GetString("template_remark")
  1574. doctor := c.GetAdminUserInfo().AdminUser.Id
  1575. diagnostic := c.GetString("diagnostic")
  1576. chief_conplaint := c.GetString("chief_conplain")
  1577. history_of_present_illness := c.GetString("history_of_present_illness")
  1578. past_history := c.GetString("past_history")
  1579. personal_history := c.GetString("personal_history")
  1580. family_history := c.GetString("family_history")
  1581. user_name := c.GetString("user_name")
  1582. doctor_advice := c.GetString("doctor_advice")
  1583. remark := c.GetString("remark")
  1584. //record_date := c.GetString("record_date")
  1585. //fmt.Println("record_date--------",record_date)
  1586. //timeLayout := "2006-01-02"
  1587. //loc, _ := time.LoadLocation("Local")
  1588. //
  1589. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. //if err != nil {
  1591. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. // return
  1593. //}
  1594. //recordDateTime := theTime.Unix()
  1595. ctime := time.Now().Unix()
  1596. template := models.HisCaseHistoryTemplate{
  1597. HistoryOfPresentIllness: history_of_present_illness,
  1598. PastHistory: past_history,
  1599. ChiefConplaint: chief_conplaint,
  1600. PersonalHistory: personal_history,
  1601. FamilyHistory: family_history,
  1602. Diagnostic: diagnostic,
  1603. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1604. Status: 1,
  1605. Ctime: ctime,
  1606. Mtime: ctime,
  1607. RecordDate: time.Now().Unix(),
  1608. TemplateName: template_name,
  1609. TemplateRemark: template_remark,
  1610. Creator: doctor,
  1611. Modifier: doctor,
  1612. UserName: user_name,
  1613. DoctorAdvice: doctor_advice,
  1614. Remark: remark,
  1615. }
  1616. err := service.SaveHisPatientCaseHistoryTemplate(template)
  1617. if err == nil {
  1618. c.ServeSuccessJSON(map[string]interface{}{
  1619. "msg": "保存成功",
  1620. })
  1621. } else {
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1623. return
  1624. }
  1625. }
  1626. func (c *HisApiController) GetCaseHistoryTemplate() {
  1627. timeLayout := "2006-01-02"
  1628. loc, _ := time.LoadLocation("Local")
  1629. keyword := c.GetString("keyword")
  1630. start_time := c.GetString("start_time")
  1631. end_time := c.GetString("end_time")
  1632. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1633. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1634. admin := c.GetAdminUserInfo()
  1635. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  1636. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  1637. c.ServeSuccessJSON(map[string]interface{}{
  1638. "template": template,
  1639. //"history": history,
  1640. })
  1641. }
  1642. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1643. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1644. utils.ErrorLog("drug_name")
  1645. return enums.ErrorCodeParamWrong
  1646. }
  1647. adviceName, _ := json["drug_name"].(string)
  1648. if len(adviceName) == 0 {
  1649. utils.ErrorLog("len(advice_name) == 0")
  1650. return enums.ErrorCodeParamWrong
  1651. }
  1652. advice.AdviceName = adviceName
  1653. adviceDesc, _ := json["advice_desc"].(string)
  1654. advice.AdviceDesc = adviceDesc
  1655. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1656. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1657. advice.DrugSpec = drugSpec
  1658. }
  1659. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1660. remark, _ := json["remark"].(string)
  1661. advice.Remark = remark
  1662. }
  1663. if json["id"] == nil {
  1664. advice.DrugId = 0
  1665. } else {
  1666. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1667. drug_id := int64(json["id"].(float64))
  1668. advice.DrugId = drug_id
  1669. }
  1670. }
  1671. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1672. advice_id := int64(json["advice_id"].(float64))
  1673. advice.ID = advice_id
  1674. if advice.ID > 0 {
  1675. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1676. if err == nil {
  1677. if hisAdvice.ID > 0 {
  1678. advice.ExecutionTime = hisAdvice.ExecutionTime
  1679. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1680. advice.ExecutionState = hisAdvice.ExecutionState
  1681. advice.CheckTime = hisAdvice.CheckTime
  1682. advice.Checker = hisAdvice.Checker
  1683. advice.CheckState = hisAdvice.CheckState
  1684. advice.StartTime = hisAdvice.StartTime
  1685. advice.FeedetlSn = hisAdvice.FeedetlSn
  1686. }
  1687. }
  1688. }
  1689. }
  1690. //
  1691. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1692. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1693. // advice.ExecutionTime = execution_time
  1694. //}
  1695. //
  1696. //
  1697. //
  1698. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1699. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1700. // advice.ExecutionStaff = execution_staff
  1701. //}
  1702. //
  1703. //
  1704. //
  1705. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1706. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1707. // advice.ExecutionState = execution_state
  1708. //}
  1709. //
  1710. //
  1711. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1712. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1713. // advice.CheckTime = check_time
  1714. //}
  1715. //
  1716. //
  1717. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1718. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1719. // advice.CheckState = check_state
  1720. //}
  1721. //
  1722. //
  1723. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1724. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1725. // advice.Checker = checker
  1726. //}
  1727. //
  1728. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1729. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1730. // advice.StartTime = start_time
  1731. //}
  1732. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1733. drugSpecUnit, _ := json["min_unit"].(string)
  1734. advice.DrugSpecUnit = drugSpecUnit
  1735. }
  1736. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1737. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1738. advice.SingleDose = singleDose
  1739. }
  1740. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1741. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1742. advice.SingleDoseUnit = singleDoseUnit
  1743. }
  1744. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1745. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1746. advice.PrescribingNumber = prescribingNumber
  1747. }
  1748. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1749. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1750. advice.PrescribingNumberUnit = prescribingNumberUnit
  1751. }
  1752. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1753. deliveryWay, _ := json["delivery_way"].(string)
  1754. advice.DeliveryWay = deliveryWay
  1755. }
  1756. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1757. executionFrequency, _ := json["execution_frequency"].(string)
  1758. advice.ExecutionFrequency = executionFrequency
  1759. }
  1760. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1761. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1762. advice.Price = price
  1763. }
  1764. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1765. med_list_codg, _ := json["medical_insurance_number"].(string)
  1766. advice.MedListCodg = med_list_codg
  1767. }
  1768. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1769. day := int64(json["day"].(float64))
  1770. advice.Day = day
  1771. }
  1772. return 0
  1773. }
  1774. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1775. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1776. id := int64(json["id"].(float64))
  1777. project.ID = id
  1778. historyProject, _ := service.GetHisProjectByID(id)
  1779. project.FeedetlSn = historyProject.FeedetlSn
  1780. }
  1781. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1782. project_id := int64(json["project_id"].(float64))
  1783. project.ProjectId = project_id
  1784. }
  1785. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1786. // price := int64(json["price"].(float64))
  1787. // formatInt_price := strconv.FormatInt(price, 10)
  1788. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1789. // project.Price = float_price
  1790. // }
  1791. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1792. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1793. project.Price = price
  1794. }
  1795. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1796. total, _ := json["total"].(string)
  1797. totals, _ := strconv.ParseInt(total, 10, 64)
  1798. project.Count = totals
  1799. }
  1800. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1801. medical_code, _ := json["medical_code"].(string)
  1802. project.MedListCodg = medical_code
  1803. }
  1804. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1805. single_dose, _ := json["single_dose"].(string)
  1806. project.SingleDose = single_dose
  1807. }
  1808. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1809. delivery_way, _ := json["delivery_way"].(string)
  1810. project.DeliveryWay = delivery_way
  1811. }
  1812. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1813. execution_frequency, _ := json["execution_frequency"].(string)
  1814. project.ExecutionFrequency = execution_frequency
  1815. }
  1816. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1817. remark, _ := json["remark"].(string)
  1818. project.Remark = remark
  1819. }
  1820. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1821. day, _ := json["number_days"].(string)
  1822. project.Day = day
  1823. }
  1824. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1825. unit, _ := json["unit"].(string)
  1826. project.Unit = unit
  1827. }
  1828. return 0
  1829. }
  1830. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1831. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1832. id := int64(json["id"].(float64))
  1833. historyAddtions, _ := service.GetHisAdditionByID(id)
  1834. additionalCharge.ID = id
  1835. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  1836. }
  1837. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1838. item_id := int64(json["item_id"].(float64))
  1839. additionalCharge.ItemId = item_id
  1840. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1841. if config.ID > 0 {
  1842. if len(config.Code) > 0 {
  1843. additionalCharge.MedListCodg = config.Code
  1844. }
  1845. }
  1846. }
  1847. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1848. // price := int64(json["price"].(float64))
  1849. // formatInt_price := strconv.FormatInt(price, 10)
  1850. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1851. // additionalCharge.Price = float_price
  1852. // }
  1853. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1854. // price := int64(json["price"].(float64))
  1855. // formatInt_price := strconv.FormatInt(price, 10)
  1856. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1857. // additionalCharge.Price = float_price
  1858. //}
  1859. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1860. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1861. additionalCharge.Price = price
  1862. }
  1863. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1864. count, _ := json["count"].(string)
  1865. counts, _ := strconv.ParseInt(count, 10, 64)
  1866. additionalCharge.Count = counts
  1867. }
  1868. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1869. item_name, _ := json["item_name"].(string)
  1870. additionalCharge.ItemName = item_name
  1871. }
  1872. return 0
  1873. }
  1874. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1875. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1876. utils.ErrorLog("drug_name")
  1877. return enums.ErrorCodeParamWrong
  1878. }
  1879. adviceName, _ := json["drug_name"].(string)
  1880. if len(adviceName) == 0 {
  1881. utils.ErrorLog("len(advice_name) == 0")
  1882. return enums.ErrorCodeParamWrong
  1883. }
  1884. advice.AdviceName = adviceName
  1885. adviceDesc, _ := json["advice_desc"].(string)
  1886. advice.AdviceDesc = adviceDesc
  1887. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1888. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1889. advice.DrugSpec = drugSpec
  1890. }
  1891. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1892. remark, _ := json["remark"].(string)
  1893. advice.Remark = remark
  1894. }
  1895. if json["id"] == nil {
  1896. advice.DrugId = 0
  1897. } else {
  1898. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1899. drug_id := int64(json["id"].(float64))
  1900. advice.DrugId = drug_id
  1901. }
  1902. }
  1903. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  1904. groupno := int64(json["groupno"].(float64))
  1905. advice.Groupno = groupno
  1906. }
  1907. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  1908. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  1909. advice.HospApprFlag = hosp_appr_flag
  1910. }
  1911. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1912. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1913. advice.PrescribingNumber = prescribingNumber
  1914. }
  1915. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  1916. // frequency_type := int64(json["frequency_type"].(float64))
  1917. // advice.FrequencyType = frequency_type
  1918. //}
  1919. //
  1920. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  1921. // day_count := int64(json["day_count"].(float64))
  1922. // advice.DayCount = day_count
  1923. //}
  1924. //
  1925. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  1926. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  1927. // week_day, _ := json["week_day"].(string)
  1928. // advice.WeekDay = week_day
  1929. //}
  1930. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1931. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1932. advice.PrescribingNumberUnit = prescribingNumberUnit
  1933. }
  1934. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1935. advice_id := int64(json["advice_id"].(float64))
  1936. advice.ID = advice_id
  1937. if advice.ID > 0 {
  1938. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1939. if err == nil {
  1940. if hisAdvice.ID > 0 {
  1941. advice.ExecutionTime = hisAdvice.ExecutionTime
  1942. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1943. advice.ExecutionState = hisAdvice.ExecutionState
  1944. advice.CheckTime = hisAdvice.CheckTime
  1945. advice.Checker = hisAdvice.Checker
  1946. advice.CheckState = hisAdvice.CheckState
  1947. advice.StartTime = hisAdvice.StartTime
  1948. advice.HospApprFlag = hisAdvice.HospApprFlag
  1949. //advice.Groupno = hisAdvice.Groupno
  1950. }
  1951. }
  1952. }
  1953. }
  1954. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  1955. if drugStockConfig.IsOpen == 1 {
  1956. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  1957. if advice.ID == 0 { //医嘱不存在
  1958. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  1959. drug.Total = drug.Total - advice.PrescribingNumber
  1960. service.UpdateBaseDrugLib(&drug)
  1961. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  1962. num := advice.PrescribingNumber * float64(drug.MinNumber)
  1963. drug.Total = drug.Total - num
  1964. service.UpdateBaseDrugLib(&drug)
  1965. }
  1966. } else if advice.ID > 0 { //医嘱存在
  1967. hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  1968. var num float64
  1969. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  1970. if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  1971. if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  1972. num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  1973. drug.Total = drug.Total + num
  1974. service.UpdateBaseDrugLib(&drug)
  1975. } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  1976. num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  1977. drug.Total = drug.Total - num
  1978. service.UpdateBaseDrugLib(&drug)
  1979. }
  1980. } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  1981. num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1982. if num2 > advice.PrescribingNumber {
  1983. num = num2 - advice.PrescribingNumber
  1984. drug.Total = drug.Total + num
  1985. service.UpdateBaseDrugLib(&drug)
  1986. } else if num2 < advice.PrescribingNumber {
  1987. num = advice.PrescribingNumber - num2
  1988. drug.Total = drug.Total - num
  1989. service.UpdateBaseDrugLib(&drug)
  1990. }
  1991. }
  1992. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  1993. if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  1994. num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1995. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1996. if num1 > num2 {
  1997. num = num1 - num2
  1998. drug.Total = drug.Total + num
  1999. service.UpdateBaseDrugLib(&drug)
  2000. } else if num1 < num2 {
  2001. num = num2 - num1
  2002. drug.Total = drug.Total - num
  2003. service.UpdateBaseDrugLib(&drug)
  2004. }
  2005. } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  2006. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2007. //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  2008. if hisAdvice.PrescribingNumber > num2 {
  2009. num = hisAdvice.PrescribingNumber - num2
  2010. drug.Total = drug.Total + num
  2011. service.UpdateBaseDrugLib(&drug)
  2012. } else if num2 < advice.PrescribingNumber {
  2013. num = num2 - hisAdvice.PrescribingNumber
  2014. drug.Total = drug.Total - num
  2015. service.UpdateBaseDrugLib(&drug)
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. //
  2022. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2023. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2024. // advice.ExecutionTime = execution_time
  2025. //}
  2026. //
  2027. //
  2028. //
  2029. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2030. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2031. // advice.ExecutionStaff = execution_staff
  2032. //}
  2033. //
  2034. //
  2035. //
  2036. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2037. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2038. // advice.ExecutionState = execution_state
  2039. //}
  2040. //
  2041. //
  2042. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2043. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2044. // advice.CheckTime = check_time
  2045. //}
  2046. //
  2047. //
  2048. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2049. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2050. // advice.CheckState = check_state
  2051. //}
  2052. //
  2053. //
  2054. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2055. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2056. // advice.Checker = checker
  2057. //}
  2058. //
  2059. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2060. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2061. // advice.StartTime = start_time
  2062. //}
  2063. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2064. drugSpecUnit, _ := json["min_unit"].(string)
  2065. advice.DrugSpecUnit = drugSpecUnit
  2066. }
  2067. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2068. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2069. advice.SingleDose = singleDose
  2070. }
  2071. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2072. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2073. advice.SingleDoseUnit = singleDoseUnit
  2074. }
  2075. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2076. deliveryWay, _ := json["delivery_way"].(string)
  2077. advice.DeliveryWay = deliveryWay
  2078. }
  2079. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2080. executionFrequency, _ := json["execution_frequency"].(string)
  2081. advice.ExecutionFrequency = executionFrequency
  2082. }
  2083. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2084. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2085. advice.Price = price
  2086. }
  2087. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2088. med_list_codg, _ := json["medical_insurance_number"].(string)
  2089. advice.MedListCodg = med_list_codg
  2090. }
  2091. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2092. day := int64(json["day"].(float64))
  2093. advice.Day = day
  2094. }
  2095. return 0
  2096. }
  2097. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2098. project.ExecutionStaff = 0
  2099. project.ExecutionState = 2
  2100. project.ExecutionTime = 0
  2101. project.Checker = 0
  2102. project.CheckState = 2
  2103. project.CheckTime = 0
  2104. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2105. id := int64(json["id"].(float64))
  2106. project.ID = id
  2107. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  2108. project.ExecutionStaff = temp_project.ExecutionStaff
  2109. project.ExecutionState = temp_project.ExecutionState
  2110. project.ExecutionTime = temp_project.ExecutionTime
  2111. project.Checker = temp_project.Checker
  2112. project.CheckState = temp_project.CheckState
  2113. project.CheckTime = temp_project.CheckTime
  2114. project.TeamId = temp_project.TeamId
  2115. }
  2116. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  2117. types := int64(json["type"].(float64))
  2118. project.Type = types
  2119. }
  2120. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2121. project_id := int64(json["project_id"].(float64))
  2122. project.ProjectId = project_id
  2123. fmt.Println(project_id)
  2124. fmt.Println(project.ProjectId)
  2125. }
  2126. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  2127. team_id := int64(json["team_id"].(float64))
  2128. project.TeamId = team_id
  2129. }
  2130. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2131. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2132. project.Price = price
  2133. }
  2134. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2135. total, _ := json["total"].(string)
  2136. totals, _ := strconv.ParseInt(total, 10, 64)
  2137. project.Count = totals
  2138. }
  2139. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2140. medical_code, _ := json["medical_code"].(string)
  2141. project.MedListCodg = medical_code
  2142. }
  2143. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2144. single_dose, _ := json["single_dose"].(string)
  2145. project.SingleDose = single_dose
  2146. }
  2147. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2148. delivery_way, _ := json["delivery_way"].(string)
  2149. project.DeliveryWay = delivery_way
  2150. }
  2151. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2152. execution_frequency, _ := json["execution_frequency"].(string)
  2153. project.ExecutionFrequency = execution_frequency
  2154. }
  2155. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2156. remark, _ := json["remark"].(string)
  2157. project.Remark = remark
  2158. }
  2159. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2160. day, _ := json["number_days"].(string)
  2161. project.Day = day
  2162. }
  2163. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2164. unit, _ := json["unit"].(string)
  2165. project.Unit = unit
  2166. }
  2167. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  2168. // frequency_type := int64(json["frequency_type"].(float64))
  2169. // project.FrequencyType = frequency_type
  2170. //}
  2171. //
  2172. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  2173. // day_count := int64(json["day_count"].(float64))
  2174. // project.DayCount = day_count
  2175. //}
  2176. //
  2177. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  2178. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  2179. // week_day, _ := json["week_day"].(string)
  2180. // project.WeekDay = week_day
  2181. //}
  2182. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  2183. if project.ID == 0 {
  2184. if stockConfig.IsOpen == 1 {
  2185. if project.Type == 3 {
  2186. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2187. f_count, _ := strconv.ParseFloat(strconv.FormatInt(int64(project.Count), 10), 64)
  2188. good.Total = good.Total - f_count
  2189. service.UpdateGoodInfo(&good)
  2190. }
  2191. }
  2192. } else {
  2193. temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  2194. if stockConfig.IsOpen == 1 {
  2195. if project.Type == 3 {
  2196. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2197. if project.Count < temp_project.Count {
  2198. other_count := temp_project.Count - project.Count
  2199. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  2200. good.Total = good.Total + other_count_two
  2201. service.UpdateGoodInfo(&good)
  2202. } else if project.Count > temp_project.Count {
  2203. other_count := project.Count - temp_project.Count
  2204. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  2205. good.Total = good.Total - other_count_two
  2206. service.UpdateGoodInfo(&good)
  2207. }
  2208. }
  2209. }
  2210. }
  2211. return 0
  2212. }
  2213. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2214. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2215. id := int64(json["id"].(float64))
  2216. additionalCharge.ID = id
  2217. }
  2218. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2219. item_id := int64(json["item_id"].(float64))
  2220. additionalCharge.ItemId = item_id
  2221. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2222. if config.ID > 0 {
  2223. if len(config.Code) > 0 {
  2224. additionalCharge.MedListCodg = config.Code
  2225. }
  2226. }
  2227. }
  2228. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2229. // price := int64(json["price"].(float64))
  2230. // formatInt_price := strconv.FormatInt(price, 10)
  2231. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2232. // additionalCharge.Price = float_price
  2233. // }
  2234. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2235. // price := int64(json["price"].(float64))
  2236. // formatInt_price := strconv.FormatInt(price, 10)
  2237. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2238. // additionalCharge.Price = float_price
  2239. //}
  2240. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2241. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2242. additionalCharge.Price = price
  2243. }
  2244. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2245. count, _ := json["count"].(string)
  2246. counts, _ := strconv.ParseInt(count, 10, 64)
  2247. additionalCharge.Count = counts
  2248. }
  2249. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2250. item_name, _ := json["item_name"].(string)
  2251. additionalCharge.ItemName = item_name
  2252. }
  2253. return 0
  2254. }
  2255. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  2256. fmt.Println("~~~~~~")
  2257. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2258. utils.ErrorLog("drug_name")
  2259. return enums.ErrorCodeParamWrong
  2260. }
  2261. adviceName, _ := json["drug_name"].(string)
  2262. if len(adviceName) == 0 {
  2263. utils.ErrorLog("len(advice_name) == 0")
  2264. return enums.ErrorCodeParamWrong
  2265. }
  2266. advice.AdviceName = adviceName
  2267. adviceDesc, _ := json["advice_desc"].(string)
  2268. advice.AdviceDesc = adviceDesc
  2269. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2270. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2271. advice.DrugSpec = drugSpec
  2272. }
  2273. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2274. remark, _ := json["remark"].(string)
  2275. advice.Remark = remark
  2276. }
  2277. if json["id"] == nil {
  2278. advice.DrugId = 0
  2279. } else {
  2280. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2281. drug_id := int64(json["id"].(float64))
  2282. advice.DrugId = drug_id
  2283. }
  2284. }
  2285. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2286. drugSpecUnit, _ := json["min_unit"].(string)
  2287. advice.DrugSpecUnit = drugSpecUnit
  2288. }
  2289. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2290. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2291. advice.SingleDose = singleDose
  2292. }
  2293. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2294. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2295. advice.SingleDoseUnit = singleDoseUnit
  2296. }
  2297. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2298. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2299. advice.PrescribingNumber = prescribingNumber
  2300. }
  2301. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2302. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2303. advice.PrescribingNumberUnit = prescribingNumberUnit
  2304. }
  2305. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2306. deliveryWay, _ := json["delivery_way"].(string)
  2307. advice.DeliveryWay = deliveryWay
  2308. }
  2309. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2310. executionFrequency, _ := json["execution_frequency"].(string)
  2311. advice.ExecutionFrequency = executionFrequency
  2312. }
  2313. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2314. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2315. advice.Price = price
  2316. }
  2317. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2318. med_list_codg, _ := json["medical_insurance_number"].(string)
  2319. advice.MedListCodg = med_list_codg
  2320. }
  2321. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2322. day := int64(json["day"].(float64))
  2323. advice.Day = day
  2324. }
  2325. return 0
  2326. }
  2327. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  2328. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  2329. types := int64(json["type"].(float64))
  2330. project.Type = types
  2331. }
  2332. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2333. project_id := int64(json["project_id"].(float64))
  2334. project.ProjectId = project_id
  2335. }
  2336. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2337. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2338. project.Price = price
  2339. }
  2340. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2341. total, _ := json["total"].(string)
  2342. totals, _ := strconv.ParseInt(total, 10, 64)
  2343. project.Count = totals
  2344. }
  2345. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2346. medical_code, _ := json["medical_code"].(string)
  2347. project.MedListCodg = medical_code
  2348. }
  2349. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2350. single_dose, _ := json["single_dose"].(string)
  2351. project.SingleDose = single_dose
  2352. }
  2353. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2354. delivery_way, _ := json["delivery_way"].(string)
  2355. project.DeliveryWay = delivery_way
  2356. }
  2357. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2358. execution_frequency, _ := json["execution_frequency"].(string)
  2359. project.ExecutionFrequency = execution_frequency
  2360. }
  2361. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2362. remark, _ := json["remark"].(string)
  2363. project.Remark = remark
  2364. }
  2365. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2366. day, _ := json["number_days"].(string)
  2367. project.Day = day
  2368. }
  2369. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2370. unit, _ := json["unit"].(string)
  2371. project.Unit = unit
  2372. }
  2373. return 0
  2374. }
  2375. func (c *HisApiController) GetHisOrderList() {
  2376. page, _ := c.GetInt64("page", -1)
  2377. limit, _ := c.GetInt64("limit", -1)
  2378. start_time := c.GetString("start_time")
  2379. end_time := c.GetString("end_time")
  2380. types, _ := c.GetInt64("type", 0)
  2381. keywords := c.GetString("keywords")
  2382. p_type, _ := c.GetInt64("p_type", 0)
  2383. timeLayout := "2006-01-02"
  2384. loc, _ := time.LoadLocation("Local")
  2385. var startTime int64
  2386. if len(start_time) > 0 {
  2387. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2388. if err != nil {
  2389. fmt.Println(err)
  2390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2391. return
  2392. }
  2393. startTime = theTime.Unix()
  2394. }
  2395. var endTime int64
  2396. if len(end_time) > 0 {
  2397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2398. if err != nil {
  2399. utils.ErrorLog(err.Error())
  2400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2401. return
  2402. }
  2403. endTime = theTime.Unix()
  2404. }
  2405. adminUser := c.GetAdminUserInfo()
  2406. org_id := adminUser.CurrentOrgId
  2407. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  2408. for _, item := range order {
  2409. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  2410. item.DoctorName = info.Doctor
  2411. item.DepartmentName = info.XtHisDepartment.Name
  2412. }
  2413. if err == nil {
  2414. c.ServeSuccessJSON(map[string]interface{}{
  2415. "order": order,
  2416. "total": total,
  2417. })
  2418. } else {
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2420. return
  2421. }
  2422. }
  2423. func (c *HisApiController) GetHisOrder() {
  2424. patient_id, _ := c.GetInt64("patient_id", 0)
  2425. number := c.GetString("number")
  2426. adminInfo := c.GetAdminUserInfo()
  2427. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  2428. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  2429. if err == nil {
  2430. c.ServeSuccessJSON(map[string]interface{}{
  2431. "order": order,
  2432. "prescription": prescriptions,
  2433. })
  2434. } else {
  2435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2436. return
  2437. }
  2438. }
  2439. func (c *HisApiController) GetHisPrescriptionList() {
  2440. record_date := c.GetString("record_date")
  2441. keywords := c.GetString("keywords")
  2442. page, _ := c.GetInt64("page")
  2443. limit, _ := c.GetInt64("limit")
  2444. timeLayout := "2006-01-02"
  2445. loc, _ := time.LoadLocation("Local")
  2446. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2447. if err != nil {
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2449. return
  2450. }
  2451. recordDateTime := theTime.Unix()
  2452. adminInfo := c.GetAdminUserInfo()
  2453. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  2454. //adminInfo := c.GetAdminUserInfo()
  2455. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  2456. //fmt.Println(prescriptionOrder)
  2457. if err == nil {
  2458. c.ServeSuccessJSON(map[string]interface{}{
  2459. "order": prescriptionOrder,
  2460. "total": total,
  2461. })
  2462. } else {
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2464. return
  2465. }
  2466. }
  2467. func (c *HisApiController) GetHisPrescriptionInfo() {
  2468. id, _ := c.GetInt64("id")
  2469. adminInfo := c.GetAdminUserInfo()
  2470. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  2471. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  2472. if err == nil {
  2473. c.ServeSuccessJSON(map[string]interface{}{
  2474. "order": prescriptionOrder,
  2475. "prescription": prescription,
  2476. })
  2477. } else {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2479. return
  2480. }
  2481. }
  2482. func (c *HisApiController) GetMedicalInsuranceConfig() {
  2483. adminUser := c.GetAdminUserInfo()
  2484. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2485. c.ServeSuccessJSON(map[string]interface{}{
  2486. "config": config,
  2487. })
  2488. }
  2489. type ResultTwo struct {
  2490. ErrMsg interface{} `json:"err_msg"`
  2491. InfRefmsgid string `json:"inf_refmsgid"`
  2492. Infcode int64 `json:"infcode"`
  2493. Output struct {
  2494. Baseinfo struct {
  2495. Age float64 `json:"age"`
  2496. Brdy string `json:"brdy"`
  2497. Certno string `json:"certno"`
  2498. Gend string `json:"gend"`
  2499. Naty string `json:"naty"`
  2500. PsnCertType string `json:"psn_cert_type"`
  2501. PsnName string `json:"psn_name"`
  2502. PsnNo string `json:"psn_no"`
  2503. } `json:"baseinfo"`
  2504. Idetinfo []interface{} `json:"idetinfo"`
  2505. Iinfo []struct {
  2506. Balc float64 `json:"balc"`
  2507. CvlservFlag string `json:"cvlserv_flag"`
  2508. EmpName string `json:"emp_name"`
  2509. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  2510. Insutype string `json:"insutype"`
  2511. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  2512. PausInsuDate interface{} `json:"paus_insu_date"`
  2513. PsnInsuDate string `json:"psn_insu_date"`
  2514. PsnInsuStas string `json:"psn_insu_stas"`
  2515. PsnType string `json:"psn_type"`
  2516. } `json:"insuinfo"`
  2517. } `json:"output"`
  2518. RefmsgTime string `json:"refmsg_time"`
  2519. RespondTime string `json:"respond_time"`
  2520. Signtype interface{} `json:"signtype"`
  2521. WarnInfo interface{} `json:"warn_info"`
  2522. }
  2523. type ResultThree struct {
  2524. Cainfo interface{} `json:"cainfo"`
  2525. ErrMsg interface{} `json:"err_msg"`
  2526. InfRefmsgid string `json:"inf_refmsgid"`
  2527. Infcode int64 `json:"infcode"`
  2528. Output struct {
  2529. Data struct {
  2530. IptOtpNo string `json:"ipt_otp_no"`
  2531. MdtrtID string `json:"mdtrt_id"`
  2532. PsnNo string `json:"psn_no"`
  2533. } `json:"data"`
  2534. } `json:"output"`
  2535. RefmsgTime string `json:"refmsg_time"`
  2536. RespondTime string `json:"respond_time"`
  2537. Signtype interface{} `json:"signtype"`
  2538. WarnMsg interface{} `json:"warn_msg"`
  2539. }
  2540. type ResultFour struct {
  2541. Cainfo string `json:"cainfo"`
  2542. ErrMsg string `json:"err_msg"`
  2543. InfRefmsgid string `json:"inf_refmsgid"`
  2544. Infcode int64 `json:"infcode"`
  2545. Output struct {
  2546. Result []struct {
  2547. BasMednFlag string `json:"bas_medn_flag"`
  2548. ChldMedcFlag string `json:"chld_medc_flag"`
  2549. ChrgitmLv string `json:"chrgitm_lv"`
  2550. Cnt float64 `json:"cnt"`
  2551. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  2552. DrtReimFlag string `json:"drt_reim_flag"`
  2553. FeedetlSn string `json:"feedetl_sn"`
  2554. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2555. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  2556. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2557. ListSpItemFlag string `json:"list_sp_item_flag"`
  2558. LmtUsedFlag string `json:"lmt_used_flag"`
  2559. MedChrgitmType string `json:"med_chrgitm_type"`
  2560. Memo string `json:"memo"`
  2561. OverlmtAmt float64 `json:"overlmt_amt"`
  2562. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2563. Pric float64 `json:"pric"`
  2564. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  2565. SelfpayProp float64 `json:"selfpay_prop"`
  2566. } `json:"result"`
  2567. } `json:"output"`
  2568. RefmsgTime string `json:"refmsg_time"`
  2569. RespondTime string `json:"respond_time"`
  2570. Signtype string `json:"signtype"`
  2571. WarnMsg string `json:"warn_msg"`
  2572. }
  2573. type ResultFive struct {
  2574. Insutype string `json:"insutype"`
  2575. }
  2576. type ResultSix struct {
  2577. Cainfo interface{} `json:"cainfo"`
  2578. ErrMsg interface{} `json:"err_msg"`
  2579. InfRefmsgid string `json:"inf_refmsgid"`
  2580. Infcode int64 `json:"infcode"`
  2581. Output struct {
  2582. } `json:"output"`
  2583. RefmsgTime string `json:"refmsg_time"`
  2584. RespondTime string `json:"respond_time"`
  2585. Signtype interface{} `json:"signtype"`
  2586. WarnMsg interface{} `json:"warn_msg"`
  2587. }
  2588. type ResultSeven struct {
  2589. Cainfo string `json:"cainfo"`
  2590. ErrMsg string `json:"err_msg"`
  2591. InfRefmsgid string `json:"inf_refmsgid"`
  2592. Infcode int64 `json:"infcode"`
  2593. Output struct {
  2594. Setldetail []interface{} `json:"setldetail"`
  2595. Setlinfo struct {
  2596. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2597. AcctPay float64 `json:"acct_pay"`
  2598. ActPayDedc float64 `json:"act_pay_dedc"`
  2599. Age float64 `json:"age"`
  2600. Balc float64 `json:"balc"`
  2601. Brdy string `json:"brdy"`
  2602. Certno string `json:"certno"`
  2603. ClrOptins string `json:"clr_optins"`
  2604. ClrType string `json:"clr_type"`
  2605. ClrWay string `json:"clr_way"`
  2606. CvlservFlag string `json:"cvlserv_flag"`
  2607. CvlservPay float64 `json:"cvlserv_pay"`
  2608. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2609. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2610. Gend string `json:"gend"`
  2611. HifesPay float64 `json:"hifes_pay"`
  2612. HifmiPay float64 `json:"hifmi_pay"`
  2613. HifobPay float64 `json:"hifob_pay"`
  2614. HifpPay float64 `json:"hifp_pay"`
  2615. HospPartAmt float64 `json:"hosp_part_amt"`
  2616. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2617. Insutype string `json:"insutype"`
  2618. MafPay float64 `json:"maf_pay"`
  2619. MdtrtCertType string `json:"mdtrt_cert_type"`
  2620. MdtrtID string `json:"mdtrt_id"`
  2621. MedType string `json:"med_type"`
  2622. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2623. MedinsSetlID string `json:"medins_setl_id"`
  2624. Naty string `json:"naty"`
  2625. OthPay float64 `json:"oth_pay"`
  2626. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2627. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2628. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2629. PsnCashPay float64 `json:"psn_cash_pay"`
  2630. PsnCertType string `json:"psn_cert_type"`
  2631. PsnName string `json:"psn_name"`
  2632. PsnNo string `json:"psn_no"`
  2633. PsnPartAmt float64 `json:"psn_part_amt"`
  2634. PsnType string `json:"psn_type"`
  2635. SetlID string `json:"setl_id"`
  2636. SetlTime string `json:"setl_time"`
  2637. } `json:"setlinfo"`
  2638. } `json:"output"`
  2639. RefmsgTime string `json:"refmsg_time"`
  2640. RespondTime string `json:"respond_time"`
  2641. Signtype interface{} `json:"signtype"`
  2642. WarnMsg interface{} `json:"warn_msg"`
  2643. }
  2644. type ResultEight struct {
  2645. Cainfo string `json:"cainfo"`
  2646. ErrMsg string `json:"err_msg"`
  2647. InfRefmsgid string `json:"inf_refmsgid"`
  2648. Infcode int64 `json:"infcode"`
  2649. Output struct {
  2650. Stmtinfo struct {
  2651. SetlOptins string `json:"setl_optins"`
  2652. StmtRslt string `json:"stmt_rslt"`
  2653. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  2654. } `json:"stmtinfo"`
  2655. } `json:"output"`
  2656. RefmsgTime string `json:"refmsg_time"`
  2657. RespondTime string `json:"respond_time"`
  2658. Signtype interface{} `json:"signtype"`
  2659. WarnMsg interface{} `json:"warn_msg"`
  2660. }
  2661. type ResultNine struct {
  2662. Cainfo string `json:"cainfo"`
  2663. ErrMsg string `json:"err_msg"`
  2664. InfRefmsgid string `json:"inf_refmsgid"`
  2665. Infcode int64 `json:"infcode"`
  2666. Output struct {
  2667. FileQuryNo string `json:"file_qury_no"`
  2668. } `json:"output"`
  2669. RefmsgTime string `json:"refmsg_time"`
  2670. RespondTime string `json:"respond_time"`
  2671. Signtype interface{} `json:"signtype"`
  2672. WarnMsg interface{} `json:"warn_msg"`
  2673. }
  2674. type ResultTen struct {
  2675. Cainfo string `json:"cainfo"`
  2676. ErrMsg string `json:"err_msg"`
  2677. InfRefmsgid string `json:"inf_refmsgid"`
  2678. Infcode int64 `json:"infcode"`
  2679. Output struct {
  2680. DldEndtime string `json:"dld_endtime"`
  2681. FileQuryNo string `json:"file_qury_no"`
  2682. Filename string `json:"filename"`
  2683. } `json:"output"`
  2684. RefmsgTime string `json:"refmsg_time"`
  2685. RespondTime string `json:"respond_time"`
  2686. Signtype interface{} `json:"signtype"`
  2687. WarnMsg interface{} `json:"warn_msg"`
  2688. }
  2689. type ResultEleven struct {
  2690. Cainfo string `json:"cainfo"`
  2691. ErrMsg string `json:"err_msg"`
  2692. InfRefmsgid string `json:"inf_refmsgid"`
  2693. Infcode int64 `json:"infcode"`
  2694. Output struct {
  2695. Setlinfo struct {
  2696. FixmedinsName string `json:"fixmedins_name"`
  2697. FixmedinsCode string `json:"fixmedins_code"`
  2698. PsnNo string `json:"psn_no"`
  2699. PsnName string `json:"psn_name"`
  2700. HifobPay float64 `json:"hifob_pay"`
  2701. Gend string `json:"gend"`
  2702. Brdy string `json:"brdy"`
  2703. PsnCertType string `json:"psn_cert_type"`
  2704. PsnType string `json:"psn_type"`
  2705. EmpName string `json:"emp_name"`
  2706. Certno string `json:"certno"`
  2707. Insutype string `json:"insutype"`
  2708. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2709. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2710. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2711. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2712. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2713. ActPayDedc float64 `json:"act_pay_dedc"`
  2714. HifpPay float64 `json:"hifp_pay"`
  2715. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2716. CvlservPay float64 `json:"cvlserv_pay"`
  2717. HifesPay float64 `json:"hifes_pay"`
  2718. HifmiPay float64 `json:"hifmi_pay"`
  2719. MafPay float64 `json:"maf_pay"`
  2720. OthPay float64 `json:"oth_pay"`
  2721. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2722. PsnPay float64 `json:"psn_pay"`
  2723. AcctPay float64 `json:"acct_pay"`
  2724. CashPayamt float64 `json:"cash_payamt"`
  2725. Balc float64 `json:"balc"`
  2726. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2727. MedinsSetlId string `json:"medins_setl_id"`
  2728. RefdSetlFlag string `json:"refd_setl_flag"`
  2729. SetlTime string `json:"setl_time"`
  2730. MedType string `json:"med_type"`
  2731. } `json:"setlinfo"`
  2732. } `json:"output"`
  2733. RefmsgTime string `json:"refmsg_time"`
  2734. RespondTime string `json:"respond_time"`
  2735. Signtype interface{} `json:"signtype"`
  2736. WarnMsg interface{} `json:"warn_msg"`
  2737. }
  2738. type Custom struct {
  2739. DetItemFeeSumamt string
  2740. Cut string
  2741. FeedetlSn string
  2742. Price string
  2743. MedListCodg string
  2744. Type int64
  2745. AdviceId int64
  2746. ProjectId int64
  2747. ItemId int64
  2748. }
  2749. //获取个人信息----挂号-----上传就诊信息
  2750. func (c *HisApiController) GetRegisterInfo() {
  2751. id, _ := c.GetInt64("id")
  2752. record_time := c.GetString("record_time")
  2753. settlementValue, _ := c.GetInt64("settlement_value")
  2754. medical_insurance_card := c.GetString("medical_insurance_card")
  2755. name := c.GetString("name")
  2756. id_card_type, _ := c.GetInt64("id_card_type")
  2757. certificates, _ := c.GetInt64("certificates")
  2758. medical_care, _ := c.GetInt64("medical_care")
  2759. birthday := c.GetString("birthday")
  2760. age, _ := c.GetInt64("age")
  2761. id_card := c.GetString("id_card")
  2762. register_type, _ := c.GetInt64("register")
  2763. doctor, _ := c.GetInt64("doctor")
  2764. department, _ := c.GetInt64("department")
  2765. gender, _ := c.GetInt64("sex")
  2766. phone := c.GetString("phone")
  2767. registration_fee, _ := c.GetFloat("registration_fee")
  2768. medical_expenses, _ := c.GetFloat("medical_expenses")
  2769. social_type, _ := c.GetInt64("social_type")
  2770. //diagnosis_id, _ := c.GetInt64("diagnosis")
  2771. diagnosis_ids := c.GetString("diagnosis")
  2772. sick_type, _ := c.GetInt64("sick_type")
  2773. reg_type := c.GetString("p_type")
  2774. timeLayout := "2006-01-02"
  2775. loc, _ := time.LoadLocation("Local")
  2776. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  2777. birthUnix := birthdays.Unix()
  2778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2779. if err != nil {
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. recordDateTime := theTime.Unix()
  2784. adminInfo := c.GetAdminUserInfo()
  2785. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  2786. if tempPatient.ID == 0 {
  2787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  2788. return
  2789. }
  2790. var patient service.Patients
  2791. if id == 0 {
  2792. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  2793. } else {
  2794. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2795. }
  2796. if patient.ID == 0 {
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2798. return
  2799. }
  2800. if len(patient.IdCardNo) == 0 {
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2802. return
  2803. }
  2804. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2805. if len(his) >= 1 {
  2806. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  2807. if len(his) >= 1 && order.ID == 0 {
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  2809. return
  2810. }
  2811. }
  2812. timeStr := time.Now().Format("2006-01-02 15:04:05")
  2813. fmt.Println(timeStr)
  2814. timeArr := strings.Split(timeStr, " ")
  2815. fmt.Println(timeArr)
  2816. timeArrTwo := strings.Split(timeArr[0], "-")
  2817. timeArrThree := strings.Split(timeArr[1], ":")
  2818. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  2819. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2820. if len(lists) == 0 {
  2821. var hisPatient models.XtHisPatient
  2822. hisPatient = models.XtHisPatient{
  2823. Name: name,
  2824. Age: age,
  2825. Gender: gender,
  2826. Birthday: birthUnix,
  2827. Phone: phone,
  2828. MedicalTreatmentType: medical_care,
  2829. IdType: certificates,
  2830. IdCardNo: id_card,
  2831. BalanceAccountsType: settlementValue,
  2832. SocialType: social_type,
  2833. MedicalInsuranceNumber: medical_insurance_card,
  2834. RegisterType: register_type,
  2835. RegisterCost: registration_fee,
  2836. TreatmentCost: medical_expenses,
  2837. AdminUserId: adminInfo.AdminUser.Id,
  2838. UserOrgId: adminInfo.CurrentOrgId,
  2839. Status: 1,
  2840. RecordDate: recordDateTime,
  2841. IsReturn: 1,
  2842. PatientId: patient.ID,
  2843. Ctime: time.Now().Unix(),
  2844. Mtime: time.Now().Unix(),
  2845. Number: str,
  2846. IdCardType: id_card_type,
  2847. Departments: department,
  2848. Doctor: doctor,
  2849. PType: reg_type,
  2850. Diagnosis: diagnosis_ids,
  2851. SickType: sick_type,
  2852. }
  2853. service.CreateHisPatient(&hisPatient)
  2854. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2855. c.ServeSuccessJSON(map[string]interface{}{
  2856. "his_info": hisPatient,
  2857. })
  2858. } else {
  2859. //chrgBchno := rand.Intn(1000000) + 10000
  2860. var hisPatient models.XtHisPatient
  2861. hisPatient = models.XtHisPatient{
  2862. Name: name,
  2863. Age: age,
  2864. Gender: gender,
  2865. Birthday: birthUnix,
  2866. Phone: phone,
  2867. MedicalTreatmentType: medical_care,
  2868. IdType: certificates,
  2869. IdCardNo: id_card,
  2870. BalanceAccountsType: settlementValue,
  2871. SocialType: social_type,
  2872. MedicalInsuranceNumber: medical_insurance_card,
  2873. RegisterType: register_type,
  2874. RegisterCost: registration_fee,
  2875. TreatmentCost: medical_expenses,
  2876. AdminUserId: adminInfo.AdminUser.Id,
  2877. UserOrgId: adminInfo.CurrentOrgId,
  2878. Status: 1,
  2879. RecordDate: recordDateTime,
  2880. IsReturn: 1,
  2881. PatientId: patient.ID,
  2882. Ctime: time.Now().Unix(),
  2883. Mtime: time.Now().Unix(),
  2884. Number: str,
  2885. IdCardType: id_card_type,
  2886. Departments: department,
  2887. Doctor: doctor,
  2888. PType: reg_type,
  2889. Diagnosis: diagnosis_ids,
  2890. SickType: sick_type,
  2891. }
  2892. service.CreateHisPatient(&hisPatient)
  2893. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2894. c.ServeSuccessJSON(map[string]interface{}{
  2895. "his_info": hisPatient,
  2896. })
  2897. }
  2898. }
  2899. //上传明细----结算
  2900. func (c *HisApiController) GetUploadInfo() {
  2901. id, _ := c.GetInt64("id")
  2902. record_time := c.GetString("record_time")
  2903. his_patient_id, _ := c.GetInt64("his_patient_id")
  2904. pay_way, _ := c.GetInt64("pay_way")
  2905. pay_price, _ := c.GetFloat("pay_price")
  2906. pay_card_no := c.GetString("pay_card_no")
  2907. discount_price, _ := c.GetFloat("discount_price")
  2908. preferential_price, _ := c.GetFloat("preferential_price")
  2909. reality_price, _ := c.GetFloat("reality_price")
  2910. found_price, _ := c.GetFloat("found_price")
  2911. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2912. private_price, _ := c.GetFloat("private_price")
  2913. timeLayout := "2006-01-02"
  2914. loc, _ := time.LoadLocation("Local")
  2915. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2916. fapiao_code := c.GetString("fapiao_code")
  2917. fapiao_number := c.GetString("fapiao_number")
  2918. diagnosis_id := c.GetString("diagnosis")
  2919. sick_type, _ := c.GetInt64("sick_type")
  2920. reg_type, _ := c.GetInt64("p_type")
  2921. order_id, _ := c.GetInt64("order_id")
  2922. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  2923. tempOrder, _ := service.GetHisOrderByID(order_id)
  2924. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2925. if err != nil {
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2927. return
  2928. }
  2929. recordDateTime := theTime.Unix()
  2930. adminUser := c.GetAdminUserInfo()
  2931. var prescriptions []*models.HisPrescription
  2932. var start_time int64
  2933. var end_time int64
  2934. ids_str := c.GetString("ids")
  2935. ids_arr := strings.Split(ids_str, ",")
  2936. if tempOrder.ID == 0 {
  2937. if settle_accounts_type == 1 { //日结
  2938. fmt.Println(reg_type)
  2939. if reg_type == 11 {
  2940. fmt.Println(reg_type)
  2941. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2942. } else {
  2943. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  2944. }
  2945. } else { //月结
  2946. start_time_str := c.GetString("start_time")
  2947. end_time_str := c.GetString("end_time")
  2948. timeLayout := "2006-01-02"
  2949. loc, _ := time.LoadLocation("Local")
  2950. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2951. if err != nil {
  2952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2953. return
  2954. }
  2955. recordStartTime := theStartTime.Unix()
  2956. start_time = recordStartTime
  2957. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2958. if err != nil {
  2959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2960. return
  2961. }
  2962. recordEndTime := theEndTime.Unix()
  2963. end_time = recordEndTime
  2964. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  2965. }
  2966. timestamp := time.Now().Unix()
  2967. tempTime := time.Unix(timestamp, 0)
  2968. timeFormat := tempTime.Format("20060102150405")
  2969. chrgBchno := rand.Intn(100000) + 10000
  2970. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2971. strconv.FormatInt(his.PatientId, 10)
  2972. var ids []int64
  2973. fmt.Println(prescriptions)
  2974. for _, item := range prescriptions {
  2975. ids = append(ids, item.ID)
  2976. }
  2977. var total float64
  2978. fmt.Println(prescriptions)
  2979. for _, item := range prescriptions {
  2980. fmt.Println(item)
  2981. if item.Type == 1 { //药品
  2982. for _, subItem := range item.HisDoctorAdviceInfo {
  2983. total = total + (subItem.Price * subItem.PrescribingNumber)
  2984. }
  2985. }
  2986. if item.Type == 2 { //项目
  2987. for _, subItem := range item.HisPrescriptionProject {
  2988. total = total + (subItem.Price * float64(subItem.Count))
  2989. }
  2990. }
  2991. for _, subItem := range item.HisAdditionalCharge {
  2992. total = total + (subItem.Price * float64(subItem.Count))
  2993. }
  2994. }
  2995. allTotal := fmt.Sprintf("%.2f", total)
  2996. totals, _ := strconv.ParseFloat(allTotal, 64)
  2997. order := &models.HisOrder{
  2998. UserOrgId: adminUser.CurrentOrgId,
  2999. HisPatientId: his.ID,
  3000. PatientId: id,
  3001. SettleAccountsDate: recordDateTime,
  3002. Ctime: time.Now().Unix(),
  3003. Mtime: time.Now().Unix(),
  3004. Status: 1,
  3005. OrderStatus: 2,
  3006. MdtrtId: his.Number,
  3007. Number: chrg_bchno,
  3008. MedfeeSumamt: totals,
  3009. PayWay: pay_way,
  3010. PayPrice: pay_price,
  3011. MedType: strconv.Itoa(int(reg_type)),
  3012. PayCardNo: pay_card_no,
  3013. DiscountPrice: discount_price,
  3014. PreferentialPrice: preferential_price,
  3015. RealityPrice: reality_price,
  3016. FoundPrice: found_price,
  3017. MedicalInsurancePrice: medical_insurance_price,
  3018. PrivatePrice: private_price,
  3019. SettleEndTime: end_time,
  3020. SettleStartTime: start_time,
  3021. SettleType: settle_accounts_type,
  3022. FaPiaoCode: fapiao_code,
  3023. FaPiaoNumber: fapiao_number,
  3024. Diagnosis: diagnosis_id,
  3025. PType: 2,
  3026. }
  3027. err = service.CreateOrder(order)
  3028. if err != nil {
  3029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3030. return
  3031. }
  3032. var customs []*Custom
  3033. for _, item := range prescriptions {
  3034. if item.Type == 1 { //药品
  3035. for _, subItem := range item.HisDoctorAdviceInfo {
  3036. cus := &Custom{
  3037. AdviceId: subItem.ID,
  3038. ProjectId: 0,
  3039. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  3040. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  3041. FeedetlSn: subItem.FeedetlSn,
  3042. Price: fmt.Sprintf("%.2f", subItem.Price),
  3043. MedListCodg: subItem.MedListCodg,
  3044. Type: 1,
  3045. }
  3046. customs = append(customs, cus)
  3047. }
  3048. }
  3049. if item.Type == 2 { //项目
  3050. for _, subItem := range item.HisPrescriptionProject {
  3051. cus := &Custom{
  3052. AdviceId: 0,
  3053. ProjectId: subItem.ID,
  3054. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  3055. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  3056. FeedetlSn: subItem.FeedetlSn,
  3057. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  3058. MedListCodg: subItem.MedListCodg,
  3059. Type: 2,
  3060. }
  3061. customs = append(customs, cus)
  3062. }
  3063. }
  3064. for _, item := range item.HisAdditionalCharge {
  3065. cus := &Custom{
  3066. ItemId: item.ID,
  3067. AdviceId: 0,
  3068. ProjectId: 0,
  3069. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  3070. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  3071. FeedetlSn: item.FeedetlSn,
  3072. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  3073. MedListCodg: item.XtHisAddtionConfig.Code,
  3074. Type: 3,
  3075. }
  3076. customs = append(customs, cus)
  3077. }
  3078. }
  3079. for _, item := range customs {
  3080. var advice_id int64 = 0
  3081. var project_id int64 = 0
  3082. var item_id int64 = 0
  3083. var types int64 = 0
  3084. if item.Type == 1 {
  3085. advice_id = item.AdviceId
  3086. project_id = 0
  3087. item_id = 0
  3088. } else if item.Type == 2 {
  3089. advice_id = 0
  3090. item_id = 0
  3091. project_id = item.ProjectId
  3092. } else if item.Type == 3 {
  3093. advice_id = 0
  3094. item_id = item.ItemId
  3095. project_id = 0
  3096. }
  3097. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  3098. cut, _ := strconv.ParseFloat(item.Cut, 32)
  3099. pric, _ := strconv.ParseFloat(item.Price, 32)
  3100. info := &models.HisOrderInfo{
  3101. OrderNumber: order.Number,
  3102. UploadDate: time.Now().Unix(),
  3103. AdviceId: advice_id,
  3104. DetItemFeeSumamt: detItemFeeSumamt,
  3105. Cnt: cut,
  3106. Pric: pric,
  3107. PatientId: id,
  3108. Status: 1,
  3109. Mtime: time.Now().Unix(),
  3110. Ctime: time.Now().Unix(),
  3111. UserOrgId: adminUser.CurrentOrgId,
  3112. HisPatientId: his.ID,
  3113. OrderId: order.ID,
  3114. ProjectId: project_id,
  3115. Type: types,
  3116. ItemId: item_id,
  3117. }
  3118. service.CreateOrderInfo(info)
  3119. }
  3120. his.Diagnosis = diagnosis_id
  3121. his.SickType = sick_type
  3122. his.RegisterType = reg_type
  3123. his.MedicalTreatmentType = reg_type
  3124. service.UpdataHisPateint(&his)
  3125. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3126. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  3127. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3128. if err == nil {
  3129. c.ServeSuccessJSON(map[string]interface{}{
  3130. "msg": "结算成功",
  3131. })
  3132. }
  3133. } else {
  3134. if tempOrder.IsPre > 0 {
  3135. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  3136. totals, _ := strconv.ParseFloat(allTotal, 64)
  3137. tempOrder.OrderStatus = 2
  3138. tempOrder.PayWay = pay_way
  3139. tempOrder.PayPrice = pay_price
  3140. tempOrder.PayCardNo = pay_card_no
  3141. tempOrder.DiscountPrice = discount_price
  3142. tempOrder.PreferentialPrice = preferential_price
  3143. tempOrder.RealityPrice = reality_price
  3144. tempOrder.FoundPrice = found_price
  3145. tempOrder.MedicalInsurancePrice = medical_insurance_price
  3146. tempOrder.PrivatePrice = private_price
  3147. tempOrder.FaPiaoCode = fapiao_code
  3148. tempOrder.FaPiaoNumber = fapiao_number
  3149. tempOrder.PType = 2
  3150. tempOrder.MedfeeSumamt = totals
  3151. tempOrder.Diagnosis = diagnosis_id
  3152. err = service.SaveHisOrder(&tempOrder)
  3153. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  3154. if err != nil {
  3155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3156. return
  3157. }
  3158. if err == nil {
  3159. c.ServeSuccessJSON(map[string]interface{}{
  3160. "msg": "结算成功",
  3161. })
  3162. }
  3163. }
  3164. }
  3165. }
  3166. //退款
  3167. func (c *HisApiController) Refund() {
  3168. order_id, _ := c.GetInt64("order_id")
  3169. order, _ := service.GetHisOrderByID(order_id)
  3170. adminUser := c.GetAdminUserInfo()
  3171. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  3172. if err == nil {
  3173. c.ServeSuccessJSON(map[string]interface{}{
  3174. "msg": "退费成功",
  3175. })
  3176. } else {
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3178. return
  3179. }
  3180. }
  3181. func (c *HisApiController) RefundNumber() {
  3182. his_patient_id, _ := c.GetInt64("id")
  3183. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  3184. info.Status = 0
  3185. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  3186. if count > 0 {
  3187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  3188. return
  3189. }
  3190. err := service.SaveHisPatient(info)
  3191. if err == nil {
  3192. c.ServeSuccessJSON(map[string]interface{}{
  3193. "msg": "退号成功",
  3194. })
  3195. } else {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3197. return
  3198. }
  3199. }
  3200. func (this *HisApiController) AdditionalCharge() {
  3201. dataBody := make(map[string]interface{}, 0)
  3202. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3203. fmt.Println(err)
  3204. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  3205. patient_id := int64(dataBody["patient_id"].(float64))
  3206. medicineData, _ := dataBody["medicineData"].([]interface{})
  3207. adminUserInfo := this.GetAdminUserInfo()
  3208. orgId := adminUserInfo.CurrentOrgId
  3209. admin_user_id := adminUserInfo.AdminUser.Id
  3210. timeStr := time.Now().Format("2006-01-02")
  3211. timeLayout := "2006-01-02 15:04:05"
  3212. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3213. timenow := timeStringToTime.Unix()
  3214. var additionalCharges []*models.HisAdditionalCharge
  3215. for _, item := range medicineData {
  3216. var randNum int
  3217. randNum = rand.Intn(10000) + 1000
  3218. timestamp := time.Now().Unix()
  3219. tempTime := time.Unix(timestamp, 0)
  3220. timeFormat := tempTime.Format("20060102150405")
  3221. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3222. items := item.(map[string]interface{})
  3223. money := items["price"].(string)
  3224. item_id_str := items["item_id"].(string)
  3225. name := items["name"].(string)
  3226. id_str := items["id"].(string)
  3227. moneys, _ := strconv.ParseInt(money, 10, 64)
  3228. monStr := strconv.FormatInt(moneys, 10)
  3229. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  3230. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  3231. id, _ := strconv.ParseInt(id_str, 10, 64)
  3232. additionalCharge := &models.HisAdditionalCharge{
  3233. ID: id,
  3234. HisPatientId: his_patient_id,
  3235. UserOrgId: orgId,
  3236. PatientId: patient_id,
  3237. RecordDate: timenow,
  3238. Price: monneyStr,
  3239. Status: 1,
  3240. ItemName: name,
  3241. ItemId: item_id,
  3242. AdminUserId: admin_user_id,
  3243. CreatedTime: time.Now().Unix(),
  3244. OrderStatus: 0,
  3245. PrescriptionNumber: "",
  3246. BatchNumber: "",
  3247. FeedetlSn: p_number,
  3248. }
  3249. service.CreateAdditionalCharge(additionalCharge)
  3250. additionalCharges = append(additionalCharges, additionalCharge)
  3251. }
  3252. this.ServeSuccessJSON(map[string]interface{}{
  3253. "msg": "添加成功",
  3254. "additional_charges": additionalCharges,
  3255. })
  3256. }
  3257. func (this *HisApiController) DeleteAddition() {
  3258. id, _ := this.GetInt64("id")
  3259. //TODO 需要判断是否已经结算
  3260. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  3261. if err == nil {
  3262. this.ServeSuccessJSON(map[string]interface{}{
  3263. "msg": "删除成功",
  3264. })
  3265. return
  3266. } else {
  3267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3268. return
  3269. }
  3270. }
  3271. func (this *HisApiController) GetAdminUsers() {
  3272. adminUser := this.GetAdminUserInfo()
  3273. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  3274. this.ServeSuccessJSON(map[string]interface{}{
  3275. "doctors": doctors,
  3276. })
  3277. }
  3278. func (this *HisApiController) GetLastOrNextHisPrescription() {
  3279. change_type, _ := this.GetInt64("type", 0)
  3280. record_date := this.GetString("record_time")
  3281. patient_id, _ := this.GetInt64("patient_id", 0)
  3282. p_type, _ := this.GetInt64("p_type", 0)
  3283. timeLayout := "2006-01-02"
  3284. loc, _ := time.LoadLocation("Local")
  3285. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3286. record_time := theAdviceRecordTime.Unix()
  3287. adminUserInfo := this.GetAdminUserInfo()
  3288. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  3289. if err == nil {
  3290. if len(prescriptions) == 0 {
  3291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3292. return
  3293. } else {
  3294. this.ServeSuccessJSON(map[string]interface{}{
  3295. "prescriptions": prescriptions,
  3296. })
  3297. return
  3298. }
  3299. } else {
  3300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3301. return
  3302. }
  3303. }
  3304. func (this *HisApiController) GetCallHisPrescription() {
  3305. patient_id, _ := this.GetInt64("patient_id", 0)
  3306. timeLayout := "2006-01-02"
  3307. loc, _ := time.LoadLocation("Local")
  3308. start_time := this.GetString("start_time")
  3309. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3310. end_time := this.GetString("end_time")
  3311. p_type, _ := this.GetInt64("p_type")
  3312. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3313. adminUserInfo := this.GetAdminUserInfo()
  3314. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  3315. if err == nil {
  3316. this.ServeSuccessJSON(map[string]interface{}{
  3317. "prescriptions": prescriptions,
  3318. })
  3319. return
  3320. } else {
  3321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3322. return
  3323. }
  3324. }
  3325. func (this *HisApiController) GetHisDayPrescription() {
  3326. timeLayout := "2006-01-02"
  3327. loc, _ := time.LoadLocation("Local")
  3328. start_time := this.GetString("start_time")
  3329. patient_id, _ := this.GetInt64("patient_id", 0)
  3330. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3331. end_time := this.GetString("end_time")
  3332. p_type, _ := this.GetInt64("p_type")
  3333. order_status, _ := this.GetInt64("type")
  3334. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3335. adminUserInfo := this.GetAdminUserInfo()
  3336. var dayHisPrescription []*models.HisPrescription
  3337. var err error
  3338. if order_status == 1 || order_status == 0 {
  3339. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  3340. } else if order_status == 2 {
  3341. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  3342. }
  3343. if err == nil {
  3344. this.ServeSuccessJSON(map[string]interface{}{
  3345. "day_prescription": dayHisPrescription,
  3346. })
  3347. return
  3348. } else {
  3349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3350. return
  3351. }
  3352. }
  3353. func (c *HisApiController) GetHisChargePatientList() {
  3354. record_date := c.GetString("record_date")
  3355. order_status, _ := c.GetInt64("type")
  3356. timeLayout := "2006-01-02"
  3357. loc, _ := time.LoadLocation("Local")
  3358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3359. if err != nil {
  3360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3361. return
  3362. }
  3363. recordDateTime := theTime.Unix()
  3364. adminInfo := c.GetAdminUserInfo()
  3365. var tempPatients []*service.NewTempPatients
  3366. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3367. if order_status != 2 {
  3368. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3369. } else {
  3370. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3371. }
  3372. var patients []*service.NewTempPatients
  3373. var patients_two []*service.NewTempPatients
  3374. for _, item := range tempPatients {
  3375. //过滤掉没挂号的和没开处方的
  3376. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  3377. patients = append(patients, item)
  3378. }
  3379. //过滤掉没挂号的
  3380. if len(item.HisPatient) > 0 {
  3381. patients_two = append(patients_two, item)
  3382. }
  3383. }
  3384. c.ServeSuccessJSON(map[string]interface{}{
  3385. "list": patients,
  3386. "list_two": patients_two,
  3387. })
  3388. }
  3389. func (c *HisApiController) GetHisUnRegisterPatientList() {
  3390. record_date := c.GetString("record_date")
  3391. timeLayout := "2006-01-02"
  3392. loc, _ := time.LoadLocation("Local")
  3393. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3394. if err != nil {
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. return
  3397. }
  3398. recordDateTime := theTime.Unix()
  3399. adminUser := c.GetAdminUserInfo()
  3400. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  3401. var patients []*service.Patients
  3402. for _, item := range tempPatients {
  3403. if item.HisPatient.ID == 0 {
  3404. patients = append(patients, item)
  3405. }
  3406. }
  3407. c.ServeSuccessJSON(map[string]interface{}{
  3408. "list": patients,
  3409. //"list_two": patients_two,
  3410. })
  3411. }
  3412. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  3413. newArr = make([]*service.Patients, 0)
  3414. for i := 0; i < len(patient); i++ {
  3415. repeat := false
  3416. for j := i + 1; j < len(patient); j++ {
  3417. if patient[i].ID == patient[j].ID {
  3418. repeat = true
  3419. break
  3420. }
  3421. }
  3422. if !repeat {
  3423. newArr = append(newArr, patient[i])
  3424. }
  3425. }
  3426. return
  3427. }
  3428. func (c *HisApiController) GetHisChargePatientInfo() {
  3429. patient_id, _ := c.GetInt64("patient_id")
  3430. his_patient_id, _ := c.GetInt64("his_patient_id")
  3431. record_date := c.GetString("record_date")
  3432. //start_time := c.GetString("start_time")
  3433. //end_time := c.GetString("end_time")
  3434. order_status, _ := c.GetInt64("type", 0)
  3435. p_type, _ := c.GetInt64("p_type", 0)
  3436. order_id, _ := c.GetInt64("order_id", 0)
  3437. timeLayout := "2006-01-02"
  3438. loc, _ := time.LoadLocation("Local")
  3439. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3440. if err != nil {
  3441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3442. return
  3443. }
  3444. recordDateTime := theTime.Unix()
  3445. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3446. //if err != nil {
  3447. //
  3448. //}
  3449. //startRecordDateTime := startTime.Unix()
  3450. //
  3451. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3452. //if err != nil {
  3453. //
  3454. //}
  3455. //endRecordDateTime := endTime.Unix()
  3456. admin := c.GetAdminUserInfo()
  3457. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  3458. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  3459. var prescriptions []*models.HisPrescription
  3460. order, _ := service.GetHisOrderByID(order_id)
  3461. if order_status == 1 || order_status == 0 {
  3462. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  3463. } else if order_status == 2 {
  3464. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  3465. }
  3466. //var monthPrescriptions []*models.HisPrescription
  3467. //if order_status == 1 || order_status == 0 {
  3468. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  3469. //} else if order_status == 2 {
  3470. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  3471. //}
  3472. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  3473. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  3474. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  3475. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  3476. //获取所有科室信息
  3477. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  3478. c.ServeSuccessJSON(map[string]interface{}{
  3479. "his_info": his_patient_info,
  3480. "xt_info": xt_patient_info,
  3481. "prescription": prescriptions,
  3482. "case_history": case_history,
  3483. "info": patientPrescriptionInfo,
  3484. "last_info": lastPatientPrescriptionInfo,
  3485. //"month_prescriptions": monthPrescriptions,
  3486. "order": order,
  3487. "doctors": doctors,
  3488. "department": department,
  3489. })
  3490. return
  3491. }
  3492. func (c *HisApiController) GetAllOrderDetail() {
  3493. order_id, _ := c.GetInt64("id", 0)
  3494. order, _ := service.GetHisOrderByID(order_id)
  3495. if order.ID == 0 {
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3497. return
  3498. }
  3499. org_id := c.GetAdminUserInfo().CurrentOrgId
  3500. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  3501. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  3502. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  3503. c.ServeSuccessJSON(map[string]interface{}{
  3504. "order": order,
  3505. "order_info": order_info,
  3506. "patient": patient,
  3507. "admin_info": adminInfo,
  3508. })
  3509. return
  3510. }
  3511. func (c *HisApiController) GetAllOrderDetailCollect() {
  3512. order_id, _ := c.GetInt64("id", 0)
  3513. order, _ := service.GetHisOrderByID(order_id)
  3514. if order.ID == 0 {
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3516. return
  3517. }
  3518. org_id := c.GetAdminUserInfo().CurrentOrgId
  3519. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  3520. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  3521. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  3522. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  3523. if his.BalanceAccountsType != 2 {
  3524. c.ServeSuccessJSON(map[string]interface{}{
  3525. "order": order,
  3526. "order_info": order_info,
  3527. "patient": patient,
  3528. "admin_info": adminInfo,
  3529. })
  3530. } else {
  3531. for _, item := range order_info {
  3532. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  3533. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  3534. item.MedChrgitmType = "09"
  3535. }
  3536. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  3537. if item.HisPrescriptionProject.Type == 2 {
  3538. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  3539. case 1:
  3540. item.MedChrgitmType = "14"
  3541. break
  3542. case 2:
  3543. item.MedChrgitmType = "05"
  3544. break
  3545. case 3:
  3546. item.MedChrgitmType = "04"
  3547. break
  3548. case 4:
  3549. item.MedChrgitmType = "14"
  3550. break
  3551. case 5:
  3552. item.MedChrgitmType = "08"
  3553. break
  3554. case 6:
  3555. item.MedChrgitmType = "14"
  3556. break
  3557. case 7:
  3558. item.MedChrgitmType = "14"
  3559. break
  3560. case 8:
  3561. item.MedChrgitmType = "03"
  3562. break
  3563. case 9:
  3564. item.MedChrgitmType = "14"
  3565. break
  3566. }
  3567. } else if item.HisPrescriptionProject.Type == 3 {
  3568. item.MedChrgitmType = "08"
  3569. }
  3570. }
  3571. }
  3572. c.ServeSuccessJSON(map[string]interface{}{
  3573. "order": order,
  3574. "order_info": order_info,
  3575. "patient": patient,
  3576. "admin_info": adminInfo,
  3577. })
  3578. }
  3579. return
  3580. }
  3581. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  3582. page, _ := c.GetInt64("page")
  3583. limit, _ := c.GetInt64("limit")
  3584. keywords := c.GetString("keywords")
  3585. start_time := c.GetString("start_time")
  3586. end_time := c.GetString("end_time")
  3587. //clr_type := c.GetString("clr_type")
  3588. insutype := c.GetString("insutype")
  3589. timeLayout := "2006-01-02"
  3590. loc, _ := time.LoadLocation("Local")
  3591. var theStartTIme int64
  3592. if len(start_time) > 0 {
  3593. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3594. theStartTIme = theTime.Unix()
  3595. }
  3596. var theEndtTIme int64
  3597. if len(end_time) > 0 {
  3598. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3599. theEndtTIme = theTime.Unix()
  3600. }
  3601. if page <= 0 {
  3602. page = 1
  3603. }
  3604. if limit <= 0 {
  3605. limit = 10
  3606. }
  3607. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  3608. c.ServeSuccessJSON(map[string]interface{}{
  3609. "total": total,
  3610. "list": list,
  3611. })
  3612. return
  3613. }
  3614. func (c *HisApiController) GetPutOnRecordList() {
  3615. page, _ := c.GetInt64("page")
  3616. limit, _ := c.GetInt64("limit")
  3617. keywords := c.GetString("keywords")
  3618. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  3619. if page <= 0 {
  3620. page = 1
  3621. }
  3622. if limit <= 0 {
  3623. limit = 10
  3624. }
  3625. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  3626. c.ServeSuccessJSON(map[string]interface{}{
  3627. "total": total,
  3628. "list": list,
  3629. })
  3630. return
  3631. }
  3632. func (c *HisApiController) GetCompareData() {
  3633. start_time := c.GetString("start_time")
  3634. end_time := c.GetString("end_time")
  3635. insutype := c.GetString("insutype")
  3636. timeLayout := "2006-01-02"
  3637. loc, _ := time.LoadLocation("Local")
  3638. var theStartTIme int64
  3639. if len(start_time) > 0 {
  3640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3641. if err != nil {
  3642. theStartTIme = 0
  3643. }
  3644. theStartTIme = theTime.Unix()
  3645. }
  3646. var theEndtTIme int64
  3647. if len(end_time) > 0 {
  3648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3649. if err != nil {
  3650. theEndtTIme = 0
  3651. }
  3652. theEndtTIme = theTime.Unix()
  3653. }
  3654. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  3655. fmt.Println(err)
  3656. if err == nil {
  3657. c.ServeSuccessJSON(map[string]interface{}{
  3658. "list": formData,
  3659. })
  3660. } else {
  3661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3662. return
  3663. }
  3664. }
  3665. func (c *HisApiController) GetFaPiaoData() {
  3666. order_id, _ := c.GetInt64("order_id")
  3667. patient_id, _ := c.GetInt64("patient_id")
  3668. number := c.GetString("number")
  3669. adminUser := c.GetAdminUserInfo()
  3670. order, _ := service.GetHisOrderByID(order_id)
  3671. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3672. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3673. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3674. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  3675. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  3676. var bedCostTotal float64 = 0 //床位总费
  3677. var bedCostSelfTotal float64 = 0 //床位自费
  3678. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3679. var operationCostTotal float64 = 0 //手术费
  3680. var operationCostSelfTotal float64 = 0 //手术费
  3681. var operationCostPartSelfTotal float64 = 0 //手术费
  3682. var otherCostTotal float64 = 0 //其他费用
  3683. var otherCostSelfTotal float64 = 0 //其他费用
  3684. var otherCostPartSelfTotal float64 = 0 //其他费用
  3685. var materialCostTotal float64 = 0 //材料费
  3686. var materialCostSelfTotal float64 = 0 //材料费
  3687. var materialCostPartSelfTotal float64 = 0 //材料费
  3688. var westernMedicineCostTotal float64 = 0 //西药费
  3689. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3690. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3691. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3692. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3693. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3694. var checkCostTotal float64 = 0 //检查费
  3695. var checkCostSelfTotal float64 = 0 //检查费
  3696. var checkCostPartSelfTotal float64 = 0 //检查费
  3697. var laboratoryCostTotal float64 = 0 //化验费
  3698. var laboratoryCostSelfTotal float64 = 0 //化验费
  3699. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3700. var treatCostTotal float64 = 0 //治疗费用
  3701. var treatCostSelfTotal float64 = 0 //治疗费用
  3702. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3703. decimal.DivisionPrecision = 2
  3704. if his.BalanceAccountsType == 2 {
  3705. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  3706. for _, item := range orderInfos_two {
  3707. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  3708. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  3709. item.MedChrgitmType = "09"
  3710. }
  3711. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  3712. if item.HisPrescriptionProject.Type == 2 {
  3713. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  3714. case 1:
  3715. item.MedChrgitmType = "14"
  3716. break
  3717. case 2:
  3718. item.MedChrgitmType = "05"
  3719. break
  3720. case 3:
  3721. item.MedChrgitmType = "04"
  3722. break
  3723. case 4:
  3724. item.MedChrgitmType = "14"
  3725. break
  3726. case 5:
  3727. item.MedChrgitmType = "08"
  3728. break
  3729. case 6:
  3730. item.MedChrgitmType = "14"
  3731. break
  3732. case 7:
  3733. item.MedChrgitmType = "14"
  3734. break
  3735. case 8:
  3736. item.MedChrgitmType = "03"
  3737. break
  3738. case 9:
  3739. item.MedChrgitmType = "14"
  3740. break
  3741. }
  3742. } else if item.HisPrescriptionProject.Type == 3 {
  3743. item.MedChrgitmType = "08"
  3744. }
  3745. }
  3746. }
  3747. for _, item := range orderInfos_two {
  3748. if item.MedChrgitmType == "01" { //床位费
  3749. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3750. bedCostSelfTotal = bedCostTotal
  3751. }
  3752. if item.MedChrgitmType == "03" { //检查费
  3753. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3754. checkCostSelfTotal = checkCostTotal
  3755. }
  3756. if item.MedChrgitmType == "04" { //化验费
  3757. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3758. laboratoryCostSelfTotal = laboratoryCostTotal
  3759. }
  3760. if item.MedChrgitmType == "05" { //治疗费
  3761. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3762. treatCostSelfTotal = treatCostTotal
  3763. }
  3764. if item.MedChrgitmType == "06" { //手术费
  3765. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3766. operationCostSelfTotal = treatCostTotal
  3767. }
  3768. if item.MedChrgitmType == "08" { //材料费
  3769. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3770. materialCostSelfTotal = materialCostTotal
  3771. }
  3772. if item.MedChrgitmType == "09" { //西药费
  3773. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3774. westernMedicineCostSelfTotal = westernMedicineCostTotal
  3775. }
  3776. if item.MedChrgitmType == "11" { //中成费
  3777. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3778. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  3779. }
  3780. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  3781. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3782. otherCostSelfTotal = otherCostTotal
  3783. }
  3784. }
  3785. } else {
  3786. for _, item := range orderInfos {
  3787. if item.MedChrgitmType == "01" { //床位费
  3788. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3789. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3790. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3791. }
  3792. if item.MedChrgitmType == "03" { //检查费
  3793. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3794. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3795. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3796. }
  3797. if item.MedChrgitmType == "04" { //化验费
  3798. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3799. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3800. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3801. }
  3802. if item.MedChrgitmType == "05" { //治疗费
  3803. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3804. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3805. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3806. }
  3807. if item.MedChrgitmType == "06" { //手术费
  3808. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3809. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3810. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3811. }
  3812. if item.MedChrgitmType == "08" { //材料费
  3813. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3814. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3815. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3816. }
  3817. if item.MedChrgitmType == "09" { //西药费
  3818. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3819. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3820. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3821. }
  3822. if item.MedChrgitmType == "11" { //中成费
  3823. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3824. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3825. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3826. }
  3827. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  3828. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3829. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3830. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3831. }
  3832. }
  3833. }
  3834. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3835. c.ServeSuccessJSON(map[string]interface{}{
  3836. "order_number": order.Number, //业务流水号
  3837. "id_card_no": his.IdCardNo, //社会保障号
  3838. "department_name": department.Name, //科室
  3839. "number": his.Number, //门诊号
  3840. "date": order.SettleEndTime, //结算日期
  3841. "name": order.PsnName, //姓名
  3842. "gender": order.Gend, //性别
  3843. "psn_cash_money": order.PsnCashPay, //个人支付
  3844. "pay_way": "门诊", //结算方式
  3845. "medfee_sumamt": order.MedfeeSumamt, //总费用
  3846. "admin_user_name": admin.UserName, //收款员
  3847. "bedCostTotal": bedCostTotal,
  3848. "bedCostSelfTotal": bedCostSelfTotal,
  3849. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3850. "operationCostTotal": operationCostTotal,
  3851. "operationCostSelfTotal": operationCostSelfTotal,
  3852. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3853. "otherCostTotal": otherCostTotal,
  3854. "otherCostSelfTotal": otherCostSelfTotal,
  3855. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3856. "materialCostTotal": materialCostTotal,
  3857. "materialCostSelfTotal": materialCostSelfTotal,
  3858. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3859. "westernMedicineCostTotal": westernMedicineCostTotal,
  3860. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3861. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3862. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3863. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3864. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3865. "checkCostTotal": checkCostTotal,
  3866. "checkCostSelfTotal": checkCostSelfTotal,
  3867. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3868. "laboratoryCostTotal": laboratoryCostTotal,
  3869. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3870. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3871. "treatCostTotal": treatCostTotal,
  3872. "treatCostSelfTotal": treatCostSelfTotal,
  3873. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3874. })
  3875. }
  3876. func (this *HisApiController) GetIncomeStatisticsData() {
  3877. start_time := this.GetString("start_time")
  3878. end_time := this.GetString("end_time")
  3879. key_words := this.GetString("key_words")
  3880. limit, _ := this.GetInt64("limit")
  3881. page, _ := this.GetInt64("page")
  3882. if page <= 0 {
  3883. page = 1
  3884. }
  3885. if limit <= 0 {
  3886. limit = 10
  3887. }
  3888. statistics_type, _ := this.GetInt64("statistics_type")
  3889. admin := this.GetAdminUserInfo()
  3890. timeLayout := "2006-01-02"
  3891. loc, _ := time.LoadLocation("Local")
  3892. var theStartTIme int64
  3893. if len(start_time) > 0 {
  3894. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3895. if err != nil {
  3896. theStartTIme = 0
  3897. }
  3898. theStartTIme = theTime.Unix()
  3899. }
  3900. var theEndtTIme int64
  3901. if len(end_time) > 0 {
  3902. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3903. if err != nil {
  3904. theEndtTIme = 0
  3905. }
  3906. theEndtTIme = theTime.Unix()
  3907. }
  3908. if statistics_type == 1 {
  3909. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3910. this.ServeSuccessJSON(map[string]interface{}{
  3911. "list": list,
  3912. "total": total,
  3913. })
  3914. } else {
  3915. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3916. this.ServeSuccessJSON(map[string]interface{}{
  3917. "list": list,
  3918. "total": total,
  3919. })
  3920. }
  3921. }
  3922. func (c *HisApiController) PostProjectInformation() {
  3923. adminUser := c.GetAdminUserInfo()
  3924. orgId := adminUser.CurrentOrgId
  3925. dataBody := make(map[string]interface{}, 0)
  3926. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3927. if err != nil {
  3928. utils.ErrorLog(err.Error())
  3929. return
  3930. }
  3931. utils.ErrorLog("%v", dataBody)
  3932. var projectList []*models.HisProject
  3933. var total_goods []interface{}
  3934. tempProjects := dataBody["projects"].([]interface{})
  3935. total_goods = tempProjects
  3936. for index, projectMap := range tempProjects {
  3937. projectM := projectMap.(map[string]interface{})
  3938. var project models.HisProject
  3939. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  3940. utils.ErrorLog("project_name")
  3941. return
  3942. }
  3943. project_name, _ := projectM["project_name"].(string)
  3944. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  3945. err_log := models.ExportErrLog{
  3946. LogType: 6,
  3947. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3948. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  3949. Status: 1,
  3950. CreateTime: time.Now().Unix(),
  3951. UpdateTime: time.Now().Unix(),
  3952. ExportTime: time.Now().Unix(),
  3953. }
  3954. service.CreateExportErrLog(&err_log)
  3955. continue
  3956. }
  3957. project.ProjectName = project_name
  3958. prices := projectM["price"].(string)
  3959. price, _ := strconv.ParseFloat(prices, 64)
  3960. if price <= 0 { //名字为空则生成一条导入错误日志
  3961. err_log := models.ExportErrLog{
  3962. LogType: 6,
  3963. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3964. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  3965. Status: 1,
  3966. CreateTime: time.Now().Unix(),
  3967. UpdateTime: time.Now().Unix(),
  3968. ExportTime: time.Now().Unix(),
  3969. }
  3970. service.CreateExportErrLog(&err_log)
  3971. continue
  3972. }
  3973. project.Price = price
  3974. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  3975. utils.ErrorLog("unit_id")
  3976. return
  3977. }
  3978. unit := projectM["unit"].(string)
  3979. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  3980. err_log := models.ExportErrLog{
  3981. LogType: 6,
  3982. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3983. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  3984. Status: 1,
  3985. CreateTime: time.Now().Unix(),
  3986. UpdateTime: time.Now().Unix(),
  3987. ExportTime: time.Now().Unix(),
  3988. }
  3989. service.CreateExportErrLog(&err_log)
  3990. continue
  3991. }
  3992. project.Unit = unit
  3993. cost_classify := projectM["cost_classify"].(string)
  3994. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  3995. err_log := models.ExportErrLog{
  3996. LogType: 6,
  3997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3998. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3999. Status: 1,
  4000. CreateTime: time.Now().Unix(),
  4001. UpdateTime: time.Now().Unix(),
  4002. ExportTime: time.Now().Unix(),
  4003. }
  4004. service.CreateExportErrLog(&err_log)
  4005. continue
  4006. }
  4007. var costClassify = "费用类别"
  4008. var cost_classify_id int64
  4009. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  4010. if len(cost_classify) != 0 {
  4011. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  4012. if errcode == gorm.ErrRecordNotFound {
  4013. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  4014. dataconfig := models.DictDataconfig{
  4015. ParentId: costClassifyConfig.ID,
  4016. Module: "system",
  4017. OrgId: orgId,
  4018. Name: cost_classify,
  4019. FieldName: "",
  4020. Value: costConfig.Value + 1,
  4021. CreatedTime: "",
  4022. UpdatedTime: "",
  4023. CreateUserId: adminUser.AdminUser.Id,
  4024. Status: 1,
  4025. Remark: "",
  4026. DeleteIdSystem: 0,
  4027. Title: "",
  4028. Content: "",
  4029. Order: 0,
  4030. Code: "",
  4031. }
  4032. service.CreatedDicConfig(&dataconfig)
  4033. }
  4034. }
  4035. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  4036. for _, it := range costClassList {
  4037. if cost_classify == it.Name {
  4038. cost_classify_id = int64(it.Value)
  4039. }
  4040. }
  4041. project.CostClassify = cost_classify_id
  4042. executive_section := projectM["executive_section"].(string)
  4043. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  4044. err_log := models.ExportErrLog{
  4045. LogType: 6,
  4046. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4047. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  4048. Status: 1,
  4049. CreateTime: time.Now().Unix(),
  4050. UpdateTime: time.Now().Unix(),
  4051. ExportTime: time.Now().Unix(),
  4052. }
  4053. service.CreateExportErrLog(&err_log)
  4054. continue
  4055. }
  4056. if len(executive_section) != 0 {
  4057. //查找科室是否有内容
  4058. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  4059. if errcodedepart == gorm.ErrRecordNotFound {
  4060. department := models.XtHisDepartment{
  4061. Name: executive_section,
  4062. Status: 1,
  4063. UserOrgId: adminUser.CurrentOrgId,
  4064. CreatedTime: time.Now().Unix(),
  4065. }
  4066. service.CreateDePartment(&department)
  4067. }
  4068. }
  4069. var executive_section_id int64
  4070. departMentList, _ := service.GetAllDepartMent(orgId)
  4071. for _, it := range departMentList {
  4072. if executive_section == it.Name {
  4073. executive_section_id = it.ID
  4074. }
  4075. }
  4076. project.ExecutiveSection = executive_section_id
  4077. medical_coverage := projectM["medical_coverage"].(string)
  4078. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  4079. err_log := models.ExportErrLog{
  4080. LogType: 6,
  4081. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4082. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  4083. Status: 1,
  4084. CreateTime: time.Now().Unix(),
  4085. UpdateTime: time.Now().Unix(),
  4086. ExportTime: time.Now().Unix(),
  4087. }
  4088. service.CreateExportErrLog(&err_log)
  4089. continue
  4090. }
  4091. var medicalCoverage = "医保等级"
  4092. var medical_coverage_id int64
  4093. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  4094. if len(medical_coverage) != 0 {
  4095. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  4096. if errormedicalcoverage == gorm.ErrRecordNotFound {
  4097. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  4098. dataconfig := models.DictDataconfig{
  4099. ParentId: medicalCoverageConfig.ID,
  4100. Module: "system",
  4101. OrgId: orgId,
  4102. Name: medical_coverage,
  4103. FieldName: "",
  4104. Value: medicalCoverageConfig.Value + 1,
  4105. CreatedTime: "",
  4106. UpdatedTime: "",
  4107. CreateUserId: adminUser.AdminUser.Id,
  4108. Status: 1,
  4109. Remark: "",
  4110. DeleteIdSystem: 0,
  4111. Title: "",
  4112. Content: "",
  4113. Order: 0,
  4114. Code: "",
  4115. }
  4116. service.CreatedDicConfig(&dataconfig)
  4117. }
  4118. }
  4119. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  4120. for _, it := range medicalCoverageList {
  4121. if medical_coverage == it.Name {
  4122. medical_coverage_id = int64(it.Value)
  4123. }
  4124. }
  4125. project.MedicalCoverage = medical_coverage_id
  4126. pinyin := projectM["pinyin"].(string)
  4127. project.Pinyin = pinyin
  4128. wubi := projectM["wubi"].(string)
  4129. project.Wubi = wubi
  4130. statistical_classification := projectM["statistical_classification"].(string)
  4131. var statisticalClassification = "统计分类"
  4132. var statistical_classification_id int64
  4133. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  4134. if len(statistical_classification) != 0 {
  4135. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  4136. if classificationerrcodes == gorm.ErrRecordNotFound {
  4137. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  4138. dataconfig := models.DictDataconfig{
  4139. ParentId: classiFication.ID,
  4140. Module: "system",
  4141. OrgId: orgId,
  4142. Name: statistical_classification,
  4143. FieldName: "",
  4144. Value: classiFicationConfig.Value + 1,
  4145. CreatedTime: "",
  4146. UpdatedTime: "",
  4147. CreateUserId: adminUser.AdminUser.Id,
  4148. Status: 1,
  4149. Remark: "",
  4150. DeleteIdSystem: 0,
  4151. Title: "",
  4152. Content: "",
  4153. Order: 0,
  4154. Code: "",
  4155. }
  4156. service.CreatedDicConfig(&dataconfig)
  4157. }
  4158. }
  4159. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  4160. for _, it := range classiFicationList {
  4161. if statistical_classification == it.Name {
  4162. statistical_classification_id = int64(it.Value)
  4163. }
  4164. }
  4165. project.StatisticalClassification = statistical_classification_id
  4166. disease_directory := int64(projectM["disease_directory"].(float64))
  4167. project.DiseaseDirectory = disease_directory
  4168. is_record := int64(projectM["is_record"].(float64))
  4169. project.IsRecord = is_record
  4170. medical_code := projectM["medical_code"].(string)
  4171. project.MedicalCode = medical_code
  4172. tube_color := projectM["tube_color"].(string)
  4173. var tubeColor = "试管颜色"
  4174. var tube_color_id int64
  4175. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  4176. if len(tube_color) != 0 {
  4177. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  4178. if errcodetube == gorm.ErrRecordNotFound {
  4179. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  4180. dataconfig := models.DictDataconfig{
  4181. ParentId: tubeColorConfig.ID,
  4182. Module: "system",
  4183. OrgId: orgId,
  4184. Name: tube_color,
  4185. FieldName: "",
  4186. Value: tubeConfig.Value + 1,
  4187. CreatedTime: "",
  4188. UpdatedTime: "",
  4189. CreateUserId: adminUser.AdminUser.Id,
  4190. Status: 1,
  4191. Remark: "",
  4192. DeleteIdSystem: 0,
  4193. Title: "",
  4194. Content: "",
  4195. Order: 0,
  4196. Code: "",
  4197. }
  4198. service.CreatedDicConfig(&dataconfig)
  4199. }
  4200. }
  4201. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  4202. for _, it := range tubeColorList {
  4203. if tube_color == it.Name {
  4204. tube_color_id = int64(it.Value)
  4205. }
  4206. }
  4207. project.TubeColor = tube_color_id
  4208. single_dose := projectM["single_dose"].(string)
  4209. project.SingleDose = single_dose
  4210. execution_frequency := projectM["execution_frequency"].(string)
  4211. project.ExecutionFrequency = execution_frequency
  4212. delivery_way := projectM["delivery_way"].(string)
  4213. project.DeliveryWay = delivery_way
  4214. number_days := projectM["number_days"].(string)
  4215. project.NumberDays = number_days
  4216. total := projectM["total"].(string)
  4217. project.Total = total
  4218. medical_status := int64(projectM["medical_status"].(float64))
  4219. project.MedicalStatus = medical_status
  4220. category := int64(projectM["category"].(float64))
  4221. project.Category = category
  4222. specail_project := int64(projectM["specail_project"].(float64))
  4223. project.SpecailProject = specail_project
  4224. social_security_directory_code := projectM["social_security_directory_code"].(string)
  4225. project.SocialSecurityDirectoryCode = social_security_directory_code
  4226. remark := projectM["remark"].(string)
  4227. project.Remark = remark
  4228. record_date := projectM["record_date"].(string)
  4229. timeLayout := "2006-01-02"
  4230. loc, _ := time.LoadLocation("Local")
  4231. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4232. project.RecordDate = theTime.Unix()
  4233. projectList = append(projectList, &project)
  4234. }
  4235. export_time := time.Now().Unix()
  4236. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4237. if len(projectList) > 0 {
  4238. for _, item := range projectList {
  4239. project := models.HisProject{
  4240. ProjectName: item.ProjectName,
  4241. Price: item.Price,
  4242. Unit: item.Unit,
  4243. CostClassify: item.CostClassify,
  4244. ExecutiveSection: item.ExecutiveSection,
  4245. MedicalCoverage: item.MedicalCoverage,
  4246. UserOrgId: orgId,
  4247. Status: 1,
  4248. CreatedTime: time.Now().Unix(),
  4249. Pinyin: item.Pinyin,
  4250. Wubi: item.Wubi,
  4251. StatisticalClassification: item.StatisticalClassification,
  4252. DiseaseDirectory: item.DiseaseDirectory,
  4253. IsRecord: item.IsRecord,
  4254. MedicalCode: item.MedicalCode,
  4255. TubeColor: item.TubeColor,
  4256. SingleDose: item.SingleDose,
  4257. DeliveryWay: item.DeliveryWay,
  4258. NumberDays: item.NumberDays,
  4259. Total: item.Total,
  4260. Category: item.Category,
  4261. MedicalStatus: item.MedicalStatus,
  4262. SpecailProject: item.SpecailProject,
  4263. RecordDate: item.RecordDate,
  4264. Remark: item.Remark,
  4265. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4266. ExecutionFrequency: item.ExecutionFrequency,
  4267. }
  4268. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  4269. if errcodeproject == gorm.ErrRecordNotFound {
  4270. service.CreateProjectInfomation(&project)
  4271. } else if errcodeproject == nil {
  4272. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  4273. }
  4274. log := models.ExportLog{
  4275. LogType: 6,
  4276. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4277. TotalNum: int64(len(total_goods)),
  4278. FailNum: int64(len(errLogs)),
  4279. SuccessNum: int64(len(projectList)),
  4280. CreateTime: time.Now().Unix(),
  4281. UpdateTime: time.Now().Unix(),
  4282. ExportTime: export_time,
  4283. Status: 1,
  4284. }
  4285. service.CreateExportLog(&log)
  4286. c.ServeSuccessJSON(map[string]interface{}{
  4287. "msg": "导入成功",
  4288. "total_num": len(total_goods),
  4289. "success_num": len(projectList),
  4290. "fail_num": int64(len(errLogs)),
  4291. })
  4292. }
  4293. } else {
  4294. log := models.ExportLog{
  4295. LogType: 6,
  4296. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4297. TotalNum: int64(len(total_goods)),
  4298. FailNum: int64(len(errLogs)),
  4299. SuccessNum: int64(len(projectList)),
  4300. CreateTime: time.Now().Unix(),
  4301. UpdateTime: time.Now().Unix(),
  4302. ExportTime: export_time,
  4303. Status: 1,
  4304. }
  4305. service.CreateExportLog(&log)
  4306. c.ServeSuccessJSON(map[string]interface{}{
  4307. "msg": "导入成功",
  4308. "total_num": len(total_goods),
  4309. "success_num": len(projectList),
  4310. "fail_num": int64(len(errLogs)),
  4311. })
  4312. }
  4313. }
  4314. //func (this *HisApiController) EditProjectInformation(){
  4315. //
  4316. // id, _ := this.GetInt64("id")
  4317. // project_team := this.GetString("project_team")
  4318. // price := this.GetString("price")
  4319. // price_float, _ := strconv.ParseFloat(price, 64)
  4320. // pinyin := this.GetString("pinyin")
  4321. // wubi := this.GetString("wubi")
  4322. // tube_color, _ := this.GetInt64("tube_color")
  4323. // team_type, _ := this.GetInt64("team_type")
  4324. // remark := this.GetString("remark")
  4325. // ids := this.GetString("ids")
  4326. // item_id := this.GetString("item_id")
  4327. // projectTeam := models.XtHisProjectTeam{
  4328. // ProjectTeam: project_team,
  4329. // Price: price_float,
  4330. // Pinyin: pinyin,
  4331. // Wubi: wubi,
  4332. // TubeColor: tube_color,
  4333. // TeamType: team_type,
  4334. // Remark: remark,
  4335. // ProjectId: ids,
  4336. // ItemId: item_id,
  4337. // }
  4338. //
  4339. //
  4340. // dataBody := make(map[string]interface{}, 0)
  4341. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4342. // if err != nil {
  4343. // utils.ErrorLog(err.Error())
  4344. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4345. // return
  4346. // }
  4347. //
  4348. // err = service.UpdatedProjectTeam(id, &projectTeam)
  4349. //
  4350. //
  4351. // if err != nil {
  4352. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4353. // return
  4354. // }
  4355. //
  4356. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  4357. // infos, _ := dataBody["info"].([]interface{})
  4358. // if len(infos) > 0 {
  4359. // var ids []string
  4360. //
  4361. // for _, item := range infos {
  4362. // items := item.(map[string]interface{})
  4363. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4364. // utils.ErrorLog("id")
  4365. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4366. // return
  4367. // }
  4368. // id := int64(items["id"].(float64))
  4369. //
  4370. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4371. // utils.ErrorLog("type")
  4372. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4373. // return
  4374. // }
  4375. // types := int64(items["type"].(float64))
  4376. //
  4377. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4378. // utils.ErrorLog("number")
  4379. // }
  4380. //
  4381. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  4382. //
  4383. // projectList := models.XtHisProjectList{
  4384. // Number: number,
  4385. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4386. // ProjectId: id,
  4387. // Status: 1,
  4388. // CreatedTime: time.Now().Unix(),
  4389. // UpdatedTime: time.Now().Unix(),
  4390. // TeamId: projectTeam.ID,
  4391. // Type: types,
  4392. // }
  4393. // list := projectList
  4394. //
  4395. // service.CreateProjectList(&list)
  4396. //
  4397. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  4398. //
  4399. // }
  4400. // ids_str := strings.Join(ids, ",")
  4401. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  4402. // service.SaveProjectTeam(&projectTeam)
  4403. // this.ServeSuccessJSON(map[string]interface{}{
  4404. // "projectTeam": projectTeam,
  4405. // })
  4406. // }
  4407. // }
  4408. //}
  4409. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  4410. name := c.GetString("name")
  4411. mode_id, _ := c.GetInt64("mode", 0)
  4412. types, _ := c.GetInt64("type", 0)
  4413. patient_id, _ := c.GetInt64("patient_id", 0)
  4414. types = 1
  4415. adminInfo := c.GetAdminUserInfo()
  4416. template := &models.HisPrescriptionTemplate{
  4417. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4418. PatientId: patient_id,
  4419. Type: types,
  4420. Status: 1,
  4421. Ctime: time.Now().Unix(),
  4422. Mtime: time.Now().Unix(),
  4423. Name: name,
  4424. Mode: mode_id,
  4425. }
  4426. dataBody := make(map[string]interface{}, 0)
  4427. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4428. if err != nil {
  4429. utils.ErrorLog(err.Error())
  4430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4431. return
  4432. }
  4433. err = service.CreateHisPrescriptionTemplate(template)
  4434. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4435. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4436. if len(prescriptions) > 0 {
  4437. for _, item := range prescriptions {
  4438. items := item.(map[string]interface{})
  4439. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4440. utils.ErrorLog("type")
  4441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4442. return
  4443. }
  4444. types := int64(items["type"].(float64))
  4445. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4446. utils.ErrorLog("med_type")
  4447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4448. return
  4449. }
  4450. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4451. ctime := time.Now().Unix()
  4452. prescription := &models.HisPrescriptionInfoTemplate{
  4453. PatientId: patient_id,
  4454. UserOrgId: adminInfo.CurrentOrgId,
  4455. Ctime: ctime,
  4456. Mtime: ctime,
  4457. Type: types,
  4458. Modifier: adminInfo.AdminUser.Id,
  4459. Creator: adminInfo.AdminUser.Id,
  4460. Status: 1,
  4461. PTemplateId: template.ID,
  4462. MedType: med_type,
  4463. }
  4464. service.CreateHisPrescriptionInfoTemplate(prescription)
  4465. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4466. advices := items["advices"].([]interface{})
  4467. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4468. ctime := time.Now().Unix()
  4469. mtime := ctime
  4470. if len(advices) > 0 {
  4471. for _, advice := range advices {
  4472. var s models.HisPrescriptionAdviceTemplate
  4473. s.PrescriptionId = prescription.ID
  4474. s.AdviceType = 2
  4475. s.StopState = 2
  4476. s.ExecutionState = 2
  4477. s.Status = 1
  4478. s.UserOrgId = adminInfo.CurrentOrgId
  4479. s.CreatedTime = ctime
  4480. s.UpdatedTime = mtime
  4481. s.PatientId = patient_id
  4482. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  4483. if errcode > 0 {
  4484. c.ServeFailJSONWithSGJErrorCode(errcode)
  4485. return
  4486. }
  4487. service.CreateHisPrescriptionAdviceTemplate(&s)
  4488. }
  4489. }
  4490. }
  4491. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4492. projects := items["project"].([]interface{})
  4493. if len(projects) > 0 {
  4494. for _, project := range projects {
  4495. var p models.HisPrescriptionProjectTemplate
  4496. p.PrescriptionId = prescription.ID
  4497. p.Ctime = time.Now().Unix()
  4498. p.Mtime = time.Now().Unix()
  4499. p.PatientId = patient_id
  4500. p.UserOrgId = adminInfo.CurrentOrgId
  4501. p.Status = 1
  4502. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  4503. if errcode > 0 {
  4504. c.ServeFailJSONWithSGJErrorCode(errcode)
  4505. return
  4506. }
  4507. service.CreateHisPrescriptionProjectTemplate(&p)
  4508. }
  4509. }
  4510. }
  4511. }
  4512. c.ServeSuccessJSON(map[string]interface{}{
  4513. "msg": "创建成功",
  4514. })
  4515. }
  4516. }
  4517. }
  4518. func (c *HisApiController) PreSettle() {
  4519. id, _ := c.GetInt64("id")
  4520. record_time := c.GetString("record_time")
  4521. his_patient_id, _ := c.GetInt64("his_patient_id")
  4522. timeLayout := "2006-01-02"
  4523. loc, _ := time.LoadLocation("Local")
  4524. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4525. diagnosis_id := c.GetString("diagnosis")
  4526. sick_type, _ := c.GetInt64("sick_type")
  4527. reg_type, _ := c.GetInt64("p_type")
  4528. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4529. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4530. if err != nil {
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4532. return
  4533. }
  4534. recordDateTime := theTime.Unix()
  4535. adminUser := c.GetAdminUserInfo()
  4536. var prescriptions []*models.HisPrescription
  4537. var start_time int64
  4538. var end_time int64
  4539. ids_str := c.GetString("ids")
  4540. ids_arr := strings.Split(ids_str, ",")
  4541. fmt.Println(reg_type)
  4542. if settle_accounts_type == 1 { //日结
  4543. if reg_type == 11 {
  4544. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4545. } else {
  4546. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4547. }
  4548. fmt.Println(prescriptions)
  4549. } else { //月结
  4550. start_time_str := c.GetString("start_time")
  4551. end_time_str := c.GetString("end_time")
  4552. timeLayout := "2006-01-02"
  4553. loc, _ := time.LoadLocation("Local")
  4554. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4555. if err != nil {
  4556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4557. return
  4558. }
  4559. recordStartTime := theStartTime.Unix()
  4560. start_time = recordStartTime
  4561. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4562. if err != nil {
  4563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4564. return
  4565. }
  4566. recordEndTime := theEndTime.Unix()
  4567. end_time = recordEndTime
  4568. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4569. }
  4570. if reg_type == 1111 || reg_type == 1112 {
  4571. reg_type = 11
  4572. }
  4573. timestamp := time.Now().Unix()
  4574. tempTime := time.Unix(timestamp, 0)
  4575. timeFormat := tempTime.Format("20060102150405")
  4576. chrgBchno := rand.Intn(100000) + 10000
  4577. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4578. strconv.FormatInt(his.PatientId, 10)
  4579. var ids []int64
  4580. for _, item := range prescriptions {
  4581. ids = append(ids, item.ID)
  4582. }
  4583. fmt.Println(ids)
  4584. var total float64
  4585. for _, item := range prescriptions {
  4586. fmt.Println(item)
  4587. if item.Type == 1 { //药品
  4588. for _, subItem := range item.HisDoctorAdviceInfo {
  4589. total = total + (subItem.Price * subItem.PrescribingNumber)
  4590. }
  4591. }
  4592. if item.Type == 2 { //项目
  4593. for _, subItem := range item.HisPrescriptionProject {
  4594. total = total + (subItem.Price * float64(subItem.Count))
  4595. }
  4596. }
  4597. for _, subItem := range item.HisAdditionalCharge {
  4598. total = total + (subItem.Price * float64(subItem.Count))
  4599. }
  4600. }
  4601. allTotal := fmt.Sprintf("%.2f", total)
  4602. totals, _ := strconv.ParseFloat(allTotal, 64)
  4603. order := &models.HisOrder{
  4604. UserOrgId: adminUser.CurrentOrgId,
  4605. HisPatientId: his.ID,
  4606. PatientId: id,
  4607. SettleAccountsDate: recordDateTime,
  4608. Ctime: time.Now().Unix(),
  4609. Mtime: time.Now().Unix(),
  4610. Status: 1,
  4611. OrderStatus: 1,
  4612. MdtrtId: his.Number,
  4613. Number: chrg_bchno,
  4614. MedfeeSumamt: totals,
  4615. SettleEndTime: end_time,
  4616. SettleStartTime: start_time,
  4617. SettleType: settle_accounts_type,
  4618. PType: 2,
  4619. IsPre: 1,
  4620. MedType: strconv.Itoa(int(reg_type)),
  4621. Diagnosis: diagnosis_id,
  4622. }
  4623. err = service.CreateOrder(order)
  4624. if err != nil {
  4625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4626. return
  4627. }
  4628. var customs []*Custom
  4629. for _, item := range prescriptions {
  4630. fmt.Println(item.Type)
  4631. if item.Type == 1 { //药品
  4632. for _, subItem := range item.HisDoctorAdviceInfo {
  4633. cus := &Custom{
  4634. AdviceId: subItem.ID,
  4635. ProjectId: 0,
  4636. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  4637. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  4638. FeedetlSn: subItem.FeedetlSn,
  4639. Price: fmt.Sprintf("%.2f", subItem.Price),
  4640. MedListCodg: subItem.MedListCodg,
  4641. Type: 1,
  4642. }
  4643. customs = append(customs, cus)
  4644. }
  4645. }
  4646. if item.Type == 2 { //项目
  4647. for _, subItem := range item.HisPrescriptionProject {
  4648. cus := &Custom{
  4649. AdviceId: 0,
  4650. ProjectId: subItem.ID,
  4651. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  4652. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  4653. FeedetlSn: subItem.FeedetlSn,
  4654. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  4655. MedListCodg: subItem.MedListCodg,
  4656. Type: 2,
  4657. }
  4658. customs = append(customs, cus)
  4659. }
  4660. }
  4661. for _, item := range item.HisAdditionalCharge {
  4662. cus := &Custom{
  4663. ItemId: item.ID,
  4664. AdviceId: 0,
  4665. ProjectId: 0,
  4666. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  4667. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  4668. FeedetlSn: item.FeedetlSn,
  4669. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  4670. MedListCodg: item.XtHisAddtionConfig.Code,
  4671. Type: 3,
  4672. }
  4673. customs = append(customs, cus)
  4674. }
  4675. }
  4676. fmt.Println(customs)
  4677. for _, item := range customs {
  4678. var advice_id int64 = 0
  4679. var project_id int64 = 0
  4680. var item_id int64 = 0
  4681. var types int64 = 0
  4682. if item.Type == 1 {
  4683. advice_id = item.AdviceId
  4684. project_id = 0
  4685. item_id = 0
  4686. } else if item.Type == 2 {
  4687. advice_id = 0
  4688. item_id = 0
  4689. project_id = item.ProjectId
  4690. } else if item.Type == 3 {
  4691. advice_id = 0
  4692. item_id = item.ItemId
  4693. project_id = 0
  4694. }
  4695. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4696. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4697. pric, _ := strconv.ParseFloat(item.Price, 32)
  4698. info := &models.HisOrderInfo{
  4699. OrderNumber: order.Number,
  4700. UploadDate: time.Now().Unix(),
  4701. AdviceId: advice_id,
  4702. DetItemFeeSumamt: detItemFeeSumamt,
  4703. Cnt: cut,
  4704. Pric: pric,
  4705. PatientId: id,
  4706. Status: 1,
  4707. Mtime: time.Now().Unix(),
  4708. Ctime: time.Now().Unix(),
  4709. UserOrgId: adminUser.CurrentOrgId,
  4710. HisPatientId: his.ID,
  4711. OrderId: order.ID,
  4712. ProjectId: project_id,
  4713. Type: types,
  4714. ItemId: item_id,
  4715. }
  4716. service.CreateOrderInfo(info)
  4717. }
  4718. his.SickType = sick_type
  4719. service.UpdataHisPateint(&his)
  4720. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4721. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4722. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4723. if err == nil {
  4724. c.ServeSuccessJSON(map[string]interface{}{
  4725. "msg": "结算成功",
  4726. })
  4727. }
  4728. }
  4729. func (c *HisApiController) GetPrivateExpensesInfo() {
  4730. order_id, _ := c.GetInt64("id", 0)
  4731. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  4732. order, _ := service.GetHisOrderByID(order_id)
  4733. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  4734. if order.ID == 0 {
  4735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4736. return
  4737. }
  4738. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4739. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4740. org_id := c.GetAdminUserInfo().CurrentOrgId
  4741. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4742. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4743. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4744. c.ServeSuccessJSON(map[string]interface{}{
  4745. "order": order,
  4746. "order_info": order_info,
  4747. "patient": patient,
  4748. "admin_info": adminInfo,
  4749. "his": his,
  4750. "current_admin": role,
  4751. "org_config": miConfig,
  4752. })
  4753. }
  4754. func (this *HisApiController) ChangeMedType() {
  4755. med_type := this.GetString("med_type")
  4756. id, _ := this.GetInt64("id")
  4757. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  4758. prescription.MedType = med_type
  4759. err := service.SaveHisPrescription(&prescription)
  4760. if err == nil {
  4761. this.ServeSuccessJSON(map[string]interface{}{
  4762. "msg": "修改成功",
  4763. })
  4764. } else {
  4765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4766. return
  4767. }
  4768. }
  4769. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  4770. patient_id, _ := c.GetInt64("patient_id")
  4771. his_patient_id, _ := c.GetInt64("his_patient_id")
  4772. record_date := c.GetString("record_date")
  4773. start_time := c.GetString("start_time")
  4774. end_time := c.GetString("end_time")
  4775. order_status, _ := c.GetInt64("type", 0)
  4776. p_type, _ := c.GetInt64("p_type", 0)
  4777. order_id, _ := c.GetInt64("order_id", 0)
  4778. timeLayout := "2006-01-02"
  4779. loc, _ := time.LoadLocation("Local")
  4780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4781. if err != nil {
  4782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4783. return
  4784. }
  4785. recordDateTime := theTime.Unix()
  4786. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4787. if err != nil {
  4788. }
  4789. startRecordDateTime := startTime.Unix()
  4790. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4791. if err != nil {
  4792. }
  4793. endRecordDateTime := endTime.Unix()
  4794. admin := c.GetAdminUserInfo()
  4795. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4796. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4797. order, _ := service.GetHisOrderByID(order_id)
  4798. var monthPrescriptions []*models.HisPrescription
  4799. if order_status == 1 || order_status == 0 {
  4800. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4801. } else if order_status == 2 {
  4802. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4803. }
  4804. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4805. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4806. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4807. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4808. //获取所有科室信息
  4809. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4810. c.ServeSuccessJSON(map[string]interface{}{
  4811. "his_info": his_patient_info,
  4812. "xt_info": xt_patient_info,
  4813. "case_history": case_history,
  4814. "info": patientPrescriptionInfo,
  4815. "last_info": lastPatientPrescriptionInfo,
  4816. "month_prescriptions": monthPrescriptions,
  4817. "order": order,
  4818. "doctors": doctors,
  4819. "department": department,
  4820. })
  4821. return
  4822. }
  4823. func (c *HisApiController) GetHisMonthPatientInfo() {
  4824. patient_id, _ := c.GetInt64("patient_id")
  4825. his_patient_id, _ := c.GetInt64("his_patient_id")
  4826. record_date := c.GetString("record_date")
  4827. number := c.GetString("number")
  4828. start_time := c.GetString("start_time")
  4829. end_time := c.GetString("end_time")
  4830. p_type, _ := c.GetInt64("p_type")
  4831. timeLayout := "2006-01-02"
  4832. loc, _ := time.LoadLocation("Local")
  4833. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4834. if err != nil {
  4835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4836. return
  4837. }
  4838. recordDateTime := theTime.Unix()
  4839. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4840. if err != nil {
  4841. }
  4842. startRecordDateTime := startTime.Unix()
  4843. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4844. if err != nil {
  4845. }
  4846. endRecordDateTime := endTime.Unix()
  4847. admin := c.GetAdminUserInfo()
  4848. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  4849. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4850. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  4851. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4852. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4853. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4854. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4855. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  4856. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4857. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  4858. //获取所有科室信息
  4859. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4860. c.ServeSuccessJSON(map[string]interface{}{
  4861. "his_info": his_patient_info,
  4862. "xt_info": xt_patient_info,
  4863. "case_history": case_history,
  4864. "info": patientPrescriptionInfo,
  4865. "month_prescriptions": monthPrescriptions,
  4866. "order": order,
  4867. "doctors": doctors,
  4868. "department": department,
  4869. "count": count,
  4870. "drugStockConfig": drugStockConfig,
  4871. "last_info": lastPatientPrescriptionInfo,
  4872. })
  4873. return
  4874. }
  4875. func (c *HisApiController) GetAllOrder() {
  4876. org_id := c.GetAdminUserInfo().CurrentOrgId
  4877. orders, _ := service.GetNewHisOrderList(org_id)
  4878. c.ServeSuccessJSON(map[string]interface{}{
  4879. "order": orders,
  4880. })
  4881. return
  4882. }