示例#1
0
class GroupForm(PhoneNumberFormMixin, GenesisModelForm):
    models_i_depend_on = ['contact']

    first_name = forms.CharField(required=False, label="Contact first name")
    last_name = forms.CharField(required=False, label="Contact last name")
    email = forms.EmailField(required=False, label="Contact email")
    phone = PhoneField(required=False, label="Contact primary phone")
    address1 = forms.CharField(required=False, label="Contact address")
    address2 = forms.CharField(required=False, label="Contact address (cont.)")
    city = forms.CharField(required=False, label="Contact city")
    state = forms.ChoiceField(choices=US_STATES,
                              required=False,
                              label="Contact state")
    zip = forms.CharField(max_length=5, required=False, label="Contact zip")

    class Meta:
        model = GenesisGroup
        fields = ('name', 'group_type', 'first_name', 'last_name', 'email',
                  'phone', 'address1', 'address2', 'city', 'state', 'zip',
                  'is_no_pii')

    def get_phone_initialdata(self):
        return self.instance.contact.phone_numbers.all()

    def save(self, *args, **kwargs):
        obj = super(GroupForm, self).save(*args, **kwargs)
        self.save_phone(obj.contact)
        return obj
示例#2
0
class ProfessionalMyProfileForm(PhoneNumberFormMixin, GenesisModelForm):
    models_i_depend_on = [
        'professional_profile', 'professional_profile.contact']

    salutation = forms.CharField(required=False)
    first_name = forms.CharField()
    middle_initial = forms.CharField(required=False)
    last_name = forms.CharField()
    address1 = forms.CharField(required=False)
    address2 = forms.CharField(required=False)
    city = forms.CharField(required=False)
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(max_length=5, required=False)
    phone = PhoneField(required=False)
    fax = forms.CharField(required=False)

    class Meta:
        model = User
        fields = (
            'salutation', 'first_name', 'middle_initial', 'last_name',
            'phone', 'address1', 'address2', 'city', 'fax')

    def get_phone_initialdata(self):
        return self.instance.professional_profile.contact.phone_numbers.all()

    def save(self, *args, **kwargs):
        obj = super(ProfessionalMyProfileForm, self).save(*args, **kwargs)
        self.save_phone(obj.professional_profile.contact)
示例#3
0
class PatientMyProfileForm(PhoneNumberFormMixin, GenesisForm):
    PROFILE_FIELDS = ('gender', 'date_of_birth')
    CONTACT_FIELDS = ('salutation', 'middle_initial', 'address1', 'address2',
                      'city', 'state', 'zip')
    USER_FIELDS = ('first_name', 'last_name')
    """This form is the one used by the patient when updating their own
    profile."""
    salutation = forms.CharField(required=False)
    first_name = forms.CharField()
    middle_initial = forms.CharField(required=False)
    last_name = forms.CharField()
    gender = forms.ChoiceField(choices=PatientProfile.GENDER_CHOICES)
    date_of_birth = forms.DateField(widget=BirthdayWidget())
    address1 = forms.CharField(label='Address')
    address2 = forms.CharField(required=False, label='Address (Line 2)')
    city = forms.CharField()
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(max_length=5)
    phone = PhoneField(required=False)

    def __init__(self, *args, **kwargs):
        self.patient = kwargs['patient']
        del kwargs['patient']
        super(PatientMyProfileForm, self).__init__(*args, **kwargs)
        for i in ((self.patient, PatientMyProfileForm.USER_FIELDS),
                  (self.patient.patient_profile.contact,
                   PatientMyProfileForm.CONTACT_FIELDS),
                  (self.patient.patient_profile,
                   PatientMyProfileForm.PROFILE_FIELDS)):
            for j in i[1]:
                self.fields[j].initial = getattr(i[0], j)

    def get_phone_initialdata(self):
        return self.patient.patient_profile.contact.phone_numbers.all()

    def save(self):
        for i in ((self.patient, PatientMyProfileForm.USER_FIELDS),
                  (self.patient.patient_profile.contact,
                   PatientMyProfileForm.CONTACT_FIELDS),
                  (self.patient.patient_profile,
                   PatientMyProfileForm.PROFILE_FIELDS)):
            for j in i[1]:
                setattr(i[0], j, self.cleaned_data.get(j))
            i[0].save()

        self.save_phone(self.patient.patient_profile.contact)

        return self.patient
