common_service.go 181KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  8. )
  9. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  10. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  11. return inspection, err
  12. }
  13. func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
  14. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
  15. return inspection, err
  16. }
  17. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  18. reference := models.XtInspectionReference{}
  19. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  20. return reference, err
  21. }
  22. func GetItemid(id int64) (models.XtInspectionReference, error) {
  23. reference := models.XtInspectionReference{}
  24. err = XTReadDB().Model(&reference).Where("id = ? and status = 1", id).Find(&reference).Error
  25. return reference, err
  26. }
  27. func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
  28. standard := models.XtQualityControlStandard{}
  29. err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
  30. if err == gorm.ErrRecordNotFound {
  31. return nil, err
  32. }
  33. if err != nil {
  34. return nil, err
  35. }
  36. return &standard, nil
  37. }
  38. func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
  39. err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
  40. return standard, err
  41. }
  42. func SaveInspection(standard *models.XtQualityControlStandard) error {
  43. err := XTWriteDB().Create(&standard).Error
  44. return err
  45. }
  46. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  47. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  48. if orgid > 0 {
  49. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  50. }
  51. table := XTReadDB().Table("xt_inspection_reference as s")
  52. fmt.Println(table)
  53. offset := (page - 1) * limit
  54. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").Count(&total).
  55. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  56. return standard, total, err
  57. }
  58. func GetDefaultBloodPressure(orgid int64) (standard []*models.XtQualityControlStandard, err error) {
  59. err = XTReadDB().Model(&standard).Where("user_org_id = ? and status = 1 and is_status = 0", orgid).Find(&standard).Error
  60. return standard, err
  61. }
  62. func GetConfigurationListTwo(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  63. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  64. if orgid > 0 {
  65. db = db.Where("x.user_org_id = ? and x.is_status =1", orgid)
  66. }
  67. table := XTReadDB().Table("xt_inspection_reference as s")
  68. fmt.Println(table)
  69. offset := (page - 1) * limit
  70. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").Count(&total).
  71. Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor and s.project_id = x.inspection_major").Where("s.org_id = ? and s.status = 1", orgid).Offset(offset).Limit(limit).Scan(&standard).Error
  72. return standard, total, err
  73. }
  74. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  75. standard := models.XtQualityControlStandard{}
  76. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  77. return standard, err
  78. }
  79. func GetIdByItemId(itemid int64, orgid int64) (models.XtInspectionReference, error) {
  80. reference := models.XtInspectionReference{}
  81. err := XTReadDB().Model(&reference).Where("item_id = ? and org_id = ?", itemid, orgid).Find(&reference).Error
  82. return reference, err
  83. }
  84. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  85. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  86. return standard, err
  87. }
  88. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  89. err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "range_value": st.RangeValue, "range_type": st.RangeType, "updated_time": time.Now().Unix()}).Error
  90. return err
  91. }
  92. func DeleteConfiguration(id int64) (err error) {
  93. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  94. return err
  95. }
  96. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  97. diseases := models.XtInspectionReference{}
  98. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  99. if err == gorm.ErrRecordNotFound {
  100. return nil, err
  101. }
  102. if err != nil {
  103. return nil, err
  104. }
  105. return &diseases, nil
  106. }
  107. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  108. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  109. return reference, err
  110. }
  111. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  112. configuration := models.XtCheckConfiguration{}
  113. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  114. if err == gorm.ErrRecordNotFound {
  115. return nil, err
  116. }
  117. if err != nil {
  118. return nil, err
  119. }
  120. return &configuration, nil
  121. }
  122. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  123. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  124. return configuration, err
  125. }
  126. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  127. err := XTWriteDB().Create(&configuration).Error
  128. return err
  129. }
  130. func GetAllChekcListTwo(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  131. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  132. table := XTReadDB().Table("xt_inspection_reference as r")
  133. fmt.Println(table)
  134. if orgid > 0 {
  135. db = db.Where("x.user_org_id = ?", orgid)
  136. }
  137. offset := (page - 1) * limit
  138. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  139. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  140. return check, total, err
  141. }
  142. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  143. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  144. table := XTReadDB().Table("xt_inspection_reference as r")
  145. fmt.Println(table)
  146. if orgid > 0 {
  147. db = db.Where("x.user_org_id = ?", orgid)
  148. }
  149. offset := (page - 1) * limit
  150. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  151. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Where("r.org_id = ? and r.status = 1", orgid).Offset(offset).Limit(limit).Scan(&check).Error
  152. return check, total, err
  153. }
  154. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  155. configuration := models.XtCheckConfiguration{}
  156. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  157. return configuration, err
  158. }
  159. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  160. err := XTWriteDB().Model(&con).Where("id=?", id).Updates(map[string]interface{}{"inspection_major": con.InspectionMajor, "inspection_frequency": con.InspectionFrequency, "sort": con.Sort, "updated_time": time.Now().Unix()}).Error
  161. return err
  162. }
  163. func DeleteCheck(id int64) error {
  164. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  165. return err
  166. }
  167. //
  168. //func GetDialysiTotal(startime int64, endtime int64, orgid int64,lapsetotype int64,sourcetype int64) (order []*models.DialysisOrder, total int64, err error) {
  169. // err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  170. // return order, total, err
  171. //}
  172. func GetDialysiTotal(startime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (models.PatientPrescriptionCountStruct, error) {
  173. counts := models.PatientPrescriptionCountStruct{}
  174. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  175. table := XTReadDB().Table("xt_paitents as s").Where("s.status = 1")
  176. fmt.Println(table)
  177. if lapsetotype > 0 {
  178. err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  179. }
  180. if lapsetotype == 0 {
  181. err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? ", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  182. }
  183. if sourcetype > 0 {
  184. err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  185. }
  186. if sourcetype == 0 {
  187. err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ?", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  188. }
  189. return counts, err
  190. }
  191. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  192. //err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
  193. //return counts, err
  194. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  195. table := readDb.Table("xt_schedule as s").Where("s.status = 1")
  196. fmt.Println(table)
  197. p := readDb.Table("xt_patients as p").Where("p.status = 1")
  198. fmt.Println(p)
  199. if starttime > 0 {
  200. db = db.Where("o.dialysis_date >=?", starttime)
  201. }
  202. if endtime > 0 {
  203. db = db.Where("o.dialysis_date<=?", endtime)
  204. }
  205. if orgid > 0 {
  206. db = db.Where("o.user_org_id = ?", orgid)
  207. }
  208. if lapsetotype > 0 {
  209. db = db.Where("p.lapseto = ?", lapsetotype)
  210. }
  211. if sourcetype > 0 {
  212. db = db.Where("p.source = ?", sourcetype)
  213. }
  214. err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id and s.schedule_date = o.dialysis_date and s.status= 1").Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
  215. return counts, err
  216. }
  217. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  218. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  219. table := readDb.Table("xt_dialysis_order as s")
  220. fmt.Println(table)
  221. err = db.Select("x.patient_id,x.lapseto_type").Joins("left join xt_dialysis_order as s on s.patient_id = x.patient_id").Where("x.lapseto_time >=? and x.lapseto_time <= ? and x.lapseto_type = 2 and s.user_org_id = ?", starttime, endtime, orgid).Group("x.patient_id").Count(&total).Scan(&counts).Error
  222. return counts, total, err
  223. }
  224. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  225. db := XTReadDB().Table("xt_patients as x")
  226. if sourcetype == 0 {
  227. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  228. }
  229. if sourcetype > 0 {
  230. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  231. }
  232. return patients, err
  233. }
  234. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  235. db := XTReadDB().Table("xt_patients as x")
  236. if sourcetype == 0 {
  237. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  238. }
  239. if sourcetype > 0 {
  240. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  241. }
  242. return patients, err
  243. }
  244. func GetPatientTotalCount(orgID int64, lapsetotype int64, sourcetype int64) (total int64) {
  245. db := readDb.Table("xt_patients as x")
  246. //if lapsetotype > 0 {
  247. // db = db.Where("x.lapseto = ?", lapsetotype)
  248. //}
  249. //if sourcetype > 0 {
  250. // db = db.Where("x.source = ?", sourcetype)
  251. //}
  252. db.Where("x.user_org_id=? and x.status=1", orgID).Count(&total)
  253. return
  254. }
  255. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  256. err = XTReadDB().Model(&dialysisorder).Group("patient_id").Where("user_org_id = ? and dialysis_date >= ? and dialysis_date <=? and status =1", orgid, starttime, endtime).Count(&total).Find(&dialysisorder).Error
  257. return dialysisorder, total, err
  258. }
  259. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  260. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  261. table := XTReadDB().Table("xt_patients as x")
  262. fmt.Println("table", table)
  263. err = db.Select("s.dialysis_date,s.prescription_id").Joins("left join xt_patients as x on x.id = s.patient_id").Where("s.dialysis_date>=? and s.dialysis_date<=? and s.user_org_id = ? and s.status = 1 and x.gender = 1", starttime, endtime, orgid).Group("s.patient_id").Count(&total).Scan(&dialysisorder).Error
  264. return dialysisorder, total, err
  265. }
  266. func GetManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  267. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  268. if lapsetotype > 0 {
  269. db = db.Where("x.lapseto = ?", lapsetotype)
  270. }
  271. if sourcetype > 0 {
  272. db = db.Where("x.source = ?", sourcetype)
  273. }
  274. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 1", orgid).Count(&total).Find(&patients).Error
  275. return patients, total, err
  276. }
  277. func GetWoManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  278. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  279. if lapsetotype > 0 {
  280. db = db.Where("x.lapseto = ?", lapsetotype)
  281. }
  282. if sourcetype > 0 {
  283. db = db.Where("x.source = ?", sourcetype)
  284. }
  285. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 2", orgid).Count(&total).Find(&patients).Error
  286. return patients, total, err
  287. }
  288. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  289. // err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_dialysis_order as o on o.patient_id = x.patient_id").Joins("join xt_patients as s on s.id = x.patient_id").Where("o.user_org_id = ? and o.status =1 and o.dialysis_date>=? and o.dialysis_date <=? and x.status =1 and s.is_infectious = 2", orgid, starttime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  290. // return counts, err
  291. //}
  292. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientContagionsCountStruct, err error) {
  293. if lapsetotype == 0 {
  294. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  295. }
  296. if sourcetype == 0 {
  297. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  298. }
  299. if lapsetotype > 0 {
  300. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.lapseto = ?", orgid, startime, endtime, lapsetotype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  301. }
  302. if sourcetype > 0 {
  303. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.source = ?", orgid, startime, endtime, sourcetype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  304. }
  305. return counts, err
  306. }
  307. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  308. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  309. return patients, total, err
  310. }
  311. func GetTotalAgeCount(orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientAgeCountStruct, err error) {
  312. if lapsetotype == 0 || sourcetype == 0 {
  313. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  314. SELECT
  315. CASE
  316. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  317. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  318. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  319. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  320. ELSE '150'
  321. END
  322. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  323. )a GROUP BY nnd`, orgid).Scan(&counts)
  324. }
  325. if lapsetotype > 0 {
  326. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  327. SELECT
  328. CASE
  329. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  330. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  331. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  332. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  333. ELSE '150'
  334. END
  335. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.lapseto = ?
  336. )a GROUP BY nnd`, orgid, lapsetotype).Scan(&counts)
  337. }
  338. if sourcetype > 0 {
  339. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  340. SELECT
  341. CASE
  342. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  343. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  344. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  345. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  346. ELSE '150'
  347. END
  348. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.source = ?
  349. )a GROUP BY nnd`, orgid, sourcetype).Scan(&counts)
  350. }
  351. return
  352. }
  353. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  354. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  355. SELECT
  356. CASE
  357. when (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')>0) and (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')<20) THEN '20'
  358. END
  359. AS nnd FROM xt_patients as s left join xt_dialysis_order as o on o.patient_id = s.id where s.user_org_id=? and s.status=1 and o.dialysis_date>= ? and o.dialysis_date<=?
  360. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  361. return
  362. }
  363. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  364. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  365. return patients, err
  366. }
  367. func GetDialysisAgeData(orgID int64, lapsetotype int64, sourcetype int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  368. if lapsetotype == 0 || sourcetype == 0 {
  369. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  370. SELECT
  371. CASE
  372. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  373. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  374. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  375. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  376. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0)a GROUP BY nnd`, orgID).Scan(&counts)
  377. }
  378. if lapsetotype > 0 {
  379. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  380. SELECT
  381. CASE
  382. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  383. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  384. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  385. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  386. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.lapseto = ?)a GROUP BY nnd`, orgID, lapsetotype).Scan(&counts)
  387. }
  388. if sourcetype > 0 {
  389. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  390. SELECT
  391. CASE
  392. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  393. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  394. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  395. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  396. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.source = ?)a GROUP BY nnd`, orgID, sourcetype).Scan(&counts)
  397. }
  398. return
  399. }
  400. func GetCurentOrgPatients(orgid int64) (patients []*models.BloodXtPatients, err error) {
  401. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  402. return patients, err
  403. }
  404. func TotalDialysisCount(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  405. db := XTReadDB().Table("xt_dialysis_order as o")
  406. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", startime, endtime, orgid).Group("o.patient_id").Scan(&order).Error
  407. return order, err
  408. }
  409. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  410. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  411. table := XTReadDB().Table("xt_schedule as s")
  412. fmt.Println(table)
  413. d := XTReadDB().Table("xt_patients as p")
  414. fmt.Println(d)
  415. if orgid > 0 {
  416. db = db.Where("o.user_org_id = ?", orgid)
  417. }
  418. if startime > 0 {
  419. db = db.Where("o.dialysis_date>=?", startime)
  420. }
  421. if endtime > 0 {
  422. db = db.Where("o.dialysis_date<=?", endtime)
  423. }
  424. offset := (page - 1) * limit
  425. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  426. return order, total, err
  427. }
  428. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrder, err error) {
  429. table := XTReadDB().Table("xt_schedule as s")
  430. fmt.Println(table)
  431. d := XTReadDB().Table("xt_patients as p")
  432. fmt.Println(d)
  433. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  434. if orgid > 0 {
  435. db = db.Where("o.user_org_id = ?", orgid)
  436. }
  437. if startime > 0 {
  438. db = db.Where("o.dialysis_date>=?", startime)
  439. }
  440. if endtime > 0 {
  441. db = db.Where("o.dialysis_date<=?", endtime)
  442. }
  443. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,s.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1 ").Scan(&order).Error
  444. return order, err
  445. }
  446. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  447. table := XTReadDB().Table("xt_schedule as s")
  448. fmt.Println(table)
  449. d := XTReadDB().Table("xt_patients as p")
  450. fmt.Println(d)
  451. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  452. if orgid > 0 {
  453. db = db.Where("o.user_org_id = ?", orgid)
  454. }
  455. if startime > 0 {
  456. db = db.Where("o.dialysis_date>=?", startime)
  457. }
  458. if endtime > 0 {
  459. db = db.Where("o.dialysis_date<=?", endtime)
  460. }
  461. offset := (page - 1) * limit
  462. err = db.Group("s.patient_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  463. return order, total, err
  464. }
  465. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  466. standard := models.XtQualityControlStandard{}
  467. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1 and is_status = 1", orgid).Last(&standard).Error
  468. return standard, err
  469. }
  470. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  471. configuration := models.XtCheckConfiguration{}
  472. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  473. return configuration, err
  474. }
  475. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  476. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  477. table := XTReadDB().Table("xt_patients as s")
  478. fmt.Println(table)
  479. if id > 0 {
  480. db = db.Where("p.patient_id = ?", id)
  481. }
  482. if orgid > 0 {
  483. db = db.Where("p.user_org_id = ?", orgid)
  484. }
  485. if startime > 0 {
  486. db = db.Where("p.record_date >= ?", startime)
  487. }
  488. if endtime > 0 {
  489. db = db.Where("p.record_date <=?", endtime)
  490. }
  491. offset := (page - 1) * limit
  492. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  493. return prescription, total, err
  494. }
  495. func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  496. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  497. table := XTReadDB().Table("xt_patients as s")
  498. fmt.Println(table)
  499. //if len(keywords) > 0 {
  500. // likeKey := "%" + keywords + "%"
  501. // db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  502. //}
  503. if patient_id > 0 {
  504. db = db.Where("s.id = ?", patient_id)
  505. }
  506. if orgid > 0 {
  507. db = db.Where("p.user_org_id = ?", orgid)
  508. }
  509. if startime > 0 {
  510. db = db.Where("p.record_date >= ?", startime)
  511. }
  512. if endtime > 0 {
  513. db = db.Where("p.record_date <=?", endtime)
  514. }
  515. offset := (page - 1) * limit
  516. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  517. return prescription, total, err
  518. }
  519. func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
  520. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  521. table := XTReadDB().Table("xt_schedule as s")
  522. fmt.Println(table)
  523. p := XTReadDB().Table("xt_patients as p")
  524. fmt.Println(p)
  525. sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
  526. if orgID > 0 {
  527. db = db.Where("o.user_org_id = ?", orgID)
  528. }
  529. if startime > 0 {
  530. db = db.Where("o.dialysis_date >=?", startime)
  531. }
  532. if endtime > 0 {
  533. db = db.Where("o.dialysis_date<=?", endtime)
  534. }
  535. if lapseto == 0 {
  536. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  537. }
  538. if lapseto > 0 {
  539. db = db.Where("p.lapseto = ?", lapseto)
  540. }
  541. offset := (page - 1) * limit
  542. err = db.Group("o.dialysis_date").Select(sql).Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1").Count(&total).Offset(offset).Limit(limit).Scan(&blood).Error
  543. return blood, total, err
  544. }
  545. func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (ttd []*models.TreatTotalStruct, err error) {
  546. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  547. table := XTReadDB().Table("xt_schedule as s")
  548. fmt.Println(table)
  549. p := XTReadDB().Table("xt_patients as p")
  550. fmt.Println(p)
  551. if orgid > 0 {
  552. db = db.Where("o.user_org_id = ?", orgid)
  553. }
  554. if startime > 0 {
  555. db = db.Where("o.dialysis_date>=?", startime)
  556. }
  557. if endtime > 0 {
  558. db = db.Where("o.dialysis_date<=?", endtime)
  559. }
  560. if lapseto == 0 {
  561. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  562. }
  563. if lapseto > 0 {
  564. db = db.Where("p.lapseto = ?", lapseto)
  565. }
  566. err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  567. return ttd, err
  568. }
  569. func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, err error) {
  570. db := readDb
  571. sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
  572. datesql := " o.dialysis_date as date"
  573. group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
  574. db = db.Table(" xt_dialysis_order AS o").Joins("left join xt_schedule as s on o.patient_id = s.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1")
  575. if orgID > 0 {
  576. db = db.Where("o.user_org_id = ?", orgID)
  577. }
  578. if modeID > 0 {
  579. db = db.Where("s.mode_id=?", modeID)
  580. }
  581. if startime > 0 {
  582. db = db.Where("o.dialysis_date>=?", startime)
  583. }
  584. if endtime > 0 {
  585. db = db.Where("o.dialysis_date<=?", endtime)
  586. }
  587. db = db.Where("o.status=1")
  588. err = db.Select("s.mode_id, count(s.mode_id) as number").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  589. if err != nil {
  590. return
  591. }
  592. var ds []*DialysisTotalDataStruct
  593. err = db.Select(datesql).Group(group).Find(&ds).Error
  594. if err != nil {
  595. return
  596. }
  597. dates := make([]string, 0)
  598. if len(ds) > 0 {
  599. for _, d := range ds {
  600. dates = append(dates, d.Date)
  601. }
  602. db = db.Where("o.dialysis_date IN (?)", dates)
  603. }
  604. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, s.mode_id").Find(&dtd).Error
  605. return
  606. }
  607. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  608. var count int
  609. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  610. table := XTReadDB().Table("xt_inspection_reference as s")
  611. if orgid > 0 {
  612. db = db.Where("x.user_org_id = ?", orgid)
  613. }
  614. fmt.Println(table)
  615. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,s.project_name").Joins("left join xt_inspection_reference as s on s.project_id = x.inspection_major").Count(&count).Order("x.sort asc").Scan(&configuration).Error
  616. return configuration, err
  617. }
  618. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64, patientid int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  619. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  620. table := XTReadDB().Table("xt_inspection_reference as r")
  621. fmt.Println(table)
  622. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  623. fmt.Println(d)
  624. if orgid > 0 {
  625. db = db.Where("x.org_id = ?", orgid)
  626. }
  627. if startime > 0 {
  628. db = db.Where("x.inspect_date >=?", startime)
  629. }
  630. if endtime > 0 {
  631. db = db.Where("x.inspect_date <=?", endtime)
  632. }
  633. if patientid > 0 {
  634. db = db.Where("x.patient_id = ?", patientid)
  635. }
  636. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  637. return
  638. }
  639. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  640. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  641. table := XTReadDB().Table("xt_inspection_reference as r")
  642. fmt.Println(table)
  643. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  644. fmt.Println(d)
  645. if id > 0 {
  646. db = db.Where("x.patient_id=?", id)
  647. }
  648. if orgid > 0 {
  649. db = db.Where("x.org_id = ?", orgid)
  650. }
  651. if startime > 0 {
  652. db = db.Where("x.inspect_date >=?", startime)
  653. }
  654. if endtime > 0 {
  655. db = db.Where("x.inspect_date <=?", endtime)
  656. }
  657. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  658. return
  659. }
  660. func GetSearchPatientInfo(orgid int64, keywords int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  661. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  662. table := XTReadDB().Table("xt_inspection_reference as r")
  663. fmt.Println(table)
  664. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  665. fmt.Println(d)
  666. p := XTReadDB().Table("xt_patients as p")
  667. fmt.Println(p)
  668. //if len(keywords) > 0 {
  669. // likeKey := "%" + keywords + "%"
  670. // db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  671. //}
  672. if keywords > 0 {
  673. db = db.Where("x.patient_id = ?", keywords)
  674. }
  675. if orgid > 0 {
  676. db = db.Where("x.org_id = ?", orgid)
  677. }
  678. if startime > 0 {
  679. db = db.Where("x.inspect_date >=?", startime)
  680. }
  681. if endtime > 0 {
  682. db = db.Where("x.inspect_date <=?", endtime)
  683. }
  684. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as p on p.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  685. return
  686. }
  687. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  688. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  689. table := XTReadDB().Table("xt_inspection_reference ar r")
  690. fmt.Println(table)
  691. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  692. return checkconfiguration, err
  693. }
  694. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  695. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  696. table := XTReadDB().Table("xt_inspection_reference ar r")
  697. fmt.Println(table)
  698. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  699. return checkconfiguration, err
  700. }
  701. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  702. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  703. table := XTReadDB().Table("xt_patients as s")
  704. fmt.Println("table", table)
  705. if orgid > 0 {
  706. db = db.Where("x.org_id = ?", orgid)
  707. }
  708. if startime > 0 {
  709. db = db.Where("x.inspect_date >= ?", startime)
  710. }
  711. if endtime > 0 {
  712. db = db.Where("x.inspect_date <=?", endtime)
  713. }
  714. offset := (page - 1) * limit
  715. err = db.Group("x.patient_id").Select("x.id,x.patient_id,x.project_id,x.project_name,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  716. return inspection, total, err
  717. }
  718. func GetPatientListInfo(orgid int64, startime int64, endtime int64, limit int64, page int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  719. patients, _, err := GetPatientListData(orgid, startime, endtime, limit, page)
  720. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  721. table := XTReadDB().Table("xt_inspection_reference as r")
  722. fmt.Println(table)
  723. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  724. pa := XTReadDB().Table("xt_patients as s")
  725. fmt.Println(pa)
  726. fmt.Println(d)
  727. if orgid > 0 {
  728. db = db.Where("x.org_id = ?", orgid)
  729. }
  730. if startime > 0 {
  731. db = db.Where("x.inspect_date >=?", startime)
  732. }
  733. if endtime > 0 {
  734. db = db.Where("x.inspect_date <=?", endtime)
  735. }
  736. //if len(ds) > 0 {
  737. // for _, d := range ds {
  738. // dates = append(dates, d.Date)
  739. // }
  740. //
  741. // db = db.Where("o.dialysis_date IN (?)", dates)
  742. //
  743. ////}
  744. selectContent := "CASE"
  745. dates := make([]string, 0)
  746. for _, item := range patients {
  747. selectContent = selectContent + " WHEN x.patient_id =" + strconv.FormatInt(item.PatientId, 10) + " THEN " + "'" + item.Name + "'"
  748. dates = append(dates, strconv.FormatInt(item.PatientId, 10))
  749. }
  750. db = db.Where("x.patient_id in(?)", dates)
  751. err = db.Select(selectContent + "ELSE '未知' END AS name,count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  752. //err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  753. return
  754. }
  755. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  756. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  757. table := XTReadDB().Table("xt_inspection_reference as r")
  758. fmt.Println(table)
  759. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  760. pa := XTReadDB().Table("xt_patients as s")
  761. fmt.Println(pa)
  762. fmt.Println(d)
  763. if id > 0 {
  764. db = db.Where("s.id = ?", id)
  765. }
  766. if orgid > 0 {
  767. db = db.Where("x.org_id = ?", orgid)
  768. }
  769. if startime > 0 {
  770. db = db.Where("x.inspect_date >=?", startime)
  771. }
  772. if endtime > 0 {
  773. db = db.Where("x.inspect_date <=?", endtime)
  774. }
  775. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  776. return
  777. }
  778. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  779. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  780. table := XTReadDB().Table("xt_inspection_reference as r")
  781. fmt.Println(table)
  782. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  783. pa := XTReadDB().Table("xt_patients as s")
  784. fmt.Println(pa)
  785. fmt.Println(d)
  786. if len(keywords) > 0 {
  787. likeKey := "%" + keywords + "%"
  788. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  789. }
  790. if orgid > 0 {
  791. db = db.Where("x.org_id = ?", orgid)
  792. }
  793. if startime > 0 {
  794. db = db.Where("x.inspect_date >=?", startime)
  795. }
  796. if endtime > 0 {
  797. db = db.Where("x.inspect_date <=?", endtime)
  798. }
  799. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  800. return
  801. }
  802. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  803. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  804. if orgid > 0 {
  805. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  806. }
  807. table := XTReadDB().Table("xt_inspection_reference as s")
  808. fmt.Println(table)
  809. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name,x.range_value,x.range_type,x.is_status").
  810. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  811. return standard, err
  812. }
  813. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  814. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  815. if orgid >= 0 {
  816. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  817. }
  818. table := XTReadDB().Table("xt_inspection_reference as s")
  819. fmt.Println(table)
  820. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
  821. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  822. return standard, err
  823. }
  824. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  825. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  826. table := XTReadDB().Table("xt_inspection_reference as r")
  827. fmt.Println(table)
  828. if orgid > 0 {
  829. db = db.Where("x.org_id = ?", orgid)
  830. }
  831. if startime > 0 {
  832. db = db.Where("x.inspect_date >=?", startime)
  833. }
  834. if endtime > 0 {
  835. db = db.Where("x.inspect_date <=?", endtime)
  836. }
  837. err = db.Group("x.item_id").Select(" count(x.item_id ) AS count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  838. return inspection, err
  839. }
  840. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  841. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  842. table := XTReadDB().Table("xt_inspection_reference as r")
  843. fmt.Println(table)
  844. if orgid > 0 {
  845. db = db.Where("x.org_id = ?", orgid)
  846. }
  847. if startime > 0 {
  848. db = db.Where("x.inspect_date >=?", startime)
  849. }
  850. if endtime > 0 {
  851. db = db.Where("x.inspect_date <=?", endtime)
  852. }
  853. err = db.Group("x.item_id").Select("count(x.item_id) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Where("x.inspect_value+0 >= r.range_min+0 and x.inspect_value+0 <= r.range_max+0").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  854. return inspection, err
  855. }
  856. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  857. fmt.Println(lapseto)
  858. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  859. table := XTReadDB().Table("xt_inspection_reference as r")
  860. fmt.Println(table)
  861. //d := XTReadDB().Table("xt_patients as s")
  862. //fmt.Println(d)
  863. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  864. fmt.Println(q)
  865. if orgid > 0 {
  866. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and r.range_type = 1 and q.user_org_id = ? and q.is_status = 1", orgid, orgid)
  867. }
  868. if startime > 0 {
  869. db = db.Where("x.inspect_date >=?", startime)
  870. }
  871. if endtime > 0 {
  872. db = db.Where("x.inspect_date <=?", endtime)
  873. }
  874. //if lapseto == 0 {
  875. // db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  876. //}
  877. //if lapseto > 0 {
  878. // db = db.Where("s.lapseto = ?", lapseto)
  879. //}
  880. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=q.min_range+0 and x.inspect_value +0 <= q.large_range+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  881. return inspection, err
  882. }
  883. func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  884. fmt.Println(lapseto)
  885. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  886. table := XTReadDB().Table("xt_inspection_reference as r")
  887. fmt.Println(table)
  888. //d := XTReadDB().Table("xt_patients as s")
  889. //fmt.Println(d)
  890. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  891. fmt.Println(q)
  892. if orgid > 0 {
  893. db = db.Where("x.org_id = ? and r.range_type = 2 and q.user_org_id = ? and q.is_status = 1 and x.inspect_value <>''", orgid, orgid)
  894. }
  895. if startime > 0 {
  896. db = db.Where("x.inspect_date >=?", startime)
  897. }
  898. if endtime > 0 {
  899. db = db.Where("x.inspect_date <=?", endtime)
  900. }
  901. //if lapseto == 0 {
  902. // db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  903. //}
  904. //if lapseto > 0 {
  905. // db = db.Where("s.lapseto = ?", lapseto)
  906. //}
  907. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when q.range_value = x.inspect_value and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  908. return inspection, err
  909. }
  910. func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  911. if lapseto == 0 {
  912. d := XTReadDB().Table("xt_patients as s")
  913. fmt.Println("d", d)
  914. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  915. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  916. "SELECT " +
  917. "CASE " +
  918. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  919. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  920. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  921. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  922. " ELSE '其他'" +
  923. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and x.inspect_value <> 0"
  924. countParams := make([]interface{}, 0)
  925. countParams = append(countParams, firststart)
  926. countParams = append(countParams, firstend)
  927. countParams = append(countParams, sencondstart)
  928. countParams = append(countParams, sencondend)
  929. countParams = append(countParams, threestart)
  930. countParams = append(countParams, threeend)
  931. countParams = append(countParams, fourstart)
  932. countParams = append(countParams, fourend)
  933. if orgid > 0 {
  934. db = db.Where("x.org_id=?", orgid)
  935. countSQL += " AND x.org_id=?"
  936. countParams = append(countParams, orgid)
  937. }
  938. if modetype > 0 {
  939. db = db.Where("x.item_id = ?", modetype)
  940. countSQL += " AND x.item_id=?"
  941. countParams = append(countParams, modetype)
  942. }
  943. if startime > 0 {
  944. db = db.Where("x.inspect_date >= ?", startime)
  945. countSQL += " AND x.inspect_date >=?"
  946. countParams = append(countParams, startime)
  947. }
  948. if endtime > 0 {
  949. db = db.Where("x.inspect_date <= ?", endtime)
  950. countSQL += " AND x.inspect_date <=?"
  951. countParams = append(countParams, endtime)
  952. }
  953. countSQL += ")a GROUP BY nnd"
  954. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  955. }
  956. if lapseto == 1 {
  957. d := XTReadDB().Table("xt_patients as s")
  958. fmt.Println("d", d)
  959. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  960. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  961. "SELECT " +
  962. "CASE " +
  963. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  964. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  965. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  966. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  967. "ELSE '其他'" +
  968. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  969. countParams := make([]interface{}, 0)
  970. countParams = append(countParams, firststart)
  971. countParams = append(countParams, firstend)
  972. countParams = append(countParams, sencondstart)
  973. countParams = append(countParams, sencondend)
  974. countParams = append(countParams, threestart)
  975. countParams = append(countParams, threeend)
  976. countParams = append(countParams, fourstart)
  977. countParams = append(countParams, fourend)
  978. if orgid > 0 {
  979. db = db.Where("x.org_id=?", orgid)
  980. countSQL += " AND x.org_id=?"
  981. countParams = append(countParams, orgid)
  982. }
  983. if modetype > 0 {
  984. db = db.Where("x.item_id = ?", modetype)
  985. countSQL += " AND x.item_id=?"
  986. countParams = append(countParams, modetype)
  987. }
  988. if startime > 0 {
  989. db = db.Where("x.inspect_date >= ?", startime)
  990. countSQL += " AND x.inspect_date >=?"
  991. countParams = append(countParams, startime)
  992. }
  993. if endtime > 0 {
  994. db = db.Where("x.inspect_date <= ?", endtime)
  995. countSQL += " AND x.inspect_date <=?"
  996. countParams = append(countParams, endtime)
  997. }
  998. countSQL += ")a GROUP BY nnd"
  999. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1000. }
  1001. if lapseto == 2 {
  1002. d := XTReadDB().Table("xt_patients as s")
  1003. fmt.Println("d", d)
  1004. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1005. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1006. "SELECT " +
  1007. "CASE " +
  1008. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1009. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1010. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1011. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1012. " ELSE '其他'" +
  1013. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1014. countParams := make([]interface{}, 0)
  1015. countParams = append(countParams, firststart)
  1016. countParams = append(countParams, firstend)
  1017. countParams = append(countParams, sencondstart)
  1018. countParams = append(countParams, sencondend)
  1019. countParams = append(countParams, threestart)
  1020. countParams = append(countParams, threeend)
  1021. countParams = append(countParams, fourstart)
  1022. countParams = append(countParams, fourend)
  1023. if orgid > 0 {
  1024. db = db.Where("x.org_id=?", orgid)
  1025. countSQL += " AND x.org_id=?"
  1026. countParams = append(countParams, orgid)
  1027. }
  1028. if modetype > 0 {
  1029. db = db.Where("x.item_id = ?", modetype)
  1030. countSQL += " AND x.item_id=?"
  1031. countParams = append(countParams, modetype)
  1032. }
  1033. if startime > 0 {
  1034. db = db.Where("x.inspect_date >= ?", startime)
  1035. countSQL += " AND x.inspect_date >=?"
  1036. countParams = append(countParams, startime)
  1037. }
  1038. if endtime > 0 {
  1039. db = db.Where("x.inspect_date <= ?", endtime)
  1040. countSQL += " AND x.inspect_date <=?"
  1041. countParams = append(countParams, endtime)
  1042. }
  1043. countSQL += ")a GROUP BY nnd"
  1044. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1045. }
  1046. return
  1047. }
  1048. func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1049. if lapseto == 0 {
  1050. d := XTReadDB().Table("xt_patients as s")
  1051. fmt.Println("d", d)
  1052. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1053. table := XTReadDB().Table("xt_inspection_reference as r")
  1054. q := XTReadDB().Table("xt_quality_control_standard as r")
  1055. fmt.Println("q", q)
  1056. fmt.Println(table)
  1057. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1058. "SELECT " +
  1059. "CASE " +
  1060. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1061. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1062. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1063. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1064. " ELSE '其他'" +
  1065. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1066. countParams := make([]interface{}, 0)
  1067. countParams = append(countParams, firststart)
  1068. countParams = append(countParams, firstend)
  1069. countParams = append(countParams, sencondstart)
  1070. countParams = append(countParams, sencondend)
  1071. countParams = append(countParams, threestart)
  1072. countParams = append(countParams, threeend)
  1073. countParams = append(countParams, fourstart)
  1074. countParams = append(countParams, fourend)
  1075. if orgid > 0 {
  1076. db = db.Where("x.org_id=?", orgid)
  1077. countSQL += " AND x.org_id=?"
  1078. countParams = append(countParams, orgid)
  1079. }
  1080. if orgid > 0 {
  1081. db = db.Where("r.user_org_id=?", orgid)
  1082. countSQL += " AND r.user_org_id=?"
  1083. countParams = append(countParams, orgid)
  1084. }
  1085. if modetype > 0 {
  1086. db = db.Where("x.item_id = ?", modetype)
  1087. countSQL += " AND x.item_id=?"
  1088. countParams = append(countParams, modetype)
  1089. }
  1090. if startime > 0 {
  1091. db = db.Where("x.inspect_date >= ? ", startime)
  1092. countSQL += " AND x.inspect_date >=?"
  1093. countParams = append(countParams, startime)
  1094. }
  1095. if endtime > 0 {
  1096. db = db.Where("x.inspect_date <= ?", endtime)
  1097. countSQL += " AND x.inspect_date <=?"
  1098. countParams = append(countParams, endtime)
  1099. }
  1100. countSQL += ")a GROUP BY nnd"
  1101. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1102. }
  1103. if lapseto == 1 {
  1104. d := XTReadDB().Table("xt_patients as s")
  1105. fmt.Println("d", d)
  1106. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1107. table := XTReadDB().Table("xt_inspection_reference as r")
  1108. q := XTReadDB().Table("xt_quality_control_standard as r")
  1109. fmt.Println("q", q)
  1110. fmt.Println(table)
  1111. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1112. "SELECT " +
  1113. "CASE " +
  1114. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1115. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1116. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1117. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1118. " ELSE '其他'" +
  1119. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1120. countParams := make([]interface{}, 0)
  1121. countParams = append(countParams, firststart)
  1122. countParams = append(countParams, firstend)
  1123. countParams = append(countParams, sencondstart)
  1124. countParams = append(countParams, sencondend)
  1125. countParams = append(countParams, threestart)
  1126. countParams = append(countParams, threeend)
  1127. countParams = append(countParams, fourstart)
  1128. countParams = append(countParams, fourend)
  1129. if orgid > 0 {
  1130. db = db.Where("x.org_id=?", orgid)
  1131. countSQL += " AND x.org_id=?"
  1132. countParams = append(countParams, orgid)
  1133. }
  1134. if orgid > 0 {
  1135. db = db.Where("r.user_org_id=?", orgid)
  1136. countSQL += " AND r.user_org_id=?"
  1137. countParams = append(countParams, orgid)
  1138. }
  1139. if modetype > 0 {
  1140. db = db.Where("x.item_id = ?", modetype)
  1141. countSQL += " AND x.item_id=?"
  1142. countParams = append(countParams, modetype)
  1143. }
  1144. if startime > 0 {
  1145. db = db.Where("x.inspect_date >= ? ", startime)
  1146. countSQL += " AND x.inspect_date >=?"
  1147. countParams = append(countParams, startime)
  1148. }
  1149. if endtime > 0 {
  1150. db = db.Where("x.inspect_date <= ?", endtime)
  1151. countSQL += " AND x.inspect_date <=?"
  1152. countParams = append(countParams, endtime)
  1153. }
  1154. countSQL += ")a GROUP BY nnd"
  1155. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1156. }
  1157. return
  1158. }
  1159. func GetProjectStandListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1160. if lapseto == 0 {
  1161. d := XTReadDB().Table("xt_patients as s")
  1162. fmt.Println("d", d)
  1163. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1164. table := XTReadDB().Table("xt_inspection_reference as r")
  1165. q := XTReadDB().Table("xt_quality_control_standard as r")
  1166. fmt.Println("q", q)
  1167. fmt.Println(table)
  1168. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1169. "SELECT " +
  1170. "CASE " +
  1171. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1172. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1173. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1174. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1175. " ELSE '其他'" +
  1176. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1177. countParams := make([]interface{}, 0)
  1178. countParams = append(countParams, firststart)
  1179. countParams = append(countParams, firstend)
  1180. countParams = append(countParams, sencondstart)
  1181. countParams = append(countParams, sencondend)
  1182. countParams = append(countParams, threestart)
  1183. countParams = append(countParams, threeend)
  1184. countParams = append(countParams, fourstart)
  1185. countParams = append(countParams, fourend)
  1186. if orgid > 0 {
  1187. db = db.Where("x.org_id=?", orgid)
  1188. countSQL += " AND x.org_id=?"
  1189. countParams = append(countParams, orgid)
  1190. }
  1191. if orgid > 0 {
  1192. db = db.Where("r.user_org_id=?", orgid)
  1193. countSQL += " AND r.user_org_id=?"
  1194. countParams = append(countParams, orgid)
  1195. }
  1196. if modetype > 0 {
  1197. db = db.Where("x.item_id = ?", modetype)
  1198. countSQL += " AND x.item_id=?"
  1199. countParams = append(countParams, modetype)
  1200. }
  1201. if startime > 0 {
  1202. db = db.Where("x.inspect_date >= ? ", startime)
  1203. countSQL += " AND x.inspect_date >=?"
  1204. countParams = append(countParams, startime)
  1205. }
  1206. if endtime > 0 {
  1207. db = db.Where("x.inspect_date <= ?", endtime)
  1208. countSQL += " AND x.inspect_date <=?"
  1209. countParams = append(countParams, endtime)
  1210. }
  1211. countSQL += ")a GROUP BY nnd"
  1212. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1213. }
  1214. if lapseto == 1 {
  1215. d := XTReadDB().Table("xt_patients as s")
  1216. fmt.Println("d", d)
  1217. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1218. table := XTReadDB().Table("xt_inspection_reference as r")
  1219. q := XTReadDB().Table("xt_quality_control_standard as r")
  1220. fmt.Println("q", q)
  1221. fmt.Println(table)
  1222. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1223. "SELECT " +
  1224. "CASE " +
  1225. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1226. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1227. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1228. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1229. " ELSE '其他'" +
  1230. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1231. countParams := make([]interface{}, 0)
  1232. countParams = append(countParams, firststart)
  1233. countParams = append(countParams, firstend)
  1234. countParams = append(countParams, sencondstart)
  1235. countParams = append(countParams, sencondend)
  1236. countParams = append(countParams, threestart)
  1237. countParams = append(countParams, threeend)
  1238. countParams = append(countParams, fourstart)
  1239. countParams = append(countParams, fourend)
  1240. if orgid > 0 {
  1241. db = db.Where("x.org_id=?", orgid)
  1242. countSQL += " AND x.org_id=?"
  1243. countParams = append(countParams, orgid)
  1244. }
  1245. if orgid > 0 {
  1246. db = db.Where("r.user_org_id=?", orgid)
  1247. countSQL += " AND r.user_org_id=?"
  1248. countParams = append(countParams, orgid)
  1249. }
  1250. if modetype > 0 {
  1251. db = db.Where("x.item_id = ?", modetype)
  1252. countSQL += " AND x.item_id=?"
  1253. countParams = append(countParams, modetype)
  1254. }
  1255. if startime > 0 {
  1256. db = db.Where("x.inspect_date >= ? ", startime)
  1257. countSQL += " AND x.inspect_date >=?"
  1258. countParams = append(countParams, startime)
  1259. }
  1260. if endtime > 0 {
  1261. db = db.Where("x.inspect_date <= ?", endtime)
  1262. countSQL += " AND x.inspect_date <=?"
  1263. countParams = append(countParams, endtime)
  1264. }
  1265. countSQL += ")a GROUP BY nnd"
  1266. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1267. }
  1268. return
  1269. }
  1270. func GetMonthProjectList(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1271. if lapseto == 0 {
  1272. d := XTReadDB().Table("xt_patients as s")
  1273. fmt.Println("d", d)
  1274. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1")
  1275. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1276. "SELECT " +
  1277. "CASE " +
  1278. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1279. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1280. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1281. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1282. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1283. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1284. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1285. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1286. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1287. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1288. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1289. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1290. " ELSE '其他'" +
  1291. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1292. countParams := make([]interface{}, 0)
  1293. countParams = append(countParams, januaryStartStrUnix)
  1294. countParams = append(countParams, januaryEndStrUnix)
  1295. countParams = append(countParams, febStartStrStrUnix)
  1296. countParams = append(countParams, febEndStrUnix)
  1297. countParams = append(countParams, marchStartStrUnix)
  1298. countParams = append(countParams, marchEndStrUnix)
  1299. countParams = append(countParams, aprStartStrUnix)
  1300. countParams = append(countParams, aprEndStrsUnix)
  1301. countParams = append(countParams, mayStartStrUnix)
  1302. countParams = append(countParams, mayEndStrsUnix)
  1303. countParams = append(countParams, junStartStrUnix)
  1304. countParams = append(countParams, junEndStrsUnix)
  1305. countParams = append(countParams, julStartStrUnix)
  1306. countParams = append(countParams, julEndStrsUnix)
  1307. countParams = append(countParams, augStartStrUnix)
  1308. countParams = append(countParams, augEndStrsUnix)
  1309. countParams = append(countParams, sepStartStrUnix)
  1310. countParams = append(countParams, sepEndStrsUnix)
  1311. countParams = append(countParams, octStartStrUnix)
  1312. countParams = append(countParams, octEndStrsUnix)
  1313. countParams = append(countParams, novStartStrUnix)
  1314. countParams = append(countParams, novEndStrsUnix)
  1315. countParams = append(countParams, decStartStrUnix)
  1316. countParams = append(countParams, decEndStrsUnix)
  1317. if orgid > 0 {
  1318. db = db.Where("x.org_id=?", orgid)
  1319. countSQL += " AND x.org_id=?"
  1320. countParams = append(countParams, orgid)
  1321. }
  1322. if modetype > 0 {
  1323. db = db.Where("x.item_id = ?", modetype)
  1324. countSQL += " AND x.item_id=?"
  1325. countParams = append(countParams, modetype)
  1326. }
  1327. if januaryStartStrUnix > 0 {
  1328. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1329. countSQL += " AND x.inspect_date >=?"
  1330. countParams = append(countParams, januaryStartStrUnix)
  1331. }
  1332. if decEndStrsUnix > 0 {
  1333. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1334. countSQL += " AND x.inspect_date <=?"
  1335. countParams = append(countParams, decEndStrsUnix)
  1336. }
  1337. countSQL += ")a GROUP BY nnd"
  1338. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1339. }
  1340. if lapseto == 1 {
  1341. d := XTReadDB().Table("xt_patients as s")
  1342. fmt.Println("d", d)
  1343. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1 ")
  1344. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1345. "SELECT " +
  1346. "CASE " +
  1347. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1348. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1349. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1350. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1351. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1352. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1353. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1354. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1355. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1356. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1357. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1358. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1359. " ELSE '其他'" +
  1360. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1361. countParams := make([]interface{}, 0)
  1362. countParams = append(countParams, januaryStartStrUnix)
  1363. countParams = append(countParams, januaryEndStrUnix)
  1364. countParams = append(countParams, febStartStrStrUnix)
  1365. countParams = append(countParams, febEndStrUnix)
  1366. countParams = append(countParams, marchStartStrUnix)
  1367. countParams = append(countParams, marchEndStrUnix)
  1368. countParams = append(countParams, aprStartStrUnix)
  1369. countParams = append(countParams, aprEndStrsUnix)
  1370. countParams = append(countParams, mayStartStrUnix)
  1371. countParams = append(countParams, mayEndStrsUnix)
  1372. countParams = append(countParams, junStartStrUnix)
  1373. countParams = append(countParams, junEndStrsUnix)
  1374. countParams = append(countParams, julStartStrUnix)
  1375. countParams = append(countParams, julEndStrsUnix)
  1376. countParams = append(countParams, augStartStrUnix)
  1377. countParams = append(countParams, augEndStrsUnix)
  1378. countParams = append(countParams, sepStartStrUnix)
  1379. countParams = append(countParams, sepEndStrsUnix)
  1380. countParams = append(countParams, octStartStrUnix)
  1381. countParams = append(countParams, octEndStrsUnix)
  1382. countParams = append(countParams, novStartStrUnix)
  1383. countParams = append(countParams, novEndStrsUnix)
  1384. countParams = append(countParams, decStartStrUnix)
  1385. countParams = append(countParams, decEndStrsUnix)
  1386. if orgid > 0 {
  1387. db = db.Where("x.org_id=?", orgid)
  1388. countSQL += " AND x.org_id=?"
  1389. countParams = append(countParams, orgid)
  1390. }
  1391. if modetype > 0 {
  1392. db = db.Where("x.item_id = ?", modetype)
  1393. countSQL += " AND x.item_id=?"
  1394. countParams = append(countParams, modetype)
  1395. }
  1396. if januaryStartStrUnix > 0 {
  1397. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1398. countSQL += " AND x.inspect_date >=?"
  1399. countParams = append(countParams, januaryStartStrUnix)
  1400. }
  1401. if decEndStrsUnix > 0 {
  1402. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1403. countSQL += " AND x.inspect_date <=?"
  1404. countParams = append(countParams, decEndStrsUnix)
  1405. }
  1406. countSQL += ")a GROUP BY nnd"
  1407. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1408. }
  1409. if lapseto == 2 {
  1410. d := XTReadDB().Table("xt_patients as s")
  1411. fmt.Println("d", d)
  1412. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_value <> 0 and x.inspect_type = 1")
  1413. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1414. "SELECT " +
  1415. "CASE " +
  1416. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1417. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1418. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1419. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1420. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1421. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1422. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1423. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1424. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1425. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1426. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1427. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1428. " ELSE '其他'" +
  1429. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1430. countParams := make([]interface{}, 0)
  1431. countParams = append(countParams, januaryStartStrUnix)
  1432. countParams = append(countParams, januaryEndStrUnix)
  1433. countParams = append(countParams, febStartStrStrUnix)
  1434. countParams = append(countParams, febEndStrUnix)
  1435. countParams = append(countParams, marchStartStrUnix)
  1436. countParams = append(countParams, marchEndStrUnix)
  1437. countParams = append(countParams, aprStartStrUnix)
  1438. countParams = append(countParams, aprEndStrsUnix)
  1439. countParams = append(countParams, mayStartStrUnix)
  1440. countParams = append(countParams, mayEndStrsUnix)
  1441. countParams = append(countParams, junStartStrUnix)
  1442. countParams = append(countParams, junEndStrsUnix)
  1443. countParams = append(countParams, julStartStrUnix)
  1444. countParams = append(countParams, julEndStrsUnix)
  1445. countParams = append(countParams, augStartStrUnix)
  1446. countParams = append(countParams, augEndStrsUnix)
  1447. countParams = append(countParams, sepStartStrUnix)
  1448. countParams = append(countParams, sepEndStrsUnix)
  1449. countParams = append(countParams, octStartStrUnix)
  1450. countParams = append(countParams, octEndStrsUnix)
  1451. countParams = append(countParams, novStartStrUnix)
  1452. countParams = append(countParams, novEndStrsUnix)
  1453. countParams = append(countParams, decStartStrUnix)
  1454. countParams = append(countParams, decEndStrsUnix)
  1455. if orgid > 0 {
  1456. db = db.Where("x.org_id=?", orgid)
  1457. countSQL += " AND x.org_id=?"
  1458. countParams = append(countParams, orgid)
  1459. }
  1460. if modetype > 0 {
  1461. db = db.Where("x.item_id = ?", modetype)
  1462. countSQL += " AND x.item_id=?"
  1463. countParams = append(countParams, modetype)
  1464. }
  1465. if januaryStartStrUnix > 0 {
  1466. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1467. countSQL += " AND x.inspect_date >=?"
  1468. countParams = append(countParams, januaryStartStrUnix)
  1469. }
  1470. if decEndStrsUnix > 0 {
  1471. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1472. countSQL += " AND x.inspect_date <=?"
  1473. countParams = append(countParams, decEndStrsUnix)
  1474. }
  1475. countSQL += ")a GROUP BY nnd"
  1476. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1477. }
  1478. return
  1479. }
  1480. func GetMonthProjectListOne(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1481. if lapseto == 0 {
  1482. d := XTReadDB().Table("xt_patients as s")
  1483. fmt.Println("d", d)
  1484. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1485. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1486. "SELECT " +
  1487. "CASE " +
  1488. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1489. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1490. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1491. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1492. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1493. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1494. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1495. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1496. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1497. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1498. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1499. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1500. " ELSE '其他'" +
  1501. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1502. countParams := make([]interface{}, 0)
  1503. countParams = append(countParams, januaryStartStrUnix)
  1504. countParams = append(countParams, januaryEndStrUnix)
  1505. countParams = append(countParams, febStartStrStrUnix)
  1506. countParams = append(countParams, febEndStrUnix)
  1507. countParams = append(countParams, marchStartStrUnix)
  1508. countParams = append(countParams, marchEndStrUnix)
  1509. countParams = append(countParams, aprStartStrUnix)
  1510. countParams = append(countParams, aprEndStrsUnix)
  1511. countParams = append(countParams, mayStartStrUnix)
  1512. countParams = append(countParams, mayEndStrsUnix)
  1513. countParams = append(countParams, junStartStrUnix)
  1514. countParams = append(countParams, junEndStrsUnix)
  1515. countParams = append(countParams, julStartStrUnix)
  1516. countParams = append(countParams, julEndStrsUnix)
  1517. countParams = append(countParams, augStartStrUnix)
  1518. countParams = append(countParams, augEndStrsUnix)
  1519. countParams = append(countParams, sepStartStrUnix)
  1520. countParams = append(countParams, sepEndStrsUnix)
  1521. countParams = append(countParams, octStartStrUnix)
  1522. countParams = append(countParams, octEndStrsUnix)
  1523. countParams = append(countParams, novStartStrUnix)
  1524. countParams = append(countParams, novEndStrsUnix)
  1525. countParams = append(countParams, decStartStrUnix)
  1526. countParams = append(countParams, decEndStrsUnix)
  1527. if orgid > 0 {
  1528. db = db.Where("x.org_id=?", orgid)
  1529. countSQL += " AND x.org_id=?"
  1530. countParams = append(countParams, orgid)
  1531. }
  1532. if modetype > 0 {
  1533. db = db.Where("x.item_id = ?", modetype)
  1534. countSQL += " AND x.item_id=?"
  1535. countParams = append(countParams, modetype)
  1536. }
  1537. if januaryStartStrUnix > 0 {
  1538. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1539. countSQL += " AND x.inspect_date >=?"
  1540. countParams = append(countParams, januaryStartStrUnix)
  1541. }
  1542. if decEndStrsUnix > 0 {
  1543. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1544. countSQL += " AND x.inspect_date <=?"
  1545. countParams = append(countParams, decEndStrsUnix)
  1546. }
  1547. countSQL += ")a GROUP BY nnd"
  1548. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1549. }
  1550. if lapseto == 1 {
  1551. d := XTReadDB().Table("xt_patients as s")
  1552. fmt.Println("d", d)
  1553. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and and x.inspect_type = 2")
  1554. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1555. "SELECT " +
  1556. "CASE " +
  1557. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1558. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1559. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1560. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1561. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1562. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1563. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1564. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1565. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1566. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1567. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1568. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1569. " ELSE '其他'" +
  1570. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1571. countParams := make([]interface{}, 0)
  1572. countParams = append(countParams, januaryStartStrUnix)
  1573. countParams = append(countParams, januaryEndStrUnix)
  1574. countParams = append(countParams, febStartStrStrUnix)
  1575. countParams = append(countParams, febEndStrUnix)
  1576. countParams = append(countParams, marchStartStrUnix)
  1577. countParams = append(countParams, marchEndStrUnix)
  1578. countParams = append(countParams, aprStartStrUnix)
  1579. countParams = append(countParams, aprEndStrsUnix)
  1580. countParams = append(countParams, mayStartStrUnix)
  1581. countParams = append(countParams, mayEndStrsUnix)
  1582. countParams = append(countParams, junStartStrUnix)
  1583. countParams = append(countParams, junEndStrsUnix)
  1584. countParams = append(countParams, julStartStrUnix)
  1585. countParams = append(countParams, julEndStrsUnix)
  1586. countParams = append(countParams, augStartStrUnix)
  1587. countParams = append(countParams, augEndStrsUnix)
  1588. countParams = append(countParams, sepStartStrUnix)
  1589. countParams = append(countParams, sepEndStrsUnix)
  1590. countParams = append(countParams, octStartStrUnix)
  1591. countParams = append(countParams, octEndStrsUnix)
  1592. countParams = append(countParams, novStartStrUnix)
  1593. countParams = append(countParams, novEndStrsUnix)
  1594. countParams = append(countParams, decStartStrUnix)
  1595. countParams = append(countParams, decEndStrsUnix)
  1596. if orgid > 0 {
  1597. db = db.Where("x.org_id=?", orgid)
  1598. countSQL += " AND x.org_id=?"
  1599. countParams = append(countParams, orgid)
  1600. }
  1601. if modetype > 0 {
  1602. db = db.Where("x.item_id = ?", modetype)
  1603. countSQL += " AND x.item_id=?"
  1604. countParams = append(countParams, modetype)
  1605. }
  1606. if januaryStartStrUnix > 0 {
  1607. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1608. countSQL += " AND x.inspect_date >=?"
  1609. countParams = append(countParams, januaryStartStrUnix)
  1610. }
  1611. if decEndStrsUnix > 0 {
  1612. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1613. countSQL += " AND x.inspect_date <=?"
  1614. countParams = append(countParams, decEndStrsUnix)
  1615. }
  1616. countSQL += ")a GROUP BY nnd"
  1617. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1618. }
  1619. if lapseto == 2 {
  1620. d := XTReadDB().Table("xt_patients as s")
  1621. fmt.Println("d", d)
  1622. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1623. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1624. "SELECT " +
  1625. "CASE " +
  1626. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1627. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1628. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1629. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1630. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1631. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1632. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1633. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1634. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1635. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1636. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1637. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1638. " ELSE '其他'" +
  1639. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1640. countParams := make([]interface{}, 0)
  1641. countParams = append(countParams, januaryStartStrUnix)
  1642. countParams = append(countParams, januaryEndStrUnix)
  1643. countParams = append(countParams, febStartStrStrUnix)
  1644. countParams = append(countParams, febEndStrUnix)
  1645. countParams = append(countParams, marchStartStrUnix)
  1646. countParams = append(countParams, marchEndStrUnix)
  1647. countParams = append(countParams, aprStartStrUnix)
  1648. countParams = append(countParams, aprEndStrsUnix)
  1649. countParams = append(countParams, mayStartStrUnix)
  1650. countParams = append(countParams, mayEndStrsUnix)
  1651. countParams = append(countParams, junStartStrUnix)
  1652. countParams = append(countParams, junEndStrsUnix)
  1653. countParams = append(countParams, julStartStrUnix)
  1654. countParams = append(countParams, julEndStrsUnix)
  1655. countParams = append(countParams, augStartStrUnix)
  1656. countParams = append(countParams, augEndStrsUnix)
  1657. countParams = append(countParams, sepStartStrUnix)
  1658. countParams = append(countParams, sepEndStrsUnix)
  1659. countParams = append(countParams, octStartStrUnix)
  1660. countParams = append(countParams, octEndStrsUnix)
  1661. countParams = append(countParams, novStartStrUnix)
  1662. countParams = append(countParams, novEndStrsUnix)
  1663. countParams = append(countParams, decStartStrUnix)
  1664. countParams = append(countParams, decEndStrsUnix)
  1665. if orgid > 0 {
  1666. db = db.Where("x.org_id=?", orgid)
  1667. countSQL += " AND x.org_id=?"
  1668. countParams = append(countParams, orgid)
  1669. }
  1670. if modetype > 0 {
  1671. db = db.Where("x.item_id = ?", modetype)
  1672. countSQL += " AND x.item_id=?"
  1673. countParams = append(countParams, modetype)
  1674. }
  1675. if januaryStartStrUnix > 0 {
  1676. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1677. countSQL += " AND x.inspect_date >=?"
  1678. countParams = append(countParams, januaryStartStrUnix)
  1679. }
  1680. if decEndStrsUnix > 0 {
  1681. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1682. countSQL += " AND x.inspect_date <=?"
  1683. countParams = append(countParams, decEndStrsUnix)
  1684. }
  1685. countSQL += ")a GROUP BY nnd"
  1686. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1687. }
  1688. return
  1689. }
  1690. func GetProjectListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  1691. if lapseto == 0 {
  1692. d := XTReadDB().Table("xt_patients as s")
  1693. fmt.Println("d", d)
  1694. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1695. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1696. "SELECT " +
  1697. "CASE " +
  1698. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1699. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1700. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1701. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1702. " ELSE '其他'" +
  1703. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1704. countParams := make([]interface{}, 0)
  1705. countParams = append(countParams, firststart)
  1706. countParams = append(countParams, firstend)
  1707. countParams = append(countParams, sencondstart)
  1708. countParams = append(countParams, sencondend)
  1709. countParams = append(countParams, threestart)
  1710. countParams = append(countParams, threeend)
  1711. countParams = append(countParams, fourstart)
  1712. countParams = append(countParams, fourend)
  1713. if orgid > 0 {
  1714. db = db.Where("x.org_id=?", orgid)
  1715. countSQL += " AND x.org_id=?"
  1716. countParams = append(countParams, orgid)
  1717. }
  1718. if modetype > 0 {
  1719. db = db.Where("x.item_id = ?", modetype)
  1720. countSQL += " AND x.item_id=?"
  1721. countParams = append(countParams, modetype)
  1722. }
  1723. if startime > 0 {
  1724. db = db.Where("x.inspect_date >= ?", startime)
  1725. countSQL += " AND x.inspect_date >=?"
  1726. countParams = append(countParams, startime)
  1727. }
  1728. if endtime > 0 {
  1729. db = db.Where("x.inspect_date <= ?", endtime)
  1730. countSQL += " AND x.inspect_date <=?"
  1731. countParams = append(countParams, endtime)
  1732. }
  1733. countSQL += ")a GROUP BY nnd"
  1734. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1735. }
  1736. if lapseto == 1 {
  1737. d := XTReadDB().Table("xt_patients as s")
  1738. fmt.Println("d", d)
  1739. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1740. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1741. "SELECT " +
  1742. "CASE " +
  1743. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1744. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1745. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1746. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1747. " ELSE '其他'" +
  1748. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1749. countParams := make([]interface{}, 0)
  1750. countParams = append(countParams, firststart)
  1751. countParams = append(countParams, firstend)
  1752. countParams = append(countParams, sencondstart)
  1753. countParams = append(countParams, sencondend)
  1754. countParams = append(countParams, threestart)
  1755. countParams = append(countParams, threeend)
  1756. countParams = append(countParams, fourstart)
  1757. countParams = append(countParams, fourend)
  1758. if orgid > 0 {
  1759. db = db.Where("x.org_id=?", orgid)
  1760. countSQL += " AND x.org_id=?"
  1761. countParams = append(countParams, orgid)
  1762. }
  1763. if modetype > 0 {
  1764. db = db.Where("x.item_id = ?", modetype)
  1765. countSQL += " AND x.item_id=?"
  1766. countParams = append(countParams, modetype)
  1767. }
  1768. if startime > 0 {
  1769. db = db.Where("x.inspect_date >= ?", startime)
  1770. countSQL += " AND x.inspect_date >=?"
  1771. countParams = append(countParams, startime)
  1772. }
  1773. if endtime > 0 {
  1774. db = db.Where("x.inspect_date <= ?", endtime)
  1775. countSQL += " AND x.inspect_date <=?"
  1776. countParams = append(countParams, endtime)
  1777. }
  1778. countSQL += ")a GROUP BY nnd"
  1779. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1780. }
  1781. if lapseto == 2 {
  1782. d := XTReadDB().Table("xt_patients as s")
  1783. fmt.Println("d", d)
  1784. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1785. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1786. "SELECT " +
  1787. "CASE " +
  1788. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1789. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1790. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1791. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1792. " ELSE '其他'" +
  1793. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1794. countParams := make([]interface{}, 0)
  1795. countParams = append(countParams, firststart)
  1796. countParams = append(countParams, firstend)
  1797. countParams = append(countParams, sencondstart)
  1798. countParams = append(countParams, sencondend)
  1799. countParams = append(countParams, threestart)
  1800. countParams = append(countParams, threeend)
  1801. countParams = append(countParams, fourstart)
  1802. countParams = append(countParams, fourend)
  1803. if orgid > 0 {
  1804. db = db.Where("x.org_id=?", orgid)
  1805. countSQL += " AND x.org_id=?"
  1806. countParams = append(countParams, orgid)
  1807. }
  1808. if modetype > 0 {
  1809. db = db.Where("x.item_id = ?", modetype)
  1810. countSQL += " AND x.item_id=?"
  1811. countParams = append(countParams, modetype)
  1812. }
  1813. if startime > 0 {
  1814. db = db.Where("x.inspect_date >= ?", startime)
  1815. countSQL += " AND x.inspect_date >=?"
  1816. countParams = append(countParams, startime)
  1817. }
  1818. if endtime > 0 {
  1819. db = db.Where("x.inspect_date <= ?", endtime)
  1820. countSQL += " AND x.inspect_date <=?"
  1821. countParams = append(countParams, endtime)
  1822. }
  1823. countSQL += ")a GROUP BY nnd"
  1824. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1825. }
  1826. return
  1827. }
  1828. func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  1829. if lapseto == 0 {
  1830. d := XTReadDB().Table("xt_patients as s")
  1831. fmt.Println("d", d)
  1832. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1833. table := XTReadDB().Table("xt_quality_control_standard as r")
  1834. fmt.Println(table)
  1835. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1836. "SELECT " +
  1837. "CASE " +
  1838. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1839. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1840. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1841. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1842. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1843. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1844. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1845. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1846. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1847. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1848. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1849. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1850. " ELSE '其他'" +
  1851. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1852. countParams := make([]interface{}, 0)
  1853. countParams = append(countParams, januaryStartStrUnix)
  1854. countParams = append(countParams, januaryEndStrUnix)
  1855. countParams = append(countParams, febStartStrStrUnix)
  1856. countParams = append(countParams, febEndStrUnix)
  1857. countParams = append(countParams, marchStartStrUnix)
  1858. countParams = append(countParams, marchEndStrUnix)
  1859. countParams = append(countParams, aprStartStrUnix)
  1860. countParams = append(countParams, aprEndStrsUnix)
  1861. countParams = append(countParams, mayStartStrUnix)
  1862. countParams = append(countParams, mayEndStrsUnix)
  1863. countParams = append(countParams, junStartStrUnix)
  1864. countParams = append(countParams, junEndStrsUnix)
  1865. countParams = append(countParams, julStartStrUnix)
  1866. countParams = append(countParams, julEndStrsUnix)
  1867. countParams = append(countParams, augStartStrUnix)
  1868. countParams = append(countParams, augEndStrsUnix)
  1869. countParams = append(countParams, sepStartStrUnix)
  1870. countParams = append(countParams, sepEndStrsUnix)
  1871. countParams = append(countParams, octStartStrUnix)
  1872. countParams = append(countParams, octEndStrsUnix)
  1873. countParams = append(countParams, novStartStrUnix)
  1874. countParams = append(countParams, novEndStrsUnix)
  1875. countParams = append(countParams, decStartStrUnix)
  1876. countParams = append(countParams, decEndStrsUnix)
  1877. if orgid > 0 {
  1878. db = db.Where("x.org_id=?", orgid)
  1879. countSQL += " AND x.org_id=?"
  1880. countParams = append(countParams, orgid)
  1881. }
  1882. if orgid > 0 {
  1883. db = db.Where("r.user_org_id=?", orgid)
  1884. countSQL += " AND r.user_org_id=?"
  1885. countParams = append(countParams, orgid)
  1886. }
  1887. if modetype > 0 {
  1888. db = db.Where("x.item_id = ?", modetype)
  1889. countSQL += " AND x.item_id=?"
  1890. countParams = append(countParams, modetype)
  1891. }
  1892. if januaryStartStrUnix > 0 {
  1893. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1894. countSQL += " AND x.inspect_date >=?"
  1895. countParams = append(countParams, januaryStartStrUnix)
  1896. }
  1897. if decEndStrsUnix > 0 {
  1898. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1899. countSQL += " AND x.inspect_date <=?"
  1900. countParams = append(countParams, decEndStrsUnix)
  1901. }
  1902. countSQL += ")a GROUP BY nnd"
  1903. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1904. }
  1905. if lapseto == 1 {
  1906. d := XTReadDB().Table("xt_patients as s")
  1907. fmt.Println("d", d)
  1908. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1909. table := XTReadDB().Table("xt_quality_control_standard as r")
  1910. fmt.Println(table)
  1911. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1912. "SELECT " +
  1913. "CASE " +
  1914. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1915. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1916. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1917. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1918. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1919. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1920. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1921. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1922. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1923. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1924. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1925. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1926. " ELSE '其他'" +
  1927. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1928. countParams := make([]interface{}, 0)
  1929. countParams = append(countParams, januaryStartStrUnix)
  1930. countParams = append(countParams, januaryEndStrUnix)
  1931. countParams = append(countParams, febStartStrStrUnix)
  1932. countParams = append(countParams, febEndStrUnix)
  1933. countParams = append(countParams, marchStartStrUnix)
  1934. countParams = append(countParams, marchEndStrUnix)
  1935. countParams = append(countParams, aprStartStrUnix)
  1936. countParams = append(countParams, aprEndStrsUnix)
  1937. countParams = append(countParams, mayStartStrUnix)
  1938. countParams = append(countParams, mayEndStrsUnix)
  1939. countParams = append(countParams, junStartStrUnix)
  1940. countParams = append(countParams, junEndStrsUnix)
  1941. countParams = append(countParams, julStartStrUnix)
  1942. countParams = append(countParams, julEndStrsUnix)
  1943. countParams = append(countParams, augStartStrUnix)
  1944. countParams = append(countParams, augEndStrsUnix)
  1945. countParams = append(countParams, sepStartStrUnix)
  1946. countParams = append(countParams, sepEndStrsUnix)
  1947. countParams = append(countParams, octStartStrUnix)
  1948. countParams = append(countParams, octEndStrsUnix)
  1949. countParams = append(countParams, novStartStrUnix)
  1950. countParams = append(countParams, novEndStrsUnix)
  1951. countParams = append(countParams, decStartStrUnix)
  1952. countParams = append(countParams, decEndStrsUnix)
  1953. if orgid > 0 {
  1954. db = db.Where("x.org_id=?", orgid)
  1955. countSQL += " AND x.org_id=?"
  1956. countParams = append(countParams, orgid)
  1957. }
  1958. if orgid > 0 {
  1959. db = db.Where("r.user_org_id=?", orgid)
  1960. countSQL += " AND r.user_org_id=?"
  1961. countParams = append(countParams, orgid)
  1962. }
  1963. if modetype > 0 {
  1964. db = db.Where("x.item_id = ?", modetype)
  1965. countSQL += " AND x.item_id=?"
  1966. countParams = append(countParams, modetype)
  1967. }
  1968. if januaryStartStrUnix > 0 {
  1969. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1970. countSQL += " AND x.inspect_date >=?"
  1971. countParams = append(countParams, januaryStartStrUnix)
  1972. }
  1973. if decEndStrsUnix > 0 {
  1974. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1975. countSQL += " AND x.inspect_date <=?"
  1976. countParams = append(countParams, decEndStrsUnix)
  1977. }
  1978. countSQL += ")a GROUP BY nnd"
  1979. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1980. }
  1981. if lapseto == 2 {
  1982. d := XTReadDB().Table("xt_patients as s")
  1983. fmt.Println("d", d)
  1984. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1985. table := XTReadDB().Table("xt_quality_control_standard as r")
  1986. fmt.Println(table)
  1987. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1988. "SELECT " +
  1989. "CASE " +
  1990. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1991. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1992. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1993. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1994. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1995. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1996. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1997. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1998. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1999. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  2000. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  2001. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  2002. " ELSE '其他'" +
  2003. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  2004. countParams := make([]interface{}, 0)
  2005. countParams = append(countParams, januaryStartStrUnix)
  2006. countParams = append(countParams, januaryEndStrUnix)
  2007. countParams = append(countParams, febStartStrStrUnix)
  2008. countParams = append(countParams, febEndStrUnix)
  2009. countParams = append(countParams, marchStartStrUnix)
  2010. countParams = append(countParams, marchEndStrUnix)
  2011. countParams = append(countParams, aprStartStrUnix)
  2012. countParams = append(countParams, aprEndStrsUnix)
  2013. countParams = append(countParams, mayStartStrUnix)
  2014. countParams = append(countParams, mayEndStrsUnix)
  2015. countParams = append(countParams, junStartStrUnix)
  2016. countParams = append(countParams, junEndStrsUnix)
  2017. countParams = append(countParams, julStartStrUnix)
  2018. countParams = append(countParams, julEndStrsUnix)
  2019. countParams = append(countParams, augStartStrUnix)
  2020. countParams = append(countParams, augEndStrsUnix)
  2021. countParams = append(countParams, sepStartStrUnix)
  2022. countParams = append(countParams, sepEndStrsUnix)
  2023. countParams = append(countParams, octStartStrUnix)
  2024. countParams = append(countParams, octEndStrsUnix)
  2025. countParams = append(countParams, novStartStrUnix)
  2026. countParams = append(countParams, novEndStrsUnix)
  2027. countParams = append(countParams, decStartStrUnix)
  2028. countParams = append(countParams, decEndStrsUnix)
  2029. if orgid > 0 {
  2030. db = db.Where("x.org_id=?", orgid)
  2031. countSQL += " AND x.org_id=?"
  2032. countParams = append(countParams, orgid)
  2033. }
  2034. if orgid > 0 {
  2035. db = db.Where("r.user_org_id=?", orgid)
  2036. countSQL += " AND r.user_org_id=?"
  2037. countParams = append(countParams, orgid)
  2038. }
  2039. if modetype > 0 {
  2040. db = db.Where("x.item_id = ?", modetype)
  2041. countSQL += " AND x.item_id=?"
  2042. countParams = append(countParams, modetype)
  2043. }
  2044. if januaryStartStrUnix > 0 {
  2045. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2046. countSQL += " AND x.inspect_date >=?"
  2047. countParams = append(countParams, januaryStartStrUnix)
  2048. }
  2049. if decEndStrsUnix > 0 {
  2050. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2051. countSQL += " AND x.inspect_date <=?"
  2052. countParams = append(countParams, decEndStrsUnix)
  2053. }
  2054. countSQL += ")a GROUP BY nnd"
  2055. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2056. }
  2057. return
  2058. }
  2059. func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  2060. if lapseto == 0 {
  2061. d := XTReadDB().Table("xt_patients as s")
  2062. fmt.Println("d", d)
  2063. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2064. table := XTReadDB().Table("xt_quality_control_standard as r")
  2065. fmt.Println(table)
  2066. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2067. "SELECT " +
  2068. "CASE " +
  2069. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2070. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2071. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2072. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2073. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2074. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2075. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2076. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2077. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2078. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2079. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2080. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2081. " ELSE '其他'" +
  2082. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2083. countParams := make([]interface{}, 0)
  2084. countParams = append(countParams, januaryStartStrUnix)
  2085. countParams = append(countParams, januaryEndStrUnix)
  2086. countParams = append(countParams, febStartStrStrUnix)
  2087. countParams = append(countParams, febEndStrUnix)
  2088. countParams = append(countParams, marchStartStrUnix)
  2089. countParams = append(countParams, marchEndStrUnix)
  2090. countParams = append(countParams, aprStartStrUnix)
  2091. countParams = append(countParams, aprEndStrsUnix)
  2092. countParams = append(countParams, mayStartStrUnix)
  2093. countParams = append(countParams, mayEndStrsUnix)
  2094. countParams = append(countParams, junStartStrUnix)
  2095. countParams = append(countParams, junEndStrsUnix)
  2096. countParams = append(countParams, julStartStrUnix)
  2097. countParams = append(countParams, julEndStrsUnix)
  2098. countParams = append(countParams, augStartStrUnix)
  2099. countParams = append(countParams, augEndStrsUnix)
  2100. countParams = append(countParams, sepStartStrUnix)
  2101. countParams = append(countParams, sepEndStrsUnix)
  2102. countParams = append(countParams, octStartStrUnix)
  2103. countParams = append(countParams, octEndStrsUnix)
  2104. countParams = append(countParams, novStartStrUnix)
  2105. countParams = append(countParams, novEndStrsUnix)
  2106. countParams = append(countParams, decStartStrUnix)
  2107. countParams = append(countParams, decEndStrsUnix)
  2108. if orgid > 0 {
  2109. db = db.Where("x.org_id=?", orgid)
  2110. countSQL += " AND x.org_id=?"
  2111. countParams = append(countParams, orgid)
  2112. }
  2113. if orgid > 0 {
  2114. db = db.Where("r.user_org_id=?", orgid)
  2115. countSQL += " AND r.user_org_id=?"
  2116. countParams = append(countParams, orgid)
  2117. }
  2118. if modetype > 0 {
  2119. db = db.Where("x.item_id = ?", modetype)
  2120. countSQL += " AND x.item_id=?"
  2121. countParams = append(countParams, modetype)
  2122. }
  2123. if januaryStartStrUnix > 0 {
  2124. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2125. countSQL += " AND x.inspect_date >=?"
  2126. countParams = append(countParams, januaryStartStrUnix)
  2127. }
  2128. if decEndStrsUnix > 0 {
  2129. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2130. countSQL += " AND x.inspect_date <=?"
  2131. countParams = append(countParams, decEndStrsUnix)
  2132. }
  2133. countSQL += ")a GROUP BY nnd"
  2134. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2135. }
  2136. if lapseto == 1 {
  2137. d := XTReadDB().Table("xt_patients as s")
  2138. fmt.Println("d", d)
  2139. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2140. table := XTReadDB().Table("xt_quality_control_standard as r")
  2141. fmt.Println(table)
  2142. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2143. "SELECT " +
  2144. "CASE " +
  2145. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2146. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2147. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2148. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2149. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2150. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2151. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2152. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2153. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2154. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2155. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2156. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2157. " ELSE '其他'" +
  2158. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value = r.range_value)"
  2159. countParams := make([]interface{}, 0)
  2160. countParams = append(countParams, januaryStartStrUnix)
  2161. countParams = append(countParams, januaryEndStrUnix)
  2162. countParams = append(countParams, febStartStrStrUnix)
  2163. countParams = append(countParams, febEndStrUnix)
  2164. countParams = append(countParams, marchStartStrUnix)
  2165. countParams = append(countParams, marchEndStrUnix)
  2166. countParams = append(countParams, aprStartStrUnix)
  2167. countParams = append(countParams, aprEndStrsUnix)
  2168. countParams = append(countParams, mayStartStrUnix)
  2169. countParams = append(countParams, mayEndStrsUnix)
  2170. countParams = append(countParams, junStartStrUnix)
  2171. countParams = append(countParams, junEndStrsUnix)
  2172. countParams = append(countParams, julStartStrUnix)
  2173. countParams = append(countParams, julEndStrsUnix)
  2174. countParams = append(countParams, augStartStrUnix)
  2175. countParams = append(countParams, augEndStrsUnix)
  2176. countParams = append(countParams, sepStartStrUnix)
  2177. countParams = append(countParams, sepEndStrsUnix)
  2178. countParams = append(countParams, octStartStrUnix)
  2179. countParams = append(countParams, octEndStrsUnix)
  2180. countParams = append(countParams, novStartStrUnix)
  2181. countParams = append(countParams, novEndStrsUnix)
  2182. countParams = append(countParams, decStartStrUnix)
  2183. countParams = append(countParams, decEndStrsUnix)
  2184. if orgid > 0 {
  2185. db = db.Where("x.org_id=?", orgid)
  2186. countSQL += " AND x.org_id=?"
  2187. countParams = append(countParams, orgid)
  2188. }
  2189. if orgid > 0 {
  2190. db = db.Where("r.user_org_id=?", orgid)
  2191. countSQL += " AND r.user_org_id=?"
  2192. countParams = append(countParams, orgid)
  2193. }
  2194. if modetype > 0 {
  2195. db = db.Where("x.item_id = ?", modetype)
  2196. countSQL += " AND x.item_id=?"
  2197. countParams = append(countParams, modetype)
  2198. }
  2199. if januaryStartStrUnix > 0 {
  2200. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2201. countSQL += " AND x.inspect_date >=?"
  2202. countParams = append(countParams, januaryStartStrUnix)
  2203. }
  2204. if decEndStrsUnix > 0 {
  2205. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2206. countSQL += " AND x.inspect_date <=?"
  2207. countParams = append(countParams, decEndStrsUnix)
  2208. }
  2209. countSQL += ")a GROUP BY nnd"
  2210. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2211. }
  2212. if lapseto == 2 {
  2213. d := XTReadDB().Table("xt_patients as s")
  2214. fmt.Println("d", d)
  2215. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2216. table := XTReadDB().Table("xt_quality_control_standard as r")
  2217. fmt.Println(table)
  2218. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2219. "SELECT " +
  2220. "CASE " +
  2221. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2222. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2223. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2224. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2225. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2226. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2227. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2228. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2229. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2230. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2231. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2232. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2233. " ELSE '其他'" +
  2234. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2235. countParams := make([]interface{}, 0)
  2236. countParams = append(countParams, januaryStartStrUnix)
  2237. countParams = append(countParams, januaryEndStrUnix)
  2238. countParams = append(countParams, febStartStrStrUnix)
  2239. countParams = append(countParams, febEndStrUnix)
  2240. countParams = append(countParams, marchStartStrUnix)
  2241. countParams = append(countParams, marchEndStrUnix)
  2242. countParams = append(countParams, aprStartStrUnix)
  2243. countParams = append(countParams, aprEndStrsUnix)
  2244. countParams = append(countParams, mayStartStrUnix)
  2245. countParams = append(countParams, mayEndStrsUnix)
  2246. countParams = append(countParams, junStartStrUnix)
  2247. countParams = append(countParams, junEndStrsUnix)
  2248. countParams = append(countParams, julStartStrUnix)
  2249. countParams = append(countParams, julEndStrsUnix)
  2250. countParams = append(countParams, augStartStrUnix)
  2251. countParams = append(countParams, augEndStrsUnix)
  2252. countParams = append(countParams, sepStartStrUnix)
  2253. countParams = append(countParams, sepEndStrsUnix)
  2254. countParams = append(countParams, octStartStrUnix)
  2255. countParams = append(countParams, octEndStrsUnix)
  2256. countParams = append(countParams, novStartStrUnix)
  2257. countParams = append(countParams, novEndStrsUnix)
  2258. countParams = append(countParams, decStartStrUnix)
  2259. countParams = append(countParams, decEndStrsUnix)
  2260. if orgid > 0 {
  2261. db = db.Where("x.org_id=?", orgid)
  2262. countSQL += " AND x.org_id=?"
  2263. countParams = append(countParams, orgid)
  2264. }
  2265. if orgid > 0 {
  2266. db = db.Where("r.user_org_id=?", orgid)
  2267. countSQL += " AND r.user_org_id=?"
  2268. countParams = append(countParams, orgid)
  2269. }
  2270. if modetype > 0 {
  2271. db = db.Where("x.item_id = ?", modetype)
  2272. countSQL += " AND x.item_id=?"
  2273. countParams = append(countParams, modetype)
  2274. }
  2275. if januaryStartStrUnix > 0 {
  2276. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2277. countSQL += " AND x.inspect_date >=?"
  2278. countParams = append(countParams, januaryStartStrUnix)
  2279. }
  2280. if decEndStrsUnix > 0 {
  2281. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2282. countSQL += " AND x.inspect_date <=?"
  2283. countParams = append(countParams, decEndStrsUnix)
  2284. }
  2285. countSQL += ")a GROUP BY nnd"
  2286. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2287. }
  2288. return
  2289. }
  2290. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2291. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2292. table := readDb.Table("xt_patients as s")
  2293. fmt.Println(table)
  2294. d := readDb.Table(" xt_inspection_reference as r")
  2295. fmt.Println(d)
  2296. if orgid > 0 {
  2297. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2298. }
  2299. if lapstor == 0 {
  2300. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2301. }
  2302. if lapstor == 1 {
  2303. db = db.Where("s.lapseto = 1")
  2304. }
  2305. if lapstor == 2 {
  2306. db = db.Where("s.lapseto = 2")
  2307. }
  2308. if startime > 0 {
  2309. db = db.Where("x.inspect_date >=?", startime)
  2310. }
  2311. if endtime > 0 {
  2312. db = db.Where("x.inspect_date <=?", endtime)
  2313. }
  2314. offset := (page - 1) * limit
  2315. err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as r on x.item_id = r.inspection_minor ").Where("r.user_org_id = ? and r.status = 1 and r.is_status = 1", orgid).Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2316. return inspection, total, err
  2317. }
  2318. //func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2319. //
  2320. // db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2321. // table := readDb.Table("xt_patients as s")
  2322. // fmt.Println(table)
  2323. // d := readDb.Table(" xt_inspection_reference as r")
  2324. // fmt.Println(d)
  2325. //
  2326. // if orgid > 0 {
  2327. // db = db.Where("x.org_id = ?", orgid)
  2328. // }
  2329. // if lapstor == 0 {
  2330. // table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2331. // }
  2332. // if lapstor == 1 {
  2333. // db = db.Where("s.lapseto = 1")
  2334. // }
  2335. // if lapstor == 2 {
  2336. // db = db.Where("s.lapseto = 2")
  2337. // }
  2338. // if startime > 0 {
  2339. // db = db.Where("x.inspect_date >=?", startime)
  2340. // }
  2341. // if endtime > 0 {
  2342. // db = db.Where("x.inspect_date <=?", endtime)
  2343. // }
  2344. // offset := (page - 1) * limit
  2345. // err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0 )").Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2346. //
  2347. // return inspection, total, err
  2348. //}
  2349. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2350. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2351. table := readDb.Table("xt_patients as s")
  2352. fmt.Println(table)
  2353. d := readDb.Table(" xt_inspection_reference as r")
  2354. fmt.Println(d)
  2355. d2 := readDb.Table("xt_quality_control_standard as d")
  2356. fmt.Println("d2", d2)
  2357. if orgid > 0 {
  2358. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1", orgid)
  2359. }
  2360. if lapstor == 0 {
  2361. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2362. }
  2363. if lapstor == 1 {
  2364. table = table.Where("s.lapseto = 1")
  2365. }
  2366. if lapstor == 2 {
  2367. table = table.Where("s.lapseto = 2")
  2368. }
  2369. if startime > 0 {
  2370. db = db.Where("x.inspect_date >=?", startime)
  2371. }
  2372. if endtime > 0 {
  2373. db = db.Where("x.inspect_date <=?", endtime)
  2374. }
  2375. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.min_range<>''and d.user_org_id = ? and d.is_status =1", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2376. return inspection, err
  2377. }
  2378. func GetTotalPatientsControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2379. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2380. table := readDb.Table("xt_quality_control_standard as s")
  2381. fmt.Println(table)
  2382. if orgid > 0 {
  2383. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2384. }
  2385. if startime > 0 {
  2386. db = db.Where("x.inspect_date >=?", startime)
  2387. }
  2388. if endtime > 0 {
  2389. db = db.Where("x.inspect_date <=?", endtime)
  2390. }
  2391. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("s.status = 1 and s.is_status =1").Count(&total).Scan(&inspection).Error
  2392. return inspection, total, err
  2393. }
  2394. func GetStandControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2395. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2396. table := readDb.Table("xt_quality_control_standard as s")
  2397. fmt.Println(table)
  2398. if orgid > 0 {
  2399. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1 ", orgid)
  2400. }
  2401. if startime > 0 {
  2402. db = db.Where("x.inspect_date >=?", startime)
  2403. }
  2404. if endtime > 0 {
  2405. db = db.Where("x.inspect_date <=?", endtime)
  2406. }
  2407. db = db.Where("s.status = 1 and s.is_status = 1")
  2408. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value+0 >= s.min_range + 0 and x.inspect_value+0 <= s.large_range + 0 ").Count(&total).Scan(&inspection).Error
  2409. return inspection, total, err
  2410. }
  2411. func GetStandControlOne(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2412. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2413. table := readDb.Table("xt_quality_control_standard as s")
  2414. fmt.Println(table)
  2415. if orgid > 0 {
  2416. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2 ", orgid)
  2417. }
  2418. if startime > 0 {
  2419. db = db.Where("x.inspect_date >=?", startime)
  2420. }
  2421. if endtime > 0 {
  2422. db = db.Where("x.inspect_date <=?", endtime)
  2423. }
  2424. db = db.Where("s.status = 1 and s.is_status = 1")
  2425. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value = s.range_value").Count(&total).Scan(&inspection).Error
  2426. return inspection, total, err
  2427. }
  2428. func GetInfectiousPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2429. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2430. table := readDb.Table("xt_patients as s")
  2431. fmt.Println(table)
  2432. d := readDb.Table(" xt_inspection_reference as r")
  2433. fmt.Println(d)
  2434. d2 := readDb.Table("xt_quality_control_standard as d")
  2435. fmt.Println("d2", d2)
  2436. if orgid > 0 {
  2437. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2438. }
  2439. if lapstor == 0 {
  2440. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2441. }
  2442. if lapstor == 1 {
  2443. table = table.Where("s.lapseto = 1")
  2444. }
  2445. if lapstor == 2 {
  2446. table = table.Where("s.lapseto = 2")
  2447. }
  2448. if startime > 0 {
  2449. db = db.Where("x.inspect_date >=?", startime)
  2450. }
  2451. if endtime > 0 {
  2452. db = db.Where("x.inspect_date <=?", endtime)
  2453. }
  2454. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2455. return inspection, err
  2456. }
  2457. func GetInfectiousControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2458. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2459. table := readDb.Table("xt_patients as s")
  2460. fmt.Println(table)
  2461. d := readDb.Table(" xt_inspection_reference as r")
  2462. fmt.Println(d)
  2463. d2 := readDb.Table("xt_quality_control_standard as d")
  2464. fmt.Println("d2", d2)
  2465. if orgid > 0 {
  2466. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2467. }
  2468. if lapstor == 0 {
  2469. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2470. }
  2471. if lapstor == 1 {
  2472. table = table.Where("s.lapseto = 1")
  2473. }
  2474. if lapstor == 2 {
  2475. table = table.Where("s.lapseto = 2")
  2476. }
  2477. if startime > 0 {
  2478. db = db.Where("x.inspect_date >=?", startime)
  2479. }
  2480. if endtime > 0 {
  2481. db = db.Where("x.inspect_date <=?", endtime)
  2482. }
  2483. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.range_value <>''and d.user_org_id = ? and d.is_status = 1", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2484. return inspection, err
  2485. }
  2486. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2487. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2488. table := readDb.Table("xt_patients as s")
  2489. fmt.Println(table)
  2490. d := readDb.Table(" xt_inspection_reference as r")
  2491. fmt.Println(d)
  2492. d2 := readDb.Table("xt_quality_control_standard as d")
  2493. fmt.Println("d2", d2)
  2494. if len(keywords) > 0 {
  2495. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  2496. }
  2497. if orgid > 0 {
  2498. db = db.Where("x.org_id = ?", orgid)
  2499. }
  2500. if lapstor == 0 {
  2501. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2502. }
  2503. if lapstor == 1 {
  2504. table = table.Where("s.lapseto = 1")
  2505. }
  2506. if lapstor == 2 {
  2507. table = table.Where("s.lapseto = 2")
  2508. }
  2509. if startime > 0 {
  2510. db = db.Where("x.inspect_date >=?", startime)
  2511. }
  2512. if endtime > 0 {
  2513. db = db.Where("x.inspect_date <=?", endtime)
  2514. }
  2515. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2516. return inspection, err
  2517. }
  2518. func GetPatientNames(orgid int64, patientid int64) (models.XtPatients, error) {
  2519. patients := models.XtPatients{}
  2520. err := readDb.Where("user_org_id = ? and id = ? and status = 1", orgid, patientid).Find(&patients).Error
  2521. return patients, err
  2522. }
  2523. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64, inspectdate int64) (inspection []*models.PatientInspectionCount, err error) {
  2524. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2525. table := readDb.Table("xt_patients as s")
  2526. fmt.Println(table)
  2527. d := readDb.Table(" xt_inspection_reference as r")
  2528. fmt.Println(d)
  2529. d2 := readDb.Table("xt_quality_control_standard as d")
  2530. fmt.Println("d2", d2)
  2531. if orgid > 0 {
  2532. db = db.Where("x.org_id = ?", orgid)
  2533. }
  2534. if patientid > 0 {
  2535. db = db.Where("x.patient_id = ?", patientid)
  2536. }
  2537. //if startime > 0 {
  2538. // db = db.Where("x.inspect_date >=?", startime)
  2539. //}
  2540. //if endtime > 0 {
  2541. // db = db.Where("x.inspect_date <=?", endtime)
  2542. //}
  2543. if itemid > 0 {
  2544. db = db.Where("x.item_id = ?", itemid)
  2545. }
  2546. if inspectdate > 0 {
  2547. db = db.Where("x.inspect_date = ?", inspectdate)
  2548. }
  2549. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2550. return inspection, err
  2551. }
  2552. func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  2553. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2554. table := readDb.Table("xt_patients as s")
  2555. fmt.Println(table)
  2556. d := readDb.Table(" xt_inspection_reference as r")
  2557. fmt.Println(d)
  2558. d2 := readDb.Table("xt_quality_control_standard as d")
  2559. fmt.Println("d2", d2)
  2560. if orgid > 0 {
  2561. db = db.Where("x.org_id = ? and (x.inspect_value <> '' or x.inspect_value+0 <> 0)", orgid)
  2562. }
  2563. if patientid > 0 {
  2564. db = db.Where("x.patient_id = ?", patientid)
  2565. }
  2566. if startime > 0 {
  2567. db = db.Where("x.inspect_date >=?", startime)
  2568. }
  2569. if endtime > 0 {
  2570. db = db.Where("x.inspect_date <=?", endtime)
  2571. }
  2572. if itemid > 0 {
  2573. db = db.Where("x.item_id = ?", itemid)
  2574. }
  2575. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2576. return inspection, err
  2577. }
  2578. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2579. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2580. table := readDb.Table("xt_patients as s")
  2581. fmt.Println(table)
  2582. d := readDb.Table(" xt_inspection_reference as r")
  2583. fmt.Println(d)
  2584. d2 := readDb.Table("xt_quality_control_standard as d")
  2585. fmt.Println("d2", d2)
  2586. if orgid > 0 {
  2587. db = db.Where("x.org_id = ?", orgid)
  2588. }
  2589. if patientid > 0 {
  2590. db = db.Where("x.patient_id = ?", patientid)
  2591. }
  2592. if startime > 0 {
  2593. db = db.Where("x.inspect_date >=?", startime)
  2594. }
  2595. if endtime > 0 {
  2596. db = db.Where("x.inspect_date <=?", endtime)
  2597. }
  2598. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.large_range,d.min_range,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2599. return inspection, err
  2600. }
  2601. func GetBloodPressureDetail(id int64) (models.XtQualityControlStandard, error) {
  2602. standard := models.XtQualityControlStandard{}
  2603. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  2604. return standard, err
  2605. }
  2606. func UpdateBloodPressure(st *models.XtQualityControlStandard, id int64) error {
  2607. err := XTWriteDB().Model(&st).Where("id=?", id).Update(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "updated_time": st.UpdatedTime}).Error
  2608. return err
  2609. }
  2610. func GetSystolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2611. db := XTReadDB().Table("xt_monitoring_record as x")
  2612. err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2613. return record, total, err
  2614. }
  2615. func GetStandSystolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2616. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2617. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -1 and s.inspection_major = 0 and x.systolic_blood_pressure <> 0 and x.systolic_blood_pressure +0 >= s.min_range +0 and x.systolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2618. return record, total, err
  2619. }
  2620. func GetDiastolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2621. db := XTReadDB().Table("xt_monitoring_record as x")
  2622. err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2623. return record, total, err
  2624. }
  2625. func GetDiastolicStandPressure(orgid int64, startime int64, endtime int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2626. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2627. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -2 and s.inspection_major = 0 and x.diastolic_blood_pressure <> 0 and x.diastolic_blood_pressure +0 >= s.min_range +0 and x.diastolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2628. return record, total, err
  2629. }
  2630. func GetQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2631. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2632. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2633. "SELECT " +
  2634. "CASE " +
  2635. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2636. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2637. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2638. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2639. " ELSE '其他'" +
  2640. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2641. countParams := make([]interface{}, 0)
  2642. countParams = append(countParams, firststart)
  2643. countParams = append(countParams, firstend)
  2644. countParams = append(countParams, sencondstart)
  2645. countParams = append(countParams, sencondend)
  2646. countParams = append(countParams, threestart)
  2647. countParams = append(countParams, threeend)
  2648. countParams = append(countParams, fourstart)
  2649. countParams = append(countParams, fourend)
  2650. if orgid > 0 {
  2651. db = db.Where("x.org_id=?", orgid)
  2652. countSQL += " AND x.org_id=?"
  2653. countParams = append(countParams, orgid)
  2654. db = db.Where("x.inspect_date>=?", firststart)
  2655. countSQL += " AND x.inspect_date>=?"
  2656. countParams = append(countParams, firststart)
  2657. db = db.Where("x.inspect_date<=?", fourend)
  2658. countSQL += " AND x.inspect_date<=?"
  2659. countParams = append(countParams, fourend)
  2660. }
  2661. countSQL += ")a GROUP BY nnd"
  2662. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2663. return
  2664. }
  2665. func GetQuarterTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2666. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2667. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2668. "SELECT " +
  2669. "CASE " +
  2670. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2671. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2672. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2673. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2674. " ELSE '其他'" +
  2675. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2676. countParams := make([]interface{}, 0)
  2677. countParams = append(countParams, firststart)
  2678. countParams = append(countParams, firstend)
  2679. countParams = append(countParams, sencondstart)
  2680. countParams = append(countParams, sencondend)
  2681. countParams = append(countParams, threestart)
  2682. countParams = append(countParams, threeend)
  2683. countParams = append(countParams, fourstart)
  2684. countParams = append(countParams, fourend)
  2685. if orgid > 0 {
  2686. db = db.Where("x.org_id=?", orgid)
  2687. countSQL += " AND x.org_id=?"
  2688. countParams = append(countParams, orgid)
  2689. db = db.Where("x.inspect_date>=?", firststart)
  2690. countSQL += " AND x.inspect_date>=?"
  2691. countParams = append(countParams, firststart)
  2692. db = db.Where("x.inspect_date<=?", fourend)
  2693. countSQL += " AND x.inspect_date<=?"
  2694. countParams = append(countParams, fourend)
  2695. }
  2696. countSQL += ")a GROUP BY nnd"
  2697. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2698. return
  2699. }
  2700. func GetContagionQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2701. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2702. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2703. "SELECT " +
  2704. "CASE " +
  2705. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2706. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2707. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2708. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2709. " ELSE '其他'" +
  2710. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2711. countParams := make([]interface{}, 0)
  2712. countParams = append(countParams, firststart)
  2713. countParams = append(countParams, firstend)
  2714. countParams = append(countParams, sencondstart)
  2715. countParams = append(countParams, sencondend)
  2716. countParams = append(countParams, threestart)
  2717. countParams = append(countParams, threeend)
  2718. countParams = append(countParams, fourstart)
  2719. countParams = append(countParams, fourend)
  2720. if orgid > 0 {
  2721. db = db.Where("x.org_id=?", orgid)
  2722. countSQL += " AND x.org_id=?"
  2723. countParams = append(countParams, orgid)
  2724. db = db.Where("x.inspect_date>=?", firststart)
  2725. countSQL += " AND x.inspect_date>=?"
  2726. countParams = append(countParams, firststart)
  2727. db = db.Where("x.inspect_date<=?", fourend)
  2728. countSQL += " AND x.inspect_date<=?"
  2729. countParams = append(countParams, fourend)
  2730. }
  2731. countSQL += ")a GROUP BY nnd"
  2732. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2733. return
  2734. }
  2735. func GetContagionTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2736. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2737. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2738. "SELECT " +
  2739. "CASE " +
  2740. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2741. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2742. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2743. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2744. " ELSE '其他'" +
  2745. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2746. countParams := make([]interface{}, 0)
  2747. countParams = append(countParams, firststart)
  2748. countParams = append(countParams, firstend)
  2749. countParams = append(countParams, sencondstart)
  2750. countParams = append(countParams, sencondend)
  2751. countParams = append(countParams, threestart)
  2752. countParams = append(countParams, threeend)
  2753. countParams = append(countParams, fourstart)
  2754. countParams = append(countParams, fourend)
  2755. if orgid > 0 {
  2756. db = db.Where("x.org_id=?", orgid)
  2757. countSQL += " AND x.org_id=?"
  2758. countParams = append(countParams, orgid)
  2759. db = db.Where("x.inspect_date>=?", firststart)
  2760. countSQL += " AND x.inspect_date>=?"
  2761. countParams = append(countParams, firststart)
  2762. db = db.Where("x.inspect_date<=?", fourend)
  2763. countSQL += " AND x.inspect_date<=?"
  2764. countParams = append(countParams, fourend)
  2765. }
  2766. countSQL += ")a GROUP BY nnd"
  2767. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2768. return
  2769. }
  2770. func GetMonthTargetStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2771. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2772. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2773. "SELECT " +
  2774. "CASE " +
  2775. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2776. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2777. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2778. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2779. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '5'" +
  2780. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '6'" +
  2781. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '7'" +
  2782. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '8'" +
  2783. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '9'" +
  2784. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '10'" +
  2785. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '11'" +
  2786. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '12'" +
  2787. " ELSE '其他'" +
  2788. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2789. countParams := make([]interface{}, 0)
  2790. countParams = append(countParams, januaryStartStrUnix)
  2791. countParams = append(countParams, januaryEndStrUnix)
  2792. countParams = append(countParams, febStartStrStrUnix)
  2793. countParams = append(countParams, febEndStrUnix)
  2794. countParams = append(countParams, marchStartStrUnix)
  2795. countParams = append(countParams, marchEndStrUnix)
  2796. countParams = append(countParams, aprStartStrUnix)
  2797. countParams = append(countParams, aprEndStrsUnix)
  2798. countParams = append(countParams, mayStartStrUnix)
  2799. countParams = append(countParams, mayEndStrsUnix)
  2800. countParams = append(countParams, junStartStrUnix)
  2801. countParams = append(countParams, junEndStrsUnix)
  2802. countParams = append(countParams, julStartStrUnix)
  2803. countParams = append(countParams, julEndStrsUnix)
  2804. countParams = append(countParams, augStartStrUnix)
  2805. countParams = append(countParams, augEndStrsUnix)
  2806. countParams = append(countParams, sepStartStrUnix)
  2807. countParams = append(countParams, sepEndStrsUnix)
  2808. countParams = append(countParams, octStartStrUnix)
  2809. countParams = append(countParams, octEndStrsUnix)
  2810. countParams = append(countParams, novStartStrUnix)
  2811. countParams = append(countParams, novEndStrsUnix)
  2812. countParams = append(countParams, decStartStrUnix)
  2813. countParams = append(countParams, decEndStrsUnix)
  2814. if orgId > 0 {
  2815. db = db.Where("x.org_id=?", orgId)
  2816. countSQL += " AND x.org_id=?"
  2817. countParams = append(countParams, orgId)
  2818. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2819. countSQL += " AND x.inspect_date>=?"
  2820. countParams = append(countParams, januaryStartStrUnix)
  2821. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2822. countSQL += " AND x.inspect_date<=?"
  2823. countParams = append(countParams, decEndStrsUnix)
  2824. }
  2825. countSQL += ")a GROUP BY nnd"
  2826. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2827. return
  2828. }
  2829. func GetMonthTargetNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2830. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2831. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2832. "SELECT " +
  2833. "CASE " +
  2834. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2835. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2836. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2837. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2838. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '5'" +
  2839. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '6'" +
  2840. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '7'" +
  2841. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '8'" +
  2842. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '9'" +
  2843. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '10'" +
  2844. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '11'" +
  2845. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '12'" +
  2846. " ELSE '其他'" +
  2847. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2848. countParams := make([]interface{}, 0)
  2849. countParams = append(countParams, januaryStartStrUnix)
  2850. countParams = append(countParams, januaryEndStrUnix)
  2851. countParams = append(countParams, febStartStrStrUnix)
  2852. countParams = append(countParams, febEndStrUnix)
  2853. countParams = append(countParams, marchStartStrUnix)
  2854. countParams = append(countParams, marchEndStrUnix)
  2855. countParams = append(countParams, aprStartStrUnix)
  2856. countParams = append(countParams, aprEndStrsUnix)
  2857. countParams = append(countParams, mayStartStrUnix)
  2858. countParams = append(countParams, mayEndStrsUnix)
  2859. countParams = append(countParams, junStartStrUnix)
  2860. countParams = append(countParams, junEndStrsUnix)
  2861. countParams = append(countParams, julStartStrUnix)
  2862. countParams = append(countParams, julEndStrsUnix)
  2863. countParams = append(countParams, augStartStrUnix)
  2864. countParams = append(countParams, augEndStrsUnix)
  2865. countParams = append(countParams, sepStartStrUnix)
  2866. countParams = append(countParams, sepEndStrsUnix)
  2867. countParams = append(countParams, octStartStrUnix)
  2868. countParams = append(countParams, octEndStrsUnix)
  2869. countParams = append(countParams, novStartStrUnix)
  2870. countParams = append(countParams, novEndStrsUnix)
  2871. countParams = append(countParams, decStartStrUnix)
  2872. countParams = append(countParams, decEndStrsUnix)
  2873. if orgId > 0 {
  2874. db = db.Where("x.org_id=?", orgId)
  2875. countSQL += " AND x.org_id=?"
  2876. countParams = append(countParams, orgId)
  2877. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2878. countSQL += " AND x.inspect_date>=?"
  2879. countParams = append(countParams, januaryStartStrUnix)
  2880. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2881. countSQL += " AND x.inspect_date<=?"
  2882. countParams = append(countParams, decEndStrsUnix)
  2883. }
  2884. countSQL += ")a GROUP BY nnd"
  2885. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2886. return
  2887. }
  2888. func GetMonthcontagionTargeStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2889. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2890. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2891. "SELECT " +
  2892. "CASE " +
  2893. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2894. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2895. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2896. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2897. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '5'" +
  2898. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '6'" +
  2899. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '7'" +
  2900. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '8'" +
  2901. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '9'" +
  2902. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '10'" +
  2903. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '11'" +
  2904. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '12'" +
  2905. " ELSE '其他'" +
  2906. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2907. countParams := make([]interface{}, 0)
  2908. countParams = append(countParams, januaryStartStrUnix)
  2909. countParams = append(countParams, januaryEndStrUnix)
  2910. countParams = append(countParams, febStartStrStrUnix)
  2911. countParams = append(countParams, febEndStrUnix)
  2912. countParams = append(countParams, marchStartStrUnix)
  2913. countParams = append(countParams, marchEndStrUnix)
  2914. countParams = append(countParams, aprStartStrUnix)
  2915. countParams = append(countParams, aprEndStrsUnix)
  2916. countParams = append(countParams, mayStartStrUnix)
  2917. countParams = append(countParams, mayEndStrsUnix)
  2918. countParams = append(countParams, junStartStrUnix)
  2919. countParams = append(countParams, junEndStrsUnix)
  2920. countParams = append(countParams, julStartStrUnix)
  2921. countParams = append(countParams, julEndStrsUnix)
  2922. countParams = append(countParams, augStartStrUnix)
  2923. countParams = append(countParams, augEndStrsUnix)
  2924. countParams = append(countParams, sepStartStrUnix)
  2925. countParams = append(countParams, sepEndStrsUnix)
  2926. countParams = append(countParams, octStartStrUnix)
  2927. countParams = append(countParams, octEndStrsUnix)
  2928. countParams = append(countParams, novStartStrUnix)
  2929. countParams = append(countParams, novEndStrsUnix)
  2930. countParams = append(countParams, decStartStrUnix)
  2931. countParams = append(countParams, decEndStrsUnix)
  2932. if orgId > 0 {
  2933. db = db.Where("x.org_id=?", orgId)
  2934. countSQL += " AND x.org_id=?"
  2935. countParams = append(countParams, orgId)
  2936. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2937. countSQL += " AND x.inspect_date>=?"
  2938. countParams = append(countParams, januaryStartStrUnix)
  2939. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2940. countSQL += " AND x.inspect_date<=?"
  2941. countParams = append(countParams, decEndStrsUnix)
  2942. }
  2943. countSQL += ")a GROUP BY nnd"
  2944. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2945. return
  2946. }
  2947. func GetMonthcontagionTargeNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2948. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2949. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2950. "SELECT " +
  2951. "CASE " +
  2952. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2953. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2954. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2955. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2956. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '5'" +
  2957. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '6'" +
  2958. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '7'" +
  2959. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '8'" +
  2960. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '9'" +
  2961. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '10'" +
  2962. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '11'" +
  2963. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '12'" +
  2964. " ELSE '其他'" +
  2965. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2966. countParams := make([]interface{}, 0)
  2967. countParams = append(countParams, januaryStartStrUnix)
  2968. countParams = append(countParams, januaryEndStrUnix)
  2969. countParams = append(countParams, febStartStrStrUnix)
  2970. countParams = append(countParams, febEndStrUnix)
  2971. countParams = append(countParams, marchStartStrUnix)
  2972. countParams = append(countParams, marchEndStrUnix)
  2973. countParams = append(countParams, aprStartStrUnix)
  2974. countParams = append(countParams, aprEndStrsUnix)
  2975. countParams = append(countParams, mayStartStrUnix)
  2976. countParams = append(countParams, mayEndStrsUnix)
  2977. countParams = append(countParams, junStartStrUnix)
  2978. countParams = append(countParams, junEndStrsUnix)
  2979. countParams = append(countParams, julStartStrUnix)
  2980. countParams = append(countParams, julEndStrsUnix)
  2981. countParams = append(countParams, augStartStrUnix)
  2982. countParams = append(countParams, augEndStrsUnix)
  2983. countParams = append(countParams, sepStartStrUnix)
  2984. countParams = append(countParams, sepEndStrsUnix)
  2985. countParams = append(countParams, octStartStrUnix)
  2986. countParams = append(countParams, octEndStrsUnix)
  2987. countParams = append(countParams, novStartStrUnix)
  2988. countParams = append(countParams, novEndStrsUnix)
  2989. countParams = append(countParams, decStartStrUnix)
  2990. countParams = append(countParams, decEndStrsUnix)
  2991. if orgId > 0 {
  2992. db = db.Where("x.org_id=?", orgId)
  2993. countSQL += " AND x.org_id=?"
  2994. countParams = append(countParams, orgId)
  2995. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2996. countSQL += " AND x.inspect_date>=?"
  2997. countParams = append(countParams, januaryStartStrUnix)
  2998. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2999. countSQL += " AND x.inspect_date<=?"
  3000. countParams = append(countParams, decEndStrsUnix)
  3001. }
  3002. countSQL += ")a GROUP BY nnd"
  3003. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  3004. return
  3005. }
  3006. func GetQuarterBloodList(orgid int64, januaryStartStrUnix int64, januaryEndStrUnix int64) (record []*models.VmMonitoringRecord, err error) {
  3007. db := XTReadDB().Table("xt_monitoring_record as x")
  3008. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.monitoring_date,x.patient_id,x.user_org_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0", orgid, januaryStartStrUnix, januaryEndStrUnix).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3009. return record, err
  3010. }
  3011. func GetTaregetNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3012. db := XTReadDB().Table("xt_inspection as x")
  3013. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3014. return inspection, err
  3015. }
  3016. func GetConfigurationNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3017. db := XTReadDB().Table("xt_inspection as x")
  3018. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value <> d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3019. return inspection, err
  3020. }
  3021. func GetInspectNoStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3022. db := XTReadDB().Table("xt_inspection as x")
  3023. offset := (page - 1) * limit
  3024. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3025. return inspection, err
  3026. }
  3027. func GetTargetStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3028. db := XTReadDB().Table("xt_inspection as x")
  3029. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3030. return inspection, err
  3031. }
  3032. func GetConfigurationStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3033. db := XTReadDB().Table("xt_inspection as x")
  3034. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value = d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3035. return inspection, err
  3036. }
  3037. func GetStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3038. db := XTReadDB().Table("xt_inspection as x")
  3039. offset := (page - 1) * limit
  3040. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3041. return inspection, err
  3042. }
  3043. func GetDiastolicStand(orgid int64, startime int64, endtime int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3044. db := XTReadDB().Table("xt_monitoring_record as x")
  3045. offset := (page - 1) * limit
  3046. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0)", orgid, startime, endtime).Offset(offset).Limit(limit).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3047. return record, err
  3048. }
  3049. func GetInspectionMoninList(id int64, orgid int64, patientid int64) (models.XtInspection, error) {
  3050. inspection := models.XtInspection{}
  3051. err = XTReadDB().Model(&inspection).Where("item_id=? and org_id = ? and status = 1 and patient_id = ?", id, orgid, patientid).Last(&inspection).Error
  3052. return inspection, err
  3053. }
  3054. func TotalSysStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3055. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3056. if orgid > 0 {
  3057. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3058. }
  3059. if startime > 0 {
  3060. db = db.Where("x.monitoring_date>=?", startime)
  3061. }
  3062. if endtime > 0 {
  3063. db = db.Where("x.monitoring_date<=?", endtime)
  3064. }
  3065. if sysmin > 0 {
  3066. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3067. }
  3068. if syslarge > 0 {
  3069. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3070. }
  3071. if diamin > 0 {
  3072. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3073. }
  3074. if dialarge > 0 {
  3075. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3076. }
  3077. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3078. return record, err
  3079. }
  3080. func TotalSysStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3081. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3082. if orgid > 0 {
  3083. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3084. }
  3085. if startime > 0 {
  3086. db = db.Where("x.monitoring_date>=?", startime)
  3087. }
  3088. if endtime > 0 {
  3089. db = db.Where("x.monitoring_date<=?", endtime)
  3090. }
  3091. if sysmin > 0 {
  3092. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3093. }
  3094. if syslarge > 0 {
  3095. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3096. }
  3097. if diamin > 0 {
  3098. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3099. }
  3100. if dialarge > 0 {
  3101. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3102. }
  3103. offset := (page - 1) * limit
  3104. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3105. return record, err
  3106. }
  3107. func TotalSysNoStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3108. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3109. if orgid > 0 {
  3110. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3111. }
  3112. if startime > 0 {
  3113. db = db.Where("x.monitoring_date>=?", startime)
  3114. }
  3115. if endtime > 0 {
  3116. db = db.Where("x.monitoring_date<=?", endtime)
  3117. }
  3118. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3119. return record, err
  3120. }
  3121. func TotalSysNoStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3122. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3123. if orgid > 0 {
  3124. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3125. }
  3126. if startime > 0 {
  3127. db = db.Where("x.monitoring_date>=?", startime)
  3128. }
  3129. if endtime > 0 {
  3130. db = db.Where("x.monitoring_date<=?", endtime)
  3131. }
  3132. offset := (page - 1) * limit
  3133. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3134. return record, err
  3135. }
  3136. func GetModeIdCount(startime int64, endtime int64, orgid int64, page int64, limit int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3137. table := XTReadDB().Table("xt_schedule as s")
  3138. fmt.Println("table", table)
  3139. db := XTReadDB().Table("xt_dialysis_order as o")
  3140. if orgid > 0 {
  3141. db = db.Where("o.user_org_id = ?", orgid)
  3142. }
  3143. if startime > 0 {
  3144. db = db.Where("o.dialysis_date>=?", startime)
  3145. }
  3146. if endtime > 0 {
  3147. db = db.Where("o.dialysis_date<=?", endtime)
  3148. }
  3149. //offset := (page - 1) * limit
  3150. err = db.Group(" s.patient_id,s.mode_id").Select("s.mode_id, s.patient_id, count(o.id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3151. return order, err
  3152. }
  3153. func GetTreatModeList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3154. table := XTReadDB().Table("xt_schedule as s")
  3155. fmt.Println("table", table)
  3156. db := XTReadDB().Table("xt_dialysis_order as o")
  3157. if orgid > 0 {
  3158. db = db.Where("o.user_org_id = ?", orgid)
  3159. }
  3160. if startime > 0 {
  3161. db = db.Where("o.dialysis_date>=?", startime)
  3162. }
  3163. if endtime > 0 {
  3164. db = db.Where("o.dialysis_date<=?", endtime)
  3165. }
  3166. err = db.Group("s.mode_id").Select("s.mode_id, s.patient_id").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3167. return order, err
  3168. }
  3169. func GetCountModeId(startime int64, endtime int64, modeid int64, orgid int64) (order []*models.BloodTreateModeIdCount, err error) {
  3170. table := XTReadDB().Table("xt_schedule as s")
  3171. fmt.Println("table", table)
  3172. db := XTReadDB().Table("xt_dialysis_order as o")
  3173. if orgid > 0 {
  3174. db = db.Where("o.user_org_id = ?", orgid)
  3175. }
  3176. if startime > 0 {
  3177. db = db.Where("o.dialysis_date>=?", startime)
  3178. }
  3179. if endtime > 0 {
  3180. db = db.Where("o.dialysis_date<=?", endtime)
  3181. }
  3182. err = db.Group("o.dialysis_date,s.mode_id").Select("s.mode_id, count(s.mode_id) as count,o.dialysis_date").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 and s.mode_id = ? and o.dialysis_date <> ''", modeid).Scan(&order).Error
  3183. return order, err
  3184. }
  3185. func GetCountRollout(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (lapseto []*models.BloodLapsetoCount, err error) {
  3186. table := XTReadDB().Table("xt_patients as s")
  3187. fmt.Println(table)
  3188. db := XTReadDB().Table("xt_patient_lapseto as x").Where("x.status = 1")
  3189. if startime > 0 {
  3190. db = db.Where("x.lapseto_time >=?", startime)
  3191. }
  3192. if endtime > 0 {
  3193. db = db.Where("x.lapseto_time<=?", endtime)
  3194. }
  3195. if lapsetotype == 0 || sourcetype == 0 {
  3196. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ?", orgid).Scan(&lapseto).Error
  3197. }
  3198. if lapsetotype > 0 {
  3199. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.lapseto = ?", orgid, lapsetotype).Scan(&lapseto).Error
  3200. }
  3201. if sourcetype > 0 {
  3202. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.source = ?", orgid, sourcetype).Scan(&lapseto).Error
  3203. }
  3204. return lapseto, err
  3205. }