Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/encoded/schemas/changelogs/treatment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog for treatment.json

### Schema version 14
* Restricted *amount* and *duration* properties to have a minimum value of 0.

### Schema version 13
* Modified regex pattern for *product_id* to disallow blank strings.

Expand Down
8 changes: 5 additions & 3 deletions src/encoded/schemas/treatment.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"properties": {
"schema_version": {
"default": "13"
"default": "14"
},
"documents": {
"description": "Documents that describe the treatment protocol."
Expand All @@ -50,7 +50,8 @@
},
"amount": {
"title": "Amount",
"type": "number"
"type": "number",
"minimum": 0
},
"amount_units": {
"title": "Amount units",
Expand All @@ -76,7 +77,8 @@
},
"duration": {
"title": "Duration",
"type": "number"
"type": "number",
"minimum": 0
},
"duration_units": {
"title": "Duration units",
Expand Down
13 changes: 13 additions & 0 deletions src/encoded/tests/fixtures/schemas/treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ def treatment_12(testapp):
'treatment_term_id': 'CHEBI:23965'
}
return testapp.post_json('/treatment', item).json['@graph'][0]


@pytest.fixture
def treatment_with_negative_duration_amount_units(testapp, organism):
item = {
'treatment_term_name': 'ethanol',
'treatment_type': 'chemical',
'duration': -9,
'duration_units': 'day',
'amount': -100,
'amount_units': 'mg'
}
return item
11 changes: 11 additions & 0 deletions src/encoded/tests/test_upgrade_treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ def test_treatment_upgrade_12_13(upgrader, treatment_12):
value = upgrader.upgrade('treatment', treatment_12, current_version='12', target_version='13')
assert value['schema_version'] == '13'
assert 'product_id' not in value


def test_treatment_upgrade_13_14(upgrader, treatment_with_negative_duration_amount_units):
value = upgrader.upgrade('treatment', treatment_with_negative_duration_amount_units, current_version='13', target_version='14')
assert value['amount'] == 0
assert value['duration'] == 0
assert value['notes'] == (
'This treatment erroneously had a negative amount of -100 '
'and was upgraded to 0. This treatment erroneously had a '
'negative duration of -9 and was upgraded to 0.'
)
23 changes: 23 additions & 0 deletions src/encoded/upgrade/treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,26 @@ def treatment_12_13(value, system):
# https://encodedcc.atlassian.net/browse/ENCD-6102
if 'product_id' in value and value['product_id'] == '':
value.pop('product_id')


@upgrade_step('treatment', '13', '14')
def treatment_13_14(value, system):
# https://encodedcc.atlassian.net/browse/ENCD-6124
if value.get('amount') < 0:
current_notes = ''
if 'notes' in value:
current_notes = value['notes']
value['notes'] = (
f'{current_notes} This treatment erroneously had a negative'
f' amount of {value["amount"]} and was upgraded to 0.'.strip()
)
value['amount'] = 0
if value.get('duration') < 0:
current_notes = ''
if 'notes' in value:
current_notes = value['notes']
value['notes'] = (
f'{current_notes} This treatment erroneously had a negative'
f' duration of {value["duration"]} and was upgraded to 0.'.strip()
)
value['duration'] = 0