<%--
  ~ This file is part of DebGen Biobank Software developed by ASTRID Research.
  ~ All rights reserved. Reproduction, modification, use or disclosure
  ~ to third parties without express authority is forbidden.
  ~
  ~ Copyright ASTRID Research Inc., Hungary, 2009-2011.
  ~
  ~ ASTRID Research
  ~ Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
  ~ Phone: +36-52-533-173        Fax: +36-52-533-174
  ~ Web: http://www.astrid.hu    E-mail: info@astrid.hu
  ~
  ~ Project name: DebGen Biobank Software project.
  ~ URLS:
  ~ Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
  --%>

<%--
    Document   : createpatient
    Created on : Dec 14, 2009, 10:40:14 AM
    Author     : inagy
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="/WEB-INF/dateformat.tld" prefix="da" %>
<script type="text/javascript" src="javascript/telepulesek.js"></script>
<link type="text/css" href="stylesheet/redmond/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<%--<script type="text/javascript" src="javascript/jquery-1.3.2.js"></script>--%>
<script type="text/javascript" src="javascript/ui.core.js"></script>
<script type="text/javascript" src="javascript/ui.datepicker.js"></script>
<!--link rel="stylesheet" type="text/css" href="stylesheet/jquery.autocomplete.css" />
<script type="text/javascript" src="http://www.google.com/jsapi"></script-->
<script type="text/javascript">



        <c:if test="${user.languageCode eq 'HU'}">
        /* Hungarian initialisation for the jQuery UI date picker plugin. */
    /* Written by Istvan Karaszi (jquerycalendar@spam.raszi.hu). */
    jQuery(function($){
        $.datepicker.regional['hu'] = {
            closeText: 'bezárás',
            prevText: '&laquo; vissza',
            nextText: 'előre &raquo;',
            currentText: 'ma',
            monthNames: ['Január', 'Február', 'Március', 'Április', 'Május', 'Június',
                'Július', 'Augusztus', 'Szeptember', 'Október', 'November', 'December'],
            monthNamesShort: ['Jan', 'Feb', 'Már', 'Ápr', 'Máj', 'Jún',
                'Júl', 'Aug', 'Szep', 'Okt', 'Nov', 'Dec'],
            dayNames: ['Vasárnap', 'Hétfö', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat'],
            dayNamesMin: ['Vas', 'Hét', 'Ked', 'Sze', 'Csü', 'Pén', 'Szo'],
            dayNamesShort: ['V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'],
            dateFormat: 'yy. mm. dd.', firstDay: 1,
            isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['hu']);
    });

        </c:if>

        //google.load("jquery", "1");
    $(document).ready(function(){
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            maxDate: '+1d',
            yearRange: '1900:2500'
                <c:if test="${not empty patient}">, defaultDate: new Date( ${patient.dateOfBirth.time} )</c:if>

            });
        $("#datepicker").datepicker('option', {dateFormat: 'yy. mm. dd.'});
        
        /*$('#autoTaj').ajaxForm({
            dataType:  'json',
            // success identifies the function to invoke when the server response
            // has been received
            success:   fillForm
        });

        $('#autoName').ajaxForm({
            dataType:  'json',
            // success identifies the function to invoke when the server response
            // has been received
            success:   showTajs
        });*/

            <c:if test="${empty patient.id}">
            searchName();
            </c:if>
            autocompleteOff();
    });

        <c:if test="${user.dataRecorder}">

        function showTajs(data) {
        if (data != null && data.size > 0) {
            // 'data' is the json object returned from the server
            var tajlist = document.getElementById('tajList');
            for(i = 0; i < data.size; i++) {
                tajlist.options[i+1] = new Option(data.list[i].text, data.list[i].taj, false, false);
            }
            tajlist.size = tajlist.options.length + 1;
            document.getElementById('tajListDiv').style.display = 'block';
        }
        renewSessionAjax();
    }

    /**
     * transfer data from taj list to taj and search
     */
    function tajListChanged() {
        if (document.getElementById('tajList').value != 0) {
            document.getElementById('tajNumber').value = document.getElementById('tajList').value;
            searchTaj();
        } else {
            resetForm();
        }
    }
        
    function fillForm(data) {
        if (data != null && data.id > 0) {
            // 'data' is the json object returned from the server
            document.getElementById('id').value = data.id;
            if (data.research == 'true' && data.diagnostical == 'true') {
                document.getElementById('patientType').value = 3;
                document.getElementById('patientType').onchange();
            } else if (data.research == 'false' && data.diagnostical == 'true') {
                document.getElementById('patientType').value = 2;
                document.getElementById('patientType').onchange();
            } else {
                document.getElementById('patientType').value = 1;
                document.getElementById('patientType').onchange();
            }
        

            document.getElementById('patientCode').value = data.patientCode;
            document.getElementById('patientCodeDiv').innerHTML = data.patientCode;

            document.getElementById('datepicker').value = data.dateOfBirth;
            $("#datepicker").datepicker('option', {defaultDate: new Date(data.dateOfBirthForJS)});
            
            
            if (data.diagnostical == 'true') {
                document.getElementById('personalId').value = data.personalIdentity.id;
                document.getElementById('patientName').value = data.personalIdentity.patientName;
                document.getElementById('maidenName').value = data.personalIdentity.maidenName;
                document.getElementById('irsz').value = data.personalIdentity.zipCode;
                document.getElementById('telepules').value = data.personalIdentity.city;
                document.getElementById('address').value = data.personalIdentity.address;
                document.getElementById('mothersName').value = data.personalIdentity.mothersName;
                document.getElementById('tajNumber').value = data.personalIdentity.medicatId;
                //document.getElementById('logNumber').value = data.personalIdentity.logNumber;
            } else {
                document.getElementById('personalId').value = "";
                document.getElementById('patientName').value = "";
                document.getElementById('maidenName').value = "";
                document.getElementById('irsz').value = "";
                document.getElementById('telepules').value = "";
                document.getElementById('address').value = "";
                document.getElementById('mothersName').value = "";
                document.getElementById('tajNumber').value = "";
                //document.getElementById('logNumber').value = "";
            }
            
            if (data.research == 'true') {
                document.getElementById('anonId').value = data.anonymousData.id;
                document.getElementById('monogr').value = data.anonymousData.monogram;
            } else {
                document.getElementById('anonId').value = "";
                document.getElementById('monogr').value = "";
            }
        }
        renewSessionAjax();
    }

    function resetForm() {
        document.getElementById('id').value = "";
        document.getElementById('patientCode').value = document.getElementById('patientCodeOld').value;
        document.getElementById('patientCodeDiv').innerHTML = document.getElementById('patientCodeOld').value;
        document.getElementById('datepicker').value = "";
        $("#datepicker").datepicker('option', {defaultDate: new Date()});
        document.getElementById('personalId').value = "";
        document.getElementById('maidenName').value = "";
        document.getElementById('irsz').value = "";
        document.getElementById('telepules').value = "";
        document.getElementById('address').value = "";
        document.getElementById('mothersName').value = "";
        document.getElementById('tajNumber').value = "";
        //document.getElementById('logNumber').value = "";
        document.getElementById('anonId').value = "";
        document.getElementById('monogr').value = "";
    }

        </c:if>
        setWebTitle('<fmt:message key="BIOBANK_BETEG" />');

        <c:if test="${user.dataRecorder}">
        /**
         * Searchs for a patient
         */
    function searchTaj() {
        //if (document.getElementById('tajNumber').value.length == 9) {
            //document.getElementById('name').value = document.getElementById('patientName').value;
            document.getElementById('taj').value = document.getElementById('tajNumber').value;
            //document.getElementById('autoTaj').submit();
            //document.getElementById('sendTaj').click();

            $('#autoTaj').ajaxSubmit({
                dataType:  'json',
                // success identifies the function to invoke when the server response
                // has been received
                success:   fillForm
            });

            // !!! Important !!!
            // always return false to prevent standard browser submit and page navigation
            return false;
       // }
    }

    function searchName() {
        if (document.getElementById('patientName').value.length > 3) {
            document.getElementById('name').value = document.getElementById('patientName').value;
            //document.getElementById('autoName').submit();
            //document.getElementById('sendName').click();

            $('#autoName').ajaxSubmit({
                dataType:  'json',
                // success identifies the function to invoke when the server response
                // has been received
                success:   showTajs
            });
        }
        
    }
        </c:if>

        function showHide(value) {
        if (value == 1) {
            //       document.getElementById('head').className = 'anonympatientheader';
            //       document.getElementById('line').className = 'anonympatientline';
            document.getElementById('anonymous').style.display = 'block';
            document.getElementById('monogram').style.display = 'block';
            document.getElementById('named').style.display = 'none';
        }
        if (value == 2) {
            //       document.getElementById('head').className = 'patientheader';
            //       document.getElementById('line').className = 'patientline';
            document.getElementById('anonymous').style.display = 'none';
            document.getElementById('monogram').style.display = 'none';
            document.getElementById('named').style.display = 'block';
        }
        if (value == 3) {
            //       document.getElementById('head').className = 'patientheader';
            //       document.getElementById('line').className = 'patientline';
            document.getElementById('anonymous').style.display = 'block';
            document.getElementById('monogram').style.display = 'none';
            document.getElementById('named').style.display = 'block';
        }
    }
