Skip to content

Commit

Permalink
Merge pull request #135 from OHDSI/ehr-1kk
Browse files Browse the repository at this point in the history
Ehr DaysSupply + other fixes
  • Loading branch information
bradanton authored Nov 19, 2024
2 parents aa39706 + 6608bf7 commit 4d4c6ae
Showing 1 changed file with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public override IEnumerable<DrugExposure> BuildDrugExposures(DrugExposure[] drug
if (drugExposure.StartDate.Year < _person.YearOfBirth)
continue;

if (drugExposure.DaysSupply.HasValue && drugExposure.DaysSupply >= 365)
continue;

if (!drugExposure.Quantity.HasValue && drugExposure.AdditionalFields != null)
{
int? quantity = null;
Expand Down Expand Up @@ -319,7 +322,7 @@ public override IEnumerable<Observation> BuildObservations(Observation[] observa
}
}

if (observation.AdditionalFields != null && observation.AdditionalFields.ContainsKey("test_result"))
if (observation.AdditionalFields != null && observation.AdditionalFields.ContainsKey("test_result") && observation.AdditionalFields["test_result"] != null)
{
if (decimal.TryParse(observation.AdditionalFields["test_result"], out var value))
observation.ValueAsNumber = value;
Expand Down Expand Up @@ -357,11 +360,12 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
if (measurement.StartDate < new DateTime(2007, 1, 1))
continue;


if (measurement.AdditionalFields != null && measurement.AdditionalFields.ContainsKey("neoplasm_histology_key"))
{
ConditionOccurrence conditionOccurrenceEvent = null;
var histologyKey = measurement.AdditionalFields["neoplasm_histology_key"];
if (_oncConditions.ContainsKey(histologyKey))
if (histologyKey != null && _oncConditions.ContainsKey(histologyKey))
{
conditionOccurrenceEvent = _oncConditions[histologyKey];
}
Expand All @@ -377,53 +381,58 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
var numericResult = measurement.AdditionalFields["numeric_result"];
var operatorValue = string.Empty;
var units = string.Empty;
if (numericResult.Contains("=>"))
{
operatorValue = "=>";
numericResult = numericResult.Replace("=>", "");
}
else if (numericResult.Contains('>'))
{
operatorValue = ">";
numericResult = numericResult.Replace(">", "");
}
else if (numericResult.Contains("<="))
{
operatorValue = "<=";
numericResult = numericResult.Replace("<=", "");
}
else if (numericResult.Contains('<'))
{
operatorValue = "<";
numericResult = numericResult.Replace("<", "");
}

if (numericResult.Contains('%'))
if (!string.IsNullOrEmpty(numericResult))
{
units = "%";
numericResult = numericResult.Replace("%", "");
}
if (numericResult.Contains("=>"))
{
operatorValue = "=>";
numericResult = numericResult.Replace("=>", "");
}
else if (numericResult.Contains('>'))
{
operatorValue = ">";
numericResult = numericResult.Replace(">", "");
}
else if (numericResult.Contains("<="))
{
operatorValue = "<=";
numericResult = numericResult.Replace("<=", "");
}
else if (numericResult.Contains('<'))
{
operatorValue = "<";
numericResult = numericResult.Replace("<", "");
}

if (numericResult.Contains("Muts/Mb"))
{
units = "Muts/Mb";
numericResult = numericResult.Replace("Muts/Mb", "");
}
if (numericResult.Contains('%'))
{
units = "%";
numericResult = numericResult.Replace("%", "");
}

if (numericResult.Contains('+'))
{
var result = Vocabulary.Lookup(numericResult.Trim(), "LabRes", DateTime.MinValue);
if (numericResult.Contains("Muts/Mb"))
{
units = "Muts/Mb";
numericResult = numericResult.Replace("Muts/Mb", "");
}

if (result.Count != 0 && result[0].ConceptId.HasValue && result[0].ConceptId > 0)
if (numericResult.Contains('+'))
{
measurement.ValueAsConceptId = result[0].ConceptId.Value;
var result = Vocabulary.Lookup(numericResult.Trim(), "LabRes", DateTime.MinValue);

if (result.Count != 0 && result[0].ConceptId.HasValue && result[0].ConceptId > 0)
{
measurement.ValueAsConceptId = result[0].ConceptId.Value;
}
}
else if (decimal.TryParse(numericResult, out decimal value))
{
measurement.ValueAsNumber = value;
}
}
else if (decimal.TryParse(numericResult, out decimal value))
{
measurement.ValueAsNumber = value;
}


if (!string.IsNullOrEmpty(operatorValue))
{
var result = Vocabulary.Lookup(operatorValue.Trim(), "Operators", DateTime.MinValue);
Expand Down Expand Up @@ -452,14 +461,17 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
{
var numericResult = measurement.AdditionalFields["result_numeric"];

if (numericResult.Contains('/'))
if (!string.IsNullOrEmpty(numericResult))
{
numericResult = numericResult.Split('/')[0];
}
if (numericResult.Contains('/'))
{
numericResult = numericResult.Split('/')[0];
}

if (decimal.TryParse(numericResult, out decimal value))
{
measurement.ValueAsNumber = value;
if (decimal.TryParse(numericResult, out decimal value))
{
measurement.ValueAsNumber = value;
}
}
}
}
Expand Down Expand Up @@ -487,6 +499,7 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
}
}


// onc
if (measurement.TypeConceptId == 32882)
{
Expand Down Expand Up @@ -514,6 +527,7 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
yield return item.First();
}


foreach (var byDate in tumorSize.GroupBy(t => t.StartDate))
{
var mes = byDate.First();
Expand Down Expand Up @@ -937,8 +951,10 @@ public override Attrition Build(ChunkData data, KeyMasterOffsetManager om)
.ToArray();
var observations = BuildObservations([.. ObservationsRaw], visitOccurrences, observationPeriods)
.ToArray();

var measurements = BuildMeasurement([.. MeasurementsRaw], visitOccurrences, observationPeriods)
.ToArray();

var deviceExposure =
BuildDeviceExposure([.. DeviceExposureRaw], visitOccurrences, observationPeriods)
.Where(d => d.StartDate >= new DateTime(2007, 1, 1))
Expand Down

0 comments on commit 4d4c6ae

Please sign in to comment.