예제 #1
0
        private async Task <HospitalDetails> ExtractHospitalDetailsAsync(MigrationDbNotification rawNotification)
        {
            var details = new HospitalDetails();

            details.HospitalId          = rawNotification.NtbsHospitalId;
            details.CaseManagerUsername = rawNotification.CaseManager;
            var consultant = RemoveCharactersNotIn(ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended, rawNotification.Consultant);

            details.Consultant = consultant;
            // details.TBServiceCode is set below, based on the hospital

            if (details.HospitalId is Guid guid)
            {
                var tbService = (await _referenceDataRepository.GetTbServiceFromHospitalIdAsync(guid));
                if (tbService == null)
                {
                    Log.Error($"No TB service exists for hospital with guid {guid}");
                }
                else
                {
                    // It's OK to only set this where it exists
                    // - the service missing will come up in notification validation
                    details.TBServiceCode = tbService.Code;
                }
            }

            // we are not doing the same check to case manager here, because leaving it empty would make it pass
            // validation - it is not a mandatory field. we don't want to lose it where it exists, so that check
            // is explicitly done during the validation step

            return(details);
        }
예제 #2
0
        private static SocialRiskFactors ExtractSocialRiskFactors(MigrationDbNotification notification)
        {
            var factors = new SocialRiskFactors();

            factors.AlcoholMisuseStatus       = Converter.GetStatusFromString(notification.AlcoholMisuseStatus);
            factors.MentalHealthStatus        = Converter.GetStatusFromString(notification.MentalHealthStatus);
            factors.AsylumSeekerStatus        = Converter.GetStatusFromString(notification.AsylumSeekerStatus);
            factors.ImmigrationDetaineeStatus = Converter.GetStatusFromString(notification.ImmigrationDetaineeStatus);

            factors.RiskFactorSmoking.Status = Converter.GetStatusFromString(notification.SmokingStatus);

            ExtractRiskFactor(factors.RiskFactorDrugs,
                              notification.riskFactorDrugs_Status,
                              notification.riskFactorDrugs_IsCurrent,
                              notification.riskFactorDrugs_InPastFiveYears,
                              notification.riskFactorDrugs_MoreThanFiveYearsAgo);

            ExtractRiskFactor(factors.RiskFactorHomelessness,
                              notification.riskFactorHomelessness_Status,
                              notification.riskFactorHomelessness_IsCurrent,
                              notification.riskFactorHomelessness_InPastFiveYears,
                              notification.riskFactorHomelessness_MoreThanFiveYearsAgo);

            ExtractRiskFactor(factors.RiskFactorImprisonment,
                              notification.riskFactorImprisonment_Status,
                              notification.riskFactorImprisonment_IsCurrent,
                              notification.riskFactorImprisonment_InPastFiveYears,
                              notification.riskFactorImprisonment_MoreThanFiveYearsAgo);

            return(factors);
        }
예제 #3
0
        private static VisitorDetails ExtractVisitorDetails(MigrationDbNotification notification)
        {
            var hasVisitor        = Converter.GetStatusFromString(notification.HasVisitor);
            int?numberOfCountries = Converter.ToNullableInt(notification.visitor_TotalNumberOfCountries);
            var countriesRecorded = new List <int?>
            {
                notification.visitor_Country1, notification.visitor_Country2, notification.visitor_Country3
            }.Distinct()
            .Count(c => c != null);
            int?totalNumberOfCountries = hasVisitor == Status.Yes && numberOfCountries != null
                ? Math.Max(numberOfCountries.Value, countriesRecorded)
                : (int?)null;

            var details = new VisitorDetails();

            details.HasVisitor             = hasVisitor;
            details.TotalNumberOfCountries = totalNumberOfCountries;
            details.Country1Id             = notification.visitor_Country1;
            details.Country2Id             = notification.visitor_Country2;
            details.Country3Id             = notification.visitor_Country3;
            details.StayLengthInMonths1    = notification.visitor_StayLengthInMonths1;
            details.StayLengthInMonths2    = notification.visitor_StayLengthInMonths2;
            details.StayLengthInMonths3    = notification.visitor_StayLengthInMonths3;
            RemoveDuplicateCountries(details);
            return(details);
        }
