Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
5a6a9e34
Commit
5a6a9e34
authored
5 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
check inconsistencies based on the columns selected on the study form
parent
06d331d0
No related branches found
No related tags found
1 merge request
!224
Feature/selectable redcap fields
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/redcap_connector.py
+43
-13
43 additions, 13 deletions
smash/web/redcap_connector.py
with
43 additions
and
13 deletions
smash/web/redcap_connector.py
+
43
−
13
View file @
5a6a9e34
...
...
@@ -8,7 +8,9 @@ import certifi
import
timeout_decorator
from
django_cron
import
CronJobBase
,
Schedule
from
web.models
import
ConfigurationItem
,
StudySubject
,
Language
from
django.forms.models
import
model_to_dict
from
web.models.constants
import
GLOBAL_STUDY_ID
from
web.models
import
ConfigurationItem
,
StudySubject
,
Language
,
Study
,
StudyRedCapColumns
from
web.models.constants
import
REDCAP_TOKEN_CONFIGURATION_TYPE
,
\
REDCAP_BASE_URL_CONFIGURATION_TYPE
,
CRON_JOB_TIMEOUT
from
web.models.inconsistent_subject
import
InconsistentField
,
InconsistentSubject
...
...
@@ -178,11 +180,12 @@ class RedcapConnector(object):
return
result
@staticmethod
def
create_inconsistency_subject
(
red_cap_subject
,
study_subject
,
url
):
fields
=
[]
def
check_sex_consistency
(
red_cap_subject
,
study_subject
):
if
study_subject
.
subject
.
sex
!=
red_cap_subject
.
sex
:
field
=
InconsistentField
.
create
(
"
sex
"
,
study_subject
.
subject
.
sex
,
red_cap_subject
.
sex
)
fields
.
append
(
field
)
return
InconsistentField
.
create
(
"
sex
"
,
study_subject
.
subject
.
sex
,
red_cap_subject
.
sex
)
@staticmethod
def
check_birth_date_consistency
(
red_cap_subject
,
study_subject
):
subject_date_born
=
""
if
study_subject
.
subject
.
date_born
is
not
None
:
subject_date_born
=
study_subject
.
subject
.
date_born
.
strftime
(
'
%Y-%m-%d
'
)
...
...
@@ -192,14 +195,20 @@ class RedcapConnector(object):
if
len
(
redcap_subject_date_born
)
>
10
:
redcap_subject_date_born
=
redcap_subject_date_born
[:
10
]
if
subject_date_born
!=
redcap_subject_date_born
:
field
=
InconsistentField
.
create
(
"
date of birth
"
,
subject_date_born
,
redcap_subject_date_born
)
fields
.
append
(
field
)
return
InconsistentField
.
create
(
"
date of birth
"
,
subject_date_born
,
redcap_subject_date_born
)
@staticmethod
def
check_dead_consistency
(
red_cap_subject
,
study_subject
):
if
study_subject
.
subject
.
dead
!=
red_cap_subject
.
dead
:
field
=
InconsistentField
.
create
(
"
dead
"
,
str
(
study_subject
.
subject
.
dead
),
str
(
red_cap_subject
.
dead
))
fields
.
append
(
field
)
return
InconsistentField
.
create
(
"
dead
"
,
str
(
study_subject
.
subject
.
dead
),
str
(
red_cap_subject
.
dead
))
@staticmethod
def
check_mpower_id_consistency
(
red_cap_subject
,
study_subject
):
if
different_string
(
study_subject
.
mpower_id
,
red_cap_subject
.
mpower_id
):
field
=
InconsistentField
.
create
(
"
mpower id
"
,
study_subject
.
mpower_id
,
red_cap_subject
.
mpower_id
)
fields
.
append
(
field
)
return
InconsistentField
.
create
(
"
mpower id
"
,
study_subject
.
mpower_id
,
red_cap_subject
.
mpower_id
)
@staticmethod
def
check_languages_consistency
(
red_cap_subject
,
study_subject
):
missing_language
=
False
if
len
(
red_cap_subject
.
languages
)
<
4
:
for
language
in
study_subject
.
subject
.
languages
.
all
():
...
...
@@ -215,8 +224,29 @@ class RedcapConnector(object):
red_cap_subject_languages
=
""
for
language
in
red_cap_subject
.
languages
:
red_cap_subject_languages
+=
language
.
name
+
"
,
"
field
=
InconsistentField
.
create
(
"
languages
"
,
subject_languages
,
red_cap_subject_languages
)
fields
.
append
(
field
)
return
InconsistentField
.
create
(
"
languages
"
,
subject_languages
,
red_cap_subject_languages
)
@staticmethod
def
create_inconsistency_subject
(
red_cap_subject
,
study_subject
,
url
):
#func dict
field_checks
=
{
'
sex
'
:
RedcapConnector
.
check_sex_consistency
,
'
date_born
'
:
RedcapConnector
.
check_birth_date_consistency
,
'
dead
'
:
RedcapConnector
.
check_dead_consistency
,
'
mpower_id
'
:
RedcapConnector
.
check_mpower_id_consistency
,
'
languages
'
:
RedcapConnector
.
check_languages_consistency
}
fields
=
[]
#get fields which are true from redcap columns
fields_to_check
=
[
k
for
k
,
v
in
model_to_dict
(
study_subject
.
study
.
redcap_columns
).
iteritems
()
if
v
is
True
]
for
field_to_check
in
fields_to_check
:
field
=
field_checks
[
field_to_check
](
red_cap_subject
,
study_subject
)
if
field
is
not
None
:
fields
.
append
(
field
)
result
=
None
if
len
(
fields
)
>
0
:
result
=
InconsistentSubject
.
create
(
smash_subject
=
study_subject
,
url
=
url
,
fields
=
fields
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment