public VisitCost CreateEnity(VisitOccurrence visit, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            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;
            }

            return(new VisitCost(visit)
            {
                VisitCostId = keyOffset.VisitCostId,
                PaidCopay = paidCopay,
                PaidCoinsurance = paidCoinsurance,
                PaidTowardDeductible = paidTowardDeductible,
                PaidByPayer = reader.GetDecimal(PaidByPayer),
                PaidByCoordinationBenefits = reader.GetDecimal(PaidByCoordinationBenefits),
                TotalPaid = reader.GetDecimal(TotalPaid),
                TotalOutOfPocket = totalOutOfPocket,
                CurrencyConceptId = reader.GetLong(CurrencyConceptId) ?? 0
            });
        }
        public DeviceCost CreateEnity(DeviceExposure de, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            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;
            }

            long?  revenueCodeConceptId = null;
            string revenueCodeSource    = null;

            if (Concepts != null)
            {
                if (Concepts.Length > 0)
                {
                    var revenueCodeConcept = Concepts[0];

                    if (revenueCodeConcept.Fields.Length > 0)
                    {
                        revenueCodeSource = reader.GetString(revenueCodeConcept.Fields[0].Key);

                        var revenueConcepts = revenueCodeConcept.GetConceptIdValues(Vocabulary, revenueCodeConcept.Fields[0],
                                                                                    reader);
                        if (revenueConcepts.Count > 0)
                        {
                            revenueCodeConceptId = revenueConcepts[0].ConceptId;
                        }
                    }
                }
            }

            return(new DeviceCost(de)
            {
                DeviceCostId = keyOffset.DeviceCostId,
                PaidCopay = paidCopay,
                PaidCoinsurance = paidCoinsurance,
                PaidTowardDeductible = paidTowardDeductible,
                PaidByPayer = reader.GetDecimal(PaidByPayer),
                PaidByCoordinationBenefits = reader.GetDecimal(PaidByCoordinationBenefits),
                TotalPaid = reader.GetDecimal(TotalPaid),
                TotalOutOfPocket = totalOutOfPocket,
                CurrencyConceptId = reader.GetLong(CurrencyConceptId) ?? 0,
                RevenueCodeConceptId = revenueCodeConceptId,
                RevenueCodeSourceValue = revenueCodeSource,
            });
        }
Esempio n. 3
0
        public VisitCost CreateEnity(VisitOccurrence visit, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            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;
            }

            long?  drgConceptId;
            string drgSource;
            long?  revenueCodeConceptId;
            string revenueCodeSource;

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

            return(new VisitCost(visit)
            {
                VisitCostId = keyOffset.VisitCostId,
                PaidCopay = paidCopay,
                PaidCoinsurance = paidCoinsurance,
                PaidTowardDeductible = paidTowardDeductible,
                PaidByPayer = reader.GetDecimal(PaidByPayer),
                PaidByCoordinationBenefits = reader.GetDecimal(PaidByCoordinationBenefits),
                TotalPaid = reader.GetDecimal(TotalPaid),
                TotalOutOfPocket = totalOutOfPocket,
                CurrencyConceptId = reader.GetLong(CurrencyConceptId) ?? 0,
                DrgConceptId = drgConceptId,
                DrgSourceValue = drgSource,
                RevenueCodeConceptId = revenueCodeConceptId,
                RevenueCodeSourceValue = revenueCodeSource
            });
        }
