コード例 #1
0
        private bool AddCost(long eventId, Func <ICostV5, Cost> createCost, IEntity entity, ICostV5 entityCost)
        {
            if (entityCost == null)
            {
                return(false);
            }

            var cost = createCost(entityCost);

            cost.CostId  = Offset.GetKeyOffset(entityCost.PersonId).VisitCostId;
            cost.EventId = eventId;

            return(ChunkData.AddCostData(cost));
        }
コード例 #2
0
        public IEnumerable <Note> GetNotes(Concept concept, IDataRecord reader,
                                           KeyMasterOffsetManager offset)
        {
            return
                (base.GetConcepts(concept, reader, offset)
                 .Select(
                     e =>
                     new Note
            {
                Id = offset.GetKeyOffset(e.PersonId).NoteId,
                EncodingConceptId = reader.GetInt(EncodingConceptId) ?? 0,
                LanguageConceptId = reader.GetInt(LanguageConceptId) ?? 0,
                Title = reader.GetString(Title),
                Text = reader.GetString(Text),

                PersonId = e.PersonId,
                ConceptId = e.ConceptId,
                StartDate = e.StartDate,

                TypeConceptId = e.TypeConceptId,
                VisitOccurrenceId = e.VisitOccurrenceId,
                VisitDetailId = e.VisitDetailId,
                SourceValue = e.SourceValue,
                ProviderId = e.ProviderId,

                AdditionalFields = e.AdditionalFields
            }));
        }
コード例 #3
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
        {
            int?relevantConditionConceptId = null;
            int?modifierConceptId          = reader.GetInt(ModifierConceptId) ?? 0;

            if (Concepts.Length == 2)
            {
                var relevantConcepts = Concepts[1].GetConceptIdValues(Vocabulary, Concepts[1].Fields[0], reader);

                if (relevantConcepts.Count > 0)
                {
                    relevantConditionConceptId = relevantConcepts.Min(c => c.ConceptId); //CDM v4
                    modifierConceptId          = relevantConditionConceptId;             //CDM v5
                }
            }

            foreach (var e in base.GetConcepts(concept, reader, offset))
            {
                yield return
                    (new ProcedureOccurrence(e)
                {
                    Id = KeyMasterOffsetManager.GetKeyOffset(e.PersonId).ProcedureOccurrenceId,
                    ReleventConditionConceptId = relevantConditionConceptId,
                    ModifierConceptId = modifierConceptId ?? 0,
                    StartTime = e.StartTime ?? e.StartDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
                    Quantity = reader.GetInt(Quantity),
                    QualifierSourceValue = reader.GetString(QualifierSourceValue)
                });
            }
        }
