/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/Nursing/src/ims/nursing/forms/assessmentcareplans/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 Daniel Laffan using IMS Development Environment (version 1.20 build 40716.900)
// Copyright (C) 1995-2004 IMS MAXIMS plc. All rights reserved.

package ims.nursing.forms.assessmentcareplans;

import ims.framework.enumerations.SortOrder;
import ims.framework.exceptions.PresentationLogicException;
import ims.nursing.vo.AdmissionAssessmentVo;
import ims.nursing.vo.AssessmentComponentCarePlans;

public class Logic extends BaseLogic
{
	protected void onFormOpen() throws ims.framework.exceptions.FormOpenException
	{
		open();
	}

	private void open()
	{
		AdmissionAssessmentVo voAdmissionAssessment;
		voAdmissionAssessment = domain.getAdmissionAssessmentByCareContext(form.getGlobalContext().Core.getCurrentCareContext());
		
		if (voAdmissionAssessment != null)
			populateForm(voAdmissionAssessment);
	}

	private void populateForm(AdmissionAssessmentVo voAdmissionAssessment)
	{
		if(voAdmissionAssessment != null)
		{
			form.gridAssessment().getRows().clear();
			form.gridCarePlans().getRows().clear();
			
			GenForm.gridAssessmentRow row;
			
			row = form.gridAssessment().getRows().newRow();
			
			if (voAdmissionAssessment.getDateTimeInitiated() != null)
				row.setColAssessmentDate(voAdmissionAssessment.getDateTimeInitiated().toString());
			
			if (voAdmissionAssessment.getAssessmentType() != null)
				row.setColAssessmentType(voAdmissionAssessment.getAssessmentType().getText());
			
			if (voAdmissionAssessment.getHcpInitiated() != null)
				row.setColInitiationHCP(voAdmissionAssessment.getHcpInitiated().toString());
			
			row.setValue(voAdmissionAssessment);
			
			GenForm.gridCarePlansRow row1;
			AssessmentComponentCarePlans voAssessmentComponentCarePlans = null;
			
			if (voAdmissionAssessment.getComponentCarePlans() != null)
			{	
				for (int i=0; i<voAdmissionAssessment.getComponentCarePlans().size(); i++)
				{
					voAssessmentComponentCarePlans = voAdmissionAssessment.getComponentCarePlans().get(i);
					
					row1 = form.gridCarePlans().getRows().newRow();
					
					if (voAssessmentComponentCarePlans.getTitle() != null)
						row1.setcolTitle(voAssessmentComponentCarePlans.getTitle());
					
					if (voAssessmentComponentCarePlans.getAssessmentComponent().getComponentType() != null)
						row1.setcolAssessment(voAssessmentComponentCarePlans.getAssessmentComponent().getComponentType().getText());
					
					row1.setcolStatus(voAssessmentComponentCarePlans.getCurrentCarePlanStatus().getStatus().getText());
					row1.setValue(voAssessmentComponentCarePlans);
				}
			}
			form.gridCarePlans().sort(2, SortOrder.ASCENDING);
		}
	}

	protected void onGridAssessmentSelectionChanged() throws PresentationLogicException
	{
		populateForm(form.gridAssessment().getValue());
	}
}
