from django import template
from pyquery import PyQuery

register = template.Library()

@register.filter
def patho_short(html):
    doc = PyQuery(html)
    report_text = doc('#rReportTab_lsvReportBody_ctrl0_ctl00_TextBox2').text().strip()
    if not report_text:
        # report_text = doc('#ContentContainer').text().strip()
        # report_text = doc('#rReportTab_lsvReportBody_ctrl0_ctl00_tblDisplay').text().strip()
        # report_text = doc(
        #     '#rReportTab_lsvReportBody_ctrl0_ctl00_tblDisplay > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1)'
        #     ).text().strip()
        report_text = doc('#rReportTab_lsvReportBody_ctrl0_ctl00_lblResult').text().strip()
    return report_text

@register.filter
def patho_long(html):
    doc = PyQuery(html)
    report_text = doc('#rReportTab_lsvReportBody_ctrl0_ctl00_tblDisplay').text().strip()
    return report_text

@register.filter
def DOB(html):
    doc = PyQuery(html)
    report_text = doc('.patientInfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(6)').text().strip()
    return report_text