示例#4
0
class PatientForm(PhoneNumberFormMixin, GenesisModelForm):
    CONTACT_FIELDS = ('salutation', 'middle_initial', 'address1', 'address2',
                      'city', 'state', 'zip')
    PROFILE_FIELDS = ('company', 'preferred_contact_method', 'gender',
                      'date_of_birth', 'insurance_identifier', 'bin_number',
                      'pcn_number', 'billing_method', 'refill_method',
                      'rx_partner', 'epc_member_identifier', 'nursing_group')

    account_number = forms.IntegerField(required=False)
    epc_member_identifier = forms.CharField(required=False,
                                            label="EPC Member ID")
    insurance_identifier = forms.CharField(required=False)
    salutation = forms.CharField(required=False)
    first_name = forms.CharField(required=False)
    middle_initial = forms.CharField(required=False)
    last_name = forms.CharField(required=False)
    gender = forms.ChoiceField(choices=PatientProfile.GENDER_CHOICES,
                               required=False)
    date_of_birth = forms.DateField(widget=BirthdayWidget())
    email = forms.EmailField(label="Email", required=False)
    email_confirm = forms.EmailField(required=False)
    address1 = forms.CharField(label='Address', required=False)
    address2 = forms.CharField(required=False, label='Address (Line 2)')
    city = forms.CharField(required=False)
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(required=False)
    phone = PhoneField(required=False, label="Primary phone")
    preferred_contact_method = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=PatientProfile.PREFERRED_CONTACT_METHOD_CHOICES,
        initial="email")
    company = forms.ModelChoiceField(queryset=None, required=False)
    bin_number = forms.CharField(required=False, label="BIN")
    pcn_number = forms.CharField(required=False, label="PCN")
    billing_method = forms.ChoiceField(
        choices=PatientProfile.BILLING_METHOD_CHOICES,
        initial=PatientProfile.BILLING_METHOD_MEDICAL,
        required=False)
    refill_method = forms.ChoiceField(
        choices=PatientProfile.REFILL_METHOD_CHOICES,
        initial=PatientProfile.REFILL_METHOD_UTILIZATION,
        required=False)
    rx_partner = forms.ModelChoiceField(queryset=PharmacyPartner.objects.all(),
                                        required=False)
    nursing_group = forms.ModelChoiceField(queryset=NursingGroup.objects.all(),
                                           required=False)

    class Meta:
        model = User
        fields = ('account_number', 'epc_member_identifier',
                  'insurance_identifier', 'salutation', 'first_name',
                  'middle_initial', 'last_name', 'gender', 'date_of_birth',
                  'email', 'email_confirm', 'address1', 'address2', 'city',
                  'phone', 'state', 'zip', 'preferred_contact_method',
                  'company', 'bin_number', 'pcn_number', 'billing_method',
                  'refill_method', 'rx_partner', 'nursing_group')

    def __init__(self, *args, **kwargs):
        self.initial_group = kwargs.pop('initial_group')
        self.supplied_username = kwargs.pop('supplied_username', None)
        super(PatientForm, self).__init__(*args, **kwargs)
        self.is_new = self.instance.pk is None
        if not self.is_new:
            self.fields['account_number'].widget.attrs['readonly'] = True
            self.fields['account_number'].initial = self.instance.pk
            self.fields['epc_member_identifier'].widget.attrs['readonly'] = \
                True
            self.fields['epc_member_identifier'].initial = \
                self.instance.patient_profile.epc_member_identifier

        if self.initial_group:
            self.fields['company'].queryset = \
                self.initial_group.companies.all()
        else:
            self.fields['company'].queryset = Company.objects.none()

        if not self.is_new:
            for cf in PatientForm.CONTACT_FIELDS:
                self.fields[cf].initial = getattr(
                    self.instance.patient_profile.contact, cf)
            for pf in PatientForm.PROFILE_FIELDS:
                self.fields[pf].initial = getattr(
                    self.instance.patient_profile, pf)
            del self.fields['email']
            del self.fields['email_confirm']

    def get_phone_initialdata(self):
        return self.instance.patient_profile.contact.phone_numbers.all()

    def clean(self):
        cleaned_data = super(PatientForm, self).clean()
        for field in ('epc_member_identifier', 'insurance_identifier'):
            if field in cleaned_data and cleaned_data[field] == '':
                cleaned_data[field] = None
        if self.is_new:
            if cleaned_data.get('preferred_contact_method') == 'email':
                if not cleaned_data.get('email'):
                    raise forms.ValidationError(
                        'If you specify email as the preferred method of '
                        'contact, you must provide an email.')
            elif cleaned_data.get('preferred_contact_method') == 'phone':
                if not len(
                        list(
                            filter(lambda pn: len(pn.phone) != 0,
                                   cleaned_data.get('phone')))):
                    raise forms.ValidationError(
                        'If you choose phone as your primary method of '
                        'contact, you must provide a phone number.')
        return cleaned_data

    def clean_email(self):
        email = self.cleaned_data.get('email')
        if not email:
            return email
        if len(email) == 0:
            return ''
        try:
            users = User.objects.all()
            if not self.is_new:
                users = users.exclude(pk=self.instance.pk)
            users.get(Q(email=email) | Q(username=email))
        except User.DoesNotExist:
            return email
        else:
            raise forms.ValidationError(
                'The email you provided is already in use.  '
                'Please provide another.')

    def clean_email_confirm(self):
        email_address = self.cleaned_data.get('email')
        email_confirm = self.cleaned_data.get('email_confirm')
        if email_address and email_address != email_confirm:
            raise forms.ValidationError(
                'The emails you provided did not match.  '
                'Please enter them again.')
        return email_address

    def clean_insurance_identifier(self):
        ins_id = self.cleaned_data['insurance_identifier']
        if ins_id is not None and ins_id != '':
            qs = PatientProfile.objects.filter(insurance_identifier=ins_id)
            if not self.is_new:
                qs = qs.exclude(pk=self.instance.patient_profile.pk)
            if qs.count() > 0:
                raise forms.ValidationError(
                    "A user with this insurance ID already exists in "
                    "the system.")
        return ins_id

    def save(self, *args, **kwargs):
        data = self.cleaned_data.copy()
        data['group'] = self.initial_group
        if self.is_new:
            if self.supplied_username is not None:
                data['username'] = self.supplied_username
            patient = PatientProfile.myghr_patients.create_user(**data)
        else:
            patient = self.instance
            patient.patient_profile.update(save=True, **data)

        # Save phone numbers.
        self.save_phone(patient.patient_profile.contact)
        self.initial_group.add_patient(patient)

        return patient
