//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <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/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Florin Blindu using IMS Development Environment (version 1.80 build 4892.20548)
// Copyright (C) 1995-2013 IMS MAXIMS. All rights reserved.

package ims.emergency.forms.edwhiteboardeditdialog;

import ims.configuration.gen.ConfigFlag;
import ims.core.vo.lookups.HcpDisType;
import ims.domain.exceptions.StaleObjectException;
import ims.emergency.forms.edwhiteboardeditdialog.GenForm.grdAssessmentsRow;
import ims.emergency.vo.AttendanceClinicalNotesForWhiteBoardVo;
import ims.emergency.vo.PatientAssessmentForWhiteboardVo;
import ims.emergency.vo.PatientWhiteboardActionsVo;
import ims.emergency.vo.PatientWhiteboardActionsVoCollection;
import ims.emergency.vo.PatientWhiteboardRecordVo;
import ims.emergency.vo.TrackingForClinicianWorklistAndTriageVo;
import ims.emergency.vo.WhiteBoardAssessmentConfigVo;
import ims.emergency.vo.WhiteBoardConfigVo;
import ims.emergency.vo.WhiteBoardOtherActionsVo;
import ims.emergency.vo.lookups.AttendanceClinicalNoteType;
import ims.emergency.vo.lookups.WhiteBoardActionStatus;
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.interfaces.ILocation;
import ims.framework.utils.Image;

public class Logic extends BaseLogic
{
	private static final long serialVersionUID = 1L;
	
	private static final String	COLUMN_TYPE			= "0";
	private static final String	COLUMN_TOOLTIP			= "1";
	private static final String	COLUMN_ACTION	= "2";
	private static final String	COLUMN_SELECT			= "3";
	
	@Override
	protected void onFormOpen(Object[] args) throws ims.framework.exceptions.PresentationLogicException
	{
		
		form.getLocalContext().setSelectedPatientWhiteboard(domain.getPatientWhiteBoard(form.getGlobalContext().Core.getPatientShort(), form.getGlobalContext().Core.getCurrentCareContext()));
		initialize();
		open();
		
	}
	
	private void open()
	{
		populateInstanceControls(domain.getTracking(form.getGlobalContext().Emergency.getTracking()),form.getLocalContext().getSelectedPatientWhiteboard());
		updateControlsState();
	}	
	
	private void updateControlsState()
	{
		
	}
	private void populateInstanceControls(TrackingForClinicianWorklistAndTriageVo selectedTracking, PatientWhiteboardRecordVo selectedPatientWhiteboard)
	{
		if (selectedTracking==null)
			return;
		
		if (selectedTracking.getPatient() != null)
		{
			form.lblPatientNameValue().setValue(selectedTracking.getPatient().getName() != null ? selectedTracking.getPatient().getName().toString() : "");
			form.lblIDValue().setValue(selectedTracking.getPatient().getHospnum() != null ? selectedTracking.getPatient().getHospnum().getIdValue() : "");
		}
		
		ILocation currentLocation = engine.getCurrentLocation();
		
		form.lblLocationValue().setValue(currentLocation != null ? currentLocation.getName() : "");
		form.lblAreaValue().setValue(selectedTracking.getCurrentArea() != null ? selectedTracking.getCurrentArea().getAreaDisplayName() : "");
		form.lblPresentingComplain().setValue(selectedTracking.getEpisode() != null && selectedTracking.getEpisode().getPresentingComplaint() != null ? selectedTracking.getEpisode().getPresentingComplaint().getText() : "");
		
		if (form.dyngrdActions().isVisible())
		{
			populateActionsGridFromData(form.dyngrdActions(),form.getLocalContext().getSelectedPatientWhiteboard());
		}
		else
		{
			populateActionsGridFromData(form.dyngrdActionsBigger(),form.getLocalContext().getSelectedPatientWhiteboard());
		}
		
		form.richTextComment().setValue(form.getLocalContext().getSelectedPatientWhiteboard()!=null && form.getLocalContext().getSelectedPatientWhiteboard().getClinicalNote()!=null ? form.getLocalContext().getSelectedPatientWhiteboard().getClinicalNote().getClinicalNote(): null);
	}
	
