/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/Nursing/src/ims/nursing/forms/bradenscaleview/Logic.java
//#############################################################################
//#                                                                           #
//#  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 Rory Fitzpatrick using IMS Development Environment (version 1.18 build 40628.1300)
// Copyright (C) 1995-2004 IMS MAXIMS plc. All rights reserved.

package ims.nursing.forms.bradenscaleview;

import java.util.ArrayList;
import com.ims.query.builder.client.QueryBuilderClient;
import com.ims.query.builder.client.SeedValue;
import com.ims.query.builder.client.exceptions.QueryBuilderClientException;
import ims.coe.vo.RiskAssessment;
import ims.coe.vo.RiskAssessmentCollection;
import ims.coe.vo.RiskDescription;
import ims.configuration.gen.ConfigFlag;
import ims.core.vo.PatientShort;
import ims.nursing.helper.RiskAssessmentHelper;
import ims.nursing.vo.BradenScale;
import ims.nursing.vo.BradenScaleCollection;
import ims.nursing.vo.BradenScaleDetailsCollection;
import ims.nursing.vo.BradenScaleSearchCriteriaVo;
import ims.domain.exceptions.DomainInterfaceException;
import ims.framework.FormName;
import ims.framework.enumerations.DialogResult;
import ims.framework.exceptions.PresentationLogicException;
import ims.framework.utils.Color;
import ims.framework.utils.Date;

public class Logic extends BaseLogic
{
	private final static String	LAST_WEEK		= "1";
	private final static String	LAST_MONTH		= "2";
	private final static String	LAST_YEAR		= "3";
	private final static String	ALL				= "4";
	private final static int	INDEX_ROW_DT	= 0;
	private final static int	INDEX_ROW_HCP	= 1;
	private final static int	NUM_COLS		= 5;

	protected void onFormOpen() throws ims.framework.exceptions.FormOpenException
	{
		
		form.imgCopyright().setValue(form.getImages().Core.Copyright);
		getBradenAssessment();

		form.cmbFilter().clear();
		form.cmbFilter().newRow(LAST_WEEK, "Within the last week");
		form.cmbFilter().newRow(LAST_MONTH, "Within the last month");
		form.cmbFilter().newRow(LAST_YEAR, "Within the last year");
		form.cmbFilter().newRow(ALL, "All");

		//WDEV-19389 --- start
		if (!(form.getGlobalContext().Core.getCurrentCareContextIsNotNull() && form.getGlobalContext().Nursing.getBradenScaleSearchCriteriaIsNotNull() && form.getGlobalContext().Nursing.getBradenScaleSearchCriteria().getCareContextIsNotNull() && form.getGlobalContext().Core.getCurrentCareContext().equals(form.getGlobalContext().Nursing.getBradenScaleSearchCriteria().getCareContext())))
			form.getGlobalContext().Nursing.setBradenScaleSearchCriteria(null);
		
		if(form.getGlobalContext().Nursing.getBradenScaleSearchCriteriaIsNotNull())
		{
			setSearchCriteria(form.getGlobalContext().Nursing.getBradenScaleSearchCriteria());
		}
		else
			form.cmbFilter().setValue(LAST_WEEK);
		//WDEV-19389 --- end
		
		filterValueChanged();
		
		try
		{
			String url = RiskAssessmentHelper.getUrlFromConfig("bradenscale.xml");
			
			if(url != null && url.length() > 0)
			{
				form.imbLink().setVisible(true);
				form.imbLink().setTooltip(url);
				form.getLocalContext().setUrl(url);
			}
			else
			{
				form.imbLink().setVisible(false);
			}
		}
		catch (PresentationLogicException e)
		{
			throw new ims.framework.exceptions.FormOpenException("Error parsing 'bradenscale.xml' file: " + e.toString());
		}
		
		updateControlsState();
	}

