Skip to content

Commit

Permalink
Add data models for ScanReport Job overview (#916)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Rae <[email protected]>
  • Loading branch information
AndrewThien and AndyRae authored Nov 28, 2024
1 parent 87c8534 commit 67b0309
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/api/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"revproxy",
"shared",
"shared.files",
"shared.jobs",
]

MIDDLEWARE = [
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions app/shared/shared/jobs/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class JobsConfig(AppConfig):
name = "shared.jobs"
label = "jobs"
158 changes: 158 additions & 0 deletions app/shared/shared/jobs/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Generated by Django 4.2.15 on 2024-11-28 09:27

from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings


def seeding_objects(apps, schema_editor):
JobStage = apps.get_model("jobs", "JobStage")
StageStatus = apps.get_model("jobs", "StageStatus")

job_stages = [
{"id": 1, "value": "UPLOAD_SCAN_REPORT", "display_name": "Upload Scan Report"},
{
"id": 2,
"value": "BUILD_CONCEPTS_FROM_DICT",
"display_name": "Build concepts from OMOP Data dictionary",
},
{
"id": 3,
"value": "REUSE_CONCEPTS",
"display_name": "Reuse concepts from other scan reports",
},
{
"id": 4,
"value": "GENERATE_RULES",
"display_name": "Auto generate mapping rules from available concepts",
},
{
"id": 5,
"value": "DOWNLOAD_RULES",
"display_name": "Generate and download mapping rules JSON",
},
]

for stage in job_stages:
JobStage.objects.create(
id=stage["id"],
value=stage["value"],
display_name=stage["display_name"],
)

stage_statuses = [
{
"id": 1,
"value": "IN_PROGRESS",
"display_name": "Job in Progress",
},
{
"id": 2,
"value": "COMPLETE",
"display_name": "Job Complete",
},
{"id": 3, "value": "FAILED", "display_name": "Job Failed"},
]

for status in stage_statuses:
StageStatus.objects.create(
id=status["id"],
value=status["value"],
display_name=status["display_name"],
)


def unseeding_objects(apps, schema_editor):
JobStage = apps.get_model("jobs", "JobStage")
StageStatus = apps.get_model("jobs", "StageStatus")
# Remove all objects
JobStage.objects.all().delete()
StageStatus.objects.all().delete()


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("mapping", "0005_auto_20241015_0900"),
]

operations = [
migrations.CreateModel(
name="JobStage",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("value", models.CharField(max_length=64)),
("display_name", models.CharField(max_length=64)),
],
),
migrations.CreateModel(
name="StageStatus",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("value", models.CharField(max_length=64)),
("display_name", models.CharField(max_length=64)),
],
),
migrations.RunPython(seeding_objects, unseeding_objects),
migrations.CreateModel(
name="Job",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("scan_report_id", models.IntegerField(null=True)),
("scan_report_table_id", models.IntegerField(null=True)),
(
"stage",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="job_stage",
to="jobs.jobstage",
),
),
(
"status",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="stage_status",
to="jobs.stagestatus",
),
),
("details", models.CharField(blank=True, max_length=256, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
"abstract": False,
},
),
]
Empty file.
32 changes: 32 additions & 0 deletions app/shared/shared/jobs/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.db import models
from shared.mapping.models import BaseModel


class JobStage(models.Model):
value = models.CharField(max_length=64)
display_name = models.CharField(max_length=64)


class StageStatus(models.Model):
value = models.CharField(max_length=64)
display_name = models.CharField(max_length=64)


class Job(BaseModel):
scan_report_id = models.IntegerField(null=True)
scan_report_table_id = models.IntegerField(null=True)
stage = models.ForeignKey(
"JobStage",
null=True,
blank=True,
on_delete=models.DO_NOTHING,
related_name="job_stage",
)
status = models.ForeignKey(
"StageStatus",
null=True,
blank=True,
on_delete=models.DO_NOTHING,
related_name="stage_status",
)
details = models.CharField(max_length=256, null=True, blank=True)

0 comments on commit 67b0309

Please sign in to comment.