Skip to content

Commit

Permalink
feat: add screening tool questions
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Mar 9, 2022
1 parent b59fb5b commit 1c91632
Show file tree
Hide file tree
Showing 14 changed files with 473 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"mycarehub.staff.apps.StaffConfig",
"mycarehub.authority.apps.AuthorityConfig",
"mycarehub.communities.apps.CommunityConfig",
"mycarehub.screeningtools.apps.ScreeningtoolsConfig",
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

Expand Down
227 changes: 227 additions & 0 deletions data/screeningtools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
[
{
"question": "In the past, has anyone made you feel threatened, fearful or in danger?",
"tool_type": "VIOLENCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 0,
"meta": {
"violence_type": "EMOTIONAL"
}
},
{
"question": "In the past, have you been slapped, punched, hit or physically hurt by someone in a way?",
"tool_type": "VIOLENCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 1,
"meta": {
"violence_type": "PHYSICAL"
}
},
{
"question": "In the past, has anyone forced or coerced you to have sexual relations against your will?",
"tool_type": "VIOLENCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 2,
"meta": {
"violence_type": "SEXUAL"
}
},
{
"question": "Are you in a relationship with a person who threatens, frightens, insults you, treats you badly or physically hurts you?",
"tool_type": "VIOLENCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 3,
"meta": {
"violence_type": "SEXUAL"
}
},
{
"question": "When was your last menstrual period?",
"tool_type": "CONTRACEPTIVE_ASSESSMENT",
"response_choices": {
"0": "This Month",
"1": "Last month",
"2": "Not Started Yet"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 0,
"meta":null
},
{
"question": "Are you pregnant?",
"tool_type": "CONTRACEPTIVE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 1,
"meta":null
},
{
"question": "If no, are you on family planning?",
"tool_type": "CONTRACEPTIVE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 2,
"meta":null
},
{
"question": "If no to Q3, would you like to use a family planning planning?",
"tool_type": "CONTRACEPTIVE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 3,
"meta":null
},
{
"question": "Have you experienced a chough for any duration?",
"tool_type": "TB_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 0,
"meta":null
},
{
"question": "Do you have a fever?",
"tool_type": "TB_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 1,
"meta":null
},
{
"question": "Have you Noticed any weight loss?",
"tool_type": "TB_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 2,
"meta":null
},
{
"question": "Do you experience night sweats?",
"tool_type": "TB_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 3,
"meta":null
},
{
"question": "Have you ever ridden in a car driven by someone (including yourself) who was \"high\" or had been using alcohol or drugs?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 0,
"meta":null
},
{
"question": "Do you ever use alcohol or drugs to relax, feel better about yourself, or fit in?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 1,
"meta":null
},
{
"question": "Do you ever use alcohol or drugs while you are by yourself, or alone?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 2,
"meta":null
},
{
"question": "Do you ever forget things you did while using alcohol or drugs?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 3,
"meta":null
},
{
"question": "Do your families or friends ever tell you that you should cut down on your drinking or drug abuse?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 4,
"meta":null
},
{
"question": "Have you ever gotten in trouble while you were using alcohol or drugs?",
"tool_type": "ALCOHOL_SUBSTANCE_ASSESSMENT",
"response_choices": {
"0": "Yes",
"1": "No"
},
"response_category": "SINGLE_CHOICE",
"response_type": "INTEGER",
"sequence": 5,
"meta":null
}
]
Empty file.
15 changes: 15 additions & 0 deletions mycarehub/screeningtools/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib import admin

from mycarehub.common.admin import BaseAdmin

from .models import ScreeningToolsQuestion, ScreeningToolsResponse


@admin.register(ScreeningToolsQuestion)
class ScreeningToolsQuestionAdmin(BaseAdmin):
pass


@admin.register(ScreeningToolsResponse)
class ScreeningToolsResponseAdmin(BaseAdmin):
pass
6 changes: 6 additions & 0 deletions mycarehub/screeningtools/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ScreeningtoolsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "mycarehub.screeningtools"
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json
import os
import sys
from pathlib import Path

from django.core.management.base import BaseCommand
from django.db import transaction

from mycarehub.screeningtools.models import ScreeningToolsQuestion


class Command(BaseCommand):
help = "Loads the screening tool questions to the database"

@transaction.atomic
def handle(self, *args, **options):
base_path = Path(__file__).parent.parent.parent.parent.parent.resolve()
sys.path.append(str(base_path))
data_dir = os.path.join(base_path, "data")
source_file_screeningtools = os.path.join(data_dir, "screeningtools.json")

data_screeningtools = json.load(open(file=source_file_screeningtools))
count = len(data_screeningtools)

for screeningtool in data_screeningtools:
r, created = ScreeningToolsQuestion.objects.get_or_create(
question=screeningtool["question"],
tool_type=screeningtool["tool_type"],
response_choices=screeningtool["response_choices"],
response_type=screeningtool["response_type"],
response_category=screeningtool["response_category"],
sequence=screeningtool["sequence"],
meta=screeningtool["meta"],
)
print(f"screeningtool: {screeningtool}; Created: {created}; {count}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from io import StringIO

from django.core.management import call_command
from django.test import TestCase

from mycarehub.screeningtools.models import ScreeningToolsQuestion


class CommandsTestCase(TestCase):
def test_load_screeningquestions(self):
"Test load screening tools"
out = StringIO()
assert not ScreeningToolsQuestion.objects.exists()
call_command("load_screeningquestions", stdout=out)
assert ScreeningToolsQuestion.objects.exists()
71 changes: 71 additions & 0 deletions mycarehub/screeningtools/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generated by Django 3.2.11 on 2022-03-09 06:34

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import mycarehub.common.models.base_models
import mycarehub.utils.general_utils
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
('clients', '0027_alter_servicerequest_request_type'),
('common', '0016_auto_20220215_1721'),
]

operations = [
migrations.CreateModel(
name='ScreeningToolsQuestion',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('active', models.BooleanField(default=True)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
('created_by', models.UUIDField(blank=True, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
('updated_by', models.UUIDField(blank=True, null=True)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('question', models.TextField()),
('tool_type', models.CharField(choices=[('TB_ASSESSMENT', 'TB Assessment'), ('VIOLENCE_ASSESSMENT', 'Violence Assessment'), ('CONTRACEPTIVE_ASSESSMENT', 'Contraceptive Assessment'), ('ALCOHOL_SUBSTANCE_ASSESSMENT', 'Alcohol and Substance Use Assessment')], max_length=32)),
('response_choices', models.JSONField(blank=True, null=True)),
('response_type', models.CharField(choices=[('INTEGER', 'Integer'), ('TEXT', 'Text'), ('DATE', 'Date')], max_length=32)),
('response_category', models.CharField(choices=[('SINGLE_CHOICE', 'Single Choice'), ('MULTI_CHOICE', 'Multiple Choice'), ('OPEN_ENDED', 'Open Ended')], max_length=32)),
('sequence', models.IntegerField()),
('meta', models.JSONField(blank=True, null=True)),
('organisation', models.ForeignKey(default=mycarehub.utils.general_utils.default_organisation, on_delete=django.db.models.deletion.PROTECT, related_name='screeningtools_screeningtoolsquestion_related', to='common.organisation')),
],
options={
'ordering': ('-updated', '-created'),
'abstract': False,
},
managers=[
('objects', mycarehub.common.models.base_models.AbstractBaseManager()),
],
),
migrations.CreateModel(
name='ScreeningToolsResponse',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('active', models.BooleanField(default=True)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
('created_by', models.UUIDField(blank=True, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
('updated_by', models.UUIDField(blank=True, null=True)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('response', models.TextField()),
('client', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='clients.client')),
('organisation', models.ForeignKey(default=mycarehub.utils.general_utils.default_organisation, on_delete=django.db.models.deletion.PROTECT, related_name='screeningtools_screeningtoolsresponse_related', to='common.organisation')),
('question', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='screeningtools.screeningtoolsquestion')),
],
options={
'ordering': ('-updated', '-created'),
'abstract': False,
},
managers=[
('objects', mycarehub.common.models.base_models.AbstractBaseManager()),
],
),
]
Empty file.
Loading

0 comments on commit 1c91632

Please sign in to comment.