department-of-veterans-affairs/vets-website

View on GitHub
src/applications/mhv-medical-records/reducers/selfEnteredData.js

Summary

Maintainability
F
4 days
Test Coverage

File selfEnteredData.js has 702 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { format } from 'date-fns';
import { Actions } from '../util/actionTypes';
import * as Const from '../util/seiConstants';

const initialState = {
Severity: Major
Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 1 day to fix

    Function selfEnteredReducer has 103 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const selfEnteredReducer = (state = initialState, action) => {
      switch (action.type) {
        case Actions.SelfEntered.GET_VITALS: {
          return {
            ...state,
    Severity: Major
    Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 4 hrs to fix

      Function convertDemographics has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const convertDemographics = patient => {
        if (!patient) return null;
        const { userProfile: profile } = patient;
        return {
          firstName: profile.name.firstName || NONE_ENTERED,
      Severity: Major
      Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 2 hrs to fix

        Function formatDate has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function formatDate(inputDate) {
          if (!inputDate) return null;
        
          const months = [
            'January',
        Severity: Minor
        Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 2 hrs to fix

          Function formatDate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          export function formatDate(inputDate) {
            if (!inputDate) return null;
          
            const months = [
              'January',
          Severity: Minor
          Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function convertTreatmentFacilities has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const convertTreatmentFacilities = recordList => {
            if (!recordList) return null;
            return recordList.map(record => ({
              facilityName: record.facilityName || NONE_ENTERED,
              facilityType:
          Severity: Minor
          Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

              if (
                monthIndex < 0 ||
                monthIndex > 11 ||
                day < 1 ||
                day > 31 ||
            Severity: Major
            Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 1 hr to fix

              Function sortDesc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export const sortDesc = key => (a, b) => {
                const valueA = a[key];
                const valueB = b[key];
              
                // Handle null values: place them at the end
              Severity: Minor
              Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 45 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid too many return statements within this function.
              Open

                    return {
                      ...state,
                      medications: convertMedications(action.payload),
                    };
              Severity: Major
              Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return null;
                Severity: Major
                Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return {
                          ...state,
                          demographics: convertDemographics(action.payload),
                        };
                  Severity: Major
                  Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return 0;
                    Severity: Major
                    Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return {
                              ...state,
                              testEntries: convertLabsAndTests(action.payload),
                            };
                      Severity: Major
                      Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return {
                                ...state,
                                treatmentFacilities: convertTreatmentFacilities(action.payload),
                              };
                        Severity: Major
                        Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                return {
                                  ...state,
                                  foodJournal: convertFoodJournal(action.payload),
                                };
                          Severity: Major
                          Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return {
                                    ...state,
                                    failedDomains: state.failedDomains.includes(failedDomain)
                                      ? state.failedDomains
                                      : [...state.failedDomains, failedDomain],
                            Severity: Major
                            Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return {
                                      ...state,
                                      failedDomains: [],
                                    };
                              Severity: Major
                              Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return {
                                        ...state,
                                        providers: convertHealthcareProviders(action.payload),
                                      };
                                Severity: Major
                                Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                    return `${monthName} ${day}, ${year}`;
                                  Severity: Major
                                  Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          return {
                                            ...state,
                                            medicalEvents: convertMedicalEvents(action.payload),
                                          };
                                    Severity: Major
                                    Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            return {
                                              ...state,
                                              militaryHistory: convertMilitaryHistory(action.payload),
                                            };
                                      Severity: Major
                                      Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              return {
                                                ...state,
                                                healthInsurance: convertHealthInsurance(action.payload),
                                              };
                                        Severity: Major
                                        Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                return {
                                                  ...state,
                                                  activityJournal: convertActivityJournal(action.payload),
                                                };
                                          Severity: Major
                                          Found in src/applications/mhv-medical-records/reducers/selfEnteredData.js - About 30 mins to fix

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                case Actions.SelfEntered.ADD_FAILED: {
                                                  const failedDomain = action.payload;
                                            
                                                  return {
                                                    ...state,
                                            src/applications/mhv-medical-records/reducers/blueButton.js on lines 347..356

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 69.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                phoneNumber: record.workPhone
                                                  ? `${record.workPhone || ''} Ext: ${record.workPhoneExt || ''}`.trim()
                                                  : NONE_ENTERED,
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 599..602

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 51.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                phoneNumber: record.contactInfoWorkPhone
                                                  ? `${record.contactInfoWorkPhone ||
                                                      ''} Ext: ${record.contactInfoWorkPhoneExt || ''}`.trim()
                                                  : NONE_ENTERED,
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 536..538

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 51.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                            const getVaHomeFacility = vaHomeFacility => {
                                              if (vaHomeFacility === true) {
                                                return 'Yes';
                                              }
                                              if (vaHomeFacility === false) {
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 544..552

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 46.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                            const getPrimaryInsurance = primaryInd => {
                                              if (primaryInd === true) {
                                                return 'Yes';
                                              }
                                              if (primaryInd === false) {
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 577..585

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 46.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                insured:
                                                  `${record.firstNameOfInsured || ''} ${record.lastNameOfInsured ||
                                                    ''}`.trim() || NONE_ENTERED,
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 529..531

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 45.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                providerName:
                                                  `${record.firstName || ''} ${record.lastName || ''}`.trim() ||
                                                  NONE_ENTERED,
                                            src/applications/mhv-medical-records/reducers/selfEnteredData.js on lines 566..568

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 45.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            There are no issues that match your filters.

                                            Category
                                            Status