Esempio n. 4
0
        private static void UpdateOffset(KeyMasterOffset offset)
        {
            var visitOffset = 0;

            if (offset.VisitOccurrenceIdChanged)
            {
                visitOffset = offset.VisitOccurrenceId;
            }

            var periodOffset = 0;

            if (offset.PayerPlanPeriodIdChanged)
            {
                periodOffset = offset.PayerPlanPeriodId;
            }

            var drugOffset = 0;

            if (offset.DrugExposureIdChanged)
            {
                drugOffset = offset.DrugExposureId;
            }

            var procedureOffset = 0;

            if (offset.ProcedureOccurrenceIdChanged)
            {
                procedureOffset = offset.ProcedureOccurrenceId;
            }

            var dbKeyOffset = new DbKeyOffset(Settings.Current.Building.BuilderConnectionString);

            foreach (var reader in dbKeyOffset.Update(Settings.Current.Building.Id.Value, visitOffset, periodOffset, drugOffset, procedureOffset))
            {
                offset.VisitOccurrenceOffset     = reader.GetLong("VisitOccurrence").Value - visitOffset;
                offset.PayerPlanPeriodOffset     = reader.GetLong("PayerPlanPeriod").Value - periodOffset;
                offset.DrugExposureOffset        = reader.GetLong("DrugExposure").Value - drugOffset;
                offset.ProcedureOccurrenceOffset = reader.GetLong("ProcedureOccurrence").Value - procedureOffset;
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var personId = reader.GetLong(PersonId);

            var  startDate = reader.GetDateTime(StartDate);
            var  endDate   = reader.GetDateTime(EndDate);
            long?id        = 0;

            if (!string.IsNullOrEmpty(Id))
            {
                id = reader.GetLong(Id);
            }

            if (personId.HasValue)
            {
                Dictionary <string, string> additionalFields = null;
                if (AdditionalFields != null)
                {
                    additionalFields = new Dictionary <string, string>(AdditionalFields.Length, StringComparer.OrdinalIgnoreCase);
                    foreach (var additionalField in AdditionalFields)
                    {
                        additionalFields.Add(additionalField, reader.GetString(additionalField));
                    }
                }

                var payerSourceValue = reader.GetString(PayerSource);
                if (string.IsNullOrWhiteSpace(payerSourceValue))
                {
                    payerSourceValue = null;
                }

                var planSource = reader.GetString(PlanSource);
                if (string.IsNullOrWhiteSpace(planSource))
                {
                    planSource = null;
                }

                yield return(new PayerPlanPeriod
                {
                    Id = id ?? 0,
                    PersonId = personId.Value,
                    StartDate = startDate,
                    EndDate = endDate,
                    PayerSourceValue = payerSourceValue,
                    PlanSourceValue = planSource,
                    FamilySourceValue = reader.GetString(FamilySource),
                    VisitOccurrenceId = reader.GetLong(VisitOccurrenceId),
                    AdditionalFields = additionalFields
                });
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            long?relevantConditionConceptId = null;

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

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

            foreach (var e in base.GetConcepts(concept, reader, keyMaster))
            {
                yield return
                    (new ProcedureOccurrence((Entity)e)
                {
                    Id = keyMaster.ProcedureOccurrenceId,
                    ReleventConditionConceptId = relevantConditionConceptId
                });
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            long?relevantConditionConceptId = null;
            long?modifierConceptId          = reader.GetLong(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, keyOffset))
            {
                yield return
                    (new ProcedureOccurrence(e)
                {
                    Id = keyOffset.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)
                });
            }
        }
Esempio n. 8
0
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public PayerPlanPeriodDataReader(List <PayerPlanPeriod> batch, KeyMasterOffset offset)
 {
     enumerator  = batch.GetEnumerator();
     this.offset = offset;
 }
Esempio n. 9
0
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public ConditionOccurrenceDataReader52(List <ConditionOccurrence> batch, KeyMasterOffset offset)
 {
     conditionEnumerator = batch.GetEnumerator();
     this.offset         = offset;
 }
Esempio n. 10
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var id = string.IsNullOrEmpty(Id) ? KeyMaster.GetLocationId() : reader.GetLong(Id);

            yield return(new Location
            {
                Id = id.Value,
                State = reader.GetString(State),
                SourceValue = reader.GetString(SourceValue),
                County = reader.GetString(Country),
                Address1 = reader.GetString(Address1),
                Address2 = reader.GetString(Address2)
            });
        }
