Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Oct 18, 2024
1 parent dc4ea40 commit 43d2008
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Rdmp.Core.Curation.Data.Datasets;

/// <inheritdoc/>
public class DatasetProviderConfiguration : DatabaseEntity, IDatasetProviderConfiguration
{

Expand Down
30 changes: 23 additions & 7 deletions Rdmp.Core/Curation/Data/Datasets/IDatasetProviderConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
using Org.BouncyCastle.Bcpg.OpenPgp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rdmp.Core.MapsDirectlyToDatabaseTable;

namespace Rdmp.Core.Curation.Data.Datasets;

public interface IDatasetProviderConfiguration

/// <summary>
/// Remords configuration for accessing external dataset providers, such as PURE
/// </summary>
public interface IDatasetProviderConfiguration: IMapsDirectlyToDatabaseTable
{
/// <summary>
/// The assembly name of the provider this configuration is used for
/// </summary>
public string Type { get; }

/// <summary>
/// A friendly name for the configuration
/// </summary>
public string Name { get; }

/// <summary>
/// The API url
/// </summary>
public string Url { get; }

/// <summary>
/// Reference to which credentials should be used to access the API
/// </summary>
public int DataAccessCredentials_ID { get; }

/// <summary>
/// The organisation ID to use with the remote provider
/// </summary>
public string Organisation_ID { get; }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Rdmp.Core.DataLoad.Engine.Mutilators;
using Rdmp.Core.DataLoad.Triggers;
using Rdmp.Core.Datasets;
using Rdmp.Core.Datasets.PureItems;

Check failure on line 13 in Rdmp.Core/DataLoad/Modules/Mutilators/PostLoad/PureDatasetPostLoadUpdater.cs

View workflow job for this annotation

GitHub Actions / Bundle Build

The type or namespace name 'PureItems' does not exist in the namespace 'Rdmp.Core.Datasets' (are you missing an assembly reference?)
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using Rdmp.Core.QueryBuilding;
using Rdmp.Core.ReusableLibraryCode.Checks;
Expand All @@ -25,6 +26,10 @@

namespace Rdmp.Core.DataLoad.Modules.Mutilators.PostLoad
{
/// <summary>
/// Used to update a Pure dataset with updated temporal data to include the new records
/// and update the description of the dataset
/// </summary>
public class PureDatasetPostLoadUpdater : IMutilateDataTables
{
private readonly string _type = typeof(PureDatasetProvider).ToString();
Expand Down Expand Up @@ -97,7 +102,7 @@ public ExitCodeType Mutilate(IDataLoadJob job)

var dt = new DataTable();
dt.BeginLoadData();
var server = catalogue.GetDistinctLiveDatabaseServer(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad,false);
var server = catalogue.GetDistinctLiveDatabaseServer(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad, false);
var con = server.GetConnection();
con.Open();
using (var cmd = server.GetCommand(sql, con))
Expand All @@ -106,7 +111,7 @@ public ExitCodeType Mutilate(IDataLoadJob job)
da.Fill(dt);
}
dt.EndLoadData();
if (dt.Rows.Count ==0) return ExitCodeType.OperationNotRequired;
if (dt.Rows.Count == 0) return ExitCodeType.OperationNotRequired;
_newRecordsCount = dt.Rows.Count;
_earliestDate = new PureDate(dt.AsEnumerable().Min(row => DateTime.Parse(row[0].ToString())));
_latestDate = new PureDate(dt.AsEnumerable().Max(row => DateTime.Parse(row[0].ToString())));
Expand All @@ -130,10 +135,10 @@ public ExitCodeType Mutilate(IDataLoadJob job)
private TemporalCoveragePeriod GetTemporalCoveragePeriod()
{
var coverage = _pureDataset.TemporalCoveragePeriod ?? new TemporalCoveragePeriod();
if(_pureDataset.TemporalCoveragePeriod is null || _pureDataset.TemporalCoveragePeriod.StartDate is null || _earliestDate.IsBefore(_pureDataset.TemporalCoveragePeriod.StartDate))
if (_pureDataset.TemporalCoveragePeriod is null || _pureDataset.TemporalCoveragePeriod.StartDate is null || _earliestDate.IsBefore(_pureDataset.TemporalCoveragePeriod.StartDate))
coverage.StartDate = _earliestDate;

if(_pureDataset.TemporalCoveragePeriod is null || _pureDataset.TemporalCoveragePeriod.EndDate is null || _pureDataset.TemporalCoveragePeriod.EndDate.IsBefore(_latestDate))
if (_pureDataset.TemporalCoveragePeriod is null || _pureDataset.TemporalCoveragePeriod.EndDate is null || _pureDataset.TemporalCoveragePeriod.EndDate.IsBefore(_latestDate))
coverage.EndDate = _latestDate;
return coverage;
}
Expand All @@ -150,7 +155,7 @@ private List<PureDescription> GetDescriptions()
var datasetDescriptionTerm = "/dk/atira/pure/dataset/descriptions/datasetdescription";
foreach (var description in _pureDataset.Descriptions.Where(d => d.Term.URI == datasetDescriptionTerm))
{
description.Value.en_GB += @$"
description.Value.En_GB += @$"
{GetUpdateText()}";
descriptions.Add(description);
}
Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core/Datasets/DatasetConfigurationUICommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using Rdmp.Core.CommandExecution;

namespace Rdmp.Core.Dataset;
namespace Rdmp.Core.Datasets;

/// <summary>
/// Common methods used by Cohort Builder UI implementations. Eliminates
Expand Down
22 changes: 15 additions & 7 deletions Rdmp.Core/Datasets/IDatasetProvider.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
using Rdmp.Core.Curation.Data.Datasets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rdmp.Core.Datasets;

/// <summary>
/// Base interface for dataset providers to impliment
/// </summary>
public interface IDatasetProvider
{

List<Curation.Data.Datasets.Dataset> FetchDatasets();
/// <summary>
/// Fetch known datasets
/// </summary>
/// <returns></returns>
List<Dataset> FetchDatasets();


Curation.Data.Datasets.Dataset FetchDatasetByID(int id);
/// <summary>
/// Fetch a specific dataset by its ID
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Dataset FetchDatasetByID(int id);

}
8 changes: 5 additions & 3 deletions Rdmp.Core/Datasets/InternalDatasetProvider.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Rdmp.Core.CommandExecution;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rdmp.Core.Datasets;

/// <summary>
/// Provider for internal datasets
/// </summary>
public class InternalDatasetProvider : IDatasetProvider
{
private readonly IBasicActivateItems _activator;
Expand All @@ -15,11 +15,13 @@ public InternalDatasetProvider(IBasicActivateItems activator)
_activator = activator;
}

/// <inheritdoc/>
public Curation.Data.Datasets.Dataset FetchDatasetByID(int id)
{
return _activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Curation.Data.Datasets.Dataset>("ID", id).FirstOrDefault();
}

/// <inheritdoc/>
public List<Curation.Data.Datasets.Dataset> FetchDatasets()
{
return _activator.RepositoryLocator.CatalogueRepository.GetAllObjects<Curation.Data.Datasets.Dataset>().ToList();
Expand Down
12 changes: 6 additions & 6 deletions Rdmp.Core/Datasets/PluginDataset.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rdmp.Core.Curation.Data.Datasets;


namespace Rdmp.Core.Datasets
{
public class PluginDataset: Curation.Data.Datasets.Dataset
/// <summary>
/// Base class to allow all plugin dataset types to be based off
/// </summary>
public class PluginDataset: Dataset
{

public PluginDataset() { }
Expand Down
141 changes: 11 additions & 130 deletions Rdmp.Core/Datasets/PureDataset.cs
Original file line number Diff line number Diff line change
@@ -1,140 +1,21 @@
using Amazon.Auth.AccessControlPolicy.ActionIdentifiers;
using NPOI.SS.Formula.Atp;
using NPOI.SS.Formula.Functions;
using SynthEHR;
// Copyright (c) The University of Dundee 2024-2024
// This file is part of the Research Data Management Platform (RDMP).
// 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.
// 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.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.


using Rdmp.Core.Datasets.PureItems;

Check failure on line 8 in Rdmp.Core/Datasets/PureDataset.cs

View workflow job for this annotation

GitHub Actions / Bundle Build

The type or namespace name 'PureItems' does not exist in the namespace 'Rdmp.Core.Datasets' (are you missing an assembly reference?)
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Rdmp.Core.Datasets;
#nullable enable

public class ENGBWrapper
{
public ENGBWrapper(string? text) { en_GB = text; }
public string? en_GB { get; set; }
}

public class URITerm
{
public URITerm(string? uri, ENGBWrapper enGBWrapper)
{
URI = uri;
term = enGBWrapper;
}
public string? URI { get; set; }
public ENGBWrapper term { get; set; }
}
public class PureDescription
{
public int? PureId { get; set; }
public ENGBWrapper? Value { get; set; }

public URITerm Term { get => new URITerm("/dk/atira/pure/dataset/descriptions/datasetdescription", new ENGBWrapper("Description")); }
}

public class Name()
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
}

public class PurePerson
{
public string? TypeDiscriminator { get; set; }
public int? PureId { get; set; }

public Name? Name { get; set; }
public URITerm? Role { get; set; }

public List<PureSystem>? Organizations { get; set; }
}

public class PureDate
{
public PureDate(DateTime dateTime)
{
Year = dateTime.Year;
Month = dateTime.Month;
Day = dateTime.Day;
}

public PureDate() { }


public DateTime ToDateTime()
{
return new DateTime(Year, Month??1, Day??1, 0, 0, 0);
}

public bool IsBefore(PureDate date)
{
if (Year < date.Year) return true;
if (Year == date.Year)
{
if (Month < date.Month) return true;
if (Month == date.Month)
{
return Day < date.Day;
}
}

return false;
}

public PureDate(int year, int? month = null, int? day = null)
{
Year = year;
if (month != null) Month = month;
if (day != null) Day = day;
}
public int Year { get; set; }
public int? Month { get; set; }
public int? Day { get; set; }
}

public class Visibility
{
public Visibility(string? key, ENGBWrapper description)
{
Key = key;
Description = description;
}
public string? Key { get; set; }
public ENGBWrapper Description { get; set; }
}

public class Workflow
{
public string? Step { get; set; }
public ENGBWrapper? Description { get; set; }
}

public class Geolocation
{
public ENGBWrapper? GeographicalCoverage { get; set; }
public string? Point { get; set; }

public string? Polygon { get; set; }
}

public class TemporalCoveragePeriod
{
public PureDate? StartDate { get; set; }
public PureDate? EndDate { get; set; }
}

public class PureSystem
{
public PureSystem(string? uuid, string? systemName)
{
UUID = uuid;
SystemName = systemName;
}
public string? SystemName { get; set; }
public string? UUID { get; set; }
}

/// <summary>
/// Used for mapping Pure datasets from the API into a C# object.
/// </summary>
public class PureDataset : PluginDataset
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
Expand Down
Loading

0 comments on commit 43d2008

Please sign in to comment.