	private void populateActionsGridFromData(DynamicGrid dynamicGrid, PatientWhiteboardRecordVo patientWhiteboardRecordVo)
	{
		if (patientWhiteboardRecordVo==null || patientWhiteboardRecordVo.getCurrentActions()==null || patientWhiteboardRecordVo.getCurrentActions().size()==0)
			return;
		
		for (int i=0;i<patientWhiteboardRecordVo.getCurrentActions().size();i++ )
		{
			PatientWhiteboardActionsVo currentAction = patientWhiteboardRecordVo.getCurrentActions().get(i);
			
			for (int j=0;j<dynamicGrid.getRows().size();j++ )
			{
				if (dynamicGrid.getRows().get(j).getValue() instanceof WhiteBoardOtherActionsVo && currentAction.getActionType().getOtherActionType().equals(((WhiteBoardOtherActionsVo)dynamicGrid.getRows().get(j).getValue()).getOtherActionType()))
				{
					dynamicGrid.getRows().get(j).getCells().get(getColumn(dynamicGrid,COLUMN_SELECT)).setValue(true);
					dynamicGrid.getRows().get(j).getCells().get(getColumn(dynamicGrid,COLUMN_ACTION)).setValue(getActionImageByStatus(currentAction.getActionStatus(),(WhiteBoardOtherActionsVo)dynamicGrid.getRows().get(j).getValue()));
					dynamicGrid.getRows().get(j).getCells().get(getColumn(dynamicGrid,COLUMN_ACTION)).setTooltip(currentAction.getActionStatus().getText());
					dynamicGrid.getRows().get(j).getCells().get(getColumn(dynamicGrid,COLUMN_ACTION)).setIdentifier(currentAction.getActionStatus());
					dynamicGrid.getRows().get(j).setValue(currentAction);
				}
			}
		}
		
	}

	private Image getActionImageByStatus(WhiteBoardActionStatus actionStatus, WhiteBoardOtherActionsVo whiteBoardOtherActionsVo)
	{
		if (WhiteBoardActionStatus.COMPLETED.equals(actionStatus))
		{
			return engine.getRegisteredImage(whiteBoardOtherActionsVo.getCompleteIcon().getID_AppImage());
		}
		else if (WhiteBoardActionStatus.REQUIRED.equals(actionStatus))
		{
			return engine.getRegisteredImage(whiteBoardOtherActionsVo.getRequiredIcon().getID_AppImage());
		}
		else 
		{
			return form.getImages().Emergency.Empty_Button_24;
		}
	}
	
	private DynamicGridColumn getColumn(DynamicGrid dyngrdActions, String identifier) 
	{
		return dyngrdActions.getColumns().getByIdentifier(identifier);
	}
	
	private void initialize()
	{
		form.lblComment().setVisible(form.getGlobalContext().Emergency.getWhiteBoardConfigIsNotNull() && form.getGlobalContext().Emergency.getWhiteBoardConfig().getComments());
		form.dyngrdActions().setVisible(form.getGlobalContext().Emergency.getWhiteBoardConfigIsNotNull() && form.getGlobalContext().Emergency.getWhiteBoardConfig().getComments());
		form.dyngrdActionsBigger().setVisible(!form.dyngrdActions().isVisible());
		form.richTextComment().setVisible(form.getGlobalContext().Emergency.getWhiteBoardConfigIsNotNull() && form.getGlobalContext().Emergency.getWhiteBoardConfig().getComments());
		form.richTextComment().setEnabled(form.getGlobalContext().Emergency.getWhiteBoardConfigIsNotNull() && form.getGlobalContext().Emergency.getWhiteBoardConfig().getComments());
		form.txtDummyCommentsRequired().setRequired(form.getGlobalContext().Emergency.getWhiteBoardConfigIsNotNull() && form.getGlobalContext().Emergency.getWhiteBoardConfig().getComments());
		
		populateAssessmentsGrid(form.getGlobalContext().Emergency.getWhiteBoardConfig());
		
		if (form.dyngrdActions().isVisible())
		{
			initializeActionsDynamicGrid(form.dyngrdActions());
			populateActionsDynGridInitially(form.dyngrdActions(),form.getGlobalContext().Emergency.getWhiteBoardConfig());
		}
		else
		{
			initializeActionsDynamicGrid(form.dyngrdActionsBigger());
			populateActionsDynGridInitially(form.dyngrdActionsBigger(),form.getGlobalContext().Emergency.getWhiteBoardConfig());
		}
		
		form.ccAuthoringInfo().initializeComponent();
		//form.richTextComment().setValue(null);
		
	}
	
