Esempio n. 1
0
        private IEnumerable <IEntity> PopulateDeath(IDataRecord reader, Concept secondaryConcept, IEntity baseConcept)
        {
            foreach (var field in secondaryConcept.Fields)
            {
                foreach (var lookupValue in secondaryConcept.GetConceptIdValues(Vocabulary, field, reader))
                {
                    if (lookupValue.ConceptId > 0)
                    {
                        yield return(new Death((Entity)baseConcept)
                        {
                            TypeConceptId = field.DefaultTypeId ?? 0,
                            ValidStartDate = lookupValue.ValidStartDate,
                            ValidEndDate = lookupValue.ValidEndDate,
                            SourceConceptId = lookupValue.SourceConceptId
                                              //TypeConceptId = 0 // !!!
                        });

                        break;
                    }
                }
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager offset)
        {
            var id        = string.IsNullOrEmpty(Id) ? -1 : reader.GetLong(Id);
            int conceptId = 0;

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

            var locationId = reader.GetLong(LocationId);

            if (!locationId.HasValue)
            {
                var locationSourceValue = reader.GetString(Location);
                if (!string.IsNullOrEmpty(Location))
                {
                    locationId = Entity.GetId(locationSourceValue);
                }
            }

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

            if (concept == null)
            {
                var cs = new CareSite
                {
                    LocationId            = locationId ?? 0,
                    PlaceOfSvcSourceValue = reader.GetString(PlaceOfSvcSourceValue),
                    ConceptId             = conceptId,
                    Name        = reader.GetString(Name),
                    SourceValue = careSiteSourceValue
                };

                if (id.Value == -1)
                {
                    id = Entity.GetId(cs.GetKey());
                }

                cs.Id = id.Value;

                yield return(cs);
            }
            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();
                int?placeOfSvcConceptId  = null;

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

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

                var cs = new CareSite
                {
                    LocationId            = locationId ?? 0,
                    PlaceOfSvcSourceValue = source,
                    ConceptId             = placeOfSvcConceptId ?? defaultConceptId,
                    Name        = reader.GetString(Name),
                    SourceValue = careSiteSourceValue
                };

                if (id.Value == -1)
                {
                    id = Entity.GetId(cs.GetKey());
                }

                cs.Id = id.Value;

                yield return(cs);
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager keyOffset)
        {
            var genderConceptId = 0;

            if (string.IsNullOrEmpty(GenderConceptId) && Vocabulary != null)
            {
                genderConceptId = Vocabulary.LookupGender(GenderSourceValue) ?? 0;
            }
            else if (reader.GetInt(GenderConceptId).HasValue)
            {
                genderConceptId = reader.GetInt(GenderConceptId).Value;
            }

            var providerIdKey = reader.GetString(ProviderIdKey);

            if (!string.IsNullOrEmpty(providerIdKey))
            {
                providerIdKey = providerIdKey.TrimStart('0');
            }

            if (concept == null)
            {
                var prov = new Provider
                {
                    CareSiteId          = reader.GetLong(CareSiteId) ?? 0,
                    ProviderSourceValue = reader.GetString(ProviderSourceValue),
                    SourceValue         = reader.GetString(SpecialtySourceValue),
                    Npi                      = reader.GetString(NPI),
                    Dea                      = reader.GetString(DEA),
                    Name                     = reader.GetString(Name),
                    YearOfBirth              = reader.GetInt(YearOfBirth),
                    GenderConceptId          = genderConceptId,
                    GenderSourceValue        = reader.GetString(GenderSourceValue),
                    GenderSourceConceptId    = reader.GetInt(GenderSourceConceptId) ?? 0,
                    SpecialtySourceConceptId = reader.GetInt(SpecialtySourceConceptId) ?? 0,
                    ProviderKey              = providerIdKey
                };

                prov.Id = string.IsNullOrEmpty(Id) ? Entity.GetId(prov.GetKey()) : reader.GetLong(Id).Value;
                yield return(prov);
            }
            else
            {
                var conceptField = concept.Fields[0];

                var sourceValue = conceptField.DefaultSource;
                if (string.IsNullOrEmpty(sourceValue))
                {
                    sourceValue = reader.GetString(conceptField.Key);
                }

                if (!string.IsNullOrEmpty(conceptField.SourceKey))
                {
                    sourceValue = reader.GetString(conceptField.SourceKey);
                }

                if (sourceValue != null && sourceValue.Length == 0)
                {
                    sourceValue = null;
                }

                var specialtyConceptIds = concept.GetConceptIdValues(Vocabulary, conceptField, reader).ToList();

                int?specialtyConcept         = null;
                int?specialtySourceConceptId = null;

                //(Unknown Physician Specialty)
                var defaultConceptId = 38004514;

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

                if (specialtyConceptIds.Count > 0)
                {
                    if (specialtyConceptIds[0].ConceptId != 0)
                    {
                        specialtyConcept = specialtyConceptIds[0].ConceptId;
                    }

                    if (specialtyConceptIds[0].SourceConceptId != 0)
                    {
                        specialtySourceConceptId = specialtyConceptIds[0].SourceConceptId;
                    }
                }

                var prov = new Provider
                {
                    CareSiteId          = reader.GetLong(CareSiteId) ?? 0,
                    ConceptId           = specialtyConcept ?? defaultConceptId,
                    ProviderSourceValue = reader.GetString(ProviderSourceValue),
                    SourceValue         = sourceValue,
                    Name              = reader.GetString(Name),
                    YearOfBirth       = reader.GetInt(YearOfBirth),
                    GenderConceptId   = genderConceptId,
                    GenderSourceValue = reader.GetString(GenderSourceValue),
                    Npi = reader.GetString(NPI),
                    Dea = reader.GetString(DEA),
                    GenderSourceConceptId    = reader.GetInt(GenderSourceConceptId) ?? 0,
                    SpecialtySourceConceptId = specialtySourceConceptId ?? 0,
                    ProviderKey = providerIdKey
                };

                prov.Id = string.IsNullOrEmpty(Id) ? Entity.GetId(prov.GetKey()) : reader.GetLong(Id).Value;

                yield return(prov);
            }
        }
Esempio n. 4
0
        public virtual IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset)
        {
            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, StringComparer.OrdinalIgnoreCase);
                    foreach (var additionalField in AdditionalFields)
                    {
                        //additionalFields.Add(String.Intern(additionalField.ToLower()), reader.GetString(additionalField));
                        additionalFields.Add(additionalField, 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);
                    }

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

                        if (!concept.IdRequired || cId.HasValue)
                        {
                            var providerIdKey = reader.GetString(ProviderIdKey);
                            if (!string.IsNullOrEmpty(providerIdKey))
                            {
                                providerIdKey = providerIdKey.TrimStart('0');
                            }

                            List <int> ingredients = null;
                            if (lookupValue.Ingredients != null)
                            {
                                ingredients = new List <int>(lookupValue.Ingredients.Count);
                                ingredients.AddRange(lookupValue.Ingredients);
                            }


                            if (!string.IsNullOrEmpty(StartTime))
                            {
                                if (DateTime.TryParse(reader.GetString(StartTime), out var dt))
                                {
                                    startDate = startDate + dt.TimeOfDay;
                                }
                            }

                            if (endDate != DateTime.MinValue && !string.IsNullOrEmpty(EndTime))
                            {
                                if (DateTime.TryParse(reader.GetString(EndTime), out var dt))
                                {
                                    endDate = endDate + dt.TimeOfDay;
                                }
                            }

                            yield return(new Entity
                            {
                                IsUnique = IsUnique,
                                PersonId = personId.Value,
                                SourceValue = sourceValue,
                                ConceptId = cId ?? 0,
                                TypeConceptId = concept.GetTypeId(field, reader),
                                ConceptIdKey = reader.GetString(field.Key),
                                StartDate = startDate,
                                EndDate = endDate == DateTime.MinValue ? (DateTime?)null : endDate,
                                ProviderId = reader.GetLong(ProviderId),
                                ProviderKey = providerIdKey,
                                VisitOccurrenceId = reader.GetLong(VisitOccurrenceId),
                                VisitDetailId = reader.GetLong(VisitDetailId),
                                AdditionalFields = additionalFields,
                                ValidStartDate = lookupValue.ValidStartDate,
                                ValidEndDate = lookupValue.ValidEndDate,
                                SourceConceptId = lookupValue.SourceConceptId,
                                Domain = lookupValue.Domain,
                                //SourceVocabularyId = lookupValue.SourceVocabularyId,
                                VocabularySourceValue = lookupValue.SourceCode,
                                Ingredients = ingredients
                            });
                        }
                    }
                }
            }
        }