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
c62f6d3f
Commit
c62f6d3f
authored
3 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
import of csv with subjects did not work with custom fields for subjects that existed in db
parent
7e66dc3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!366
Resolve "import custom fields data bug"
Pipeline
#48168
failed
3 years ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG
+4
-1
4 additions, 1 deletion
CHANGELOG
smash/web/importer/importer.py
+2
-1
2 additions, 1 deletion
smash/web/importer/importer.py
smash/web/tests/importer/test_importer.py
+36
-3
36 additions, 3 deletions
smash/web/tests/importer/test_importer.py
with
42 additions
and
5 deletions
CHANGELOG
+
4
−
1
View file @
c62f6d3f
...
...
@@ -26,7 +26,10 @@ smasch (1.1.0~alpha.0-1) unstable; urgency=low
multiple days (#430, #429)
* bug fix: Search form should always redirect to web.views.kit_requests
(#433)
* bug fix: printing mail template failed for general appointments (#435).
* bug fix: printing mail template failed for general appointments (#435)
* bug fix: import of csv with subjects did not work with custom fields for
subjects that existed in db (#415)
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 25 Feb 2021 17:00:00 +0200
...
...
This diff is collapsed.
Click to expand it.
smash/web/importer/importer.py
+
2
−
1
View file @
c62f6d3f
...
...
@@ -66,7 +66,7 @@ class Importer(EtlCommon):
new_value
=
self
.
get_new_value
(
old_value
,
getattr
(
study_subject
,
field
.
name
))
self
.
create_provenance_and_change_data
(
db_study_subject
,
field
.
name
,
new_value
,
StudySubject
)
db_study_subject
.
save
()
study_subject
=
db_study_subject
self
.
merged_count
+=
1
else
:
if
study_subject
.
type_id
is
None
:
...
...
@@ -77,6 +77,7 @@ class Importer(EtlCommon):
self
.
create_provenance_for_new_object
(
Subject
,
study_subject
.
subject
)
self
.
create_provenance_for_new_object
(
StudySubject
,
study_subject
)
self
.
added_count
+=
1
for
custom_field_value
in
self
.
reader
.
get_custom_fields
(
study_subject
):
study_subject
.
set_custom_data_value
(
custom_field_value
.
study_subject_field
,
custom_field_value
.
value
)
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/importer/test_importer.py
+
36
−
3
View file @
c62f6d3f
...
...
@@ -5,10 +5,12 @@ import logging
from
django.test
import
TestCase
from
django.utils
import
timezone
from
web.importer
import
Importer
from
web.models
import
Subject
,
StudySubject
,
Provenance
,
SubjectImportData
from
web.tests.functions
import
create_study_subject
,
get_test_study
,
get_control_subject_type
from
web.importer
import
Importer
,
CsvSubjectImportReader
from
web.models
import
Subject
,
StudySubject
,
Provenance
,
SubjectImportData
,
EtlColumnMapping
from
web.tests.functions
import
create_study_subject
,
get_test_study
,
get_control_subject_type
,
get_resource_path
from
.mock_reader
import
MockReader
from
...models.constants
import
CUSTOM_FIELD_TYPE_TEXT
from
...models.custom_data
import
CustomStudySubjectField
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -110,3 +112,34 @@ class TestImporter(TestCase):
self
.
assertEqual
(
existing_study_subject
.
subject
.
last_name
,
subject
.
last_name
)
self
.
assertEqual
(
existing_study_subject
.
subject
.
date_born
.
strftime
(
"
%Y-%m-%d
"
),
subject
.
date_born
.
strftime
(
"
%Y-%m-%d
"
))
def
test_load_with_merge_custom_field
(
self
):
study_subject
=
create_study_subject
(
nd_number
=
'
Cov-000001
'
)
study_subject
.
screening_number
=
study_subject
.
nd_number
study_subject
.
save
()
self
.
test_load_custom_field
()
def
test_load_custom_field
(
self
):
field
=
CustomStudySubjectField
.
objects
.
create
(
study
=
get_test_study
(),
name
=
'
my custom field
'
,
type
=
CUSTOM_FIELD_TYPE_TEXT
)
subject_import_data
=
SubjectImportData
.
objects
.
create
(
study
=
get_test_study
(),
date_format
=
"
%d-%m-%Y
"
)
EtlColumnMapping
.
objects
.
create
(
etl_data
=
subject_import_data
,
column_name
=
"
screening_number
"
,
csv_column_name
=
"
participant_id
"
,
table_name
=
StudySubject
.
_meta
.
db_table
)
EtlColumnMapping
.
objects
.
create
(
etl_data
=
subject_import_data
,
column_name
=
"
nd_number
"
,
csv_column_name
=
"
participant_id
"
,
table_name
=
StudySubject
.
_meta
.
db_table
)
subject_import_data
.
filename
=
get_resource_path
(
'
import_custom_field.csv
'
)
reader
=
CsvSubjectImportReader
(
subject_import_data
)
importer
=
Importer
(
reader
=
reader
)
importer
.
execute
()
self
.
assertEqual
(
3
,
StudySubject
.
objects
.
count
())
study_subject
=
StudySubject
.
objects
.
filter
(
nd_number
=
'
Cov-000001
'
).
first
()
self
.
assertEqual
(
"
Bla
"
,
study_subject
.
get_custom_data_value
(
field
).
value
)
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