/** * Copies an act item for each product referred to in its template. * * @param editor the editor * @param template the product template * @return the acts generated from the template */ protected List<Act> createTemplateActs(ActItemEditor editor, Product template) { List<Act> result = new ArrayList<>(); ActRelationshipCollectionPropertyEditor collection = getEditor(); IMObjectCopier copier = new IMObjectCopier(new ActItemCopyHandler()); Collection<TemplateProduct> includes = getProductIncludes(template, editor.getPatient()); Act act = (Act) editor.getObject(); Act copy = act; // replace the existing act with the first Date startTime = act.getActivityStartTime(); for (TemplateProduct include : includes) { if (copy == null) { // copy the act, and associate the product List<IMObject> objects = copier.apply(act); copy = (Act) objects.get(0); LayoutContext context = new DefaultLayoutContext(getContext()); context.setComponentFactory(new ReadOnlyComponentFactory(context)); editor = (ActItemEditor) createEditor(copy, context); // reset the start-time, which may have been set by the editor copy.setActivityStartTime(startTime); // create the component - must do this to ensure that the product editor is created editor.getComponent(); } setTemplateProduct(editor, template, include); collection.add(copy); collection.setEditor(copy, editor); setModified(copy, true); result.add(copy); copy = null; } return result; }
/** * Returns the set of acts being edited. * * @return the set of acts being edited. */ public List<Act> getActs() { ActRelationshipCollectionPropertyEditor collection = getEditor(); return new ArrayList<>(collection.getActs().keySet()); }