001:package com.xoetrope.medical.forms;
002:
003:import java.awt.Color;
004:
005:import com.xoetrope.swing.XDateEdit;
006:import com.xoetrope.swing.date.XTimeChooser;
007:import net.xoetrope.optional.annotation.Find;
008:import net.xoetrope.swing.XComboBox;
009:import net.xoetrope.swing.XDialog;
010:import net.xoetrope.swing.XEdit;
011:import net.xoetrope.swing.XLabel;
012:import net.xoetrope.swing.XButton;
013:import net.xoetrope.xui.data.XBaseModel;
014:import net.xoetrope.xui.data.XModel;
015:
016:/**
017: * Adds functionality to Add Existing and Add New dialogs
018: *
019: * <p> Copyright (c) Xoetrope Ltd., 2002-2006, This software is licensed under
020: * the GNU Public License (GPL), please see license.txt for more details</p>
021: *
022: * @author kingsley.elmes
023: */
024:public class AddMedication extends XDialog
025:{
026: public static final int ADD_NEW_MEDICATION = 1;
027: public static final int ADD_EXISTING_MEDICATION = 2;
028:
029: @Find
030: XComboBox drugBox, frequencyBox, dosageUnit, routeBox, targetUnit;
031:
032: @Find
033: XEdit dosageAmt, targetAmt;
034:
035: @Find
036: XTimeChooser timeInput;
037:
038: @Find
039: XDateEdit dateInput;
040:
041: @Find
042: XLabel counterLbl;
043:
044: @Find
045: XButton cancelButton;
046:
047: private XModel currentAED, newNode;
048: private String title;
049: private Integer nextId;
050: private boolean saveAndContinue;
051: private int counter, totalDosage;
052:
053: public AddMedication()
054: {
055: super ();
056:
057: saveAndContinue = false;
058: nextId = (Integer)project.getObject( "nextMedicationID" );
059: if ( nextId == null )
060: nextId = new Integer( 0 );
061: }
062:
063: public String getBanner()
064: {
065: // obtain integer from root model which specifies
066: // the type of dialog being created
067: XBaseModel model = (XBaseModel)rootModel.get( "dlgType" );
068: int dlgType = Integer.parseInt( model.get().toString());
069:
070: // return appropriate banner
071: if ( dlgType == ADD_NEW_MEDICATION )
072: return "epilepsyBanner/green";
073: else
074: return "epilepsyBanner/blue";
075: }
076:
077: public String getTitle()
078: {
079: // obtain integer from root model which specifies
080: // the type of dialog being created
081: XBaseModel model = (XBaseModel)rootModel.get( "dlgType" );
082: int dlgType = model.getAttribValueAsInt( model.VALUE_ATTRIBUTE );
083:
084: // return appropriate title
085: if ( dlgType == ADD_NEW_MEDICATION )
086: return "Add New";
087: else
088: return "Add Existing";
089: }
090:
091: public void saveClickContinue()
092: {
093: saveAndContinue = true;
094: saveClick();
095: }
096:
097: public void saveClick()
098: {
099: // Get the next medication ID
100: int id = nextId.intValue() + 1;
101: nextId = new Integer( ++id );
102: project.setObject( "nextMedicationID", nextId );
103:
104: // Obtain reference to currentAED table
105: currentAED = (XModel)rootModel.get( "currentAED" );
106:
107: // Add new node to the currentAED table
108: XBaseModel newRow = (XBaseModel)currentAED.get( "newNode" + id );
109: newRow.setAttribValue ( XBaseModel.VALUE_ATTRIBUTE, ("newNode" + id ));
110:
111: // Add values to appropriate columns in table
112: newRow.set( "1", drugBox.getSelectedItem().toString() );
113: newRow.set( "2", dateInput.getText());
114: newRow.set( "3", dosageAmt.getText() + " " + dosageUnit.getSelectedItem().toString() );
115: newRow.set( "4", frequencyBox.getSelectedItem().toString() );
116: newRow.set( "5", timeInput.getSelectedItem().toString() );
117: newRow.set( "6", routeBox.getSelectedItem().toString() );
118: newRow.set( "7", targetAmt.getText() + " " + targetUnit.getSelectedItem().toString() );
119: newRow.set( "8", "" );
120:
121: if ( !saveAndContinue )
122: closeDlg();
123: else {
124: drugBox.setEnabled( false );
125: targetAmt.setEnabled( false );
126:
127: totalDosage += Integer.parseInt( dosageAmt.getText());
128:
129: counter++;
130: counterLbl.setVisible( true );
131: counterLbl.setText( "" + counter + " Added, (" + totalDosage + " mg)" );
132:
133: int targetDosage = Integer.parseInt( targetAmt.getText());
134: if ( totalDosage > targetDosage )
135: counterLbl.setForeground( Color.red );
136:
137: cancelButton.setText( "Close" );
138: }
139:
140: saveAndContinue = false;
141: }
142:}
|