	private BradenScaleSearchCriteriaVo getSearchCriteria()
	{
		BradenScaleSearchCriteriaVo searchCriteria = new BradenScaleSearchCriteriaVo();
		
		searchCriteria.setFilter(form.cmbFilter().getValue());
		searchCriteria.setCareContext(form.getGlobalContext().Core.getCurrentCareContext());
		
		return searchCriteria;
	}
	
	
	private void setSearchCriteria(BradenScaleSearchCriteriaVo bradenScaleSearchCriteriaVo)
	{
		form.cmbFilter().setValue(bradenScaleSearchCriteriaVo.getFilter());	
		filterValueChanged();
		updateControlsState();
	}
	
	private void filterValueChanged()
	{
		//WDEV-2446 
		if (form.cmbFilter().getValue() != null)
		{
			BradenScaleCollection bradens = null;
			Date dateFrom = null;
			Date dateTo = null;
	
			if (form.cmbFilter().getValue().equals(LAST_WEEK))
			{
				dateFrom = new Date();
				dateFrom.addDay(-7);
				// dateTo = new Date();
			}
			else if (form.cmbFilter().getValue().equals(LAST_MONTH))
			{
				dateFrom = new Date();
				dateFrom.addDay(-31);
				// dateTo = new Date();
			}
			else if (form.cmbFilter().getValue().equals(LAST_YEAR))
			{
				dateFrom = new Date();
				dateFrom.addDay(-365);
				// dateTo = new Date();
			}
			
			try
			{
				bradens = domain.listAssessments(dateFrom, dateTo, form.getGlobalContext().Core.getCurrentCareContext());
			}
			catch (DomainInterfaceException e)
			{
				engine.showMessage(e.getMessage());
			}
	
			form.getLocalContext().setBradenAssessments(bradens);
			form.getLocalContext().setGroupIndex(new Integer(0));
	
			populateScreenFromData();
	
			try
			{
				onCmbRecordToUpdateValueChanged();
			}
			catch (PresentationLogicException e1)
			{
				engine.showMessage(e1.getMessage());
			}
			form.getGlobalContext().Nursing.setBradenScaleSearchCriteria(getSearchCriteria());//WDEV-19389 
		}
		else
		{
			clearGridRows();
			form.cmbRecordToUpdate().clear();
			form.cmbRecordToUpdate().setValue(null);
			
			form.getLocalContext().setBradenAssessments(new BradenScaleCollection());
			form.getLocalContext().setGroupIndex(new Integer(0));
	
			populateScreenFromData();
			form.getGlobalContext().Nursing.setBradenScaleSearchCriteria(null);//WDEV-19389 
		}
		
	}

	protected void onBtnNewClick() throws PresentationLogicException
	{
		form.getGlobalContext().COE.setAddNew(Boolean.TRUE);
		form.getGlobalContext().COE.setBradenScaleRecord(null);
		engine.open(form.getForms().Nursing.BradenScaleDialog, "Add new Braden Scale Assessment");
	}

	protected void onBtnUpdateClick() throws PresentationLogicException
	{
		if (form.cmbRecordToUpdate().getValue() == null)
		{
			engine.showMessage("Please select a record to update !");
			return;
		}
		form.getGlobalContext().COE.setAddNew(Boolean.FALSE);
		form.getGlobalContext().COE.setBradenScaleRecord(form.cmbRecordToUpdate().getValue());
		engine.open(form.getForms().Nursing.BradenScaleDialog, "Edit assessment");
	}

	protected void onBtnNextClick() throws PresentationLogicException
	{
		form.getLocalContext().setGroupIndex(new Integer(form.getLocalContext().getGroupIndex().intValue() + 1));
		populateScreenFromData();
		updateControlsState();
	}

	protected void onBtnPrevClick() throws PresentationLogicException
	{
		if (form.getLocalContext().getGroupIndex().intValue() == 0)
			return;

		form.getLocalContext().setGroupIndex(new Integer(form.getLocalContext().getGroupIndex().intValue() - 1));
		populateScreenFromData();
		updateControlsState();
	}

	protected void onCmbFilterValueChanged() throws PresentationLogicException
	{
		filterValueChanged();
		updateControlsState();
	}

	private void updateControlsState() 
	{
		form.btnUpdate().setEnabled(form.cmbRecordToUpdate().getValue() != null);
		form.btnPrint().setEnabled(form.cmbRecordToUpdate().getValue() != null);
	}

