{% extends "base.html" %}

{% block head %}
<script type="text/javascript" src="/site_media/js/date.js"></script>
<script type="text/javascript">

dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.form.FilteringSelect");
dojo.require('dojo.cookie');
dojo.require("dojox.data.QueryReadStore");


function onChangeDiseaseStage() {
    if (document.treatmentForm.disease_stage.value == 5)
        document.treatmentForm.primary_tumor_site.disabled = false;
    else {
        document.treatmentForm.primary_tumor_site.value = "";
        document.treatmentForm.primary_tumor_site.disabled = true;
    }
}

function onLoadBody() {
    if (document.getElementById('id_patient').value == ""
      ||document.getElementById('id_patient').value == "None")
        document.getElementById('id_patient').value = dojo.cookie("patient");
    if (document.getElementById("id_date_started").value == "") {
        document.getElementById("id_date_started").value = Date.today().addWeeks(1).toString("yy/MM/dd");
        document.treatmentForm.date_started.value = Date.today().addWeeks(1).toString("yyyy-MM-dd");
    }
    if (document.getElementById("id_date_completed").value == "") {
        document.getElementById("id_date_completed").value = Date.today().addWeeks(2).toString("yy/MM/dd");
        document.treatmentForm.date_completed.value = Date.today().addWeeks(2).toString("yyyy-MM-dd");
    }

    document.treatmentForm.disease_stage.onchange = onChangeDiseaseStage;
    onChangeDiseaseStage();
}

</script>
{% endblock %}

{% block title %}
Treatment Form
{% endblock %}

{% block content %}
{% if object %}
<h2>Update treatment</h2>
{% else %}
<h2>Create treatment</h2>
{% endif %}

{% if form.has_errors %}
<h2>Please correct the following error{{ form.errors|pluralize }}:</h2>
{% endif %}

<p>{{object.patient.name}}</p>
<form action="." class="cssform" method="POST" name="treatmentForm">  {% csrf_token %}

    <input type="text" readonly="readonly" id="id_id" name="id" value={{object.id}}> 
    <input type="text" readonly="readonly" id="id_patient" name="patient" value={{object.patient_id}}>
    <p><label for="id_bed">病床號</label>
       {{ form.bed }}
       {% if form.bed.errors %}{{ form.bed.errors }}{% endif %}</p>
        <div dojoType="dojox.data.QueryReadStore" jsId="icdStore"
            url="/get/icd9cm/"
            requestMethod="get"></div>
    <p><label for="id_icd9">ICD9診斷</label>
        <input dojoType="dijit.form.FilteringSelect"
            id="id_icd9"
            name="icd9"
            style="width: 320px;"
            value="{{object.icd9.code}}"
            autoComplete="false"
            searchAttr="name"
            store="icdStore"
            onChange="" />
        {% if form.icd9.errors %}*** {{ form.icd9.errors|join:", " }}{% endif %}</p>
    <p><label for="id_other_diagnosis">其他診斷</label>
       {{ form.other_diagnosis }}
       {% if form.other_diagnosis.errors %}{{ form.other_diagnosis.errors }}{% endif %}</p>
    <p><label for="id_date_started">Date started</label>
       <input type="text" id="id_date_started" name="date_started" value="{{object.date_started}}"
            dojoType="dijit.form.DateTextBox"
            required="true" />
       {% if form.date_started.errors %}{{ form.date_started.errors }}{% endif %}</p>
    <p><label for="id_date_completed">Date completed</label>
       <input type="text" id="id_date_completed" name="date_completed" value="{{object.date_completed}}"
            dojoType="dijit.form.DateTextBox"
            required="true" />
       {% if form.date_completed.errors %}{{ form.date_completed.errors }}{% endif %}</p>
    <p><label for="id_tracking_mode">Tracking Mode</label>
       {{ form.tracking_mode }}
       {% if form.tracking_mode.errors %}{{ form.tracking_mode.errors }}{% endif %}</p>
    <p><label for="id_referral">轉介醫師</label>
       {{ form.referral }}
       {% if form.referral.errors %}{{ form.referral.errors }}{% endif %}</p>
    <p><label for="id_oncologist">Oncologist</label>
       {{ form.oncologist }}
       {% if form.oncologist.errors %}{{ form.oncologist.errors }}{% endif %}</p>
    <p><label for="id_surgeon">Surgeon</label>
       {{ form.surgeon }}
       {% if form.surgeon.errors %}{{ form.surgeon.errors }}{% endif %}</p>
    <p><label for="id_accounting">記帳別</label>
       {{ form.accounting }}
       {% if form.accounting.errors %}{{ form.accounting.errors }}{% endif %}</p>
    <p><label for="id_karnofsky_score">Karnofsky Score</label>
       {{ form.karnofsky_score }}
       {% if form.karnofsky_score.errors %}{{ form.karnofsky_score.errors }}{% endif %}</p>
    <p><label for="id_disease_stage">Disease Stage</label>
       {{ form.disease_stage }}
       {% if form.disease_stage.errors %}{{ form.disease_stage.errors }}{% endif %}</p>
    <p><label for="id_primary_tumor_site">Primary Tumor Site</label>
       {{ form.primary_tumor_site }}
       {% if form.primary_tumor_site.errors %}{{ form.primary_tumor_site.errors }}{% endif %}</p>
    <p><label for="id_input">已</label>
       {{ form.input }}
       {% if form.input.errors %}{{ form.input.errors }}{% endif %}</p>
    <p><label for="id_output">待</label>
       {{ form.output }}
       {% if form.output.errors %}{{ form.output.errors }}{% endif %}</p>
    <p><label for="id_complications">併發症</label>
       {{ form.complications }}
       {% if form.complications.errors %}{{ form.complications.errors }}{% endif %}</p>
    <p><label for="id_chief_complaint">Chief complaint</label>
       {{ form.chief_complaint }}
       {% if form.chief_complaint.errors %}{{ form.chief_complaint.errors }}{% endif %}</p>
    <p><label for="id_memo">Memo</label>
       {{ form.memo }}
       {% if form.memo.errors %}{{ form.memo.errors }}{% endif %}</p>
    <div style="margin-left: 150px;">
        <input type="submit" /> <input type="reset" />
    </div>
    <a href='/patient/detail/'>Return to patient</a>
</form>

<!--
This is a lifesaver when debugging!
<p> {{ form.error_dict }} </p>
-->

{% endblock %}