Esempio n. 11
0
        public void Update(int buildingId, KeyMasterOffset offset, long visitOffset, long periodOffset, long drugOffset,
                           long procedureOffset, long deviceOffset, long conditionOffset, long measurementOffset, long observationOffset,
                           long observationPeriodOffset, long visitCostOffset, long procedureCostOffset, long deviceCostOffset,
                           long drugEraOffset, long conditionEraOffset, long noteOffset)
        {
            var attempt = 0;
            var done    = false;

            while (!done)
            {
                using (var connection = SqlConnectionHelper.OpenMSSQLConnection(connectionString))
                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            attempt++;
                            const string updateQuery = "UPDATE [KeyOffset] " +
                                                       "SET [VisitOccurrence] = [VisitOccurrence] + @visitOffset " +
                                                       ",[PayerPlanPeriod] = [PayerPlanPeriod] + @periodOffset " +
                                                       ",[DrugExposure] = [DrugExposure] + @drugOffset " +
                                                       ",[ProcedureOccurrence] = [ProcedureOccurrence] + @procedureOffset " +
                                                       ",[DeviceExposure] = [DeviceExposure] + @deviceOffset " +

                                                       ",[ConditionOccurrence] = [ConditionOccurrence] +  @conditionOffset " +
                                                       ",[Measurement] = [Measurement] + @measurementOffset " +
                                                       ",[Observation] = [Observation] + @observationOffset " +
                                                       ",[ObservationPeriod] = [ObservationPeriod] + @observationPeriodOffset " +
                                                       ",[VisitCost] = [VisitCost] + @visitCostOffset " +
                                                       ",[ProcedureCost] = [ProcedureCost] + @procedureCostOffset " +
                                                       ",[DeviceCost] = [DeviceCost] + @deviceCostOffset " +
                                                       ",[DrugEra] = [DrugEra] + @drugEraOffset " +
                                                       ",[Note] = [Note] + @noteOffset " +
                                                       ",[ConditionEra] = [ConditionEra] + @conditionEraOffset " +
                                                       "OUTPUT INSERTED.[VisitOccurrence], INSERTED.[PayerPlanPeriod], INSERTED.[DrugExposure], INSERTED.[ProcedureOccurrence], INSERTED.[DeviceExposure], " +
                                                       "INSERTED.[ConditionOccurrence], INSERTED.[Measurement], INSERTED.[Observation], INSERTED.[ObservationPeriod], INSERTED.[VisitCost], INSERTED.[ProcedureCost], INSERTED.[DeviceCost], INSERTED.[DrugEra], INSERTED.[ConditionEra], INSERTED.[Note] " +
                                                       "WHERE [BuildingId] = @buildingId ";

                            using (var cmd = new SqlCommand(updateQuery, connection, transaction))
                            {
                                cmd.Parameters.Add("@buildingId", SqlDbType.Int);
                                cmd.Parameters["@buildingId"].Value = buildingId;

                                cmd.Parameters.Add("@visitOffset", SqlDbType.BigInt);
                                cmd.Parameters["@visitOffset"].Value = visitOffset;

                                cmd.Parameters.Add("@periodOffset", SqlDbType.BigInt);
                                cmd.Parameters["@periodOffset"].Value = periodOffset;

                                cmd.Parameters.Add("@drugOffset", SqlDbType.BigInt);
                                cmd.Parameters["@drugOffset"].Value = drugOffset;

                                cmd.Parameters.Add("@procedureOffset", SqlDbType.BigInt);
                                cmd.Parameters["@procedureOffset"].Value = procedureOffset;

                                cmd.Parameters.Add("@deviceOffset", SqlDbType.BigInt);
                                cmd.Parameters["@deviceOffset"].Value = deviceOffset;

                                cmd.Parameters.Add("@conditionOffset", SqlDbType.BigInt);
                                cmd.Parameters["@conditionOffset"].Value = conditionOffset;

                                cmd.Parameters.Add("@measurementOffset", SqlDbType.BigInt);
                                cmd.Parameters["@measurementOffset"].Value = measurementOffset;

                                cmd.Parameters.Add("@observationOffset", SqlDbType.BigInt);
                                cmd.Parameters["@observationOffset"].Value = observationOffset;

                                cmd.Parameters.Add("@observationPeriodOffset", SqlDbType.BigInt);
                                cmd.Parameters["@observationPeriodOffset"].Value = observationPeriodOffset;

                                cmd.Parameters.Add("@visitCostOffset", SqlDbType.BigInt);
                                cmd.Parameters["@visitCostOffset"].Value = visitCostOffset;

                                cmd.Parameters.Add("@procedureCostOffset", SqlDbType.BigInt);
                                cmd.Parameters["@procedureCostOffset"].Value = procedureCostOffset;

                                cmd.Parameters.Add("@deviceCostOffset", SqlDbType.BigInt);
                                cmd.Parameters["@deviceCostOffset"].Value = deviceCostOffset;

                                cmd.Parameters.Add("@drugEraOffset", SqlDbType.BigInt);
                                cmd.Parameters["@drugEraOffset"].Value = drugEraOffset;

                                cmd.Parameters.Add("@conditionEraOffset", SqlDbType.BigInt);
                                cmd.Parameters["@conditionEraOffset"].Value = conditionEraOffset;

                                cmd.Parameters.Add("@noteOffset", SqlDbType.BigInt);
                                cmd.Parameters["@noteOffset"].Value = noteOffset;

                                cmd.CommandTimeout = 30000;
                                using (var reader = cmd.ExecuteReader())
                                {
                                    while (reader.Read())
                                    {
                                        offset.VisitOccurrenceOffset     = reader.GetLong("VisitOccurrence").Value - visitOffset;
                                        offset.PayerPlanPeriodOffset     = reader.GetLong("PayerPlanPeriod").Value - periodOffset;
                                        offset.DrugExposureOffset        = reader.GetLong("DrugExposure").Value - drugOffset;
                                        offset.ProcedureOccurrenceOffset = reader.GetLong("ProcedureOccurrence").Value -
                                                                           procedureOffset;
                                        offset.DeviceExposureOffset = reader.GetLong("DeviceExposure").Value - deviceOffset;

                                        offset.ConditionOccurrenceOffset = reader.GetLong("ConditionOccurrence").Value -
                                                                           conditionOffset;
                                        offset.MeasurementOffset       = reader.GetLong("Measurement").Value - measurementOffset;
                                        offset.ObservationOffset       = reader.GetLong("Observation").Value - observationOffset;
                                        offset.ObservationPeriodOffset = reader.GetLong("ObservationPeriod").Value -
                                                                         observationPeriodOffset;
                                        offset.VisitCostOffset     = reader.GetLong("VisitCost").Value - visitCostOffset;
                                        offset.ProcedureCostOffset = reader.GetLong("ProcedureCost").Value - procedureCostOffset;
                                        offset.DeviceCostOffset    = reader.GetLong("DeviceCost").Value - deviceCostOffset;
                                        offset.DrugEraOffset       = reader.GetLong("DrugEra").Value - drugEraOffset;
                                        offset.ConditionEraOffset  = reader.GetLong("ConditionEra").Value - conditionEraOffset;
                                        offset.NoteOffset          = reader.GetLong("Note").Value - noteOffset;
                                    }
                                }
                            }

                            transaction.Commit();
                            done = true;
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();

                            if (attempt > 10)
                            {
                                throw;
                            }
                        }
                    }
            }
        }
