Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubstanceUsageAtAdmission"/> class.
        /// </summary>
        /// <param name="substanceProblemAndFrequency">The substance problem and frequency.</param>
        /// <param name="usualAdministrationRouteType">Type of the usual route of administration.</param>
        /// <param name="firstUseAge">The first use age.</param>
        /// <param name="detailedDrugCode">The detailed drug code.</param>
        public SubstanceUsageAtAdmission(SubstanceProblemAndFrequency substanceProblemAndFrequency,
                                         TedsAnswer <UsualAdministrationRouteType> usualAdministrationRouteType,
                                         TedsAnswer <int?> firstUseAge,
                                         TedsAnswer <DetailedDrugCode> detailedDrugCode)
        {
            Check.IsNotNull(substanceProblemAndFrequency, () => SubstanceProblemAndFrequency);
            SubstanceProblemAndFrequency = substanceProblemAndFrequency;

            CheckIfTedsAnswerHasInvalidNonResponse(usualAdministrationRouteType, () => this.UsualAdministrationRouteType, "usual route of administration");
            UsualAdministrationRouteType = usualAdministrationRouteType;

            CheckIfTedsAnswerHasInvalidNonResponse(firstUseAge, () => this.FirstUseAge, "age of first use");
            FirstUseAge = firstUseAge;

            CheckIfTedsAnswerHasInvalidNonResponse(detailedDrugCode, () => this.DetailedDrugCode, "detailed drug code");
            DetailedDrugCode = detailedDrugCode;

            // Note: two-digit substance problem code forms the first two digits of its associated detailed drug code
            if (substanceProblemAndFrequency.SubstanceProblemType.HasResponse && detailedDrugCode != null && detailedDrugCode.HasResponse)
            {
                if (detailedDrugCode.Response.SubstanceProblemType.Key != substanceProblemAndFrequency.SubstanceProblemType.Response.Key)
                {
                    throw new ArgumentException("The detailed drug code is not associated with the substance problem code.");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the substance use frequency type code.
        /// </summary>
        /// <param name="substanceUsageAtAdmission">The substance usage at admission.</param>
        /// <returns>
        /// A string of use frequency code.
        /// </returns>
        public static string GetSubstanceUseFrequencyTypeCode(SubstanceUsageAtAdmission substanceUsageAtAdmission)
        {
            var useFrequencyCode = "98";

            if (substanceUsageAtAdmission != null)
            {
                useFrequencyCode = SubstanceProblemAndFrequency.GetSubstanceUseFrequencyTypeCode(substanceUsageAtAdmission.SubstanceProblemAndFrequency);
            }
            return(useFrequencyCode);
        }
Esempio n. 3
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (DetailedDrugCode != null ? DetailedDrugCode.GetHashCode() : 0);
         result = (result * 397) ^ (FirstUseAge != null ? FirstUseAge.GetHashCode() : 0);
         result = (result * 397) ^ (UsualAdministrationRouteType != null ? UsualAdministrationRouteType.GetHashCode() : 0);
         result = (result * 397) ^ (SubstanceProblemAndFrequency != null ? SubstanceProblemAndFrequency.GetHashCode() : 0);
         return(result);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TedsDischargeInterviewSubstanceUsage"/> class.
 /// </summary>
 /// <param name="substanceProblemAndFrequency">The substance problem and frequency.</param>
 public TedsDischargeInterviewSubstanceUsage(
     SubstanceProblemAndFrequency substanceProblemAndFrequency)
 {
     Check.IsNotNull(substanceProblemAndFrequency, () => SubstanceProblemAndFrequency);
     SubstanceProblemAndFrequency = substanceProblemAndFrequency;
 }
Esempio n. 5
0
        /// <summary>
        /// Generates the discharge record.
        /// </summary>
        /// <returns>A string.</returns>
        public virtual string GenerateDischargeRecord()
        {
            // Included in both the admission and the discharge data sets are several key fields. The key fields
            // combine to form a unique identifier (retrieval key) for the record in the TEDS discharge
            // database. Any discharge record submitted to TEDS that matches a record already in the TEDS
            // database on all the discharge key fields is rejected as a duplicate.
            // Discharge Data Key fields are:
            // State Code
            // Provider Identifier
            // Client Identifier
            // Co-dependent/Collateral code
            // Type of Service at Discharge
            // Date of Discharge


            if (!IsComplete())
            {
                return("Cannot generate discharge record due to the incompleteness of the interview.\r\n " + _completenessMessage);
            }

            var recordBuilder = new StringBuilder();

            // *** 1. DATA SUBMISSION INFORMATION
            // i.e. System Data Set (SDS) - 3 processing control data items that are reported by all States.

            // DIS 1 - SYSTEM TRANSACTION TYPE
            // Valid Entries: A, C, D
            // An invalid entry in this field is automatically changed to "A."
            var dis1 = TedsDischargeKeyFields.SystemDataSet.SystemTransactionType.Code;

            recordBuilder.Append(dis1);

            // DIS 2 - STATE CODE - (KEY FIELD)
            // Valid Entries: The valid FIPS two-letter state code for the submitting State.
            // An invalid entry in this field automatically causes record to fail.
            var dis2 = TedsDischargeKeyFields.SystemDataSet.StateProvince;

            recordBuilder.Append(dis2);

            // DIS 3 - REPORTING DATE
            // Valid Entries: MMYYYY
            // Every record in a state submission must contain the same date of submission.
            var dis3 = string.Format("{0:MMyyyy}", TedsDischargeKeyFields.SystemDataSet.ReportingDate);

            recordBuilder.Append(dis3);

            // *** 2. BASIC TEDS DISCHARGE DATA
            // Data in fields 4 through 10.

            // DIS 4 - PROVIDER IDENTIFIER - (KEY FIELD)
            // Valid Entries: Entry must contain a valid provider ID that matches the State ID or the I-SATS ID in SAMHSA's I-SATS.
            // If this field is blank, the record will not be processed.
            // Field Length: 15
            // Data Type: Alphanumeric (Left-justified and filled with blank spaces)
            var dis4 = string.Format("{0,-15}", TedsDischargeKeyFields.ProviderIdentifier.IdentifierValue);

            recordBuilder.Append(dis4);

            // DIS 5 - CLIENT IDENTIFIER - (KEY FIELD)
            // Valid entries: An identifier of from 1 to 15 alphanumeric characters that is unique within the
            // state for NOMS participation and for states not participating in NOMS must, at a
            // minimum, be unique within the provider. If the field is blank, the record will not
            // be processed.
            // Field Length: 15
            // Data Type: Alphanumeric (Left-justified and filled with blank spaces)
            var dis5 = string.Format("{0,-15}", TedsDischargeKeyFields.ClientIdentifier.IdentifierValue);

            recordBuilder.Append(dis5);

            // DIS 6 - CO-DEPENDENT/COLLATERAL - (KEY FIELD)
            // Valid Entries:
            // 1 Yes
            // 2 No
            var dis6 = "2";

            if (TedsDischargeKeyFields.CoDependentIndicator)
            {
                dis6 = "1";
            }
            recordBuilder.Append(dis6);

            // DIS 7 - TYPE OF SERVICE AT DISCHARGE (KEY FIELD)
            // Field Length: 2
            // Data Type: Numeric
            var dis7 = TedsDischargeKeyFields.TedsServiceType.Response.Code;

            recordBuilder.Append(dis7);

            // DIS 8 - DATE OF LAST CONTACT
            // Valid Entries: MMDDYYYY
            var dis8 = string.Format("{0:MMddyyyy}", LastFaceToFaceContactDate);

            recordBuilder.Append(dis8);

            // DIS 9 - DATE OF DISCHARGE - (KEY FIELD)
            // Valid Entries: MMDDYYYY
            var dis9 = string.Format("{0:MMddyyyy}", TedsDischargeKeyFields.DischargeDate);

            recordBuilder.Append(dis9);

            // DIS 10 - REASON FOR DISCHARGE, TRANSFER, OR DISCONTINUANCE OF TREATMENT
            // Field Length: 2
            var dis10 = string.Format("{0, 2}", string.Empty);

            if (TedsDischargeReason.HasResponse)
            {
                dis10 = TedsDischargeReason.Response.Code;
            }
            else if (TedsDischargeReason.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis10 = "08";
            }
            else
            {
                throw new InvalidDataException(string.Format("Invalid Teds Discharge reason '{0}' for Teds Discharge interview '{1}'.", TedsDischargeReason.TedsNonResponse.Name, Key));
            }
            recordBuilder.Append(dis10);

            // *** 3. ADMISSIONS DATA REPORTED ON DISCHARGE RECORD
            // The data in fields 11 through 20 are for the admission (or transfer) that corresponds to
            // the discharge reported in the record. The data in these fields should match exactly with
            // the data reported in the corresponding TEDS admission (or transfer) record so that the
            // discharge record can be matched with the appropriate admission (or transfer) record in
            // the TEDS system.

            // DIS 11 - PROVIDER IDENTIFIER AT ADMISSION
            // This number will usually be the same as the entry in DIS 4 (provider ID at discharge), but may be different.
            var dis11 = string.Format("{0,-15}", TedsAdmissionRecord.TedsAdmissionKeyFields.ProviderIdentifier.IdentifierValue);

            recordBuilder.Append(dis11);

            // DIS 12 - CLIENT IDENTIFIER AT ADMISSION
            // This number should be the same as the entry in DIS.5 (client ID at discharge) when client ID is unique within the state.
            var dis12 = dis5;

            recordBuilder.Append(dis12);

            // DIS 13 - CO-DEPENDENT/COLLATERAL (from admission record)
            // A Co-Dependent/Collateral is defined in item DIS 6 above.
            var dis13 = dis6;

            recordBuilder.Append(dis13);

            // DIS 14 - CLIENT TRANSACTION TYPE (from admission record)
            // This field identifies whether the Admission record is for an initial admission (A)
            // or a Transfer/change in service (T).
            // Valid entries: (Admission Record)
            // A Admission
            // T Transfer
            var dis14 = TedsAdmissionRecord.TedsAdmissionKeyFields.ClientTransactionType.Code;

            recordBuilder.Append(dis14);

            // DIS 15 - DATE OF ADMISSION (from admission record)
            // Valid entries: MMDDYYYY
            var dis15 = string.Format("{0:MMddyyyy}", TedsAdmissionRecord.TedsAdmissionKeyFields.AdmissionDate);

            recordBuilder.Append(dis15);

            // DIS 16 - TYPE OF SERVICE AT ADMISSION
            var dis16 = TedsAdmissionRecord.TedsAdmissionKeyFields.TedsServiceType.Response.Code;

            recordBuilder.Append(dis16);

            // DIS 17 - DATE OF BIRTH
            // Valid entries: MMDDYYYY
            var dis17 = string.Format("{0:MMddyyyy}", TedsAdmissionRecord.BirthDate);

            recordBuilder.Append(dis17);

            // DIS 18 - SEX
            var dis18 = "8";

            if (TedsAdmissionRecord.TedsGenderInformation != null)
            {
                if (TedsAdmissionRecord.TedsGenderInformation.TedsGender.HasResponse)
                {
                    dis18 = TedsAdmissionRecord.TedsGenderInformation.TedsGender.Response.Code;
                }
                else if (TedsAdmissionRecord.TedsGenderInformation.TedsGender.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
                {
                    dis18 = "7";
                }
            }
            recordBuilder.Append(dis18);

            // DIS 19 - RACE
            var dis19 = "98";

            if (TedsAdmissionRecord.TedsRace.HasResponse)
            {
                dis19 = TedsAdmissionRecord.TedsRace.Response.Code;
            }
            else if (TedsAdmissionRecord.TedsRace.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis19 = "97";
            }
            recordBuilder.Append(dis19);

            // DIS 20 - ETHNICITY
            var dis20 = "98";

            if (TedsAdmissionRecord.TedsEthnicity.HasResponse)
            {
                dis20 = TedsAdmissionRecord.TedsEthnicity.Response.Code;
            }
            else if (TedsAdmissionRecord.TedsEthnicity.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis20 = "97";
            }
            recordBuilder.Append(dis20);

            // **** 4. DISCHARGE DATA NOMS ELEMENTS
            // The data in fields 21-30 are the NOMS data elements for the discharge data set.

            // DIS 21(a) - SUBSTANCE PROBLEM AT DISCHARGE, PRIMARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceProblemTypeCode(PrimaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 21(b) - SUBSTANCE PROBLEM AT DISCHARGE, SECONDARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceProblemTypeCode(SecondaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 21(c) - SUBSTANCE PROBLEM AT DISCHARGE, TERTIARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceProblemTypeCode(TertiaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 22(a) - FREQUENCY OF USE AT DISCHARGE, PRIMARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceUseFrequencyTypeCode(PrimaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 22(b) - FREQUENCY OF USE AT DISCHARGE, SECONDARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceUseFrequencyTypeCode(SecondaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 22(c) - FREQUENCY OF USE AT DISCHARGE, TERTIARY
            recordBuilder.Append(SubstanceProblemAndFrequency.GetSubstanceUseFrequencyTypeCode(TertiaryTedsDischargeRecordSubstanceUsage.SubstanceProblemAndFrequency));

            // DIS 23 - LIVING ARRANGEMENTS AT DISCHARGE
            var dis23 = "98";

            if (LivingArrangementsType.HasResponse)
            {
                dis23 = LivingArrangementsType.Response.Code;
            }
            else if (LivingArrangementsType.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis23 = "97";
            }
            recordBuilder.Append(dis23);

            // DIS 24 - EMPLOYMENT STATUS AT DISCHARGE
            var dis24 = "98";

            if (TedsEmploymentStatusInformation.TedsEmploymentStatus.HasResponse)
            {
                dis24 = TedsEmploymentStatusInformation.TedsEmploymentStatus.Response.Code;
            }
            else if (TedsEmploymentStatusInformation.TedsEmploymentStatus.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis24 = "97";
            }
            recordBuilder.Append(dis24);

            // DIS 25 - DETAILED NOT IN LABOR FORCE AT DISCHARGE
            var dis25 = "98";

            if (TedsEmploymentStatusInformation.DetailedNotInLaborForce.HasResponse)
            {
                dis25 = TedsEmploymentStatusInformation.DetailedNotInLaborForce.Response.Code;
            }
            else if (TedsEmploymentStatusInformation.DetailedNotInLaborForce.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis25 = "97";
            }
            else if (TedsEmploymentStatusInformation.DetailedNotInLaborForce.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.NotApplicable)
            {
                dis25 = "96";
            }
            recordBuilder.Append(dis25);

            // DIS 26 - NUMBER OF ARRESTS IN 30 DAYS PRIOR TO DISCHARGE
            // Valid entries: 00-96 Number of arrests
            // 97 Unknown
            // 98 Not Collected
            var dis26 = "98";

            if (ArrestsInPastThirtyDaysCount.HasResponse)
            {
                Debug.Assert(ArrestsInPastThirtyDaysCount.Response != null, "ArrestsInThirtyDaysNumber.Response != null");
                dis26 = string.Format("{0,2}", ArrestsInPastThirtyDaysCount.Response.Value);
            }
            else if (ArrestsInPastThirtyDaysCount.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis26 = "97";
            }
            recordBuilder.Append(dis26);

            // DIS 27 - FREQUENCY OF ATTENDANCE AT SELF-HELP PROGRAMS DIS 27 (e.g., AA, NA, etc.) IN 30 DAYS PRIOR TO DISCHARGE
            // Field: 31
            // Begin Column: 136
            // End Column: 137
            var dis27 = string.Format("{0,2}", string.Empty);

            if (ParticipatedSelfHelpGroupInPastThirtyDaysType.HasResponse)
            {
                dis27 = ParticipatedSelfHelpGroupInPastThirtyDaysType.Response.Code;
            }
            else if (ArrestsInPastThirtyDaysCount.TedsNonResponse.Name == WellKnownNames.TedsModule.TedsNonResponse.Unknown)
            {
                dis27 = "97";
            }
            recordBuilder.Append(dis27);


            return(recordBuilder.ToString());
        }