コード例 #4
0
        public object GetValue(int i)
        {
            if (_enumerator.Current == null)
            {
                return(null);
            }

            switch (i)
            {
            case 0:
                return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.TypeConceptId);

            case 5:
                return(_enumerator.Current.ModifierConceptId);

            case 6:
                return(_enumerator.Current.Quantity);

            case 7:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 8:
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (KeyMasterOffsetManager.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId,
                                                            _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);

            case 9:
                return(_enumerator.Current.SourceValue);

            case 10:
                return(_enumerator.Current.SourceConceptId);

            case 11:
                return(_enumerator.Current.QualifierSourceValue);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #5
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
                return(_offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.EndDate);

            case 5:
                return(_enumerator.Current.TypeConceptId);

            case 6:
                return(_enumerator.Current.StopReason);

            case 7:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 8:
            {
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(_offset.GetId(_enumerator.Current.PersonId,
                                             _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);
            }

            case 9:
                return(_enumerator.Current.StatusConceptId);

            case 10:
                return(_enumerator.Current.SourceValue);

            case 11:
                return(_enumerator.Current.SourceConceptId);

            case 12:
                return(_enumerator.Current.StatusSourceValue);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #6
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
                return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.StartDate);

            case 3:
                return(_enumerator.Current.StartTime);

            case 4:
                return(_enumerator.Current.TypeConceptId);

            case 5:
                return(_enumerator.Current.Text);

            case 6:
                return(_enumerator.Current.ProviderId);

            case 7:
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (KeyMasterOffsetManager.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId,
                                                            _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);

            case 8:
                return(_enumerator.Current.SourceValue);

            case 9:
                return(_enumerator.Current.ConceptId);

            case 10:
                return(_enumerator.Current.Title);

            case 11:
                return(_enumerator.Current.EncodingConceptId);

            case 12:
                return(_enumerator.Current.LanguageConceptId);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #7
0
ファイル: EraHelper.cs プロジェクト: tyults/ETL-LambdaBuilder
        public static List <PayerPlanPeriod> GetPayerPlanPeriods(PayerPlanPeriod[] entities, int gap, Func <PayerPlanPeriod, PayerPlanPeriod, bool> canBeCombined, KeyMasterOffsetManager offset)
        {
            var result = new List <PayerPlanPeriod>();

            if (entities.Length == 0)
            {
                return(result);
            }

            var ordered =
                entities.OrderBy(e => e.StartDate).ToList();
            var payerPlanPeriod = ordered[0];
            var list            = new List <PayerPlanPeriod>();

            foreach (var entity in ordered)
            {
                if (canBeCombined(entity, payerPlanPeriod))
                {
                    list.Add(entity);
                    continue;
                }

                result.AddRange(GetEras(list, gap, -1).Select(i => new PayerPlanPeriod
                {
                    Id               = KeyMasterOffsetManager.GetKeyOffset(i.PersonId).PayerPlanPeriodId,
                    PersonId         = i.PersonId,
                    StartDate        = i.StartDate,
                    EndDate          = i.EndDate,
                    PayerSourceValue =
                        payerPlanPeriod.PayerSourceValue,
                    FamilySourceValue =
                        payerPlanPeriod.FamilySourceValue,
                    PlanSourceValue =
                        payerPlanPeriod.PlanSourceValue
                }));

                list.Clear();
                payerPlanPeriod = entity;
                list.Add(entity);
            }

            result.AddRange(GetEras(list, gap, -1).Select(i => new PayerPlanPeriod
            {
                Id               = KeyMasterOffsetManager.GetKeyOffset(i.PersonId).PayerPlanPeriodId,
                PersonId         = i.PersonId,
                StartDate        = i.StartDate,
                EndDate          = i.EndDate,
                PayerSourceValue =
                    payerPlanPeriod.PayerSourceValue,
                FamilySourceValue =
                    payerPlanPeriod.FamilySourceValue,
                PlanSourceValue =
                    payerPlanPeriod.PlanSourceValue
            }));


            return(result);
        }
コード例 #8
0
 /// <summary>
 /// A Drug Era is defined as a span of time when the Person is assumed to be exposed to a particular drug.
 /// Successive periods of Drug Exposures are combined under certain rules to produce continuous Drug Eras.
 /// The Drug Era  is populated by pulling from the set of drug exposure.  A drug era is therefore understood as exposure to a certain compound over a certain period of time.
 /// There will only be one type of persistence window (duration that is allowed to elapse between drug exposures) applied to this CDM, which is 30 days.
 /// </summary>
 /// <param name="drugExposures">set of drug exposure entities</param>
 /// <param name="observationPeriods">the observation periods entities for current person</param>
 /// <returns>Enumeration of drug era</returns>
 public virtual IEnumerable <EraEntity> BuildDrugEra(DrugExposure[] drugExposures, ObservationPeriod[] observationPeriods)
 {
     foreach (var eraEntity in EraHelper.GetEras(
                  Clean(drugExposures, observationPeriods, true).Where(d => string.IsNullOrEmpty(d.Domain) || d.Domain == "Drug"), 30, 38000182))
     {
         eraEntity.Id = KeyMasterOffsetManager.GetKeyOffset(eraEntity.PersonId).DrugEraId;
         yield return(eraEntity);
     }
 }
コード例 #9
0
 /// <summary>
 /// CONDITION_ERAs are chronological periods of condition occurrence.
 /// There will only be one type of persistence window (duration that is allowed to elapse between condition occurrences) applied to this CDM, which is 30 days.
 /// CONDITION_END_DATE will be the CONDITION_START_DATE.
 /// </summary>
 /// <param name="conditionOccurrences">Set of condition occurrence entities</param>
 /// <param name="observationPeriods">the observation periods entities for current person</param>
 /// <returns>Enumeration of condition era</returns>
 public virtual IEnumerable <EraEntity> BuildConditionEra(ConditionOccurrence[] conditionOccurrences, ObservationPeriod[] observationPeriods)
 {
     foreach (var eraEntity in EraHelper.GetEras(
                  Clean(conditionOccurrences, observationPeriods, true).Where(c => string.IsNullOrEmpty(c.Domain) || c.Domain == "Condition"), 30,
                  38000247))
     {
         eraEntity.Id = KeyMasterOffsetManager.GetKeyOffset(eraEntity.PersonId).ConditionEraId;
         yield return(eraEntity);
     }
 }
コード例 #10
0
 public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                   KeyMasterOffsetManager offset)
 {
     foreach (var entity in base.GetConcepts(concept, reader, offset))
     {
         yield return(new DeviceExposure(entity)
         {
             Id = offset.GetKeyOffset(entity.PersonId).DeviceExposureId,
             UniqueDeviceId = reader.GetString(UniqueDeviceId),
             Quantity = reader.GetInt(Quantity) ?? 0
         });
     }
 }
コード例 #11
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
            {
                return(KeyMasterOffsetManager.GetKeyOffset(_visitEnumerator.Current.PersonId)
                       .VisitOccurrenceIdChanged
                       ? KeyMasterOffsetManager.GetId(_visitEnumerator.Current.PersonId, _visitEnumerator.Current.Id)
                       : _visitEnumerator.Current.Id);
            }

            case 1:
                return(_visitEnumerator.Current.PersonId);

            case 2:
                return(_visitEnumerator.Current.ConceptId);

            case 3:
                return(_visitEnumerator.Current.StartDate);

            case 4:
                return(_visitEnumerator.Current.StartTime);

            case 5:
                return(_visitEnumerator.Current.EndDate);

            case 6:
                return(_visitEnumerator.Current.EndTime);

            case 7:
                return(_visitEnumerator.Current.TypeConceptId);

            case 8:
                return(_visitEnumerator.Current.ProviderId == 0 ? null : _visitEnumerator.Current.ProviderId);

            case 9:
                return(_visitEnumerator.Current.CareSiteId == 0 ? null : _visitEnumerator.Current.CareSiteId);

            case 10:
                return(_visitEnumerator.Current.SourceValue);

            case 11:
                return(_visitEnumerator.Current.SourceConceptId);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #12
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
        {
            var de = base.GetConcepts(concept, reader, offset).ToList();

            if (de.Count > 0)
            {
                yield return(new DeviceExposure(de[0])
                {
                    Id = KeyMasterOffsetManager.GetKeyOffset(de[0].PersonId).DeviceExposureId,
                    UniqueDeviceId = reader.GetString(UniqueDeviceId),
                    StartTime = de[0].StartTime ?? de[0].StartDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
                    Quantity = reader.GetInt(Quantity) ?? 0
                });
            }
        }
