• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 20710112565

05 Jan 2026 08:56AM UTC coverage: 55.8% (-1.4%) from 57.197%
20710112565

Pull #2279

github

JFriel
Merge branch 'develop' of https://github.com/HicServices/RDMP into spike/refresh
Pull Request #2279: [UI Overhaul] Spike/refresh

11249 of 21727 branches covered (51.77%)

Branch coverage included in aggregate %.

807 of 1108 new or added lines in 29 files covered. (72.83%)

724 existing lines in 67 files now uncovered.

31893 of 55588 relevant lines covered (57.37%)

16680.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.93
/Rdmp.Core/Curation/Data/ExtractionFilter.cs
1
// Copyright (c) The University of Dundee 2018-2024
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.Data.Common;
10
using System.Linq;
11
using Rdmp.Core.Curation.Data.Cohort;
12
using Rdmp.Core.Curation.FilterImporting.Construction;
13
using Rdmp.Core.MapsDirectlyToDatabaseTable;
14
using Rdmp.Core.MapsDirectlyToDatabaseTable.Attributes;
15
using Rdmp.Core.MapsDirectlyToDatabaseTable.Injection;
16
using Rdmp.Core.Repositories;
17
using Rdmp.Core.ReusableLibraryCode;
18

19
namespace Rdmp.Core.Curation.Data;
20