示例#5
0
class PatientWizardForm(PatientForm):
    CONTACT_FIELDS = (
        'salutation',
        'middle_initial',
        'address1',
        'address2',
        'city',
        'state',
        'zip',
    )
    PROFILE_FIELDS = ('company', 'preferred_contact_method', 'gender',
                      'date_of_birth', 'security_question1',
                      'security_question2', 'security_question3',
                      'security_answer1', 'security_answer2',
                      'security_answer3', 'insurance_identifier', 'pcn_number',
                      'bin_number', 'billing_method', 'rx_partner',
                      'epc_member_identifier')

    insurance_identifier = forms.CharField()
    salutation = forms.CharField(required=False)
    first_name = forms.CharField()
    middle_initial = forms.CharField(required=False)
    last_name = forms.CharField()
    gender = forms.ChoiceField(choices=PatientProfile.GENDER_CHOICES)
    date_of_birth = forms.DateField(widget=BirthdayWidget())
    email = forms.EmailField(label="Email", required=False)
    email_confirm = forms.EmailField(required=False)
    address1 = forms.CharField(label='Address')
    address2 = forms.CharField(required=False, label='Address (Line 2)')
    city = forms.CharField()
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(max_length=5)
    phone = PhoneField(required=False, label="Primary phone")
    preferred_contact_method = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=PatientProfile.PREFERRED_CONTACT_METHOD_CHOICES,
        initial="email")
    company = forms.ModelChoiceField(queryset=None, required=False)
    bin_number = forms.CharField(required=False, label="BIN")
    pcn_number = forms.CharField(required=False, label="PCN")
    billing_method = forms.ChoiceField(
        choices=PatientProfile.BILLING_METHOD_CHOICES,
        initial=PatientProfile.BILLING_METHOD_MEDICAL)
    refill_method = forms.ChoiceField(
        choices=PatientProfile.REFILL_METHOD_CHOICES,
        initial=PatientProfile.REFILL_METHOD_UTILIZATION)
    rx_partner = forms.ModelChoiceField(queryset=PharmacyPartner.objects.all(),
                                        required=False)

    class Meta:
        model = User
        fields = ('account_number', 'insurance_identifier', 'salutation',
                  'first_name', 'middle_initial', 'last_name', 'gender',
                  'date_of_birth', 'email', 'email_confirm', 'address1',
                  'address2', 'city', 'phone', 'preferred_contact_method',
                  'company', 'bin_number', 'pcn_number', 'billing_method',
                  'refill_method', 'rx_partner')

    def clean(self):
        qs = PatientProfile.objects.filter(
            date_of_birth=self.cleaned_data['date_of_birth'],
            user__last_name=self.cleaned_data['last_name'])
        if qs.count() > 0:
            raise forms.ValidationError(
                "Patient with this DOB / Last name already exists.")