Esempio n. 12
0
        private static void UpdateOffset(KeyMasterOffset offset)
        {
            var visitOffset = 0;

            if (offset.VisitOccurrenceIdChanged)
            {
                visitOffset = offset.VisitOccurrenceId;
            }

            var periodOffset = 0;

            if (offset.PayerPlanPeriodIdChanged)
            {
                periodOffset = offset.PayerPlanPeriodId;
            }

            var drugOffset = 0;

            if (offset.DrugExposureIdChanged)
            {
                drugOffset = offset.DrugExposureId;
            }

            var procedureOffset = 0;

            if (offset.ProcedureOccurrenceIdChanged)
            {
                procedureOffset = offset.ProcedureOccurrenceId;
            }

            var deviceOffset = 0;

            if (offset.DeviceExposureIdChanged)
            {
                deviceOffset = offset.DeviceExposureId;
            }



            var conditionOffset = 0;

            if (offset.ConditionOccurrenceIdChanged)
            {
                conditionOffset = offset.ConditionOccurrenceId;
            }

            var measurementOffset = 0;

            if (offset.MeasurementIdChanged)
            {
                measurementOffset = offset.MeasurementId;
            }

            var observationOffset = 0;

            if (offset.ObservationIdChanged)
            {
                observationOffset = offset.ObservationId;
            }

            var observationPeriodOffset = 0;

            if (offset.ObservationPeriodIdChanged)
            {
                observationPeriodOffset = offset.ObservationPeriodId;
            }

            var visitCostOffset = 0;

            if (offset.VisitCostIdChanged)
            {
                visitCostOffset = offset.VisitCostId;
            }

            var procedureCostOffset = 0;

            if (offset.ProcedureCostIdChanged)
            {
                procedureCostOffset = offset.ProcedureCostId;
            }

            var deviceCostOffset = 0;

            if (offset.DeviceCostIdChanged)
            {
                deviceCostOffset = offset.DeviceCostId;
            }

            var drugEraOffset = 0;

            if (offset.DrugEraIdChanged)
            {
                drugEraOffset = offset.DrugEraId;
            }

            var conditionEraOffset = 0;

            if (offset.ConditionEraIdChanged)
            {
                conditionEraOffset = offset.ConditionEraId;
            }

            var dbKeyOffset = new DbKeyOffset(Settings.Current.Building.BuilderConnectionString);

            foreach (
                var reader in
                dbKeyOffset.Update(Settings.Current.Building.Id.Value, visitOffset, periodOffset, drugOffset,
                                   procedureOffset, deviceOffset, conditionOffset, measurementOffset, observationOffset,
                                   observationPeriodOffset, visitCostOffset, procedureCostOffset, deviceCostOffset, drugEraOffset,
                                   conditionEraOffset))
            {
                offset.VisitOccurrenceOffset     = reader.GetLong("VisitOccurrence").Value - visitOffset;
                offset.PayerPlanPeriodOffset     = reader.GetLong("PayerPlanPeriod").Value - periodOffset;
                offset.DrugExposureOffset        = reader.GetLong("DrugExposure").Value - drugOffset;
                offset.ProcedureOccurrenceOffset = reader.GetLong("ProcedureOccurrence").Value - procedureOffset;
                offset.DeviceExposureOffset      = reader.GetLong("DeviceExposure").Value - deviceOffset;

                offset.ConditionOccurrenceOffset = reader.GetLong("ConditionOccurrence").Value - conditionOffset;
                offset.MeasurementOffset         = reader.GetLong("Measurement").Value - measurementOffset;
                offset.ObservationOffset         = reader.GetLong("Observation").Value - observationOffset;
                offset.ObservationPeriodOffset   = reader.GetLong("ObservationPeriod").Value - observationPeriodOffset;
                offset.VisitCostOffset           = reader.GetLong("VisitCost").Value - visitCostOffset;
                offset.ProcedureCostOffset       = reader.GetLong("ProcedureCost").Value - procedureCostOffset;
                offset.DeviceCostOffset          = reader.GetLong("DeviceCost").Value - deviceCostOffset;
                offset.DrugEraOffset             = reader.GetLong("DrugEra").Value - drugEraOffset;
                offset.ConditionEraOffset        = reader.GetLong("ConditionEra").Value - conditionEraOffset;
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var de = base.GetConcepts(concept, reader, keyOffset).ToList();

            if (de.Count > 0)
            {
                yield return(new DeviceExposure(de[0])
                {
                    Id = keyOffset.DeviceExposureId,
                    UniqueDeviceId = reader.GetString(UniqueDeviceId),
                    StartTime = de[0].StartTime ?? de[0].StartDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
                    Quantity = reader.GetInt(Quantity) ?? 0
                });
            }
        }
Esempio n. 14
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            long?    relevantConditionConceptId = 0;
            DateTime?endDate = null;

            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);
                }
            }


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

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

                yield return(new DrugExposure(e)
                {
                    Id = keyOffset.DrugExposureId,
                    Refills = reader.GetInt(Refill),
                    DaysSupply = reader.GetInt(DaysSupply),
                    CalculatedDaysSupply = calculatedDaysSupply,
                    Quantity = reader.GetDecimal(Quantity),
                    Sig = reader.GetString(Sig),
                    RelevantConditionConceptId = relevantConditionConceptId,
                    EndDate = endDate == DateTime.MinValue ? null : endDate,
                    GetEraConceptIdsCall = Vocabulary.LookupIngredientLevel,
                    RouteConceptId = reader.GetLong(RouteConceptId),
                    RouteSourceValue = reader.GetString(RouteSourceValue),
                    DoseUnitConceptId = reader.GetLong(DoseUnitConceptId),
                    DoseUnitSourceValue = reader.GetString(DoseUnitSourceValue),
                    StopReason = reader.GetString(StopReason)
                });
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var de = base.GetConcepts(concept, reader, keyOffset).ToList();

            if (de.Count > 0)
            {
                yield return(new DeviceExposure(de[0])
                {
                    Id = keyOffset.DeviceExposureId,
                    UniqueDeviceId = reader.GetString(UniqueDeviceId),
                    Quantity = reader.GetInt(Quantity) ?? 0
                });
            }
        }
