common_service.go 169KB

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