	protected void onFormDialogClosed(FormName formName, DialogResult result) throws PresentationLogicException
	{
		if (result.equals(DialogResult.OK) && formName.equals(form.getForms().Core.Reports))
		{
			printReport();
		}
		else if (result.equals(DialogResult.OK) && formName.equals(form.getForms().Nursing.BradenScaleDialog))
			filterValueChanged();
		
		updateControlsState();
	}

	private boolean getBradenAssessment()
	{
		RiskAssessmentCollection risks = form.getGlobalContext().COE.getBradenAssessments();

		if (risks == null)
		{
			try
			{
				risks = ims.nursing.helper.RiskAssessmentHelper.getBSRisks();
			}
			catch (PresentationLogicException e)
			{
				engine.showMessage(e.getMessage());
				return false;
			}
			form.getGlobalContext().COE.setBradenAssessments(risks);
		}

		form.gridBraden().getRows().clear();
		// Date/time
		GenForm.gridBradenRow row = form.gridBraden().getRows().newRow();
		row.setColFall("Date/Time");
		row.setBold(true);
		row.setBackColor(Color.Beige);
		row = form.gridBraden().getRows().newRow();
		row.setColFall("HCP");
		row.setBold(true);
		row.setBackColor(Color.Beige);

		form.gridAssessments().getRows().clear();
		GenForm.gridAssessmentsRow ar = form.gridAssessments().getRows().newRow();
		ar.setBold(true);
		ar.setBackColor(Color.Beige);
		ar = form.gridAssessments().getRows().newRow();
		ar.setBold(true);
		ar.setBackColor(Color.Beige);

		for (int i = 0; i < risks.size(); i++)
		{
			RiskAssessment risk = risks.get(i);

			row = form.gridBraden().getRows().newRow();
			row.setColFall(risk.getName());

			ar = form.gridAssessments().getRows().newRow();
		}

		row = form.gridBraden().getRows().newRow();
		row.setColFall("TOTAL");
		row.setTooltip("<b>Very Low risk:</b> > 18<br> <b>At risk:</b> 15-18<br><b>Moderate risk:</b> 13-14<br><b>High risk:</b> 10-12<br><b>Very High risk:</b> < 9");
		row.setBold(true);
		row.setBackColor(Color.Beige);

		ar = form.gridAssessments().getRows().newRow();
		ar.setBold(true);
		ar.setBackColor(Color.Beige);

		return true;
	}

