synthea_webservice/webservice/apps/synthea/forms.py

29 lines
1003 B
Python

from django.utils.translation import gettext_lazy as _
from django.forms import ModelForm
from django import forms
from apps.synthea.models import Synthea
from .lib.utils import available_states, available_modules
class SyntheaForm(ModelForm):
class Meta:
model = Synthea
fields = ['state', 'population', 'gender', 'age', 'module']
# This is loaded only once during startup. So changing the state data will not be picked up after a restart
state_options = [('',_('Select'))]
for item in available_states():
state_options.append((item['id'],item['name']))
module_options = [('',_('Any'))]
for item in available_modules():
module_options.append((item['id'],item['name']))
widgets = {
'state': forms.Select(choices=state_options),
'gender': forms.Select(choices=[('',_('Any')),('m',_('Male')),('f',_('Female'))]),
'module': forms.Select(choices=module_options)
}