医院数据库:查找出现在多个健康记录上的健康卡号实例

时间:2018-10-19 18:58:54

标签: sql ms-access

在安大略省,每位居民都获得一个健康卡号(HCN)。 在我们医院,为患者分配了病历号(MRN)。

我要查找一个实例,其中一个HCN出现在多个MRN上(这可能是由职员创建新的MRN导致的,即使患者/ HCN已经存在一个新的MRN也是如此。)

我希望输出仅列出创建的每个“重复” MRN的一个示例,以及其他数据,以便就是否合并记录做出良好,快速的决定(例如:生日,姓名,地址字段) ,电子邮件地址)。

我的表格包括:

  • MRN,姓名,出生日期列表
  • 将MRN链接到以下表中使用的“唯一记录号”(Urn)的表
  • 缸和HCN列表
  • 骨灰盒和患者地址列表

我正在使用Microsoft Access,并已建立关系。我尝试了一些不同的代码,但可以使用一些帮助。我仍在学习SQL,现在还无法正确使用它。

这是Access生成的基准代码:

SELECT [HCN, Mri Urn].[Edited HCN], [MRN, Name, DOB].[Medical Record],
   [MRN, Name, DOB].Name, [MRN, Name, DOB].Birthdate, 
   [Pat Address, Adm Urn].[Pat City], [Pat Address, Adm Urn].[Pat Street],
   [Pat Address, Adm Urn].[Pat Street2], [Pat Address, Adm Urn].[Pat Email],
   [Pat Address, Adm Urn].[Pat Home Phone]
FROM [Pat Address, Adm Urn] 
INNER JOIN ([MRN, Name, DOB] 
INNER JOIN ([HCN, Mri Urn] 
INNER JOIN [ADM's Mri Urn-Adm Urn link] 
   ON [HCN, Mri Urn].Urn = [ADM's Mri Urn-Adm Urn link].[Mri Urn]) 
   ON [MRN, Name, DOB].[Medical Record] = [ADM's Mri Urn-Adm Urn link].[Mri Urn]) 
   ON [Pat Address, Adm Urn].Urn = [ADM's Mri Urn-Adm Urn link].Urn
ORDER BY [HCN, Mri Urn].[Edited HCN], 
   [MRN, Name, DOB].[Medical Record], 
   [MRN, Name, DOB].Name, 
   [MRN, Name, DOB].Birthdate, 
   [Pat Address, Adm Urn].[Pat City], 
   [Pat Address, Adm Urn].[Pat Street], 
   [Pat Address, Adm Urn].[Pat Street2], 
   [Pat Address, Adm Urn].[Pat Email], 
   [Pat Address, Adm Urn].[Pat Home Phone];

1 个答案:

答案 0 :(得分:0)

由于它们的命名,您的表很难遵循:)我不确定这是否是您的意思(没有任何示例数据会更难理解):

SELECT 
[HCN, Mri Urn].[Edited HCN],
       [MRN, Name, DOB].[Medical Record],
       [MRN, Name, DOB].Name,
       [MRN, Name, DOB].Birthdate,
       [Pat Address, Adm Urn].[Pat City],
       [Pat Address, Adm Urn].[Pat Street],
       [Pat Address, Adm Urn].[Pat Street2],
       [Pat Address, Adm Urn].[Pat Email],
       [Pat Address, Adm Urn].[Pat Home Phone]
FROM [Pat Address, Adm Urn]
    INNER JOIN([MRN, Name, DOB]
    INNER JOIN([HCN, Mri Urn]
    INNER JOIN [ADM's Mri Urn-Adm Urn link]
        ON [HCN, Mri Urn].Urn = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
        ON [MRN, Name, DOB].[Medical Record] = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
        ON [Pat Address, Adm Urn].Urn = [ADM's Mri Urn-Adm Urn link].Urn
where  [ADM's Mri Urn-Adm Urn link].Urn in 
(select urn from  [ADM's Mri Urn-Adm Urn link]
group by URN having count(*) > 1)
ORDER BY [HCN, Mri Urn].[Edited HCN],
         [MRN, Name, DOB].[Medical Record],
         [MRN, Name, DOB].Name,
         [MRN, Name, DOB].Birthdate,
         [Pat Address, Adm Urn].[Pat City],
         [Pat Address, Adm Urn].[Pat Street],
         [Pat Address, Adm Urn].[Pat Street2],
         [Pat Address, Adm Urn].[Pat Email],
         [Pat Address, Adm Urn].[Pat Home Phone];