	private void populateScreenFromData()
	{
		int nScore;
		int nTotalScore = 0;

		BradenScaleCollection falls = form.getLocalContext().getBradenAssessments();

		clearGridRows();
		form.cmbRecordToUpdate().clear();

		if (form.getLocalContext().getBradenIdsIsNotNull())
			form.getLocalContext().getBradenIds().clear();
		else
			form.getLocalContext().setBradenIds(new ArrayList());

		int startIndex = form.getLocalContext().getGroupIndex().intValue() * NUM_COLS;
		int endIndex = startIndex + NUM_COLS <= falls.size() ? startIndex + NUM_COLS : falls.size();

		GenForm.gridAssessmentsRow row;
		for (int i = startIndex; i < endIndex; i++)
		{
			form.cmbRecordToUpdate().newRow(falls.get(i), (falls.get(i).getDateTimeInitiated() == null ? "-" : falls.get(i).getDateTimeInitiated().toString()) + ", " + (falls.get(i).getHcpInitiated() == null ? "-" : falls.get(i).getHcpInitiated().getName().toString()));
			form.getLocalContext().getBradenIds().add(falls.get(i).getID_Assessment());
			//form.btnPrint().setEnabled(true);
		}

		int ix = startIndex;

		// first record
		if (ix < endIndex)
		{
			nTotalScore = 0;

			row = form.gridAssessments().getRows().get(INDEX_ROW_DT);
			row.setColAss1(falls.get(ix).getDateTimeInitiated() != null ? falls.get(ix).getDateTimeInitiated().toString() : "");
			row = form.gridAssessments().getRows().get(INDEX_ROW_HCP);
			row.setColAss1(falls.get(ix).getHcpInitiated() != null ? falls.get(ix).getHcpInitiated().getName().toString() : "");

			for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
			{
				// both grids must have the same number of rows
				row = form.gridAssessments().getRows().get(i + INDEX_ROW_HCP + 1);

				nScore = getScoreByAssessmentName(form.gridBraden().getRows().get(i + INDEX_ROW_HCP + 1).getColFall(), falls.get(ix).getAssessmentDetails());
				nTotalScore += nScore;
				row.setColAss1(String.valueOf(nScore));
			}

			// the total
			row = form.gridAssessments().getRows().get(form.gridAssessments().getRows().size() - 1);
			row.setColAss1(String.valueOf(nTotalScore));

			ix++;
		}

		// second record
		if (ix < endIndex)
		{
			nTotalScore = 0;

			row = form.gridAssessments().getRows().get(INDEX_ROW_DT);
			row.setColAss2(falls.get(ix).getDateTimeInitiated() != null ? falls.get(ix).getDateTimeInitiated().toString() : "");
			row = form.gridAssessments().getRows().get(INDEX_ROW_HCP);
			row.setColAss2(falls.get(ix).getHcpInitiated() != null ? falls.get(ix).getHcpInitiated().getName().toString() : "");

			for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
			{
				// both grids must have the same number of rows
				row = form.gridAssessments().getRows().get(i + INDEX_ROW_HCP + 1);

				nScore = getScoreByAssessmentName(form.gridBraden().getRows().get(i + INDEX_ROW_HCP + 1).getColFall(), falls.get(ix).getAssessmentDetails());
				nTotalScore += nScore;
				row.setColAss2(String.valueOf(nScore));
			}

			// the total
			row = form.gridAssessments().getRows().get(form.gridAssessments().getRows().size() - 1);
			row.setColAss2(String.valueOf(nTotalScore));

			ix++;
		}

		// third record
		if (ix < endIndex)
		{
			nTotalScore = 0;

			row = form.gridAssessments().getRows().get(INDEX_ROW_DT);
			row.setColAss3(falls.get(ix).getDateTimeInitiated() != null ? falls.get(ix).getDateTimeInitiated().toString() : "");
			row = form.gridAssessments().getRows().get(INDEX_ROW_HCP);
			row.setColAss3(falls.get(ix).getHcpInitiated() != null ? falls.get(ix).getHcpInitiated().getName().toString() : "");

			for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
			{
				// both grids must have the same number of rows
				row = form.gridAssessments().getRows().get(i + INDEX_ROW_HCP + 1);

				nScore = getScoreByAssessmentName(form.gridBraden().getRows().get(i + INDEX_ROW_HCP + 1).getColFall(), falls.get(ix).getAssessmentDetails());
				nTotalScore += nScore;
				row.setColAss3(String.valueOf(nScore));
			}

			// the total
			row = form.gridAssessments().getRows().get(form.gridAssessments().getRows().size() - 1);
			row.setColAss3(String.valueOf(nTotalScore));

			ix++;
		}

		// fourth record
		if (ix < endIndex)
		{
			nTotalScore = 0;

			row = form.gridAssessments().getRows().get(INDEX_ROW_DT);
			row.setColAss4(falls.get(ix).getDateTimeInitiated() != null ? falls.get(ix).getDateTimeInitiated().toString() : "");
			row = form.gridAssessments().getRows().get(INDEX_ROW_HCP);
			row.setColAss4(falls.get(ix).getHcpInitiated() != null ? falls.get(ix).getHcpInitiated().getName().toString() : "");

			for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
			{
				// both grids must have the same number of rows
				row = form.gridAssessments().getRows().get(i + INDEX_ROW_HCP + 1);

				nScore = getScoreByAssessmentName(form.gridBraden().getRows().get(i + INDEX_ROW_HCP + 1).getColFall(), falls.get(ix).getAssessmentDetails());
				nTotalScore += nScore;
				row.setColAss4(String.valueOf(nScore));
			}

			// the total
			row = form.gridAssessments().getRows().get(form.gridAssessments().getRows().size() - 1);
			row.setColAss4(String.valueOf(nTotalScore));

			ix++;
		}

		// fifth record
		if (ix < endIndex)
		{
			nTotalScore = 0;

			row = form.gridAssessments().getRows().get(INDEX_ROW_DT);
			row.setColAss5(falls.get(ix).getDateTimeInitiated() != null ? falls.get(ix).getDateTimeInitiated().toString() : "");
			row = form.gridAssessments().getRows().get(INDEX_ROW_HCP);
			row.setColAss5(falls.get(ix).getHcpInitiated() != null ? falls.get(ix).getHcpInitiated().getName().toString() : "");

			for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
			{
				// both grids must have the same number of rows
				row = form.gridAssessments().getRows().get(i + INDEX_ROW_HCP + 1);

				nScore = getScoreByAssessmentName(form.gridBraden().getRows().get(i + INDEX_ROW_HCP + 1).getColFall(), falls.get(ix).getAssessmentDetails());
				nTotalScore += nScore;
				row.setColAss5(String.valueOf(nScore));
			}

			// the total
			row = form.gridAssessments().getRows().get(form.gridAssessments().getRows().size() - 1);
			row.setColAss5(String.valueOf(nTotalScore));

			ix++;
		}

		// enable/disable Prev/Next buttons
		if (form.getLocalContext().getGroupIndex().intValue() > 0)
			form.btnPrev().setEnabled(true);
		else
			form.btnPrev().setEnabled(false);

		if (endIndex >= falls.size())
			form.btnNext().setEnabled(false);
		else
			form.btnNext().setEnabled(true);

		String legend;

		if (falls.size() > 0)
			legend = "<B><CENTER>Rec. " + String.valueOf(form.getLocalContext().getGroupIndex().intValue() * NUM_COLS + 1) + "-" + String.valueOf(endIndex) + " of " + String.valueOf(falls.size()) + "</CENTER></B>";
		else
			legend = "<B><CENTER>No records</CENTER></B>";

		form.htmLegend().setHTML(legend);
	}