Esempio n. 16
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var id = string.IsNullOrEmpty(Id) ? KeyMaster.GetLocationId() : int.Parse(reader[Id].ToString());

            yield return(new Location
            {
                Id = id,
                State = reader.GetString(State),
                SourceValue = reader.GetString(SourceValue)
            });
        }
Esempio n. 17
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var locationSourceValue = reader.GetString(Location);
            int?locationId          = null;

            if (!string.IsNullOrEmpty(Location))
            {
                locationId = Vocabulary.LookupLocation(locationSourceValue);
            }

            var observationPeriodGap = 32;

            if (!string.IsNullOrEmpty(ObservationPeriodGap))
            {
                observationPeriodGap = int.Parse(ObservationPeriodGap);
            }

            var genderSource    = reader.GetString(Gender);
            var genderConceptId = Vocabulary.LookupGender(genderSource);

            var personId = reader.GetLong(PersonId);

            if (personId.HasValue)
            {
                yield return(new Person
                {
                    ObservationPeriodGap = observationPeriodGap,
                    PersonId = personId.Value,
                    StartDate = reader.GetDateTime(StartDate),
                    EndDate = reader.GetDateTime(EndDate),
                    PersonSourceValue = reader.GetString(PersonSourceValue),
                    GenderSourceValue = genderSource,
                    GenderConceptId = genderConceptId,
                    LocationId = locationId,
                    YearOfBirth = reader.GetInt(YearOfBirth),
                    MonthOfBirth = reader.GetInt(MonthOfBirth),
                    DayOfBirth = reader.GetInt(DayOfBirth),
                    LocationSourceValue = locationSourceValue,
                    CareSiteId = reader.GetInt(CareSiteId),
                    EthnicitySourceValue = reader.GetString(Ethnicity),
                    EthnicityConceptId = reader.GetInt(EthnicityConceptId) ?? 0,
                    RaceSourceValue = reader.GetString(Race),
                    RaceConceptId = reader.GetInt(RaceConceptId) ?? 0,
                    ProviderId = reader.GetInt(ProviderId)
                });
            }
        }
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public ObservationPeriodDataReader52(List <ObservationPeriod> batch, KeyMasterOffset offset)
 {
     this.observationPeriodsEnumerator = batch.GetEnumerator();
     this.offset = offset;
 }
 public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var  id        = string.IsNullOrEmpty(Id) ? KeyMaster.GetCareSiteId() : reader.GetLong(Id);
            long conceptId = 0;

            if (!string.IsNullOrEmpty(PlaceOfSvcConceptId) && reader.GetLong(PlaceOfSvcConceptId).HasValue)
            {
                conceptId = reader.GetLong(PlaceOfSvcConceptId).Value;
            }

            var locationId          = reader.GetLong(LocationId);
            var careSiteSourceValue = string.IsNullOrEmpty(CareSiteSourceValue)
            ? id.Value.ToString(CultureInfo.InvariantCulture)
            : reader.GetString(CareSiteSourceValue);

            if (concept == null)
            {
                yield return(new CareSite
                {
                    Id = id.Value,
                    LocationId = locationId.HasValue ? locationId.Value : 0,
                    PlaceOfSvcSourceValue = reader.GetString(PlaceOfSvcSourceValue),
                    ConceptId = conceptId,
                    Name = reader.GetString(Name),
                    SourceValue = careSiteSourceValue
                });
            }
            else
            {
                var conceptField = concept.Fields[0];

                var source = reader.GetString(conceptField.Key) ?? reader.GetString(conceptField.SourceKey);
                if (source != null && source.Length == 0)
                {
                    source = null;
                }

                var  placeOfSvcConceptIds = concept.GetConceptIdValues(Vocabulary, conceptField, reader).ToList();
                long?placeOfSvcConceptId  = null;

                long defaultConceptId = 0;
                if (conceptField.DefaultConceptId.HasValue)
                {
                    defaultConceptId = conceptField.DefaultConceptId.Value;
                }

                if (placeOfSvcConceptIds.Count > 0 && placeOfSvcConceptIds[0].ConceptId != 0)
                {
                    placeOfSvcConceptId = placeOfSvcConceptIds[0].ConceptId;
                }

                yield return(new CareSite
                {
                    Id = id.Value,
                    LocationId = locationId.HasValue ? locationId.Value : 0,
                    PlaceOfSvcSourceValue = source,
                    ConceptId = placeOfSvcConceptId.HasValue ? placeOfSvcConceptId.Value : defaultConceptId,
                    Name = reader.GetString(Name),
                    SourceValue = careSiteSourceValue
                });
            }
        }
        public ProcedureCost CreateEnity(ProcedureOccurrence procedure, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var paidCopay            = reader.GetDecimal(PaidCopay);
            var paidCoinsurance      = reader.GetDecimal(PaidCoinsurance);
            var paidTowardDeductible = reader.GetDecimal(PaidTowardDeductible);

            long?  revenueCodeConceptId  = null;
            string revenueCodeSource     = null;
            long?  diseaseClassConceptId = null;
            var    diseaseClassSource    = "";
            string diseaseClassLookupKey = null;

            if (Concepts != null)
            {
                if (Concepts.Length > 0)
                {
                    var revenueCodeConcept = Concepts[0];

                    if (revenueCodeConcept.Fields.Length > 0)
                    {
                        revenueCodeSource = reader.GetString(revenueCodeConcept.Fields[0].Key);

                        var revenueConcepts = revenueCodeConcept.GetConceptIdValues(Vocabulary, revenueCodeConcept.Fields[0], reader);
                        if (revenueConcepts.Count > 0)
                        {
                            revenueCodeConceptId = revenueConcepts[0].ConceptId;
                        }
                    }
                }

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

                    if (diseaseConcepts.Count > 0)
                    {
                        diseaseClassConceptId = diseaseConcepts[0].ConceptId;
                    }

                    diseaseClassLookupKey = diseaseClassConcept.GetConceptIdLookupKey(reader);
                }
            }

            decimal?totalOutOfPocket = null;

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

            return(new ProcedureCost(procedure)
            {
                ProcedureCostId = keyOffset.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,
                DiseaseClassConceptId = diseaseClassConceptId,
                DiseaseClassSourceValue = diseaseClassSource,
                DiseaseClassLookupKey = diseaseClassLookupKey,
                CurrencyConceptId = reader.GetLong(CurrencyConceptId) ?? 0
            });
        }
