gt: 			for (int i=0; i < voCollTransfersOut.size(); i++)
context: //#############################################################################
  //#                                                                           #
  //#  Copyright (C) <2014>  <IMS MAXIMS>                                       #
  //#                                                                           #
  //#  This program is free software: you can redistribute it and/or modify     #
  //#  it under the terms of the GNU Affero General Public License as           #
  //#  published by the Free Software Foundation, either version 3 of the       #
  //#  License, or (at your option) any later version.                          # 
  //#                                                                           #
  //#  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 Affero General Public License for more details.                      #
  //#                                                                           #
  //#  You should have received a copy of the GNU Affero General Public License #
  //#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
  //#                                                                           #
  //#############################################################################
  //#EOH
  // This code was generated by Marius Mihalec using IMS Development Environment (version 1.62 build 3112.33410)
  // Copyright (C) 1995-2008 IMS MAXIMS plc. All rights reserved.
  
  package ims.core.forms.warddataview;
  
  import ims.clinical.vo.lookups.VTEAsessmentStatus;
  import ims.configuration.gen.ConfigFlag;
  import ims.core.admin.pas.vo.InpatientEpisodeRefVo;
  import ims.core.admin.pas.vo.PASEventRefVo;
  import ims.core.forms.warddataview.GenForm.grdInpatientsRow;
  import ims.core.helper.ResetPIDBarHelper;
  import ims.core.vo.InpatientEpisodeLiteVo;
  import ims.core.vo.InpatientEpisodeLiteVoCollection;
  import ims.core.vo.LocationLiteVo;
  import ims.core.vo.LocationLiteVoCollection;
  import ims.core.vo.PasEventADTVo;
  import ims.core.vo.PatientId;
  import ims.core.vo.PatientShort;
  import ims.core.vo.PendingElectiveAdmissionAdmitVo;
  import ims.core.vo.PendingElectiveAdmissionAdmitVoCollection;
  import ims.core.vo.PendingEmergencyAdmissionAdmitVo;
  import ims.core.vo.PendingEmergencyAdmissionAdmitVoCollection;
  import ims.core.vo.PendingTransfersLiteVo;
  import ims.core.vo.PendingTransfersLiteVoCollection;
  import ims.core.vo.WardBayConfigVo;
  import ims.core.vo.WardDataViewVo;
  import ims.core.vo.WardDataViewVoCollection;
  import ims.core.vo.WardViewSearchCriteriaVo;
  import ims.core.vo.lookups.PatIdType;
  import ims.framework.Control;
  import ims.framework.FormName;
  import ims.framework.controls.DynamicGrid;
  import ims.framework.controls.DynamicGridCell;
  import ims.framework.controls.DynamicGridColumn;
  import ims.framework.controls.DynamicGridRow;
  import ims.framework.enumerations.Alignment;
  import ims.framework.enumerations.DialogResult;
  import ims.framework.enumerations.DynamicCellType;
  import ims.framework.exceptions.CodingRuntimeException;
  import ims.framework.exceptions.PresentationLogicException;
  import ims.framework.interfaces.ILocation;
  import ims.framework.utils.Color;
  import ims.framework.utils.Image;
  
  import com.ims.query.builder.client.QueryBuilderClient;
  import com.ims.query.builder.client.SeedValue;
  import com.ims.query.builder.client.exceptions.QueryBuilderClientException;
  
  public class Logic extends BaseLogic
  {
  	private static final long serialVersionUID = 1L;
  	public static final String	COLNAME							= "-1";	
  	public static final Integer	CURRENT							= -5;
  	public static final Integer	INCOMING_ADMISION				= -6;
  	public static final Integer	INCOMING_PENDING_TRANSFERS		= -7;
  	public static final Integer	OUTGOING_DISCHARGE				= -8;
  	public static final Integer	OUTGOING_PENDING_TRANSFERS		= -9;
  	
  	@Override
  	protected void onFormOpen(Object[] args) throws ims.framework.exceptions.PresentationLogicException
  	{		
  		form.imbRefresh().setEnabled(false);
  		loadHospitals();	
  		
  		if (form.getGlobalContext().Core.getWardDataViewSearchCriteriaIsNotNull())///WDEV-12925 -Start
  		{
  			form.cmbHospital().setValue(form.getGlobalContext().Core.getWardDataViewSearchCriteria().getHospital());
  			loadWardsForSelectedHosp();
  			form.cmbWard().setValue(form.getGlobalContext().Core.getWardDataViewSearchCriteria().getWard());
  			wardValueChanged();
  		}///WDEV-12925-End
  		else
  		{
  			//WDEV-15908 - starts here
      		ILocation currentLocation = engine.getCurrentLocation();
      		LocationLiteVo currentHospiptal = domain.getCurrentHospital(currentLocation);
      		form.cmbHospital().setValue(currentHospiptal);
      		
      		loadWardsForSelectedHosp();
      		if(currentLocation instanceof LocationLiteVo)
      		{
      			form.cmbWard().setValue((LocationLiteVo) currentLocation);
      			wardValueChanged();
      		}
      		
      		if(form.cmbWard().getValue() == null && form.cmbWard().getValues() != null && form.cmbWard().getValues().size() == 1)
      		{
      			if(form.cmbWard().getValues().get(0) instanceof LocationLiteVo)
      			{
      				form.cmbWard().setValue((LocationLiteVo) form.cmbWard().getValues().get(0));
      				wardValueChanged();
      			}
      		}
      		//WDEV-15908 - ends here
  		}
  	}
  	
  	private void populateSearchCriteriaDataFromScreen()///WDEV-12925
  	{
  		if (form.cmbHospital().getValue() == null)
  		{
  			form.getGlobalContext().Core.setWardDataViewSearchCriteria(null);
  			return;
  		}
  		WardViewSearchCriteriaVo crit = new WardViewSearchCriteriaVo();
  		crit.setHospital(form.cmbHospital().getValue());
  		crit.setWard(form.cmbWard().getValue());
  		form.getGlobalContext().Core.setWardDataViewSearchCriteria(crit);
  	}
  
  	private void loadHospitals()
  	{
  		LocationLiteVoCollection hospColl = domain.listActiveHospitalsLite();
  		if(hospColl != null)
  		{
  			for(int x = 0; x < hospColl.size(); x++)
  			{
  				if(hospColl.get(x) != null)
  					form.cmbHospital().newRow(hospColl.get(x), hospColl.get(x).getName());
  			}
  		}
  	}
  
  	private void addWard(LocationLiteVo ward) 
  	{
  		if(ward == null)
  			return;
  		
  		form.cmbWard().newRow(ward, ward.getName());
  	}
  
  	
  	@Override
  	protected void onCmbWardValueChanged() throws PresentationLogicException 
  	{		
  		wardValueChanged();
  		populateSearchCriteriaDataFromScreen();///WDEV-12925
  	}
  	
  	private void wardValueChanged()
  	{
  		form.getGlobalContext().Core.setSelectingPatientForm(null);
  		form.getGlobalContext().Core.setPatientShort(null);
  		form.getGlobalContext().Core.setCurrentCareContext(null);
  		
  		form.imbRefresh().setEnabled(false);
  		
  		if(form.cmbWard().getValue() != null)
  		{
  			WardBayConfigVo voWardBayConfig = domain.getWardBayConfigByWard(form.cmbWard().getValue());
  			if(voWardBayConfig != null)
  				form.getGlobalContext().Core.setHasWaitingArea(voWardBayConfig.getIsWaitingAreaIsNotNull() && voWardBayConfig != null && voWardBayConfig.getIsWaitingArea());
  			
  			form.imbRefresh().setEnabled(true);
  		}
  		
  		loadData();
  		populateDynamicGridFromData();
  		populateInpatientsGrid();
  	}
  
  	private void populateInpatientsGrid()
  	{
  		form.grdInpatients().getRows().clear();
  		
  		PatIdType dispIdType = PatIdType.getNegativeInstance(ConfigFlag.UI.DISPLAY_PATID_TYPE.getValue()); 
  		form.grdInpatients().setColDisplayIdCaption(dispIdType.getText());
  		
  		if(form.cmbWard().getValue() == null)
  			return;
  		
  		if(ConfigFlag.UI.BED_INFO_UI_TYPE.getValue().equals("CCO"))
  			fillGridFromHomeLeaveANDInpatRecords();
  		else
  			fillFromInpatRecords();
  		
  	}
  
  	private void fillFromInpatRecords() 
  	{
  		WardDataViewVoCollection voCollWdv = domain.listInpatientsInBedsByWard(form.cmbWard().getValue());
  		if(voCollWdv != null)
  		{
  			for (WardDataViewVo voWdv : voCollWdv)
  			{
  				grdInpatientsRow row = form.grdInpatients().getRows().newRow();
  				PatientShort voPatient = voWdv.getPatient();
  				if(voPatient != null)
  				{
  					if(voPatient.getNameIsNotNull())
  					{
  						row.setColForename(voPatient.getName().getForename());
  						row.setColSurname(voPatient.getName().getSurname());
  					}
  					
  					PatientId patId = voPatient.getDisplayId();
  					row.setColDisplayId(patId != null ? patId.getValue() : null);				
  					Integer age = voPatient.calculateAge();
  					if(age != null)
  						row.setColAge(String.valueOf(age));
  	
  					if(voPatient.getHasActiveAlertsIsNotNull() && voPatient.getHasActiveAlerts())   //wdev-11083
  						row.setColAlert(form.getImages().Core.Alert16); //WDEV-18011 
  					row.setColInfant(calculateInfants(voPatient));
  				}
  				
  				if(voWdv.getBayIsNotNull())
  					row.setColBay(voWdv.getBay().getName());
  				if(voWdv.getBedIsNotNull())
  					row.setColBedNumber(voWdv.getBed().getBedNumber());		
  				
  				row.setColPasEventHidden(voWdv.getPasEvent());
  				
  				//wdev-14784
  				if(	voWdv.getInpatEpisodeIsNotNull() && voWdv.getInpatEpisode().getVTEAssessmentStatusIsNotNull()  && ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true) //wdev-15062
  				{
  					row.setColVTEStatus(VTEAsessmentStatus.REQUIRED.equals(voWdv.getInpatEpisode().getVTEAssessmentStatus()) ? form.getImages().OCRR.Requested : (VTEAsessmentStatus.INPROGRESS.equals(voWdv.getInpatEpisode().getVTEAssessmentStatus()) ? form.getImages().OCRR.InProgress : null));
  											
  				}
  				else
  				{
  					row.setColVTEStatus(null);
  				}
  				//----------
  				
  				row.setTooltip(buildRowTooltip(voWdv));
  				row.setValue(voPatient);
  			}
  		}
  	}
  
  	private void fillGridFromHomeLeaveANDInpatRecords()
  	{
  		InpatientEpisodeLiteVoCollection voCollHL = form.getLocalContext().getOnHomeLeave();
  		for (int i=0; i < voCollHL.size() ; i++ )
  		{
  			InpatientEpisodeLiteVo voHLInpatEpis = voCollHL.get(i);
  			grdInpatientsRow row = form.grdInpatients().getRows().newRow();
  			
  			PatientShort voPatient = voHLInpatEpis.getPasEvent().getPatient();
  			if(voPatient != null)
  			{
  				if(voPatient.getNameIsNotNull())
  				{
  					row.setColForename(voPatient.getName().getForename());
  					row.setColSurname(voPatient.getName().getSurname());
  				}
  				
  				PatientId patId = voPatient.getDisplayId();
  				row.setColDisplayId(patId != null ? patId.getValue() : null);				
  				Integer age = voPatient.calculateAge();
  				if(age != null)
  					row.setColAge(String.valueOf(age));
  
  				if(voPatient.getHasActiveAlertsIsNotNull() && voPatient.getHasActiveAlerts())   //wdev-11083
  					row.setColAlert(form.getImages().Core.Alert16); //WDEV-18011 
  				row.setColInfant(calculateInfants(voPatient));
  			}
  			//wdev-14784
  			if(	voHLInpatEpis != null && voHLInpatEpis.getVTEAssessmentStatusIsNotNull() && ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true ) //wdev-15062
  			{
  				row.setColVTEStatus(VTEAsessmentStatus.REQUIRED.equals(voHLInpatEpis.getVTEAssessmentStatus()) ? form.getImages().OCRR.Requested : (VTEAsessmentStatus.INPROGRESS.equals(voHLInpatEpis.getVTEAssessmentStatus()) ? form.getImages().OCRR.InProgress : null));
  										
  			}
  			else
  			{
  				row.setColVTEStatus(null);
  			}
  			//----------
  			
  			row.setColBay("");
  			row.setColBedNumber("(H)");		
  			
  			row.setColPasEventHidden(voHLInpatEpis.getPasEvent());		
  			
  			row.setTooltip(buildRowTooltip(voHLInpatEpis.getPasEvent(),voHLInpatEpis));	//wdev-14784
  
  			row.setValue(voHLInpatEpis.getPasEvent().getPatient());
  		}
  
  		fillFromInpatRecords();
  		
  		
  		form.grdInpatients().sort(0);
  	}
  
  	private String buildRowTooltip(PasEventADTVo voPE, InpatientEpisodeLiteVo voHLInpatEpis)
  	{
  		if (voPE == null)
  			throw new CodingRuntimeException("voPE cannot be null in method buildRowTooltip");
  		
  		String consultant = voPE.getConsultantIsNotNull() ? voPE.getConsultant().getIMosName() : "";
  		String nhsNo =  voPE.getPatientIsNotNull() && voPE.getPatient().getNhsn() != null ?  voPE.getPatient().getNhsn().getValue() : "";
  		//wdev-14784
  		String vteStatus = "";
  		//wdev-14784
  		if(	voHLInpatEpis != null && voHLInpatEpis.getVTEAssessmentStatusIsNotNull() && ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true) //wdev-15062
  		{
  			vteStatus = VTEAsessmentStatus.REQUIRED.equals(voHLInpatEpis.getVTEAssessmentStatus()) ? voHLInpatEpis.getVTEAssessmentStatus().getIItemText()  : (VTEAsessmentStatus.INPROGRESS.equals(voHLInpatEpis.getVTEAssessmentStatus()) ? voHLInpatEpis.getVTEAssessmentStatus().getIItemText() : (VTEAsessmentStatus.COMPLETED.equals(voHLInpatEpis.getVTEAssessmentStatus()) ? voHLInpatEpis.getVTEAssessmentStatus().getIItemText() : ""));  //wdev-14858 
  		}
  		
  		//---------
  		
  		StringBuffer strTooltip = new StringBuffer();
  		
  		if( ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true) //wdev-15062
  		{
  			strTooltip.append("<html><head></head><body><p><font color='#FF0000'><strong>Other Detail</strong></font>" +
  				"<table width='210' border='0'><tr><td width='70'><font color='#0033FF'>NHS Number :</font></td><td>" +
  				nhsNo +
  				"</td></tr><tr><td><font color='#0033FF'>Consultant :</font></td><td>" +
  				consultant +
  				"</td></tr><tr><td><font color='#0033FF'>VTE Assessment Status :</font></td><td>" +
  				vteStatus +
  				"</td></tr></table></p>" +
  				"</body></html>");
  		}
  		else
  		{
  			strTooltip.append("<html><head></head><body><p><font color='#FF0000'><strong>Other Detail</strong></font>" +
  					"<table width='210' border='0'><tr><td width='70'><font color='#0033FF'>NHS Number :</font></td><td>" +
  					nhsNo +
  					"</td></tr><tr><td><font color='#0033FF'>Consultant :</font></td><td>" +
  					consultant +
  					"</td></tr></table></p>" +
  					"</body></html>");
  		}
  		
  		return strTooltip.toString();
  	}
  
  	private String buildRowTooltip(WardDataViewVo voWdv)
  	{
  		if (voWdv == null)
  			throw new CodingRuntimeException("voWdv cannot be null in method buildRowTooltip");
  		
  		String consultant = voWdv.getPasEventIsNotNull() && voWdv.getPasEvent().getConsultantIsNotNull() ? voWdv.getPasEvent().getConsultant().getIMosName() : "";
  		String nhsNo =  voWdv.getPatientIsNotNull() && voWdv.getPatient().getNhsn() != null ?  voWdv.getPatient().getNhsn().getValue() : "";
  		
  		//wdev-14784
  		String vteStatus = "";
  		//wdev-14784
  		if(	voWdv.getInpatEpisodeIsNotNull() && voWdv.getInpatEpisode().getVTEAssessmentStatusIsNotNull()  && ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true) //wdev-15062
  		{
  			vteStatus = VTEAsessmentStatus.REQUIRED.equals(voWdv.getInpatEpisode().getVTEAssessmentStatus()) ? voWdv.getInpatEpisode().getVTEAssessmentStatus().getIItemText()  : (VTEAsessmentStatus.INPROGRESS.equals(voWdv.getInpatEpisode().getVTEAssessmentStatus()) ? voWdv.getInpatEpisode().getVTEAssessmentStatus().getIItemText() :(VTEAsessmentStatus.COMPLETED.equals(voWdv.getInpatEpisode().getVTEAssessmentStatus()) ? voWdv.getInpatEpisode().getVTEAssessmentStatus().getIItemText() :"")); //wdev-14858
  		}
  		
  		//---------
  		
  		StringBuffer strTooltip = new StringBuffer();
  		
  		if( ConfigFlag.UI.VTE_RISK_ASSESSMENT_FUNCTIONALITY.getValue() == true)   //wdev-15062
  		{
  			strTooltip.append("<html><head></head><body><p><font color='#FF0000'><strong>Other Detail</strong></font>" +
  				"<table width='210' border='0'><tr><td width='70'><font color='#0033FF'>NHS Number :</font></td><td>" +
  				nhsNo +
  				"</td></tr><tr><td><font color='#0033FF'>Consultant :</font></td><td>" +
  				consultant +
  				"</td></tr><tr><td><font color='#0033FF'>VTE Assessment Status :</font></td><td>" +
  				vteStatus +
  				"</td></tr></table></p>" +
  				"</body></html>");
  		}
  		else
  		{
  			strTooltip.append("<html><head></head><body><p><font color='#FF0000'><strong>Other Detail</strong></font>" +
  					"<table width='210' border='0'><tr><td width='70'><font color='#0033FF'>NHS Number :</font></td><td>" +
  					nhsNo +
  					"</td></tr><tr><td><font color='#0033FF'>Consultant :</font></td><td>" +
  					consultant +
  					"</td></tr></table></p>" +
  					"</body></html>");
  		}
  		
  		return strTooltip.toString();
  	}
  
  	private void clearDisplay()
  	{
  		clearData();
  		form.dyngrdDisplay().clear();
  		form.grdInpatients().getRows().clear();
  	}
  
  	private void clearData()
  	{
  		form.getLocalContext().setOnHomeLeave(null);
  		form.getLocalContext().setOnTheWard(null);
  		form.getLocalContext().setTransfersOut(null);
  		form.getLocalContext().setPendingElective(null);
  		form.getLocalContext().setPendingEmergency(null);
  		form.getLocalContext().setTransfersIn(null);
  		form.getLocalContext().setWaitingArea(null);
  	}
  
  	private DynamicGridColumn getColumn(String identifier)
  	{
  		return form.dyngrdDisplay().getColumns().getByIdentifier(identifier);
  	}
  
  	private void initializeDynamicGrid() 
  	{	
  		DynamicGrid dynGrid = form.dyngrdDisplay();
  		dynGrid.clear();
  		DynamicGridColumn colPatient = null;	
  		colPatient = dynGrid.getColumns().newColumn("Patient", COLNAME);
  		colPatient.setWidth(250);		
  		colPatient.setAlignment(Alignment.CENTER);		
  	}
  	
  	private void populateDynamicGridFromData()
  	{		
  		initializeDynamicGrid();
  		
  		DynamicGrid dynGrid = form.dyngrdDisplay();		
  		DynamicGridRow dynRow = dynGrid.getRows().newRow();
  		DynamicGridRow patientRow =null;
  		dynRow.setIdentifier(CURRENT);
  		dynRow.setReadOnly(false);
  		dynRow.setSelectable(false);
  		dynRow.setExpanded(true);
  
  		DynamicGridCell cellPatient = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);
  		cellPatient.getItems().clear();
  		cellPatient.setBackColor(Color.Bisque);
  		cellPatient.setValue("<h3>ON THE WARD</h3>");
  
  		if(ConfigFlag.UI.BED_INFO_UI_TYPE.getValue()!="WST")//WDEV-14410 
  		{
  		dynRow = cellPatient.getRow().getRows().newRow();
  		dynRow.setExpanded(true);
  		dynRow.setSelectable(false);
  		
  		DynamicGridCell cellHomeLeave = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);				
  		cellHomeLeave.setValue("<h3>Home Leave</h3>");
  		cellHomeLeave.setBackColor(Color.Aqua);
  
  		//wdev-13509
  
  		InpatientEpisodeLiteVoCollection voCollHL = form.getLocalContext().getOnHomeLeave();
  	    if(voCollHL != null)
  	    {
  			for (int i=0; i < voCollHL.size() ; i++ )
  			{
  			    InpatientEpisodeLiteVo voHLInpatEpis = voCollHL.get(i);
  			    if(voHLInpatEpis.getIsOnHomeLeaveIsNotNull()
  			    	&& voHLInpatEpis.getIsOnHomeLeave())
  			    {
  			    	dynRow = cellHomeLeave.getRow().getRows().newRow();
  			    	dynRow.setSelectable(false);
  					dynRow.setExpanded(true);
  			    	
  					DynamicGridCell cellPatientRow = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);		
  					cellPatientRow.setAutoPostBack(true);
  					cellPatientRow.setBackColor(Color.White);
  					cellPatientRow.setIdentifier(CURRENT);
  					cellPatientRow.setValue("<img src = " + form.getImages().Core.Person.getImagePath() + "> &nbsp;&nbsp;" +  voHLInpatEpis.getPatientString());
  					String tooltip = voHLInpatEpis.getPatientString();
  					if (voHLInpatEpis.getBedIsNotNull() && voHLInpatEpis.getBed().getBayIsNotNull() && voHLInpatEpis.getBed().getBay().getNameIsNotNull())
  						tooltip+=" Bay: "+voHLInpatEpis.getBed().getBay().getName();
  					if (voHLInpatEpis.getVacatedBedNumberIsNotNull() 
  						&& voHLInpatEpis.getVacatedBedNumber().toString() != "")
  						tooltip+=" Vacated Bed: "+voHLInpatEpis.getVacatedBedNumber();
  					if (voHLInpatEpis.getExpectedDateOfReturnIsNotNull())
  						tooltip+=" Expected Return : "+voHLInpatEpis.getExpectedDateOfReturn().toString();
  					if (voHLInpatEpis.getExpectedTimeOfReturnIsNotNull())
  						tooltip+=" at "+ voHLInpatEpis.getExpectedTimeOfReturn().toString();
  					cellPatientRow.setTooltip(tooltip);
  					if (voHLInpatEpis.getPasEventIsNotNull())
  					{
  						dynRow.setValue(voHLInpatEpis.getPasEvent().getPatient());
  						dynRow.setIdentifier(voHLInpatEpis);
  					}
  			    }
  			}
  	    }
  		}
  		dynRow = cellPatient.getRow().getRows().newRow();
  		dynRow.setExpanded(true);
  		dynRow.setSelectable(false);
  
  		DynamicGridCell cellOutgoingDischarge = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);				
  		cellOutgoingDischarge.setValue("<b><i>For Discharge</i></b>");
  		cellOutgoingDischarge.setBackColor(Color.Aqua);
  		
  		dynRow = cellOutgoingDischarge.getRow().getRows().newRow();
  		dynRow.setExpanded(true);
  		dynRow.setSelectable(false);
  		DynamicGridCell cellOutgoingOccupiedDueDischarge24h = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);				
  		cellOutgoingOccupiedDueDischarge24h.setValue("<b><i>Due discharge within 24h</i></b>");
  		
  		InpatientEpisodeLiteVoCollection voCollInpatEpis = form.getLocalContext().getOnTheWard();
  		if(voCollInpatEpis != null)
  		{
  			for (int i=0; i < voCollInpatEpis.size() ; i++ )
  			{
  				InpatientEpisodeLiteVo voInpatEpis = voCollInpatEpis.get(i);
  				
  				if(voInpatEpis.isDischargeDueWithin24Hrs())
  			    {
  					if(voInpatEpis.getIsConfirmedDischargeIsNotNull() && voInpatEpis.getIsConfirmedDischarge())
  						continue;
  					
  					patientRow = cellOutgoingOccupiedDueDischarge24h.getRow().getRows().newRow();
  					patientRow.setSelectable(true);
  					DynamicGridCell cellPatientRow = patientRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);		
  					cellPatientRow.setAutoPostBack(true);
  					cellPatientRow.setBackColor( Color.fromRGB(255, 105, 0));
  					cellPatientRow.setIdentifier(CURRENT);
  					cellPatientRow.setValue("<img src = " + form.getImages().Core.Person.getImagePath() + "> &nbsp;&nbsp;" +  voInpatEpis.getPatientString());
  					if (voInpatEpis.getPasEventIsNotNull())
  					{
  						patientRow.setValue(voInpatEpis.getPasEvent().getPatient());
  						patientRow.setIdentifier(voInpatEpis.getPasEvent());
  					}
  					
  			    }
  			}
  		}
  		dynRow = cellOutgoingDischarge.getRow().getRows().newRow();
  		dynRow.setExpanded(true);
  		dynRow.setSelectable(false);
  		DynamicGridCell cellOutgoingConfirmedDischarge24h = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);				
  		cellOutgoingConfirmedDischarge24h.setValue("<b><i>Confirmed discharge within 24h</i></b>");
  		
  		if(voCollInpatEpis != null)
  		{
  			for (int i=0; i < voCollInpatEpis.size() ; i++ )
  			{
  				InpatientEpisodeLiteVo voInpatEpis = voCollInpatEpis.get(i);
  				
  				if(voInpatEpis.isDischargeDueWithin24Hrs())
  			    {
  					if(voInpatEpis.getIsConfirmedDischargeIsNotNull() && voInpatEpis.getIsConfirmedDischarge())
  					{
  						patientRow = cellOutgoingConfirmedDischarge24h.getRow().getRows().newRow();			
  						patientRow.setSelectable(true);
  						DynamicGridCell cellPatientRow = patientRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);		
  						cellPatientRow.setAutoPostBack(true);
  						cellPatientRow.setBackColor(Color.Red);
  						cellPatientRow.setIdentifier(CURRENT);
  						cellPatientRow.setValue("<img src = " + form.getImages().Core.Person.getImagePath() + "> &nbsp;&nbsp;" +  voInpatEpis.getPatientString());
  						if (voInpatEpis.getPasEventIsNotNull())
  						{
  							patientRow.setValue(voInpatEpis.getPasEvent().getPatient());
  							patientRow.setIdentifier(voInpatEpis.getPasEvent());
  						}
  				    }
  			    }
  			}
  		}
  
  		
  		dynRow = cellPatient.getRow().getRows().newRow();
  		dynRow.setExpanded(true);
  		dynRow.setSelectable(false);
  		DynamicGridCell cellOutgoingTransfer = dynRow.getCells().newCell(getColumn(COLNAME), DynamicCellType.HTMLVIEW);				
  		cellOutgoingTransfer.setValue("<b><i>For Transfer Out</i></b>");
  		cellOutgoingTransfer.setBackColor(Color.Aqua);
  		
  		PendingTransfersLiteVoCollection voCollTransfersOut = form.getLocalContext().getTransfersOut();
  		if(voCollTransfersOut != null)
  		{
  