コード例 #13
0
ファイル: EraHelper.cs プロジェクト: lanicon/ETL-CDMBuilder
 public static List <ObservationPeriod> GetObservationPeriods(int gap, EraEntity[] entities, KeyMasterOffsetManager offset)
 {
     return
         (GetEras(entities, gap, entities[0].TypeConceptId ?? -1).Select(
              period =>
              new ObservationPeriod
     {
         Id = offset.GetKeyOffset(period.PersonId).ObservationPeriodId,
         PersonId = period.PersonId,
         StartDate = period.StartDate,
         EndDate = period.EndDate.Value,
         TypeConceptId = period.TypeConceptId
     }).
          ToList());
 }
コード例 #14
0
 public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
 {
     return
         (base.GetConcepts(concept, reader, offset)
          .Select(
              e =>
              new Note(e)
     {
         Id = KeyMasterOffsetManager.GetKeyOffset(e.PersonId).NoteId,
         EncodingConceptId = reader.GetInt(EncodingConceptId) ?? 0,
         LanguageConceptId = reader.GetInt(LanguageConceptId) ?? 0,
         Title = reader.GetString(Title),
         Text = reader.GetString(Text),
         StartTime = e.StartTime ?? e.StartDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
     }));
 }
コード例 #15
0
        public override IEnumerable <VisitCost> BuildVisitCosts(VisitOccurrence[] visitOccurrences)
        {
            foreach (var c in base.BuildVisitCosts(visitOccurrences).Where(vc => vc.TotalPaid.HasValue))
            {
                ChunkData.AddCostData(new Cost(c.PersonId)
                {
                    CostId            = KeyMasterOffsetManager.GetKeyOffset(c.PersonId).VisitCostId,
                    CurrencyConceptId = c.CurrencyConceptId,
                    TypeId            = 5031,
                    Domain            = "Visit",
                    EventId           = c.Id,
                    TotalPaid         = c.TotalPaid
                });

                yield return(c);
            }
        }
コード例 #16
0
        public override IEnumerable <ProcedureCost> BuildProcedureCosts(ProcedureOccurrence[] procedureOccurrences)
        {
            foreach (var c in base.BuildProcedureCosts(procedureOccurrences))
            {
                ChunkData.AddCostData(new Cost(c.PersonId)
                {
                    CostId            = KeyMasterOffsetManager.GetKeyOffset(c.PersonId).VisitCostId,
                    CurrencyConceptId = c.CurrencyConceptId,
                    TypeId            = 5032,
                    Domain            = "Procedure",
                    EventId           = c.Id,
                    TotalPaid         = c.TotalPaid,
                    TotalCharge       = c.PaidByCoordinationBenefits
                });

                yield return(c);
            }
        }
コード例 #17
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            int?   statusConceptId = 0;
            string statusSource    = null;

            if (Concepts != null)
            {
                var conditionStatusConcept = Concepts.FirstOrDefault(c => c.Name == "ConditionStatusConceptId");
                if (conditionStatusConcept != null)
                {
                    var statusConcepts = conditionStatusConcept.GetConceptIdValues(Vocabulary, conditionStatusConcept.Fields[0], reader);
                    statusSource = reader.GetString(conditionStatusConcept.Fields[0].Key);

                    if (statusConcepts.Count > 0)
                    {
                        statusConceptId = statusConcepts.Min(c => c.ConceptId);
                        statusSource    = statusConcepts.Min(c => c.SourceCode);

                        if (string.IsNullOrEmpty(statusSource))
                        {
                            statusSource = reader.GetString(conditionStatusConcept.Fields[0].Key);
                        }

                        if (string.IsNullOrEmpty(statusSource))
                        {
                            statusSource = reader.GetString(conditionStatusConcept.Fields[0].SourceKey);
                        }
                    }
                }
            }

            return
                (base.GetConcepts(concept, reader, offset)
                 .Select(
                     e =>
                     new ConditionOccurrence(e)
            {
                Id = offset.GetKeyOffset(e.PersonId).ConditionOccurrenceId,
                StatusConceptId = statusConceptId.HasValue ? statusConceptId.Value : 0,
                StatusSourceValue = statusSource
            }));
        }
