Beispiel #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)
                    {
                        var  sourceConceptIdValues = secondaryConcept.GetSourceConceptIdValues(Vocabulary, field, reader);
                        long sourceConceptId       = 0;

                        if (sourceConceptIdValues.Any())
                        {
                            sourceConceptId = sourceConceptIdValues[0].ConceptId.HasValue
                          ? sourceConceptIdValues[0].ConceptId.Value
                          : 0;
                        }

                        yield return(new Death((Entity)baseConcept)
                        {
                            TypeConceptId = field.DefaultTypeId.HasValue ? field.DefaultTypeId.Value : 0,
                            ValidStartDate = lookupValue.ValidStartDate,
                            ValidEndDate = lookupValue.ValidEndDate,
                            SourceConceptId = sourceConceptId
                                              //TypeConceptId = 0 // !!!
                        });

                        break;
                    }
                }
            }
        }
        public virtual IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffset keyOffset)
        {
            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);
                    }

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

                    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)
                        {
                            foreach (var sourceConceptId in concept.GetSourceConceptIdValues(Vocabulary, field, reader))
                            {
                                var providerIdKey = reader.GetString(ProviderIdKey);
                                if (!string.IsNullOrEmpty(providerIdKey))
                                {
                                    providerIdKey = providerIdKey.TrimStart('0');
                                }

                                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 = providerIdKey,
                                    VisitOccurrenceId = reader.GetLong(VisitOccurrenceId),
                                    AdditionalFields = additionalFields,
                                    ValidStartDate = lookupValue.ValidStartDate,
                                    ValidEndDate = lookupValue.ValidEndDate,
                                    SourceConceptId = sourceConceptId.ConceptId.HasValue ? sourceConceptId.ConceptId.Value : 0,
                                    Domain = lookupValue.Domain,
                                    SourceVocabularyId = lookupValue.SourceVocabularyId,
                                    LookupKey = reader.GetString(LookupKey)
                                });
                            }
                        }
                    }
                }
            }
        }