irc-netcore-api/IRaCIS.Core.Domain/SQLFile/Sql脚本.sql

113 lines
6.4 KiB
Transact-SQL

-----2022-05-27------------------------
update DataInspection set BatchId=Id where BatchId is null
update QCChallenge set Code=ChallengeCode
update QCChallenge set ChallengeCode='Q'+ RIGHT('00000'+CAST( Code AS nvarchar(50)),5);
-----2022-08-11------------------------
update [dbo].[Site] set Code= convert(int,RIGHT(SiteCode,4))
update Site set SiteName= substring(SiteName,1,charindex('医院',SiteName)+1),AliasName=substring(SiteName,charindex('医院',SiteName)+2,30) where SiteName like '%医院%医院'
update Doctor set Physician='Chief Physician',PhysicianCN='主任医师' where RankId='dcbf4d1a-8373-4539-a0ae-1ba76d57bb48'
update Doctor set Physician='Deputy Chief Physician',PhysicianCN='副主任医师' where RankId='3a6e3335-cea4-4803-a136-d6301883a937'
update Doctor set RankOther='Professor',RankOtherCN='教授' where RankId='dcbf4d1a-8373-4539-a0ae-1ba76d57bb48'
update Doctor set RankOther='Associate Professor',RankOtherCN='副教授' where RankId='3a6e3335-cea4-4803-a136-d6301883a937'
update Doctor set Physician='Staff',PhysicianCN='医师' where RankId='82411c2e-9832-4c6f-a859-e3b6e796760d'
update DataInspection set JsonDetail= replace(cast(JsonDetail as varchar(max)),'Insepection','CommonData')
update ReadingClinicalData set FileCount=(select count(*) from ReadingClinicalDataPDF where ReadingClinicalDataId =ReadingClinicalData.Id)
update NoneDicomStudy set FileCount=(select count(*) from NoneDicomStudyFile where NoneDicomStudyId =NoneDicomStudy.Id)
update DataInspection set CreateUserName= (select UserName from [User] where [User].Id = DataInspection.CreateUserId)
update DataInspection set RoleName=(select UserName from [User] INNER join UserType on [User].UserTypeId =UserType.Id where [User].Id=DataInspection.CreateUserId)
update DataInspection set CreateUserRealName=(select LastName+' / '+FirstName from [User] where [User].Id=DataInspection.CreateUserId)
update TrialDocUserTypeConfirmedUser set CreateUserId=ConfirmUserId,CreateTime=SignFirstViewTime
update SystemDocConfirmedUser set CreateUserId=ConfirmUserId,CreateTime=SignFirstViewTime
update TrialDocUserTypeConfirmedUser set CreateUserId=ConfirmUserId,CreateTime=getdate() where SignFirstViewTime is null
update SystemDocConfirmedUser set CreateUserId=ConfirmUserId,CreateTime=getdate() where SignFirstViewTime is null
update TrialDocUserTypeConfirmedUser set IsDeleted=0 where IsDeleted is null
update SystemDocConfirmedUser set IsDeleted=0 where IsDeleted is null
update EnrollReadingCategory set TrialReadingCriterionId= ISNUll((select top 1 Id from ReadingQuestionCriterionTrial where IsConfirm=1 and TrialId=Enroll.TrialId ) ,'00000000-0000-0000-0000-000000000000')
FROM EnrollReadingCategory INNER JOIN Enroll ON (EnrollReadingCategory.EnrollId = Enroll.Id)
update VisitTask set TrialReadingCriterionId=(select top 1 Id from ReadingQuestionCriterionTrial where IsConfirm=1 and TrialId=VisitTask.TrialId)
select * from EnrollReadingCategory where TrialReadingCriterionId is null
select * from VisitTask where TrialReadingCriterionId is null
update Site set Site.Code = (select b.code2 from (select Id,row_number() over(order by Site.SiteName) code2 from Site) b where b.Id =Site.Id)
update Site set SiteCode= 'S'+ RIGHT('0000'+CAST(Site.Code as varchar(10)),4)
-----------------------------------------之前的-------------------------------------------------------------
--无序维护sql
update VisitTask set TaskBlindName='Follow Up '
from VisitTask
INNER join ReadingQuestionCriterionTrial on VisitTask.TrialReadingCriterionId=ReadingQuestionCriterionTrial.Id
INNER join SubjectVisit on VisitTask.SourceSubjectVisitId=SubjectVisit.Id
where SubjectVisit.IsBaseLine=0 and ReadingQuestionCriterionTrial.IsReadingTaskViewInOrder=0
-- 有序维护sql
update VisitTask set TaskBlindName='Follow Up '+ cast(sv.rn as varchar)
from VisitTask
join ReadingQuestionCriterionTrial on VisitTask.TrialReadingCriterionId=ReadingQuestionCriterionTrial.Id
--join SubjectVisit on VisitTask.SourceSubjectVisitId=SubjectVisit.Id
join ( select Id SubjectVisitId, IsBaseLine, ROW_NUMBER() over( partition by SubjectId order by VisitNum asc )-1 rn,VisitNum from SubjectVisit) sv on VisitTask.SourceSubjectVisitId=sv.SubjectVisitId
where sv.IsBaseLine=0 and ReadingQuestionCriterionTrial.IsReadingTaskViewInOrder=1
update VisitTask set TaskBlindName='Baseline' from VisitTask xiuga
join SubjectVisit on VisitTask.SourceSubjectVisitId=SubjectVisit.Id where SubjectVisit.IsBaseLine=1
----------------------------------------------修改 ----------------------------------------
update Dictionary set code =0 where Id='15bb5529-a6fe-439f-5196-08da179a7080'
update Dictionary set code =1 where Id='0628d7be-afba-4471-5197-08da179a7080'
update Dictionary set code =2 where Id='41bfec4b-dbfb-401d-5198-08da179a7080'
update Dictionary set code =-1 where Id='1fac678d-69b6-41c3-5199-08da179a7080'
go
update ReadingQuestionCriterionTrial set DigitPlaces=DigitPlaces-1 where DigitPlaces is not null
update ReadingQuestionCriterionTrial set DigitPlaces=-1 where DigitPlaces=3
--阅片标准维护
update DataInspection set ObjectRelationParentId3 = (select top 1 TrialReadingCriterionId from SubjectUser where Id =DataInspection.GeneralId) where EntityName='SubjectUser'
update DataInspection set ObjectRelationParentId2 = (select top 1 TrialReadingCriterionId from ReadingPeriodSet where Id =DataInspection.GeneralId) where EntityName='ReadingPeriodSet'
update DataInspection set ObjectRelationParentId2 = (select top 1 TrialReadingCriterionId from ReadModule where Id =DataInspection.GeneralId) where EntityName='ReadModule'
update DataInspection set ObjectRelationParentId2 = (select top 1 TrialReadingCriterionId from TaskConsistentRule where Id =DataInspection.GeneralId) where EntityName='TaskConsistentRule'
update DataInspection set ObjectRelationParentId3 = (select top 1 TrialReadingCriterionId from VisitTask where Id =DataInspection.GeneralId) where EntityName='VisitTask'
update ReadingTableQuestionTrial set DictionaryCode='' where DictionaryCode is null
--维护RowInfo的OrderMark
select * from ReadingTableAnswerRowInfo
update ReadingTableAnswerRowInfo set ReadingTableAnswerRowInfo.OrderMark=ReadingQuestionTrial.OrderMark from ReadingQuestionTrial
inner join ReadingTableAnswerRowInfo on ReadingTableAnswerRowInfo.QuestionId=ReadingQuestionTrial.Id