コード例 #18
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            //var obsConcepts = base.GetConcepts(concept, reader, offset).ToList();
            var unitConcept = GetUnitConcept(reader);

            int?valueAsConceptId = null;

            if (Concepts.Length > 2)
            {
                var valueConcepts = base.GetConcepts(Concepts[2], reader, null).ToList();
                if (valueConcepts.Count > 0)
                {
                    valueAsConceptId = valueConcepts[0].ConceptId;
                }
            }
            else
            {
                valueAsConceptId = reader.GetInt(ValueAsConceptId);
            }

            foreach (var entity in base.GetConcepts(concept, reader, offset))
            {
                yield return(new Measurement(entity)
                {
                    Id = offset.GetKeyOffset(entity.PersonId).MeasurementId,
                    SourceValue = string.IsNullOrWhiteSpace(entity.SourceValue)
                        ? null
                        : entity.SourceValue,
                    RangeLow = reader.GetDecimal(RangeLow),
                    RangeHigh = reader.GetDecimal(RangeHigh),
                    ValueAsNumber = reader.GetDecimal(ValueAsNumber),
                    OperatorConceptId = reader.GetInt(OperatorConceptId) ?? 0,
                    UnitConceptId = unitConcept.Key ?? 0,
                    UnitSourceValue = string.IsNullOrWhiteSpace(unitConcept.Value) ? null : unitConcept.Value,
                    ValueSourceValue = reader.GetString(ValueSourceValue),
                    ValueAsConceptId = valueAsConceptId ?? 0,
                    Time = reader.GetString(Time)
                });
            }
        }
コード例 #19
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            int?   statusConceptId = 0;
            string statusSource    = null;

            if (Concepts.Length == 2)
            {
                var statusConcepts = Concepts[1].GetConceptIdValues(Vocabulary, Concepts[1].Fields[0], reader);
                statusSource = reader.GetString(Concepts[1].Fields[0].Key);

                if (statusConcepts.Count > 0)
                {
                    statusConceptId = statusConcepts.Min(c => c.ConceptId);
                    statusSource    = statusConcepts.Min(c => c.SourceCode);

                    if (string.IsNullOrEmpty(statusSource))
                    {
                        statusSource = reader.GetString(Concepts[1].Fields[0].Key);
                    }

                    if (string.IsNullOrEmpty(statusSource))
                    {
                        statusSource = reader.GetString(Concepts[1].Fields[0].SourceKey);
                    }
                }
            }

            return
                (base.GetConcepts(concept, reader, offset)
                 .Select(
                     e =>
                     new ConditionOccurrence(e)
            {
                Id = KeyMasterOffsetManager.GetKeyOffset(e.PersonId).ConditionOccurrenceId,
                StatusConceptId = statusConceptId.HasValue ? statusConceptId.Value : 0,
                StartTime = e.StartTime ??
                            e.StartDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
                StatusSourceValue = statusSource
            }));
        }
コード例 #20
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
        {
            int?relevantConditionConceptId = null;
            int?modifierConceptId          = reader.GetInt(ModifierConceptId) ?? 0;

            if (Concepts != null)
            {
                var secondConcept = Concepts.FirstOrDefault(c => c.Name != "ProcedureConceptId");
                if (secondConcept != null)
                {
                    var relevantConcepts = secondConcept.GetConceptIdValues(Vocabulary, secondConcept.Fields[0], reader);

                    if (relevantConcepts.Count > 0)
                    {
                        relevantConditionConceptId = relevantConcepts.Min(c => c.ConceptId); //CDM v4
                        modifierConceptId          = relevantConditionConceptId;             //CDM v5
                    }
                }
            }

            var quantity = reader.GetDecimal(Quantity);
            int?q        = null;

            if (quantity.HasValue)
            {
                q = System.Decimal.ToInt32(quantity.Value);
            }

            foreach (var e in base.GetConcepts(concept, reader, offset))
            {
                yield return
                    (new ProcedureOccurrence(e)
                {
                    Id = offset.GetKeyOffset(e.PersonId).ProcedureOccurrenceId,
                    ReleventConditionConceptId = relevantConditionConceptId,
                    ModifierConceptId = modifierConceptId ?? 0,
                    Quantity = q,
                    QualifierSourceValue = reader.GetString(QualifierSourceValue)
                });
            }
        }
コード例 #21
0
        public ProcedureCost CreateEnity(ProcedureOccurrence procedure, IDataRecord reader,
            KeyMasterOffsetManager offset)
        {
            var paidCopay = reader.GetDecimal(PaidCopay);
            var paidCoinsurance = reader.GetDecimal(PaidCoinsurance);
            var paidTowardDeductible = reader.GetDecimal(PaidTowardDeductible);

            decimal? totalOutOfPocket = null;

            if (paidCopay.HasValue && paidCoinsurance.HasValue && paidTowardDeductible.HasValue)
            {
                totalOutOfPocket = paidCopay + paidCoinsurance + paidTowardDeductible;
            }
            else if (paidCoinsurance.HasValue && paidTowardDeductible.HasValue)
            {
                totalOutOfPocket = paidCoinsurance + paidTowardDeductible;
            }

            PopulateOthersConcepts(reader, out var drgConceptId, out var drgSource, out var revenueCodeConceptId,
                out var revenueCodeSource);

            return new ProcedureCost(procedure)
            {
                ProcedureCostId = offset.GetKeyOffset(procedure.PersonId).ProcedureCostId,
                PaidCopay = paidCopay,
                PaidCoinsurance = paidCoinsurance,
                PaidTowardDeductible = paidTowardDeductible,
                PaidByPayer = reader.GetDecimal(PaidByPayer),
                PaidByCoordinationBenefits = reader.GetDecimal(PaidByCoordinationBenefits),
                TotalPaid = reader.GetDecimal(TotalPaid),
                TotalOutOfPocket = totalOutOfPocket,
                RevenueCodeConceptId = revenueCodeConceptId,
                RevenueCodeSourceValue = revenueCodeSource,
                DrgConceptId = drgConceptId,
                DrgSourceValue = drgSource,
                CurrencyConceptId = reader.GetInt(CurrencyConceptId) ?? 0
            };
        }