Esempio n. 22
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var obsConcepts = base.GetConcepts(concept, reader, keyMaster).ToList();

            if (obsConcepts.Count > 0)
            {
                var  unitConcept = GetUnitConcept(reader);
                long?relevantConditionConceptId = null;

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

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

                var createObservation = new Func <Observation>(() => new Observation((Entity)obsConcepts[0])
                {
                    SourceValue                = string.IsNullOrWhiteSpace(obsConcepts[0].SourceValue) ? null : obsConcepts[0].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,
                    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 (!string.IsNullOrEmpty(obsConcepts[0].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);
                }
            }
        }
Esempio n. 23
0
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public NoteDataReader52(List <Note> batch, KeyMasterOffset offset)
 {
     enumerator  = batch.GetEnumerator();
     this.offset = offset;
 }
Esempio n. 24
0
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public DrugExposureDataReader(List <DrugExposure> batch, KeyMasterOffset offset)
 {
     exposureEnumerator = batch.GetEnumerator();
     this.offset        = offset;
 }
Esempio n. 25
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            var locationSourceValue = reader.GetString(Location);
            int?locationId          = null;

            if (!string.IsNullOrEmpty(Location))
            {
                locationId = Vocabulary.LookupLocation(locationSourceValue);
            }

            var genderSource    = reader.GetString(Gender);
            var genderConceptId = Vocabulary.LookupGender(genderSource);

            var personId = reader.GetLong(PersonId);

            if (personId.HasValue)
            {
                Dictionary <string, string> additionalFields = null;
                if (AdditionalFields != null)
                {
                    additionalFields = new Dictionary <string, string>(AdditionalFields.Length, StringComparer.OrdinalIgnoreCase);
                    foreach (var additionalField in AdditionalFields)
                    {
                        additionalFields.Add(additionalField, reader.GetString(additionalField));
                    }
                }

                var startDate = reader.GetDateTime(StartDate);
                var endDate   = reader.GetDateTime(EndDate);
                var startTime = reader.GetTime(StartTime) ?? startDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture);
                var endTime   = reader.GetTime(EndTime) ?? endDate.ToString("HH:mm:ss", CultureInfo.InvariantCulture);

                yield return(new Person
                {
                    ObservationPeriodGap = reader.GetInt(ObservationPeriodGap) ?? 32,
                    AdditionalFields = additionalFields,
                    PersonId = personId.Value,
                    StartDate = startDate,
                    EndDate = endDate,
                    StartTime = startTime,
                    EndTime = endTime,
                    PersonSourceValue = reader.GetString(PersonSourceValue),
                    GenderSourceValue = genderSource,
                    GenderConceptId = genderConceptId ?? 0,
                    LocationId = locationId,
                    YearOfBirth = reader.GetInt(YearOfBirth),
                    MonthOfBirth = reader.GetInt(MonthOfBirth),
                    DayOfBirth = reader.GetInt(DayOfBirth),
                    LocationSourceValue = locationSourceValue,
                    CareSiteId = reader.GetInt(CareSiteId),
                    EthnicitySourceValue = reader.GetString(Ethnicity),
                    EthnicityConceptId = reader.GetInt(EthnicityConceptId) ?? 0,
                    RaceSourceValue = reader.GetString(Race),
                    RaceConceptId = reader.GetInt(RaceConceptId) ?? 0,
                    ProviderId = reader.GetInt(ProviderId),
                    TimeOfBirth = reader.GetTime(TimeOfBirth),
                    GenderSourceConceptId = reader.GetInt(GenderSourceConceptId) ?? 0,            // CCAE
                    RaceSourceConceptId = reader.GetInt(RaceSourceConceptId) ?? 0,
                    EthnicitySourceConceptId = reader.GetInt(EthnicitySourceConceptId) ?? 0,
                    TypeConceptId = reader.GetInt(PeriodTypeConceptId),
                });
            }
        }