示例#6
0
class ProfessionalForm(PhoneNumberFormMixin, GenesisModelForm):
    CONTACT_FIELDS = (
        'salutation', 'middle_initial', 'address1', 'address2', 'city',
        'state', 'zip', 'fax')
    PROFILE_FIELDS = ('timezone_name', 'nursing_group')

    salutation = forms.CharField(required=False)
    first_name = forms.CharField()
    middle_initial = forms.CharField(required=False)
    last_name = forms.CharField()
    email = forms.EmailField()
    confirm_email = forms.EmailField()
    address1 = forms.CharField(label='Address', required=False)
    address2 = forms.CharField(label='Address (cont.)', required=False)
    city = forms.CharField(required=False)
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(
        max_length=5, required=False, widget=forms.TextInput(attrs={'class': 'zip'}))
    phone = PhoneField(required=False)
    fax = forms.CharField(required=False)
    timezone_name = forms.ChoiceField(
        choices=ProfessionalProfile.ALLOWED_TIMEZONES, label="Timezone")
    nursing_group = forms.ModelChoiceField(
        queryset=NursingGroup.objects.all(),
        required=False
    )

    class Meta:
        model = User
        fields = (
            'salutation', 'first_name', 'middle_initial', 'last_name',
            'email', 'confirm_email', 'address1', 'address2', 'city',
            'phone', 'fax', 'timezone_name', 'nursing_group')

    def __init__(self, *args, **kwargs):
        self.requester = kwargs.pop('requester')
        self.initial_group = kwargs.pop('initial_group')
        super(ProfessionalForm, self).__init__(*args, **kwargs)

        if not self.is_new:
            for cf in ProfessionalForm.CONTACT_FIELDS:
                self.fields[cf].initial = getattr(
                    self.instance.professional_profile.contact, cf)
            for pf in ProfessionalForm.PROFILE_FIELDS:
                self.fields[pf].initial = getattr(
                    self.instance.professional_profile, pf)
            del self.fields['email']
            del self.fields['confirm_email']

    def get_phone_initialdata(self):
        return self.instance.professional_profile.contact.phone_numbers.all()

    def clean_email(self):
        email = self.cleaned_data.get('email')
        try:
            if self.is_new:
                User.objects.get(Q(email=email) | Q(username=email))
            else:
                User.objects.exclude(pk=self.instance.pk).get(
                    Q(email=email) | Q(username=email))
        except User.DoesNotExist:
            return email
        else:
            raise forms.ValidationError(
                "The provided email address is already in use.  "
                "Please provide another.")

    def clean_confirm_email(self):
        email_address = self.cleaned_data.get('email')
        email_confirm = self.cleaned_data.get('confirm_email')
        if email_address != email_confirm:
            raise forms.ValidationError(
                'The provided emails did not match.  Please enter them again.')
        return email_confirm

    def save(self, commit=True, **kwargs):
        data = self.cleaned_data
        kwargs = {}
        kwargs.update(data)
        kwargs['parent_group'] = self.initial_group
        if data.get('email'):
            kwargs['username'] = data['email']
        if self.is_new:
            user = ProfessionalProfile.objects.create_user(**kwargs)
        else:
            user = self.instance
            user.professional_profile.update(save=True, **kwargs)

        self.save_phone(user.professional_profile.contact)

        return user