コード例 #22
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            foreach (var entity in base.GetConcepts(concept, reader, offset))
            {
                var unitConcept      = GetUnitConcept(reader, "UnitConceptId");
                var qualifierConcept = GetUnitConcept(reader, "QualifierConceptId");

                var createObservation = new Func <Observation>(() => new Observation(entity)
                {
                    Id          = offset.GetKeyOffset(entity.PersonId).ObservationId,
                    SourceValue = string.IsNullOrWhiteSpace(entity.SourceValue)
                        ? null
                        : entity.SourceValue,
                    RangeLow             = reader.GetDecimal(RangeLow),
                    RangeHigh            = reader.GetDecimal(RangeHigh),
                    UnitsConceptId       = unitConcept.Key ?? 0,
                    UnitsSourceValue     = string.IsNullOrWhiteSpace(unitConcept.Value) ? null : unitConcept.Value,
                    ValueAsConceptId     = reader.GetInt(ValueAsConceptId) ?? 0,
                    QualifierConceptId   = qualifierConcept.Key ?? 0,
                    QualifierSourceValue = string.IsNullOrWhiteSpace(qualifierConcept.Value) ? null : qualifierConcept.Value,
                    //RelevantConditionConceptId = relevantConditionConceptId ?? 0
                });

                var observation = createObservation();
                observation.ValueAsNumber = reader.GetDecimal(ValueAsNumber);
                if (observation.ValueAsNumber.HasValue)
                {
                    observation.ValueAsNumber = Math.Round(observation.ValueAsNumber.Value, 3);
                }

                observation.ValueAsString = reader.GetString(ValueAsString);

                yield return(observation);
            }
        }
