{# clinician_response.html #}
{% extends "base.html" %}

{% comment %}
    template parameters:
        clinician_involvement_requested: bool
        clinician_involvement_required_unknown: bool
        clinician_involvement_required_yellow: bool
        consent_mode: ConsentMode
        contact_request: ContactRequest
        extra_form: bool
        Leaflet: Leaflet class
        option_c_available: bool
        option_r_available: bool
        patient_lookup: PatientLookup
        permitted_to_contact_discharged_patients_for_n_days: int
        settings: Django settings object
        study: Study
        unknown_consent_mode: bool
{% endcomment %}

{% block extrahead %}
    <script>
        {% include "clinician_response.js" with initial_response=clinician_response.response %}
        // passed through: option_c_available, option_r_available
    </script>
{% endblock %}
{% block onload %}onload="startup()"{% endblock %}
{% block mainsiteheader %}{% endblock %}

{% block content %}

    {# <h1 id="debug"></h1> #}

    <p>Dear {{ patient_lookup.clinician_salutation }},</p>

    <p>Based on anonymised information in the CPFT Research Database, a
    research team has identified the following patient of yours as
    potentially eligible for a study that they are conducting:</p>

    {% include "patient_table.html" with patient_lookup=patient_lookup consent_mode=consent_mode verbose=True %}

    <p>The study is:</p>

    {% include 'study_table.html' with study=study contact_request=contact_request to_clinician=True offer_details=True offer_clinician_form=True %}

    <p>At this stage, the researchers do not know the patient’s identity.
    They have identified the patient based on a search of the anonymised
    CPFT Research Database. Patient information may only be disclosed to
    the researchers with the patient’s consent.</p>

    {% if clinician_involvement_requested %}

        <b>The researchers have indicated that they would like you, as the
        patient’s clinician, to consider this request.</b>
        This may be because they would need clinical information from you
        to establish whether the patient is indeed eligible to participate,
        or because they would need information from you as part of the
        study itself.

    {% elif clinician_involvement_required_yellow %}

        The researchers would like the patient’s permission to be
        contacted.
        <b>This patient has actively chosen that all approaches by research
        teams should be on a case-by-case
        basis via the primary clinical team</b> (“approach mode YELLOW”),
        and so this request has been passed along to you.

    {% elif clinician_involvement_required_unknown %}

        The researchers would like the patient’s permission to be
        contacted.
        <b>This patient has never been asked their preference regarding
        direct approaches by research teams,</b>
        and so this request has been passed along to you.
        <b>We would like to know the patient’s preference about being
        contacted for this study,
        but also about future studies in general.</b>

    {% else %}

        <div class="important">Bug! Clinician involvement not specified. Please contact the CRATE developer.</div>

    {% endif %}

    <p>We would be very grateful if you would do the following:</p>

    <h2>Check…</h2>

    {% if patient_lookup.is_under_16 %}
        <div class="important">
            <b>Under 16!</b>
            This patient is under 16. Please follow the procedure
            outlined in the leaflet
            “<a href="{% url 'leaflet' Leaflet.CPFT_CLINRES %}" target="_blank"><i>Information for clinicians and
            researchers about the CPFT research database</i></a>”.
        </div>
    {% else %}
        {# MCA doesn't apply to under-16s, so we don't need both. #}
        <div>
            <b>Lacks capacity?</b>
            If the patient lacks capacity to decide about research participation,
            please follow the procedure outlined in the leaflet
            “<a href="{% url 'leaflet' Leaflet.CPFT_CLINRES %}" target="_blank"><i>Information for clinicians and
            researchers about the CPFT research database</i></a>”.
        </div>
    {% endif %}

    {% include "discharged_phrase.html" %}

    <h2>Read…</h2>

    <div>
        <span class="action">Please examine the
        <a href="{% url 'study_details' study.id %}" target="_blank">study details</a>.</span>
        (You don’t have to consider detailed inclusion/exclusion
        criteria; that’s the researcher’s job. If you think the patient
        <i>might</i> be suitable, that’s good enough.)
    </div>

    <h2>Choose.</h2>

    <p class="action">
        <b>Please select an option below, and follow the
        instructions that appear.</b>
    </p>

    <br>
    <div class="highlight">
        <form action="{% url 'clinician_response' clinician_response.id %}" method="POST">

            {% csrf_token %}
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}

            {# Manual control of radio choice; see https://docs.djangoproject.com/en/1.8/ref/forms/widgets/ #}
            <label id="optionR_radio" onclick="showR();">
                <input type="radio"
                       name="response"
                       value="{{ ClinicianResponse.RESPONSE_R }}"
                       {% if clinician_response.response == ClinicianResponse.RESPONSE_R %}checked{% endif %}>
                <b>R. The patient may be eligible for this study.
                Do the work for me.</b> I authorize the Research
                Database Manager to send the patient a letter on my
                behalf, signed <i>pp</i> me, passing on this request.
                <br>
            </label>

            <label onclick="showA();">
                <input type="radio"
                       name="response"
                       value="{{ ClinicianResponse.RESPONSE_A }}"
                       {% if clinician_response.response == ClinicianResponse.RESPONSE_A %}checked{% endif %}>
                <b>A. The patient may be eligible for this study. I
                shall pass this request along to the patient.</b>
                <br>
            </label>

            <label onclick="showB();">
                <input type="radio"
                       name="response"
                       value="{{ ClinicianResponse.RESPONSE_B }}"
                       {% if clinician_response.response == ClinicianResponse.RESPONSE_B %}checked{% endif %}>
                <b>B. As the patient’s clinician, I decline to pass
                this request on to the patient.</b>
                <br>
            </label>

            {# The appearance of option C is conditional on option_c_available; see clinician_response.js #}
            <label id="optionC_radio" onclick="showC();">
                <input type="radio"
                       name="response"
                       value="{{ ClinicianResponse.RESPONSE_C }}"
                       {% if clinician_response.response == ClinicianResponse.RESPONSE_C %}checked{% endif %}>
                <b>C. The patient is ineligible for this study.</b>
                <br>
            </label>

            <label onclick="showD();">
                <input type="radio" name="response"
                       value="{{ ClinicianResponse.RESPONSE_D }}"
                       {% if clinician_response.response == ClinicianResponse.RESPONSE_D %}checked{% endif %}>
                <b>D. The patient is Dead, Discharged, or their Details
                are Defunct, preventing contact.</b>
                <br>
            </label>

            <div id="optionR">
                <hr>
                <div class="indent">
                    <div class="action">Thank you. Please confirm your name below and click
                    “Submit”. We’ll do the rest.</div>
                </div>
            </div>

            <div id="optionA">
                <hr>
                <div class="indent">
                    <p>Thank you.</p>

                    <p class="action"><b>Please print out the
                    <a href="{% url 'clinician_pack' clinician_response.id clinician_response.token %}"
                        target="_blank">CUSTOMIZED INFORMATION PACK</a>.
                        </b></p>
                    <p>If possible, please use a double-sided colour A4 printer.</p>

                    <p class="action">Now choose whether you prefer to
                    discuss this with the patient in person, or pass on the
                    request by letter. A letter has been drafted for your
                    signature (it’s in the pack) in case you prefer the
                    latter.</p>

                    <p class="important">If you prefer to discuss this with
                    the patient <b>in person:</b></p>

                    <ol>
                        <li>Please show the materials to the patient.</li>

                        {% if unknown_consent_mode %}
                            <li>Please explain to that all CPFT patients are asked their views
                            about being contacted in the future by research teams about taking
                            part in research. In addition, one particular research team is
                            already interested in patients like them, and we would like to know
                            whether they are willing for that research team to be given their
                            details, so that researchers can talk to them about taking part in
                            research. They are <i>not</i> being asked for consent to
                            participate, just for consent to being sent information by the
                            researchers and for the researchers to see their CPFT records (to
                            check they’re suitable for the study).</li>
                        {% endif %}

                        <li>Please ask them to choose (consent or refuse) <b>about this
                        study</b> on their personalized form and sign it.</li>

                        {% if extra_form %}
                            <li>If they consent, please complete the researcher’s form as
                            best you can.</li>
                        {% endif %}

                        {% if unknown_consent_mode %}
                            <li>Please ask them to choose (GREEN, YELLOW, or RED) <b>about
                            studies in general</b> on the other decision form, fill in their
                            details, and sign it.</li>
                        {% endif %}

                        <li>
                            Return the
                            form{% if extra_form or unknown_consent_mode %}s{% endif %}
                            to {{ settings.RDBM_ADDRESS|join:", " }}.
                        </li>
                    </ol>

                    <div class="important">If you prefer to pass the
                    request to the patient <b>by letter:</b></div>

                    <ol>
                        <li>Please sign the draft letter from you to the patient.</li>
                        
                        {% if contact_request.is_extra_form %}
                            <li>Please fill in the researcher’s “clinician” form as best you can.</li>
                        {% endif %}

                        <li>Please send (or ask your secretary to send) all materials to the
                        patient. Include an envelope pre-addressed to
                        {{ settings.RDBM_ADDRESS|join:", " }} (if you’d
                        like stocks of pre-printed envelopes, please e-mail
                        <a href="mailto:{{ settings.RDBM_EMAIL }}">{{ settings.RDBM_EMAIL }}</a>).</li>
                    </ol>
                    
                    <div>Confirm your name below and click “Submit”. Thank you!</div>
                </div>
            </div>

            <div id="optionB">
                <hr>
                <div class="indent">
                    <p>Thank you.</p>

                    <p>Normally, the decision about being contacted for
                    research studies should be the patient’s. However, all
                    approaches such as this one, via the clinical team, are
                    subject to your “veto”: as the patient’s clinician, you
                    may decline to pass the request on to the patient. If
                    you choose this option, no information about the
                    patient will be given to the research team. Please only
                    choose this option in exceptional circumstances, as it
                    reduces the patient’s ability to choose. Exceptional
                    circumstances might include those in which, in your
                    judgement, an offer to the patient to participate in
                    research might cause extreme distress, or that the
                    patient currently lacks the capacity to make a decision
                    about participation (and the study does not concern
                    such patients specifically). Your views on the study
                    itself should not prompt you to select this option; all
                    studies supported by CPFT have ethical approval and we
                    seek to promote patient choice about research
                    participation. Please give a reason for your choice,
                    so that we may audit use of this option.</p>

                    <div class="fieldWrapper">
                        <b>{{ form.veto_reason.label_tag }}</b>
                        {{ form.veto_reason }}
                        {{ form.veto_reason.errors }}
                    </div>

                    <div class="action">Now, please confirm your name below and
                    click “Submit”. Thank you!</div>
                </div>
            </div>

            <div id="optionC">
                <hr>
                <div class="indent">
                    <p>Thank you.</p>
                    <p>
                        If you can, please supply a brief reason. This will
                        not be passed to the researchers but will help us
                        to monitor the accuracy of researchers’ requests
                        from the Research Database.
                    </p>

                    <div class="fieldWrapper">
                        <b>{{ form.ineligible_reason.label_tag }}</b>
                        {{ form.ineligible_reason }}
                        {{ form.ineligible_reason.errors }}
                    </div>

                    <div class="action">>Now, please confirm your name below
                    and click “Submit”. Thank you!</div>
                </div>
            </div>

            <div id="optionD">
                <hr>
                <div class="indent">
                    <p>Thank you.</p>
                    <p>
                        If you can, please give further details. This will
                        not be passed to the researchers but will help us
                        to monitor the accuracy of researchers’ requests
                        from the Research Database.
                    </p>

                    <div class="fieldWrapper">
                        <b>{{ form.pt_uncontactable_reason.label_tag }}</b>
                        {{ form.pt_uncontactable_reason }}
                        {{ form.pt_uncontactable_reason.errors }}
                    </div>

                    <div class="action">Now, please confirm your name below and
                    click “Submit”. Thank you!</div>
                </div>
            </div>

            <div id="submit" class="indent">
                <div class="fieldWrapper">
                    <b>{{ form.clinician_confirm_name.label_tag }}</b>
                    {{ form.clinician_confirm_name }}
                    {{ form.clinician_confirm_name.errors }}
                </div>

                <input type="submit" value="Submit">

            </div>
        </form>
    </div>

    <p>If you have any queries, please telephone the Research Database
    Manager on {{ settings.RDBM_TELEPHONE }}.</p>

    <p>Thank you for your help!<p>

    {% include "clinician_notes.html" with settings=settings Leaflet=Leaflet %}

    {# {% include 'show_form_errors.html' with form=form %} #}

{% endblock %}
