from django import forms
from .models import observation, nutritional_value, blood_Pressure,History_examination, vitals,treatment_details,scheduling
from baseapp.models import treatment
from crispy_forms.helper import FormHelper
from django.utils.safestring import mark_safe
from crispy_forms.layout import Submit,Layout, ButtonHolder,HTML
from django.urls import reverse_lazy
from datetime import datetime, timedelta

class form_observation(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
      class Meta:
        model = observation
        fields = ['report_name',
                'report_file',
                'report_vaue']
        
class form_observation_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      
      self.as_p = True        

   report_name = forms.CharField(required=False,max_length=75, help_text="Search by report name",label=mark_safe('<strong> Report Name </strong>')) 
   report_vaue = forms.CharField(required=False,max_length=50,help_text="Search by report value ",label=mark_safe('<strong> Report Value </strong>'))



class form_nutritional_value(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
      class Meta:
        model = nutritional_value
        fields = ['height',
                'weight' , 'Waistratio']
        #,'BMI'
               #  'fk_patient',
               #  'fk_employee'
class form_nutritional_value_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True        
   height = forms.FloatField(widget=forms.NumberInput,required=False, help_text="Search by height ",label=mark_safe('<strong> Height </strong>')) 
   weight = forms.FloatField(widget=forms.NumberInput,required=False,help_text="Search by weight ",label=mark_safe('<strong> Weight </strong>'))
   BMI= forms.FloatField(widget=forms.NumberInput,required=False,help_text="Search by BMI ",label=mark_safe('<strong> BMI </strong>'))
   Waistratio= forms.FloatField(widget=forms.NumberInput,required=False,help_text="Search by WHR = Waist circumference in cms/ hip circumference in cms ",label=mark_safe('<strong> WHR </strong>'))
        
class form_blood_Pressure(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
      class Meta:
        model = blood_Pressure
        fields = ['sys_bld_pressure',
                'sys_bld_abnormal',
                'sys_bld_notes',
                'dias_bld_pressure',
                'dias_bld_abnormal',
                'dias_bld_notes',
                'body_position',
                'body_position_notes',
                'pulse',
                'pulse_abnormal',
                'bld_oxy_saturation',
                'bld_oxy_saturation_abnormal']
        
class form_blood_Pressure_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True       

   sys_bld_pressure = forms.FloatField(required=False,widget=forms.NumberInput, help_text="Search by systoic blood pressure value ",label=mark_safe('<strong> Systoic blood Pressure </strong>')) 
   dias_bld_pressure = forms.FloatField(required=False,widget=forms.NumberInput,help_text="Search by diastolic blood pressure value ",label=mark_safe('<strong> Diastolic blood Pressure </strong>'))
   body_position = forms.ChoiceField(required=False,label=mark_safe('<strong> Body position </strong>'),help_text="Search by body position ", choices=[(0,'Not Selected')] +list(blood_Pressure.objects.all().values_list('body_position','body_position')))

        


        
class form_History_examination(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
      class Meta:
        model = History_examination
        fields = ['Chief_complaint',
                'symptom_duration',
                'units',
                'present_illness',
                'Smoking_status',
                'consultation_images']
        
class form_History_examination_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True       

   Chief_complaint = forms.CharField(required=False,help_text="Search by complaint  ",label=mark_safe('<strong> Chief Complaint </strong>'))
   symptom_duration =  forms.FloatField(required=False,widget=forms.NumberInput, help_text="Search by symptom duration ",label=mark_safe('<strong> Symptoms duration </strong>')) 
   units  = forms.ChoiceField(required=False,label=mark_safe('<strong> Units </strong>'),help_text="Search by units ", choices=[(0,'Not Selected')] +list(History_examination.objects.all().values_list('units','units')))
   Smoking_status  = forms.ChoiceField(required=False,label=mark_safe('<strong> Smoking Status </strong>'),help_text="Search by smoking status ", choices=[(0,'Not Selected')] +list(History_examination.objects.all().values_list('Smoking_status','Smoking_status')))
                


   # Smoking_status = forms.ChoiceField(required=False,widget=forms.c,help_text='Provide smoking status to search',label='Symptom duration')

   # units = forms.CharField(required=False,max_length=250,help_text='Search by ',label='')

        
class form_vitals(forms.ModelForm): 
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit','Save'))
         self.as_p = True  
     
      class Meta:
        model = vitals
        fields = ['temperature',
                'temperature_abnormal',
                'temperature_notes',
                'Res_rate',
                'Res_rate_abnormal',
                'Res_notes',
                ]        
        
class form_vitals_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True   

   temperature = forms.FloatField(required=False,widget=forms.NumberInput, help_text="Search by temperature ",label=mark_safe('<strong> Temperature </strong>')) 

   Res_rate = forms.FloatField(required=False,widget=forms.NumberInput,help_text="Search by respiratory rate ",label=mark_safe('<strong> Respiratory Rate </strong>'))




        
class form_treatment_details(forms.ModelForm):
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
      class Meta:
        model = treatment_details
        fields = ['fk_treatment',
                  'treatment_notes'
               ]
        
class form_treatment_details_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True    

   class Meta:
        model = treatment_details
        fields = ['fk_treatment'
                  'treatment_notes'
               ]    
   fk_treatment =forms.ChoiceField(required=False,help_text="Search by treatment ",label=mark_safe('<strong> Treatment </strong>'), choices=[(0,'Not Selected')] +list(treatment.objects.all().values_list('id','treatment_name'))) 
   treatment_notes = forms.CharField(required=False,max_length=250,help_text="Search by treatment details ",label=mark_safe('<strong> Treatment Notes </strong>'))




class form_scheduling(forms.ModelForm):
      class Meta:
        model = scheduling
        fields = ['date_scheduled',
                  'time_duration' ]   
      def __init__(self, *args, **kwargs): 
         super().__init__(*args, **kwargs)
         self.helper = FormHelper(self)
         self.helper.form_method = 'Post' 
         self.helper.add_input(Submit('submit', 'Save'))
         self.as_p = True  
         self.fields['date_scheduled'].initial = datetime.now().strftime("%d/%m/%Y %I:%M:00") # datetime.now()
         self.fields['time_duration'].initial =  '00:30:00' #datetime.now().strftime("%I:%M:00") 

      #time_duration = forms.TimeField(required=True, help_text='Enter Time in Railway Format hh:mm:ss ',label='Schedule Time'  )
      #date_scheduled = forms.DateField(required=True, help_text='Enter date for scheduling ',label='Schedule Date' , widget= forms.DateInput( attrs={'type': 'date', 'max':datetime.now()})) 

 
        
class form_scheduling_search(forms.Form):
   def __init__(self, *args, **kwargs): 
      super().__init__(*args, **kwargs)
      self.helper = FormHelper(self)
      self.helper.form_method = 'GET' 
      self.helper.add_input(Submit('submit', 'Search'))
      self.as_p = True    

      
   class Meta:
        model = scheduling
        fields = ['date_scheduled',
                  'time_duration']
        
   date_scheduled = forms.DateField(required=False, help_text="Search by scheduling date ",label=mark_safe('<strong> Date Scheduled </strong>'), widget= forms.DateInput(attrs={'type': 'date','max':datetime.now().date()})) 

