Skip to content

Commit

Permalink
Add openhim queue model and signal
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Nov 23, 2023
1 parent 2ed991b commit 553b062
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eventstore/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

class EventstoreConfig(AppConfig):
name = "eventstore"

def ready(self):
import eventstore.signals # noqa
54 changes: 54 additions & 0 deletions eventstore/migrations/0062_openhimqueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 4.1.7 on 2023-11-23 09:40

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("eventstore", "0061_alter_optout_reason"),
]

operations = [
migrations.CreateModel(
name="OpenHIMQueue",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("object_id", models.UUIDField()),
(
"object_type",
models.CharField(
choices=[
("PrebirthRegistration", "PrebirthRegistration"),
("CHWRegistration", "CHWRegistration"),
("PublicRegistration", "PublicRegistration"),
("ChannelSwitch", "ChannelSwitch"),
("OptOut", "OptOut"),
],
max_length=30,
),
),
(
"status",
models.PositiveSmallIntegerField(
choices=[
(0, "Pending"),
(1, "Processing"),
(2, "Complete"),
(3, "Error"),
],
default=0,
),
),
],
),
]
36 changes: 36 additions & 0 deletions eventstore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,3 +1094,39 @@ def clean(self):
date(self.dob_year, self.dob_month, self.dob_day)
except ValueError as e:
raise ValidationError(f"Invalid date of birth date, {str(e)}")


class OpenHIMQueue(models.Model):
class ObjectType:
PREBIRTH_REGISTRATION = "PrebirthRegistration"
CHW_REGISTRATION = "CHWRegistration"
PUBLIC_REGISTRATION = "PublicRegistration"
CHANNEL_SWITCH = "ChannelSwitch"
OPTOUT = "OptOut"
choices = (
(PREBIRTH_REGISTRATION, "PrebirthRegistration"),
(CHW_REGISTRATION, "CHWRegistration"),
(PUBLIC_REGISTRATION, "PublicRegistration"),
(CHANNEL_SWITCH, "ChannelSwitch"),
(OPTOUT, "OptOut"),
)

class Status:
PENDING = 0
PROCESSING = 1
COMPLETE = 2
ERROR = 3

choices = (
(PENDING, "Pending"),
(PROCESSING, "Processing"),
(COMPLETE, "Complete"),
(ERROR, "Error"),
)

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
object_id = models.UUIDField()
object_type = models.CharField(max_length=30, choices=ObjectType.choices)
status = models.PositiveSmallIntegerField(
choices=Status.choices, default=Status.PENDING
)
13 changes: 13 additions & 0 deletions eventstore/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from eventstore.models import OpenHIMQueue, PrebirthRegistration


@receiver(post_save, sender=PrebirthRegistration)
def create_user_profile(sender, instance, created, **kwargs):
if created:
OpenHIMQueue.objects.create(
object_id=instance.id,
object_type=OpenHIMQueue.ObjectType.PREBIRTH_REGISTRATION,
)
Empty file added eventstore/tests/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions eventstore/test_models.py → eventstore/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
HCSStudyBRandomization,
HealthCheckUserProfile,
Message,
OpenHIMQueue,
PrebirthRegistration,
)


Expand Down Expand Up @@ -569,3 +571,19 @@ def test_get_random_study_b_arm(self, mock_get_study_totals_per_province):

mock_get_study_totals_per_province.return_value = (2000, 10)
self.assertIsNone(rand.get_random_study_b_arm())


class PrebirthRegistrationTests(TestCase):
def test_create_signal(self):
prebirthregistration = PrebirthRegistration.objects.create(
contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91",
device_contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91",
edd="2020-12-01",
)

queue_record = OpenHIMQueue.objects.first()

self.assertEqual(queue_record.object_id, prebirthregistration.id)
self.assertEqual(
queue_record.object_type, OpenHIMQueue.ObjectType.PREBIRTH_REGISTRATION
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 553b062

Please sign in to comment.