	private void clearGridRows()
	{
		for (int i = 0; i < form.gridAssessments().getRows().size(); i++)
		{
			GenForm.gridAssessmentsRow row = form.gridAssessments().getRows().get(i);

			row.setColAss1("");
			row.setColAss2("");
			row.setColAss3("");
			row.setColAss4("");
			row.setColAss5("");
			row.setValue(null);
		}
	}

	private int getScoreByAssessmentName(String colFall, BradenScaleDetailsCollection assessmentDetails)
	{
		int nScore = 0;

		RiskAssessment risk;
		RiskDescription descr;

		for (int i = 0; i < form.getGlobalContext().COE.getBradenAssessments().size(); i++)
		{
			risk = form.getGlobalContext().COE.getBradenAssessments().get(i);

			if (risk.getName().equalsIgnoreCase(colFall))
			{
				for (int j = 0; j < risk.getRiskFactors().size(); j++)
				{
					descr = risk.getRiskFactors().get(j);

					for (int k = 0; k < assessmentDetails.size(); k++)
					{
						if (assessmentDetails.get(k).getAssessment().toString().equals(descr.getId()) && assessmentDetails.get(k).getSelect().equals(Boolean.TRUE))
						{
							nScore += Integer.valueOf(descr.getScore()).intValue();
						}
					}
				}

				break;
			}
		}

		return nScore;
	}

	protected void onCmbRecordToUpdateValueChanged() throws PresentationLogicException
	{
		updateControlsState();
		
		try
		{
			if (domain.isPartOfSkinAssessment(form.cmbRecordToUpdate().getValue()) == Boolean.TRUE)
				form.btnUpdate().setText("View");
			else
				form.btnUpdate().setText("Edit");
		}
		catch (DomainInterfaceException e)
		{
			engine.showMessage("Error retrieving skin assessment record: " + e.getMessage());
			return;
		}
		
		form.getLocalContext().setSelectedRecord(form.cmbRecordToUpdate().getValue());
	}

	protected void onBtnPrintClick() throws PresentationLogicException
	{
		// form.getGlobalContext().COE.setBradenScaleRecord(form.cmbRecordToUpdate().getValue());
		// engine.open(form.getForms().COE.RptBradenScale);
		engine.open(form.getForms().Core.Reports);
	}

