-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Pro_HisPatient](
@REQ_PROCNO uniqueidentifier,
@hospitalno nvarchar(64)=null
)
AS
BEGIN
SET NOCOUNT ON;
declare @patname nvarchar(1000)
declare @hisid nvarchar(1000)
declare @idcard nvarchar(1000)
declare @patientid nvarchar(1000)
declare @mk uniqueidentifier
declare @tb as table(mk uniqueidentifier)
declare @modality as nvarchar(100)
SELECT @patname=p.PATNAME,@hisid=p.HISID,@idcard=p.IDCARDNO,@mk=i.SERV_REGNO,@patientid=p.PATIENTID,@modality=o.MODALITY
from R_PATIENT p
join IMG_SERV_REG i on p.PATIENTNO=i.PATIENTNO
join REQ_PROC o on o.SERV_REGNO=i.SERV_REGNO where REQ_PROCNO=@REQ_PROCNO
print @patname
print @hisid
print @idcard
print @mk
print @patientid
print @modality
print @patientid
--身份证号
if(@idcard is not null and @idcard<>'' and (LEN(@idcard)=18 or len(@idcard)=15))
begin
--hisid
if(@hisid is not null and @hisid<>'')
begin
insert into @tb
SELECT distinct MERGER_FK FROM V_REPORTLIST WHERE (PATIENTID=@patientid or IDCARDNO=@idcard or HISID=@hisid)
end
else
begin
insert into @tb
SELECT distinct MERGER_FK FROM V_REPORTLIST WHERE (PATIENTID=@patientid or IDCARDNO=@idcard )
end
end
else
begin
--hisid
if(@hisid is not null and @hisid<>'')
begin
insert into @tb
SELECT distinct MERGER_FK FROM V_REPORTLIST WHERE (PATIENTID=@patientid or HISID=@hisid)
end
else
begin
insert into @tb
SELECT distinct MERGER_FK FROM V_REPORTLIST WHERE (PATIENTID=@patientid )
end
end
--select * from @tb
select v.*,dbo.GetAllExamitem(v.REQ_PROCNO) AllDirection
from V_REPORTLIST v
join @tb b on v.MERGER_FK=b.mk
left join T_OrderLink l on l.REQ_PROCNO= v.REQ_PROCNO and l.ISSAVE=1
where 1=1
and (l.Main_REQ_PROCNO is null or l.REQ_PROCNO=l.Main_REQ_PROCNO)
and STATUS in ( '已诊断', '已审核', '已终审', '已打印')
and v.REQ_PROCNO <> @REQ_PROCNO and PATNAME=@patname
order by v.STUDY_DATE DESC
END
CREATE VIEW [dbo].[V_REPORTLIST]
AS
SELECT c.STUDY_DATE, c.MODALITY, c.PARTOFCHECK,
p.PATIENTID, p.PATNAME, i.ACCESSION_NO, c.STATUS,
c.REQ_PROC_ID, '' AS PROC_DETAILNO, p.MERGER_FK, p.PATIENTNO,
i.SERV_REGNO, c.REQ_PROCNO, r.REPORTNO,
p.HISID, c.STUDY_INS_UID, i.ACCESSION_DATE, i.ADM_ID_ISS,
c.ALLPARTOFCHECK,c.STUDY_DATE as CHECKDATE,i.ADM_ID,p.IDCARDNO,i.PAT_AGE,i.EXIGENCE,p.SEX
FROM dbo.R_PATIENT p
INNER JOIN dbo.IMG_SERV_REG i ON p.PATIENTNO = i.PATIENTNO
INNER JOIN dbo.REQ_PROC c ON i.SERV_REGNO = c.SERV_REGNO
INNER JOIN dbo.GENERAL_REPORT r ON c.REQ_PROCNO = r.REQ_PROCNO
WHERE (c.STATUS IN ( '已诊断', '诊断中', '审核中', '审核退回', '已审核', '已终审', '已打印')) AND
(c.DELETE_SIGN = '1')
and i.OFDEPARTMENT<>'FSK'
union all
SELECT c.STUDY_DATE, c.MODALITY, c.PARTOFCHECK,
p.PATIENTID, p.PATNAME, i.ACCESSION_NO, c.STATUS,
c.REQ_PROC_ID, '' AS PROC_DETAILNO, p.MERGER_FK, p.PATIENTNO,
i.SERV_REGNO, c.REQ_PROCNO, r.REPORTNO,
p.HISID, c.STUDY_INS_UID, i.ACCESSION_DATE, i.ADM_ID_ISS,
c.ALLPARTOFCHECK,c.STUDY_DATE as CHECKDATE,i.ADM_ID,p.IDCARDNO,i.PAT_AGE,i.EXIGENCE,p.SEX
FROM dbo.R_PATIENT p
INNER JOIN dbo.IMG_SERV_REG i ON p.PATIENTNO = i.PATIENTNO
INNER JOIN dbo.REQ_PROC c ON i.SERV_REGNO = c.SERV_REGNO
INNER JOIN dbo.GENERAL_REPORT r ON c.REQ_PROCNO = r.REQ_PROCNO
WHERE (c.STATUS IN ('已检查','处理中', '已诊断', '诊断中', '审核中', '审核退回', '已审核', '已终审', '已打印')) AND
(c.DELETE_SIGN = '1')
and i.OFDEPARTMENT='FSK'