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

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

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

78.85
/Rdmp.Core/Curation/Data/ExtractionFilter.cs
1
// Copyright (c) The University of Dundee 2018-2019
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

44
    /// <summary>
45
    /// 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
46
    /// the <see cref="Catalogue"/> but must always be associated with only one specific extractable column (<see cref="ExtractionInformation"/>)
47
    /// </summary>
48
    [Relationship(typeof(ExtractionInformation), RelationshipType.LocalReference)]
49
    public int ExtractionInformation_ID
50
    {
51
        get => _extractionInformationID;
1,672✔
52
        set => SetField(ref _extractionInformationID, value);
224✔
53
    }
54

55
    #endregion
56

57
    #region Relationships
58

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

63
    #endregion
64

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

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

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

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

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

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

88
    #region Relationships
89

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

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

100
    #endregion
101

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

107
    /// <summary>
108
    /// 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
109
    /// copied out in <see cref="CohortIdentificationConfiguration"/>, ExtractionConfiguration etc.  This ensures a single curated block of
110
    /// logic that everyone shares.
111
    /// </summary>
112
    /// <param name="repository"></param>
113
    /// <param name="name"></param>
114
    /// <param name="parent"></param>
115
    public ExtractionFilter(ICatalogueRepository repository, string name, ExtractionInformation parent)
76✔
116
    {
117
        name ??= $"New Filter {Guid.NewGuid()}";
76!
118

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

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

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

137
        ClearAllInjections();
148✔
138
    }
148✔
139

140
    /// <inheritdoc/>
141
    public override string ToString() => Name;
20✔
142

143
    //we are an extraction filter ourselves! so obviously we werent cloned from one! (this is for aggregate and data export filters and satisfies IFilter).  Actually we can
144
    //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
145
    //become the new master anyway since we are at the highest level for filters
146

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

158
    /// <inheritdoc/>
159
    public IHasDependencies[] GetObjectsThisDependsOn()
160
    {
161
        return new IHasDependencies[] { ExtractionInformation };
×
162
    }
163

164
    /// <inheritdoc/>
165
    public IHasDependencies[] GetObjectsDependingOnThis() => ExtractionFilterParameters.ToArray();
20✔
166

167
    public void InjectKnown(ExtractionFilterParameterSet[] instance)
168
    {
169
        _knownExtractionFilterParameterSets = new Lazy<ExtractionFilterParameterSet[]>(instance);
30✔
170
    }
30✔
171

172
    public void ClearAllInjections()
173
    {
174
        _knownExtractionFilterParameterSets = new Lazy<ExtractionFilterParameterSet[]>(() =>
226✔
175
            CatalogueRepository.GetAllObjectsWithParent<ExtractionFilterParameterSet>(this));
252✔
176
    }
226✔
177

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

184
        base.DeleteInDatabase();
20✔
185
    }
20✔
186
}
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