/** * On Grid Selection Changed event handler */ protected void onGrdTargetSelectionChanged() throws PresentationLogicException { // Get the latest information from domain if (form.grdTarget().getValue() instanceof PatientGoalRefVo) { form.getLocalContext().setSelectedRowValue(domain.getPatientGoal((PatientGoalRefVo) form.grdTarget().getValue())); form.getLocalContext().setSelectedPatientGoalVo((PatientGoalVo) form.getLocalContext().getSelectedRowValue()); populateInstanceControls((PatientGoalVo) form.getLocalContext().getSelectedRowValue(), null); } else if (form.grdTarget().getValue() instanceof PatientGoalTargetRefVo) { if (!(form.grdTarget().getSelectedRow().getParentRow().getValue() instanceof PatientGoalRefVo)) throw new CodingRuntimeException("Major logical error - A PatientGoalTarget must be child of a PatientGoal"); form.getLocalContext().setSelectedRowValue(domain.getPatientGoalTarget((PatientGoalTargetRefVo) form.grdTarget().getValue())); populateInstanceControls(domain.getPatientGoal((PatientGoalRefVo) form.grdTarget().getSelectedRow().getParentRow().getValue()), (PatientGoalTargetVo) form.getLocalContext().getSelectedRowValue()); } // Update controls state updateControlsState(); }
/** * Function used to update the context menu options visibility */ private void updateContextMenuState() { form.getContextMenus().getGenericGridAddItem().setVisible(FormMode.VIEW.equals(form.getMode())); // Determine the text on update option in context menu if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalRefVo) { form.getContextMenus().getGenericGridUpdateItem().setText("Edit"); } else if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalTargetRefVo) { form.getContextMenus().getGenericGridUpdateItem().setText("Edit Target"); } form.getContextMenus().getGenericGridUpdateItem().setVisible(FormMode.VIEW.equals(form.getMode()) && form.getLocalContext().getSelectedRowValueIsNotNull()); }
/** * Function used to populate grid, instance controls based on selection, set * form in VIEW mode */ public void open() throws PresentationLogicException { // Clear the screen clear(); // Populate grid populateGrid(domain.listPatientGoals(form.getGlobalContext().Core.getCurrentCareContext())); // Reselect value in grid form.grdTarget().setValue(form.getLocalContext().getSelectedRowValue()); // Reread from grid (just in case the local context in no longer in grid // - KEEP THIS LINE) form.getLocalContext().setSelectedRowValue(form.grdTarget().getValue()); // Populate instance controls // (we need to populate according to our selection) if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalRefVo) { populateInstanceControls(domain.getPatientGoal((PatientGoalRefVo) form.getLocalContext().getSelectedRowValue()), null); } else if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalTargetRefVo) { if (form.grdTarget().getSelectedRow() == null || form.grdTarget().getSelectedRow().getParentRow() == null || !(form.grdTarget().getSelectedRow().getParentRow().getValue() instanceof PatientGoalRefVo)) { throw new CodingRuntimeException("Major logical error - A PatientGoalTarget must be child of a PatientGoal"); } populateInstanceControls(domain.getPatientGoal((PatientGoalRefVo) form.grdTarget().getSelectedRow().getParentRow().getValue()), domain.getPatientGoalTarget((PatientGoalTargetRefVo) form.getLocalContext().getSelectedRowValue())); } else form.getLocalContext().setSelectedPatientGoalVo(null); // Set form mode to View form.setMode(FormMode.VIEW); }
/** * Function used to edit a PatientGoal or a PatientGoalTarget instance */ public void updateInstance() { if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalRefVo) { // Get PatientGoal object data from domain form.getLocalContext().setSelectedRowValue(domain.getPatientGoal((PatientGoalRefVo) form.getLocalContext().getSelectedRowValue())); // Populate instance controls with fresh data populateInstanceControls((PatientGoalVo) form.getLocalContext().getSelectedRowValue(), null); } else if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalTargetRefVo) { // Check for a valid value in parent row if (form.grdTarget().getSelectedRow() == null || form.grdTarget().getSelectedRow().getParentRow() == null || !(form.grdTarget().getSelectedRow().getParentRow().getValue() instanceof PatientGoalRefVo)) throw new CodingRuntimeException("Major Logical Error - PatientGoalTarget rows must have a PatientGoal target"); // Get parent PatientGoal object data from domain PatientGoalVo patientGoal = domain.getPatientGoal((PatientGoalRefVo) form.grdTarget().getSelectedRow().getParentRow().getValue()); // Get PatientGoalTarget object data from domain form.getLocalContext().setSelectedRowValue(domain.getPatientGoalTarget((PatientGoalTargetRefVo) form.getLocalContext().getSelectedRowValue())); // Populate instance controls with fresh data populateInstanceControls(patientGoal, (PatientGoalTargetVo) form.getLocalContext().getSelectedRowValue()); } // Set form in EDIT mode form.setMode(FormMode.EDIT); }
/** * Function used to get a PatientGoal from database */ public PatientGoalVo getPatientGoal(PatientGoalRefVo patientGoalRef) { // If no PatientGoalRefVo is provided or no ID is present return null if (patientGoalRef == null || !patientGoalRef.getID_PatientGoalIsNotNull()) return null; // Return PatientGoal based on ID return PatientGoalVoAssembler.create((PatientGoal) getDomainFactory().getDomainObject(PatientGoal.class, patientGoalRef.getID_PatientGoal())); }
/** * Function used to temporarily add a target to a goal */ private boolean addNewTargetToSelectedGoal() { // Not only the local context containing the selected object needs to be // a PatientGoal, // but also in the grid on the form a row must be selected, and that row // value must be of type PatientGoal // Check for a selected PatientGoal if (!(form.getLocalContext().getSelectedRowValue() instanceof PatientGoalVo)) throw new CodingRuntimeException("Major Logical Error - Can only add a PatientGoalTarget to a PatientGoal"); // Check for a selected row if (form.grdTarget().getSelectedRow() != null && !(form.grdTarget().getSelectedRow().getValue() instanceof PatientGoalRefVo)) throw new CodingRuntimeException("Major Logical Error - Can only add a PatientGoalTarget to a selected Patient Goal"); // Get a PatientGoalTargetVo from screen data PatientGoalTargetVo patientGoalTarget = populatePatientGoalTargetFromScreen(); // Validate PatientGoalTarget VO obtained from screen data String[] errors = patientGoalTarget.validate(); if (errors != null && errors.length > 0) { engine.showErrors(errors); return false; } // Add a child row to currently selected row with PatientGoalTarget // value grdTargetRow newRow = form.grdTarget().getSelectedRow().getRows().newRow(); setPatientGoalTargetRow(newRow, patientGoalTarget); // Set background color for new row newRow.setBackColor(Color.Bisque); // Get PatientGoalVo from local context PatientGoalVo patientGoal = (PatientGoalVo) form.getLocalContext().getSelectedRowValue(); // Check PatientGoal target collection - create a new collection if need // to if (!patientGoal.getTargetIsNotNull()) { patientGoal.setTarget(new PatientGoalTargetVoCollection()); } // Add target to selected PatientGoal patientGoal.getTarget().add(patientGoalTarget); return true; }
/** * Function used to update the controls state */ public void updateControlsState() { // Set state of the container form.ctnGoals().setCollapsed(FormMode.VIEW.equals(form.getMode()) && !form.getLocalContext().getSelectedRowValueIsNotNull()); // Enable & select appropriate tabs form.ctnGoals().lyrGoals().Goal().setHeaderEnabled(true); form.ctnGoals().lyrGoals().Target().setHeaderEnabled(FormMode.VIEW.equals(form.getMode()) || form.getLocalContext().getSelectedRowValueIsNotNull()); if (form.getLocalContext().getSelectedRowValue() instanceof PatientGoalTargetRefVo) { form.ctnGoals().lyrGoals().showTarget(); } else { form.ctnGoals().lyrGoals().showGoal(); } // Set the state of 'Edit' button if (FormMode.VIEW.equals(form.getMode())) { form.btnEdit().setVisible(form.getLocalContext().getSelectedRowValueIsNotNull()); } else if (FormMode.EDIT.equals(form.getMode())) { boolean editPatientGoal = form.getLocalContext().getSelectedRowValue() instanceof PatientGoalRefVo; boolean editPatientGoalTarget = form.getLocalContext().getSelectedRowValue() instanceof PatientGoalTargetRefVo; // Goal tab controls form.ctnGoals().lyrGoals().Goal().cmbAreaOfNeed().setEnabled(!editPatientGoalTarget); form.ctnGoals().lyrGoals().Goal().cmbGoalType().setEnabled(!editPatientGoalTarget); form.ctnGoals().lyrGoals().Goal().txtGoal().setEnabled(!editPatientGoalTarget); form.ctnGoals().lyrGoals().Goal().dtimCreated().setEnabled(!editPatientGoalTarget); form.ctnGoals().lyrGoals().Goal().qmbAuthoringHCP().setEnabled(!editPatientGoalTarget); form.ctnGoals().lyrGoals().Goal().dteAchieved().setEnabled(!editPatientGoalTarget); // Target tab controls form.ctnGoals().lyrGoals().Target().txtTarget().setEnabled(editPatientGoal || editPatientGoalTarget); form.ctnGoals().lyrGoals().Target().cmbLOA().setEnabled(editPatientGoal || editPatientGoalTarget); form.ctnGoals().lyrGoals().Target().txtReasonNonA().setEnabled(editPatientGoal || editPatientGoalTarget); form.ctnGoals().lyrGoals().Target().dteTargetDate().setEnabled(editPatientGoal || editPatientGoalTarget); form.ctnGoals().lyrGoals().Target().dteAchievedDate().setEnabled(editPatientGoal || editPatientGoalTarget); // Target tab buttons form.ctnGoals().lyrGoals().Target().btnAdd().setVisible(editPatientGoal); form.ctnGoals().lyrGoals().Target().btnClear().setVisible(editPatientGoal); } // Call function to update context menu updateContextMenuState(); }