	private void printReport()
	{
		BradenScale braden = form.cmbRecordToUpdate().getValue();

		if (braden == null)
			return;

		int nCol = -1;
		ArrayList ids = form.getLocalContext().getBradenIds();

		for (int i = 0; i < ids.size(); i++)
		{
			if (braden.getID_Assessment().equals(ids.get(i)))
			{
				nCol = i;
				break;
			}
		}

		if (nCol == -1)
		{
			engine.showMessage("Internal error, could not find the Braden record to print !");
			return;
		}

		String urlQueryServer = ConfigFlag.GEN.QUERY_SERVER_URL.getValue();
		String urlReportServer = ConfigFlag.GEN.REPORT_SERVER_URL.getValue();

		String[] obj = null;
		try
		{
			obj = domain.getReportAndTemplate(form.getGlobalContext().Core.getReportID(), form.getGlobalContext().Core.getTemplateID());
		}
		catch (DomainInterfaceException e)
		{
			engine.showMessage("Error retrieving report template !\r\n" + e.getMessage());
			return;
		}

		if (obj == null || obj.length == 0)
		{
			engine.showMessage("I could not get the report and template !");
			return;
		}

		PatientShort ps = form.getGlobalContext().Core.getPatientShort();
		QueryBuilderClient client = new QueryBuilderClient(urlQueryServer, engine.getSessionId());

		client.addSeed(new SeedValue("BRADEN_ID", braden.getID_Assessment(), Integer.class));
		if (ps != null)
		{
			// client.addSeed(new SeedValue("PID", ps.getHospnum().getValue(),
			// String.class));
			ims.core.vo.PatientId id = ps.getDisplayId();
			if (id != null)
			{
				client.addSeed(new SeedValue("PID", id.getValue(), String.class));
			}

			client.addSeed(new SeedValue("AGE", ps.getAge(), Integer.class));
		}

		addExtraSeeds(nCol, client, ps.getAge());

		String resultUrl = "";

		try
		{
			resultUrl = client.buildReportAsUrl(obj[0], obj[1], urlReportServer, QueryBuilderClient.PDF, "", 1);
		}
		catch (QueryBuilderClientException e1)
		{
			engine.showMessage("Error creating report: " + e1.getMessage());
			return;
		}

		engine.openUrl(resultUrl);
	}