예제 #4
0
        private List <TreatmentEvent> CombineTreatmentEvents(Notification notification,
                                                             MigrationDbNotification rawNotification,
                                                             IEnumerable <TreatmentEvent> notificationTransferEvents,
                                                             IEnumerable <TreatmentEvent> notificationOutcomeEvents)
        {
            // For post mortem cases the death event is the ONLY event we want to import so the final outcome is
            // correctly reported.
            if (notification.ClinicalDetails.IsPostMortem == true)
            {
                return(new List <TreatmentEvent>
                {
                    new TreatmentEvent
                    {
                        EventDate = rawNotification.DeathDate,
                        TreatmentEventType = TreatmentEventType.TreatmentOutcome,
                        TreatmentOutcomeId = _postMortemOutcomeType.TreatmentOutcomeId,
                        TreatmentOutcome = _postMortemOutcomeType
                    }
                });
            }

            var treatmentEvents = new List <TreatmentEvent>();

            if (notification.NotificationStatus != NotificationStatus.Draft)
            {
                treatmentEvents.Add(NotificationHelper.CreateTreatmentStartEvent(notification));
            }

            treatmentEvents.AddRange(notificationTransferEvents);
            treatmentEvents.AddRange(notificationOutcomeEvents);
            return(treatmentEvents);
        }
예제 #5
0
        private PreviousTbHistory ExtractPreviousTbHistory(MigrationDbNotification rawNotification)
        {
            var details = new PreviousTbHistory();

            details.PreviouslyHadTb            = Converter.GetStatusFromString(rawNotification.PreviouslyHadTb);
            details.PreviousTbDiagnosisYear    = rawNotification.PreviousTbDiagnosisYear;
            details.PreviouslyTreated          = Converter.GetStatusFromString(rawNotification.PreviouslyTreated);
            details.PreviousTreatmentCountryId = rawNotification.PreviousTreatmentCountryId;
            return(details);
        }
예제 #6
0
        private static ComorbidityDetails ExtractComorbidityDetails(MigrationDbNotification notification)
        {
            var details = new ComorbidityDetails();

            details.DiabetesStatus     = Converter.GetStatusFromString(notification.DiabetesStatus);
            details.LiverDiseaseStatus = Converter.GetStatusFromString(notification.LiverDiseaseStatus);
            details.RenalDiseaseStatus = Converter.GetStatusFromString(notification.RenalDiseaseStatus);
            details.HepatitisBStatus   = Converter.GetStatusFromString(notification.HepatitisBStatus);
            details.HepatitisCStatus   = Converter.GetStatusFromString(notification.HepatitisCStatus);
            return(details);
        }
예제 #7
0
        private MDRDetails ExtractMdrDetailsAsync(MigrationDbNotification rawNotification)
        {
            var mdr = new MDRDetails();

            mdr.ExposureToKnownCaseStatus = Converter.GetStatusFromString(rawNotification.mdr_ExposureToKnownTbCase);
            mdr.RelationshipToCase        = rawNotification.mdr_RelationshipToCase;
            // Notification.mdr_CaseInUKStatus is not used, as in NTBS it's calculated on the fly
            mdr.CountryId = rawNotification.mdr_CountryId;
            if (!string.IsNullOrEmpty(rawNotification.mdr_RelatedNotificationId))
            {
                mdr.NotifiedToPheStatus   = Status.Yes;
                mdr.RelatedNotificationId = int.Parse(rawNotification.mdr_RelatedNotificationId);
            }

            return(mdr);
        }
