common_service.go 184KB

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