	private void populateActionsDynGridInitially(DynamicGrid dyngrdActions, WhiteBoardConfigVo whiteBoardConfig)
	{
		dyngrdActions.getRows().clear();
		
		if (whiteBoardConfig==null)
			return;
		
		for (int i=0;whiteBoardConfig.getSelectedActions()!=null && i<whiteBoardConfig.getSelectedActions().size();i++)
		{
			addRowToActionsDyngrd(dyngrdActions,whiteBoardConfig.getSelectedActions().get(i));
		}
	}

	private void addRowToActionsDyngrd(DynamicGrid dyngrdActions, WhiteBoardOtherActionsVo whiteboardOtherAction)
	{
		if(	whiteboardOtherAction == null)
			return;
		
		DynamicGridRow row = dyngrdActions.getRows().newRow();
		row.setValue(whiteboardOtherAction);
		row.setIdentifier(whiteboardOtherAction);
		
		DynamicGridCell cellType = row.getCells().newCell(getColumn(dyngrdActions,COLUMN_TYPE), DynamicCellType.STRING);
		cellType.setValue(whiteboardOtherAction.getOtherActionType().getText());
		cellType.setTooltip(whiteboardOtherAction.getOtherActionType().getText());
		cellType.setReadOnly(true);
		
		DynamicGridCell cellTooltip = row.getCells().newCell(getColumn(dyngrdActions,COLUMN_TOOLTIP), DynamicCellType.STRING);
		cellTooltip.setValue(whiteboardOtherAction.getOtherActionTooltip());
		cellTooltip.setTooltip(whiteboardOtherAction.getOtherActionTooltip());
		cellTooltip.setReadOnly(true);
		
		DynamicGridCell cellAction = row.getCells().newCell(getColumn(dyngrdActions,COLUMN_ACTION), DynamicCellType.IMAGEBUTTON);
		cellAction.setValue(form.getImages().Emergency.Empty_Button_24);
		cellAction.setIdentifier(WhiteBoardActionStatus.NO_ACTION);
		cellAction.setTooltip(WhiteBoardActionStatus.NO_ACTION.getText());
		cellAction.setAutoPostBack(true);
		cellAction.setReadOnly(false);
		
		DynamicGridCell cellSelect = row.getCells().newCell(getColumn(dyngrdActions,COLUMN_SELECT), DynamicCellType.BOOL);
		cellSelect.setValue(false);
		
	}
	
	private void initializeActionsDynamicGrid(DynamicGrid dyngrdActions)
	{
		dyngrdActions.clear();
		
		DynamicGridColumn column = dyngrdActions.getColumns().newColumn("Type",COLUMN_TYPE);
		column.setWidth(270);
		column.setHeaderAlignment(Alignment.LEFT);
		column.setAlignment(Alignment.LEFT);
		
		column = dyngrdActions.getColumns().newColumn("Tooltip",COLUMN_TOOLTIP);
		column.setWidth(200);
		column.setHeaderAlignment(Alignment.LEFT);
		column.setAlignment(Alignment.LEFT);
			
		column = dyngrdActions.getColumns().newColumn("Action",COLUMN_ACTION);
		column.setWidth(80);
		column.setHeaderAlignment(Alignment.CENTER);
		column.setAlignment(Alignment.CENTER);

		column = dyngrdActions.getColumns().newColumn("Select",COLUMN_SELECT);
		column.setWidth(-1);
		column.setHeaderAlignment(Alignment.CENTER);
		column.setAlignment(Alignment.CENTER);
		
		dyngrdActions.setSelectable(false);
	}
	
