renalreg/radar

View on GitHub
radar/ukrdc_importer/medications.py

Summary

Maintainability
C
1 day
Test Coverage

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

def convert_medications(patient, sda_medications):
    user = get_import_user()

    medications = list()

Severity: Minor
Found in radar/ukrdc_importer/medications.py - 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

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

def parse_medications(sda_medications):
    def log(index, sda_medication, e):
        logger.error(
            "Ignoring invalid medication index={index}, errors={errors}".format(
                index=index, errors=e.flatten()
Severity: Major
Found in radar/ukrdc_importer/medications.py and 4 other locations - About 3 hrs to fix
radar/ukrdc_importer/addresses.py on lines 77..85
radar/ukrdc_importer/aliases.py on lines 32..40
radar/ukrdc_importer/patient_numbers.py on lines 38..51
radar/ukrdc_importer/results.py on lines 87..100

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 72.

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 5 locations. Consider refactoring.
Open

def get_medications(patient):
    q = Medication.query
    q = q.filter(Medication.source_type == "UKRDC")
    q = q.filter(Medication.patient == patient)
    return q.all()
Severity: Major
Found in radar/ukrdc_importer/medications.py and 4 other locations - About 2 hrs to fix
radar/ukrdc_importer/addresses.py on lines 104..108
radar/ukrdc_importer/aliases.py on lines 59..63
radar/ukrdc_importer/patient_numbers.py on lines 70..74
radar/ukrdc_importer/results.py on lines 125..129

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 58.

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 5 locations. Consider refactoring.
Open

        if medication is None:
            logger.info("Creating medication id={id}".format(id=medication_id))
            medication = Medication(id=medication_id)
        else:
            logger.info("Updating medication id={id}".format(id=medication_id))
Severity: Major
Found in radar/ukrdc_importer/medications.py and 4 other locations - About 2 hrs to fix
radar/ukrdc_importer/addresses.py on lines 138..142
radar/ukrdc_importer/aliases.py on lines 88..92
radar/ukrdc_importer/patient_numbers.py on lines 111..115
radar/ukrdc_importer/results.py on lines 227..231

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 56.

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 3 locations. Consider refactoring.
Open

def sync_medications(patient, medications_to_keep):
    def log(medication):
        logger.info("Deleting medication id={}".format(medication.id))

    medications = get_medications(patient)
Severity: Major
Found in radar/ukrdc_importer/medications.py and 2 other locations - About 2 hrs to fix
radar/ukrdc_importer/aliases.py on lines 66..71
radar/ukrdc_importer/patient_numbers.py on lines 77..82

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 5 locations. Consider refactoring.
Open

    @property
    def to_date(self):
        to_time = self.to_time

        if to_time is None:
Severity: Major
Found in radar/ukrdc_importer/medications.py and 4 other locations - About 50 mins to fix
radar/ukrdc_importer/addresses.py on lines 28..35
radar/ukrdc_importer/addresses.py on lines 41..48
radar/ukrdc_importer/demographics.py on lines 58..65
radar/ukrdc_importer/demographics.py on lines 71..78

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 36.

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