#coding=utf-8

#from django import newforms as forms
from django import forms
from django_measurement.forms import MeasurementField
#from django.newforms import form_for_model
from django.forms import ModelForm
from .models import *
# import  autocomplete_light
from dal import autocomplete

#PatientForm = form_for_model(Patient)

class PatientForm(forms.Form):
    ChartNo = forms.CharField()
    Name = forms.CharField()
    idcode = forms.CharField()

#TreatmentForm = form_for_model(Treatment)

class TreatmentForm(ModelForm):
# class TreatmentForm(autocomplete_light.ModelForm):
    def clean(self):
        cleaned_data = super(TreatmentForm, self).clean()
        if cleaned_data['icd10cm']:
            cleaned_data['icd9'] = ICD9Diag.objects.get(pk=cleaned_data['icd10cm'].ICD9CM_code.replace('.', ''))
            
    class Meta:
        model = Treatment
        fields = '__all__'
        widgets = {
            'icd10cm': autocomplete.ModelSelect2(url='icd10-autocomplete')
        }


class LesionForm(forms.ModelForm):
    class Meta:
        model = Lesion
        fields = [
            'calibration_table', 
            'density_correction', 

            # 'treatment', 
            'sub_location', 
            'pathology', 
            'dimensions', 

            # 'volume', 
            'volume_measure', 

            'plan_name', 

            'collimator_type', 
            'collimator', 

            'path_no', 
            'beam_no', 

            'mu_max', 
            'mu_min', 

            'dose', 
            'fractions', 
            'iso_dose_curve', 

            'dmin', 
            'dmax', 
            'dmean', 

            'coverage', 
            'ci', 
            'nci', 

            'start_date', 
            'end_date', 

            'memo', 
            ]
