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
95c8fe6d
Commit
95c8fe6d
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
added check of default_visit_duration_in_months
parent
d4c4e50c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!188
Feature/improve management of visits from subject list
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/forms/study_forms.py
+28
-6
28 additions, 6 deletions
smash/web/forms/study_forms.py
with
28 additions
and
6 deletions
smash/web/forms/study_forms.py
+
28
−
6
View file @
95c8fe6d
...
...
@@ -3,6 +3,9 @@ import logging
from
django.forms
import
ModelForm
,
ValidationError
from
web.models
import
Study
,
StudyNotificationParameters
,
StudyColumns
,
StudySubject
import
datetime
from
dateutil.relativedelta
import
relativedelta
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -11,15 +14,34 @@ class StudyEditForm(ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
StudyEditForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
clean_nd_number_study_subject_regex
(
self
):
nd_number_study_subject_regex
=
self
.
cleaned_data
.
get
(
'
nd_number_study_subject_regex
'
)
def
clean
(
self
):
cleaned_data
=
super
(
StudyEditForm
,
self
).
clean
()
#check regex
nd_number_study_subject_regex
=
cleaned_data
.
get
(
'
nd_number_study_subject_regex
'
)
if
StudySubject
.
check_nd_number_regex
(
nd_number_study_subject_regex
)
==
False
:
raise
ValidationError
(
'
Please enter a valid nd_number_study_subject_regex regex.
'
)
self
.
add_error
(
'
nd_number_study_subject_regex
'
,
'
Please enter a valid nd_number_study_subject_regex regex.
'
)
#check default_visit_duration_in_months
t
=
datetime
.
datetime
.
today
()
visit_duration_in_months
=
cleaned_data
.
get
(
'
default_visit_duration_in_months
'
)
visit_duration
=
relativedelta
(
months
=
int
(
visit_duration_in_months
))
control_follow_up
=
cleaned_data
.
get
(
'
default_delta_time_for_control_follow_up
'
)
patient_follow_up
=
cleaned_data
.
get
(
'
default_delta_time_for_patient_follow_up
'
)
units
=
cleaned_data
.
get
(
'
default_delta_time_for_follow_up_units
'
)
control_delta
=
relativedelta
(
**
{
units
:
control_follow_up
})
patient_delta
=
relativedelta
(
**
{
units
:
patient_follow_up
})
#relative time delta has no __cmp__ method, so we add them to a datetime
min_delta_time
=
min
((
t
+
control_delta
),
(
t
+
patient_delta
))
if
(
t
+
visit_duration
)
>
min_delta_time
:
self
.
add_error
(
'
default_visit_duration_in_months
'
,
'
Please enter a valid
"
duration of the visits
"
. It must be shorter than the time difference between patient and control visits.
'
)
return
nd_number_study_subject_regex
return
cleaned_data
class
Meta
:
model
=
Study
...
...
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