</script>
<script type="text/javascript" src="javascript/jquery.autocomplete.js"></script>
<script type="text/javascript" src="javascript/jquery.form.js"></script>
<div class="window500">
    <div class="title"><fmt:message key="BIOBANK_BETEG_ADATAI" /></div>
    <div class="content">
        <div style="padding: 10px;">
            <table border="0" cellspacing="10" cellpadding="5">
                <tbody>
                    <tr>
                        <td id="head" class="patientheader" ></td>
                        <td><fmt:message key="BIOBANK_BETEG" /></td>
                </tr>
                </tbody>
            </table>
            <div id="line" style="width: 476px;" class="patientline">
                <fmt:message key="BIOBANK_BETEG_ADATAI" />
            </div>
            <form id="autoTaj" name="autoTaj" action="autofillfromtaj.html" method="POST">
                <input id="taj" name="tajNumber" type="hidden" value="" />
                <input id="sendTaj" type="submit" name="keres" style="display: none; visibility: hidden;" value="keres" />
            </form>
            <form id="autoName" name="autoName" action="autofillfromname.html" method="POST">
                <input id="name" name="patientName" type="hidden" value="" />
                <input id="sendName" type="submit" name="keres" style="display: none; visibility: hidden;" value="keres" />
            </form>
            <form name="patient" action="savepatient.html" method="POST">
                <input id="id" type="hidden" name="id" value="${patient.id}">

                <%@ include file="../showembedederror.jsp" %>
                <div id="userdiv">
                    <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">
                        <tbody>
                            <tr>
                                <td style="width: 120px;"><fmt:message key="patientCode" />:</td>
                        <td style="width: 340px;">
                        <c:if test="${not empty patient.id or not empty patient.patientCode}">
                            <c:if test="${empty patient.id}">
                                <div id="patientCodeDiv" >${patient.patientCode}</div>
                            </c:if>
                            <c:if test="${not empty patient.id}">
                                <div id="patientCodeDiv" ><a href="showpatient.html?patient=${patient.id}">${patient.patientCode}</a></div>
                            </c:if>
                            <input id="patientCode" class="input" type="hidden" name="patientCode" value="${patient.patientCode}">
                            <input id="patientCodeOld" class="input" type="hidden" name="patientCodeOld" value="${patientCode}">
                        </c:if>
                        <c:if test="${empty patient.id and empty patient.patientCode}">
                            <div id="patientCodeDiv" >${patientCode}</div>
                            <input id="patientCode" class="input" type="hidden" name="patientCode" value="${patientCode}">
                            <input id="patientCodeOld" class="input" type="hidden" name="patientCodeOld" value="${patientCode}">
                        </c:if>
                        </td>
                        </tr>
                        <tr>
                            <td style="width: 120px;"><fmt:message key="BEVITEL_MODJA" />:</td>
                        <td style="width: 340px;">
                        <c:if test="${user.dataRecorder or empty patient}">
                            <select id="patientType" class="styled" id="patientType" name="patientType" onclick="return showHide(document.getElementById('patientType').value);">
                                <option value="1" ${not empty patient and not patient.named ? 'selected' : ''}><fmt:message key="NEV_NELKUL" /></option>
                                <c:if test="${user.dataRecorder}">
                                    <option value="2" ${empty patient or not patient.anonymous ? 'selected' : ''}><fmt:message key="NEVVEL" /></option>
                                    <option value="3" ${not empty patient and patient.namedAndAnonymous ? 'selected' : ''}><fmt:message key="NEV_NELKUL_ES_NEVVEL" /></option>
                                </c:if>
                            </select>
                        </c:if>
                        <c:if test="${not user.dataRecorder and not empty patient}">
                            <input id="patientType" type="hidden" name="patientType" value="${patient.patientType}" />
                            <fmt:message key="${not patient.named ? 'NEV_NELKUL' : ''}${not patient.anonymous ? 'NEVVEL' : ''}${patient.namedAndAnonymous ? 'NEV_NELKUL_ES_NEVVEL' : ''}" />
                        </c:if>
                        </td>
                        </tr>
                        </tbody>
                    </table>
                    <div id="monogram" style="display: ${(not user.dataRecorder and empty patient) or (patient.anonymous and not patient.named) or (not user.dataRecorder and patient.namedAndAnonymous) ? 'block' : 'none'}">
                        <div class="patientline"><fmt:message key="anonymData" /></div>
                        <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">
                            <tbody>
                                <tr>
                                    <td style="width: 112px;" ><fmt:message key="monogram" />:</td>
                            <td style="width: 340px;">
                            <c:if test="${user.dataRecorder or empty patient}">
                                <input id="monogr" class="required" type="text" name="monogram" value="${patient.anonymousData.monogram}" />
                            </c:if>
                            <c:if test="${not user.dataRecorder and not empty patient}">
                                <input id="monogr" class="required" type="hidden" name="monogram" value="${patient.anonymousData.monogram}" />
                                ${patient.anonymousData.monogram}
                            </c:if>
                            </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div id="anonymous" style="display: ${patient.anonymous ? 'block' : 'none'}">
                        <input id="anonId" type="hidden" name="anonymousId" value="${patient.anonymousData.anonymousId}">
                        <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">
                            <tbody>
                                <tr>
                                    <td style="width: 112px;" ></td>
                                    <td style="width: 340px;"></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div id="named" style="display: ${empty patient or patient.named ? 'block' : 'none'}">
                        <c:if test="${user.dataRecorder}">
                            <div class="patientline"><fmt:message key="personalData" /></div>
                            <input id="personalId" type="hidden" name="personalId" value="${patient.identity.personalId}">
