Skip to content

Commit

Permalink
Merge pull request #161 from OHDSI/cdm-to-cdm-add-vocab
Browse files Browse the repository at this point in the history
Cdm to cdm add vocab
  • Loading branch information
bradanton authored Feb 19, 2025
2 parents f8f032a + d807e97 commit b5146c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public override Attrition Build(ChunkData data, KeyMasterOffsetManager o)
visitOccurrences.Add(visitOccurrence.Id, visitOccurrence);
}

var visitDetails = new List<VisitDetail>();
var visitDetails = new Dictionary<long, VisitDetail>();

foreach (var vd in VisitDetailsRaw)
{
Expand All @@ -143,7 +143,7 @@ public override Attrition Build(ChunkData data, KeyMasterOffsetManager o)
continue;
}

visitDetails.Add(vd);
visitDetails.Add(vd.Id, vd);
}

foreach (var de in DrugExposuresRaw)
Expand Down Expand Up @@ -182,12 +182,12 @@ public override Attrition Build(ChunkData data, KeyMasterOffsetManager o)
de.Domain = "Device";
}

TryToRemap(DrugExposuresRaw);
TryToRemap(ConditionOccurrencesRaw);
TryToRemap(ProcedureOccurrencesRaw);
TryToRemap(ObservationsRaw);
TryToRemap(MeasurementsRaw);
TryToRemap(DeviceExposureRaw);
TryToRemap(DrugExposuresRaw, visitOccurrences, visitDetails);
TryToRemap(ConditionOccurrencesRaw, visitOccurrences, visitDetails);
TryToRemap(ProcedureOccurrencesRaw, visitOccurrences, visitDetails);
TryToRemap(ObservationsRaw, visitOccurrences, visitDetails);
TryToRemap(MeasurementsRaw, visitOccurrences, visitDetails);
TryToRemap(DeviceExposureRaw, visitOccurrences, visitDetails);

var newEntities = new List<IEntity>();

Expand Down Expand Up @@ -226,7 +226,7 @@ public override Attrition Build(ChunkData data, KeyMasterOffsetManager o)
// push built entities to ChunkBuilder for further save to CDM database
AddToChunk(person, death, [.. observationPeriods], payerPlanPeriods, [.. drugExposures],
[.. conditionOccurrences], [.. procedureOccurrences], [.. observations], [.. measurements],
[.. visitOccurrences.Values], [.. visitDetails], null, [.. deviceExposure], null, null);
[.. visitOccurrences.Values], [.. visitDetails.Values], null, [.. deviceExposure], null, null);

foreach (var c in CostRaw)
ChunkData.AddCostData(c);
Expand Down Expand Up @@ -398,11 +398,16 @@ protected IEnumerable<T> GetNewMap<T>(IEnumerable<T> entities, List<IEntity> new
}
}

private void TryToRemap(IEnumerable<IEntity> records)
private void TryToRemap(IEnumerable<IEntity> records, Dictionary<long, VisitOccurrence> visits, Dictionary<long, VisitDetail> visitDetails)
{
foreach (var record in records)
{
if(record.VisitOccurrenceId.HasValue && _removedVisitIds.ContainsKey(record.VisitOccurrenceId.Value))
if (record.VisitOccurrenceId.HasValue && _removedVisitIds.ContainsKey(record.VisitOccurrenceId.Value))
{
record.VisitOccurrenceId = null;
}

if (record.VisitOccurrenceId.HasValue && !visits.ContainsKey(record.VisitOccurrenceId.Value))
{
record.VisitOccurrenceId = null;
}
Expand All @@ -412,7 +417,12 @@ private void TryToRemap(IEnumerable<IEntity> records)
record.VisitDetailId = null;
}

UpdateLookup(record);
if (record.VisitDetailId.HasValue && !visitDetails.ContainsKey(record.VisitDetailId.Value))
{
record.VisitDetailId = null;
}

UpdateLookup(record);
}
}

Expand All @@ -436,6 +446,9 @@ private void UpdateLookup(IEntity e)
case "icd10pcs":
lookupName = "icd10pcs";
break;
case "icd10":
lookupName = "icd10";
break;
case "icd9cm":
lookupName = "icd9cm";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ public object GetValue(int i)
return _enumerator.Current.PaidDispensingFee.Round();

case 16:
return (long?)_offset.GetId(_enumerator.Current.PersonId,
_enumerator.Current.PayerPlanPeriodId.Value);
if (_enumerator.Current.PayerPlanPeriodId.HasValue)
{
if (_offset.GetKeyOffset(_enumerator.Current.PersonId).PayerPlanPeriodIdChanged)
return _offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.PayerPlanPeriodId.Value);
else
return _enumerator.Current.PayerPlanPeriodId;
}

return null;

case 17:
return _enumerator.Current.AmountAllowed.Round();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void Fill(bool forLookup, bool readFromS3)
_lookups.Add(o.Key.Split('/')[3].Replace(".txt.gz", ""), lookup);
}

if (Vendor is framework.etl.Transformation.CDM.CdmPersonBuilder.CdmVendor)
if (Vendor.Name == "CDM")
{
var getObjectRequest = new GetObjectRequest
{
Expand Down Expand Up @@ -197,6 +197,7 @@ public void Fill(bool forLookup, bool readFromS3)
}

_conceptIdToSourceVocabularyId.TrimExcess();
Console.WriteLine("_conceptIdToSourceVocabularyId: " + _conceptIdToSourceVocabularyId.Keys.Count);
}
}

Expand Down

0 comments on commit b5146c1

Please sign in to comment.