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 from .lib.utils import run_synthea 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.')) population = models.PositiveSmallIntegerField(_('Population'), default=50, help_text=_('The size of the population')) gender = models.CharField(_('Gender'), blank=True,max_length=1, help_text=_('Select the gender type')) age = models.CharField(_('Age range'), blank=True,default='18-100', max_length=10, help_text=_('Select the age range. Enter [min age]-[max age]')) module = models.CharField(_('Module'),blank=True, max_length=50, help_text=_('Select the module')) 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