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
91766b4c
Commit
91766b4c
authored
5 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
merging subject data on import implemented
parent
a5038856
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!231
Resolve "auto-import of subject data"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/importer/importer.py
+17
-1
17 additions, 1 deletion
smash/web/importer/importer.py
smash/web/tests/importer/test_importer.py
+34
-0
34 additions, 0 deletions
smash/web/tests/importer/test_importer.py
with
51 additions
and
1 deletion
smash/web/importer/importer.py
+
17
−
1
View file @
91766b4c
...
...
@@ -3,6 +3,8 @@ import logging
import
sys
import
traceback
from
django.db
import
models
from
subject_import_reader
import
SubjectImportReader
from
warning_counter
import
MsgCounterHandler
from
web.models
import
StudySubject
,
Subject
...
...
@@ -57,7 +59,21 @@ class Importer(object):
db_study_subjects
=
StudySubject
.
objects
.
filter
(
screening_number
=
study_subject
.
screening_number
)
if
db_study_subjects
.
count
()
>
0
:
db_study_subject
=
db_study_subjects
.
first
()
raise
NotImplementedError
()
for
field
in
Subject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
setattr
(
db_study_subject
.
subject
,
field
.
name
,
new_value
)
print
db_study_subject
.
subject
.
first_name
db_study_subject
.
subject
.
save
()
for
field
in
StudySubject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
setattr
(
db_study_subject
,
field
.
name
,
new_value
)
db_study_subject
.
save
()
self
.
merged_count
+=
1
else
:
study_subject
.
subject
.
save
()
study_subject
.
subject
=
Subject
.
objects
.
filter
(
id
=
study_subject
.
subject
.
id
)[
0
]
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/importer/test_importer.py
+
34
−
0
View file @
91766b4c
# coding=utf-8
import
datetime
import
logging
from
django.test
import
TestCase
from
mock_reader
import
MockReader
from
tests.functions
import
create_study_subject
from
web.importer
import
Importer
from
web.models
import
Subject
,
StudySubject
,
Study
from
web.models.constants
import
GLOBAL_STUDY_ID
...
...
@@ -70,3 +72,35 @@ class TestImporter(TestCase):
self
.
assertEqual
(
0
,
importer
.
added_count
)
self
.
assertEqual
(
1
,
importer
.
problematic_count
)
def
test_import_merge_subject
(
self
):
existing_study_subject
=
create_study_subject
()
study_subjects
=
[]
subject
=
Subject
()
subject
.
first_name
=
"
XYZ
"
subject
.
last_name
=
"
AAA
"
subject
.
date_born
=
datetime
.
datetime
.
now
()
study_subject
=
StudySubject
()
study_subject
.
screening_number
=
existing_study_subject
.
screening_number
study_subject
.
subject
=
subject
study_subject
.
study
=
self
.
study
study_subjects
.
append
(
study_subject
)
importer
=
Importer
(
filename
=
"
empty.csv
"
,
reader
=
MockReader
(
study_subjects
))
subject_counter
=
Subject
.
objects
.
count
()
study_subject_counter
=
StudySubject
.
objects
.
count
()
importer
.
execute
()
self
.
assertEqual
(
subject_counter
,
Subject
.
objects
.
count
())
self
.
assertEqual
(
study_subject_counter
,
StudySubject
.
objects
.
count
())
self
.
assertEqual
(
0
,
importer
.
added_count
)
self
.
assertEqual
(
1
,
importer
.
merged_count
)
self
.
assertEqual
(
0
,
importer
.
problematic_count
)
self
.
assertEqual
(
0
,
importer
.
warning_count
)
existing_study_subject
=
StudySubject
.
objects
.
filter
(
id
=
existing_study_subject
.
id
)[
0
]
self
.
assertEquals
(
existing_study_subject
.
subject
.
first_name
,
subject
.
first_name
)
self
.
assertEquals
(
existing_study_subject
.
subject
.
last_name
,
subject
.
last_name
)
self
.
assertEquals
(
existing_study_subject
.
subject
.
date_born
.
strftime
(
"
%Y-%m-%d
"
),
subject
.
date_born
.
strftime
(
"
%Y-%m-%d
"
))
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