def get_dots_case_json(casedoc, anchor_date=None):
    """
    Return JSON-ready array of the DOTS block for given patient.
    Pulling properties from PATIENT document.
    Patient document trumps casedoc in this use case.
    """

    if anchor_date is None:
        anchor_date = datetime.now(tz=timezone(settings.TIME_ZONE))
    enddate = anchor_date
    ret = {
        'regimens': [
            # non art is 0
            int(getattr(casedoc, CASE_NONART_REGIMEN_PROP, None) or 0),
            # art is 1
            int(getattr(casedoc, CASE_ART_REGIMEN_PROP, None) or 0),
        ],
        'regimen_labels': [
            list(casedoc.nonart_labels),
            list(casedoc.art_labels)
        ],
        'days': [],
        # dmyung - hack to have query_observations timezone
        # be relative specific to the eastern seaboard
        'anchor': anchor_date.strftime("%d %b %Y"),
    }

    observations = query_observations(
        casedoc._id, enddate-timedelta(days=DOT_DAYS_INTERVAL), enddate)
    for delta in range(DOT_DAYS_INTERVAL):
        obs_date = enddate - timedelta(days=delta)
        day_arr = filter_obs_for_day(obs_date.date(), observations)
        day_data = DOTDay.merge_from_observations(day_arr)
        ret['days'].append(day_data.to_case_json(casedoc, ret['regimen_labels']))

    ret['days'].reverse()
    return ret
dataset/ETHPy150Open dimagi/commcare-hq/custom/_legacy/pact/dot_data.py/get_dots_case_json/original