from django import forms
from .models import condition,diagnose,disease_details
from baseapp.models import disease
from crispy_forms.helper import FormHelper
from django.utils.safestring import mark_safe
from crispy_forms.layout import Submit,Layout, ButtonHolder,HTML, Reset,Button
from django.urls import reverse_lazy
from datetime import datetime

class form_diagnose(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 = diagnose
        fields = ['diag',
                'diag_accept',
                'order',
                'certainty',
                'status',
                'diag_notes',
               ]
        
class form_diagnose_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        

        
   diag = forms.CharField(required=False,max_length=75, help_text='Search by diagnosis',label=mark_safe('<strong> Diagnosis </strong>')) 
   order = forms.ChoiceField(required=False,help_text='Search by order',label=mark_safe('<strong> Order </strong>'),choices=  diagnose.list_order)
   certainty= forms.ChoiceField(required=False,help_text='Search by certainty',label=mark_safe('<strong> Certainty </strong>'),choices=diagnose.list_certainty)

   diag_notes = forms.CharField(required=False,max_length=50,help_text='Search by diagnosis notes',label=mark_safe('<strong> Diagnosis Notes </strong>'))



class form_condition(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 = condition
        fields = ['condi',
                'status',                
                'date_identified',
                'action',
                'condi_notes',
               ]
        
class form_condition_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      
   
   condi = forms.CharField(required=False,max_length=75, help_text="Search by condition ",label=mark_safe('<strong> Condition </strong>')) 
   status = forms.ChoiceField(required=False,help_text="Search by status ",label=mark_safe('<strong> Status </strong>'),choices=[(0,'Not Selected')] +list(condition.objects.all().values_list('status','status')))
   date_identified =  forms.DateField(required=False, help_text="Search by date ",label=mark_safe('<strong> Date identified </strong>'), widget= forms.DateInput( attrs={'type': 'date', 'max':datetime.now()})) 
   #action = forms.ChoiceField(required=False,help_text="Search by action ",label=mark_safe('<strong> Action </strong>'),choices=list(condition.objects.all().values_list('action','action')))
   #action_notes = forms.CharField(required=False,max_length=50,help_text="Search by notes ",label=mark_safe('<strong> Action Notes </strong>'))


class form_disease_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 = disease_details

        fields = ['fk_disease',
                'disease_notes',
                'status'
               ]

class form_disease_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_layout(Layout.)
      self.helper.add_input(Submit('submit', 'Search'))
      #self.helper.add_input(Button('cancel', 'Cancel', css_class='btn-danger', onclick="window.history.back()"))
      self.as_p = True        


   fk_disease = forms.ChoiceField(required=False,help_text="Search by disease ",label=mark_safe('<strong> Disease </strong>'), choices=[(0,'Not Selected')] +list(disease.objects.all().values_list('id','disease_name'))) 
   disease_notes = forms.CharField(required=False,max_length=50,help_text="Search by disease details ",label=mark_safe('<strong> Disease Notes </strong>'))
