diff --git a/sources/Framework/org.ohdsi.cdm.framework.etl/Transformation/OptumPanther/OptumPantherPersonBuilder.cs b/sources/Framework/org.ohdsi.cdm.framework.etl/Transformation/OptumPanther/OptumPantherPersonBuilder.cs index f2095267..ef4d3654 100644 --- a/sources/Framework/org.ohdsi.cdm.framework.etl/Transformation/OptumPanther/OptumPantherPersonBuilder.cs +++ b/sources/Framework/org.ohdsi.cdm.framework.etl/Transformation/OptumPanther/OptumPantherPersonBuilder.cs @@ -182,6 +182,9 @@ public override IEnumerable 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; @@ -319,7 +322,7 @@ public override IEnumerable 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; @@ -357,11 +360,12 @@ public override IEnumerable 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]; } @@ -377,53 +381,58 @@ public override IEnumerable 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); @@ -452,14 +461,17 @@ public override IEnumerable 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; + } } } } @@ -487,6 +499,7 @@ public override IEnumerable BuildMeasurement(Measurement[] measurem } } + // onc if (measurement.TypeConceptId == 32882) { @@ -514,6 +527,7 @@ public override IEnumerable BuildMeasurement(Measurement[] measurem yield return item.First(); } + foreach (var byDate in tumorSize.GroupBy(t => t.StartDate)) { var mes = byDate.First(); @@ -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))