his_api_controller.go 142KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072
  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/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. }
  70. func (c *HisApiController) Sscard() {
  71. //r := CardInit()
  72. //if r == 0 {
  73. // GetBaseInfo()
  74. //}
  75. //c.ServeSuccessJSON(map[string]interface{}{
  76. // "list": "11",
  77. //})
  78. }
  79. func GetBaseInfo() error {
  80. //handle := syscall.MustLoadDLL("SSCard.dll")
  81. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  82. //
  83. //str := make([]byte, 256)
  84. //str1 := make([]byte, 256)
  85. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  86. //if ferr != nil {
  87. // fmt.Println("ReadCardBas 报错", ferr.Error())
  88. // return ferr
  89. //}
  90. //
  91. //fmt.Println(string(str))
  92. //
  93. //fmt.Println(r)
  94. return nil
  95. }
  96. func CardInit() int {
  97. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  98. //add := DllTestDef.MustFindProc("Init")
  99. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  100. //if err != nil {
  101. // fmt.Println("SSCard的运算结果为:", ret)
  102. //}
  103. //result := int(ret)
  104. return 0
  105. }
  106. func IntPtr(n int) uintptr {
  107. return uintptr(n)
  108. }
  109. func StrPtr(s string) uintptr {
  110. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  111. }
  112. func (c *HisApiController) GetHisPatientList() {
  113. //types, _ := c.GetInt64("type", 0)
  114. record_date := c.GetString("record_date")
  115. sch_type, _ := c.GetInt64("sch_type")
  116. timeLayout := "2006-01-02"
  117. loc, _ := time.LoadLocation("Local")
  118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  119. if err != nil {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. return
  122. }
  123. recordDateTime := theTime.Unix()
  124. adminInfo := c.GetAdminUserInfo()
  125. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  126. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  127. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  128. //获取当前用户的信息
  129. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  130. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  131. //获取所有科室信息
  132. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "list": patients,
  135. "list_two": patients_two,
  136. "info": adminUserInfo,
  137. "doctors": doctors,
  138. "department": department,
  139. })
  140. }
  141. func (c *HisApiController) GetHisPatientInfo() {
  142. patient_id, _ := c.GetInt64("patient_id")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. record_date := c.GetString("record_date")
  145. number := c.GetString("number")
  146. start_time := c.GetString("start_time")
  147. end_time := c.GetString("end_time")
  148. p_type, _ := c.GetInt64("p_type")
  149. timeLayout := "2006-01-02"
  150. loc, _ := time.LoadLocation("Local")
  151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  152. if err != nil {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. recordDateTime := theTime.Unix()
  157. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  158. if err != nil {
  159. }
  160. startRecordDateTime := startTime.Unix()
  161. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  162. if err != nil {
  163. }
  164. endRecordDateTime := endTime.Unix()
  165. admin := c.GetAdminUserInfo()
  166. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  167. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  168. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  169. var prescriptions []*models.HisPrescription
  170. var last_prescriptions []*models.HisPrescription
  171. var sch_prescriptions []*models.HisPrescriptionInfoTemplate
  172. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  173. if p_type == 1 { //住院
  174. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  175. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  176. } else { //门诊
  177. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  178. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  179. }
  180. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  181. if sch.ID > 0 {
  182. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  183. sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  184. }
  185. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  186. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  187. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  188. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  189. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  190. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  191. //获取所有科室信息
  192. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  193. c.ServeSuccessJSON(map[string]interface{}{
  194. "his_info": his_patient_info,
  195. "xt_info": xt_patient_info,
  196. "prescription": prescriptions,
  197. "case_history": case_history,
  198. "info": patientPrescriptionInfo,
  199. "month_prescriptions": monthPrescriptions,
  200. "order": order,
  201. "doctors": doctors,
  202. "department": department,
  203. "sch_prescriptions": sch_prescriptions,
  204. "last_prescriptions": last_prescriptions,
  205. "schedule": sch,
  206. "count": count,
  207. })
  208. return
  209. }
  210. func (c *HisApiController) GetHisPrescriptionConfig() {
  211. adminInfo := c.GetAdminUserInfo()
  212. //获取医嘱模版
  213. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  214. //获取所有基础药
  215. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  216. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  217. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  218. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  219. //获取所有科室信息
  220. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  221. //获取诊断信息
  222. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  223. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  224. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  225. c.ServeSuccessJSON(map[string]interface{}{
  226. "drugs": drugs,
  227. "advices_template": advices,
  228. "drugways": drugways,
  229. "efs": efs,
  230. "doctors": doctors,
  231. "department": department,
  232. "sick": sick,
  233. "additions": additions,
  234. "diagnose": diagnose,
  235. })
  236. }
  237. func (c *HisApiController) CreateHisPrescription() {
  238. record_date := c.GetString("record_date")
  239. patient_id, _ := c.GetInt64("patient_id")
  240. reg_type, _ := c.GetInt64("reg_type")
  241. diagnose, _ := c.GetInt64("diagnose")
  242. sick_type, _ := c.GetInt64("sick_type")
  243. sick_history := c.GetString("sick_history")
  244. doctor_id, _ := c.GetInt64("doctor", 0)
  245. department, _ := c.GetInt64("department", 0)
  246. his_patient_id, _ := c.GetInt64("his_patient_id")
  247. p_type, _ := c.GetInt64("p_type")
  248. dataBody := make(map[string]interface{}, 0)
  249. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  250. if err != nil {
  251. utils.ErrorLog(err.Error())
  252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. return
  254. }
  255. timeLayout := "2006-01-02"
  256. loc, _ := time.LoadLocation("Local")
  257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  258. if err != nil {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  260. return
  261. }
  262. adminInfo := c.GetAdminUserInfo()
  263. recordDateTime := theTime.Unix()
  264. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  265. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  266. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  267. if len(lists) == 1 {
  268. his_patient_id = lists[0].ID
  269. }
  270. }
  271. //校验库存总量
  272. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  273. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  274. if len(prescriptions) > 0 {
  275. for _, item := range prescriptions {
  276. items := item.(map[string]interface{})
  277. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  278. advices := items["advices"].([]interface{})
  279. if len(advices) > 0 {
  280. for _, advice := range advices {
  281. var drug_id int64
  282. var prescribing_number float64
  283. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  284. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  285. }
  286. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "float64" {
  287. prescribing_number = advice.(map[string]interface{})["prescribing_number"].(float64)
  288. }
  289. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
  290. if drug.ID == 0 {
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  292. return
  293. }
  294. if prescribing_number > drug.Total {
  295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  296. return
  297. }
  298. }
  299. }
  300. }
  301. }
  302. }
  303. }
  304. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  305. var hpInfo models.HisPrescriptionInfo
  306. if info.ID == 0 {
  307. var randNum int
  308. randNum = rand.Intn(10000) + 1000
  309. timestamp := time.Now().Unix()
  310. tempTime := time.Unix(timestamp, 0)
  311. timeFormat := tempTime.Format("20060102150405")
  312. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  313. hpInfo = models.HisPrescriptionInfo{
  314. HisPatientId: his_patient_id,
  315. UserOrgId: adminInfo.CurrentOrgId,
  316. RecordDate: theTime.Unix(),
  317. PatientId: patient_id,
  318. Status: 1,
  319. Ctime: time.Now().Unix(),
  320. Mtime: time.Now().Unix(),
  321. Creator: adminInfo.AdminUser.Id,
  322. Modifier: adminInfo.AdminUser.Id,
  323. Diagnosis: diagnose,
  324. SickHistory: sick_history,
  325. Departments: department,
  326. RegisterType: reg_type,
  327. PrescriptionNumber: p_number,
  328. PrescriptionStatus: 1,
  329. Doctor: role.UserName,
  330. DoctorId: doctor_id,
  331. SickType: sick_type,
  332. PType: p_type,
  333. }
  334. service.SavePatientPrescriptionInfo(hpInfo)
  335. } else {
  336. hpInfo = models.HisPrescriptionInfo{
  337. ID: info.ID,
  338. UserOrgId: adminInfo.CurrentOrgId,
  339. RecordDate: info.RecordDate,
  340. PatientId: info.PatientId,
  341. Status: 1,
  342. Ctime: info.Ctime,
  343. Mtime: time.Now().Unix(),
  344. Creator: info.Creator,
  345. Modifier: adminInfo.AdminUser.Id,
  346. Diagnosis: diagnose,
  347. SickHistory: sick_history,
  348. Departments: department,
  349. RegisterType: reg_type,
  350. PrescriptionNumber: info.PrescriptionNumber,
  351. Doctor: role.UserName,
  352. PrescriptionStatus: info.PrescriptionStatus,
  353. DoctorId: doctor_id,
  354. SickType: sick_type,
  355. PType: info.PType,
  356. HisPatientId: info.HisPatientId,
  357. }
  358. service.SavePatientPrescriptionInfo(hpInfo)
  359. }
  360. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  361. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  362. var tempPrescription *models.HisPrescription
  363. if len(prescriptions) > 0 {
  364. for _, item := range prescriptions {
  365. items := item.(map[string]interface{})
  366. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  367. utils.ErrorLog("id")
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. id := int64(items["id"].(float64))
  372. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  373. tempPrescription = &new_prescription
  374. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  375. utils.ErrorLog("type")
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. types := int64(items["type"].(float64))
  380. if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
  381. utils.ErrorLog("order_status")
  382. }
  383. order_status := int64(items["order_status"].(float64))
  384. if order_status == 0 {
  385. order_status = 1
  386. }
  387. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  388. utils.ErrorLog("pre_time")
  389. }
  390. preTime, _ := items["pre_time"].(string)
  391. timeLayout := "2006-01-02"
  392. loc, _ := time.LoadLocation("Local")
  393. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  394. if err != nil {
  395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  396. return
  397. }
  398. pTime := theTime2.Unix()
  399. ctime := time.Now().Unix()
  400. if tempPrescription.ID == 0 {
  401. prescription := &models.HisPrescription{
  402. ID: id,
  403. PatientId: patient_id,
  404. UserOrgId: adminInfo.CurrentOrgId,
  405. RecordDate: recordDateTime,
  406. Ctime: ctime,
  407. Mtime: ctime,
  408. Type: types,
  409. Modifier: adminInfo.AdminUser.Id,
  410. Creator: adminInfo.AdminUser.Id,
  411. Status: 1,
  412. Doctor: role.UserName,
  413. HisPatientId: his_patient_id,
  414. OrderStatus: order_status,
  415. BatchNumber: "",
  416. PrescriptionNumber: hpInfo.PrescriptionNumber,
  417. PreTime: pTime,
  418. PType: p_type,
  419. }
  420. tempPrescription = prescription
  421. service.SaveHisPrescription(tempPrescription)
  422. } else {
  423. tempPrescription.Type = types
  424. tempPrescription.Modifier = adminInfo.AdminUser.Id
  425. tempPrescription.Mtime = time.Now().Unix()
  426. tempPrescription.Doctor = role.UserName
  427. tempPrescription.OrderStatus = order_status
  428. tempPrescription.PreTime = pTime
  429. service.SaveHisPrescription(tempPrescription)
  430. }
  431. //service.SaveHisPrescription(prescription)
  432. //更改患者挂号状态
  433. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  434. fmt.Println("更改失败", err2)
  435. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  436. advices := items["advices"].([]interface{})
  437. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  438. groupNo := int64(0)
  439. ctime := time.Now().Unix()
  440. mtime := ctime
  441. if len(advices) > 0 {
  442. for _, advice := range advices {
  443. var s models.HisDoctorAdviceInfo
  444. s.PrescriptionId = tempPrescription.ID
  445. s.AdviceType = 2
  446. s.AdviceDoctor = doctor_id
  447. s.StopState = 2
  448. s.ExecutionState = 2
  449. s.AdviceDate = recordDateTime
  450. s.Status = 1
  451. s.UserOrgId = adminInfo.CurrentOrgId
  452. s.RecordDate = recordDateTime
  453. s.StartTime = tempPrescription.PreTime
  454. s.Groupno = groupNo
  455. s.CreatedTime = ctime
  456. s.UpdatedTime = mtime
  457. s.PatientId = patient_id
  458. s.HisPatientId = his_patient_id
  459. s.StartTime = pTime
  460. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  461. if errcode > 0 {
  462. c.ServeFailJSONWithSGJErrorCode(errcode)
  463. return
  464. }
  465. s.StartTime = pTime
  466. service.CreateHisDoctorAdvice(&s)
  467. var randNum int
  468. randNum = rand.Intn(10000) + 1000
  469. timestamp := time.Now().Unix()
  470. tempTime := time.Unix(timestamp, 0)
  471. timeFormat := tempTime.Format("20060102150405")
  472. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  473. service.CreateHisDoctorAdvice(&s)
  474. }
  475. }
  476. }
  477. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  478. projects := items["project"].([]interface{})
  479. if len(projects) > 0 {
  480. for _, project := range projects {
  481. var p models.HisPrescriptionProject
  482. p.PrescriptionId = tempPrescription.ID
  483. p.Ctime = time.Now().Unix()
  484. p.Mtime = time.Now().Unix()
  485. p.PatientId = patient_id
  486. p.RecordDate = recordDateTime
  487. p.Doctor = doctor_id
  488. p.UserOrgId = adminInfo.CurrentOrgId
  489. p.HisPatientId = his_patient_id
  490. p.Status = 1
  491. p.StartTime = pTime
  492. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  493. if errcode > 0 {
  494. c.ServeFailJSONWithSGJErrorCode(errcode)
  495. return
  496. }
  497. service.CreateHisProjectTwo(&p)
  498. var randNum int
  499. randNum = rand.Intn(10000) + 1000
  500. timestamp := time.Now().Unix()
  501. tempTime := time.Unix(timestamp, 0)
  502. timeFormat := tempTime.Format("20060102150405")
  503. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  504. service.SaveHisProjectTwo(&p)
  505. if p.Type == 3 { //处理透前准备耗材数量数据
  506. consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  507. if consumables.ID > 0 {
  508. consumables.Count = p.Count
  509. service.UpdateConsumables(&consumables)
  510. }
  511. }
  512. }
  513. }
  514. }
  515. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  516. addition := items["addition"].([]interface{})
  517. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  518. ctime := time.Now().Unix()
  519. mtime := ctime
  520. if len(addition) > 0 {
  521. for _, item := range addition {
  522. var s models.HisAdditionalCharge
  523. s.PrescriptionId = tempPrescription.ID
  524. s.Status = 1
  525. s.UserOrgId = adminInfo.CurrentOrgId
  526. s.RecordDate = recordDateTime
  527. s.CreatedTime = ctime
  528. s.UpdatedTime = mtime
  529. s.PatientId = patient_id
  530. s.HisPatientId = his_patient_id
  531. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  532. if errcode > 0 {
  533. c.ServeFailJSONWithSGJErrorCode(errcode)
  534. return
  535. }
  536. service.CreateAdditionalCharge(&s)
  537. var randNum int
  538. randNum = rand.Intn(10000) + 1000
  539. timestamp := time.Now().Unix()
  540. tempTime := time.Unix(timestamp, 0)
  541. timeFormat := tempTime.Format("20060102150405")
  542. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  543. service.CreateAdditionalCharge(&s)
  544. }
  545. }
  546. }
  547. }
  548. }
  549. }
  550. if err == nil {
  551. c.ServeSuccessJSON(map[string]interface{}{
  552. "msg": "保存成功",
  553. })
  554. return
  555. } else {
  556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  557. return
  558. }
  559. }
  560. func (c *HisApiController) EditHisPrescription() {
  561. record_date := c.GetString("record_date")
  562. patient_id, _ := c.GetInt64("patient_id")
  563. reg_type, _ := c.GetInt64("reg_type")
  564. diagnose, _ := c.GetInt64("diagnose")
  565. sick_type, _ := c.GetInt64("sick_type")
  566. sick_history := c.GetString("sick_history")
  567. doctor_id, _ := c.GetInt64("doctor", 0)
  568. department, _ := c.GetInt64("department", 0)
  569. his_patient_id, _ := c.GetInt64("his_patient_id")
  570. p_type, _ := c.GetInt64("p_type")
  571. dataBody := make(map[string]interface{}, 0)
  572. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  573. if err != nil {
  574. utils.ErrorLog(err.Error())
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  576. return
  577. }
  578. timeLayout := "2006-01-02"
  579. loc, _ := time.LoadLocation("Local")
  580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  581. if err != nil {
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. adminInfo := c.GetAdminUserInfo()
  586. recordDateTime := theTime.Unix()
  587. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  588. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
  589. var hpInfo models.HisPrescriptionInfo
  590. if info.ID == 0 {
  591. var randNum int
  592. randNum = rand.Intn(10000) + 1000
  593. timestamp := time.Now().Unix()
  594. tempTime := time.Unix(timestamp, 0)
  595. timeFormat := tempTime.Format("20060102150405")
  596. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  597. hpInfo = models.HisPrescriptionInfo{
  598. UserOrgId: adminInfo.CurrentOrgId,
  599. RecordDate: theTime.Unix(),
  600. PatientId: patient_id,
  601. Status: 1,
  602. Ctime: time.Now().Unix(),
  603. Mtime: time.Now().Unix(),
  604. Creator: adminInfo.AdminUser.Id,
  605. Modifier: adminInfo.AdminUser.Id,
  606. Diagnosis: diagnose,
  607. SickHistory: sick_history,
  608. Departments: department,
  609. RegisterType: reg_type,
  610. PrescriptionNumber: p_number,
  611. PrescriptionStatus: 1,
  612. Doctor: role.UserName,
  613. DoctorId: doctor_id,
  614. SickType: sick_type,
  615. PType: p_type,
  616. }
  617. service.SavePatientPrescriptionInfo(hpInfo)
  618. } else {
  619. hpInfo = models.HisPrescriptionInfo{
  620. ID: info.ID,
  621. UserOrgId: adminInfo.CurrentOrgId,
  622. RecordDate: info.RecordDate,
  623. PatientId: info.PatientId,
  624. Status: 1,
  625. Ctime: info.Ctime,
  626. Mtime: time.Now().Unix(),
  627. Creator: info.Creator,
  628. Modifier: adminInfo.AdminUser.Id,
  629. Diagnosis: diagnose,
  630. SickHistory: sick_history,
  631. Departments: department,
  632. RegisterType: reg_type,
  633. PrescriptionNumber: info.PrescriptionNumber,
  634. Doctor: role.UserName,
  635. PrescriptionStatus: info.PrescriptionStatus,
  636. DoctorId: doctor_id,
  637. SickType: sick_type,
  638. PType: info.PType,
  639. }
  640. service.SavePatientPrescriptionInfo(hpInfo)
  641. }
  642. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  643. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  644. if len(prescriptions) > 0 {
  645. for _, item := range prescriptions {
  646. items := item.(map[string]interface{})
  647. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  648. utils.ErrorLog("id")
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. id := int64(items["id"].(float64))
  653. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  654. utils.ErrorLog("type")
  655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  656. return
  657. }
  658. types := int64(items["type"].(float64))
  659. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  660. ctime := time.Now().Unix()
  661. prescription := &models.HisPrescription{
  662. ID: id,
  663. PatientId: patient_id,
  664. UserOrgId: adminInfo.CurrentOrgId,
  665. RecordDate: recordDateTime,
  666. Ctime: ctime,
  667. Mtime: ctime,
  668. Type: types,
  669. Modifier: adminInfo.AdminUser.Id,
  670. Creator: adminInfo.AdminUser.Id,
  671. Status: 1,
  672. Doctor: role.UserName,
  673. HisPatientId: his_patient_id,
  674. OrderStatus: 1,
  675. BatchNumber: "",
  676. PrescriptionNumber: hpInfo.PrescriptionNumber,
  677. PType: hpInfo.PType,
  678. }
  679. if historyPrescription.ID > 0 {
  680. prescription.PreTime = historyPrescription.PreTime
  681. }
  682. service.SaveHisPrescription(prescription)
  683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  684. advices := items["advices"].([]interface{})
  685. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  686. groupNo := int64(0)
  687. ctime := time.Now().Unix()
  688. mtime := ctime
  689. if len(advices) > 0 {
  690. for _, advice := range advices {
  691. var s models.HisDoctorAdviceInfo
  692. s.PrescriptionId = prescription.ID
  693. s.AdviceType = 2
  694. s.AdviceDoctor = adminInfo.AdminUser.Id
  695. s.StopState = 2
  696. s.ExecutionState = 2
  697. s.AdviceDate = recordDateTime
  698. s.Status = 1
  699. s.UserOrgId = adminInfo.CurrentOrgId
  700. s.RecordDate = recordDateTime
  701. s.StartTime = prescription.PreTime
  702. s.Groupno = groupNo
  703. s.CreatedTime = ctime
  704. s.UpdatedTime = mtime
  705. s.PatientId = patient_id
  706. s.HisPatientId = his_patient_id
  707. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  708. if errcode > 0 {
  709. c.ServeFailJSONWithSGJErrorCode(errcode)
  710. return
  711. }
  712. service.CreateHisDoctorAdvice(&s)
  713. }
  714. }
  715. }
  716. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  717. projects := items["project"].([]interface{})
  718. if len(projects) > 0 {
  719. for _, project := range projects {
  720. var p models.HisPrescriptionProject
  721. p.PrescriptionId = prescription.ID
  722. p.Ctime = time.Now().Unix()
  723. p.Mtime = time.Now().Unix()
  724. p.PatientId = patient_id
  725. p.RecordDate = recordDateTime
  726. p.UserOrgId = adminInfo.CurrentOrgId
  727. p.HisPatientId = his_patient_id
  728. p.Status = 1
  729. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  730. if errcode > 0 {
  731. c.ServeFailJSONWithSGJErrorCode(errcode)
  732. return
  733. }
  734. service.CreateHisProjectTwo(&p)
  735. }
  736. }
  737. }
  738. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  739. addition := items["addition"].([]interface{})
  740. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  741. ctime := time.Now().Unix()
  742. mtime := ctime
  743. if len(addition) > 0 {
  744. for _, item := range addition {
  745. var s models.HisAdditionalCharge
  746. s.PrescriptionId = prescription.ID
  747. s.Status = 1
  748. s.UserOrgId = adminInfo.CurrentOrgId
  749. s.RecordDate = recordDateTime
  750. s.CreatedTime = ctime
  751. s.UpdatedTime = mtime
  752. s.PatientId = patient_id
  753. s.HisPatientId = his_patient_id
  754. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  755. if errcode > 0 {
  756. c.ServeFailJSONWithSGJErrorCode(errcode)
  757. return
  758. }
  759. service.CreateAdditionalCharge(&s)
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. if err == nil {
  767. c.ServeSuccessJSON(map[string]interface{}{
  768. "msg": "保存成功",
  769. })
  770. return
  771. } else {
  772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  773. return
  774. }
  775. }
  776. func (c *HisApiController) DeletePrescription() {
  777. prescription_id, _ := c.GetInt64("id")
  778. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  779. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  780. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  781. if err == nil {
  782. if len(projects) > 0 {
  783. for _, item := range projects {
  784. if item.Type == 3 { //处理透前准备耗材数量数据
  785. consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
  786. if consumables.ID > 0 {
  787. consumables.Count = 0
  788. service.UpdateConsumables(&consumables)
  789. }
  790. }
  791. }
  792. }
  793. if len(advices) > 0 {
  794. for _, item := range advices {
  795. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  796. drug.Total = drug.Total + item.PrescribingNumber
  797. service.UpdateBaseDrugLib(&drug)
  798. }
  799. }
  800. c.ServeSuccessJSON(map[string]interface{}{
  801. "msg": "删除成功",
  802. })
  803. return
  804. } else {
  805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  806. return
  807. }
  808. }
  809. func (c *HisApiController) DeleteDoctorAdvice() {
  810. id, _ := c.GetInt64("id")
  811. advice, _ := service.GetHisDoctorAdvicesById(id)
  812. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  813. if err == nil {
  814. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  815. drug.Total = drug.Total + advice.PrescribingNumber
  816. service.UpdateBaseDrugLib(&drug)
  817. c.ServeSuccessJSON(map[string]interface{}{
  818. "msg": "删除成功",
  819. })
  820. return
  821. } else {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  823. return
  824. }
  825. }
  826. func (c *HisApiController) DeleteProject() {
  827. id, _ := c.GetInt64("id")
  828. adminInfo := c.GetAdminUserInfo()
  829. project, _ := service.GetHisProjectByID(id)
  830. var consumable models.DialysisBeforePrepare
  831. if project.ID > 0 && project.Type == 3 {
  832. consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
  833. }
  834. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  835. if err == nil {
  836. if consumable.ID > 0 {
  837. consumable.Count = 0
  838. service.UpdateConsumables(&consumable)
  839. }
  840. c.ServeSuccessJSON(map[string]interface{}{
  841. "msg": "删除成功",
  842. })
  843. return
  844. } else {
  845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  846. return
  847. }
  848. }
  849. func (c *HisApiController) CreateHisAdditionalCharge() {
  850. his_patient_id, _ := c.GetInt64("his_patient_id")
  851. patient_id, _ := c.GetInt64("patient_id")
  852. record_date := c.GetString("record_date")
  853. timeLayout := "2006-01-02"
  854. loc, _ := time.LoadLocation("Local")
  855. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  856. if err != nil {
  857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. return
  859. }
  860. adminInfo := c.GetAdminUserInfo()
  861. recordDateTime := theTime.Unix()
  862. dataBody := make(map[string]interface{}, 0)
  863. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  864. if err != nil {
  865. utils.ErrorLog(err.Error())
  866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. return
  868. }
  869. var additions []*models.HisAdditionalCharge
  870. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  871. additions, _ := dataBody["addition"].([]interface{})
  872. if len(additions) > 0 {
  873. for _, item := range additions {
  874. items := item.(map[string]interface{})
  875. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  876. utils.ErrorLog("item_id")
  877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  878. return
  879. }
  880. item_id := int64(items["item_id"].(float64))
  881. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  882. utils.ErrorLog("item_name")
  883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. item_name := items["item_name"].(string)
  887. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  888. utils.ErrorLog("price")
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  890. return
  891. }
  892. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  893. ctime := time.Now().Unix()
  894. additional := &models.HisAdditionalCharge{
  895. PatientId: patient_id,
  896. HisPatientId: his_patient_id,
  897. UserOrgId: adminInfo.CurrentOrgId,
  898. RecordDate: recordDateTime,
  899. CreatedTime: ctime,
  900. UpdatedTime: ctime,
  901. Modifier: adminInfo.AdminUser.Id,
  902. Creator: adminInfo.AdminUser.Id,
  903. Price: price,
  904. ItemName: item_name,
  905. ItemId: item_id,
  906. Status: 1,
  907. }
  908. additions = append(additions, additional)
  909. }
  910. }
  911. }
  912. for _, item := range additions {
  913. service.CreateAddtionalCharge(item)
  914. }
  915. c.ServeSuccessJSON(map[string]interface{}{
  916. "msg": "创建成功",
  917. })
  918. }
  919. func (c *HisApiController) CreateHisPatientCaseHistory() {
  920. blood_fat := c.GetString("blood_fat")
  921. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  922. blood_sugar := c.GetString("blood_sugar")
  923. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  924. fmt.Println(bloodsugarfloat)
  925. chief_conplaint := c.GetString("chief_conplaint")
  926. dbp := c.GetString("dbp")
  927. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  928. delivery_way, _ := c.GetInt64("delivery_way")
  929. diagnostic := c.GetString("diagnostic")
  930. family_history := c.GetString("family_history")
  931. height := c.GetString("height")
  932. history_of_present_illness := c.GetString("history_of_present_illness")
  933. is_infect, _ := c.GetInt64("is_infect")
  934. fmt.Println("is", is_infect)
  935. past_history := c.GetString("past_history")
  936. patient_id, _ := c.GetInt64("patient_id")
  937. his_patient_id, _ := c.GetInt64("his_patient_id")
  938. fmt.Println("patient_id", patient_id)
  939. personal_history := c.GetString("personal_history")
  940. pulse := c.GetString("pulse")
  941. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  942. sbp := c.GetString("sbp")
  943. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  944. heightfloat, _ := strconv.ParseFloat(height, 64)
  945. sicktype := c.GetString("sick_type")
  946. fmt.Println("sicketype", sicktype)
  947. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  948. symptom := c.GetString("symptom")
  949. sick_date := c.GetString("sick_date")
  950. temperatures := c.GetString("temperature")
  951. fmt.Println("temperatures", temperatures)
  952. temperature, _ := strconv.ParseFloat(temperatures, 64)
  953. record_date := c.GetString("record_date")
  954. breathing := c.GetString("breathing")
  955. doctor_advice := c.GetString("doctor_advice")
  956. remark := c.GetString("remark")
  957. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  958. sick, _ := c.GetInt64("sick")
  959. diagnose, _ := c.GetInt64("diagnose")
  960. id, _ := c.GetInt64("id")
  961. timeLayout := "2006-01-02"
  962. loc, _ := time.LoadLocation("Local")
  963. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  964. allergic_history := c.GetString("allergic_history")
  965. if err != nil {
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  967. return
  968. }
  969. recordDateTime := theTime.Unix()
  970. fmt.Println("recordDataTime", recordDateTime)
  971. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  972. if err != nil {
  973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  974. return
  975. }
  976. sickTimes := sickTime.Unix()
  977. ctime := time.Now().Unix()
  978. caseHistory := models.HisPatientCaseHistory{
  979. HisPatientId: his_patient_id,
  980. PatientId: patient_id,
  981. Temperature: temperature,
  982. BloodSugar: bloodsugarfloat,
  983. Pulse: pulsefloat,
  984. Sbp: sbpfloat,
  985. Dbp: dbpfloat,
  986. Height: heightfloat,
  987. BloodFat: bloodfatfloat,
  988. SickType: sick_type,
  989. Symptom: symptom,
  990. SickDate: sickTimes,
  991. IsInfect: is_infect,
  992. HistoryOfPresentIllness: history_of_present_illness,
  993. PastHistory: past_history,
  994. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  995. ChiefConplaint: chief_conplaint,
  996. PersonalHistory: personal_history,
  997. FamilyHistory: family_history,
  998. Diagnostic: diagnostic,
  999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1000. Status: 1,
  1001. Ctime: ctime,
  1002. Mtime: ctime,
  1003. RecordDate: recordDateTime,
  1004. DeliveryWay: delivery_way,
  1005. Breathing: breathingfloat,
  1006. DoctorAdvice: doctor_advice,
  1007. Remark: remark,
  1008. Sick: sick,
  1009. Diagnose: diagnose,
  1010. AllergicHistory: allergic_history,
  1011. }
  1012. //查询该患者是否有病历
  1013. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  1014. if errcodes == gorm.ErrRecordNotFound {
  1015. err = service.SaveHisPatientCaseHistory(&caseHistory)
  1016. if err != nil {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1018. return
  1019. }
  1020. c.ServeSuccessJSON(map[string]interface{}{
  1021. "caseHistory": caseHistory,
  1022. })
  1023. return
  1024. } else if errcodes == nil {
  1025. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  1026. if err != nil {
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1028. return
  1029. }
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "caseHistory": caseHistory,
  1032. })
  1033. }
  1034. //查询该患者是否有病历
  1035. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  1036. //if errcode == gorm.ErrRecordNotFound {
  1037. // err = service.SaveHisPatientCaseHistory(caseHistory)
  1038. // if err != nil {
  1039. // c.ServeSuccessJSON(map[string]interface{}{
  1040. // "msg": "保存成功",
  1041. // })
  1042. // }
  1043. //} else if errcode == nil {
  1044. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1045. // return
  1046. //}
  1047. }
  1048. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  1049. patient_id, _ := c.GetInt64("patient_id", 0)
  1050. adminUser := c.GetAdminUserInfo()
  1051. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "list": caseHistorys,
  1054. })
  1055. }
  1056. func (c *HisApiController) GetHisPatientCaseHistory() {
  1057. record_date, _ := c.GetInt64("record_date", 0)
  1058. patient_id, _ := c.GetInt64("patient_id", 0)
  1059. admin := c.GetAdminUserInfo()
  1060. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  1061. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  1062. c.ServeSuccessJSON(map[string]interface{}{
  1063. "info": info,
  1064. "case_history": case_history,
  1065. })
  1066. }
  1067. func (c *HisApiController) CreateCaseHistoryTemplate() {
  1068. template_name := c.GetString("template_name")
  1069. template_remark := c.GetString("template_remark")
  1070. doctor := c.GetAdminUserInfo().AdminUser.Id
  1071. diagnostic := c.GetString("diagnostic")
  1072. chief_conplaint := c.GetString("chief_conplain")
  1073. history_of_present_illness := c.GetString("history_of_present_illness")
  1074. past_history := c.GetString("past_history")
  1075. personal_history := c.GetString("personal_history")
  1076. family_history := c.GetString("family_history")
  1077. user_name := c.GetString("user_name")
  1078. doctor_advice := c.GetString("doctor_advice")
  1079. remark := c.GetString("remark")
  1080. //record_date := c.GetString("record_date")
  1081. //fmt.Println("record_date--------",record_date)
  1082. //timeLayout := "2006-01-02"
  1083. //loc, _ := time.LoadLocation("Local")
  1084. //
  1085. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1086. //if err != nil {
  1087. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1088. // return
  1089. //}
  1090. //recordDateTime := theTime.Unix()
  1091. ctime := time.Now().Unix()
  1092. template := models.HisCaseHistoryTemplate{
  1093. HistoryOfPresentIllness: history_of_present_illness,
  1094. PastHistory: past_history,
  1095. ChiefConplaint: chief_conplaint,
  1096. PersonalHistory: personal_history,
  1097. FamilyHistory: family_history,
  1098. Diagnostic: diagnostic,
  1099. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1100. Status: 1,
  1101. Ctime: ctime,
  1102. Mtime: ctime,
  1103. RecordDate: time.Now().Unix(),
  1104. TemplateName: template_name,
  1105. TemplateRemark: template_remark,
  1106. Creator: doctor,
  1107. Modifier: doctor,
  1108. UserName: user_name,
  1109. DoctorAdvice: doctor_advice,
  1110. Remark: remark,
  1111. }
  1112. err := service.SaveHisPatientCaseHistoryTemplate(template)
  1113. if err == nil {
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "msg": "保存成功",
  1116. })
  1117. } else {
  1118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1119. return
  1120. }
  1121. }
  1122. func (c *HisApiController) GetCaseHistoryTemplate() {
  1123. timeLayout := "2006-01-02"
  1124. loc, _ := time.LoadLocation("Local")
  1125. keyword := c.GetString("keyword")
  1126. start_time := c.GetString("start_time")
  1127. end_time := c.GetString("end_time")
  1128. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1129. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1130. admin := c.GetAdminUserInfo()
  1131. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  1132. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  1133. c.ServeSuccessJSON(map[string]interface{}{
  1134. "template": template,
  1135. //"history": history,
  1136. })
  1137. }
  1138. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1139. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1140. utils.ErrorLog("drug_name")
  1141. return enums.ErrorCodeParamWrong
  1142. }
  1143. adviceName, _ := json["drug_name"].(string)
  1144. if len(adviceName) == 0 {
  1145. utils.ErrorLog("len(advice_name) == 0")
  1146. return enums.ErrorCodeParamWrong
  1147. }
  1148. advice.AdviceName = adviceName
  1149. adviceDesc, _ := json["advice_desc"].(string)
  1150. advice.AdviceDesc = adviceDesc
  1151. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1152. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1153. advice.DrugSpec = drugSpec
  1154. }
  1155. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1156. remark, _ := json["remark"].(string)
  1157. advice.Remark = remark
  1158. }
  1159. if json["id"] == nil {
  1160. advice.DrugId = 0
  1161. } else {
  1162. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1163. drug_id := int64(json["id"].(float64))
  1164. advice.DrugId = drug_id
  1165. }
  1166. }
  1167. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1168. advice_id := int64(json["advice_id"].(float64))
  1169. advice.ID = advice_id
  1170. if advice.ID > 0 {
  1171. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1172. if err == nil {
  1173. if hisAdvice.ID > 0 {
  1174. advice.ExecutionTime = hisAdvice.ExecutionTime
  1175. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1176. advice.ExecutionState = hisAdvice.ExecutionState
  1177. advice.CheckTime = hisAdvice.CheckTime
  1178. advice.Checker = hisAdvice.Checker
  1179. advice.CheckState = hisAdvice.CheckState
  1180. advice.StartTime = hisAdvice.StartTime
  1181. advice.FeedetlSn = hisAdvice.FeedetlSn
  1182. }
  1183. }
  1184. }
  1185. }
  1186. //
  1187. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1188. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1189. // advice.ExecutionTime = execution_time
  1190. //}
  1191. //
  1192. //
  1193. //
  1194. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1195. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1196. // advice.ExecutionStaff = execution_staff
  1197. //}
  1198. //
  1199. //
  1200. //
  1201. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1202. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1203. // advice.ExecutionState = execution_state
  1204. //}
  1205. //
  1206. //
  1207. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1208. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1209. // advice.CheckTime = check_time
  1210. //}
  1211. //
  1212. //
  1213. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1214. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1215. // advice.CheckState = check_state
  1216. //}
  1217. //
  1218. //
  1219. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1220. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1221. // advice.Checker = checker
  1222. //}
  1223. //
  1224. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1225. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1226. // advice.StartTime = start_time
  1227. //}
  1228. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1229. drugSpecUnit, _ := json["min_unit"].(string)
  1230. advice.DrugSpecUnit = drugSpecUnit
  1231. }
  1232. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1233. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1234. advice.SingleDose = singleDose
  1235. }
  1236. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1237. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1238. advice.SingleDoseUnit = singleDoseUnit
  1239. }
  1240. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1241. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1242. advice.PrescribingNumber = prescribingNumber
  1243. }
  1244. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1245. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1246. advice.PrescribingNumberUnit = prescribingNumberUnit
  1247. }
  1248. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1249. deliveryWay, _ := json["delivery_way"].(string)
  1250. advice.DeliveryWay = deliveryWay
  1251. }
  1252. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1253. executionFrequency, _ := json["execution_frequency"].(string)
  1254. advice.ExecutionFrequency = executionFrequency
  1255. }
  1256. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1257. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1258. advice.Price = price
  1259. }
  1260. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1261. med_list_codg, _ := json["medical_insurance_number"].(string)
  1262. advice.MedListCodg = med_list_codg
  1263. }
  1264. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1265. day := int64(json["day"].(float64))
  1266. advice.Day = day
  1267. }
  1268. return 0
  1269. }
  1270. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1271. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1272. id := int64(json["id"].(float64))
  1273. project.ID = id
  1274. historyProject, _ := service.GetHisProjectByID(id)
  1275. project.FeedetlSn = historyProject.FeedetlSn
  1276. }
  1277. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1278. project_id := int64(json["project_id"].(float64))
  1279. project.ProjectId = project_id
  1280. }
  1281. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1282. // price := int64(json["price"].(float64))
  1283. // formatInt_price := strconv.FormatInt(price, 10)
  1284. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1285. // project.Price = float_price
  1286. // }
  1287. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1288. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1289. project.Price = price
  1290. }
  1291. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1292. total, _ := json["total"].(string)
  1293. totals, _ := strconv.ParseInt(total, 10, 64)
  1294. project.Count = totals
  1295. }
  1296. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1297. medical_code, _ := json["medical_code"].(string)
  1298. project.MedListCodg = medical_code
  1299. }
  1300. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1301. single_dose, _ := json["single_dose"].(string)
  1302. project.SingleDose = single_dose
  1303. }
  1304. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1305. delivery_way, _ := json["delivery_way"].(string)
  1306. project.DeliveryWay = delivery_way
  1307. }
  1308. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1309. execution_frequency, _ := json["execution_frequency"].(string)
  1310. project.ExecutionFrequency = execution_frequency
  1311. }
  1312. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1313. remark, _ := json["remark"].(string)
  1314. project.Remark = remark
  1315. }
  1316. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1317. day, _ := json["number_days"].(string)
  1318. project.Day = day
  1319. }
  1320. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1321. unit, _ := json["unit"].(string)
  1322. project.Unit = unit
  1323. }
  1324. return 0
  1325. }
  1326. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1327. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1328. id := int64(json["id"].(float64))
  1329. historyAddtions, _ := service.GetHisAdditionByID(id)
  1330. additionalCharge.ID = id
  1331. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  1332. }
  1333. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1334. item_id := int64(json["item_id"].(float64))
  1335. additionalCharge.ItemId = item_id
  1336. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1337. if config.ID > 0 {
  1338. if len(config.Code) > 0 {
  1339. additionalCharge.MedListCodg = config.Code
  1340. }
  1341. }
  1342. }
  1343. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1344. // price := int64(json["price"].(float64))
  1345. // formatInt_price := strconv.FormatInt(price, 10)
  1346. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1347. // additionalCharge.Price = float_price
  1348. // }
  1349. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1350. // price := int64(json["price"].(float64))
  1351. // formatInt_price := strconv.FormatInt(price, 10)
  1352. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1353. // additionalCharge.Price = float_price
  1354. //}
  1355. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1356. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1357. additionalCharge.Price = price
  1358. }
  1359. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1360. count, _ := json["count"].(string)
  1361. counts, _ := strconv.ParseInt(count, 10, 64)
  1362. additionalCharge.Count = counts
  1363. }
  1364. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1365. item_name, _ := json["item_name"].(string)
  1366. additionalCharge.ItemName = item_name
  1367. }
  1368. return 0
  1369. }
  1370. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1371. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1372. utils.ErrorLog("drug_name")
  1373. return enums.ErrorCodeParamWrong
  1374. }
  1375. adviceName, _ := json["drug_name"].(string)
  1376. if len(adviceName) == 0 {
  1377. utils.ErrorLog("len(advice_name) == 0")
  1378. return enums.ErrorCodeParamWrong
  1379. }
  1380. advice.AdviceName = adviceName
  1381. adviceDesc, _ := json["advice_desc"].(string)
  1382. advice.AdviceDesc = adviceDesc
  1383. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1384. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1385. advice.DrugSpec = drugSpec
  1386. }
  1387. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1388. remark, _ := json["remark"].(string)
  1389. advice.Remark = remark
  1390. }
  1391. if json["id"] == nil {
  1392. advice.DrugId = 0
  1393. } else {
  1394. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1395. drug_id := int64(json["id"].(float64))
  1396. advice.DrugId = drug_id
  1397. }
  1398. }
  1399. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1400. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1401. advice.PrescribingNumber = prescribingNumber
  1402. }
  1403. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1404. advice_id := int64(json["advice_id"].(float64))
  1405. advice.ID = advice_id
  1406. if advice.ID > 0 {
  1407. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1408. if err == nil {
  1409. if hisAdvice.ID > 0 {
  1410. advice.ExecutionTime = hisAdvice.ExecutionTime
  1411. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1412. advice.ExecutionState = hisAdvice.ExecutionState
  1413. advice.CheckTime = hisAdvice.CheckTime
  1414. advice.Checker = hisAdvice.Checker
  1415. advice.CheckState = hisAdvice.CheckState
  1416. advice.StartTime = hisAdvice.StartTime
  1417. }
  1418. }
  1419. }
  1420. }
  1421. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  1422. if advice.ID == 0 { //医嘱不存在
  1423. drug.Total = drug.Total - advice.PrescribingNumber
  1424. service.UpdateBaseDrugLib(&drug)
  1425. } else if advice.ID > 0 { //医嘱存在
  1426. hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  1427. var num float64
  1428. if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  1429. num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  1430. drug.Total = drug.Total + num
  1431. service.UpdateBaseDrugLib(&drug)
  1432. } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  1433. num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  1434. drug.Total = drug.Total - num
  1435. service.UpdateBaseDrugLib(&drug)
  1436. }
  1437. }
  1438. //
  1439. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1440. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1441. // advice.ExecutionTime = execution_time
  1442. //}
  1443. //
  1444. //
  1445. //
  1446. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1447. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1448. // advice.ExecutionStaff = execution_staff
  1449. //}
  1450. //
  1451. //
  1452. //
  1453. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1454. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1455. // advice.ExecutionState = execution_state
  1456. //}
  1457. //
  1458. //
  1459. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1460. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1461. // advice.CheckTime = check_time
  1462. //}
  1463. //
  1464. //
  1465. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1466. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1467. // advice.CheckState = check_state
  1468. //}
  1469. //
  1470. //
  1471. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1472. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1473. // advice.Checker = checker
  1474. //}
  1475. //
  1476. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1477. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1478. // advice.StartTime = start_time
  1479. //}
  1480. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1481. drugSpecUnit, _ := json["min_unit"].(string)
  1482. advice.DrugSpecUnit = drugSpecUnit
  1483. }
  1484. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1485. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1486. advice.SingleDose = singleDose
  1487. }
  1488. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1489. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1490. advice.SingleDoseUnit = singleDoseUnit
  1491. }
  1492. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1493. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1494. advice.PrescribingNumberUnit = prescribingNumberUnit
  1495. }
  1496. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1497. deliveryWay, _ := json["delivery_way"].(string)
  1498. advice.DeliveryWay = deliveryWay
  1499. }
  1500. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1501. executionFrequency, _ := json["execution_frequency"].(string)
  1502. advice.ExecutionFrequency = executionFrequency
  1503. }
  1504. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1505. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1506. advice.Price = price
  1507. }
  1508. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1509. med_list_codg, _ := json["medical_insurance_number"].(string)
  1510. advice.MedListCodg = med_list_codg
  1511. }
  1512. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1513. day := int64(json["day"].(float64))
  1514. advice.Day = day
  1515. }
  1516. return 0
  1517. }
  1518. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1519. project.ExecutionStaff = 0
  1520. project.ExecutionState = 2
  1521. project.ExecutionTime = 0
  1522. project.Checker = 0
  1523. project.CheckState = 2
  1524. project.CheckTime = 0
  1525. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1526. id := int64(json["id"].(float64))
  1527. project.ID = id
  1528. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  1529. project.ExecutionStaff = temp_project.ExecutionStaff
  1530. project.ExecutionState = temp_project.ExecutionState
  1531. project.ExecutionTime = temp_project.ExecutionTime
  1532. project.Checker = temp_project.Checker
  1533. project.CheckState = temp_project.CheckState
  1534. project.CheckTime = temp_project.CheckTime
  1535. }
  1536. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1537. types := int64(json["type"].(float64))
  1538. project.Type = types
  1539. }
  1540. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1541. project_id := int64(json["project_id"].(float64))
  1542. project.ProjectId = project_id
  1543. fmt.Println(project_id)
  1544. fmt.Println(project.ProjectId)
  1545. }
  1546. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1547. // price := int64(json["price"].(float64))
  1548. // formatInt_price := strconv.FormatInt(price, 10)
  1549. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1550. // project.Price = float_price
  1551. // }
  1552. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1553. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1554. project.Price = price
  1555. }
  1556. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1557. total, _ := json["total"].(string)
  1558. totals, _ := strconv.ParseInt(total, 10, 64)
  1559. project.Count = totals
  1560. }
  1561. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1562. medical_code, _ := json["medical_code"].(string)
  1563. project.MedListCodg = medical_code
  1564. }
  1565. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1566. single_dose, _ := json["single_dose"].(string)
  1567. project.SingleDose = single_dose
  1568. }
  1569. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1570. delivery_way, _ := json["delivery_way"].(string)
  1571. project.DeliveryWay = delivery_way
  1572. }
  1573. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1574. execution_frequency, _ := json["execution_frequency"].(string)
  1575. project.ExecutionFrequency = execution_frequency
  1576. }
  1577. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1578. remark, _ := json["remark"].(string)
  1579. project.Remark = remark
  1580. }
  1581. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1582. day, _ := json["number_days"].(string)
  1583. project.Day = day
  1584. }
  1585. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1586. unit, _ := json["unit"].(string)
  1587. project.Unit = unit
  1588. }
  1589. return 0
  1590. }
  1591. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1592. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1593. id := int64(json["id"].(float64))
  1594. additionalCharge.ID = id
  1595. }
  1596. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1597. item_id := int64(json["item_id"].(float64))
  1598. additionalCharge.ItemId = item_id
  1599. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1600. if config.ID > 0 {
  1601. if len(config.Code) > 0 {
  1602. additionalCharge.MedListCodg = config.Code
  1603. }
  1604. }
  1605. }
  1606. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1607. // price := int64(json["price"].(float64))
  1608. // formatInt_price := strconv.FormatInt(price, 10)
  1609. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1610. // additionalCharge.Price = float_price
  1611. // }
  1612. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1613. // price := int64(json["price"].(float64))
  1614. // formatInt_price := strconv.FormatInt(price, 10)
  1615. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1616. // additionalCharge.Price = float_price
  1617. //}
  1618. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1619. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1620. additionalCharge.Price = price
  1621. }
  1622. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1623. count, _ := json["count"].(string)
  1624. counts, _ := strconv.ParseInt(count, 10, 64)
  1625. additionalCharge.Count = counts
  1626. }
  1627. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1628. item_name, _ := json["item_name"].(string)
  1629. additionalCharge.ItemName = item_name
  1630. }
  1631. return 0
  1632. }
  1633. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  1634. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1635. utils.ErrorLog("drug_name")
  1636. return enums.ErrorCodeParamWrong
  1637. }
  1638. adviceName, _ := json["drug_name"].(string)
  1639. if len(adviceName) == 0 {
  1640. utils.ErrorLog("len(advice_name) == 0")
  1641. return enums.ErrorCodeParamWrong
  1642. }
  1643. advice.AdviceName = adviceName
  1644. adviceDesc, _ := json["advice_desc"].(string)
  1645. advice.AdviceDesc = adviceDesc
  1646. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1647. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1648. advice.DrugSpec = drugSpec
  1649. }
  1650. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1651. remark, _ := json["remark"].(string)
  1652. advice.Remark = remark
  1653. }
  1654. if json["id"] == nil {
  1655. advice.DrugId = 0
  1656. } else {
  1657. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1658. drug_id := int64(json["id"].(float64))
  1659. advice.DrugId = drug_id
  1660. }
  1661. }
  1662. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1663. drugSpecUnit, _ := json["min_unit"].(string)
  1664. advice.DrugSpecUnit = drugSpecUnit
  1665. }
  1666. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1667. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1668. advice.SingleDose = singleDose
  1669. }
  1670. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1671. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1672. advice.SingleDoseUnit = singleDoseUnit
  1673. }
  1674. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1675. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1676. advice.PrescribingNumber = prescribingNumber
  1677. }
  1678. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1679. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1680. advice.PrescribingNumberUnit = prescribingNumberUnit
  1681. }
  1682. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1683. deliveryWay, _ := json["delivery_way"].(string)
  1684. advice.DeliveryWay = deliveryWay
  1685. }
  1686. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1687. executionFrequency, _ := json["execution_frequency"].(string)
  1688. advice.ExecutionFrequency = executionFrequency
  1689. }
  1690. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1691. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1692. advice.Price = price
  1693. }
  1694. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1695. med_list_codg, _ := json["medical_insurance_number"].(string)
  1696. advice.MedListCodg = med_list_codg
  1697. }
  1698. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1699. day := int64(json["day"].(float64))
  1700. advice.Day = day
  1701. }
  1702. return 0
  1703. }
  1704. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  1705. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1706. types := int64(json["type"].(float64))
  1707. project.Type = types
  1708. }
  1709. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1710. project_id := int64(json["project_id"].(float64))
  1711. project.ProjectId = project_id
  1712. }
  1713. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1714. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1715. project.Price = price
  1716. }
  1717. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1718. total, _ := json["total"].(string)
  1719. totals, _ := strconv.ParseInt(total, 10, 64)
  1720. project.Count = totals
  1721. }
  1722. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1723. medical_code, _ := json["medical_code"].(string)
  1724. project.MedListCodg = medical_code
  1725. }
  1726. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1727. single_dose, _ := json["single_dose"].(string)
  1728. project.SingleDose = single_dose
  1729. }
  1730. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1731. delivery_way, _ := json["delivery_way"].(string)
  1732. project.DeliveryWay = delivery_way
  1733. }
  1734. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1735. execution_frequency, _ := json["execution_frequency"].(string)
  1736. project.ExecutionFrequency = execution_frequency
  1737. }
  1738. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1739. remark, _ := json["remark"].(string)
  1740. project.Remark = remark
  1741. }
  1742. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1743. day, _ := json["number_days"].(string)
  1744. project.Day = day
  1745. }
  1746. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1747. unit, _ := json["unit"].(string)
  1748. project.Unit = unit
  1749. }
  1750. return 0
  1751. }
  1752. func (c *HisApiController) GetHisOrderList() {
  1753. page, _ := c.GetInt64("page", -1)
  1754. limit, _ := c.GetInt64("limit", -1)
  1755. start_time := c.GetString("start_time")
  1756. end_time := c.GetString("end_time")
  1757. types, _ := c.GetInt64("type", 0)
  1758. keywords := c.GetString("keywords")
  1759. p_type, _ := c.GetInt64("p_type", 0)
  1760. timeLayout := "2006-01-02"
  1761. loc, _ := time.LoadLocation("Local")
  1762. var startTime int64
  1763. if len(start_time) > 0 {
  1764. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1765. if err != nil {
  1766. fmt.Println(err)
  1767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1768. return
  1769. }
  1770. startTime = theTime.Unix()
  1771. }
  1772. var endTime int64
  1773. if len(end_time) > 0 {
  1774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1775. if err != nil {
  1776. utils.ErrorLog(err.Error())
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1778. return
  1779. }
  1780. endTime = theTime.Unix()
  1781. }
  1782. adminUser := c.GetAdminUserInfo()
  1783. org_id := adminUser.CurrentOrgId
  1784. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  1785. for _, item := range order {
  1786. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  1787. item.DoctorName = info.Doctor
  1788. item.DepartmentName = info.XtHisDepartment.Name
  1789. }
  1790. if err == nil {
  1791. c.ServeSuccessJSON(map[string]interface{}{
  1792. "order": order,
  1793. "total": total,
  1794. })
  1795. } else {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. return
  1798. }
  1799. }
  1800. func (c *HisApiController) GetHisOrder() {
  1801. patient_id, _ := c.GetInt64("patient_id", 0)
  1802. number := c.GetString("number")
  1803. adminInfo := c.GetAdminUserInfo()
  1804. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  1805. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  1806. if err == nil {
  1807. c.ServeSuccessJSON(map[string]interface{}{
  1808. "order": order,
  1809. "prescription": prescriptions,
  1810. })
  1811. } else {
  1812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1813. return
  1814. }
  1815. }
  1816. func (c *HisApiController) GetHisPrescriptionList() {
  1817. record_date := c.GetString("record_date")
  1818. keywords := c.GetString("keywords")
  1819. page, _ := c.GetInt64("page")
  1820. limit, _ := c.GetInt64("limit")
  1821. timeLayout := "2006-01-02"
  1822. loc, _ := time.LoadLocation("Local")
  1823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1824. if err != nil {
  1825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1826. return
  1827. }
  1828. recordDateTime := theTime.Unix()
  1829. adminInfo := c.GetAdminUserInfo()
  1830. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  1831. //adminInfo := c.GetAdminUserInfo()
  1832. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  1833. //fmt.Println(prescriptionOrder)
  1834. if err == nil {
  1835. c.ServeSuccessJSON(map[string]interface{}{
  1836. "order": prescriptionOrder,
  1837. "total": total,
  1838. })
  1839. } else {
  1840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1841. return
  1842. }
  1843. }
  1844. func (c *HisApiController) GetHisPrescriptionInfo() {
  1845. id, _ := c.GetInt64("id")
  1846. adminInfo := c.GetAdminUserInfo()
  1847. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  1848. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  1849. if err == nil {
  1850. c.ServeSuccessJSON(map[string]interface{}{
  1851. "order": prescriptionOrder,
  1852. "prescription": prescription,
  1853. })
  1854. } else {
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1856. return
  1857. }
  1858. }
  1859. func (c *HisApiController) GetMedicalInsuranceConfig() {
  1860. adminUser := c.GetAdminUserInfo()
  1861. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1862. c.ServeSuccessJSON(map[string]interface{}{
  1863. "config": config,
  1864. })
  1865. }
  1866. type ResultTwo struct {
  1867. ErrMsg interface{} `json:"err_msg"`
  1868. InfRefmsgid string `json:"inf_refmsgid"`
  1869. Infcode int64 `json:"infcode"`
  1870. Output struct {
  1871. Baseinfo struct {
  1872. Age float64 `json:"age"`
  1873. Brdy string `json:"brdy"`
  1874. Certno string `json:"certno"`
  1875. Gend string `json:"gend"`
  1876. Naty string `json:"naty"`
  1877. PsnCertType string `json:"psn_cert_type"`
  1878. PsnName string `json:"psn_name"`
  1879. PsnNo string `json:"psn_no"`
  1880. } `json:"baseinfo"`
  1881. Idetinfo []interface{} `json:"idetinfo"`
  1882. Iinfo []struct {
  1883. Balc float64 `json:"balc"`
  1884. CvlservFlag string `json:"cvlserv_flag"`
  1885. EmpName string `json:"emp_name"`
  1886. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1887. Insutype string `json:"insutype"`
  1888. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1889. PausInsuDate interface{} `json:"paus_insu_date"`
  1890. PsnInsuDate string `json:"psn_insu_date"`
  1891. PsnInsuStas string `json:"psn_insu_stas"`
  1892. PsnType string `json:"psn_type"`
  1893. } `json:"insuinfo"`
  1894. } `json:"output"`
  1895. RefmsgTime string `json:"refmsg_time"`
  1896. RespondTime string `json:"respond_time"`
  1897. Signtype interface{} `json:"signtype"`
  1898. WarnInfo interface{} `json:"warn_info"`
  1899. }
  1900. type ResultThree struct {
  1901. Cainfo interface{} `json:"cainfo"`
  1902. ErrMsg interface{} `json:"err_msg"`
  1903. InfRefmsgid string `json:"inf_refmsgid"`
  1904. Infcode int64 `json:"infcode"`
  1905. Output struct {
  1906. Data struct {
  1907. IptOtpNo string `json:"ipt_otp_no"`
  1908. MdtrtID string `json:"mdtrt_id"`
  1909. PsnNo string `json:"psn_no"`
  1910. } `json:"data"`
  1911. } `json:"output"`
  1912. RefmsgTime string `json:"refmsg_time"`
  1913. RespondTime string `json:"respond_time"`
  1914. Signtype interface{} `json:"signtype"`
  1915. WarnMsg interface{} `json:"warn_msg"`
  1916. }
  1917. type ResultFour struct {
  1918. Cainfo string `json:"cainfo"`
  1919. ErrMsg string `json:"err_msg"`
  1920. InfRefmsgid string `json:"inf_refmsgid"`
  1921. Infcode int64 `json:"infcode"`
  1922. Output struct {
  1923. Result []struct {
  1924. BasMednFlag string `json:"bas_medn_flag"`
  1925. ChldMedcFlag string `json:"chld_medc_flag"`
  1926. ChrgitmLv string `json:"chrgitm_lv"`
  1927. Cnt float64 `json:"cnt"`
  1928. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1929. DrtReimFlag string `json:"drt_reim_flag"`
  1930. FeedetlSn string `json:"feedetl_sn"`
  1931. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1932. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1933. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1934. ListSpItemFlag string `json:"list_sp_item_flag"`
  1935. LmtUsedFlag string `json:"lmt_used_flag"`
  1936. MedChrgitmType string `json:"med_chrgitm_type"`
  1937. Memo string `json:"memo"`
  1938. OverlmtAmt float64 `json:"overlmt_amt"`
  1939. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1940. Pric float64 `json:"pric"`
  1941. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1942. SelfpayProp float64 `json:"selfpay_prop"`
  1943. } `json:"result"`
  1944. } `json:"output"`
  1945. RefmsgTime string `json:"refmsg_time"`
  1946. RespondTime string `json:"respond_time"`
  1947. Signtype string `json:"signtype"`
  1948. WarnMsg string `json:"warn_msg"`
  1949. }
  1950. type ResultFive struct {
  1951. Insutype string `json:"insutype"`
  1952. }
  1953. type ResultSix struct {
  1954. Cainfo interface{} `json:"cainfo"`
  1955. ErrMsg interface{} `json:"err_msg"`
  1956. InfRefmsgid string `json:"inf_refmsgid"`
  1957. Infcode int64 `json:"infcode"`
  1958. Output struct {
  1959. } `json:"output"`
  1960. RefmsgTime string `json:"refmsg_time"`
  1961. RespondTime string `json:"respond_time"`
  1962. Signtype interface{} `json:"signtype"`
  1963. WarnMsg interface{} `json:"warn_msg"`
  1964. }
  1965. type ResultSeven struct {
  1966. Cainfo string `json:"cainfo"`
  1967. ErrMsg string `json:"err_msg"`
  1968. InfRefmsgid string `json:"inf_refmsgid"`
  1969. Infcode int64 `json:"infcode"`
  1970. Output struct {
  1971. Setldetail []interface{} `json:"setldetail"`
  1972. Setlinfo struct {
  1973. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1974. AcctPay float64 `json:"acct_pay"`
  1975. ActPayDedc float64 `json:"act_pay_dedc"`
  1976. Age float64 `json:"age"`
  1977. Balc float64 `json:"balc"`
  1978. Brdy string `json:"brdy"`
  1979. Certno string `json:"certno"`
  1980. ClrOptins string `json:"clr_optins"`
  1981. ClrType string `json:"clr_type"`
  1982. ClrWay string `json:"clr_way"`
  1983. CvlservFlag string `json:"cvlserv_flag"`
  1984. CvlservPay float64 `json:"cvlserv_pay"`
  1985. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1986. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1987. Gend string `json:"gend"`
  1988. HifesPay float64 `json:"hifes_pay"`
  1989. HifmiPay float64 `json:"hifmi_pay"`
  1990. HifobPay float64 `json:"hifob_pay"`
  1991. HifpPay float64 `json:"hifp_pay"`
  1992. HospPartAmt float64 `json:"hosp_part_amt"`
  1993. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1994. Insutype string `json:"insutype"`
  1995. MafPay float64 `json:"maf_pay"`
  1996. MdtrtCertType string `json:"mdtrt_cert_type"`
  1997. MdtrtID string `json:"mdtrt_id"`
  1998. MedType string `json:"med_type"`
  1999. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2000. MedinsSetlID string `json:"medins_setl_id"`
  2001. Naty string `json:"naty"`
  2002. OthPay float64 `json:"oth_pay"`
  2003. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2004. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2005. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2006. PsnCashPay float64 `json:"psn_cash_pay"`
  2007. PsnCertType string `json:"psn_cert_type"`
  2008. PsnName string `json:"psn_name"`
  2009. PsnNo string `json:"psn_no"`
  2010. PsnPartAmt float64 `json:"psn_part_amt"`
  2011. PsnType string `json:"psn_type"`
  2012. SetlID string `json:"setl_id"`
  2013. SetlTime string `json:"setl_time"`
  2014. } `json:"setlinfo"`
  2015. } `json:"output"`
  2016. RefmsgTime string `json:"refmsg_time"`
  2017. RespondTime string `json:"respond_time"`
  2018. Signtype interface{} `json:"signtype"`
  2019. WarnMsg interface{} `json:"warn_msg"`
  2020. }
  2021. type ResultEight struct {
  2022. Cainfo string `json:"cainfo"`
  2023. ErrMsg string `json:"err_msg"`
  2024. InfRefmsgid string `json:"inf_refmsgid"`
  2025. Infcode int64 `json:"infcode"`
  2026. Output struct {
  2027. Stmtinfo struct {
  2028. SetlOptins string `json:"setl_optins"`
  2029. StmtRslt string `json:"stmt_rslt"`
  2030. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  2031. } `json:"stmtinfo"`
  2032. } `json:"output"`
  2033. RefmsgTime string `json:"refmsg_time"`
  2034. RespondTime string `json:"respond_time"`
  2035. Signtype interface{} `json:"signtype"`
  2036. WarnMsg interface{} `json:"warn_msg"`
  2037. }
  2038. type ResultNine struct {
  2039. Cainfo string `json:"cainfo"`
  2040. ErrMsg string `json:"err_msg"`
  2041. InfRefmsgid string `json:"inf_refmsgid"`
  2042. Infcode int64 `json:"infcode"`
  2043. Output struct {
  2044. FileQuryNo string `json:"file_qury_no"`
  2045. } `json:"output"`
  2046. RefmsgTime string `json:"refmsg_time"`
  2047. RespondTime string `json:"respond_time"`
  2048. Signtype interface{} `json:"signtype"`
  2049. WarnMsg interface{} `json:"warn_msg"`
  2050. }
  2051. type ResultTen struct {
  2052. Cainfo string `json:"cainfo"`
  2053. ErrMsg string `json:"err_msg"`
  2054. InfRefmsgid string `json:"inf_refmsgid"`
  2055. Infcode int64 `json:"infcode"`
  2056. Output struct {
  2057. DldEndtime string `json:"dld_endtime"`
  2058. FileQuryNo string `json:"file_qury_no"`
  2059. Filename string `json:"filename"`
  2060. } `json:"output"`
  2061. RefmsgTime string `json:"refmsg_time"`
  2062. RespondTime string `json:"respond_time"`
  2063. Signtype interface{} `json:"signtype"`
  2064. WarnMsg interface{} `json:"warn_msg"`
  2065. }
  2066. type ResultEleven struct {
  2067. Cainfo string `json:"cainfo"`
  2068. ErrMsg string `json:"err_msg"`
  2069. InfRefmsgid string `json:"inf_refmsgid"`
  2070. Infcode int64 `json:"infcode"`
  2071. Output struct {
  2072. Setlinfo struct {
  2073. FixmedinsName string `json:"fixmedins_name"`
  2074. FixmedinsCode string `json:"fixmedins_code"`
  2075. PsnNo string `json:"psn_no"`
  2076. PsnName string `json:"psn_name"`
  2077. HifobPay float64 `json:"hifob_pay"`
  2078. Gend string `json:"gend"`
  2079. Brdy string `json:"brdy"`
  2080. PsnCertType string `json:"psn_cert_type"`
  2081. PsnType string `json:"psn_type"`
  2082. EmpName string `json:"emp_name"`
  2083. Certno string `json:"certno"`
  2084. Insutype string `json:"insutype"`
  2085. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2086. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2087. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2088. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2089. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2090. ActPayDedc float64 `json:"act_pay_dedc"`
  2091. HifpPay float64 `json:"hifp_pay"`
  2092. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2093. CvlservPay float64 `json:"cvlserv_pay"`
  2094. HifesPay float64 `json:"hifes_pay"`
  2095. HifmiPay float64 `json:"hifmi_pay"`
  2096. MafPay float64 `json:"maf_pay"`
  2097. OthPay float64 `json:"oth_pay"`
  2098. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2099. PsnPay float64 `json:"psn_pay"`
  2100. AcctPay float64 `json:"acct_pay"`
  2101. CashPayamt float64 `json:"cash_payamt"`
  2102. Balc float64 `json:"balc"`
  2103. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2104. MedinsSetlId string `json:"medins_setl_id"`
  2105. RefdSetlFlag string `json:"refd_setl_flag"`
  2106. SetlTime string `json:"setl_time"`
  2107. MedType string `json:"med_type"`
  2108. } `json:"setlinfo"`
  2109. } `json:"output"`
  2110. RefmsgTime string `json:"refmsg_time"`
  2111. RespondTime string `json:"respond_time"`
  2112. Signtype interface{} `json:"signtype"`
  2113. WarnMsg interface{} `json:"warn_msg"`
  2114. }
  2115. type Custom struct {
  2116. DetItemFeeSumamt string
  2117. Cut string
  2118. FeedetlSn string
  2119. Price string
  2120. MedListCodg string
  2121. Type int64
  2122. AdviceId int64
  2123. ProjectId int64
  2124. ItemId int64
  2125. }
  2126. //获取个人信息----挂号-----上传就诊信息
  2127. func (c *HisApiController) GetRegisterInfo() {
  2128. id, _ := c.GetInt64("id")
  2129. record_time := c.GetString("record_time")
  2130. settlementValue, _ := c.GetInt64("settlement_value")
  2131. medical_insurance_card := c.GetString("medical_insurance_card")
  2132. name := c.GetString("name")
  2133. id_card_type, _ := c.GetInt64("id_card_type")
  2134. certificates, _ := c.GetInt64("certificates")
  2135. medical_care, _ := c.GetInt64("medical_care")
  2136. birthday := c.GetString("birthday")
  2137. age, _ := c.GetInt64("age")
  2138. id_card := c.GetString("id_card")
  2139. register_type, _ := c.GetInt64("register")
  2140. doctor, _ := c.GetInt64("doctor")
  2141. department, _ := c.GetInt64("department")
  2142. gender, _ := c.GetInt64("sex")
  2143. phone := c.GetString("phone")
  2144. registration_fee, _ := c.GetFloat("registration_fee")
  2145. medical_expenses, _ := c.GetFloat("medical_expenses")
  2146. social_type, _ := c.GetInt64("social_type")
  2147. diagnosis_id, _ := c.GetInt64("diagnosis")
  2148. sick_type, _ := c.GetInt64("sick_type")
  2149. reg_type := c.GetString("p_type")
  2150. timeLayout := "2006-01-02"
  2151. loc, _ := time.LoadLocation("Local")
  2152. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  2153. birthUnix := birthdays.Unix()
  2154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2155. if err != nil {
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2157. return
  2158. }
  2159. recordDateTime := theTime.Unix()
  2160. adminInfo := c.GetAdminUserInfo()
  2161. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  2162. if tempPatient.ID == 0 {
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  2164. return
  2165. }
  2166. var patient service.Patients
  2167. if id == 0 {
  2168. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  2169. } else {
  2170. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2171. }
  2172. if patient.ID == 0 {
  2173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2174. return
  2175. }
  2176. if len(patient.IdCardNo) == 0 {
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2178. return
  2179. }
  2180. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2181. if len(his) >= 1 {
  2182. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  2183. if len(his) >= 1 && order.ID == 0 {
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  2185. return
  2186. }
  2187. }
  2188. timeStr := time.Now().Format("2006-01-02 15:04:05")
  2189. fmt.Println(timeStr)
  2190. timeArr := strings.Split(timeStr, " ")
  2191. fmt.Println(timeArr)
  2192. timeArrTwo := strings.Split(timeArr[0], "-")
  2193. timeArrThree := strings.Split(timeArr[1], ":")
  2194. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  2195. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2196. if len(lists) == 0 {
  2197. var hisPatient models.XtHisPatient
  2198. hisPatient = models.XtHisPatient{
  2199. Name: name,
  2200. Age: age,
  2201. Gender: gender,
  2202. Birthday: birthUnix,
  2203. Phone: phone,
  2204. MedicalTreatmentType: medical_care,
  2205. IdType: certificates,
  2206. IdCardNo: id_card,
  2207. BalanceAccountsType: settlementValue,
  2208. SocialType: social_type,
  2209. MedicalInsuranceNumber: medical_insurance_card,
  2210. RegisterType: register_type,
  2211. RegisterCost: registration_fee,
  2212. TreatmentCost: medical_expenses,
  2213. AdminUserId: adminInfo.AdminUser.Id,
  2214. UserOrgId: adminInfo.CurrentOrgId,
  2215. Status: 1,
  2216. RecordDate: recordDateTime,
  2217. IsReturn: 1,
  2218. PatientId: patient.ID,
  2219. Ctime: time.Now().Unix(),
  2220. Mtime: time.Now().Unix(),
  2221. Number: str,
  2222. IdCardType: id_card_type,
  2223. Departments: department,
  2224. Doctor: doctor,
  2225. PType: reg_type,
  2226. Diagnosis: diagnosis_id,
  2227. SickType: sick_type,
  2228. }
  2229. service.CreateHisPatient(&hisPatient)
  2230. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2231. c.ServeSuccessJSON(map[string]interface{}{
  2232. "his_info": hisPatient,
  2233. })
  2234. } else {
  2235. //chrgBchno := rand.Intn(1000000) + 10000
  2236. var hisPatient models.XtHisPatient
  2237. hisPatient = models.XtHisPatient{
  2238. Name: name,
  2239. Age: age,
  2240. Gender: gender,
  2241. Birthday: birthUnix,
  2242. Phone: phone,
  2243. MedicalTreatmentType: medical_care,
  2244. IdType: certificates,
  2245. IdCardNo: id_card,
  2246. BalanceAccountsType: settlementValue,
  2247. SocialType: social_type,
  2248. MedicalInsuranceNumber: medical_insurance_card,
  2249. RegisterType: register_type,
  2250. RegisterCost: registration_fee,
  2251. TreatmentCost: medical_expenses,
  2252. AdminUserId: adminInfo.AdminUser.Id,
  2253. UserOrgId: adminInfo.CurrentOrgId,
  2254. Status: 1,
  2255. RecordDate: recordDateTime,
  2256. IsReturn: 1,
  2257. PatientId: patient.ID,
  2258. Ctime: time.Now().Unix(),
  2259. Mtime: time.Now().Unix(),
  2260. Number: str,
  2261. IdCardType: id_card_type,
  2262. Departments: department,
  2263. Doctor: doctor,
  2264. PType: reg_type,
  2265. Diagnosis: diagnosis_id,
  2266. SickType: sick_type,
  2267. }
  2268. service.CreateHisPatient(&hisPatient)
  2269. c.ServeSuccessJSON(map[string]interface{}{
  2270. "his_info": hisPatient,
  2271. })
  2272. }
  2273. //timeStr := time.Now().Format("2006-01-02")
  2274. //timeArr := strings.Split(timeStr, "-")
  2275. //var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)+ ""
  2276. }
  2277. //上传明细----结算
  2278. func (c *HisApiController) GetUploadInfo() {
  2279. id, _ := c.GetInt64("id")
  2280. record_time := c.GetString("record_time")
  2281. his_patient_id, _ := c.GetInt64("his_patient_id")
  2282. pay_way, _ := c.GetInt64("pay_way")
  2283. pay_price, _ := c.GetFloat("pay_price")
  2284. pay_card_no := c.GetString("pay_card_no")
  2285. discount_price, _ := c.GetFloat("discount_price")
  2286. preferential_price, _ := c.GetFloat("preferential_price")
  2287. reality_price, _ := c.GetFloat("reality_price")
  2288. found_price, _ := c.GetFloat("found_price")
  2289. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2290. private_price, _ := c.GetFloat("private_price")
  2291. timeLayout := "2006-01-02"
  2292. loc, _ := time.LoadLocation("Local")
  2293. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2294. fapiao_code := c.GetString("fapiao_code")
  2295. fapiao_number := c.GetString("fapiao_number")
  2296. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2297. if err != nil {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. }
  2301. recordDateTime := theTime.Unix()
  2302. adminUser := c.GetAdminUserInfo()
  2303. var prescriptions []*models.HisPrescription
  2304. var start_time int64
  2305. var end_time int64
  2306. if settle_accounts_type == 1 { //日结
  2307. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime)
  2308. } else { //月结
  2309. start_time_str := c.GetString("start_time")
  2310. end_time_str := c.GetString("end_time")
  2311. timeLayout := "2006-01-02"
  2312. loc, _ := time.LoadLocation("Local")
  2313. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2314. if err != nil {
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2316. return
  2317. }
  2318. recordStartTime := theStartTime.Unix()
  2319. start_time = recordStartTime
  2320. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2321. if err != nil {
  2322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2323. return
  2324. }
  2325. recordEndTime := theEndTime.Unix()
  2326. end_time = recordEndTime
  2327. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2328. }
  2329. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2330. fmt.Println("~~~~~~~~~")
  2331. fmt.Println(his.Number)
  2332. fmt.Println("~~~~~~~~~")
  2333. timestamp := time.Now().Unix()
  2334. tempTime := time.Unix(timestamp, 0)
  2335. timeFormat := tempTime.Format("20060102150405")
  2336. chrgBchno := rand.Intn(100000) + 10000
  2337. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2338. strconv.FormatInt(his.PatientId, 10)
  2339. var ids []int64
  2340. for _, item := range prescriptions {
  2341. ids = append(ids, item.ID)
  2342. }
  2343. var total float64
  2344. for _, item := range prescriptions {
  2345. if item.Type == 1 { //药品
  2346. for _, subItem := range item.HisDoctorAdviceInfo {
  2347. total = total + (subItem.Price * subItem.PrescribingNumber)
  2348. }
  2349. }
  2350. if item.Type == 2 { //项目
  2351. for _, subItem := range item.HisPrescriptionProject {
  2352. total = total + (subItem.Price * float64(subItem.Count))
  2353. }
  2354. }
  2355. for _, subItem := range item.HisAdditionalCharge {
  2356. total = total + (subItem.Price * float64(subItem.Count))
  2357. }
  2358. }
  2359. allTotal := fmt.Sprintf("%.2f", total)
  2360. totals, _ := strconv.ParseFloat(allTotal, 64)
  2361. order := &models.HisOrder{
  2362. UserOrgId: adminUser.CurrentOrgId,
  2363. HisPatientId: his.ID,
  2364. PatientId: id,
  2365. SettleAccountsDate: recordDateTime,
  2366. Ctime: time.Now().Unix(),
  2367. Mtime: time.Now().Unix(),
  2368. Status: 1,
  2369. OrderStatus: 2,
  2370. MdtrtId: his.Number,
  2371. Number: chrg_bchno,
  2372. MedfeeSumamt: totals,
  2373. PayWay: pay_way,
  2374. PayPrice: pay_price,
  2375. PayCardNo: pay_card_no,
  2376. DiscountPrice: discount_price,
  2377. PreferentialPrice: preferential_price,
  2378. RealityPrice: reality_price,
  2379. FoundPrice: found_price,
  2380. MedicalInsurancePrice: medical_insurance_price,
  2381. PrivatePrice: private_price,
  2382. SettleEndTime: end_time,
  2383. SettleStartTime: start_time,
  2384. SettleType: settle_accounts_type,
  2385. FaPiaoCode: fapiao_code,
  2386. FaPiaoNumber: fapiao_number,
  2387. PType: 2,
  2388. }
  2389. err = service.CreateOrder(order)
  2390. if err != nil {
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2392. return
  2393. }
  2394. var customs []*Custom
  2395. for _, item := range prescriptions {
  2396. if item.Type == 1 { //药品
  2397. for _, subItem := range item.HisDoctorAdviceInfo {
  2398. cus := &Custom{
  2399. AdviceId: subItem.ID,
  2400. ProjectId: 0,
  2401. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2402. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2403. FeedetlSn: subItem.FeedetlSn,
  2404. Price: fmt.Sprintf("%.2f", subItem.Price),
  2405. MedListCodg: subItem.MedListCodg,
  2406. Type: 1,
  2407. }
  2408. customs = append(customs, cus)
  2409. }
  2410. }
  2411. if item.Type == 2 { //项目
  2412. for _, subItem := range item.HisPrescriptionProject {
  2413. cus := &Custom{
  2414. AdviceId: 0,
  2415. ProjectId: subItem.ID,
  2416. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2417. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2418. FeedetlSn: subItem.FeedetlSn,
  2419. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2420. MedListCodg: subItem.MedListCodg,
  2421. Type: 2,
  2422. }
  2423. customs = append(customs, cus)
  2424. }
  2425. }
  2426. for _, item := range item.HisAdditionalCharge {
  2427. cus := &Custom{
  2428. ItemId: item.ID,
  2429. AdviceId: 0,
  2430. ProjectId: 0,
  2431. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2432. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2433. FeedetlSn: item.FeedetlSn,
  2434. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2435. MedListCodg: item.XtHisAddtionConfig.Code,
  2436. Type: 3,
  2437. }
  2438. customs = append(customs, cus)
  2439. }
  2440. }
  2441. for _, item := range customs {
  2442. var advice_id int64 = 0
  2443. var project_id int64 = 0
  2444. var item_id int64 = 0
  2445. var types int64 = 0
  2446. if item.Type == 1 {
  2447. advice_id = item.AdviceId
  2448. project_id = 0
  2449. item_id = 0
  2450. } else if item.Type == 2 {
  2451. advice_id = 0
  2452. item_id = 0
  2453. project_id = item.ProjectId
  2454. } else if item.Type == 3 {
  2455. advice_id = 0
  2456. item_id = item.ItemId
  2457. project_id = 0
  2458. }
  2459. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2460. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2461. pric, _ := strconv.ParseFloat(item.Price, 32)
  2462. info := &models.HisOrderInfo{
  2463. OrderNumber: order.Number,
  2464. UploadDate: time.Now().Unix(),
  2465. AdviceId: advice_id,
  2466. DetItemFeeSumamt: detItemFeeSumamt,
  2467. Cnt: cut,
  2468. Pric: pric,
  2469. PatientId: id,
  2470. Status: 1,
  2471. Mtime: time.Now().Unix(),
  2472. Ctime: time.Now().Unix(),
  2473. UserOrgId: adminUser.CurrentOrgId,
  2474. HisPatientId: his.ID,
  2475. OrderId: order.ID,
  2476. ProjectId: project_id,
  2477. Type: types,
  2478. ItemId: item_id,
  2479. }
  2480. service.CreateOrderInfo(info)
  2481. }
  2482. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2483. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  2484. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2485. if err == nil {
  2486. c.ServeSuccessJSON(map[string]interface{}{
  2487. "msg": "结算成功",
  2488. })
  2489. }
  2490. }
  2491. //退款
  2492. func (c *HisApiController) Refund() {
  2493. order_id, _ := c.GetInt64("order_id")
  2494. //number := c.GetString("number")
  2495. order, _ := service.GetHisOrderByID(order_id)
  2496. adminUser := c.GetAdminUserInfo()
  2497. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2498. if config.IsOpen == 1 { //对接了医保,走医保流程
  2499. } else {
  2500. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  2501. if err == nil {
  2502. c.ServeSuccessJSON(map[string]interface{}{
  2503. "msg": "退费成功",
  2504. })
  2505. } else {
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2507. return
  2508. }
  2509. }
  2510. }
  2511. func (this *HisApiController) AdditionalCharge() {
  2512. dataBody := make(map[string]interface{}, 0)
  2513. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2514. fmt.Println(err)
  2515. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2516. patient_id := int64(dataBody["patient_id"].(float64))
  2517. medicineData, _ := dataBody["medicineData"].([]interface{})
  2518. adminUserInfo := this.GetAdminUserInfo()
  2519. orgId := adminUserInfo.CurrentOrgId
  2520. admin_user_id := adminUserInfo.AdminUser.Id
  2521. timeStr := time.Now().Format("2006-01-02")
  2522. timeLayout := "2006-01-02 15:04:05"
  2523. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2524. timenow := timeStringToTime.Unix()
  2525. var additionalCharges []*models.HisAdditionalCharge
  2526. for _, item := range medicineData {
  2527. var randNum int
  2528. randNum = rand.Intn(10000) + 1000
  2529. timestamp := time.Now().Unix()
  2530. tempTime := time.Unix(timestamp, 0)
  2531. timeFormat := tempTime.Format("20060102150405")
  2532. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2533. items := item.(map[string]interface{})
  2534. money := items["price"].(string)
  2535. item_id_str := items["item_id"].(string)
  2536. name := items["name"].(string)
  2537. id_str := items["id"].(string)
  2538. moneys, _ := strconv.ParseInt(money, 10, 64)
  2539. monStr := strconv.FormatInt(moneys, 10)
  2540. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2541. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2542. id, _ := strconv.ParseInt(id_str, 10, 64)
  2543. additionalCharge := &models.HisAdditionalCharge{
  2544. ID: id,
  2545. HisPatientId: his_patient_id,
  2546. UserOrgId: orgId,
  2547. PatientId: patient_id,
  2548. RecordDate: timenow,
  2549. Price: monneyStr,
  2550. Status: 1,
  2551. ItemName: name,
  2552. ItemId: item_id,
  2553. AdminUserId: admin_user_id,
  2554. CreatedTime: time.Now().Unix(),
  2555. OrderStatus: 0,
  2556. PrescriptionNumber: "",
  2557. BatchNumber: "",
  2558. FeedetlSn: p_number,
  2559. }
  2560. service.CreateAdditionalCharge(additionalCharge)
  2561. additionalCharges = append(additionalCharges, additionalCharge)
  2562. }
  2563. this.ServeSuccessJSON(map[string]interface{}{
  2564. "msg": "添加成功",
  2565. "additional_charges": additionalCharges,
  2566. })
  2567. }
  2568. func (this *HisApiController) DeleteAddition() {
  2569. id, _ := this.GetInt64("id")
  2570. //TODO 需要判断是否已经结算
  2571. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2572. if err == nil {
  2573. this.ServeSuccessJSON(map[string]interface{}{
  2574. "msg": "删除成功",
  2575. })
  2576. return
  2577. } else {
  2578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2579. return
  2580. }
  2581. }
  2582. func (this *HisApiController) GetAdminUsers() {
  2583. adminUser := this.GetAdminUserInfo()
  2584. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2585. this.ServeSuccessJSON(map[string]interface{}{
  2586. "doctors": doctors,
  2587. })
  2588. }
  2589. func (this *HisApiController) GetLastOrNextHisPrescription() {
  2590. change_type, _ := this.GetInt64("type", 0)
  2591. record_date := this.GetString("record_time")
  2592. patient_id, _ := this.GetInt64("patient_id", 0)
  2593. p_type, _ := this.GetInt64("p_type", 0)
  2594. timeLayout := "2006-01-02"
  2595. loc, _ := time.LoadLocation("Local")
  2596. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2597. record_time := theAdviceRecordTime.Unix()
  2598. adminUserInfo := this.GetAdminUserInfo()
  2599. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  2600. if err == nil {
  2601. if len(prescriptions) == 0 {
  2602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2603. return
  2604. } else {
  2605. this.ServeSuccessJSON(map[string]interface{}{
  2606. "prescriptions": prescriptions,
  2607. })
  2608. return
  2609. }
  2610. } else {
  2611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2612. return
  2613. }
  2614. }
  2615. func (this *HisApiController) GetCallHisPrescription() {
  2616. patient_id, _ := this.GetInt64("patient_id", 0)
  2617. timeLayout := "2006-01-02"
  2618. loc, _ := time.LoadLocation("Local")
  2619. start_time := this.GetString("start_time")
  2620. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2621. end_time := this.GetString("end_time")
  2622. p_type, _ := this.GetInt64("p_type")
  2623. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2624. adminUserInfo := this.GetAdminUserInfo()
  2625. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  2626. if err == nil {
  2627. this.ServeSuccessJSON(map[string]interface{}{
  2628. "prescriptions": prescriptions,
  2629. })
  2630. return
  2631. } else {
  2632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2633. return
  2634. }
  2635. }
  2636. func (this *HisApiController) GetHisDayPrescription() {
  2637. timeLayout := "2006-01-02"
  2638. loc, _ := time.LoadLocation("Local")
  2639. start_time := this.GetString("start_time")
  2640. patient_id, _ := this.GetInt64("patient_id", 0)
  2641. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2642. end_time := this.GetString("end_time")
  2643. p_type, _ := this.GetInt64("p_type")
  2644. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2645. adminUserInfo := this.GetAdminUserInfo()
  2646. dayHisPrescription, err := service.GetMonthHisPrescriptionThree(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  2647. if err == nil {
  2648. this.ServeSuccessJSON(map[string]interface{}{
  2649. "day_prescription": dayHisPrescription,
  2650. })
  2651. return
  2652. } else {
  2653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2654. return
  2655. }
  2656. }
  2657. func (c *HisApiController) GetHisChargePatientList() {
  2658. record_date := c.GetString("record_date")
  2659. timeLayout := "2006-01-02"
  2660. loc, _ := time.LoadLocation("Local")
  2661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2662. if err != nil {
  2663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2664. return
  2665. }
  2666. recordDateTime := theTime.Unix()
  2667. adminInfo := c.GetAdminUserInfo()
  2668. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2669. tempPatients, _ := service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2670. var patients []*service.NewTempPatients
  2671. var patients_two []*service.NewTempPatients
  2672. for _, item := range tempPatients {
  2673. //过滤掉没挂号的和没开处方的
  2674. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  2675. patients = append(patients, item)
  2676. }
  2677. //过滤掉没挂号的
  2678. if len(item.HisPatient) > 0 {
  2679. patients_two = append(patients_two, item)
  2680. }
  2681. }
  2682. c.ServeSuccessJSON(map[string]interface{}{
  2683. "list": patients,
  2684. "list_two": patients_two,
  2685. })
  2686. }
  2687. func (c *HisApiController) GetHisUnRegisterPatientList() {
  2688. record_date := c.GetString("record_date")
  2689. timeLayout := "2006-01-02"
  2690. loc, _ := time.LoadLocation("Local")
  2691. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2692. if err != nil {
  2693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2694. return
  2695. }
  2696. recordDateTime := theTime.Unix()
  2697. adminUser := c.GetAdminUserInfo()
  2698. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  2699. var patients []*service.Patients
  2700. for _, item := range tempPatients {
  2701. if item.HisPatient.ID == 0 {
  2702. patients = append(patients, item)
  2703. }
  2704. }
  2705. c.ServeSuccessJSON(map[string]interface{}{
  2706. "list": patients,
  2707. //"list_two": patients_two,
  2708. })
  2709. }
  2710. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  2711. newArr = make([]*service.Patients, 0)
  2712. for i := 0; i < len(patient); i++ {
  2713. repeat := false
  2714. for j := i + 1; j < len(patient); j++ {
  2715. if patient[i].ID == patient[j].ID {
  2716. repeat = true
  2717. break
  2718. }
  2719. }
  2720. if !repeat {
  2721. newArr = append(newArr, patient[i])
  2722. }
  2723. }
  2724. return
  2725. }
  2726. func (c *HisApiController) GetHisChargePatientInfo() {
  2727. patient_id, _ := c.GetInt64("patient_id")
  2728. his_patient_id, _ := c.GetInt64("his_patient_id")
  2729. record_date := c.GetString("record_date")
  2730. start_time := c.GetString("start_time")
  2731. end_time := c.GetString("end_time")
  2732. order_status, _ := c.GetInt64("type", 0)
  2733. p_type, _ := c.GetInt64("p_type", 0)
  2734. timeLayout := "2006-01-02"
  2735. loc, _ := time.LoadLocation("Local")
  2736. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2737. if err != nil {
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. return
  2740. }
  2741. recordDateTime := theTime.Unix()
  2742. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2743. if err != nil {
  2744. }
  2745. startRecordDateTime := startTime.Unix()
  2746. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2747. if err != nil {
  2748. }
  2749. endRecordDateTime := endTime.Unix()
  2750. admin := c.GetAdminUserInfo()
  2751. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  2752. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  2753. var prescriptions []*models.HisPrescription
  2754. if order_status == 1 || order_status == 0 {
  2755. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2756. } else if order_status == 2 {
  2757. prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2758. }
  2759. var monthPrescriptions []*models.HisPrescription
  2760. if order_status == 1 || order_status == 0 {
  2761. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2762. } else if order_status == 2 {
  2763. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2764. }
  2765. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  2766. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  2767. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  2768. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  2769. //获取所有科室信息
  2770. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  2771. c.ServeSuccessJSON(map[string]interface{}{
  2772. "his_info": his_patient_info,
  2773. "xt_info": xt_patient_info,
  2774. "prescription": prescriptions,
  2775. "case_history": case_history,
  2776. "info": patientPrescriptionInfo,
  2777. "month_prescriptions": monthPrescriptions,
  2778. "order": order,
  2779. "doctors": doctors,
  2780. "department": department,
  2781. })
  2782. return
  2783. }
  2784. func (c *HisApiController) GetAllOrderDetail() {
  2785. order_id, _ := c.GetInt64("id", 0)
  2786. order, _ := service.GetHisOrderByID(order_id)
  2787. if order.ID == 0 {
  2788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2789. return
  2790. }
  2791. org_id := c.GetAdminUserInfo().CurrentOrgId
  2792. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2793. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2794. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2795. c.ServeSuccessJSON(map[string]interface{}{
  2796. "order": order,
  2797. "order_info": order_info,
  2798. "patient": patient,
  2799. "admin_info": adminInfo,
  2800. })
  2801. return
  2802. }
  2803. func (c *HisApiController) GetAllOrderDetailCollect() {
  2804. order_id, _ := c.GetInt64("id", 0)
  2805. order, _ := service.GetHisOrderByID(order_id)
  2806. if order.ID == 0 {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2808. return
  2809. }
  2810. org_id := c.GetAdminUserInfo().CurrentOrgId
  2811. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2812. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2813. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2814. c.ServeSuccessJSON(map[string]interface{}{
  2815. "order": order,
  2816. "order_info": order_info,
  2817. "patient": patient,
  2818. "admin_info": adminInfo,
  2819. })
  2820. return
  2821. }
  2822. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  2823. page, _ := c.GetInt64("page")
  2824. limit, _ := c.GetInt64("limit")
  2825. keywords := c.GetString("keywords")
  2826. start_time := c.GetString("start_time")
  2827. end_time := c.GetString("end_time")
  2828. //clr_type := c.GetString("clr_type")
  2829. insutype := c.GetString("insutype")
  2830. timeLayout := "2006-01-02"
  2831. loc, _ := time.LoadLocation("Local")
  2832. var theStartTIme int64
  2833. if len(start_time) > 0 {
  2834. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2835. theStartTIme = theTime.Unix()
  2836. }
  2837. var theEndtTIme int64
  2838. if len(end_time) > 0 {
  2839. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2840. theEndtTIme = theTime.Unix()
  2841. }
  2842. if page <= 0 {
  2843. page = 1
  2844. }
  2845. if limit <= 0 {
  2846. limit = 10
  2847. }
  2848. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  2849. c.ServeSuccessJSON(map[string]interface{}{
  2850. "total": total,
  2851. "list": list,
  2852. })
  2853. return
  2854. }
  2855. func (c *HisApiController) GetPutOnRecordList() {
  2856. page, _ := c.GetInt64("page")
  2857. limit, _ := c.GetInt64("limit")
  2858. keywords := c.GetString("keywords")
  2859. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  2860. if page <= 0 {
  2861. page = 1
  2862. }
  2863. if limit <= 0 {
  2864. limit = 10
  2865. }
  2866. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  2867. c.ServeSuccessJSON(map[string]interface{}{
  2868. "total": total,
  2869. "list": list,
  2870. })
  2871. return
  2872. }
  2873. func (c *HisApiController) GetCompareData() {
  2874. start_time := c.GetString("start_time")
  2875. end_time := c.GetString("end_time")
  2876. insutype := c.GetString("insutype")
  2877. timeLayout := "2006-01-02"
  2878. loc, _ := time.LoadLocation("Local")
  2879. var theStartTIme int64
  2880. if len(start_time) > 0 {
  2881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2882. if err != nil {
  2883. theStartTIme = 0
  2884. }
  2885. theStartTIme = theTime.Unix()
  2886. }
  2887. var theEndtTIme int64
  2888. if len(end_time) > 0 {
  2889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2890. if err != nil {
  2891. theEndtTIme = 0
  2892. }
  2893. theEndtTIme = theTime.Unix()
  2894. }
  2895. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  2896. if err == nil {
  2897. c.ServeSuccessJSON(map[string]interface{}{
  2898. "list": formData,
  2899. })
  2900. } else {
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2902. return
  2903. }
  2904. }
  2905. func (c *HisApiController) GetFaPiaoData() {
  2906. order_id, _ := c.GetInt64("order_id")
  2907. patient_id, _ := c.GetInt64("patient_id")
  2908. adminUser := c.GetAdminUserInfo()
  2909. order, _ := service.GetHisOrderByID(order_id)
  2910. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2911. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  2912. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2913. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  2914. var bedCostTotal float64 = 0 //床位总费
  2915. var bedCostSelfTotal float64 = 0 //床位自费
  2916. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2917. var operationCostTotal float64 = 0 //手术费
  2918. var operationCostSelfTotal float64 = 0 //手术费
  2919. var operationCostPartSelfTotal float64 = 0 //手术费
  2920. var otherCostTotal float64 = 0 //其他费用
  2921. var otherCostSelfTotal float64 = 0 //其他费用
  2922. var otherCostPartSelfTotal float64 = 0 //其他费用
  2923. var materialCostTotal float64 = 0 //材料费
  2924. var materialCostSelfTotal float64 = 0 //材料费
  2925. var materialCostPartSelfTotal float64 = 0 //材料费
  2926. var westernMedicineCostTotal float64 = 0 //西药费
  2927. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2928. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2929. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2930. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2931. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2932. var checkCostTotal float64 = 0 //检查费
  2933. var checkCostSelfTotal float64 = 0 //检查费
  2934. var checkCostPartSelfTotal float64 = 0 //检查费
  2935. var laboratoryCostTotal float64 = 0 //化验费
  2936. var laboratoryCostSelfTotal float64 = 0 //化验费
  2937. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2938. var treatCostTotal float64 = 0 //治疗费用
  2939. var treatCostSelfTotal float64 = 0 //治疗费用
  2940. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2941. decimal.DivisionPrecision = 2
  2942. for _, item := range orderInfos {
  2943. if item.MedChrgitmType == "01" { //床位费
  2944. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2945. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2946. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2947. }
  2948. if item.MedChrgitmType == "03" { //检查费
  2949. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2950. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2951. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2952. }
  2953. if item.MedChrgitmType == "04" { //化验费
  2954. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2955. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2956. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2957. }
  2958. if item.MedChrgitmType == "05" { //治疗费
  2959. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2960. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2961. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2962. }
  2963. if item.MedChrgitmType == "06" { //手术费
  2964. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2965. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2966. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2967. }
  2968. if item.MedChrgitmType == "08" { //材料费
  2969. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2970. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2971. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2972. }
  2973. if item.MedChrgitmType == "09" { //西药费
  2974. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2975. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2976. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2977. }
  2978. if item.MedChrgitmType == "11" { //中成费
  2979. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2980. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2981. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2982. }
  2983. if item.MedChrgitmType == "14" { //其他费
  2984. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2985. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  2986. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  2987. }
  2988. }
  2989. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2990. c.ServeSuccessJSON(map[string]interface{}{
  2991. "order_number": order.Number, //业务流水号
  2992. "id_card_no": his.IdCardNo, //社会保障号
  2993. "department_name": department.Name, //科室
  2994. "number": his.Number, //门诊号
  2995. "date": order.SettleAccountsDate, //结算日期
  2996. "name": order.PsnName, //姓名
  2997. "gender": order.Gend, //性别
  2998. "psn_cash_money": order.PsnCashPay, //个人支付
  2999. "pay_way": "门诊", //结算方式
  3000. "medfee_sumamt": order.MedfeeSumamt, //总费用
  3001. "admin_user_name": admin.UserName, //收款员
  3002. "bedCostTotal": bedCostTotal,
  3003. "bedCostSelfTotal": bedCostSelfTotal,
  3004. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3005. "operationCostTotal": operationCostTotal,
  3006. "operationCostSelfTotal": operationCostSelfTotal,
  3007. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3008. "otherCostTotal": otherCostTotal,
  3009. "otherCostSelfTotal": otherCostSelfTotal,
  3010. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3011. "materialCostTotal": materialCostTotal,
  3012. "materialCostSelfTotal": materialCostSelfTotal,
  3013. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3014. "westernMedicineCostTotal": westernMedicineCostTotal,
  3015. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3016. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3017. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3018. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3019. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3020. "checkCostTotal": checkCostTotal,
  3021. "checkCostSelfTotal": checkCostSelfTotal,
  3022. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3023. "laboratoryCostTotal": laboratoryCostTotal,
  3024. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3025. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3026. "treatCostTotal": treatCostTotal,
  3027. "treatCostSelfTotal": treatCostSelfTotal,
  3028. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3029. })
  3030. }
  3031. func (this *HisApiController) GetIncomeStatisticsData() {
  3032. start_time := this.GetString("start_time")
  3033. end_time := this.GetString("end_time")
  3034. key_words := this.GetString("key_words")
  3035. limit, _ := this.GetInt64("limit")
  3036. page, _ := this.GetInt64("page")
  3037. if page <= 0 {
  3038. page = 1
  3039. }
  3040. if limit <= 0 {
  3041. limit = 10
  3042. }
  3043. statistics_type, _ := this.GetInt64("statistics_type")
  3044. admin := this.GetAdminUserInfo()
  3045. timeLayout := "2006-01-02"
  3046. loc, _ := time.LoadLocation("Local")
  3047. var theStartTIme int64
  3048. if len(start_time) > 0 {
  3049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3050. if err != nil {
  3051. theStartTIme = 0
  3052. }
  3053. theStartTIme = theTime.Unix()
  3054. }
  3055. var theEndtTIme int64
  3056. if len(end_time) > 0 {
  3057. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3058. if err != nil {
  3059. theEndtTIme = 0
  3060. }
  3061. theEndtTIme = theTime.Unix()
  3062. }
  3063. if statistics_type == 1 {
  3064. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3065. this.ServeSuccessJSON(map[string]interface{}{
  3066. "list": list,
  3067. "total": total,
  3068. })
  3069. } else {
  3070. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3071. this.ServeSuccessJSON(map[string]interface{}{
  3072. "list": list,
  3073. "total": total,
  3074. })
  3075. }
  3076. }
  3077. func (c *HisApiController) PostProjectInformation() {
  3078. adminUser := c.GetAdminUserInfo()
  3079. orgId := adminUser.CurrentOrgId
  3080. dataBody := make(map[string]interface{}, 0)
  3081. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3082. if err != nil {
  3083. utils.ErrorLog(err.Error())
  3084. return
  3085. }
  3086. utils.ErrorLog("%v", dataBody)
  3087. var projectList []*models.HisProject
  3088. var total_goods []interface{}
  3089. tempProjects := dataBody["projects"].([]interface{})
  3090. total_goods = tempProjects
  3091. for index, projectMap := range tempProjects {
  3092. projectM := projectMap.(map[string]interface{})
  3093. var project models.HisProject
  3094. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  3095. utils.ErrorLog("project_name")
  3096. return
  3097. }
  3098. project_name, _ := projectM["project_name"].(string)
  3099. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  3100. err_log := models.ExportErrLog{
  3101. LogType: 6,
  3102. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3103. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  3104. Status: 1,
  3105. CreateTime: time.Now().Unix(),
  3106. UpdateTime: time.Now().Unix(),
  3107. ExportTime: time.Now().Unix(),
  3108. }
  3109. service.CreateExportErrLog(&err_log)
  3110. continue
  3111. }
  3112. project.ProjectName = project_name
  3113. prices := projectM["price"].(string)
  3114. price, _ := strconv.ParseFloat(prices, 64)
  3115. if price <= 0 { //名字为空则生成一条导入错误日志
  3116. err_log := models.ExportErrLog{
  3117. LogType: 6,
  3118. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3119. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  3120. Status: 1,
  3121. CreateTime: time.Now().Unix(),
  3122. UpdateTime: time.Now().Unix(),
  3123. ExportTime: time.Now().Unix(),
  3124. }
  3125. service.CreateExportErrLog(&err_log)
  3126. continue
  3127. }
  3128. project.Price = price
  3129. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  3130. utils.ErrorLog("unit_id")
  3131. return
  3132. }
  3133. unit := projectM["unit"].(string)
  3134. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  3135. err_log := models.ExportErrLog{
  3136. LogType: 6,
  3137. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3138. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  3139. Status: 1,
  3140. CreateTime: time.Now().Unix(),
  3141. UpdateTime: time.Now().Unix(),
  3142. ExportTime: time.Now().Unix(),
  3143. }
  3144. service.CreateExportErrLog(&err_log)
  3145. continue
  3146. }
  3147. project.Unit = unit
  3148. cost_classify := projectM["cost_classify"].(string)
  3149. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  3150. err_log := models.ExportErrLog{
  3151. LogType: 6,
  3152. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3153. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3154. Status: 1,
  3155. CreateTime: time.Now().Unix(),
  3156. UpdateTime: time.Now().Unix(),
  3157. ExportTime: time.Now().Unix(),
  3158. }
  3159. service.CreateExportErrLog(&err_log)
  3160. continue
  3161. }
  3162. var costClassify = "费用类别"
  3163. var cost_classify_id int64
  3164. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  3165. if len(cost_classify) != 0 {
  3166. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  3167. if errcode == gorm.ErrRecordNotFound {
  3168. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  3169. dataconfig := models.DictDataconfig{
  3170. ParentId: costClassifyConfig.ID,
  3171. Module: "system",
  3172. OrgId: orgId,
  3173. Name: cost_classify,
  3174. FieldName: "",
  3175. Value: costConfig.Value + 1,
  3176. CreatedTime: "",
  3177. UpdatedTime: "",
  3178. CreateUserId: adminUser.AdminUser.Id,
  3179. Status: 1,
  3180. Remark: "",
  3181. DeleteIdSystem: 0,
  3182. Title: "",
  3183. Content: "",
  3184. Order: 0,
  3185. Code: "",
  3186. }
  3187. service.CreatedDicConfig(&dataconfig)
  3188. }
  3189. }
  3190. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  3191. for _, it := range costClassList {
  3192. if cost_classify == it.Name {
  3193. cost_classify_id = int64(it.Value)
  3194. }
  3195. }
  3196. project.CostClassify = cost_classify_id
  3197. executive_section := projectM["executive_section"].(string)
  3198. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  3199. err_log := models.ExportErrLog{
  3200. LogType: 6,
  3201. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3202. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  3203. Status: 1,
  3204. CreateTime: time.Now().Unix(),
  3205. UpdateTime: time.Now().Unix(),
  3206. ExportTime: time.Now().Unix(),
  3207. }
  3208. service.CreateExportErrLog(&err_log)
  3209. continue
  3210. }
  3211. if len(executive_section) != 0 {
  3212. //查找科室是否有内容
  3213. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  3214. if errcodedepart == gorm.ErrRecordNotFound {
  3215. department := models.XtHisDepartment{
  3216. Name: executive_section,
  3217. Status: 1,
  3218. UserOrgId: adminUser.CurrentOrgId,
  3219. CreatedTime: time.Now().Unix(),
  3220. }
  3221. service.CreateDePartment(&department)
  3222. }
  3223. }
  3224. var executive_section_id int64
  3225. departMentList, _ := service.GetAllDepartMent(orgId)
  3226. for _, it := range departMentList {
  3227. if executive_section == it.Name {
  3228. executive_section_id = it.ID
  3229. }
  3230. }
  3231. project.ExecutiveSection = executive_section_id
  3232. medical_coverage := projectM["medical_coverage"].(string)
  3233. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  3234. err_log := models.ExportErrLog{
  3235. LogType: 6,
  3236. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3237. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3238. Status: 1,
  3239. CreateTime: time.Now().Unix(),
  3240. UpdateTime: time.Now().Unix(),
  3241. ExportTime: time.Now().Unix(),
  3242. }
  3243. service.CreateExportErrLog(&err_log)
  3244. continue
  3245. }
  3246. var medicalCoverage = "医保等级"
  3247. var medical_coverage_id int64
  3248. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  3249. if len(medical_coverage) != 0 {
  3250. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  3251. if errormedicalcoverage == gorm.ErrRecordNotFound {
  3252. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  3253. dataconfig := models.DictDataconfig{
  3254. ParentId: medicalCoverageConfig.ID,
  3255. Module: "system",
  3256. OrgId: orgId,
  3257. Name: medical_coverage,
  3258. FieldName: "",
  3259. Value: medicalCoverageConfig.Value + 1,
  3260. CreatedTime: "",
  3261. UpdatedTime: "",
  3262. CreateUserId: adminUser.AdminUser.Id,
  3263. Status: 1,
  3264. Remark: "",
  3265. DeleteIdSystem: 0,
  3266. Title: "",
  3267. Content: "",
  3268. Order: 0,
  3269. Code: "",
  3270. }
  3271. service.CreatedDicConfig(&dataconfig)
  3272. }
  3273. }
  3274. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  3275. for _, it := range medicalCoverageList {
  3276. if medical_coverage == it.Name {
  3277. medical_coverage_id = int64(it.Value)
  3278. }
  3279. }
  3280. project.MedicalCoverage = medical_coverage_id
  3281. pinyin := projectM["pinyin"].(string)
  3282. project.Pinyin = pinyin
  3283. wubi := projectM["wubi"].(string)
  3284. project.Wubi = wubi
  3285. statistical_classification := projectM["statistical_classification"].(string)
  3286. var statisticalClassification = "统计分类"
  3287. var statistical_classification_id int64
  3288. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  3289. if len(statistical_classification) != 0 {
  3290. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  3291. if classificationerrcodes == gorm.ErrRecordNotFound {
  3292. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  3293. dataconfig := models.DictDataconfig{
  3294. ParentId: classiFication.ID,
  3295. Module: "system",
  3296. OrgId: orgId,
  3297. Name: statistical_classification,
  3298. FieldName: "",
  3299. Value: classiFicationConfig.Value + 1,
  3300. CreatedTime: "",
  3301. UpdatedTime: "",
  3302. CreateUserId: adminUser.AdminUser.Id,
  3303. Status: 1,
  3304. Remark: "",
  3305. DeleteIdSystem: 0,
  3306. Title: "",
  3307. Content: "",
  3308. Order: 0,
  3309. Code: "",
  3310. }
  3311. service.CreatedDicConfig(&dataconfig)
  3312. }
  3313. }
  3314. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  3315. for _, it := range classiFicationList {
  3316. if statistical_classification == it.Name {
  3317. statistical_classification_id = int64(it.Value)
  3318. }
  3319. }
  3320. project.StatisticalClassification = statistical_classification_id
  3321. disease_directory := int64(projectM["disease_directory"].(float64))
  3322. project.DiseaseDirectory = disease_directory
  3323. is_record := int64(projectM["is_record"].(float64))
  3324. project.IsRecord = is_record
  3325. medical_code := projectM["medical_code"].(string)
  3326. project.MedicalCode = medical_code
  3327. tube_color := projectM["tube_color"].(string)
  3328. var tubeColor = "试管颜色"
  3329. var tube_color_id int64
  3330. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  3331. if len(tube_color) != 0 {
  3332. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  3333. if errcodetube == gorm.ErrRecordNotFound {
  3334. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  3335. dataconfig := models.DictDataconfig{
  3336. ParentId: tubeColorConfig.ID,
  3337. Module: "system",
  3338. OrgId: orgId,
  3339. Name: tube_color,
  3340. FieldName: "",
  3341. Value: tubeConfig.Value + 1,
  3342. CreatedTime: "",
  3343. UpdatedTime: "",
  3344. CreateUserId: adminUser.AdminUser.Id,
  3345. Status: 1,
  3346. Remark: "",
  3347. DeleteIdSystem: 0,
  3348. Title: "",
  3349. Content: "",
  3350. Order: 0,
  3351. Code: "",
  3352. }
  3353. service.CreatedDicConfig(&dataconfig)
  3354. }
  3355. }
  3356. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  3357. for _, it := range tubeColorList {
  3358. if tube_color == it.Name {
  3359. tube_color_id = int64(it.Value)
  3360. }
  3361. }
  3362. project.TubeColor = tube_color_id
  3363. single_dose := projectM["single_dose"].(string)
  3364. project.SingleDose = single_dose
  3365. execution_frequency := projectM["execution_frequency"].(string)
  3366. project.ExecutionFrequency = execution_frequency
  3367. delivery_way := projectM["delivery_way"].(string)
  3368. project.DeliveryWay = delivery_way
  3369. number_days := projectM["number_days"].(string)
  3370. project.NumberDays = number_days
  3371. total := projectM["total"].(string)
  3372. project.Total = total
  3373. medical_status := int64(projectM["medical_status"].(float64))
  3374. project.MedicalStatus = medical_status
  3375. category := int64(projectM["category"].(float64))
  3376. project.Category = category
  3377. specail_project := int64(projectM["specail_project"].(float64))
  3378. project.SpecailProject = specail_project
  3379. social_security_directory_code := projectM["social_security_directory_code"].(string)
  3380. project.SocialSecurityDirectoryCode = social_security_directory_code
  3381. remark := projectM["remark"].(string)
  3382. project.Remark = remark
  3383. record_date := projectM["record_date"].(string)
  3384. timeLayout := "2006-01-02"
  3385. loc, _ := time.LoadLocation("Local")
  3386. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3387. project.RecordDate = theTime.Unix()
  3388. projectList = append(projectList, &project)
  3389. }
  3390. export_time := time.Now().Unix()
  3391. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3392. if len(projectList) > 0 {
  3393. for _, item := range projectList {
  3394. project := models.HisProject{
  3395. ProjectName: item.ProjectName,
  3396. Price: item.Price,
  3397. Unit: item.Unit,
  3398. CostClassify: item.CostClassify,
  3399. ExecutiveSection: item.ExecutiveSection,
  3400. MedicalCoverage: item.MedicalCoverage,
  3401. UserOrgId: orgId,
  3402. Status: 1,
  3403. CreatedTime: time.Now().Unix(),
  3404. Pinyin: item.Pinyin,
  3405. Wubi: item.Wubi,
  3406. StatisticalClassification: item.StatisticalClassification,
  3407. DiseaseDirectory: item.DiseaseDirectory,
  3408. IsRecord: item.IsRecord,
  3409. MedicalCode: item.MedicalCode,
  3410. TubeColor: item.TubeColor,
  3411. SingleDose: item.SingleDose,
  3412. DeliveryWay: item.DeliveryWay,
  3413. NumberDays: item.NumberDays,
  3414. Total: item.Total,
  3415. Category: item.Category,
  3416. MedicalStatus: item.MedicalStatus,
  3417. SpecailProject: item.SpecailProject,
  3418. RecordDate: item.RecordDate,
  3419. Remark: item.Remark,
  3420. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3421. ExecutionFrequency: item.ExecutionFrequency,
  3422. }
  3423. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  3424. if errcodeproject == gorm.ErrRecordNotFound {
  3425. service.CreateProjectInfomation(&project)
  3426. } else if errcodeproject == nil {
  3427. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  3428. }
  3429. log := models.ExportLog{
  3430. LogType: 6,
  3431. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3432. TotalNum: int64(len(total_goods)),
  3433. FailNum: int64(len(errLogs)),
  3434. SuccessNum: int64(len(projectList)),
  3435. CreateTime: time.Now().Unix(),
  3436. UpdateTime: time.Now().Unix(),
  3437. ExportTime: export_time,
  3438. Status: 1,
  3439. }
  3440. service.CreateExportLog(&log)
  3441. c.ServeSuccessJSON(map[string]interface{}{
  3442. "msg": "导入成功",
  3443. "total_num": len(total_goods),
  3444. "success_num": len(projectList),
  3445. "fail_num": int64(len(errLogs)),
  3446. })
  3447. }
  3448. } else {
  3449. log := models.ExportLog{
  3450. LogType: 6,
  3451. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3452. TotalNum: int64(len(total_goods)),
  3453. FailNum: int64(len(errLogs)),
  3454. SuccessNum: int64(len(projectList)),
  3455. CreateTime: time.Now().Unix(),
  3456. UpdateTime: time.Now().Unix(),
  3457. ExportTime: export_time,
  3458. Status: 1,
  3459. }
  3460. service.CreateExportLog(&log)
  3461. c.ServeSuccessJSON(map[string]interface{}{
  3462. "msg": "导入成功",
  3463. "total_num": len(total_goods),
  3464. "success_num": len(projectList),
  3465. "fail_num": int64(len(errLogs)),
  3466. })
  3467. }
  3468. }
  3469. //func (this *HisApiController) EditProjectInformation(){
  3470. //
  3471. // id, _ := this.GetInt64("id")
  3472. // project_team := this.GetString("project_team")
  3473. // price := this.GetString("price")
  3474. // price_float, _ := strconv.ParseFloat(price, 64)
  3475. // pinyin := this.GetString("pinyin")
  3476. // wubi := this.GetString("wubi")
  3477. // tube_color, _ := this.GetInt64("tube_color")
  3478. // team_type, _ := this.GetInt64("team_type")
  3479. // remark := this.GetString("remark")
  3480. // ids := this.GetString("ids")
  3481. // item_id := this.GetString("item_id")
  3482. // projectTeam := models.XtHisProjectTeam{
  3483. // ProjectTeam: project_team,
  3484. // Price: price_float,
  3485. // Pinyin: pinyin,
  3486. // Wubi: wubi,
  3487. // TubeColor: tube_color,
  3488. // TeamType: team_type,
  3489. // Remark: remark,
  3490. // ProjectId: ids,
  3491. // ItemId: item_id,
  3492. // }
  3493. //
  3494. //
  3495. // dataBody := make(map[string]interface{}, 0)
  3496. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3497. // if err != nil {
  3498. // utils.ErrorLog(err.Error())
  3499. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3500. // return
  3501. // }
  3502. //
  3503. // err = service.UpdatedProjectTeam(id, &projectTeam)
  3504. //
  3505. //
  3506. // if err != nil {
  3507. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3508. // return
  3509. // }
  3510. //
  3511. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  3512. // infos, _ := dataBody["info"].([]interface{})
  3513. // if len(infos) > 0 {
  3514. // var ids []string
  3515. //
  3516. // for _, item := range infos {
  3517. // items := item.(map[string]interface{})
  3518. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3519. // utils.ErrorLog("id")
  3520. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3521. // return
  3522. // }
  3523. // id := int64(items["id"].(float64))
  3524. //
  3525. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3526. // utils.ErrorLog("type")
  3527. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3528. // return
  3529. // }
  3530. // types := int64(items["type"].(float64))
  3531. //
  3532. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  3533. // utils.ErrorLog("number")
  3534. // }
  3535. //
  3536. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  3537. //
  3538. // projectList := models.XtHisProjectList{
  3539. // Number: number,
  3540. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3541. // ProjectId: id,
  3542. // Status: 1,
  3543. // CreatedTime: time.Now().Unix(),
  3544. // UpdatedTime: time.Now().Unix(),
  3545. // TeamId: projectTeam.ID,
  3546. // Type: types,
  3547. // }
  3548. // list := projectList
  3549. //
  3550. // service.CreateProjectList(&list)
  3551. //
  3552. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  3553. //
  3554. // }
  3555. // ids_str := strings.Join(ids, ",")
  3556. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  3557. // service.SaveProjectTeam(&projectTeam)
  3558. // this.ServeSuccessJSON(map[string]interface{}{
  3559. // "projectTeam": projectTeam,
  3560. // })
  3561. // }
  3562. // }
  3563. //}
  3564. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  3565. name := c.GetString("name")
  3566. mode_id, _ := c.GetInt64("mode", 0)
  3567. types, _ := c.GetInt64("type", 0)
  3568. patient_id, _ := c.GetInt64("patient_id", 0)
  3569. types = 1
  3570. adminInfo := c.GetAdminUserInfo()
  3571. template := &models.HisPrescriptionTemplate{
  3572. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3573. PatientId: patient_id,
  3574. Type: types,
  3575. Status: 1,
  3576. Ctime: time.Now().Unix(),
  3577. Mtime: time.Now().Unix(),
  3578. Name: name,
  3579. Mode: mode_id,
  3580. }
  3581. dataBody := make(map[string]interface{}, 0)
  3582. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3583. if err != nil {
  3584. utils.ErrorLog(err.Error())
  3585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3586. return
  3587. }
  3588. err = service.CreateHisPrescriptionTemplate(template)
  3589. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3590. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3591. if len(prescriptions) > 0 {
  3592. for _, item := range prescriptions {
  3593. items := item.(map[string]interface{})
  3594. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3595. utils.ErrorLog("type")
  3596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3597. return
  3598. }
  3599. types := int64(items["type"].(float64))
  3600. ctime := time.Now().Unix()
  3601. prescription := &models.HisPrescriptionInfoTemplate{
  3602. PatientId: patient_id,
  3603. UserOrgId: adminInfo.CurrentOrgId,
  3604. Ctime: ctime,
  3605. Mtime: ctime,
  3606. Type: types,
  3607. Modifier: adminInfo.AdminUser.Id,
  3608. Creator: adminInfo.AdminUser.Id,
  3609. Status: 1,
  3610. PTemplateId: template.ID,
  3611. }
  3612. service.CreateHisPrescriptionInfoTemplate(prescription)
  3613. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3614. advices := items["advices"].([]interface{})
  3615. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3616. groupNo := int64(0)
  3617. ctime := time.Now().Unix()
  3618. mtime := ctime
  3619. if len(advices) > 0 {
  3620. for _, advice := range advices {
  3621. var s models.HisPrescriptionAdviceTemplate
  3622. s.PrescriptionId = prescription.ID
  3623. s.AdviceType = 2
  3624. s.StopState = 2
  3625. s.ExecutionState = 2
  3626. s.Status = 1
  3627. s.UserOrgId = adminInfo.CurrentOrgId
  3628. s.Groupno = groupNo
  3629. s.CreatedTime = ctime
  3630. s.UpdatedTime = mtime
  3631. s.PatientId = patient_id
  3632. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  3633. if errcode > 0 {
  3634. c.ServeFailJSONWithSGJErrorCode(errcode)
  3635. return
  3636. }
  3637. service.CreateHisPrescriptionAdviceTemplate(&s)
  3638. }
  3639. }
  3640. }
  3641. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3642. projects := items["project"].([]interface{})
  3643. if len(projects) > 0 {
  3644. for _, project := range projects {
  3645. var p models.HisPrescriptionProjectTemplate
  3646. p.PrescriptionId = prescription.ID
  3647. p.Ctime = time.Now().Unix()
  3648. p.Mtime = time.Now().Unix()
  3649. p.PatientId = patient_id
  3650. p.UserOrgId = adminInfo.CurrentOrgId
  3651. p.Status = 1
  3652. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  3653. if errcode > 0 {
  3654. c.ServeFailJSONWithSGJErrorCode(errcode)
  3655. return
  3656. }
  3657. service.CreateHisPrescriptionProjectTemplate(&p)
  3658. }
  3659. }
  3660. }
  3661. }
  3662. c.ServeSuccessJSON(map[string]interface{}{
  3663. "msg": "创建成功",
  3664. })
  3665. }
  3666. }
  3667. }