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):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('token')
|
|
|
|
verbose_name_plural = _('tokens')
|
|
|
|
|
|
|
|
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):
|
|
|
|
log,zip_file = run_synthea(
|
|
|
|
self.state,
|
|
|
|
self.population,
|
|
|
|
self.gender,
|
|
|
|
self.age,
|
|
|
|
self.module
|
|
|
|
)
|
|
|
|
|
|
|
|
self.log = log
|
|
|
|
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
return zip_file
|
|
|
|
|