Esempio n. 26
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var id = string.IsNullOrEmpty(Id) ? KeyMaster.GetCareSiteId() : int.Parse(reader[Id].ToString());

            yield return(new CareSite
            {
                Id = id,
                LocationId = reader.GetLong(LocationId).Value,
                PlaceOfSvcSourceValue = reader.GetString(PlaceOfSvcSourceValue),
                SourceValue = id.ToString()
            });
        }
Esempio n. 27
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var personId  = reader.GetLong(PersonId);
            var startDate = reader.GetDateTime(StartDate);
            var endDate   = reader.GetDateTime(EndDate);

            var e = new Entity
            {
                IsUnique      = false,
                PersonId      = personId.Value,
                SourceValue   = " ",
                ConceptId     = concept.Fields[0].DefaultConceptId.Value,
                TypeConceptId = concept.Fields[0].DefaultTypeId.Value,
                StartDate     = startDate,
                EndDate       = endDate
            };

            yield return(new Cohort(e)
            {
                Id = reader.GetLong(Id).Value
            });
        }
 // A custom DataReader is implemented to prevent the need for the HashSet to be transformed to a DataTable for loading by SqlBulkCopy
 public ProcedureCostDataReader(List <ProcedureCost> batch, KeyMasterOffset offset)
 {
     enumerator  = batch.GetEnumerator();
     this.offset = offset;
 }