21
/// <summary>
22
/// Defines as a single line SQL Where statement, a way of reducing the scope of a data extraction / aggregation etc.  For example,
23
/// 'Only prescriptions for diabetes medications'.  An ExtractionFilter can have 0 or more ExtractionFilterParameters which allows
24
/// you to define a more versatile filter e.g. 'Only prescriptions for drug @bnfCode'
25
/// 
26
/// <para>Typically an ExtractionFilter is cloned out as either a DeployedExtractionFilter or an AggregateFilter and either used as is or
27
/// customised in its new state (where its parameters might have values populated into them).</para>
28
/// 
29
/// <para>It is not uncommon for an extraction to involve multiple customised copies of the same Extraction filter for example a user might
30
/// take the filter 'Prescriptions of drug @Drugname' and make 3 copies in a given project in DataExportManager (this would result in
31
/// 3 DeployedExtractionFilters) and set the value of the first to 'Paracetamol' the second to 'Aspirin' and the third to 'Ibuprofen'
32
/// and then put them all in a single AND container.</para>
33
/// 
34
/// <para>At query building time QueryBuilder rationalizes all the various containers, subcontainers, filters and parameters into one extraction
35
/// SQL query (including whatever columns/transforms it was setup with).</para>
36
/// </summary>
37
public class ExtractionFilter : ConcreteFilter, IHasDependencies, IInjectKnown<ExtractionFilterParameterSet[]>
38
{
39
    #region Database Properties
40

41
    private int _extractionInformationID;
42
    private Lazy<ExtractionFilterParameterSet[]> _knownExtractionFilterParameterSets;
43
    private int _order;
44

45
    /// <summary>
46
    /// The column in the <see cref="Catalogue"/> which is best/most associated with this filter.  A filter can query any column in any of the table(s) under
47
    /// the <see cref="Catalogue"/> but must always be associated with only one specific extractable column (<see cref="ExtractionInformation"/>)
48
    /// </summary>
49
    [Relationship(typeof(ExtractionInformation), RelationshipType.LocalReference)]
50
    public int ExtractionInformation_ID
51
    {
52
        get => _extractionInformationID;
214✔
53
        set => SetField(ref _extractionInformationID, value);
214✔
54
    }
55

56
    #endregion
57

58
    #region Relationships
59

60
    /// <inheritdoc/>
61
    [NoMappingToDatabase]
62
    public override IContainer FilterContainer => null;
4✔
63

64
    #endregion
65

66
    /// <inheritdoc/>
67
    [NoMappingToDatabase]
68
    public override int? FilterContainer_ID
69
    {
70
        get => throw new NotSupportedException();
×
71
        set => throw new NotSupportedException();
×
72
    }
73

74
    [NoMappingToDatabase]
75
    public ExtractionFilterParameterSet[] ExtractionFilterParameterSets => _knownExtractionFilterParameterSets.Value;
30✔
76

77
    /// <inheritdoc/>
78
    public override ColumnInfo GetColumnInfoIfExists() => ExtractionInformation.ColumnInfo;
26✔
79

80
    /// <inheritdoc/>
81
    public override IFilterFactory GetFilterFactory() => new ExtractionFilterFactory(ExtractionInformation);
14✔
82

83
    /// <inheritdoc/>
84
    public override Catalogue GetCatalogue() => ExtractionInformation.CatalogueItem.Catalogue;
×
85

86
    /// <inheritdoc/>
87
    public override ISqlParameter[] GetAllParameters() => ExtractionFilterParameters.ToArray();
62✔
88

89
    #region Relationships
90

91
    /// <inheritdoc cref="ExtractionInformation_ID"/>
92
    [NoMappingToDatabase]
93
    public ExtractionInformation ExtractionInformation =>
94
        Repository.GetObjectByID<ExtractionInformation>(ExtractionInformation_ID);
62✔
95

96
    /// <inheritdoc cref="ConcreteFilter.GetAllParameters"/>
97
    [NoMappingToDatabase]
98
    public IEnumerable<ExtractionFilterParameter> ExtractionFilterParameters =>
99
        Repository.GetAllObjectsWithParent<ExtractionFilterParameter>(this);
92✔
100

101
    #endregion
102

103
    public ExtractionFilter()
×
104
    {
105
        ClearAllInjections();
×
106
    }
×
107

108
    /// <summary>
109
    /// Creates a new WHERE SQL block for reuse with the <see cref="Catalogue"/> in which the <paramref name="parent"/> resides.  This is a top level master filter and can be
110
    /// copied out in <see cref="CohortIdentificationConfiguration"/>, ExtractionConfiguration etc.  This ensures a single curated block of
111
    /// logic that everyone shares.
112
    /// </summary>
113
    /// <param name="repository"></param>
114
    /// <param name="name"></param>
115
    /// <param name="parent"></param>
116
    public ExtractionFilter(ICatalogueRepository repository, string name, ExtractionInformation parent)
76✔
117
    {
118
        name ??= $"New Filter {Guid.NewGuid()}";
76!
119

120
        repository.InsertAndHydrate(this, new Dictionary<string, object>
76✔
121
        {
76✔
122
            { "Name", name },
76✔
123
            { "ExtractionInformation_ID", parent.ID }
76✔
124
        });
76✔
125

126
        ClearAllInjections();
76✔
127
    }
76✔
128

129
    internal ExtractionFilter(ICatalogueRepository repository, DbDataReader r)
130
        : base(repository, r)
138✔
131
    {
132
        ExtractionInformation_ID = int.Parse(r["ExtractionInformation_ID"].ToString());
138✔
133
        WhereSQL = r["WhereSQL"] as string;
138✔
134
        Description = r["Description"] as string;
138✔
135
        Name = r["Name"] as string;
138✔
136
        IsMandatory = (bool)r["IsMandatory"];
138✔
137
        Order = (int)ObjectToNullableInt(r["Order"]);
138✔
138

139

140
        ClearAllInjections();
138✔
141
    }
138✔
142

143
    /// <inheritdoc/>
144
    public override string ToString() => Name;
22✔
145

146
    //we are an extraction filter ourselves! so obviously we weren't cloned from one! (this is for aggregate and data export filters and satisfies IFilter).  Actually we can
147
    //be cloned via the publishing (elevation) from a custom filter defined at Aggregate level for example.  But in this case we don't need to know the ID anyway since we
148
    //become the new master anyway since we are at the highest level for filters
149

150
    /// <summary>
151
    /// Returns null, <see cref="ExtractionFilter"/> are master level filters and therefore never cloned from another filter
152
    /// </summary>
153
    [NoMappingToDatabase]
154
    public override int? ClonedFromExtractionFilter_ID
155
    {
156
        get => null;
×
157
        set => throw new NotSupportedException(
×
158
            "ClonedFromExtractionFilter_ID is only supported on lower level filters e.g. DeployedExtractionFilter and AggregateFilter");
×
159
    }
160
    public override int Order { get => _order; set => SetField(ref _order,value); }
322✔
161

162
    /// <inheritdoc/>
163
    public IHasDependencies[] GetObjectsThisDependsOn()
164
    {
165
        return new IHasDependencies[] { ExtractionInformation };
×
166
    }
167

168
    /// <inheritdoc/>
169
    public IHasDependencies[] GetObjectsDependingOnThis() => ExtractionFilterParameters.ToArray();
20✔
170

171
    public void InjectKnown(ExtractionFilterParameterSet[] instance)
172
    {
UNCOV
173
        _knownExtractionFilterParameterSets = new Lazy<ExtractionFilterParameterSet[]>(instance);
×
UNCOV
174
    }
×
175

176
    public void ClearAllInjections()
177
    {
178
        _knownExtractionFilterParameterSets = new Lazy<ExtractionFilterParameterSet[]>(() =>
216✔
179
            CatalogueRepository.GetAllObjectsWithParent<ExtractionFilterParameterSet>(this));
244✔
180
    }
216✔
181

182
    public override void DeleteInDatabase()
183
    {
184
        if (ExtractionFilterParameterSets.Any())
22✔
185
            throw new Exception(
2✔
186
                $"Cannot delete '{this}' because there are one or more {nameof(ExtractionFilterParameterSet)} declared on it");
2✔
187

188
        base.DeleteInDatabase();
20✔
189
    }
20✔
190
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc