public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager keyOffset) { var visitDetails = base.GetConcepts(concept, reader, keyOffset).ToList(); if (visitDetails.Count > 0) { int? dischargeToConceptId = null; string dischargeToSourceValue = null; if (Concepts != null) { var dischargeConcept = Concepts.FirstOrDefault(c => c.Name == "DischargeToConceptId"); if (dischargeConcept != null) { var dischargeConcepts = base.GetConcepts(dischargeConcept, reader, null).ToList(); dischargeToSourceValue = reader.GetString(dischargeConcept.Fields[0].Key); if (dischargeConcepts.Count > 0) { dischargeToConceptId = dischargeConcepts[0].ConceptId; dischargeToSourceValue = dischargeConcepts[0].SourceValue; } } } else { dischargeToConceptId = reader.GetInt(DischargeToConceptId); dischargeToSourceValue = reader.GetString(DischargeToSourceValue); } int? admittingSourceConceptId = null; string admittingSourceValue = null; if (Concepts != null) { var admittingConcept = Concepts.FirstOrDefault(c => c.Name == "AdmittedFromConceptId"); if (admittingConcept != null) { var admittingConcepts = base.GetConcepts(admittingConcept, reader, null).ToList(); admittingSourceValue = reader.GetString(admittingConcept.Fields[0].Key); if (admittingConcepts.Count > 0) { admittingSourceConceptId = admittingConcepts[0].ConceptId; admittingSourceValue = admittingConcepts[0].SourceValue; } } } else { admittingSourceConceptId = reader.GetInt(AdmittingSourceConceptId); admittingSourceValue = reader.GetString(AdmittingSourceValue); } var id = reader.GetLong(Id); var visitDetail = new VisitDetail((Entity)visitDetails[0]) { CareSiteId = reader.GetLong(CareSiteId) ?? 0, AdmittingSourceConceptId = admittingSourceConceptId ?? 0, AdmittingSourceValue = admittingSourceValue, DischargeToConceptId = dischargeToConceptId ?? 0, DischargeToSourceValue = dischargeToSourceValue, PrecedingVisitDetailId = reader.GetInt(PrecedingVisitDetailId) }; if (id.HasValue) { visitDetail.Id = id.Value; } else { visitDetail.IdUndefined = true; } yield return(visitDetail); } }
public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager keyOffset) { var locationSourceValue = reader.GetString(Location); long?locationId = null; if (!string.IsNullOrEmpty(Location)) { locationId = Entity.GetId(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.TimeOfDay; var endTime = reader.GetTime(EndTime) ?? endDate.TimeOfDay; DateTime?timeOfBirth = null; var tob = reader.GetDateTime(TimeOfBirth); if (tob > DateTime.MinValue) { timeOfBirth = tob; } var deathDatetime = reader.GetDateTime(DeathDatetime); yield return(new Person { ObservationPeriodGap = reader.GetInt(ObservationPeriodGap) ?? 32, AdditionalFields = additionalFields, PersonId = personId.Value, StartDate = startDate, EndDate = endDate, PersonSourceValue = reader.GetString(PersonSourceValue), GenderSourceValue = genderSource, GenderConceptId = genderConceptId ?? 0, LocationId = locationId, YearOfBirth = reader.GetInt(YearOfBirth), MonthOfBirth = reader.GetInt(MonthOfBirth), DayOfBirth = reader.GetInt(DayOfBirth), TimeOfDeath = deathDatetime == DateTime.MinValue ? (DateTime?)null : deathDatetime, LocationSourceValue = locationSourceValue, CareSiteId = reader.GetLong(CareSiteId), EthnicitySourceValue = reader.GetString(Ethnicity), EthnicityConceptId = reader.GetInt(EthnicityConceptId) ?? 0, RaceSourceValue = reader.GetString(Race), RaceConceptId = reader.GetInt(RaceConceptId) ?? 0, ProviderId = reader.GetLong(ProviderId), TimeOfBirth = timeOfBirth, GenderSourceConceptId = reader.GetInt(GenderSourceConceptId) ?? 0, // CCAE RaceSourceConceptId = reader.GetInt(RaceSourceConceptId) ?? 0, EthnicitySourceConceptId = reader.GetInt(EthnicitySourceConceptId) ?? 0, TypeConceptId = reader.GetInt(PeriodTypeConceptId), PotentialChildId = reader.GetLong(PotentialChildId), PotentialChildBirthDate = reader.GetDateTime(PotentialChildBirthDate) }); } }
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)); } } if (concept != null && concept.Fields != null) { 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) ?? 0, 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 }); } } } } } }
public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager 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; } int payerConceptId = 0; int payerSourceConceptId = 0; int planConceptId = 0; int planSourceConceptId = 0; int sponsorConceptId = 0; int sponsorSourceConceptId = 0; string sponsorSource = null; int stopReasonConceptId = 0; int stopReasonSourceConceptId = 0; string stopReasonSource = null; if (Concepts != null) // payer_concept_id { var payerConcept = Concepts.FirstOrDefault(c => c.Name == "PayerConceptId"); if (payerConcept != null) { var payerConcepts = base.GetConcepts(payerConcept, reader, null).ToList(); payerSourceValue = reader.GetString(payerConcept.Fields[0].Key); if (payerConcepts.Count > 0) { payerConceptId = payerConcepts[0].ConceptId; payerSourceConceptId = payerConcepts[0].SourceConceptId; } } var planConcept = Concepts.FirstOrDefault(c => c.Name == "PlanConceptId"); if (planConcept != null) { var planConcepts = base.GetConcepts(planConcept, reader, null).ToList(); planSource = reader.GetString(planConcept.Fields[0].Key); if (planConcepts.Count > 0) { planConceptId = planConcepts[0].ConceptId; planSourceConceptId = planConcepts[0].SourceConceptId; } } var sponsorConcept = Concepts.FirstOrDefault(c => c.Name == "SponsorConceptId"); if (sponsorConcept != null) { var sponsorConcepts = base.GetConcepts(sponsorConcept, reader, null).ToList(); sponsorSource = reader.GetString(sponsorConcept.Fields[0].Key); if (sponsorConcepts.Count > 0) { sponsorConceptId = sponsorConcepts[0].ConceptId; sponsorSourceConceptId = sponsorConcepts[0].SourceConceptId; } } var stopReasonConcept = Concepts.FirstOrDefault(c => c.Name == "StopReasonConceptId"); if (stopReasonConcept != null) { var stopReasonConcepts = base.GetConcepts(stopReasonConcept, reader, null).ToList(); stopReasonSource = reader.GetString(stopReasonConcept.Fields[0].Key); if (stopReasonConcepts.Count > 0) { stopReasonConceptId = stopReasonConcepts[0].ConceptId; stopReasonSourceConceptId = stopReasonConcepts[0].SourceConceptId; } } } yield return(new PayerPlanPeriod { Id = id ?? 0, PersonId = personId.Value, StartDate = startDate, EndDate = endDate, PayerConceptId = payerConceptId, PayerSourceConceptId = payerSourceConceptId, PayerSourceValue = payerSourceValue, PlanConceptId = planConceptId, PlanSourceConceptId = planSourceConceptId, PlanSourceValue = planSource, SponsorConceptId = sponsorConceptId, SponsorSourceConceptId = sponsorSourceConceptId, SponsorSourceValue = sponsorSource, StopReasonConceptId = stopReasonConceptId, StopReasonSourceConceptId = stopReasonSourceConceptId, StopReasonSourceValue = stopReasonSource, FamilySourceValue = reader.GetString(FamilySource), VisitOccurrenceId = reader.GetLong(VisitOccurrenceId), AdditionalFields = additionalFields }); } }
public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager keyOffset) { int? genderConceptId = 0; string genderSource = null; int? specialtyConceptId = 0; int? specialtySourceConceptId = 0; string specialtySource = null; if (Concepts != null) { var genderConcept = Concepts.FirstOrDefault(c => c.Name == "GenderConceptId"); if (genderConcept != null) { var genderConcepts = genderConcept.GetConceptIdValues(Vocabulary, genderConcept.Fields[0], reader); genderSource = reader.GetString(genderConcept.Fields[0].Key); if (genderConcepts.Count > 0) { genderConceptId = genderConcepts.Min(c => c.ConceptId); genderSource = genderConcepts.Min(c => c.SourceCode); if (string.IsNullOrEmpty(genderSource)) { genderSource = reader.GetString(genderConcept.Fields[0].Key); } if (string.IsNullOrEmpty(genderSource)) { genderSource = reader.GetString(genderConcept.Fields[0].SourceKey); } } } var specialtyConcept = Concepts.FirstOrDefault(c => c.Name == "SpecialtyConceptId"); if (specialtyConcept != null) { var specialtyConcepts = specialtyConcept.GetConceptIdValues(Vocabulary, specialtyConcept.Fields[0], reader); specialtySource = reader.GetString(specialtyConcept.Fields[0].Key); if (specialtyConcepts.Count > 0) { specialtyConceptId = specialtyConcepts.Min(c => c.ConceptId); specialtySourceConceptId = specialtyConcepts.Min(c => c.SourceConceptId); specialtySource = specialtyConcepts.Min(c => c.SourceCode); if (string.IsNullOrEmpty(specialtySource)) { specialtySource = reader.GetString(specialtyConcept.Fields[0].Key); } if (string.IsNullOrEmpty(specialtySource)) { specialtySource = reader.GetString(specialtyConcept.Fields[0].SourceKey); } } } } var prov = new Provider { CareSiteId = reader.GetLong(CareSiteId) ?? 0, ConceptId = specialtyConceptId ?? 0, ProviderSourceValue = reader.GetString(ProviderSourceValue), SourceValue = specialtySource, 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 }; prov.Id = string.IsNullOrEmpty(Id) ? Entity.GetId(prov.GetKey()) : reader.GetLong(Id).Value; yield return(prov); }
public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader, KeyMasterOffsetManager offset) { DateTime?endDate = null; int routeConceptId = 0; string routeSourceValue = null; if (Concepts.Length == 2) { var routeConcepts = base.GetConcepts(Concepts[1], reader, null).ToList(); routeSourceValue = reader.GetString(Concepts[1].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) }); } }
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; int?operatorConceptId = null; if (Concepts != null) { var valueConcept = Concepts.FirstOrDefault(c => c.Name == "ValueAsConceptId"); if (valueConcept != null) { var valueConcepts = base.GetConcepts(valueConcept, reader, null).ToList(); if (valueConcepts.Count > 0) { valueAsConceptId = valueConcepts[0].ConceptId; } } var operatorConcept = Concepts.FirstOrDefault(c => c.Name == "OperatorConceptId"); if (operatorConcept != null) { var operatorConcepts = base.GetConcepts(operatorConcept, reader, null).ToList(); if (operatorConcepts.Count > 0) { operatorConceptId = operatorConcepts[0].ConceptId; } } } else { if (operatorConceptId == null) { operatorConceptId = reader.GetInt(OperatorConceptId); } if (valueAsConceptId == null) { 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 = 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) }); } }