	private void populateAssessmentsGrid(WhiteBoardConfigVo whiteBoardConfig)
	{
		form.grdAssessments().getRows().clear();
		if (whiteBoardConfig==null)
			return;
		
		for (int i=0;whiteBoardConfig.getAssessments()!=null && i<whiteBoardConfig.getAssessments().size();i++)
		{
			addRowToAssessmentsGrid(whiteBoardConfig.getAssessments().get(i));
		}
		
	}
	
	
	private void addRowToAssessmentsGrid(WhiteBoardAssessmentConfigVo whiteBoardAssessment)
	{
		if (whiteBoardAssessment==null)
			return;
		
		grdAssessmentsRow row = form.grdAssessments().getRows().newRow();
		
		row.setcolName(whiteBoardAssessment.getName());
		row.setTooltipForcolName(whiteBoardAssessment.getName());
		
		PatientAssessmentForWhiteboardVo patientAssessment=domain.getPatientAssessment(form.getGlobalContext().Core.getCurrentCareContext(), whiteBoardAssessment.getAssociatedAssessment());
		
		row.setcolScore(patientAssessment!=null && patientAssessment.getScore()!=null ? patientAssessment.getScore().toString() : null);
		row.setTooltipForcolScore(patientAssessment!=null && patientAssessment.getScore()!=null ? patientAssessment.getScore().toString() : null);
		
		row.setcolCompletionHcp(patientAssessment!=null && patientAssessment.getCompletedHCP()!=null  &&  patientAssessment.getCompletedHCP().getName()!=null ? patientAssessment.getCompletedHCP().getName().toString() : null);
		row.setTooltipForcolCompletionHcp(patientAssessment!=null && patientAssessment.getCompletedHCP()!=null  &&  patientAssessment.getCompletedHCP().getName()!=null ? patientAssessment.getCompletedHCP().getName().toString() : null);
		
		row.setcolCompletionDateTime(patientAssessment!=null && patientAssessment.getCompletedDateTime()!=null ? patientAssessment.getCompletedDateTime().toString() : null);
		row.setTooltipForcolCompletionDateTime(patientAssessment!=null && patientAssessment.getCompletedDateTime()!=null ? patientAssessment.getCompletedDateTime().toString() : null);
	}
	@Override
	protected void onBtnCancelClick() throws ims.framework.exceptions.PresentationLogicException
	{
		engine.close(DialogResult.ABORT);
	}
	@Override
	protected void onBtnSaveClick() throws ims.framework.exceptions.PresentationLogicException
	{
		if (save())
			engine.close(DialogResult.OK);
	}
	private boolean save()
	{
		PatientWhiteboardRecordVo patientWhiteBoardToSave=populateDataFromScreen(form.getLocalContext().getSelectedPatientWhiteboard());
		
		PatientWhiteboardRecordVo patientWhiteBoardExistent = domain.getPatientWhiteBoard(form.getGlobalContext().Core.getPatientShort(), form.getGlobalContext().Core.getCurrentCareContext());
		
		// Condition to create only one WhiteBoardConfiguration Per Area
		if (patientWhiteBoardExistent != null && patientWhiteBoardToSave.getID_PatientWhiteboardRecord()==null)
		{
			engine.showMessage("A Patient Whiteboard  for selected patient already exist. The screen will be refreshed");
			form.getLocalContext().setSelectedPatientWhiteboard(patientWhiteBoardExistent);
			open();
			return false;
		}
		
		
		String[] errors = patientWhiteBoardToSave.validate();
		
		if (errors != null && errors.length > 0)
		{
			engine.showErrors(errors);
			return false;
		}
		
		try
		{
			form.getLocalContext().setSelectedPatientWhiteboard(domain.savePatientWhiteBoard(patientWhiteBoardToSave));
		}
		catch (StaleObjectException e)
		{
			
			engine.showMessage(ConfigFlag.UI.STALE_OBJECT_MESSAGE.getValue());
			form.getLocalContext().setSelectedPatientWhiteboard(domain.getPatientWhiteBoard(form.getGlobalContext().Core.getPatientShort(), form.getGlobalContext().Core.getCurrentCareContext()));
			open();
			return false;
		}
		
		return true;
		
	}
	private PatientWhiteboardRecordVo populateDataFromScreen(PatientWhiteboardRecordVo patientWhiteboard)
	{
		if (patientWhiteboard==null)
			patientWhiteboard= new PatientWhiteboardRecordVo();
		else
			patientWhiteboard=(PatientWhiteboardRecordVo) patientWhiteboard.clone();
		
		patientWhiteboard.setPatient(form.getGlobalContext().Core.getPatientShort());
		patientWhiteboard.setAttendance(form.getGlobalContext().Core.getCurrentCareContext());
		patientWhiteboard.setEpisode(form.getGlobalContext().Core.getCurrentCareContext().getEpisodeOfCare());
		
		patientWhiteboard.setCurrentActions(form.dyngrdActions().isVisible() ? populateCurrentActionsDataFromScreen(form.dyngrdActions(),patientWhiteboard) : populateCurrentActionsDataFromScreen(form.dyngrdActionsBigger(),patientWhiteboard));
		
		patientWhiteboard.setAuthoringInformation(form.ccAuthoringInfo().getValue());
		
		patientWhiteboard.setClinicalNote(populateClinicalNoteFromScreen(patientWhiteboard.getClinicalNote()));
		
		return patientWhiteboard;
	}
	
