2020-11-13 15:31:14 +01:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from django_cryptography.fields import encrypt
|
|
|
|
|
|
|
|
from lib.utils.general import get_random_string
|
|
|
|
from lib.models.base import MetaDataModel
|
|
|
|
|
2020-11-16 16:30:41 +01:00
|
|
|
from .lib.utils import run_synthea
|
|
|
|
|
2020-11-13 15:31:14 +01:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
class Synthea(MetaDataModel):
|
2020-11-27 12:49:03 +01:00
|
|
|
"""Synthea model that holds some iformation about a generated output.
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
----------
|
|
|
|
id : uuid
|
|
|
|
A unique ID for every Synthea run. Leave empty for auto generating a new value.
|
|
|
|
state : str
|
|
|
|
The state for which you want to generate Synthea patient data
|
|
|
|
population : int
|
|
|
|
The amount of patients you want to generate
|
|
|
|
gender : datetime
|
|
|
|
Generate only male (m), only female(f) or leave empty for male and female
|
|
|
|
age : str
|
|
|
|
The age range for the patients. Enter like [min_age]-[max_age]
|
|
|
|
module : str
|
|
|
|
The module to use for patient generating. Leave empty for random use by Synthea
|
|
|
|
log : str
|
|
|
|
The outcome of a single patient generating run. This can be read in the admin area.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Synthea: A new Synthea model
|
|
|
|
"""
|
2020-11-13 15:31:14 +01:00
|
|
|
|
|
|
|
class Meta:
|
2020-11-27 12:49:03 +01:00
|
|
|
verbose_name = _('synthea')
|
|
|
|
verbose_name_plural = _('synthea')
|
2020-11-13 15:31:14 +01:00
|
|
|
|
|
|
|
id = models.UUIDField(_('ID'), primary_key=True, unique=True, default=uuid.uuid4, editable=False, help_text=_('A unique id'))
|
|
|
|
state = models.CharField(_('State'), max_length=200, help_text=_('The state for which synthea generate data.'))
|
2020-11-16 16:30:41 +01:00
|
|
|
population = models.PositiveSmallIntegerField(_('Population'), default=50, help_text=_('The size of the population'))
|
2020-11-13 15:31:14 +01:00
|
|
|
gender = models.CharField(_('Gender'), blank=True,max_length=1, help_text=_('Select the gender type'))
|
2020-11-16 16:30:41 +01:00
|
|
|
age = models.CharField(_('Age range'), blank=True,default='18-100', max_length=10, help_text=_('Select the age range. Enter [min age]-[max age]'))
|
2020-11-13 15:31:14 +01:00
|
|
|
module = models.CharField(_('Module'),blank=True, max_length=50, help_text=_('Select the module'))
|
2020-11-16 16:30:41 +01:00
|
|
|
log = models.TextField(_('Log'),blank=True, help_text=_('Synthea logfile output'))
|
|
|
|
|
|
|
|
def generate(self):
|
2020-11-27 12:49:03 +01:00
|
|
|
"""Run the patient generation. This will return a logfile and a zipfile location for download.
|
|
|
|
|
|
|
|
The log will be stored in the model when done. This log can then be seen/readed in the admin section of Django
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: The zip file location on disk.
|
|
|
|
"""
|
|
|
|
# Start generating patient data.
|
2020-11-16 16:30:41 +01:00
|
|
|
log,zip_file = run_synthea(
|
|
|
|
self.state,
|
|
|
|
self.population,
|
|
|
|
self.gender,
|
|
|
|
self.age,
|
|
|
|
self.module
|
|
|
|
)
|
2020-11-27 12:49:03 +01:00
|
|
|
# Store the log from the Synthea run in the database.
|
2020-11-16 16:30:41 +01:00
|
|
|
self.log = log
|
|
|
|
self.save()
|
2020-11-27 12:49:03 +01:00
|
|
|
# Return the zip file locaton for download
|
2020-11-16 16:30:41 +01:00
|
|
|
return zip_file
|
|
|
|
|