Esempio n. 29
0
        public virtual IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            var personId = reader.GetLong(PersonId);

            if (personId.HasValue)
            {
                var startDate = reader.GetDateTime(StartDate);
                var endDate   = startDate;
                if (!string.IsNullOrEmpty(EndDate))
                {
                    endDate = reader.GetDateTime(EndDate);
                }

                Dictionary <string, string> additionalFields = null;
                if (AdditionalFields != null)
                {
                    additionalFields = new Dictionary <string, string>(AdditionalFields.Length);
                    foreach (var additionalField in AdditionalFields)
                    {
                        additionalFields.Add(additionalField.ToLower(), reader.GetString(additionalField));
                    }
                }

                foreach (var field in concept.Fields)
                {
                    var sourceValue = field.DefaultSource;
                    if (string.IsNullOrEmpty(sourceValue))
                    {
                        sourceValue = reader.GetString(field.Key);
                    }

                    if (!field.IsNullable && string.IsNullOrEmpty(sourceValue) && field.DefaultConceptId == null && field.ConceptId == null)
                    {
                        continue;
                    }

                    // Used when: field.Key used for conceptId mapping and
                    // field.SourceKey used for SourceValue (by default field.Key and field.SourceKey are identical)
                    if (!string.IsNullOrEmpty(field.SourceKey))
                    {
                        sourceValue = reader.GetString(field.SourceKey);
                    }

                    if (!string.IsNullOrEmpty(concept.SourceLookup))
                    {
                        var source = Vocabulary.LookupSource(sourceValue, concept.SourceLookup);
                        if (!string.IsNullOrEmpty(source))
                        {
                            sourceValue = source;
                        }
                    }

                    foreach (var lookupValue in concept.GetValues(Vocabulary, field, reader))
                    {
                        var cId = lookupValue.ConceptId;
                        if (!cId.HasValue && field.DefaultConceptId.HasValue)
                        {
                            cId = field.DefaultConceptId;
                        }

                        if (!concept.IdRequired || cId.HasValue)
                        {
                            yield return(new Entity
                            {
                                IsUnique = IsUnique,
                                PersonId = personId.Value,
                                SourceValue = sourceValue,
                                ConceptId = cId.HasValue ? cId.Value : 0,
                                TypeConceptId = concept.GetTypeId(field, reader),
                                StartDate = startDate,
                                EndDate = endDate == DateTime.MinValue ? (DateTime?)null : endDate,
                                ProviderId = reader.GetInt(ProviderId),
                                ProviderKey = reader.GetString(ProviderIdKey),
                                VisitOccurrenceId = reader.GetLong(VisitOccurrenceId),
                                AdditionalFields = additionalFields,
                                ValidStartDate = lookupValue.ValidStartDate,
                                ValidEndDate = lookupValue.ValidEndDate
                            });
                        }
                    }
                }
            }
        }
Esempio n. 30
0
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataReader reader, KeyMasterOffset keyMaster)
        {
            long?    relevantConditionConceptId = 0;
            DateTime?endDate = null;

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

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


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

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

                var refillString = reader.GetString(Refill);

                int?refill = null;

                if (!string.IsNullOrEmpty(refillString))
                {
                    int refillValue;

                    // in Optum Refill looks like: 01, 02...
                    int.TryParse(refillString, out refillValue);

                    refill = refillValue;
                }

                yield return(new DrugExposure(e)
                {
                    Id = keyMaster.DrugExposureId,
                    Refills = refill,
                    DaysSupply = reader.GetInt(DaysSupply),
                    CalculatedDaysSupply = calculatedDaysSupply,
                    Quantity = GetQuantity(reader),
                    RelevantConditionConceptId = relevantConditionConceptId,
                    EndDate = endDate == DateTime.MinValue ? null : endDate,
                    GetEraConceptIdsCall = Vocabulary.LookupIngredientLevel
                });
            }
        }