<!--                            <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">-->
<!--                                <tbody>-->
<!--                                    -->
<!--                                </tbody>-->
<!--                            </table>-->
                            <div id="tajListDiv" style="display: none">
                                <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">
                                    <tbody>
                                        <tr>
                                            <td style="width: 112px;" ></td>
                                            <td style="width: 340px;">
                                                <div class="selectbg">
                                                    <select class="transparent" id="tajList" name="tajList" size="2" onchange="return tajListChanged();">
                                                        <option value="0"><fmt:message key="NEW_PATIENT" /></option>
                                                    </select>
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <table class="formtable" border="0" width="477px" cellspacing="0" cellpadding="3">
                                <tbody>
                                <tr>
                                    <td style="width: 112px;"><fmt:message key="TAJ" />:</td>
                                <td style="width: 340px;"><input class="required" type="text" id="tajNumber" name="tajNumber" value="${patient.identity.tajNumber}" onkeyup="return searchTaj();" /></td>
                                </tr>
                                
                                <tr>
                                        <td style="width: 112px;"><fmt:message key="BETEG_NEV" />:</td>
                                <td style="width: 340px;"><input class="required" type="text" id="patientName" name="patientName" value="${patient.identity.patientName}" ${empty patient.id ? 'onkeyup="return searchName();"' : ''} /></td>
                                </tr>
                               
                                <tr>
                                        <td style="width: 112px;"><fmt:message key="SZULETESI_NEV" />:</td>
                                <td style="width: 340px;"><input class="input" type="text" id="maidenName" name="maidenName" value="${patient.identity.maidenName}" /></td>
                                </tr>
                                <tr>
                                    <td style="width: 112px;"><fmt:message key="dateOfBirth" />:</td>
                                <td style="width: 340px;"><input id="datepicker" class="required" type="text" id="dateOfBirth" name="dateOfBirth" value="${patient.dateOfBirthForWeb}" /></td>
                                </tr>
                                <tr>
                                    <td style="width: 112px;"><fmt:message key="IRSZ" /> <fmt:message key="TELEPULES" />:</td>
                                <td style="width: 340px;" nowrap><input id="irsz" class="shortinput" style="width: 12%" size="4" maxlength="4" type="text" name="zipCode" value="${patient.identity.zipCode gt 0 ? patient.identity.zipCode : ''}" onkeyup="return getTelepules(document.getElementById('irsz').value, '');"> <input id="telepules" class="shortinput" style="width: 86%" size="30" type="text" name="city" value="${patient.identity.city}" /></td>
                                </tr>
                                <tr>
                                    <td style="width: 112px;"><fmt:message key="CIM" />:</td>
                                <td style="width: 340px;"><input class="input" type="text" id="address" name="address" value="${patient.identity.address}" /></td>
                                </tr>
                                <tr>
                                    <td style="width: 112px;"><fmt:message key="ANYJA_NEVE" />:</td>
                                <td style="width: 340px;"><input class="input" type="text" id="mothersName" name="mothersName" value="${patient.identity.mothersName}" /></td>
                                </tr>
                                </tbody>
                            </table>
                        </c:if>
                    </div>
                </div>
                <!--div class="patientline"><fmt:message key="labelPrint" /></div-->
                <br />
                <div align="right">
                    <input class="button" type="submit" value="<fmt:message key="MENTÉS" />">
                </div>
            </form>
        </div>
    </div>
    <div class="copyright">
        &copy; 2009-2010 Astrid Research Inc.
    </div>
</div>