예제 #8
0
        private ContactTracing ExtractContactTracingDetails(MigrationDbNotification rawNotification)
        {
            var details = new ContactTracing();

            details.AdultsIdentified          = rawNotification.AdultsIdentified;
            details.ChildrenIdentified        = rawNotification.ChildrenIdentified;
            details.AdultsScreened            = rawNotification.AdultsScreened;
            details.ChildrenScreened          = rawNotification.ChildrenScreened;
            details.AdultsActiveTB            = rawNotification.AdultsActiveTB;
            details.ChildrenActiveTB          = rawNotification.ChildrenActiveTB;
            details.AdultsLatentTB            = rawNotification.AdultsLatentTB;
            details.ChildrenLatentTB          = rawNotification.ChildrenLatentTB;
            details.AdultsStartedTreatment    = rawNotification.AdultsStartedTreatment;
            details.ChildrenStartedTreatment  = rawNotification.ChildrenStartedTreatment;
            details.AdultsFinishedTreatment   = rawNotification.AdultsFinishedTreatment;
            details.ChildrenFinishedTreatment = rawNotification.ChildrenFinishedTreatment;
            return(details);
        }
예제 #9
0
        private async Task <PatientDetails> ExtractPatientDetails(MigrationDbNotification notification)
        {
            var addressRaw = string.Join(" \n",
                                         notification.Line1,
                                         notification.Line2,
                                         notification.City,
                                         notification.County);
            var address = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashAndNewLine,
                addressRaw);
            var givenName      = RemoveCharactersNotIn(ValidationRegexes.CharacterValidation, notification.GivenName);
            var familyName     = RemoveCharactersNotIn(ValidationRegexes.CharacterValidation, notification.FamilyName);
            var localPatientId = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                notification.LocalPatientId);

            var details = new PatientDetails();

            details.FamilyName        = familyName;
            details.GivenName         = givenName;
            details.NhsNumber         = notification.NhsNumber;
            details.NhsNumberNotKnown = notification.NhsNumberNotKnown == 1 || notification.NhsNumber == null;
            details.Dob            = notification.DateOfBirth;
            details.YearOfUkEntry  = notification.UkEntryYear;
            details.UkBorn         = notification.UkBorn;
            details.CountryId      = notification.BirthCountryId ?? Countries.UnknownId;
            details.LocalPatientId = localPatientId;
            details.Postcode       = notification.Postcode;
            details.PostcodeLookup = await _postcodeService.FindPostcodeAsync(notification.Postcode);

            details.PostcodeToLookup = details.PostcodeLookup?.Postcode;
            details.NoFixedAbode     = notification.NoFixedAbode == 1;
            details.Address          = address;
            details.EthnicityId      = notification.NtbsEthnicGroupId ?? Ethnicities.NotStatedId;
            details.SexId            = notification.NtbsSexId ?? Sexes.UnknownId;
            details.OccupationId     = notification.NtbsOccupationId;
            details.OccupationOther  = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                notification.OccupationFreetext);

            ForceValidNhsNumber(details);

            return(details);
        }
예제 #10
0
        private static ImmunosuppressionDetails ExtractImmunosuppressionDetails(MigrationDbNotification notification)
        {
            var details = new ImmunosuppressionDetails();

            details.Status = Converter.GetStatusFromString(notification.ImmunosuppressionStatus);
            if (details.Status != Status.Yes)
            {
                return(details);
            }

            details.HasBioTherapy      = Converter.GetNullableBoolValue(notification.HasBioTherapy);
            details.HasTransplantation = Converter.GetNullableBoolValue(notification.HasTransplantation);
            details.HasOther           = Converter.GetNullableBoolValue(notification.HasOther);

            if (details.HasBioTherapy != true && details.HasTransplantation != true && details.HasOther != true)
            {
                details.HasOther         = true;
                details.OtherDescription = "No immunosuppression type was provided in the legacy record";
            }
            else if (details.HasOther == true)
            {
                if (!string.IsNullOrWhiteSpace(notification.OtherDescription))
                {
                    var otherDescription = RemoveCharactersNotIn(
                        ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                        notification.OtherDescription);
                    details.OtherDescription = otherDescription;
                }
                else
                {
                    details.OtherDescription = "No description provided in the legacy system";
                }
            }

            // Ensure that if a description exists, HasOther is ticked
            if (details.HasOther != true && !string.IsNullOrWhiteSpace(details.OtherDescription))
            {
                details.HasOther = true;
            }

            return(details);
        }
