org.obiba.onyx.jade.instrument.atcor.dao.impl.JdbcSphygmoCorDao.java Source code

Java tutorial

Introduction

Here is the source code for org.obiba.onyx.jade.instrument.atcor.dao.impl.JdbcSphygmoCorDao.java

Source

/*******************************************************************************
 * Copyright 2008(c) The OBiBa Consortium. All rights reserved.
 * 
 * This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package org.obiba.onyx.jade.instrument.atcor.dao.impl;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.obiba.onyx.jade.instrument.atcor.dao.SphygmoCorDao;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

public class JdbcSphygmoCorDao extends NamedParameterJdbcDaoSupport implements SphygmoCorDao {

    //
    // Constants
    //

    private static final String INSERT_PATIENT_SQL = "insert into PATIENT (SYSTEM_ID, STUDY_ID, PATIENT_ID, PATIENT_NO, FAM_NAME, FIRST_NAME, DOB, SEX) "
            + "values (:systemId, :studyId, :patientId, :patientNo, :familyName, :firstName, :birthDate, :gender)";

    private static final String DELETE_PATIENT_BY_ID_SQL = "delete from PATIENT where PATIENT_ID = :patientId";

    private static final String DELETE_PATIENT_BY_NUMBER_SQL = "delete from PATIENT where PATIENT_NO = :patientNo";

    private static final String DELETE_ALL_PATIENTS_SQL = "delete from PATIENT";

    private static final String DELETE_ALL_OUTPUT_SQL = "delete from M_PWA";

    private static final String GET_OUTPUT_SQL = "select * from M_PWA, PATIENT where PATIENT_ID = :patientNo and M_PWA.PATIENT_NO = PATIENT.PATIENT_NO";

    //
    // Methods
    //

    public void addPatient(String systemId, String studyId, String patientId, int patientNo, String familyName,
            String firstName, Date birthDate, String gender) {
        Map paramMap = new HashMap();

        paramMap.put("systemId", systemId);
        paramMap.put("studyId", studyId);
        paramMap.put("patientId", patientId);
        paramMap.put("patientNo", patientNo);
        paramMap.put("familyName", familyName);
        paramMap.put("firstName", firstName);
        paramMap.put("birthDate", birthDate);
        paramMap.put("gender", gender);

        getNamedParameterJdbcTemplate().update(INSERT_PATIENT_SQL, paramMap);
    }

    public void deletePatientById(String patientId) {
        Map paramMap = new HashMap();

        paramMap.put("patientId", patientId);

        getNamedParameterJdbcTemplate().update(DELETE_PATIENT_BY_ID_SQL, paramMap);
    }

    public void deletePatientByNumber(int patientNo) {
        Map paramMap = new HashMap();

        paramMap.put("patientNo", patientNo);

        getNamedParameterJdbcTemplate().update(DELETE_PATIENT_BY_NUMBER_SQL, paramMap);
    }

    public void deleteAllPatients() {
        Map paramMap = new HashMap();

        getNamedParameterJdbcTemplate().update(DELETE_ALL_PATIENTS_SQL, paramMap);
    }

    public void deleteAllOutput() {
        Map paramMap = new HashMap();

        getNamedParameterJdbcTemplate().update(DELETE_ALL_OUTPUT_SQL, paramMap);
    }

    public List getOutput(int patientNo) {
        Map paramMap = new HashMap();
        paramMap.put("patientNo", patientNo);

        List matches = getNamedParameterJdbcTemplate().queryForList(GET_OUTPUT_SQL, paramMap);

        return matches.size() > 0 ? matches : null;
    }
}