コード例 #23
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
            {
                return(_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged
                            ? _offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id)
                            : _enumerator.Current.Id);
            }

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.StartDate);

            case 5:
                return(_enumerator.Current.EndDate);

            case 6:
                return(_enumerator.Current.EndDate);

            case 7:
                return(_enumerator.Current.TypeConceptId);

            case 8:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 9:
                return(_enumerator.Current.CareSiteId == 0 ? null : _enumerator.Current.CareSiteId);

            case 10:
                return(_enumerator.Current.SourceValue);

            case 11:
                return(_enumerator.Current.SourceConceptId);

            case 12:
                return(_enumerator.Current.AdmittingSourceConceptId);

            case 13:
                return(_enumerator.Current.AdmittingSourceValue);

            case 14:
                return(_enumerator.Current.DischargeToConceptId);

            case 15:
                return(_enumerator.Current.DischargeToSourceValue);

            case 16:
                if (_enumerator.Current.PrecedingVisitOccurrenceId.HasValue)
                {
                    if (_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(_offset.GetId(_enumerator.Current.PersonId,
                                             _enumerator.Current.PrecedingVisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.PrecedingVisitOccurrenceId);
                }

                return(_enumerator.Current.PrecedingVisitOccurrenceId);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #24
0
        public object GetValue(int i)
        {
            if (_enumerator.Current == null)
            {
                return(null);
            }

            switch (i)
            {
            case 0:

                return(_offset.GetId(_enumerator.Current.PersonId,
                                     _enumerator.Current.CostId)); //TODO VisitCostOffset -> CostOffset

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                if (_enumerator.Current.Domain == "Visit" && !_offset
                    .GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                {
                    return(_enumerator.Current.EventId);
                }

                return(_offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.EventId));

            case 3:
                return(_enumerator.Current.EventFieldConceptId);

            case 4:
                return(_enumerator.Current.CostConceptId);

            case 5:
                return(_enumerator.Current.TypeId);

            case 6:
                return(_enumerator.Current.CurrencyConceptId);

            case 7:
                return(_enumerator.Current.CostValue.Round());

            case 8:
                return(_enumerator.Current.IncurredDate);

            case 9:
                return(_enumerator.Current.BilledDate);

            case 10:
                return(_enumerator.Current.PaidDate);

            case 11:
                return(_enumerator.Current.RevenueCodeConceptId);

            case 12:
                return(_enumerator.Current.DrgConceptId);

            case 13:
                return(_enumerator.Current.SourceValue);

            case 14:
                return(_enumerator.Current.SourceConceptId);

            case 15:
                return(_enumerator.Current.RevenueCodeSourceValue);

            case 16:
                return(_enumerator.Current.DrgSourceValue);

            case 17:
                return(_enumerator.Current.PayerPlanPeriodId.HasValue
                        ? _offset.GetId(_enumerator.Current.PersonId,
                                        _enumerator.Current.PayerPlanPeriodId.Value)
                        : _enumerator.Current.PayerPlanPeriodId);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #25
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            foreach (var entity in base.GetConcepts(concept, reader, offset))
            {
                var unitConcept = GetUnitConcept(reader);
                int?relevantConditionConceptId = null;

                if (Concepts.Length == 3)
                {
                    var relevantConditionConcepts =
                        Concepts[2].GetConceptIdValues(Vocabulary, Concepts[2].Fields[0], reader);

                    if (relevantConditionConcepts.Count > 0)
                    {
                        relevantConditionConceptId = relevantConditionConcepts.Min(c => c.ConceptId);
                    }
                }

                var createObservation = new Func <Observation>(() => new Observation(entity)
                {
                    Id          = offset.GetKeyOffset(entity.PersonId).ObservationId,
                    SourceValue = string.IsNullOrWhiteSpace(entity.SourceValue)
                        ? null
                        : entity.SourceValue,
                    RangeLow                   = reader.GetDecimal(RangeLow),
                    RangeHigh                  = reader.GetDecimal(RangeHigh),
                    UnitsConceptId             = unitConcept.Key ?? 0,
                    UnitsSourceValue           = string.IsNullOrWhiteSpace(unitConcept.Value) ? null : unitConcept.Value,
                    ValueAsConceptId           = reader.GetInt(ValueAsConceptId) ?? 0,
                    QualifierConceptId         = reader.GetInt(QualifierConceptId) ?? 0,
                    QualifierSourceValue       = reader.GetString(QualifierSourceValue),
                    RelevantConditionConceptId = relevantConditionConceptId ?? 0
                });

                if (ValuesAsNumber != null && ValuesAsNumber.Length > 1)
                {
                    foreach (var valueAsNumber in ValuesAsNumber)
                    {
                        var value = reader.GetDecimal(valueAsNumber);
                        if (value != null)
                        {
                            var observation = createObservation();

                            observation.ValueAsNumber = Math.Round(value.Value, 3);
                            observation.SourceValue   = observation.ValueAsNumber.ToString();
                            observation.TypeConceptId = 38000277;
                            yield return(observation);
                        }
                    }
                }
                else if (ValuesAsString != null && ValuesAsString.Length > 1)
                {
                    foreach (var valueAsString in ValuesAsString)
                    {
                        var value = reader.GetString(valueAsString);
                        if (!string.IsNullOrEmpty(value) && value != "-" && value != "9") //TMP
                        {
                            var observation = createObservation();
                            observation.ValueAsString = reader.GetString(valueAsString);
                            observation.SourceValue   = valueAsString;
                            observation.TypeConceptId = 38000278;
                            yield return(observation);
                        }
                    }
                }
                //else if (obsConcepts[0].ConceptId > 0 || !string.IsNullOrEmpty(obsConcepts[0].SourceValue))
                else if (entity.ConceptId > 0 || concept.Fields[0].IsNullable || !string.IsNullOrEmpty(entity.SourceValue))
                {
                    var observation = createObservation();
                    if (ValuesAsNumber != null && ValuesAsNumber.Length > 0)
                    {
                        observation.ValueAsNumber = reader.GetDecimal(ValuesAsNumber[0]);
                        if (observation.ValueAsNumber.HasValue)
                        {
                            observation.ValueAsNumber = Math.Round(observation.ValueAsNumber.Value, 3);
                        }
                    }

                    if (ValuesAsString != null && ValuesAsString.Length > 0)
                    {
                        observation.ValueAsString = reader.GetString(ValuesAsString[0]);

                        // Workaround, map ValueAsString (usind SourceLookup) and reset SourceValue to original value
                        if (observation.AdditionalFields != null &&
                            observation.AdditionalFields.ContainsKey("original_source"))
                        {
                            observation.ValueAsString = observation.SourceValue;
                            observation.SourceValue   = observation.AdditionalFields["original_source"];
                        }
                    }

                    yield return(observation);
                }
            }
        }
コード例 #26
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
        {
            DateTime?endDate = null;

            int    routeConceptId   = 0;
            string routeSourceValue = null;

            if (Concepts != null)
            {
                var routeConcept = Concepts.FirstOrDefault(c => c.Name == "RouteConceptId");
                if (routeConcept != null)
                {
                    var routeConcepts = base.GetConcepts(routeConcept, reader, null).ToList();
                    routeSourceValue = reader.GetString(routeConcept.Fields[0].Key);
                    if (routeConcepts.Count > 0)
                    {
                        routeConceptId   = routeConcepts[0].ConceptId;
                        routeSourceValue = routeConcepts[0].SourceValue;
                    }
                }
            }
            else
            {
                routeConceptId   = reader.GetInt(RouteConceptId) ?? 0;
                routeSourceValue = reader.GetString(RouteSourceValue);
            }


            foreach (var c in base.GetConcepts(concept, reader, offset))
            {
                var e = (Entity)c;

                var calculatedDaysSupply = reader.GetInt(DaysSupply) ?? 0;
                if (!string.IsNullOrEmpty(EndDate))
                {
                    if (calculatedDaysSupply > 0 && calculatedDaysSupply <= 365)
                    {
                        endDate = e.StartDate.AddDays(calculatedDaysSupply - 1);
                    }
                    else
                    {
                        endDate = reader.GetDateTime(EndDate);
                    }
                }

                var verbatimEndDate = reader.GetDateTime(VerbatimEndDate);

                yield return(new DrugExposure(e)
                {
                    Id = offset.GetKeyOffset(e.PersonId).DrugExposureId,
                    Refills = reader.GetIntSafe(Refill),
                    DaysSupply = reader.GetInt(DaysSupply),
                    CalculatedDaysSupply = calculatedDaysSupply,
                    Quantity = reader.GetDecimal(Quantity),
                    Sig = reader.GetString(Sig),
                    EndDate = endDate == DateTime.MinValue ? null : endDate,
                    VerbatimEndDate = verbatimEndDate == DateTime.MinValue ? (DateTime?)null : verbatimEndDate,
                    RouteConceptId = routeConceptId,
                    RouteSourceValue = routeSourceValue,
                    DoseUnitConceptId = reader.GetInt(DoseUnitConceptId) ?? 0,
                    DoseUnitSourceValue = reader.GetString(DoseUnitSourceValue),
                    StopReason = reader.GetString(StopReason)
                });
            }
        }
コード例 #27
0
        public object GetValue(int i)
        {
            if (_enumerator.Current == null)
            {
                return(null);
            }

            switch (i)
            {
            case 0:
                return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.EndDate);

            case 5:
                return(_enumerator.Current.TypeConceptId);

            case 6:
                return(_enumerator.Current.StopReason);

            case 7:
                return(_enumerator.Current.Refills);

            case 8:
                return(_enumerator.Current.Quantity);

            case 9:
                return(_enumerator.Current.DaysSupply);

            case 10:
                return(_enumerator.Current.Sig);

            case 11:
                return(_enumerator.Current.RouteConceptId);

            case 12:
                return(_enumerator.Current.EffectiveDrugDose);

            case 13:
                return(_enumerator.Current.DoseUnitConceptId);

            case 14:
                return(_enumerator.Current.LotNumber);

            case 15:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 16:
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (KeyMasterOffsetManager.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(KeyMasterOffsetManager.GetId(_enumerator.Current.PersonId,
                                                            _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);

            case 17:
                return(_enumerator.Current.SourceValue);

            case 18:
                return(_enumerator.Current.SourceConceptId);

            case 19:
                return(_enumerator.Current.RouteSourceValue);

            case 20:
                return(_enumerator.Current.DoseUnitSourceValue);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #28
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
                return(_offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.Time);

            case 5:
                return(_enumerator.Current.TypeConceptId);

            case 6:
                return(_enumerator.Current.OperatorConceptId);

            case 7:
                return(_enumerator.Current.ValueAsNumber);

            case 8:
                return(_enumerator.Current.ValueAsConceptId);

            case 9:
                return(_enumerator.Current.UnitConceptId);

            case 10:
                return(_enumerator.Current.RangeLow);

            case 11:
                return(_enumerator.Current.RangeHigh);

            case 12:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 13:
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(_offset.GetId(_enumerator.Current.PersonId,
                                             _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);

            case 14:
                return(_enumerator.Current.SourceValue);

            case 15:
                return(_enumerator.Current.SourceConceptId);

            case 16:
                return(_enumerator.Current.UnitSourceValue);

            case 17:
                return(_enumerator.Current.ValueSourceValue);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #29
0
        public override Attrition Build(ChunkData data, KeyMasterOffsetManager o)
        {
            Offset    = o;
            ChunkData = data;

            var result = BuildPerson(PersonRecords.ToList());
            var person = result.Key;

            if (person == null)
            {
                Complete = true;
                return(result.Value);
            }

            var observationPeriods =
                BuildObservationPeriods(9999, ObservationPeriodsRaw.ToArray())
                .ToArray();

            if (Excluded(person, observationPeriods))
            {
                Complete = true;
                return(Attrition.ImplausibleYOBPostEarliestOP);
            }


            var visitDetails = BuildVisitDetails(null, VisitOccurrencesRaw.ToArray(), observationPeriods).ToArray();

            var visitOccurrences = new Dictionary <long, VisitOccurrence>();
            var visitIds         = new List <long>();

            foreach (var visitOccurrence in BuildVisitOccurrences(VisitOccurrencesRaw.ToArray(), observationPeriods))
            {
                if (visitOccurrence.IdUndefined)
                {
                    visitOccurrence.Id          = Offset.GetKeyOffset(visitOccurrence.PersonId).VisitOccurrenceId;
                    visitOccurrence.IdUndefined = false;
                }

                if (!visitOccurrences.ContainsKey(visitOccurrence.Id))
                {
                    visitOccurrences.Add(visitOccurrence.Id, visitOccurrence);
                    visitIds.Add(visitOccurrence.Id);
                }

                var ecntrId = visitOccurrence.AdditionalFields["ecntr_id"];
                if (long.TryParse(ecntrId, out var visitId))
                {
                    if (!_visitIdMap.ContainsKey(visitId))
                    {
                        _visitIdMap.Add(visitId, new List <VisitOccurrence>());
                    }

                    _visitIdMap[visitId].Add(visitOccurrence);
                }
            }

            foreach (var visitDetail in visitDetails)
            {
                var vo = GetVisitOccurrence(visitDetail);
                visitDetail.VisitOccurrenceId = vo?.Id ?? 0;
            }

            long?prevVisitId = null;

            foreach (var visitId in visitIds.OrderBy(v => v))
            {
                if (prevVisitId.HasValue)
                {
                    visitOccurrences[visitId].PrecedingVisitOccurrenceId = prevVisitId;
                }

                prevVisitId = visitId;
            }

            foreach (var e in ConditionOccurrencesRaw)
            {
                SetVisitId(e);
            }

            foreach (var e in ProcedureOccurrencesRaw)
            {
                SetVisitId(e);
            }

            foreach (var e in ObservationsRaw)
            {
                SetVisitId(e);
            }

            foreach (var e in DrugExposuresRaw)
            {
                SetVisitId(e);
            }

            foreach (var e in MeasurementsRaw)
            {
                SetVisitId(e);
            }

            foreach (var e in DeviceExposureRaw)
            {
                SetVisitId(e);
            }

            var conditionOccurrences =
                BuildConditionOccurrences(ConditionOccurrencesRaw.ToArray(), visitOccurrences, observationPeriods)
                .ToArray();

            foreach (var co in conditionOccurrences)
            {
                co.Id = Offset.GetKeyOffset(co.PersonId).ConditionOccurrenceId;
            }

            var procedureOccurrences =
                BuildProcedureOccurrences(ProcedureOccurrencesRaw.ToArray(), visitOccurrences, observationPeriods)
                .ToArray();

            foreach (var procedureOccurrence in procedureOccurrences)
            {
                procedureOccurrence.Id =
                    Offset.GetKeyOffset(procedureOccurrence.PersonId).ProcedureOccurrenceId;
            }

            var observations = BuildObservations(ObservationsRaw.ToArray(), visitOccurrences, observationPeriods)
                               .ToArray();

            foreach (var ob in observations)
            {
                ob.Id = Offset.GetKeyOffset(ob.PersonId).ObservationId;
            }

            var drugExposures =
                BuildDrugExposures(DrugExposuresRaw.ToArray(), visitOccurrences, observationPeriods)
                .ToArray();

            var measurements = BuildMeasurement(MeasurementsRaw.ToArray(), visitOccurrences, observationPeriods)
                               .ToArray();
            var deviceExposure = BuildDeviceExposure(DeviceExposureRaw.ToArray(), visitOccurrences, observationPeriods)
                                 .ToArray();

            // set corresponding ProviderIds
            SetProviderIds(drugExposures);
            SetProviderIds(conditionOccurrences);
            SetProviderIds(visitOccurrences.Values.ToArray());
            SetProviderIds(procedureOccurrences);
            SetProviderIds(observations);
            SetProviderIds(visitDetails);

            // push built entities to ChunkBuilder for further save to CDM database
            AddToChunk(person, null,
                       observationPeriods,
                       new PayerPlanPeriod[0],
                       drugExposures,
                       conditionOccurrences,
                       procedureOccurrences,
                       observations,
                       measurements,
                       visitOccurrences.Values.ToArray(), visitDetails, new Cohort[0], deviceExposure, new Note[0]);

            Complete = true;

            return(Attrition.None);
        }
コード例 #30
0
        // is this called only because the datatype specific methods are not implemented?
        // probably performance to be gained by not passing object back?
        public object GetValue(int i)
        {
            switch (i)
            {
            case 0:
                return(_offset.GetId(_enumerator.Current.PersonId, _enumerator.Current.Id));

            case 1:
                return(_enumerator.Current.PersonId);

            case 2:
                return(_enumerator.Current.ConceptId);

            case 3:
                return(_enumerator.Current.StartDate);

            case 4:
                return(_enumerator.Current.StartDate.TimeOfDay);

            case 5:
                return(_enumerator.Current.TypeConceptId);

            case 6:
                return(_enumerator.Current.ValueAsNumber);

            case 7:
                return(_enumerator.Current.ValueAsString);

            case 8:
                return(_enumerator.Current.ValueAsConceptId);

            case 9:
                return(_enumerator.Current.QualifierConceptId);

            case 10:
                return(_enumerator.Current.UnitsConceptId);

            case 11:
                return(_enumerator.Current.ProviderId == 0 ? null : _enumerator.Current.ProviderId);

            case 12:
                if (_enumerator.Current.VisitOccurrenceId.HasValue)
                {
                    if (_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitOccurrenceIdChanged)
                    {
                        return(_offset.GetId(_enumerator.Current.PersonId,
                                             _enumerator.Current.VisitOccurrenceId.Value));
                    }

                    return(_enumerator.Current.VisitOccurrenceId.Value);
                }

                return(null);

            case 13:
                if (_enumerator.Current.VisitDetailId.HasValue)
                {
                    if (_offset.GetKeyOffset(_enumerator.Current.PersonId).VisitDetailIdChanged)
                    {
                        return(_offset.GetId(_enumerator.Current.PersonId,
                                             _enumerator.Current.VisitDetailId.Value));
                    }

                    return(_enumerator.Current.VisitDetailId);
                }

                return(null);

            case 14:
                return(_enumerator.Current.SourceValue);

            case 15:
                return(_enumerator.Current.SourceConceptId);

            case 16:
                return(_enumerator.Current.UnitsSourceValue);

            case 17:
                return(_enumerator.Current.QualifierSourceValue);

            case 18:
                return(_enumerator.Current.EventId);

            case 19:
                return(_enumerator.Current.EventFieldConceptId);

            case 20:
                return(_enumerator.Current.ValueAsDatetime);

            default:
                throw new NotImplementedException();
            }
        }