	private AttendanceClinicalNotesForWhiteBoardVo populateClinicalNoteFromScreen(AttendanceClinicalNotesForWhiteBoardVo attendanceClinicalNotesForWhiteBoardVo)
	{
		if (!form.richTextComment().isVisible() || !form.richTextComment().isEnabled())
			return null;
		
		if (attendanceClinicalNotesForWhiteBoardVo==null)
			attendanceClinicalNotesForWhiteBoardVo = new AttendanceClinicalNotesForWhiteBoardVo();
		else
			attendanceClinicalNotesForWhiteBoardVo=(AttendanceClinicalNotesForWhiteBoardVo) attendanceClinicalNotesForWhiteBoardVo.clone();
		
		attendanceClinicalNotesForWhiteBoardVo.setPatient(form.getGlobalContext().Core.getPatientShort());
		attendanceClinicalNotesForWhiteBoardVo.setEpisode(form.getGlobalContext().Core.getCurrentCareContext().getEpisodeOfCare());
		attendanceClinicalNotesForWhiteBoardVo.setAttendance(form.getGlobalContext().Core.getCurrentCareContext());
		
		attendanceClinicalNotesForWhiteBoardVo.setAuthoringInformation(form.ccAuthoringInfo().getValue());
		attendanceClinicalNotesForWhiteBoardVo.setClinicalNote(form.richTextComment().getValue());
		attendanceClinicalNotesForWhiteBoardVo.setNoteType(AttendanceClinicalNoteType.WHITEBOARD_COMMENT);
		attendanceClinicalNotesForWhiteBoardVo.setDiscipline(HcpDisType.NURSING);
		
		return attendanceClinicalNotesForWhiteBoardVo;
	}
	
	private PatientWhiteboardActionsVoCollection populateCurrentActionsDataFromScreen(DynamicGrid dynamicGrid, PatientWhiteboardRecordVo patientWhiteboard)
	{
		PatientWhiteboardActionsVoCollection currentActions = new PatientWhiteboardActionsVoCollection();
		for (int i=0;i<dynamicGrid.getRows().size(); i++)
		{
			if ((Boolean)dynamicGrid.getRows().get(i).getCells().get(getColumn(dynamicGrid,COLUMN_SELECT)).getValue() == true)
			{
		
				if (dynamicGrid.getRows().get(i).getValue() instanceof PatientWhiteboardActionsVo)
				{
					PatientWhiteboardActionsVo tempCurrentAction = (PatientWhiteboardActionsVo) dynamicGrid.getRows().get(i).getValue();
					if (tempCurrentAction.getActionStatus().equals((WhiteBoardActionStatus)dynamicGrid.getRows().get(i).getCells().get(getColumn(dynamicGrid,COLUMN_ACTION)).getIdentifier()))
					{
						PatientWhiteboardActionsVo action = (PatientWhiteboardActionsVo) dynamicGrid.getRows().get(i).getValue();
						currentActions.add(action);
					}
					else
					{	
						PatientWhiteboardActionsVo action = createPatientWhiteboardActionsVo(dynamicGrid,dynamicGrid.getRows().get(i));
						currentActions.add(action);
				
						patientWhiteboard.setActionHistory(addActionToHistory(patientWhiteboard.getActionHistory(),action));	
					}
				}
				else if (dynamicGrid.getRows().get(i).getValue() instanceof WhiteBoardOtherActionsVo)
				{
					PatientWhiteboardActionsVo action = createPatientWhiteboardActionsVo(dynamicGrid,dynamicGrid.getRows().get(i));
					currentActions.add(action);
					
					patientWhiteboard.setActionHistory(addActionToHistory(patientWhiteboard.getActionHistory(),action));
				}
			}
		}
		
		return currentActions;
	}
	
