Skip to content

Commit

Permalink
add client's caregiver (#66)
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Jan 10, 2022
1 parent aa46737 commit 62b49c2
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.routers import DefaultRouter, SimpleRouter

from mycarehub.clients.views import (
CaregiverViewSet,
ClientFacilityViewSet,
ClientViewSet,
IdentifierViewSet,
Expand All @@ -26,6 +27,7 @@
router.register("related_persons", RelatedPersonViewSet)
router.register("clients", ClientViewSet)
router.register("client_facilities", ClientFacilityViewSet)
router.register("caregivers", CaregiverViewSet)

app_name = "api"
urlpatterns = router.urls
6 changes: 6 additions & 0 deletions mycarehub/clients/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mycarehub.common.admin import BaseAdmin

from .models import (
Caregiver,
Client,
ClientFacility,
HealthDiaryAttachment,
Expand Down Expand Up @@ -37,6 +38,11 @@ class RelatedPersonAdmin(BaseAdmin):
pass


@admin.register(Caregiver)
class CaregiverAdmin(BaseAdmin):
pass


@admin.register(Client)
class ClientAdmin(BaseAdmin):
list_display = (
Expand Down
48 changes: 48 additions & 0 deletions mycarehub/clients/migrations/0018_auto_20220110_1440.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 3.2.9 on 2022-01-10 11:40

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


class Migration(migrations.Migration):

dependencies = [
('common', '0015_faq'),
('clients', '0017_auto_20211126_1201'),
]

operations = [
migrations.CreateModel(
name='Caregiver',
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)),
('first_name', models.TextField()),
('last_name', models.TextField()),
('caregiver_type', models.CharField(choices=[('FATHER', 'Father'), ('MOTHER', 'Mother'), ('SIBLING', 'Sibling')], max_length=64)),
('phone_number', models.TextField(blank=True, max_length=14, null=True)),
('organisation', models.ForeignKey(default=mycarehub.users.models.default_organisation, on_delete=django.db.models.deletion.PROTECT, related_name='clients_caregiver_related', to='common.organisation')),
],
options={
'ordering': ('-updated', '-created'),
'abstract': False,
},
managers=[
('objects', mycarehub.common.models.base_models.AbstractBaseManager()),
],
),
migrations.AddField(
model_name='client',
name='caregiver',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='client_caregiver', to='clients.caregiver'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2022-01-10 12:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('clients', '0018_auto_20220110_1440'),
]

operations = [
migrations.AlterField(
model_name='caregiver',
name='caregiver_type',
field=models.CharField(choices=[('FATHER', 'Father'), ('MOTHER', 'Mother'), ('SIBLING', 'Sibling'), ('HEALTHCARE_PROFESSIONAL', 'Healthcare Professional')], max_length=64),
),
]
20 changes: 20 additions & 0 deletions mycarehub/clients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ def __str__(self):
return f"{self.first_name} {self.other_name} {self.last_name} ({self.relationship_type})"


class Caregiver(AbstractBase):
"""
A caregiver is a person who is assigned to a client.
"""

class CaregiverType(models.TextChoices):
FATHER = "FATHER", _("Father")
MOTHER = "MOTHER", _("Mother")
SIBLING = "SIBLING", _("Sibling")
HEALTHCARE_PROFESSIONAL = "HEALTHCARE_PROFESSIONAL", _("Healthcare Professional")

first_name = models.TextField()
last_name = models.TextField()
caregiver_type = models.CharField(max_length=64, choices=CaregiverType.choices)
phone_number = models.TextField(null=True, blank=True, max_length=14)


@register_snippet
class Client(AbstractBase):
"""
Expand Down Expand Up @@ -261,6 +278,9 @@ class Client(AbstractBase):
null=True,
blank=True,
)
caregiver = models.OneToOneField(
Caregiver, related_name="client_caregiver", on_delete=models.PROTECT, null=True, blank=True
)

def __str__(self):
return (
Expand Down
7 changes: 7 additions & 0 deletions mycarehub/clients/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rest_framework.serializers import ModelSerializer

from mycarehub.clients.models import (
Caregiver,
Client,
ClientFacility,
HealthDiaryAttachment,
Expand Down Expand Up @@ -40,6 +41,12 @@ class Meta:
fields = "__all__"


class CaregiverSerializer(ModelSerializer):
class Meta:
model = Caregiver
fields = "__all__"


class ClientSerializer(ModelSerializer):
class Meta:
model = Client
Expand Down
20 changes: 20 additions & 0 deletions mycarehub/clients/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework import status

from mycarehub.clients.models import (
Caregiver,
Client,
ClientFacility,
Identifier,
Expand Down Expand Up @@ -134,6 +135,25 @@ def setUp(self):
super().setUp()


class CaregiverViewsetTest(CRUDTestMixin):
def setUp(self):
self.url_list = reverse("api:caregiver-list")
self.comparison_field = "first_name"
self.url_detail_base = "api:caregiver-detail"
self.instance = baker.make(
Caregiver,
organisation=self.global_organisation,
)
self.data = {
"first_name": fake.first_name(),
"last_name": fake.last_name(),
"caregiver_type": "FATHER",
"phone_number": fake.phone_number(),
}
self.detail_url = reverse(self.url_detail_base, kwargs={"pk": self.instance.pk})
super().setUp()


class ClientViewsetTest(CRUDTestMixin):
def setUp(self):
super().setUp() # early, because we need the user initialized
Expand Down
7 changes: 7 additions & 0 deletions mycarehub/clients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.viewsets import ModelViewSet

from mycarehub.clients.models import (
Caregiver,
Client,
ClientFacility,
HealthDiaryAttachment,
Expand All @@ -14,6 +15,7 @@
SecurityQuestionResponse,
)
from mycarehub.clients.serializers import (
CaregiverSerializer,
ClientFacilitySerializer,
ClientRegistrationSerializer,
ClientSerializer,
Expand Down Expand Up @@ -47,6 +49,11 @@ class RelatedPersonViewSet(ModelViewSet):
serializer_class = RelatedPersonSerializer


class CaregiverViewSet(ModelViewSet):
queryset = Caregiver.objects.order_by("pk")
serializer_class = CaregiverSerializer


class ClientViewSet(ModelViewSet):
queryset = Client.objects.order_by("pk")
serializer_class = ClientSerializer
Expand Down

0 comments on commit 62b49c2

Please sign in to comment.