import datetime
from haystack import indexes
from registry.models import OPNote, PathologyReport


class OPNoteIndex(indexes.SearchIndex, indexes.Indexable):

    text       = indexes.CharField(document=True, use_template=True)    

    PatChartNo = indexes.CharField(model_attr='PatChartNo')
    KeyCode    = indexes.CharField(model_attr='KeyCode')
    KeyName    = indexes.CharField(model_attr='KeyName', null=True)
    department = indexes.CharField(model_attr='department', null=True)
    date       = indexes.DateTimeField(model_attr='date', null=True)

    def get_model(self):
        return OPNote

    def get_updated_field(self):
        return "date"

    # def index_queryset(self, using=None):
    #     """Used when the entire index for model is updated."""
    #     return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())


class PathologyReportIndex(indexes.SearchIndex, indexes.Indexable):

    text       = indexes.CharField(document=True, use_template=True)    

    ChartNo         = indexes.IntegerField (model_attr='ChartNo',         null=True)
    ReportKey       = indexes.CharField    (model_attr='ReportKey',       null=True)
    ReportCode      = indexes.CharField    (model_attr='ReportCode',      null=True)
    PersonID        = indexes.CharField    (model_attr='PersonID',        null=True)

    PathCode        = indexes.CharField    (model_attr='PathCode') 
    SpecimenGetDate = indexes.DateField    (model_attr='SpecimenGetDate', null=True)
    ReportDate      = indexes.DateTimeField(model_attr='ReportDate',      null=True)
    # url             = models.TextField(                null=True)
    # html            = models.TextField(                null=True)

    def get_model(self):
        return PathologyReport

    def get_updated_field(self):
        return "date"

    # def index_queryset(self, using=None):
    #     """Used when the entire index for model is updated."""
    #     return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())