예제 #11
0
        private async Task <Notification> AsNotificationAsync(MigrationDbNotification rawNotification)
        {
            var notification = new Notification();

            notification.ETSID            = rawNotification.EtsId;
            notification.LTBRID           = rawNotification.LtbrId;
            notification.LTBRPatientId    = rawNotification.Source == "LTBR" ? rawNotification.GroupId : null;
            notification.NotificationDate = rawNotification.NotificationDate;
            notification.CreationDate     = DateTime.Now;
            if (Converter.GetNullableBoolValue(rawNotification.IsDenotified) == true)
            {
                notification.NotificationStatus    = NotificationStatus.Denotified;
                notification.DenotificationDetails = new DenotificationDetails
                {
                    DateOfDenotification = rawNotification.DenotificationDate ?? DateTime.Now,
                    Reason           = DenotificationReason.Other,
                    OtherDescription = "Denotified in legacy system, with denotification date " +
                                       (rawNotification.DenotificationDate?.ToString() ?? "missing")
                };
            }
            else
            {
                notification.NotificationStatus = NotificationStatus.Notified;
            }

            notification.PatientDetails = await ExtractPatientDetails(rawNotification);

            notification.ClinicalDetails          = ExtractClinicalDetails(rawNotification);
            notification.TravelDetails            = ExtractTravelDetails(rawNotification);
            notification.VisitorDetails           = ExtractVisitorDetails(rawNotification);
            notification.ComorbidityDetails       = ExtractComorbidityDetails(rawNotification);
            notification.ImmunosuppressionDetails = ExtractImmunosuppressionDetails(rawNotification);
            notification.SocialRiskFactors        = ExtractSocialRiskFactors(rawNotification);
            notification.HospitalDetails          = await ExtractHospitalDetailsAsync(rawNotification);

            notification.ContactTracing    = ExtractContactTracingDetails(rawNotification);
            notification.PreviousTbHistory = ExtractPreviousTbHistory(rawNotification);
            notification.MDRDetails        = ExtractMdrDetailsAsync(rawNotification);

            return(notification);
        }
예제 #12
0
        private static ClinicalDetails ExtractClinicalDetails(MigrationDbNotification notification)
        {
            var details = new ClinicalDetails();

            details.SymptomStartDate          = notification.SymptomOnsetDate;
            details.FirstPresentationDate     = notification.FirstPresentationDate;
            details.TBServicePresentationDate = notification.TbServicePresentationDate;
            details.DiagnosisDate             = notification.DiagnosisDate ?? notification.StartOfTreatmentDate ?? notification.NotificationDate;
            details.DidNotStartTreatment      = Converter.GetNullableBoolValue(notification.DidNotStartTreatment);
            details.TreatmentStartDate        = notification.StartOfTreatmentDate;
            details.MDRTreatmentStartDate     = notification.MDRTreatmentStartDate;
            details.IsSymptomatic             = Converter.GetNullableBoolValue(notification.IsSymptomatic);
            details.IsPostMortem = Converter.GetNullableBoolValue(notification.IsPostMortem);
            details.HIVTestState = Converter.GetEnumValue <HIVTestStatus>(notification.HivTestStatus);
            details.IsDotOffered = Converter.GetStatusFromString(notification.IsDotOffered);
            details.DotStatus    = Converter.GetEnumValue <DotStatus>(notification.DotStatus);
            details.EnhancedCaseManagementStatus = Converter.GetStatusFromString(notification.EnhancedCaseManagementStatus);
            details.BCGVaccinationState          = Converter.GetStatusFromString(notification.BCGVaccinationState);
            details.BCGVaccinationYear           = notification.BCGVaccinationYear;
            details.TreatmentRegimen             = Converter.GetEnumValue <TreatmentRegimen>(notification.TreatmentRegimen);
            details.Notes = notification.Notes;
            return(details);
        }