his_api_controller.go 179KB

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