	private PatientWhiteboardActionsVoCollection addActionToHistory(PatientWhiteboardActionsVoCollection actHistoryColl, PatientWhiteboardActionsVo action)
	{
		if (actHistoryColl==null)
			actHistoryColl= new PatientWhiteboardActionsVoCollection();
		else
			actHistoryColl=(PatientWhiteboardActionsVoCollection) actHistoryColl.clone();
		
		actHistoryColl.add(action);
		
		return actHistoryColl;
	}
	
	private PatientWhiteboardActionsVo createPatientWhiteboardActionsVo(DynamicGrid dynamicGrid, DynamicGridRow row)
	{
		PatientWhiteboardActionsVo patWhiteboardAction=new PatientWhiteboardActionsVo();
		
		patWhiteboardAction.setAuthoringInformation(form.ccAuthoringInfo().getValue());
		if (row.getValue() instanceof WhiteBoardOtherActionsVo)
		{
			patWhiteboardAction.setActionType((WhiteBoardOtherActionsVo) row.getValue());
		}
		else if (row.getValue() instanceof PatientWhiteboardActionsVo)
		{
			patWhiteboardAction.setActionType(((PatientWhiteboardActionsVo) row.getValue()).getActionType());
		}
		patWhiteboardAction.setActionStatus((WhiteBoardActionStatus) row.getCells().get(getColumn(dynamicGrid,COLUMN_ACTION)).getIdentifier());
		return patWhiteboardAction;
	}
	
	@Override
	protected void onDyngrdActionsCellButtonClicked(DynamicGridCell cell)
	{
		dynGridCellButtonClicked(form.dyngrdActions(),cell);
	}
	
	@Override
	protected void onDyngrdActionsBiggerCellButtonClicked(DynamicGridCell cell)
	{
		dynGridCellButtonClicked(form.dyngrdActionsBigger(),cell);
	}

	private void dynGridCellButtonClicked(DynamicGrid dynamicGrid, DynamicGridCell cell)
	{
		cell.getRow().getCells().get(getColumn(dynamicGrid, COLUMN_SELECT)).setValue(true);
		
		if (WhiteBoardActionStatus.NO_ACTION.equals((WhiteBoardActionStatus)cell.getIdentifier()))
		{
			cell.setIdentifier(WhiteBoardActionStatus.REQUIRED);
			cell.setTooltip(WhiteBoardActionStatus.REQUIRED.getText());
			
			if (cell.getRow().getValue() instanceof PatientWhiteboardActionsVo)
			{
				cell.setValue(engine.getRegisteredImage(((WhiteBoardOtherActionsVo)cell.getRow().getIdentifier()).getRequiredIcon().getID_AppImage()));
			}
			else if (cell.getRow().getValue() instanceof WhiteBoardOtherActionsVo)
			{
				cell.setValue(engine.getRegisteredImage(((WhiteBoardOtherActionsVo)cell.getRow().getValue()).getRequiredIcon().getID_AppImage()));
			}
		}
		else if (WhiteBoardActionStatus.REQUIRED.equals((WhiteBoardActionStatus)cell.getIdentifier()))
		{
			cell.setIdentifier(WhiteBoardActionStatus.COMPLETED);
			cell.setTooltip(WhiteBoardActionStatus.COMPLETED.getText());
			
			if (cell.getRow().getValue() instanceof PatientWhiteboardActionsVo)
			{
				cell.setValue(engine.getRegisteredImage(((WhiteBoardOtherActionsVo)cell.getRow().getIdentifier()).getCompleteIcon().getID_AppImage()));
			}
			else if (cell.getRow().getValue() instanceof WhiteBoardOtherActionsVo)
			{
				cell.setValue(engine.getRegisteredImage(((WhiteBoardOtherActionsVo)cell.getRow().getValue()).getCompleteIcon().getID_AppImage()));
			}
		}
		else if (WhiteBoardActionStatus.COMPLETED.equals((WhiteBoardActionStatus)cell.getIdentifier()))
		{
			cell.setIdentifier(WhiteBoardActionStatus.NO_ACTION);
			cell.setTooltip(WhiteBoardActionStatus.NO_ACTION.getText());
			
			if (cell.getRow().getValue() instanceof PatientWhiteboardActionsVo)
			{
				cell.setValue(form.getImages().Emergency.Empty_Button_24);
			}
			else if (cell.getRow().getValue() instanceof WhiteBoardOtherActionsVo)
			{
				cell.setValue(form.getImages().Emergency.Empty_Button_24);
			}
		}
	}
}
