• 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

57.75
/Rdmp.Core/QueryBuilding/ReleaseIdentifierSubstitution.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.Text.RegularExpressions;
9
using FAnsi.Discovery.QuerySyntax;
10
using Rdmp.Core.Curation.Data;
11
using Rdmp.Core.Curation.Data.Spontaneous;
12
using Rdmp.Core.DataExport.Data;
13
using Rdmp.Core.MapsDirectlyToDatabaseTable;
14
using Rdmp.Core.MapsDirectlyToDatabaseTable.Attributes;
15
using Rdmp.Core.QueryBuilding.SyntaxChecking;
16
using Rdmp.Core.ReusableLibraryCode.Checks;
17

18
namespace Rdmp.Core.QueryBuilding;
19

20
/// <summary>
21
/// Records how (via SQL) replace the private patient identifier column (e.g. CHI) with the release identifier (e.g. swap [biochemistry]..[chi] for
22
/// [cohort]..[ReleaseId]).  Also includes the Join SQL string for linking the cohort table (which contains the ReleaseId e.g. [cohort]) with the dataset
23
/// table (e.g. [biochemistry]).
24
/// 
25
/// <para>This class is an IColumn and is designed to be added as a new Column to a QueryBuilder as normal (See ExtractionQueryBuilder)</para>
26
/// </summary>
27
public class ReleaseIdentifierSubstitution : SpontaneousObject, IColumn
28
{
29
    public string JoinSQL { get; private set; }
224✔
30

31
    /// <summary>
32
    /// The identifiable column which is being substituted on
33
    /// </summary>
34
    public IColumn OriginalDatasetColumn;
35

36
    private readonly IQuerySyntaxHelper _querySyntaxHelper;
37

38
    [Sql] public string SelectSQL { get; set; }
476✔
39

40
    public string Alias { get; private set; }
1,352✔
41

42
    //all these are hard coded to null or false really
43
    public ColumnInfo ColumnInfo => OriginalDatasetColumn.ColumnInfo;
112✔
44

45
    public int Order
46
    {
47
        get => OriginalDatasetColumn.Order;
208✔
48
        set { }
×
49
    }
50

51
    public bool HashOnDataRelease => false;
126✔
52
    public bool IsExtractionIdentifier => OriginalDatasetColumn.IsExtractionIdentifier;
×
53
    public bool IsPrimaryKey => OriginalDatasetColumn.IsPrimaryKey;
16✔
54

55
    public ReleaseIdentifierSubstitution(MemoryRepository repo, IColumn extractionIdentifierToSubFor,
56
        IExtractableCohort extractableCohort, bool isPartOfMultiCHISubstitution,
57
        IQuerySyntaxHelper querySyntaxHelper) : base(repo)
112✔
58
    {
59
        if (!extractionIdentifierToSubFor.IsExtractionIdentifier)
112!
60
            throw new Exception(
×
61
                $"Column {extractionIdentifierToSubFor} is not marked IsExtractionIdentifier so cannot be substituted for a ReleaseIdentifier");
×
62

63
        OriginalDatasetColumn = extractionIdentifierToSubFor;
112✔
64
        _querySyntaxHelper = querySyntaxHelper;
112✔
65
        if (OriginalDatasetColumn.ColumnInfo == null)
112!
66
            throw new Exception(
×
67
                $"The column {OriginalDatasetColumn.GetRuntimeName()} references a ColumnInfo that has been deleted");
×
68

69
        var syntaxHelper = extractableCohort.GetQuerySyntaxHelper();
112✔
70

71
        //the externally referenced Cohort table
72
        var privateCol = extractableCohort.ExternalCohortTable.DiscoverPrivateIdentifier();
112✔
73

74
        var collateStatement = "";
112✔
75

76
        //the release identifier join might require collation
77

78
        //if the private has a collation
79
        if (!string.IsNullOrWhiteSpace(privateCol.Collation))
112✔
80
        {
81
            var cohortCollation = privateCol.Collation;
112✔
82
            var otherTableCollation = OriginalDatasetColumn.ColumnInfo.Collation;
112✔
83

84

85
            //only collate if the server types match and if the collations differ
86
            if (privateCol.Table.Database.Server.DatabaseType ==
112✔
87
                OriginalDatasetColumn.ColumnInfo.TableInfo.DatabaseType)
112✔
88
                if (!string.IsNullOrWhiteSpace(otherTableCollation) &&
112!
89
                    !string.Equals(cohortCollation, otherTableCollation))
112✔
90
                    collateStatement = $" collate {cohortCollation}";
×
91
        }
92

93

94
        if (!isPartOfMultiCHISubstitution)
112!
95
        {
96
            SelectSQL = extractableCohort.GetReleaseIdentifier();
112✔
97
            Alias = syntaxHelper.GetRuntimeName(SelectSQL);
112✔
98
        }
99
        else
100
        {
101
            SelectSQL =
×
102
                $"(SELECT DISTINCT {extractableCohort.GetReleaseIdentifier()} FROM {privateCol.Table.GetFullyQualifiedName()} WHERE {extractableCohort.WhereSQL()} AND {privateCol.GetFullyQualifiedName()}={OriginalDatasetColumn.SelectSQL}{collateStatement})";
×
103

104
            if (!string.IsNullOrWhiteSpace(OriginalDatasetColumn.Alias))
×
105
            {
106
                var toReplace = extractableCohort.GetPrivateIdentifier(true);
×
107
                var toReplaceWith = extractableCohort.GetReleaseIdentifier(true);
×
108

109
                //take the same name as the underlying column
110
                Alias = OriginalDatasetColumn.Alias;
×
111

112
                //but replace all instances of CHI with PROCHI (or Barcode, or whatever)
113
                if (!Alias.Contains(toReplace) || Regex.Matches(Alias, Regex.Escape(toReplace)).Count > 1)
×
114
                    throw new Exception(
×
115
                        $"Failed to resolve multiple extraction identifiers in dataset.  Either mark a single column as the IsExtractionIdentifier for this extraction or ensure all columns are of compatible type and have the text \"{toReplace}\" appearing once (and only once in its name)");
×
116

117
                Alias = Alias.Replace(toReplace, toReplaceWith);
×
118
            }
119
            else
120
            {
121
                throw new Exception(
×
122
                    $"In cases where you have multiple columns marked IsExtractionIdentifier, they must all have Aliases, the column {OriginalDatasetColumn.SelectSQL} does not have one");
×
123
            }
124
        }
125

126
        JoinSQL = $"{OriginalDatasetColumn.SelectSQL}={privateCol.GetFullyQualifiedName()}{collateStatement}";
112✔
127
    }
112✔
128

129
    public string GetRuntimeName() =>
130
        string.IsNullOrWhiteSpace(Alias) ? _querySyntaxHelper.GetRuntimeName(SelectSQL) : Alias;
242!
131

132
    public void Check(ICheckNotifier notifier)
133
    {
134
        new ColumnSyntaxChecker(this).Check(notifier);
126✔
135
    }
126✔
136
}
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