示例#7
0
class CompanyForm(PhoneNumberFormMixin, GenesisModelForm):
    CONTACT_FIELDS = (
        'first_name', 'last_name', 'email', 'address1', 'address2', 'city',
        'state', 'zip',)

    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    phone = PhoneField(label='Phone')
    address1 = forms.CharField(label='Address')
    address2 = forms.CharField(label='Address (cont.)', required=False)
    city = forms.CharField()
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(max_length=5)

    class Meta:
        model = Company
        fields = (
            'name', 'payor',  'first_name', 'last_name', 'email', 'phone', 'address1',
            'address2', 'city', 'group_identifier', 'billing_method',
            'refill_method', 'start_kit_size', 'minimum_refill_quantity', 'bin_id',
            'pcn_id', 'glucose_control_refill_frequency', 'lancing_refill_frequency',
            'default_pharmacy', 'api_partner', 'nursing_group', 'compliance_nursing_group')

    def __init__(self, *args, **kwargs):
        self.initial_group = kwargs.pop('initial_group')
        super(CompanyForm, self).__init__(*args, **kwargs)
        self.fields['payor'].queryset = self.initial_group.payors.all()
        if self.instance.pk:
            for cf in CompanyForm.CONTACT_FIELDS:
                self.fields[cf].initial = getattr(self.instance.contact, cf)

    def get_phone_initialdata(self):
        return self.instance.contact.phone_numbers.all()

    def clean_name(self):
        name = self.cleaned_data.get('name')
        try:
            if self.instance.pk:
                self.initial_group.companies.exclude(pk=self.instance.pk).get(
                    name=name)
            else:
                self.initial_group.companies.get(name=name)
        except Company.DoesNotExist:
            return name
        else:
            raise forms.ValidationError(
                'A company with that name already exists.  Please choose '
                'another name.')

    def save(self, commit=True, **kwargs):
        company = super(CompanyForm, self).save(commit=False, **kwargs)

        company.group = self.initial_group
        contact = company.pk and company.contact or Contact()
        for cf in CompanyForm.CONTACT_FIELDS:
            setattr(contact, cf, self.cleaned_data.get(cf))
        contact.save()
        if not company.pk:
            company.contact = contact
        company.save()
        self.save_phone(contact)
        return company
示例#8
0
class PayorForm(PhoneNumberFormMixin, GenesisModelForm):
    CONTACT_FIELDS = ('first_name', 'last_name', 'email', 'address1',
                      'address2', 'city', 'state', 'zip')

    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField(required=False)
    phone = PhoneField(label='Phone', required=False)
    address1 = forms.CharField(label='Address', required=False)
    address2 = forms.CharField(label='Address (cont.)', required=False)
    city = forms.CharField(widget=forms.TextInput(attrs={'class': 'required'}))
    state = forms.ChoiceField(choices=US_STATES, required=False)
    zip = forms.CharField(max_length=5)

    class Meta:
        model = Payor
        fields = ('name', 'first_name', 'last_name', 'email', 'phone',
                  'address1', 'address2', 'city')

    def __init__(self, *args, **kwargs):
        if kwargs.get('initial_group'):
            self.initial_group = kwargs.pop('initial_group')
        elif kwargs.get('instance'):
            self.initial_group = kwargs['instance'].group
        else:
            self.initial_group = None
        super(PayorForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            for cf in PayorForm.CONTACT_FIELDS:
                self.fields[cf].initial = getattr(self.instance.contact, cf)

    def get_phone_initialdata(self):
        return self.instance.contact.phone_numbers.all()

    def clean_name(self):
        name = self.cleaned_data.get('name')
        try:
            if self.instance.pk:
                self.initial_group.payors.exclude(pk=self.instance.pk).get(
                    name=name)
            else:
                self.initial_group.payors.get(name=name)
        except Payor.DoesNotExist:
            return name
        else:
            raise forms.ValidationError(
                'A payor with that name already exists.  Please choose another '
                'name.')

    def save(self, commit=True, **kwargs):
        payor = super(PayorForm, self).save(commit=False, **kwargs)
        payor.group = self.initial_group
        contact = payor.pk and payor.contact or Contact()
        for cf in PayorForm.CONTACT_FIELDS:
            setattr(contact, cf, self.cleaned_data.get(cf))
        contact.save()
        if not payor.pk:
            payor.contact = contact
        payor.save()
        self.save_phone(contact)
        return payor