/*
* iDART: The Intelligent Dispensing of Antiretroviral Treatment
* Copyright (C) 2006 Cell-Life
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version
* 2 for more details.
*
* You should have received a copy of the GNU General Public License version 2
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package org.celllife.idart.gui.reportParameters;
import java.util.Calendar;
import java.util.Date;
import model.manager.reports.MissedAppointmentsReport;
import org.apache.log4j.Logger;
import org.celllife.idart.commonobjects.CommonObjects;
import org.celllife.idart.gui.platform.GenericReportGui;
import org.celllife.idart.gui.platform.GenericReportGuiInterface;
import org.celllife.idart.gui.utils.ResourceUtils;
import org.celllife.idart.gui.utils.iDartColor;
import org.celllife.idart.gui.utils.iDartFont;
import org.celllife.idart.gui.utils.iDartImage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.vafada.swtcalendar.SWTCalendar;
import org.vafada.swtcalendar.SWTCalendarListener;
/**
*/
public class MissedAppointments extends GenericReportGui {
private Group grpClinicSelection;
private Label lblClinic;
private CCombo cmbClinic;
private Label lblMinimumDaysLate;
private Text txtMinimumDaysLate;
private Text txtMaximumDaysLate;
private Label lblMaximumDaysLate;
private Group grpDateRange;
private SWTCalendar swtCal;
/**
* Constructor
*
* @param parent
* Shell
* @param activate
* boolean
*/
public MissedAppointments(Shell parent, boolean activate) {
super(parent, GenericReportGuiInterface.REPORTTYPE_CLINICMANAGEMENT,
activate);
}
/**
* This method initializes newMonthlyStockOverview
*/
@Override
protected void createShell() {
buildShell(REPORT_MISSED_APPOINTMENTS, new Rectangle(100, 50, 600,
510));
// create the composites
createMyGroups();
}
private void createMyGroups() {
createGrpClinicSelection();
createGrpDateRange();
}
/**
* This method initializes compHeader
*
*/
@Override
protected void createCompHeader() {
iDartImage icoImage = iDartImage.REPORT_PATIENTDEFAULTERS;
buildCompdHeader(REPORT_MISSED_APPOINTMENTS, icoImage);
}
/**
* This method initializes grpClinicSelection
*
*/
private void createGrpClinicSelection() {
grpClinicSelection = new Group(getShell(), SWT.NONE);
grpClinicSelection.setText("Missed Appointments Report Settings");
grpClinicSelection.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
grpClinicSelection.setBounds(new Rectangle(60, 79, 465, 114));
lblClinic = new Label(grpClinicSelection, SWT.NONE);
lblClinic.setBounds(new Rectangle(30, 25, 167, 20));
lblClinic.setText("Select Clinic");
lblClinic.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
cmbClinic = new CCombo(grpClinicSelection, SWT.BORDER);
cmbClinic.setBounds(new Rectangle(202, 25, 160, 20));
cmbClinic.setEditable(false);
cmbClinic.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
cmbClinic.setBackground(ResourceUtils.getColor(iDartColor.WHITE));
CommonObjects.populateClinics(getHSession(), cmbClinic);
lblMinimumDaysLate = new Label(grpClinicSelection, SWT.NONE);
lblMinimumDaysLate.setBounds(new Rectangle(31, 57, 126, 21));
lblMinimumDaysLate.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
lblMinimumDaysLate.setText("Minimum Days Late:");
txtMinimumDaysLate = new Text(grpClinicSelection, SWT.BORDER);
txtMinimumDaysLate.setBounds(new Rectangle(201, 56, 45, 20));
txtMinimumDaysLate.setText("3");
txtMinimumDaysLate.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
lblMaximumDaysLate = new Label(grpClinicSelection, SWT.NONE);
lblMaximumDaysLate.setBounds(new Rectangle(31, 86, 122, 21));
lblMaximumDaysLate.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
lblMaximumDaysLate.setText("Maximum Days Late:");
txtMaximumDaysLate = new Text(grpClinicSelection, SWT.BORDER);
txtMaximumDaysLate.setBounds(new Rectangle(202, 86, 43, 19));
txtMaximumDaysLate.setText("14");
txtMaximumDaysLate.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
}
/**
* This method initializes grpDateRange
*
*/
private void createGrpDateRange() {
grpDateRange = new Group(getShell(), SWT.NONE);
grpDateRange.setText("Select Report Date:");
grpDateRange.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8));
grpDateRange.setBounds(new Rectangle(142, 214, 309, 211));
swtCal = new SWTCalendar(grpDateRange);
swtCal.setBounds(40, 40, 220, 160);
}
/**
* Method getCalendarDate.
*
* @return Calendar
*/
public Calendar getCalendarDate() {
return swtCal.getCalendar();
}
/**
* Method setCalendarDate.
*
* @param date
* Date
*/
public void setCalendarDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
swtCal.setCalendar(calendar);
}
/**
* Method addDateChangedListener.
*
* @param listener
* SWTCalendarListener
*/
public void addDateChangedListener(SWTCalendarListener listener) {
swtCal.addSWTCalendarListener(listener);
}
/**
* This method initializes compButtons
*
*/
@Override
protected void createCompButtons() {
}
@Override
protected void cmdViewReportWidgetSelected() {
boolean viewReport = true;
int max = 0;
int min = 0;
if (cmbClinic.getText().equals("")) {
MessageBox missing = new MessageBox(getShell(), SWT.ICON_ERROR
| SWT.OK);
missing.setText("No Clinic Was Selected");
missing
.setMessage("No clinic was selected. Please select a clinic by looking through the list of available clinics.");
missing.open();
viewReport = false;
}
if (txtMinimumDaysLate.getText().equals("")
|| txtMaximumDaysLate.getText().equals("")) {
MessageBox incorrectData = new MessageBox(getShell(),
SWT.ICON_ERROR | SWT.OK);
incorrectData.setText("Invalid Information");
incorrectData
.setMessage("The minimum and maximum days late must both be numbers.");
incorrectData.open();
txtMinimumDaysLate.setText("");
txtMinimumDaysLate.setFocus();
viewReport = false;
} else if (!txtMinimumDaysLate.getText().equals("")
&& !txtMaximumDaysLate.getText().equals("")) {
try {
min = Integer.parseInt(txtMinimumDaysLate.getText());
max = Integer.parseInt(txtMaximumDaysLate.getText());
if ((min < 0) || (max < 0)) {
MessageBox incorrectData = new MessageBox(getShell(),
SWT.ICON_ERROR | SWT.OK);
incorrectData.setText("Invalid Information");
incorrectData
.setMessage("The minimum and maximum days late must both be positive numbers.");
incorrectData.open();
txtMinimumDaysLate.setText("");
txtMinimumDaysLate.setFocus();
viewReport = false;
}
if (min >= max) {
MessageBox incorrectData = new MessageBox(getShell(),
SWT.ICON_ERROR | SWT.OK);
incorrectData.setText("Invalid Information");
incorrectData
.setMessage("The minimum days late must be smaller than the maximum days late.");
incorrectData.open();
txtMinimumDaysLate.setFocus();
viewReport = false;
}
} catch (NumberFormatException nfe) {
MessageBox incorrectData = new MessageBox(getShell(),
SWT.ICON_ERROR | SWT.OK);
incorrectData.setText("Invalid Information");
incorrectData
.setMessage("The minimum and maximum days late must both be whole numbers.");
incorrectData.open();
txtMinimumDaysLate.setText("");
txtMinimumDaysLate.setFocus();
viewReport = false;
}
}
if (viewReport) {
MissedAppointmentsReport report = new MissedAppointmentsReport(getShell(),cmbClinic.getText(),
Integer.parseInt(txtMinimumDaysLate.getText()),
Integer.parseInt(txtMaximumDaysLate.getText()),
swtCal.getCalendar().getTime());
viewReport(report);
}
}
/**
* This method is called when the user presses "Close" button
*
*/
@Override
protected void cmdCloseWidgetSelected() {
cmdCloseSelected();
}
@Override
protected void setLogger() {
setLog(Logger.getLogger(this.getClass()));
}
}