Skip to content

Commit

Permalink
fix: screening tools loader
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Mar 11, 2022
1 parent a57bb16 commit 0167c0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 12 additions & 4 deletions data/screeningtools.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"response_type": "INTEGER",
"sequence": 0,
"meta": {
"violence_type": "EMOTIONAL"
"helper_text": "Emotional violence Assessment",
"violence_type": "EMOTIONAL",
"violence_code": "GBV-EV"
}
},
{
Expand All @@ -24,7 +26,9 @@
"response_type": "INTEGER",
"sequence": 1,
"meta": {
"violence_type": "PHYSICAL"
"helper_text": "Physical violence Assessment",
"violence_type": "PHYSICAL",
"violence_code": " GBV-PV"
}
},
{
Expand All @@ -38,7 +42,9 @@
"response_type": "INTEGER",
"sequence": 2,
"meta": {
"violence_type": "SEXUAL"
"helper_text": "Sexual violence",
"violence_type": "SEXUAL",
"violence_code": "GBV-SV"
}
},
{
Expand All @@ -52,7 +58,9 @@
"response_type": "INTEGER",
"sequence": 3,
"meta": {
"violence_type": "SEXUAL"
"helper_text": "Sexual violence",
"violence_type": "SEXUAL",
"violence_code": "GBV-IPV"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def handle(self, *args, **options):
count = len(data_screeningtools)

for screeningtool in data_screeningtools:
if ScreeningToolsQuestion.objects.filter(question=screeningtool["question"]).exists():
continue
r, created = ScreeningToolsQuestion.objects.get_or_create(
question=screeningtool["question"],
tool_type=screeningtool["tool_type"],
Expand All @@ -32,4 +34,5 @@ def handle(self, *args, **options):
sequence=screeningtool["sequence"],
meta=screeningtool["meta"],
)
r.save()
print(f"screeningtool: {screeningtool}; Created: {created}; {count}")
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ def test_load_screeningquestions(self):
assert not ScreeningToolsQuestion.objects.exists()
call_command("load_screeningquestions", stdout=out)
assert ScreeningToolsQuestion.objects.exists()
lenObjects = ScreeningToolsQuestion.objects.count()
call_command("load_screeningquestions", stdout=out)
assert ScreeningToolsQuestion.objects.count() == lenObjects

0 comments on commit 0167c0d

Please sign in to comment.