From e96ba218dad40fc83fda49b280d4c42aa416541c Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Tue, 8 Oct 2024 13:16:05 +0300 Subject: [PATCH 1/2] Add support of the multiple VALUE_AS_CONCEPT_ID --- .../Common/Definitions/EntityDefinition.cs | 20 +++++++-- .../Common/Lookups/Lookup.cs | 42 +++++-------------- .../Common/Lookups/LookupValue.cs | 2 +- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs b/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs index e9a548ae..324be38b 100644 --- a/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs +++ b/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs @@ -131,7 +131,7 @@ public virtual IEnumerable GetConcepts(Concept concept, IDataRecord rea } } - yield return new Entity + var entity = new Entity { IsUnique = IsUnique, PersonId = personId.Value, @@ -150,17 +150,29 @@ public virtual IEnumerable GetConcepts(Concept concept, IDataRecord rea ValidEndDate = lookupValue.ValidEndDate, SourceConceptId = sourceConceptId, Domain = lookupValue.Domain, - //SourceVocabularyId = lookupValue.SourceVocabularyId, VocabularySourceValue = lookupValue.SourceCode, Ingredients = ingredients, - ValueAsConceptId = lookupValue.ValueAsConceptId, + ValueAsConceptId = null, SourceConcepts = lookupValue.SourceConcepts.ToList(), }; + + if (lookupValue.ValueAsConceptIds == null || lookupValue.ValueAsConceptIds.Count == 0) + { + yield return entity; + } + else + { + foreach (var valueAsConceptId in lookupValue.ValueAsConceptIds) + { + entity.ValueAsConceptId = valueAsConceptId; + yield return entity; + } + } } } } } } } -} +} \ No newline at end of file diff --git a/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/Lookup.cs b/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/Lookup.cs index 829d3643..648e3808 100644 --- a/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/Lookup.cs +++ b/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/Lookup.cs @@ -136,33 +136,6 @@ public void Fill(AmazonS3Client client, string bucket, string prefix) ValidEndDate = validEndDate }; - //if (spliter.Results.Length > 5) - //{ - // //lv.SourceConceptId = IsNullOrEmpty(spliter.Results[6]) - // // ? 0 - // // : long.Parse(spliter.Results[6]); - - // var sourceConceptId = IsNullOrEmpty(spliter.Results[6]) - // ? 0 - // : long.Parse(spliter.Results[6]); - - // var sourceValidStartDate = DateTime.MinValue; - // var sourceValidEndDate = DateTime.MaxValue; - - // if (spliter.Results.Length > 6) - // { - // DateTime.TryParse(spliter.Results[7], out sourceValidStartDate); - // DateTime.TryParse(spliter.Results[8], out sourceValidEndDate); - // } - - // lv.SourceConcepts.Add(new SourceConcepts - // { - // ConceptId = sourceConceptId, - // ValidStartDate = sourceValidStartDate, - // ValidEndDate = sourceValidEndDate - // }); - //} - value = lv; _lookup[sourceCode].Add(conceptId, value); } @@ -204,11 +177,16 @@ public void Fill(AmazonS3Client client, string bucket, string prefix) value.Ingredients.Add(ingredient); } } - - if (spliter.Results.Length > 10) + + if (spliter.Results.Length > 10) { - if (!IsNullOrEmpty(spliter.Results[10])) - value.ValueAsConceptId = long.Parse(spliter.Results[10]); + + if (!IsNullOrEmpty(spliter.Results[10]) && + long.TryParse(spliter.Results[10], out var valueAsConceptId)) + { + value.ValueAsConceptIds ??= []; + value.ValueAsConceptIds.Add(valueAsConceptId); + } } } } @@ -253,7 +231,7 @@ private IEnumerable GetValues(string sourceCode, DateTime? eventDat Ingredients = _lookup[sourceCode][conceptId].Ingredients, ValidStartDate = _lookup[sourceCode][conceptId].ValidStartDate, ValidEndDate = _lookup[sourceCode][conceptId].ValidEndDate, - ValueAsConceptId = _lookup[sourceCode][conceptId].ValueAsConceptId, + ValueAsConceptIds = _lookup[sourceCode][conceptId].ValueAsConceptIds, //SourceValidStartDate = _lookup[sourceCode][conceptId].SourceValidStartDate, //SourceValidEndDate = _lookup[sourceCode][conceptId].SourceValidEndDate, SourceConcepts = _lookup[sourceCode][conceptId].SourceConcepts, diff --git a/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/LookupValue.cs b/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/LookupValue.cs index 41d3e0f1..93e1f150 100644 --- a/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/LookupValue.cs +++ b/sources/Framework/org.ohdsi.cdm.framework/Common/Lookups/LookupValue.cs @@ -34,7 +34,7 @@ public class LookupValue : IEquatable public HashSet SourceConcepts { get; set; } = []; public HashSet Ingredients { get; set; } - public long? ValueAsConceptId { get; set; } + public HashSet ValueAsConceptIds { get; set; } public bool Equals(LookupValue other) { From 30975e69f57c28adedbdc8b382701c9da3db18d9 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Wed, 9 Oct 2024 14:27:57 +0300 Subject: [PATCH 2/2] Update EntityDefinition.cs --- .../Common/Definitions/EntityDefinition.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs b/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs index 324be38b..85ed7383 100644 --- a/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs +++ b/sources/Framework/org.ohdsi.cdm.framework/Common/Definitions/EntityDefinition.cs @@ -1,4 +1,5 @@ -using org.ohdsi.cdm.framework.common.Builder; +using Force.DeepCloner; +using org.ohdsi.cdm.framework.common.Builder; using org.ohdsi.cdm.framework.common.Extensions; using org.ohdsi.cdm.framework.common.Lookups; using org.ohdsi.cdm.framework.common.Omop; @@ -165,8 +166,9 @@ public virtual IEnumerable GetConcepts(Concept concept, IDataRecord rea { foreach (var valueAsConceptId in lookupValue.ValueAsConceptIds) { - entity.ValueAsConceptId = valueAsConceptId; - yield return entity; + var ent = entity.DeepClone(); + ent.ValueAsConceptId = valueAsConceptId; + yield return ent; } } }