	private void addExtraSeeds(int nCol, QueryBuilderClient client, Integer age)
	{
		String hr = "";
		String mr = "";
		String lr = "";

		int nScore = -1;

		if (nCol == 0)
		{
			client.addSeed(new SeedValue("A", form.gridAssessments().getRows().get(2).getColAss1(), String.class));
			client.addSeed(new SeedValue("B", form.gridAssessments().getRows().get(3).getColAss1(), String.class));
			client.addSeed(new SeedValue("C", form.gridAssessments().getRows().get(4).getColAss1(), String.class));
			client.addSeed(new SeedValue("D", form.gridAssessments().getRows().get(5).getColAss1(), String.class));
			client.addSeed(new SeedValue("E", form.gridAssessments().getRows().get(6).getColAss1(), String.class));
			client.addSeed(new SeedValue("F", form.gridAssessments().getRows().get(7).getColAss1(), String.class));

			client.addSeed(new SeedValue("TOTAL_SCORE", form.gridAssessments().getRows().get(8).getColAss1(), String.class));

			nScore = Integer.parseInt(form.gridAssessments().getRows().get(8).getColAss1());
		}
		else if (nCol == 1)
		{
			client.addSeed(new SeedValue("A", form.gridAssessments().getRows().get(2).getColAss2(), String.class));
			client.addSeed(new SeedValue("B", form.gridAssessments().getRows().get(3).getColAss2(), String.class));
			client.addSeed(new SeedValue("C", form.gridAssessments().getRows().get(4).getColAss2(), String.class));
			client.addSeed(new SeedValue("D", form.gridAssessments().getRows().get(5).getColAss2(), String.class));
			client.addSeed(new SeedValue("E", form.gridAssessments().getRows().get(6).getColAss2(), String.class));
			client.addSeed(new SeedValue("F", form.gridAssessments().getRows().get(7).getColAss2(), String.class));

			client.addSeed(new SeedValue("TOTAL_SCORE", form.gridAssessments().getRows().get(8).getColAss2(), String.class));

			nScore = Integer.parseInt(form.gridAssessments().getRows().get(8).getColAss2());
		}
		else if (nCol == 2)
		{
			client.addSeed(new SeedValue("A", form.gridAssessments().getRows().get(2).getColAss3(), String.class));
			client.addSeed(new SeedValue("B", form.gridAssessments().getRows().get(3).getColAss3(), String.class));
			client.addSeed(new SeedValue("C", form.gridAssessments().getRows().get(4).getColAss3(), String.class));
			client.addSeed(new SeedValue("D", form.gridAssessments().getRows().get(5).getColAss3(), String.class));
			client.addSeed(new SeedValue("E", form.gridAssessments().getRows().get(6).getColAss3(), String.class));
			client.addSeed(new SeedValue("F", form.gridAssessments().getRows().get(7).getColAss3(), String.class));

			client.addSeed(new SeedValue("TOTAL_SCORE", form.gridAssessments().getRows().get(8).getColAss3(), String.class));

			nScore = Integer.parseInt(form.gridAssessments().getRows().get(8).getColAss3());
		}
		else if (nCol == 3)
		{
			client.addSeed(new SeedValue("A", form.gridAssessments().getRows().get(2).getColAss4(), String.class));
			client.addSeed(new SeedValue("B", form.gridAssessments().getRows().get(3).getColAss4(), String.class));
			client.addSeed(new SeedValue("C", form.gridAssessments().getRows().get(4).getColAss4(), String.class));
			client.addSeed(new SeedValue("D", form.gridAssessments().getRows().get(5).getColAss4(), String.class));
			client.addSeed(new SeedValue("E", form.gridAssessments().getRows().get(6).getColAss4(), String.class));
			client.addSeed(new SeedValue("F", form.gridAssessments().getRows().get(7).getColAss4(), String.class));

			client.addSeed(new SeedValue("TOTAL_SCORE", form.gridAssessments().getRows().get(8).getColAss4(), String.class));

			nScore = Integer.parseInt(form.gridAssessments().getRows().get(8).getColAss4());
		}
		else if (nCol == 4)
		{
			client.addSeed(new SeedValue("A", form.gridAssessments().getRows().get(2).getColAss5(), String.class));
			client.addSeed(new SeedValue("B", form.gridAssessments().getRows().get(3).getColAss5(), String.class));
			client.addSeed(new SeedValue("C", form.gridAssessments().getRows().get(4).getColAss5(), String.class));
			client.addSeed(new SeedValue("D", form.gridAssessments().getRows().get(5).getColAss5(), String.class));
			client.addSeed(new SeedValue("E", form.gridAssessments().getRows().get(6).getColAss5(), String.class));
			client.addSeed(new SeedValue("F", form.gridAssessments().getRows().get(7).getColAss5(), String.class));

			client.addSeed(new SeedValue("TOTAL_SCORE", form.gridAssessments().getRows().get(8).getColAss5(), String.class));

			nScore = Integer.parseInt(form.gridAssessments().getRows().get(8).getColAss5());
		}

		if (nScore != -1)
		{
			if (nScore < 13)
				hr = "Yes";
			else if (nScore >= 13 && nScore <= 14)
				mr = "Yes";
			else if (age != null && age.intValue() <= 75 && nScore >= 15 && nScore <= 16)
				lr = "Yes";
			else if (age != null && age.intValue() > 75 && nScore >= 15 && nScore <= 18)
				lr = "Yes";
		}

		client.addSeed(new SeedValue("HR", hr, String.class));
		client.addSeed(new SeedValue("MR", mr, String.class));
		client.addSeed(new SeedValue("LR", lr, String.class));
	}

	protected void onImbLinkClick() throws PresentationLogicException
	{
		//engine.openUrl(form.imbLink().getTooltip());
		engine.openUrl(form.getLocalContext().getUrl());
	}
}
