Example usage for org.apache.wicket MarkupContainer setOutputMarkupPlaceholderTag

List of usage examples for org.apache.wicket MarkupContainer setOutputMarkupPlaceholderTag

Introduction

In this page you can find the example usage for org.apache.wicket MarkupContainer setOutputMarkupPlaceholderTag.

Prototype

public final Component setOutputMarkupPlaceholderTag(final boolean outputTag) 

Source Link

Document

Render a placeholder tag when the component is not visible.

Usage

From source file:com.asptt.plongee.resa.wicket.page.admin.palanque.PalanqueForm.java

@SuppressWarnings("serial")
public PalanqueForm(String id, NavigationOriginePage originePage, final Palanque palanqueUpdate, Date dateMin,
        Date dateMax, final FeedbackPanel feedback) {

    super(id);//from   www  . j  a  va  2s  .c  om
    feedback.setOutputMarkupId(true);
    dateMini = dateMin;
    dateMaxi = dateMax;
    origPage = originePage;

    //Rcupration de la fiche de securite dans la session
    fs = ResaSession.get().getFicheSecurite();

    //init de la palanque
    if (null == palanqueUpdate) {
        this.palanque = new Palanque();
        this.palanque.setDatePlongee(fs.getDatePlongee());
        this.palanque.setNumero(fs.getNbPalanques() + 1);
    } else {
        this.palanque = palanqueUpdate;
        //methode pour initialiser les ChoiceRenderPlongeur de la palanque
        initPalanque(palanqueUpdate);
    }

    //initialisation des plongeurs  inscrire pour ne pas allez la chercher  chaque fois
    //        listPlongeursAInscrireForpalanque = ResaSession.get().getPlongeeService().initListPlongeursAInscrire(fs);
    listPlongeursAInscrireForpalanque = ResaSession.get().getListPlongeursAInscrire();

    //sauvegarde de la palanque en cas d'annulation de modification
    //TODO - se servir de l'implementation de la methode clone
    final Palanque palanqueSAV = new Palanque(palanque);

    //sauvegarde des plongeursAInscrire en cas d'annulation de modification
    final List<ChoiceRenderPlongeur> plongeursAInscrireSAV = new ArrayList<ChoiceRenderPlongeur>();
    if (null != ResaSession.get().getListPlongeursAInscrire()) {
        plongeursAInscrireSAV.addAll(ResaSession.get().getListPlongeursAInscrire());
    }

    final CompoundPropertyModel<Palanque> modelPalanque = new CompoundPropertyModel<Palanque>(palanque);
    setModel(modelPalanque);

    add(new Label("messageNumPalanque", new StringResourceModel(
            CatalogueMessages.SAISIE_PALANQUE_MSG_NUM_PALANQUE, this, new Model<Palanque>(palanque))));

    // Ajout de la checkbox Bapteme
    AjaxCheckBox checkBox = new AjaxCheckBox("bapteme", new PropertyModel(modelPalanque, "isBapteme")) {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            //                getIsBapteme = this.getModelObject();
            //                logger.info("value of getIsBapteme = "+this.getModelObject().toString());
            //                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    };
    add(checkBox);

    //----------------------Le Choix des plongeurs ------------------------
    final IModel<ChoiceRenderPlongeur> ddcModel = new PropertyModel<ChoiceRenderPlongeur>(this,
            "selectedPlongeur");
    final DropDownChoice ddc = new DropDownChoice<ChoiceRenderPlongeur>("listPlongeurs",
            //                new PropertyModel(this, "selectedPlongeur"),
            ddcModel, listPlongeursAInscrireForpalanque, new PlongeurChoiceRenderer("value", "key")) {
        @Override
        protected boolean wantOnSelectionChangedNotifications() {
            return true;
        }

        @Override
        protected void onSelectionChanged(ChoiceRenderPlongeur newSelection) {
            setSelectedPlongeur(ddcModel.getObject());
        }
    };

    ddc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    ddc.setOutputMarkupId(true);
    add(ddc);

    //--------------GUIGE----------------------- 
    final Label labelGuide = new Label("nomGuide", new PropertyModel(modelPalanque, "nomCompletGuide"));
    labelGuide.setOutputMarkupId(true);
    add(labelGuide);
    add(new IndicatingAjaxLink("valideGuide") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getGuide() != null) {
                //on a dja un guide de saisi, donc erreur et on fait rien
                error("Le guide  dj t saisi : " + getGuide().getValue()
                        + " Impossible d'en saisir un autre");
            } else if (null == getSelectedPlongeur()) {
                error("Vous devez d'abord slectionner un plongeur");
            } else {
                setGuide(getSelectedPlongeur());
                suppEntreeListPlongeursAInscrire(getGuide());
                setSelectedPlongeur(null);
                target.addComponent(labelGuide);
                target.addComponent(ddc);
            }
        }
    });
    final MarkupContainer containAptGuide = new WebMarkupContainer("containGuide");
    Label labelAptGuide = new Label("labelAptGuide", Model.of(new String("aptitude")));
    labelAptGuide.setOutputMarkupId(true);
    containAptGuide.add(labelAptGuide);
    TextField<String> valueAptPlongeur = new TextField<String>("aptitudePlongeur");
    valueAptPlongeur.setOutputMarkupId(true);
    containAptGuide.add(valueAptPlongeur);
    containAptGuide.add(new AjaxButton("validAptGuide") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque pp = (Palanque) form.getModelObject();
            if (null != pp.getAptitudePlongeur()) {
                ChoiceRenderPlongeur oldGuide = getSelectedPlongeur();
                Adherent adh = ResaSession.get().getAdherentService()
                        .rechercherAdherentParIdentifiantTous(getGuide().getKey());
                String key = adh.getNumeroLicense();
                String value = adh.getNom() + "  " + adh.getPrenom() + "  " + pp.getAptitudePlongeur();
                ChoiceRenderPlongeur newGuide = new ChoiceRenderPlongeur(key, value);
                //on met le plongeur modifi comme guide
                setGuide(newGuide);
                //On supprime "ancien" et "nouveau" plongeur des plongeurs  inscrire
                listPlongeursAInscrireForpalanque.remove(oldGuide);
                listPlongeursAInscrireForpalanque.remove(newGuide);
                //On redonne le choix dans la selection du plongeur
                setSelectedPlongeur(null);
                // on remet aptitudePlongeur  null pour la prochaine fois
                pp.setAptitudePlongeur(null);
            }
            containAptGuide.setVisible(!containAptGuide.isVisible());
            target.addComponent(labelGuide);
            target.addComponent(containAptGuide);
            target.addComponent(ddc);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });
    containAptGuide.setVisible(false);
    containAptGuide.setOutputMarkupId(true);
    containAptGuide.setOutputMarkupPlaceholderTag(true);
    add(containAptGuide);
    add(new IndicatingAjaxLink("modifierGuide") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getGuide() == null) {
                error("Le guide n'est pas saisi ");
            } else {
                containAptGuide.setVisible(!containAptGuide.isVisible());
                target.addComponent(labelGuide);
                target.addComponent(containAptGuide);
                target.addComponent(ddc);
            }
        }
    });
    add(new IndicatingAjaxLink("annulerGuide") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getGuide() == null) {
                error("Le guide n'est pas saisi ");
            } else {
                addEntreeListPlongeursAInscrire(getGuide());
                setGuide(null);
                setSelectedPlongeur(null);
                target.addComponent(labelGuide);
                target.addComponent(ddc);
            }
        }
    });
    //--------------PLONGEUR1----------------------- 
    final Label labelPlongeur1 = new Label("nomPlongeur1",
            new PropertyModel(modelPalanque, "nomCompletPlongeur1"));
    labelPlongeur1.setOutputMarkupId(true);
    add(labelPlongeur1);
    add(new IndicatingAjaxLink("validePlongeur1") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur1() != null) {
                //on a dja un Plongeur1 de saisi, donc erreur et on fait rien
                error("Le Plongeur1  dj t saisi : " + getPlongeur1().getValue()
                        + " Impossible d'en saisir un autre");
            } else if (null == getSelectedPlongeur()) {
                error("Vous devez d'abord slectionner un plongeur");
            } else {
                setPlongeur1(getSelectedPlongeur());
                suppEntreeListPlongeursAInscrire(getPlongeur1());
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur1);
                target.addComponent(ddc);
            }
        }
    });
    final MarkupContainer containAptPlongeur1 = new WebMarkupContainer("containPlongeur1");
    Label labelAptPlongeur1 = new Label("labelAptPlongeur1", Model.of(new String("aptitude")));
    labelAptPlongeur1.setOutputMarkupId(true);
    containAptPlongeur1.add(labelAptPlongeur1);
    TextField<String> valueAptPlongeur1 = new TextField<String>("aptitudePlongeur");
    valueAptPlongeur1.setOutputMarkupId(true);
    containAptPlongeur1.add(valueAptPlongeur1);
    containAptPlongeur1.add(new AjaxButton("validAptPlongeur1") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque pp = (Palanque) form.getModelObject();
            if (null != pp.getAptitudePlongeur()) {
                ChoiceRenderPlongeur oldPlongeur1 = getSelectedPlongeur();
                Adherent adh = ResaSession.get().getAdherentService()
                        .rechercherAdherentParIdentifiantTous(getPlongeur1().getKey());
                String key = adh.getNumeroLicense();
                String value = adh.getNom() + "  " + adh.getPrenom() + "  " + pp.getAptitudePlongeur();
                ChoiceRenderPlongeur newPlongeur1 = new ChoiceRenderPlongeur(key, value);
                //on met le plongeur modifi 
                setPlongeur1(newPlongeur1);
                //On supprime "ancien" et "nouveau" plongeur des plongeurs  inscrire
                listPlongeursAInscrireForpalanque.remove(oldPlongeur1);
                listPlongeursAInscrireForpalanque.remove(newPlongeur1);
                //On redonne le choix dans la selection du plongeur
                setSelectedPlongeur(null);
                // on remet aptitudePlongeur  null pour la prochaine fois
                pp.setAptitudePlongeur(null);
            }
            containAptPlongeur1.setVisible(!containAptPlongeur1.isVisible());
            target.addComponent(labelPlongeur1);
            target.addComponent(containAptPlongeur1);
            target.addComponent(ddc);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });
    containAptPlongeur1.setVisible(false);
    containAptPlongeur1.setOutputMarkupId(true);
    containAptPlongeur1.setOutputMarkupPlaceholderTag(true);
    add(containAptPlongeur1);

    add(new IndicatingAjaxLink("modifierPlongeur1") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur1() == null) {
                error("Le plongeur1 n'est pas saisi ");
            } else {
                containAptPlongeur1.setVisible(!containAptPlongeur1.isVisible());
                target.addComponent(labelPlongeur1);
                target.addComponent(containAptPlongeur1);
                target.addComponent(ddc);
            }
        }
    });
    add(new IndicatingAjaxLink("annulerPlongeur1") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur1() == null) {
                error("Le Plongeur1 n'est pas saisi ");
            } else {
                addEntreeListPlongeursAInscrire(getPlongeur1());
                setPlongeur1(null);
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur1);
                target.addComponent(ddc);
            }
        }
    });
    //--------------PLONGEUR2----------------------- 
    final Label labelPlongeur2 = new Label("nomPlongeur2",
            new PropertyModel(modelPalanque, "nomCompletPlongeur2"));
    labelPlongeur2.setOutputMarkupId(true);
    add(labelPlongeur2);
    add(new IndicatingAjaxLink("validePlongeur2") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur2() != null) {
                //on a dja un Plongeur2 de saisi, donc erreur et on fait rien
                error("Le Plongeur2  dj t saisi : " + getPlongeur2().getValue()
                        + " Impossible d'en saisir un autre");
            } else if (null == getSelectedPlongeur()) {
                error("Vous devez d'abord slectionner un plongeur");
            } else {
                setPlongeur2(getSelectedPlongeur());
                suppEntreeListPlongeursAInscrire(getPlongeur2());
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur2);
                target.addComponent(ddc);
            }
        }
    });
    final MarkupContainer containAptPlongeur2 = new WebMarkupContainer("containPlongeur2");
    Label labelAptPlongeur2 = new Label("labelAptPlongeur2", Model.of(new String("aptitude")));
    labelAptPlongeur2.setOutputMarkupId(true);
    containAptPlongeur2.add(labelAptPlongeur2);
    TextField<String> valueAptPlongeur2 = new TextField<String>("aptitudePlongeur");
    valueAptPlongeur2.setOutputMarkupId(true);
    containAptPlongeur2.add(valueAptPlongeur2);
    containAptPlongeur2.add(new AjaxButton("validAptPlongeur2") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque pp = (Palanque) form.getModelObject();
            if (null != pp.getAptitudePlongeur()) {
                ChoiceRenderPlongeur oldPlongeur2 = getSelectedPlongeur();
                Adherent adh = ResaSession.get().getAdherentService()
                        .rechercherAdherentParIdentifiantTous(getPlongeur2().getKey());
                String key = adh.getNumeroLicense();
                String value = adh.getNom() + "  " + adh.getPrenom() + "  " + pp.getAptitudePlongeur();
                ChoiceRenderPlongeur newPlongeur2 = new ChoiceRenderPlongeur(key, value);
                //on met le plongeur modifi
                setPlongeur2(newPlongeur2);
                //On supprime "ancien" et "nouveau" plongeur des plongeurs  inscrire
                listPlongeursAInscrireForpalanque.remove(oldPlongeur2);
                listPlongeursAInscrireForpalanque.remove(newPlongeur2);
                //On redonne le choix dans la selection du plongeur
                setSelectedPlongeur(null);
                // on remet aptitudePlongeur  null pour la prochaine fois
                pp.setAptitudePlongeur(null);
            }
            containAptPlongeur2.setVisible(!containAptPlongeur2.isVisible());
            target.addComponent(labelPlongeur2);
            target.addComponent(containAptPlongeur2);
            target.addComponent(ddc);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });
    containAptPlongeur2.setVisible(false);
    containAptPlongeur2.setOutputMarkupId(true);
    containAptPlongeur2.setOutputMarkupPlaceholderTag(true);
    add(containAptPlongeur2);

    add(new IndicatingAjaxLink("modifierPlongeur2") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur2() == null) {
                error("Le plongeur2 n'est pas saisi ");
            } else {
                containAptPlongeur2.setVisible(!containAptPlongeur2.isVisible());
                target.addComponent(labelPlongeur2);
                target.addComponent(containAptPlongeur2);
                target.addComponent(ddc);
            }
        }
    });
    add(new IndicatingAjaxLink("annulerPlongeur2") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur2() == null) {
                error("Le Plongeur2 n'est pas saisi ");
            } else {
                addEntreeListPlongeursAInscrire(getPlongeur2());
                setPlongeur2(null);
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur2);
                target.addComponent(ddc);
            }
        }
    });
    //--------------PLONGEUR3----------------------- 
    final Label labelPlongeur3 = new Label("nomPlongeur3",
            new PropertyModel(modelPalanque, "nomCompletPlongeur3"));
    labelPlongeur3.setOutputMarkupId(true);
    add(labelPlongeur3);
    add(new IndicatingAjaxLink("validePlongeur3") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur3() != null) {
                //on a dja un Plongeur3 de saisi, donc erreur et on fait rien
                error("Le Plongeur3  dj t saisi : " + getPlongeur3().getValue()
                        + " Impossible d'en saisir un autre");
            } else if (null == getSelectedPlongeur()) {
                error("Vous devez d'abord slectionner un plongeur");
            } else {
                setPlongeur3(getSelectedPlongeur());
                suppEntreeListPlongeursAInscrire(getPlongeur3());
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur3);
                target.addComponent(ddc);
            }
        }
    });
    final MarkupContainer containAptPlongeur3 = new WebMarkupContainer("containPlongeur3");
    Label labelAptPlongeur3 = new Label("labelAptPlongeur3", Model.of(new String("aptitude")));
    labelAptPlongeur3.setOutputMarkupId(true);
    containAptPlongeur3.add(labelAptPlongeur3);
    TextField<String> valueAptPlongeur3 = new TextField<String>("aptitudePlongeur");
    valueAptPlongeur3.setOutputMarkupId(true);
    containAptPlongeur3.add(valueAptPlongeur3);
    containAptPlongeur3.add(new AjaxButton("validAptPlongeur3") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque pp = (Palanque) form.getModelObject();
            if (null != pp.getAptitudePlongeur()) {
                ChoiceRenderPlongeur oldPlongeur3 = getSelectedPlongeur();
                Adherent adh = ResaSession.get().getAdherentService()
                        .rechercherAdherentParIdentifiantTous(getPlongeur3().getKey());
                String key = adh.getNumeroLicense();
                String value = adh.getNom() + "  " + adh.getPrenom() + "  " + pp.getAptitudePlongeur();
                ChoiceRenderPlongeur newPlongeur3 = new ChoiceRenderPlongeur(key, value);
                //on met le plongeur modifi
                setPlongeur3(newPlongeur3);
                //On supprime "ancien" et "nouveau" plongeur des plongeurs  inscrire
                listPlongeursAInscrireForpalanque.remove(oldPlongeur3);
                listPlongeursAInscrireForpalanque.remove(newPlongeur3);
                //On redonne le choix dans la selection du plongeur
                setSelectedPlongeur(null);
                // on remet aptitudePlongeur  null pour la prochaine fois
                pp.setAptitudePlongeur(null);
            }
            containAptPlongeur3.setVisible(!containAptPlongeur3.isVisible());
            target.addComponent(labelPlongeur3);
            target.addComponent(containAptPlongeur3);
            target.addComponent(ddc);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });
    containAptPlongeur3.setVisible(false);
    containAptPlongeur3.setOutputMarkupId(true);
    containAptPlongeur3.setOutputMarkupPlaceholderTag(true);
    add(containAptPlongeur3);

    add(new IndicatingAjaxLink("modifierPlongeur3") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur3() == null) {
                error("Le plongeur3 n'est pas saisi ");
            } else {
                containAptPlongeur3.setVisible(!containAptPlongeur3.isVisible());
                target.addComponent(labelPlongeur3);
                target.addComponent(containAptPlongeur3);
                target.addComponent(ddc);
            }
        }
    });
    add(new IndicatingAjaxLink("annulerPlongeur3") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur3() == null) {
                error("Le Plongeur3 n'est pas saisi ");
            } else {
                addEntreeListPlongeursAInscrire(getPlongeur3());
                setPlongeur3(null);
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur3);
                target.addComponent(ddc);
            }
        }
    });
    //--------------PLONGEUR4----------------------- 
    final Label labelPlongeur4 = new Label("nomPlongeur4",
            new PropertyModel(modelPalanque, "nomCompletPlongeur4"));
    labelPlongeur4.setOutputMarkupId(true);
    add(labelPlongeur4);
    add(new IndicatingAjaxLink("validePlongeur4") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur4() != null) {
                //on a dja un Plongeur4 de saisi, donc erreur et on fait rien
                error("Le Plongeur4  dj t saisi : " + getPlongeur4().getValue()
                        + " Impossible d'en saisir un autre");
            } else if (null == getSelectedPlongeur()) {
                error("Vous devez d'abord slectionner un plongeur");
            } else {
                setPlongeur4(getSelectedPlongeur());
                suppEntreeListPlongeursAInscrire(getPlongeur4());
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur4);
                target.addComponent(ddc);
            }
        }
    });
    final MarkupContainer containAptPlongeur4 = new WebMarkupContainer("containPlongeur4");
    Label labelAptPlongeur4 = new Label("labelAptPlongeur4", Model.of(new String("aptitude")));
    labelAptPlongeur4.setOutputMarkupId(true);
    containAptPlongeur4.add(labelAptPlongeur4);
    TextField<String> valueAptPlongeur4 = new TextField<String>("aptitudePlongeur");
    valueAptPlongeur4.setOutputMarkupId(true);
    containAptPlongeur4.add(valueAptPlongeur4);
    containAptPlongeur4.add(new AjaxButton("validAptPlongeur4") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque pp = (Palanque) form.getModelObject();
            if (null != pp.getAptitudePlongeur()) {
                ChoiceRenderPlongeur oldPlongeur4 = getSelectedPlongeur();
                Adherent adh = ResaSession.get().getAdherentService()
                        .rechercherAdherentParIdentifiantTous(getPlongeur4().getKey());
                String key = adh.getNumeroLicense();
                String value = adh.getNom() + "  " + adh.getPrenom() + "  " + pp.getAptitudePlongeur();
                ChoiceRenderPlongeur newPlongeur4 = new ChoiceRenderPlongeur(key, value);
                //on met le plongeur modifi comme guide
                setPlongeur4(newPlongeur4);
                //On supprime "ancien" et "nouveau" plongeur des plongeurs  inscrire
                listPlongeursAInscrireForpalanque.remove(oldPlongeur4);
                listPlongeursAInscrireForpalanque.remove(newPlongeur4);
                //On redonne le choix dans la selection du plongeur
                setSelectedPlongeur(null);
                // on remet aptitudePlongeur  null pour la prochaine fois
                pp.setAptitudePlongeur(null);
            }
            containAptPlongeur4.setVisible(!containAptPlongeur4.isVisible());
            target.addComponent(labelPlongeur4);
            target.addComponent(containAptPlongeur4);
            target.addComponent(ddc);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });
    containAptPlongeur4.setVisible(false);
    containAptPlongeur4.setOutputMarkupId(true);
    containAptPlongeur4.setOutputMarkupPlaceholderTag(true);
    add(containAptPlongeur4);
    add(new IndicatingAjaxLink("modifierPlongeur4") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur4() == null) {
                error("Le plongeur4 n'est pas saisi ");
            } else {
                containAptPlongeur4.setVisible(!containAptPlongeur4.isVisible());
                target.addComponent(labelPlongeur4);
                target.addComponent(containAptPlongeur4);
                target.addComponent(ddc);
            }
        }
    });

    add(new IndicatingAjaxLink("annulerPlongeur4") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.addComponent(feedback);
            if (getPlongeur4() == null) {
                error("Le Plongeur4 n'est pas saisi ");
            } else {
                addEntreeListPlongeursAInscrire(getPlongeur4());
                setPlongeur4(null);
                setSelectedPlongeur(null);
                target.addComponent(labelPlongeur4);
                target.addComponent(ddc);
            }
        }
    });
    //-----------------Profondeur Maxi--------------------------
    TextField pMaxPrevu = new TextField<Integer>("profondeurMaxPrevue", Integer.class);
    pMaxPrevu.add(new MaximumValidator<Integer>(60));
    pMaxPrevu.add(new MinimumValidator<Integer>(0));
    add(pMaxPrevu);
    TextField pMaxRea = new TextField<Integer>("profondeurMaxRea", Integer.class);
    pMaxRea.add(new MaximumValidator<Integer>(60));
    pMaxRea.add(new MinimumValidator<Integer>(0));
    add(pMaxRea);
    //-----------------Dure de la plonge--------------------------
    TextField dureePrevu = new TextField<Integer>("dureeTotalePrevue", Integer.class);
    add(dureePrevu);
    TextField dureeRea = new TextField<Integer>("dureeTotaleRea", Integer.class);
    add(dureeRea);
    //-----------------Paliers--------------------------
    TextField palier3 = new TextField<Integer>("palier3m", Integer.class);
    palier3.add(new MinimumValidator<Integer>(0));
    add(palier3);
    TextField palier6 = new TextField<Integer>("palier6m", Integer.class);
    palier6.add(new MinimumValidator<Integer>(0));
    add(palier6);
    TextField palier9 = new TextField<Integer>("palier9m", Integer.class);
    palier9.add(new MinimumValidator<Integer>(0));
    add(palier9);
    TextField palierP = new TextField<Integer>("palierProfond", Integer.class);
    palierP.add(new MinimumValidator<Integer>(0));
    add(palierP);
    //-----------------Heure de sortie
    TextField heureSortie = new TextField<Integer>("hhSortie", Integer.class);
    heureSortie.add(new MaximumValidator<Integer>(24));
    heureSortie.add(new MinimumValidator<Integer>(0));
    add(heureSortie);
    TextField minuteSortie = new TextField<Integer>("mnSortie", Integer.class);
    minuteSortie.add(new MaximumValidator<Integer>(60));
    minuteSortie.add(new MinimumValidator<Integer>(0));
    add(minuteSortie);
    //------------------- Validation de la palanquee
    AjaxButton b_validerPalanque = new AjaxButton("validerPalanque") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Palanque palanqueForm = (Palanque) form.getModelObject();
            boolean formatAptitude = true;
            if (palanqueForm.getListPlongeursPalanque().size() > 0) {
                for (ChoiceRenderPlongeur crp : palanqueForm.getListPlongeursPalanque()) {
                    if (crp.getValue().contains("/")) {
                        formatAptitude = false;
                    } else {
                        error("Vrifier les aptitudes des plongeurs");
                    }
                }
            }
            if (formatAptitude) {
                if (palanqueForm.getListPlongeursPalanque().size() > 0) {
                    //init de l'heure de sortie avec les champs
                    palanqueForm.setHeureSortie(palanqueForm.getHhSortie(), palanqueForm.getMnSortie());
                    //suppression des plongeurs de la palanque dans les plongeurs  inscrire
                    suppPlongeursAInscrire(palanqueForm.getListPlongeursPalanque());

                    fs.getPalanques().remove(palanque);
                    fs.getPalanques().add(palanqueForm);

                    if (palanqueForm.getIsBapteme()) {
                        // c'est un Bapteme on remet le guide dans la liste des plongeurs  inscrire
                        // pour pouvoir le re-inscrire sur une autre palanque
                        if (!listPlongeursAInscrireForpalanque.contains(getGuide())) {
                            listPlongeursAInscrireForpalanque.add(getGuide());
                        }
                    }
                    //mise  jour des plongeurs  inscrire en session
                    ResaSession.get().setListPlongeursAInscrire(listPlongeursAInscrireForpalanque);
                    //Retour sur la feuille de saisie pour d'autres palanques eventuelles
                    setResponsePage(new SaisieFicheSecurite(origPage, dateMini, dateMaxi));
                } else {
                    error("Cette palanque ne contient aucun plongeur !");
                }
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    };

    b_validerPalanque.setOutputMarkupId(true);
    add(b_validerPalanque);

    // bouton retour saisie Fiche de securite en reprennant les sauvegardes
    add(new Link("cancel") {
        @Override
        public void onClick() {
            for (Palanque ps : fs.getPalanques()) {
                if (ps.getNumero() == palanqueSAV.getNumero()) {
                    fs.getPalanques().set(fs.getPalanques().indexOf(ps), palanqueSAV);
                    break;
                }
            }
            ResaSession.get().setListPlongeursAInscrire(plongeursAInscrireSAV);
            setResponsePage(new SaisieFicheSecurite(origPage, dateMini, dateMaxi));
        }
    });

}

From source file:org.artifactory.webapp.wicket.page.browse.treebrowser.tabs.jnlp.JnlpViewTabPanel.java

License:Open Source License

private void setRepository(RepoDescriptor repoDescriptor) {
    String servletContextUrl = RequestUtils.getWicketServletContextUrl();
    final String key = repoDescriptor.getKey();
    final String virtualRepoUrl = servletContextUrl + "/" + key + "/";

    String jnlpHref = virtualRepoUrl + fileItem.getFileInfo().getRelPath();
    JnlpUtils.AppletInfo appletInfo = JnlpUtils.getAppletInfo(jnlpContent, jnlpHref);
    boolean isJavaFxApplet = appletInfo != null;

    // add links//  w  w  w.j a va2  s .  c  o m
    MarkupContainer jnlpLinksBorder = new FieldSetBorder("jnlpLinksBorder");
    jnlpLinksBorder.add(new LaunchWebStartLink("webstart", virtualRepoUrl, key));
    Component appletLink = new LaunchAppletLink("applet", appletInfo, key);
    appletLink.setVisible(isJavaFxApplet);
    jnlpLinksBorder.add(appletLink);
    addOrReplace(jnlpLinksBorder);

    // add script snippet
    if (isJavaFxApplet) {
        MarkupContainer scriptSnippetBorder = new FieldSetBorder("scriptSnippetBorder") {
            @Override
            public String getTitle() {
                return format("Applet's Script Snippet (%s repository)", key);
            }
        };
        scriptSnippetBorder.add(
                WicketUtils.getSyntaxHighlighter("scriptSnippet", appletInfo.getScriptSnippet(), Syntax.xml));
        addOrReplace(scriptSnippetBorder);
    } else {
        MarkupContainer scriptSnippetBorder = new PlaceHolder("scriptSnippetBorder");
        scriptSnippetBorder.setOutputMarkupId(true);
        scriptSnippetBorder.setOutputMarkupPlaceholderTag(true);
        scriptSnippetBorder.add(new PlaceHolder("scriptSnippet"));
        addOrReplace(scriptSnippetBorder);
    }
}

From source file:org.obiba.onyx.jade.core.wicket.instrument.MeasuresListPanel.java

License:Open Source License

@SuppressWarnings("serial")
private void addNoMeasureAvailableMessage() {
    MarkupContainer noMeasureAvailable = new MarkupContainer("noMeasureAvailable") {

        @Override/*  w w w  .  j a va  2  s.  c  o  m*/
        public boolean isVisible() {
            // Only visible when no measures
            return getMeasures().size() == 0;
        }

    };
    noMeasureAvailable.setOutputMarkupPlaceholderTag(true);
    add(noMeasureAvailable);
}

From source file:org.patientview.radar.web.panels.DiagnosisPanel.java

License:Open Source License

public DiagnosisPanel(String id, final IModel<Long> radarNumberModel) {
    super(id);/*from  w  w w.j a v  a 2 s .  c  om*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // Set up model
    // Set up loadable detachable, working for null radar numbers (new patients) and existing
    final CompoundPropertyModel<Diagnosis> model = new CompoundPropertyModel<Diagnosis>(
            new LoadableDetachableModel<Diagnosis>() {
                @Override
                protected Diagnosis load() {
                    if (radarNumberModel.getObject() != null) {
                        Long radarNumber;
                        try {
                            radarNumber = radarNumberModel.getObject();
                        } catch (ClassCastException e) {
                            Object obj = radarNumberModel.getObject();
                            radarNumber = Long.parseLong((String) obj);
                        }
                        Diagnosis diagnosis = diagnosisManager.getDiagnosisByRadarNumber(radarNumber);
                        if (diagnosis != null) {
                            return diagnosis;
                        } else {
                            return new Diagnosis();
                        }
                    } else {
                        return new Diagnosis();
                    }
                }
            });

    // Clinical presentation A - goes here in the file as referenced in form submit
    final DropDownChoice<ClinicalPresentation> clinicalPresentationA = new ClinicalPresentationDropDownChoice(
            "clinicalPresentationA");
    clinicalPresentationA.setOutputMarkupId(true);
    clinicalPresentationA.setOutputMarkupPlaceholderTag(true);

    final Form<Diagnosis> form = new Form<Diagnosis>("form", model) {
        @Override
        protected void onValidateModelObjects() {
            super.onValidateModelObjects();
            Diagnosis diagnosis = getModelObject();
            ClinicalPresentation presentationA = diagnosis.getClinicalPresentationA();
            ClinicalPresentation presentationB = diagnosis.getClinicalPresentationB();

            // Validate that the two aren't the same
            if (presentationA != null && presentationB != null && presentationA.equals(presentationB)) {
                clinicalPresentationA.error("A and B cannot be the same");
            }
        }

        @Override
        protected void onSubmit() {
            Diagnosis diagnosis = getModelObject();
            Date dateOfDiagnosis = diagnosis.getBiopsyDate();
            Long radarNumber;
            try {
                radarNumber = radarNumberModel.getObject();
            } catch (ClassCastException e) {
                Object obj = radarNumberModel.getObject();
                radarNumber = Long.parseLong((String) obj);
            }

            Patient patient = patientManager.getPatientByRadarNumber(radarNumber);
            Date dob = patient.getDob();
            if (dateOfDiagnosis != null && dob != null) {
                int age = Years.yearsBetween(new DateTime(dob), new DateTime(dateOfDiagnosis)).getYears();
                diagnosis.setAgeAtDiagnosis(age);
            }
            diagnosisManager.saveDiagnosis(diagnosis);

            // additional significant diagnosis needs to carry through to clinical data
            List<ClinicalData> clinicalDataList = clinicalDataManager
                    .getClinicalDataByRadarNumber(diagnosis.getRadarNumber());
            if (clinicalDataList.isEmpty()) {
                ClinicalData clinicalData = new ClinicalData();
                clinicalData.setSequenceNumber(1);
                clinicalData.setRadarNumber(diagnosis.getRadarNumber());
                clinicalDataList.add(clinicalData);
            }

            for (ClinicalData clinicalData : clinicalDataList) {
                clinicalData.setSignificantDiagnosis1(diagnosis.getSignificantDiagnosis1());
                clinicalData.setSignificantDiagnosis2(diagnosis.getSignificantDiagnosis2());
                clinicalDataManager.saveClinicalDate(clinicalData);
            }

        }
    };
    add(form);

    final List<Component> componentsToUpdate = new ArrayList<Component>();

    Label successLabel = RadarComponentFactory.getSuccessMessageLabel("successMessage", form,
            componentsToUpdate);
    Label successLabelDown = RadarComponentFactory.getSuccessMessageLabel("successMessageDown", form,
            componentsToUpdate);

    Label errorLabel = RadarComponentFactory.getErrorMessageLabel("errorMessage", form, componentsToUpdate);
    Label errorLabelDown = RadarComponentFactory.getErrorMessageLabel("errorMessageDown", form,
            componentsToUpdate);

    TextField<Long> radarNumber = new TextField<Long>("radarNumber");
    radarNumber.setEnabled(false);
    form.add(radarNumber);

    TextField hospitalNumber = new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager));
    form.add(hospitalNumber);

    TextField firstName = new TextField("firstName",
            RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager));
    form.add(firstName);

    TextField surname = new TextField("surname",
            RadarModelFactory.getSurnameModel(radarNumberModel, patientManager));
    form.add(surname);

    TextField dob = new DateTextField("dateOfBirth",
            RadarModelFactory.getDobModel(radarNumberModel, patientManager), RadarApplication.DATE_PATTERN);
    form.add(dob);

    DropDownChoice<DiagnosisCode> diagnosisCodeDropDownChoice = new DropDownChoice<DiagnosisCode>(
            "diagnosisCode", diagnosisManager.getDiagnosisCodes(),
            new ChoiceRenderer<DiagnosisCode>("abbreviation", "id"));
    diagnosisCodeDropDownChoice.setEnabled(false);
    form.add(diagnosisCodeDropDownChoice);

    form.add(new TextArea("text"));

    form.add(new Label("diagnosisOrBiopsy", new LoadableDetachableModel<Object>() {
        @Override
        protected Object load() {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getDiagnosisCode() != null) {
                return diagnosis.getDiagnosisCode().getId().equals(SRNS_ID) ? "diagnosis" : "original biopsy";
            }
            return "";
        }
    }));

    // this field is also used for date of diagnosis
    RadarDateTextField biopsyDate = new RadarDateTextField("biopsyDate", form, componentsToUpdate);

    form.add(biopsyDate);

    RadarDateTextField esrfDate = new RadarDateTextField("esrfDate", form, componentsToUpdate);
    form.add(esrfDate);

    TextField ageAtDiagnosis = new TextField("ageAtDiagnosis");
    ageAtDiagnosis.setOutputMarkupId(true);
    ageAtDiagnosis.setOutputMarkupPlaceholderTag(true);
    form.add(ageAtDiagnosis);
    componentsToUpdate.add(ageAtDiagnosis);
    form.add(new CheckBox("prepubertalAtDiagnosis"));

    final RadarTextFieldWithValidation heightAtDiagnosis = new RadarTextFieldWithValidation("heightAtDiagnosis",
            new RangeValidator<Double>(RadarApplication.MIN_HEIGHT, RadarApplication.MAX_HEIGHT), form,
            componentsToUpdate);
    form.add(heightAtDiagnosis);

    // Clinical presentation B - A is further up the file
    final DropDownChoice<ClinicalPresentation> clinicalPresentationB = new ClinicalPresentationDropDownChoice(
            "clinicalPresentationB");
    clinicalPresentationB.setOutputMarkupId(true);
    clinicalPresentationB.setOutputMarkupPlaceholderTag(true);

    form.add(clinicalPresentationA, clinicalPresentationB);
    form.add(new RadarDateTextField("onsetSymptomsDate", form, componentsToUpdate));

    ComponentFeedbackPanel clinicalPresentationFeedback = new ComponentFeedbackPanel(
            "clinicalPresentationFeedback", clinicalPresentationA);
    clinicalPresentationFeedback.setOutputMarkupId(true);
    clinicalPresentationFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(clinicalPresentationFeedback);

    // Steroid resistance radio groups
    RadioGroup steroidRadioGroup = new RadioGroup("steroidResistance") {
        @Override
        public boolean isVisible() {
            DiagnosisCode diagnosisCode = model.getObject().getDiagnosisCode();
            if (diagnosisCode != null) {
                return diagnosisCode.getId().equals(SRNS_ID);
            } else {
                return false;
            }

        }
    };
    steroidRadioGroup.setRequired(true);
    steroidRadioGroup.add(new Radio<Diagnosis.SteroidResistance>("primarySteroidResistance",
            new Model<Diagnosis.SteroidResistance>(Diagnosis.SteroidResistance.PRIMARY)));
    steroidRadioGroup.add(new Radio<Diagnosis.SteroidResistance>("secondarySteroidResistance",
            new Model<Diagnosis.SteroidResistance>(Diagnosis.SteroidResistance.SECONDARY)));
    steroidRadioGroup.add(new Radio<Diagnosis.SteroidResistance>("presumedSteroidResistance",
            new Model<Diagnosis.SteroidResistance>(Diagnosis.SteroidResistance.PRESUMED)));
    steroidRadioGroup.add(new Radio<Diagnosis.SteroidResistance>("biopsyProven",
            new Model<Diagnosis.SteroidResistance>(Diagnosis.SteroidResistance.BPS)));
    form.add(steroidRadioGroup);

    // Construct feedback panel
    final ComponentFeedbackPanel steroidFeedbackPanel = new ComponentFeedbackPanel("steroidResistanceFeedback",
            steroidRadioGroup);
    steroidFeedbackPanel.setOutputMarkupPlaceholderTag(true);
    form.add(steroidFeedbackPanel);
    steroidRadioGroup.setOutputMarkupPlaceholderTag(true);
    steroidRadioGroup.add(steroidFeedbackPanel);
    componentsToUpdate.add(steroidFeedbackPanel);

    // Additional significant diagnosis
    form.add(new TextField("significantDiagnosis1"));
    form.add(new TextField("significantDiagnosis2"));

    // Biopsy Diagnosis visibilities
    IModel<String> biopsyLabelModel = new LoadableDetachableModel<String>() {
        @Override
        protected String load() {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getDiagnosisCode() != null) {
                if (diagnosis.getDiagnosisCode().getId().equals(SRNS_ID)) {
                    return "Biopsy Diagnosis";
                } else {
                    return "Biopsy Proven Diagnosis";
                }
            } else {
                return "";
            }
        }
    };

    IModel<List> biopsyDiagnosisModel = new LoadableDetachableModel<List>() {
        @Override
        protected List load() {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getDiagnosisCode() != null) {
                if (diagnosis.getDiagnosisCode().getId().equals(SRNS_ID)) {
                    return Arrays.asList(Diagnosis.BiopsyDiagnosis.MINIMAL_CHANGE,
                            Diagnosis.BiopsyDiagnosis.FSGS, Diagnosis.BiopsyDiagnosis.MESANGIAL_HYPERTROPHY,
                            Diagnosis.BiopsyDiagnosis.OTHER);
                } else {
                    return Arrays.asList(Diagnosis.BiopsyDiagnosis.YES, Diagnosis.BiopsyDiagnosis.NO);
                }
            }
            return Collections.emptyList();
        }
    };

    DropDownChoice biopsyDiagnosis = new DropDownChoice("biopsyProvenDiagnosis", biopsyDiagnosisModel,
            new ChoiceRenderer("label", "id"));

    Label biopsyDiagnosisLabel = new Label("biopsyDiagnosisLabel", biopsyLabelModel);

    form.add(biopsyDiagnosis, biopsyDiagnosisLabel);

    Diagnosis diagnosis = model.getObject();
    boolean showOtherDetailsOnInit;
    showOtherDetailsOnInit = diagnosis.getMutationYorN9() == Diagnosis.MutationYorN.Y;
    final IModel<Boolean> otherDetailsVisibilityModel = new Model<Boolean>(showOtherDetailsOnInit);

    boolean showMoreDetailsOnInit = false;
    if (diagnosis.getMutationYorN1() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN2() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN3() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN4() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN5() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN6() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN7() == Diagnosis.MutationYorN.Y
            || diagnosis.getMutationYorN8() == Diagnosis.MutationYorN.Y) {

        showMoreDetailsOnInit = true;
    }

    final IModel<Boolean> moreDetailsVisibilityModel = new Model<Boolean>(showMoreDetailsOnInit);

    WebMarkupContainer geneMutationContainer = new WebMarkupContainer("geneMutationContainer") {
        @Override
        public boolean isVisible() {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getDiagnosisCode() != null) {
                return diagnosis.getDiagnosisCode().getId().equals(SRNS_ID);
            }
            return false;
        }
    };

    WebMarkupContainer mutationContainer = new WebMarkupContainer("mutationContainer");

    form.add(geneMutationContainer);

    Label geneMutationLabel = new Label("geneMutationLabel", "Gene Mutation");

    geneMutationContainer.add(geneMutationLabel);
    geneMutationContainer.add(mutationContainer);

    // Gene mutations
    mutationContainer
            .add(new DiagnosisGeneMutationPanel("nphs1Container", 1, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("nphs2Container", 2, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("nphs3Container", 3, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("wt1Container", 4, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("cd2apContainer", 5, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("trpc6Container", 6, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("actn4Container", 7, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel("lamb2Container", 8, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    mutationContainer
            .add(new DiagnosisGeneMutationPanel(OTHER_CONTAINER_ID, 9, (CompoundPropertyModel) form.getModel(),
                    otherDetailsVisibilityModel, moreDetailsVisibilityModel, componentsToUpdate));

    // Other gene mutation container
    MarkupContainer otherGeneMutationContainer = new WebMarkupContainer("otherGeneMutationContainer") {

        @Override
        public boolean isVisible() {
            return otherDetailsVisibilityModel.getObject();
        }
    };

    otherGeneMutationContainer.setOutputMarkupId(true);
    otherGeneMutationContainer.setOutputMarkupPlaceholderTag(true);

    otherGeneMutationContainer.add(new TextArea("otherGeneMutation"));

    geneMutationContainer.add(otherGeneMutationContainer);

    // more details
    MarkupContainer moreDetailsContainer = new WebMarkupContainer("moreDetailsContainer") {

        @Override
        public boolean isVisible() {
            return moreDetailsVisibilityModel.getObject();
        }
    };
    moreDetailsContainer.setOutputMarkupId(true);
    moreDetailsContainer.setOutputMarkupPlaceholderTag(true);
    moreDetailsContainer.add(new TextArea("moreDetails", new Model()));
    geneMutationContainer.add(moreDetailsContainer);
    componentsToUpdate.add(moreDetailsContainer);

    componentsToUpdate.add(otherGeneMutationContainer);

    boolean showKaroTypeOtherOnInit = false;
    if (diagnosis.getKarotype() != null) {
        showKaroTypeOtherOnInit = diagnosis.getKarotype().getId().equals(KAROTYPE_OTHER_ID);
    }
    final IModel<Boolean> karoTypeOtherVisibilityModel = new Model<Boolean>(showKaroTypeOtherOnInit);

    // Add Karotype
    DropDownChoice<Karotype> karotypeDropDownChoice = new DropDownChoice<Karotype>("karotype",
            diagnosisManager.getKarotypes(), new ChoiceRenderer<Karotype>("description", "id"));

    WebMarkupContainer karoTypeContainer = new WebMarkupContainer("karoTypeContainer") {
        @Override
        public boolean isVisible() {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getDiagnosisCode() != null) {
                return diagnosis.getDiagnosisCode().getId().equals(SRNS_ID);
            }
            return false;
        }
    };
    karoTypeContainer.add(karotypeDropDownChoice);
    form.add(karoTypeContainer);

    karotypeDropDownChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Diagnosis diagnosis = model.getObject();
            Karotype karotype = diagnosis.getKarotype();
            if (karotype != null) {
                karoTypeOtherVisibilityModel.setObject(karotype.getId().equals(KAROTYPE_OTHER_ID));
                ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
            }
        }
    });

    // karotype other
    MarkupContainer karoTypeOtherContainer = new WebMarkupContainer("karoTypeOtherContainer") {
        @Override
        public boolean isVisible() {
            return karoTypeOtherVisibilityModel.getObject();
        }
    };
    karoTypeOtherContainer.setOutputMarkupId(true);
    karoTypeOtherContainer.setOutputMarkupPlaceholderTag(true);
    karoTypeOtherContainer.add(new TextArea("karoTypeOtherText"));
    componentsToUpdate.add(karoTypeOtherContainer);
    form.add(karoTypeOtherContainer);

    // Parental consanguinity and family history
    form.add(new YesNoDropDownChoice("parentalConsanguinity"));

    YesNoDropDownChoice familyHistory = new YesNoDropDownChoice("familyHistory");

    boolean showFamilyOnInit = false;
    showFamilyOnInit = diagnosis.getFamilyHistory() == Diagnosis.YesNo.YES;
    final IModel<Boolean> familyVisibilityModel = new Model<Boolean>(showFamilyOnInit);

    familyHistory.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Diagnosis diagnosis = model.getObject();
            if (diagnosis.getFamilyHistory() != null) {
                familyVisibilityModel.setObject(diagnosis.getFamilyHistory() == Diagnosis.YesNo.YES);
            }
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    form.add(familyHistory);
    // Family history containers
    form.add(new DiagnosisRelativePanel("relative1Container", 1, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));
    form.add(new DiagnosisRelativePanel("relative2Container", 2, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));
    form.add(new DiagnosisRelativePanel("relative3Container", 3, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));
    form.add(new DiagnosisRelativePanel("relative4Container", 4, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));
    form.add(new DiagnosisRelativePanel("relative5Container", 5, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));
    form.add(new DiagnosisRelativePanel("relative6Container", 6, (CompoundPropertyModel) form.getModel(),
            familyVisibilityModel, componentsToUpdate));

    componentsToUpdate.add(clinicalPresentationFeedback);

    Label radarFamilyLabel = new Label("radarFamilyLabel", "RaDaR No") {

        @Override
        public boolean isVisible() {
            return familyVisibilityModel.getObject();
        }
    };
    radarFamilyLabel.setOutputMarkupId(true);
    radarFamilyLabel.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(radarFamilyLabel);
    form.add(radarFamilyLabel);

    DiagnosisAjaxSubmitLink save = new DiagnosisAjaxSubmitLink("save") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    DiagnosisAjaxSubmitLink saveDown = new DiagnosisAjaxSubmitLink("saveDown") {

        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    form.add(save, saveDown);
}

From source file:org.patientview.radar.web.panels.firstvisit.ClinicalPicturePanel.java

License:Open Source License

public ClinicalPicturePanel(String id, final IModel<Long> radarNumberModel, final boolean isFirstVisit) {

    super(id);/*w  w w . ja  v a2  s. c  o m*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // set srns elements to hide
    srnsElementsToHide = Arrays.asList(URTICARIA_CONTAINER_ID, URTICARIA_DETAIL_CONTAINER_ID,
            PARTIAL_LIPODYSTROPHY_CONTAINER_ID, PRECEEDING_INFECTION_CONTAINER_ID,
            PRECEEDING_INFECTION_DETAIL_CONTAINER_ID, CHRONIC_INFECTION_ACTIVE_CONTAINER_ID,
            CHRONIC_INFECTION_DETAIL_CONTAINER_ID);

    // set mpgn elements to hide
    mpgnElementsToHide = Arrays.asList(THROMBOSIS_CONTAINER_ID, PERITONITIS_CONTAINER_ID,
            PULMONARY_OEDEMA_CONTAINER_ID, DIABETES_TYPE_CONTAINER_ID, RASH_CONTAINER_ID,
            RASH_DETAIL_CONTAINER_ID, POSSIBLE_IMMUNISATION_TRIGGER_CONTAINER_ID, PHENOTYPE_CONTAINER_1,
            PHENOTYPE_CONTAINER_2, PHENOTYPE_CONTAINER_3, PHENOTYPE_CONTAINER_4);

    // set srns elements to hide on follow up
    srnsElementsToHideFollowup = Arrays.asList(PATIENT_DETAILS_CONTAINER);

    final WebMarkupContainer clinicalPictureContainer = new WebMarkupContainer("clinicalPictureContainer");
    clinicalPictureContainer.setVisible(isFirstVisit);
    clinicalPictureContainer.setOutputMarkupId(true);
    clinicalPictureContainer.setOutputMarkupPlaceholderTag(true);
    add(clinicalPictureContainer);

    final TextField<Double> diastolicBloodPressure = new TextField<Double>("diastolicBloodPressure");

    final CompoundPropertyModel<ClinicalData> firstVisitModel = new CompoundPropertyModel<ClinicalData>(
            new LoadableDetachableModel<ClinicalData>() {
                @Override
                protected ClinicalData load() {
                    if (radarNumberModel.getObject() != null) {
                        // If we have a radar number get the list from DAO
                        ClinicalData clinicalData;
                        clinicalData = clinicalDataManager
                                .getFirstClinicalDataByRadarNumber(radarNumberModel.getObject());

                        if (clinicalData != null) {
                            return clinicalData;
                        }
                    }
                    // By default just return new one
                    ClinicalData clinicalDataNew = new ClinicalData();
                    clinicalDataNew.setSequenceNumber(1);
                    return clinicalDataNew;
                }
            });

    final IModel<ClinicalData> followUpModel = new LoadableDetachableModel<ClinicalData>() {
        private Long id;

        @Override
        protected ClinicalData load() {
            if (id == null) {
                return new ClinicalData();
            } else {
                return clinicalDataManager.getClinicalData(id);
            }
        }

        @Override
        public void detach() {
            ClinicalData clinicalData = getObject();
            if (clinicalData != null) {
                id = clinicalData.getId();
            }
            super.detach();
        }
    };

    final IModel<ClinicalData> formModel;
    if (isFirstVisit) {
        formModel = firstVisitModel;
    } else {
        formModel = new CompoundPropertyModel<ClinicalData>(followUpModel);
    }

    IModel<List> clinicalPictureListModel = new AbstractReadOnlyModel<List>() {
        @Override
        public List getObject() {

            if (radarNumberModel.getObject() != null) {
                List list = clinicalDataManager.getClinicalDataByRadarNumber(radarNumberModel.getObject());
                return !list.isEmpty() ? list : Collections.emptyList();
            }

            return Collections.emptyList();
        }
    };

    WebMarkupContainer followupContainer = new WebMarkupContainer("followupContainer");
    followupContainer.setVisible(!isFirstVisit);
    followupContainer.setOutputMarkupPlaceholderTag(true);

    final DropDownChoice clinicalPicturesSwitcher = new DropDownChoice("clinicalPicturesSwitcher",
            followUpModel, clinicalPictureListModel, new DateChoiceRenderer("clinicalPictureDate", "id") {
                @Override
                protected Date getDate(Object object) {
                    return ((ClinicalData) object).getClinicalPictureDate();
                }
            });

    clinicalPicturesSwitcher.setNullValid(true);

    clinicalPicturesSwitcher.setOutputMarkupId(true);
    clinicalPictureContainer.setOutputMarkupPlaceholderTag(true);
    followupContainer.add(clinicalPicturesSwitcher);
    clinicalPicturesSwitcher.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            clinicalPictureContainer.setVisible(true);
            target.add(clinicalPictureContainer);

        }
    });

    AjaxLink addNew = new AjaxLink("addNew") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            ClinicalData clinicalData = new ClinicalData();
            Diagnosis daignosis = RadarModelFactory.getDiagnosisModel(radarNumberModel, diagnosisManager)
                    .getObject();
            if (daignosis != null) {
                clinicalData.setSignificantDiagnosis1(daignosis.getSignificantDiagnosis1());
                clinicalData.setSignificantDiagnosis2(daignosis.getSignificantDiagnosis2());
            }

            ClinicalData firstClinicalData = clinicalDataManager
                    .getFirstClinicalDataByRadarNumber(radarNumberModel.getObject());
            if (firstClinicalData != null) {
                clinicalData.setPhenotype1(firstClinicalData.getPhenotype1());
                clinicalData.setPhenotype2(firstClinicalData.getPhenotype2());
                clinicalData.setPhenotype3(firstClinicalData.getPhenotype3());
                clinicalData.setPhenotype4(firstClinicalData.getPhenotype4());
            }

            formModel.setObject(clinicalData);
            clinicalPictureContainer.setVisible(true);
            clinicalPicturesSwitcher.clearInput();
            target.add(clinicalPictureContainer, clinicalPicturesSwitcher);

        }
    };

    followupContainer.add(addNew);
    add(followupContainer);

    final List<Component> componentsToUpdate = new ArrayList<Component>();
    if (clinicalPicturesSwitcher.isVisible()) {
        componentsToUpdate.add(clinicalPicturesSwitcher);
    }

    final Form<ClinicalData> form = new Form<ClinicalData>("form", formModel) {
        @Override
        protected void onValidateModelObjects() {
            super.onValidateModelObjects();
            ClinicalData clinicalData = getModelObject();
            Integer systolicBloodPressureVal = clinicalData.getSystolicBloodPressure();
            Integer diastolicBloodPressureVal = clinicalData.getDiastolicBloodPressure();
            if (systolicBloodPressureVal != null && diastolicBloodPressureVal != null) {
                if (!(systolicBloodPressureVal.compareTo(diastolicBloodPressureVal) > 0)) {
                    diastolicBloodPressure.error("This value has to be less than the first value");
                }
            }

        }

        @Override
        protected void onSubmit() {
            ClinicalData clinicalData = getModelObject();
            Long radarNumber;

            if (clinicalData.getRadarNumber() == null) {
                try {
                    radarNumber = radarNumberModel.getObject();
                } catch (ClassCastException e) {
                    Object obj = radarNumberModel.getObject();
                    radarNumber = Long.parseLong((String) obj);
                }

                clinicalData.setRadarNumber(radarNumber);
            }
            clinicalDataManager.saveClinicalDate(clinicalData);

            // if first visit - follow through phenotypes to following visit records
            if (isFirstVisit) {
                List<ClinicalData> clinicalDatas = clinicalDataManager
                        .getClinicalDataByRadarNumber(clinicalData.getRadarNumber());

                for (ClinicalData cd : clinicalDatas) {
                    // ignore first visit
                    if (clinicalData.getId().equals(cd.getId())) {
                        continue;
                    }
                    cd.setPhenotype1(clinicalData.getPhenotype1());
                    cd.setPhenotype2(clinicalData.getPhenotype2());
                    cd.setPhenotype3(clinicalData.getPhenotype3());
                    cd.setPhenotype4(clinicalData.getPhenotype4());
                    clinicalDataManager.saveClinicalDate(cd);
                }
            }
        }
    };

    clinicalPictureContainer.add(form);

    final IModel<Boolean> isSrnsModel = new AbstractReadOnlyModel<Boolean>() {
        private DiagnosisCode diagnosisCode = null;

        @Override
        public Boolean getObject() {
            if (diagnosisCode == null) {
                if (radarNumberModel.getObject() != null) {
                    Diagnosis diagnosis = diagnosisManager
                            .getDiagnosisByRadarNumber(radarNumberModel.getObject());
                    diagnosisCode = diagnosis != null ? diagnosis.getDiagnosisCode() : null;
                }
            }

            if (diagnosisCode != null) {
                return diagnosisCode.getId().equals(DiagnosisPanel.SRNS_ID);
            }
            return false;
        }
    };

    Label successLabel = RadarComponentFactory.getSuccessMessageLabel("successMessage", form,
            componentsToUpdate);
    Label successLabelDown = RadarComponentFactory.getSuccessMessageLabel("successMessageDown", form,
            componentsToUpdate);

    Label errorLabel = RadarComponentFactory.getErrorMessageLabel("errorMessage", form, componentsToUpdate);
    Label errorLabelDown = RadarComponentFactory.getErrorMessageLabel("errorMessageDown", form,
            componentsToUpdate);

    TextField<Long> radarNumber = new TextField<Long>("radarNumber", radarNumberModel);
    radarNumber.setEnabled(false);
    form.add(radarNumber);

    form.add(new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager)));

    form.add(new TextField("diagnosis", new PropertyModel(
            RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation")));

    form.add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager)));

    form.add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager)));

    form.add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager),
            RadarApplication.DATE_PATTERN));

    RadarRequiredDateTextField clinicalPictureDate = new RadarRequiredDateTextField("clinicalPictureDate", form,
            componentsToUpdate);
    form.add(clinicalPictureDate);

    RadarTextFieldWithValidation height = new RadarTextFieldWithValidation("height",
            new RangeValidator<Double>(RadarApplication.MIN_HEIGHT, RadarApplication.MAX_HEIGHT), form,
            componentsToUpdate);
    form.add(height);

    RadarTextFieldWithValidation weight = new RadarTextFieldWithValidation("weight",
            new RangeValidator<Double>(3.0, 100.0), form, componentsToUpdate);
    form.add(weight);
    // Blood pressure
    TextField<Double> systolicBloodPressure = new TextField("systolicBloodPressure");
    systolicBloodPressure.add(new RangeValidator<Integer>(50, 200));
    form.add(systolicBloodPressure);

    final ComponentFeedbackPanel systolicBloodPressureFeedback = new ComponentFeedbackPanel(
            "systolicBloodPressureFeedback", systolicBloodPressure);
    systolicBloodPressureFeedback.setOutputMarkupId(true);
    systolicBloodPressureFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(systolicBloodPressureFeedback);

    diastolicBloodPressure.add(new RangeValidator<Integer>(20, 150));
    form.add(diastolicBloodPressure);

    final ComponentFeedbackPanel diastolicBloodPressureFeedback = new ComponentFeedbackPanel(
            "diastolicBloodPressureFeedback", diastolicBloodPressure);
    diastolicBloodPressureFeedback.setOutputMarkupId(true);
    diastolicBloodPressureFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(diastolicBloodPressureFeedback);

    Component meanArterialPressure = new TextField("meanArterialPressure").setEnabled(false);
    meanArterialPressure.setOutputMarkupPlaceholderTag(true);
    meanArterialPressure.setOutputMarkupId(true);
    form.add(meanArterialPressure);
    componentsToUpdate.add(meanArterialPressure);

    WebMarkupContainer phenotypeContainer1 = new WebMarkupContainer(PHENOTYPE_CONTAINER_1) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer2 = new WebMarkupContainer(PHENOTYPE_CONTAINER_2) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer3 = new WebMarkupContainer(PHENOTYPE_CONTAINER_3) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    WebMarkupContainer phenotypeContainer4 = new WebMarkupContainer(PHENOTYPE_CONTAINER_4) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    phenotypeContainer1.add(new PhenotypeChooser("phenotype1"));
    phenotypeContainer2.add(new PhenotypeChooser("phenotype2"));
    phenotypeContainer3.add(new PhenotypeChooser("phenotype3"));
    phenotypeContainer4.add(new PhenotypeChooser("phenotype4"));

    form.add(phenotypeContainer1);
    form.add(phenotypeContainer2);
    form.add(phenotypeContainer3);
    form.add(phenotypeContainer4);

    form.add(new TextArea("comments"));
    form.add(new TextField("significantDiagnosis1"));
    form.add(new TextField("significantDiagnosis2"));

    // Yes/No/Unknown for the following
    WebMarkupContainer patientDetailsContainer = new WebMarkupContainer(PATIENT_DETAILS_CONTAINER) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    patientDetailsContainer.setOutputMarkupPlaceholderTag(true);
    form.add(patientDetailsContainer);

    patientDetailsContainer.add(new YesNoRadioGroup("oedema", true));
    patientDetailsContainer.add(new YesNoRadioGroup("hypovalaemia", true));
    patientDetailsContainer.add(new YesNoRadioGroup("fever", true));

    WebMarkupContainer thrombosisContainer = new WebMarkupContainer(THROMBOSIS_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup thrombosis = new YesNoRadioGroup("thrombosis", true);
    thrombosisContainer.add(thrombosis);
    patientDetailsContainer.add(thrombosisContainer);

    WebMarkupContainer peritonitisContainer = new WebMarkupContainer(PERITONITIS_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    peritonitisContainer.add(new YesNoRadioGroup("peritonitis", true));
    patientDetailsContainer.add(peritonitisContainer);

    WebMarkupContainer pulmonaryOedemaContainer = new WebMarkupContainer(PULMONARY_OEDEMA_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return isSrnsModel.getObject();
        }
    };
    pulmonaryOedemaContainer.add(new YesNoRadioGroup("pulmonaryOedema", true));
    patientDetailsContainer.add(pulmonaryOedemaContainer);
    patientDetailsContainer.add(new YesNoRadioGroup("hypertension", true));

    //urticaria
    boolean showUrticariaOnInit = form.getModelObject().getUrticaria() != null
            ? form.getModelObject().getUrticaria()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showUrticariaOnInit = false;
    }

    final IModel<Boolean> showUrticariaIModel = new Model<Boolean>(showUrticariaOnInit);

    MarkupContainer urticariaDetailContainer = new WebMarkupContainer(URTICARIA_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showUrticariaIModel.getObject();
            }
            return false;
        }
    };
    componentsToUpdate.add(urticariaDetailContainer);

    urticariaDetailContainer.add(new TextArea("rashDetail")); // shares same field in db as rash detail It seems
    patientDetailsContainer.add(urticariaDetailContainer);
    urticariaDetailContainer.setOutputMarkupId(true);
    urticariaDetailContainer.setOutputMarkupPlaceholderTag(true);

    // More yes/no options
    WebMarkupContainer urticariaContainer = new WebMarkupContainer(URTICARIA_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup urticaria = new YesNoRadioGroup("urticaria", true);
    urticariaContainer.add(urticaria);
    patientDetailsContainer.add(urticariaContainer);
    urticaria.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showUrticariaIModel.setObject(Boolean.TRUE.equals(form.getModelObject().getUrticaria()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    // Diabetes
    WebMarkupContainer diabetesTypeContainer = new WebMarkupContainer(DIABETES_TYPE_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    diabetesTypeContainer.add(new DropDownChoice<ClinicalData.DiabetesType>("diabetesType",
            Arrays.asList(ClinicalData.DiabetesType.TYPE_I, ClinicalData.DiabetesType.TYPE_II,
                    ClinicalData.DiabetesType.NO),
            new ChoiceRenderer<ClinicalData.DiabetesType>("label", "id")));
    patientDetailsContainer.add(diabetesTypeContainer);

    boolean showRashDetailsOnInit = form.getModelObject().getRash() != null ? form.getModelObject().getRash()
            : false;
    // only show if diag is srns
    if (isSrnsModel.getObject().equals(false)) {
        showRashDetailsOnInit = false;
    }

    final IModel<Boolean> showRashDetailsIModel = new Model<Boolean>(showRashDetailsOnInit);

    // Rash details needs show/hide
    final MarkupContainer rashDetailContainer = new WebMarkupContainer(RASH_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showRashDetailsIModel.getObject();
            }
            return false;
        }
    };

    rashDetailContainer.add(new TextArea("rashDetail"));
    patientDetailsContainer.add(rashDetailContainer);
    rashDetailContainer.setOutputMarkupId(true);
    rashDetailContainer.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(rashDetailContainer);

    // More yes/no options
    WebMarkupContainer rashContainer = new WebMarkupContainer(RASH_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };
    YesNoRadioGroup rash = new YesNoRadioGroup("rash", true);
    rashContainer.add(rash);
    patientDetailsContainer.add(rashContainer);

    rash.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showRashDetailsIModel.setObject(Boolean.TRUE.equals(form.getModelObject().getRash()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    WebMarkupContainer possibleImmunisationTriggerContainer = new WebMarkupContainer(
            POSSIBLE_IMMUNISATION_TRIGGER_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup possibleImmunisationTrigger = new YesNoRadioGroup("possibleImmunisationTrigger", true);
    possibleImmunisationTriggerContainer.add(possibleImmunisationTrigger);
    patientDetailsContainer.add(possibleImmunisationTriggerContainer);

    WebMarkupContainer partialLipodystrophyContainer = new WebMarkupContainer(
            PARTIAL_LIPODYSTROPHY_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup partialLipodystrophy = new YesNoRadioGroup("partialLipodystrophy", true);

    partialLipodystrophyContainer.add(partialLipodystrophy);
    patientDetailsContainer.add(partialLipodystrophyContainer);

    WebMarkupContainer preceedingInfectionContainer = new WebMarkupContainer(
            PRECEEDING_INFECTION_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    // preceding infection
    boolean showPrecedingInfectionOnInit = form.getModelObject().getPreceedingInfection() != null
            ? form.getModelObject().getPreceedingInfection()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showPrecedingInfectionOnInit = false;
    }

    final IModel<Boolean> showPrecedingInfectioModel = new Model<Boolean>(showPrecedingInfectionOnInit);

    YesNoRadioGroup preceedingInfection = new YesNoRadioGroup("preceedingInfection", true);
    preceedingInfectionContainer.add(preceedingInfection);
    preceedingInfection.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showPrecedingInfectioModel
                    .setObject(Boolean.TRUE.equals(form.getModelObject().getPreceedingInfection()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });
    patientDetailsContainer.add(preceedingInfectionContainer);

    // Preceeding infection show/hide
    MarkupContainer preceedingInfectionDetailContainer = new WebMarkupContainer(
            PRECEEDING_INFECTION_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return showPrecedingInfectioModel.getObject();
        }
    };
    TextAreaWithHelpText preceedingInfectionDetail = new TextAreaWithHelpText("preceedingInfectionDetail",
            "Enter details") {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null ? clinicalData.getPreceedingInfectionDetail() != null
                    ? clinicalData.getPreceedingInfectionDetail()
                    : "" : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setPreceedingInfectionDetail(data);
            }
        }
    };
    preceedingInfectionDetail.initBehaviour();
    preceedingInfectionDetailContainer.add(preceedingInfectionDetail);
    patientDetailsContainer.add(preceedingInfectionDetailContainer);
    componentsToUpdate.add(preceedingInfectionDetailContainer);
    preceedingInfectionDetailContainer.setOutputMarkupId(true);
    preceedingInfectionDetailContainer.setOutputMarkupPlaceholderTag(true);

    // chronic infection
    boolean showChronicOnInit = form.getModelObject().getChronicInfection() != null
            ? form.getModelObject().getChronicInfection()
            : false;

    // only show if diag is mpgn/dd
    if (isSrnsModel.getObject().equals(true)) {
        showChronicOnInit = false;
    }

    final IModel<Boolean> showChronicModel = new Model<Boolean>(showChronicOnInit);

    WebMarkupContainer chronicInfectionActiveContainer = new WebMarkupContainer(
            CHRONIC_INFECTION_ACTIVE_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            return !hideElement(isFirstVisit, isSrnsModel.getObject(), getId());
        }
    };

    YesNoRadioGroup chronicInfection = new YesNoRadioGroup("chronicInfection", true);
    chronicInfection.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showChronicModel.setObject(Boolean.TRUE.equals(form.getModelObject().getChronicInfection()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });
    chronicInfectionActiveContainer.add(chronicInfection);
    patientDetailsContainer.add(chronicInfectionActiveContainer);

    // Chronic infection show/hide
    MarkupContainer chronicInfectionDetailContainer = new WebMarkupContainer(
            CHRONIC_INFECTION_DETAIL_CONTAINER_ID) {
        @Override
        public boolean isVisible() {
            if (!hideElement(isFirstVisit, isSrnsModel.getObject(), getId())) {
                return showChronicModel.getObject();
            }
            return false;
        }
    };
    TextAreaWithHelpText chronicInfectionDetail = new TextAreaWithHelpText("chronicInfectionDetail",
            "Enter Details") {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null ? clinicalData.getChronicInfectionDetail() != null
                    ? clinicalData.getChronicInfectionDetail()
                    : "" : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setChronicInfectionDetail(data);
            }
        }
    };

    chronicInfectionDetail.initBehaviour();

    chronicInfectionDetailContainer.add(chronicInfectionDetail);
    componentsToUpdate.add(chronicInfectionDetailContainer);
    chronicInfectionDetailContainer.setOutputMarkupId(true);
    chronicInfectionDetailContainer.setOutputMarkupPlaceholderTag(true);

    patientDetailsContainer.add(chronicInfectionDetailContainer);

    boolean showOphthalmoscopyDetailsOnInit = form.getModelObject().getOphthalmoscopy() != null
            ? form.getModelObject().getOphthalmoscopy()
            : false;

    final IModel<Boolean> showOphthalmoscopyDetailsIModel = new Model<Boolean>(showOphthalmoscopyDetailsOnInit);

    YesNoRadioGroup ophthalmoscopy = new YesNoRadioGroup("ophthalmoscopy", true);
    patientDetailsContainer.add(ophthalmoscopy);
    ophthalmoscopy.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            showOphthalmoscopyDetailsIModel
                    .setObject(Boolean.TRUE.equals(form.getModelObject().getOphthalmoscopy()));
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdate);
        }
    });

    // Ophthalmoscopy show/hide
    MarkupContainer ophthalmoscopyDetailContainer = new WebMarkupContainer("ophthalmoscopyDetailContainer") {
        @Override
        public boolean isVisible() {
            return showOphthalmoscopyDetailsIModel.getObject();
        }
    };
    ophthalmoscopyDetailContainer.setOutputMarkupId(true);
    ophthalmoscopyDetailContainer.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(ophthalmoscopyDetailContainer);

    TextAreaWithHelpText ophthalmoscopyDetail = new TextAreaWithHelpText("ophthalmoscopyDetail",
            ClinicalData.OPHTHALMOSCOPY_HELP_TEXT) {
        @Override
        public String getModelData() {
            ClinicalData clinicalData = formModel.getObject();
            return clinicalData != null
                    ? clinicalData.getOphthalmoscopyDetail() != null ? clinicalData.getOphthalmoscopyDetail()
                            : ""
                    : "";
        }

        @Override
        public void setModelData(String data) {
            ClinicalData clinicalData = formModel.getObject();
            if (clinicalData != null) {
                clinicalData.setOphthalmoscopyDetail(data);
            }
        }
    };

    ophthalmoscopyDetail.initBehaviour();

    ophthalmoscopyDetailContainer.add(ophthalmoscopyDetail);

    patientDetailsContainer.add(ophthalmoscopyDetailContainer);

    componentsToUpdate.add(systolicBloodPressureFeedback);
    componentsToUpdate.add(diastolicBloodPressureFeedback);

    // Complications
    WebMarkupContainer complicationsContainer = new WebMarkupContainer("complicationsContainer") {
        @Override
        public boolean isVisible() {
            return !isFirstVisit && isSrnsModel.getObject();
        }
    };

    complicationsContainer.add(new YesNoRadioGroup("infectionNecessitatingHospitalisation", false, false));
    MarkupContainer infectionDetailContainer = new WebMarkupContainer("infectionDetailContainer");
    infectionDetailContainer.add(new TextArea("infectionDetail"));
    complicationsContainer.add(infectionDetailContainer);

    complicationsContainer.add(new YesNoRadioGroup("complicationThrombosis", false, false));
    MarkupContainer complicationThrombosisDetailContainer = new WebMarkupContainer(
            "complicationThrombosisContainer");
    complicationThrombosisDetailContainer.add(new TextArea("complicationThrombosisDetail"));
    complicationsContainer.add(complicationThrombosisDetailContainer);

    // Hypertension
    complicationsContainer.add(new YesNoRadioGroup("hypertension", true));

    // CKD stage
    complicationsContainer.add(new CkdStageRadioGroup("ckdStage"));
    form.add(complicationsContainer);

    // Listed for transplant?

    WebMarkupContainer listedForTransplantContainer = new WebMarkupContainer("listedForTransplantContainer") {
        @Override
        public boolean isVisible() {
            return !isFirstVisit && isSrnsModel.getObject();
        }
    };

    form.add(listedForTransplantContainer);
    listedForTransplantContainer.add(new YesNoRadioGroup("listedForTransplant"));

    ClinicalAjaxSubmitLink save = new ClinicalAjaxSubmitLink("save") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    ClinicalAjaxSubmitLink saveDown = new ClinicalAjaxSubmitLink("saveDown") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    };

    form.add(save, saveDown);
}

From source file:org.patientview.radar.web.panels.followup.RrtTherapyPanel.java

License:Open Source License

public RrtTherapyPanel(String id, final IModel<Long> radarNumberModel) {
    super(id);/*from ww w  .jav  a  2 s  . c om*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // General details
    TextField radarNumber = new TextField("radarNumber", radarNumberModel);
    radarNumber.setEnabled(false);
    add(radarNumber);

    add(new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager)));

    add(new TextField("diagnosis", new PropertyModel(
            RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation")));

    add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager)));
    add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager)));
    add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager),
            RadarApplication.DATE_PATTERN));

    final IModel<Date> esrfDateModel = new LoadableDetachableModel<Date>() {
        @Override
        protected Date load() {
            Diagnosis diagnosis = RadarModelFactory.getDiagnosisModel(radarNumberModel, diagnosisManager)
                    .getObject();
            if (diagnosis != null) {
                return diagnosis.getEsrfDate();
            }
            return null;
        }
    };
    add(new DateLabel("esrfDate", esrfDateModel,
            new PatternDateConverter(RadarApplication.DATE_PATTERN, true)) {
        @Override
        public boolean isVisible() {
            return esrfDateModel.getObject() != null;
        }
    });
    add(new WebMarkupContainer("esrfNotEnteredContainer") {
        @Override
        public boolean isVisible() {
            return esrfDateModel.getObject() == null;
        }
    });

    // Reusable panel for the dialysis table
    add(new DialysisTablePanel("dialysisContainer", radarNumberModel));

    final IModel transplantListModel = new AbstractReadOnlyModel<List>() {
        @Override
        public List getObject() {

            if (radarNumberModel.getObject() != null) {
                return transplantManager.getTransplantsByRadarNumber(radarNumberModel.getObject());
            }
            return Collections.emptyList();

        }
    };

    final IModel editTransplantModel = new Model<Transplant>();
    final List<Component> addTransplantFormComponentsToUpdate = new ArrayList<Component>();
    final List<Component> editTransplantFormComponentsToUpdate = new ArrayList<Component>();

    final WebMarkupContainer transplantsContainer = new WebMarkupContainer("transplantsContainer");
    add(transplantsContainer);
    transplantsContainer.setOutputMarkupPlaceholderTag(true);
    transplantsContainer.setOutputMarkupId(true);

    // Container for edit transplants
    final MarkupContainer editTransplantContainer = new WebMarkupContainer("editTransplantContainer") {
        @Override
        public boolean isVisible() {
            return editTransplantModel.getObject() != null;
        }
    };

    editTransplantContainer.setOutputMarkupPlaceholderTag(true);
    editTransplantContainer.setOutputMarkupPlaceholderTag(true);
    add(editTransplantContainer);

    final IModel<Transplant.RejectData> addRejectModel = new CompoundPropertyModel<Transplant.RejectData>(
            new Model<Transplant.RejectData>());
    // Container for reject transplants
    final MarkupContainer rejectDataContainer = new WebMarkupContainer("rejectDataContainer") {
        @Override
        public boolean isVisible() {
            return addRejectModel.getObject() != null;
        }
    };
    rejectDataContainer.setOutputMarkupPlaceholderTag(true);
    rejectDataContainer.setOutputMarkupId(true);

    add(rejectDataContainer);

    // Transplants table
    transplantsContainer.add(new ListView<Transplant>("transplants", transplantListModel) {
        @Override
        protected void populateItem(final ListItem<Transplant> item) {
            item.setModel(new CompoundPropertyModel<Transplant>(item.getModelObject()));
            item.add(DateLabel.forDatePattern("date", RadarApplication.DATE_PATTERN));
            item.add(new Label("modality.description"));
            item.add(new Label("recurr", new AbstractReadOnlyModel<Object>() {
                @Override
                public Object getObject() {
                    return Boolean.TRUE.equals(item.getModelObject().getRecurr()) ? "yes" : "no";
                }
            }));
            item.add(DateLabel.forDatePattern("dateRecurr", RadarApplication.DATE_PATTERN));
            item.add(DateLabel.forDatePattern("dateFailureRejectData.failureDate",
                    RadarApplication.DATE_PATTERN));

            IModel rejectDataListModel = new AbstractReadOnlyModel<List>() {
                @Override
                public List getObject() {
                    return transplantManager.getRejectDataByTransplantNumber(item.getModelObject().getId());
                }
            };
            final WebMarkupContainer rejectDataListContainer = new WebMarkupContainer(
                    "rejectDataListContainer");
            rejectDataListContainer.setOutputMarkupId(true);
            rejectDataContainer.setOutputMarkupPlaceholderTag(true);
            rejectDataListContainer
                    .add(new ListView<Transplant.RejectData>("rejectDataList", rejectDataListModel) {
                        @Override
                        protected void populateItem(final ListItem<Transplant.RejectData> rejectDataListItem) {
                            rejectDataListItem.setModel(new CompoundPropertyModel<Transplant.RejectData>(
                                    rejectDataListItem.getModelObject()));
                            rejectDataListItem.add(
                                    DateLabel.forDatePattern("rejectedDate", RadarApplication.DATE_PATTERN));
                            rejectDataListItem
                                    .add(DateLabel.forDatePattern("biopsyDate", RadarApplication.DATE_PATTERN));
                            AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") {
                                @Override
                                public void onClick(AjaxRequestTarget target) {
                                    transplantManager.deleteRejectData(rejectDataListItem.getModelObject());
                                    target.add(rejectDataListContainer);
                                }
                            };
                            rejectDataListItem.add(ajaxDeleteLink);
                            ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour());

                            AuthenticatedWebSession session = RadarSecuredSession.get();
                            if (session.isSignedIn()) {
                                if (session.getRoles().hasRole(User.ROLE_PATIENT)) {
                                    ajaxDeleteLink.setVisible(false);
                                }
                            }

                        }
                    });

            item.add(rejectDataListContainer);

            // Delete, edit and add reject buttons
            AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Transplant transplant = item.getModelObject();
                    transplantManager.deleteTransplant(transplant);
                    target.add(addTransplantFormComponentsToUpdate
                            .toArray(new Component[addTransplantFormComponentsToUpdate.size()]));
                    target.add(transplantsContainer);
                }
            };
            item.add(ajaxDeleteLink);
            ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour());
            AjaxLink ajaxEditLink = new AjaxLink("editLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    editTransplantModel.setObject(item.getModelObject());
                    target.add(editTransplantContainer);
                }
            };
            item.add(ajaxEditLink);
            AjaxLink ajaxAddRejectLink = new AjaxLink("addRejectLink") {
                {
                    if (item.getModelObject().getDateFailureRejectData() != null) {
                        if (item.getModelObject().getDateFailureRejectData().getFailureDate() != null) {
                            setVisible(false);
                        }
                    }
                }

                @Override
                public void onClick(AjaxRequestTarget target) {
                    Transplant.RejectData rejectData = new Transplant.RejectData();
                    rejectData.setTransplantId(item.getModelObject().getId());
                    addRejectModel.setObject(rejectData);
                    target.add(rejectDataContainer);
                }
            };
            item.add(ajaxAddRejectLink);

            AuthenticatedWebSession session = RadarSecuredSession.get();
            if (session.isSignedIn()) {
                if (session.getRoles().hasRole(User.ROLE_PATIENT)) {
                    ajaxDeleteLink.setVisible(false);
                    ajaxEditLink.setVisible(false);
                    ajaxAddRejectLink.setVisible(false);
                }
            }
        }
    });

    final List<Component> rejectDataComponentsToUpdate = new ArrayList<Component>();
    // Form for adding reject data - model probably needs changing
    Form<Transplant.RejectData> rejectDataForm = new Form<Transplant.RejectData>("form", addRejectModel);
    rejectDataForm.add(new RadarDateTextField("rejectedDate", rejectDataForm, rejectDataComponentsToUpdate));
    rejectDataForm.add(new RadarDateTextField("biopsyDate", rejectDataForm, rejectDataComponentsToUpdate));
    rejectDataForm.add(new AjaxSubmitLink("add") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(rejectDataContainer);
            target.add(transplantsContainer);
            target.add(
                    rejectDataComponentsToUpdate.toArray(new Component[rejectDataComponentsToUpdate.size()]));
            try {
                transplantManager.saveRejectDataWithValidation((Transplant.RejectData) form.getModelObject());
            } catch (InvalidModelException e) {
                for (String error : e.getErrors()) {
                    error(error);
                }
                return;

            }
            addRejectModel.setObject(null);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(
                    rejectDataComponentsToUpdate.toArray(new Component[rejectDataComponentsToUpdate.size()]));
        }
    });
    rejectDataForm.add(new AjaxLink("cancel") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            addRejectModel.setObject(null);
            target.add(rejectDataContainer);
        }
    });
    rejectDataForm.add(DateLabel.forDatePattern("transplantDate", new Model<Date>(), "dd/MM/yyyy"));
    rejectDataContainer.add(rejectDataForm);
    rejectDataForm.add(new FeedbackPanel("dateRejectFeedback", new IFeedbackMessageFilter() {
        public boolean accept(FeedbackMessage feedbackMessage) {
            List<String> acceptedErrorMessages = new ArrayList<String>();
            acceptedErrorMessages.addAll(TransplantManager.REJECT_DATA_ERROR_MESSAGES);
            return acceptedErrorMessages.contains(feedbackMessage.getMessage());
        }
    }));

    // Edit transplant form
    Form<Transplant> editTransplantForm = new TransplantForm("form",
            new CompoundPropertyModel<Transplant>(editTransplantModel), editTransplantFormComponentsToUpdate);
    editTransplantContainer.add(editTransplantForm);

    editTransplantForm.add(new AjaxSubmitLink("saveTop") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(editTransplantContainer);
            target.add(transplantsContainer);

            try {
                transplantManager.saveTransplant((Transplant) form.getModelObject());
            } catch (InvalidModelException e) {
                for (String error : e.getErrors()) {
                    error(error);
                }
                return;
            }

            editTransplantModel.setObject(null);

        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(editTransplantFormComponentsToUpdate
                    .toArray(new Component[editTransplantFormComponentsToUpdate.size()]));
        }
    });

    editTransplantForm.add(new AjaxLink("cancelTop") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            editTransplantModel.setObject(null);
            target.add(editTransplantContainer);
        }
    });

    editTransplantForm.add(new AjaxSubmitLink("saveBottom") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(editTransplantContainer);
            target.add(transplantsContainer);

            try {
                transplantManager.saveTransplant((Transplant) form.getModelObject());
            } catch (InvalidModelException e) {
                for (String error : e.getErrors()) {
                    error(error);
                }
                return;
            }

            editTransplantModel.setObject(null);

        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(editTransplantFormComponentsToUpdate
                    .toArray(new Component[editTransplantFormComponentsToUpdate.size()]));
        }
    });

    editTransplantForm.add(new AjaxLink("cancelBottom") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            editTransplantModel.setObject(null);
            target.add(editTransplantContainer);
        }
    });

    // Add transplant form
    Form<Transplant> addTransplantForm = new TransplantForm("addTransplantForm",
            new CompoundPropertyModel<Transplant>(new Transplant()), addTransplantFormComponentsToUpdate);
    addTransplantForm.add(new AjaxSubmitLink("add") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            target.add(form);
            Transplant transplant = (Transplant) form.getModelObject();
            transplant.setRadarNumber(radarNumberModel.getObject());
            try {
                transplantManager.saveTransplant(transplant);
            } catch (InvalidModelException e) {
                for (String error : e.getErrors()) {
                    error(error);
                }
                return;
            }
            form.getModel().setObject(new Transplant());
            transplantsContainer.setVisible(true);
            target.add(transplantsContainer);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(addTransplantFormComponentsToUpdate
                    .toArray(new Component[addTransplantFormComponentsToUpdate.size()]));
        }
    });
    addTransplantForm.setOutputMarkupId(true);
    addTransplantForm.setOutputMarkupPlaceholderTag(true);
    add(addTransplantForm);

}

From source file:org.patientview.radar.web.panels.generic.GenericDemographicsPanel.java

License:Open Source License

private void init(Patient patient) {
    setOutputMarkupId(true);//  w  w w  .  j a  v a2s  .  c  om
    setOutputMarkupPlaceholderTag(true);

    List<Component> nonEditableComponents = new ArrayList<Component>();

    final ProfessionalUser user = (ProfessionalUser) RadarSecuredSession.get().getUser();

    if (patient.getDateReg() == null) {
        patient.setDateReg(new Date());
    }

    // components to update on ajax refresh
    final List<Component> componentsToUpdateList = new ArrayList<Component>();

    // add form
    final IModel<Patient> model = new Model(patient);

    //Error Message
    String message = "Please complete all mandatory fields";
    final LabelMessage labelMessage = new LabelMessage();
    labelMessage.setMessage(message);
    final PropertyModel<LabelMessage> messageModel = new PropertyModel<LabelMessage>(labelMessage, "message");

    // no exist data in patient table, then use the user name to populate.
    if (patient.getSurname() == null || patient.getForename() == null) {

        String name = utilityManager.getUserName(patient.getNhsno());

        if (name != null && !"".equals(name)) {
            // split the user name with a space
            String[] names = name.split(" ");
            if (names != null && names.length >= 2) {
                patient.setForename(name.substring(0, name.indexOf(names[names.length - 1])));
                patient.setSurname(names[names.length - 1]);

            } else {
                patient.setForename(name);
            }
        }
    }

    Form<Patient> form = new Form<Patient>("form", new CompoundPropertyModel(model)) {
        @Override
        protected void onSubmit() {

            Patient patient = getModel().getObject();

            // check dob exists
            if (patient.getDob() != null) {
                // make sure diagnosis date is after dob
                if (patient.getDateOfGenericDiagnosis() != null
                        && patient.getDateOfGenericDiagnosis().compareTo(patient.getDob()) < 0) {
                    get("dateOfGenericDiagnosisContainer:dateOfGenericDiagnosis")
                            .error("Your diagnosis date cannot be before your date of birth");
                }
            }

            // Leaving this in, saved to the DB table
            patient.setGeneric(true);

            try {
                /** At this point we either have
                 1) A new patient we would like to register
                 2) A link patient we would like to register
                 3) An existing linked patient we would like to update changes to the Patient table
                 4) An existing patient we would like to update changes to the Patient table **/
                userManager.addPatientUserOrUpdatePatient(patient);

            } catch (RegisterException re) {
                LOGGER.error("Registration Exception", re);
                String message = "Failed to register patient: " + re.getMessage();
                labelMessage.setMessage(message);
                error(message);
            } catch (Exception e) {
                String message = "Error registering new patient to accompany this demographic";
                LOGGER.error("Unknown error", e);
                error(message);
            }
        }
    };

    add(form);

    WebMarkupContainer patientDetail = new PatientDetailPanel("patientDetail", patient, "Demographics");
    patientDetail.setOutputMarkupId(true);
    patientDetail.setOutputMarkupPlaceholderTag(true);
    form.add(patientDetail);
    componentsToUpdateList.add(patientDetail);

    RadarRequiredTextField surname = new RadarRequiredTextField("surname", form, componentsToUpdateList);
    RadarRequiredTextField forename = new RadarRequiredTextField("forename", form, componentsToUpdateList);
    TextField alias = new TextField("surnameAlias");
    RadarRequiredDateTextField dateOfBirth = new RadarRequiredDateTextField("dob", form,
            componentsToUpdateList);

    form.add(surname, forename, alias, dateOfBirth);
    nonEditableComponents.add(surname);
    nonEditableComponents.add(forename);
    nonEditableComponents.add(dateOfBirth);
    // Sex
    RadarRequiredDropdownChoice sex = new RadarRequiredDropdownChoice("sexModel", patientManager.getSexes(),
            new ChoiceRenderer<Sex>("type", "id"), form, componentsToUpdateList);

    nonEditableComponents.add(sex);

    // Ethnicity
    DropDownChoice<Ethnicity> ethnicity = new DropDownChoice<Ethnicity>("ethnicity",
            utilityManager.getEthnicities(), new ChoiceRenderer<Ethnicity>("name", "id"));
    form.add(sex, ethnicity);

    // Address fields
    TextField address1 = new TextField("address1");
    TextField address2 = new TextField("address2");
    TextField address3 = new TextField("address3");
    TextField address4 = new TextField("address4");
    RadarTextFieldWithValidation postcode = new RadarTextFieldWithValidation("postcode",
            new PatternValidator("[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$"), form,
            componentsToUpdateList);
    form.add(address1, address2, address3, address4, postcode);

    nonEditableComponents.add(address1);
    nonEditableComponents.add(address2);
    nonEditableComponents.add(address3);
    nonEditableComponents.add(address4);
    nonEditableComponents.add(postcode);
    // More info
    Label nhsNumber = new Label("nhsno");

    WebMarkupContainer nhsNumberContainer = new WebMarkupContainer("nhsNumberContainer");

    nhsNumberContainer.add(nhsNumber);

    // add new ids section
    final List<Component> addIdComponentsToUpdate = new ArrayList<Component>();

    IModel<AddIdModel> addIdModel = new Model<AddIdModel>(new AddIdModel());
    Form<AddIdModel> addIdForm = new Form<AddIdModel>("addIdForm", new CompoundPropertyModel(addIdModel)) {
        @Override
        protected void onSubmit() {
            AddIdModel idModel = getModel().getObject();
            Patient patient = model.getObject();
            String id = idModel.getId();
            if (idModel.getIdType() != null) {
                if (idModel.getIdType().equals(IdType.CHANNELS_ISLANDS)) {
                    patient.setChannelIslandsId(id);
                }
                if (idModel.getIdType().equals(IdType.HOSPITAL_NUMBER)) {
                    patient.setHospitalnumber(id);
                }
                if (idModel.getIdType().equals(IdType.INDIA)) {
                    patient.setIndiaId(id);
                }
                if (idModel.getIdType().equals(IdType.RENAL_REGISTRY_NUMBER)) {
                    patient.setRrNo(id);
                }
                if (idModel.getIdType().equals(IdType.REPUBLIC_OF_IRELAND)) {
                    patient.setRepublicOfIrelandId(id);
                }
                if (idModel.getIdType().equals(IdType.UK_TRANSPLANT_NUMBER)) {
                    patient.setUktNo(id);
                }
            }
        }

    };

    AjaxSubmitLink addIdSubmit = new AjaxSubmitLink("addIdSubmit") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, addIdComponentsToUpdate);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, addIdComponentsToUpdate);
        }
    };

    TextField addIdValue = new TextField("id");

    DropDownChoice addIdType = null;

    // Link patients should not be able to add hospital numbers
    if (!patient.isLinked()) {
        addIdType = new DropDownChoice("idType",
                Arrays.asList(IdType.HOSPITAL_NUMBER, IdType.RENAL_REGISTRY_NUMBER, IdType.UK_TRANSPLANT_NUMBER,
                        IdType.REPUBLIC_OF_IRELAND, IdType.CHANNELS_ISLANDS, IdType.INDIA),
                new ChoiceRenderer());
    } else {
        addIdType = new DropDownChoice("idType",
                Arrays.asList(IdType.RENAL_REGISTRY_NUMBER, IdType.UK_TRANSPLANT_NUMBER,
                        IdType.REPUBLIC_OF_IRELAND, IdType.CHANNELS_ISLANDS, IdType.INDIA),
                new ChoiceRenderer());
    }

    addIdForm.add(addIdValue, addIdType, addIdSubmit);
    form.add(addIdForm);

    TextField hospitalNumber = new TextField("hospitalnumber");
    WebMarkupContainer hospitalNumberContainer = new WebMarkupContainer("hospitalNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getHospitalnumber() != null) {
                if (!model.getObject().getHospitalnumber().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };

    hospitalNumberContainer.add(hospitalNumber);
    nonEditableComponents.add(hospitalNumber);

    TextField renalRegistryNumber = new TextField("rrNo");
    WebMarkupContainer renalRegistryNumberContainer = new WebMarkupContainer("renalRegistryNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getRrNo() != null) {
                if (!model.getObject().getRrNo().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    renalRegistryNumberContainer.add(renalRegistryNumber);

    TextField ukTransplantNumber = new TextField("uktNo");

    WebMarkupContainer ukTransplantNumberContainer = new WebMarkupContainer("ukTransplantNumberContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getUktNo() != null) {
                if (!model.getObject().getUktNo().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    ukTransplantNumberContainer.add(ukTransplantNumber);

    // add other generic ids
    TextField republicOfIrelandId = new TextField("republicOfIrelandId");

    WebMarkupContainer republicOfIrelandIdContainer = new WebMarkupContainer("republicOfIrelandIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getRepublicOfIrelandId() != null) {
                if (!model.getObject().getRepublicOfIrelandId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    republicOfIrelandIdContainer.add(republicOfIrelandId);

    TextField isleOfManId = new TextField("isleOfManId");

    WebMarkupContainer isleOfManIdContainer = new WebMarkupContainer("isleOfManIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getIsleOfManId() != null) {
                if (!model.getObject().getIsleOfManId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };

    isleOfManIdContainer.add(isleOfManId);

    TextField channelIslandsId = new TextField("channelIslandsId");

    WebMarkupContainer channelIslandsIdContainer = new WebMarkupContainer("channelIslandsIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getChannelIslandsId() != null) {
                if (!model.getObject().getChannelIslandsId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    channelIslandsIdContainer.add(channelIslandsId);

    TextField indiaId = new TextField("indiaId");

    WebMarkupContainer indiaIdContainer = new WebMarkupContainer("indiaIdContainer") {
        @Override
        public boolean isVisible() {
            if (model.getObject().getIndiaId() != null) {
                if (!model.getObject().getIndiaId().isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    };
    indiaIdContainer.add(indiaId);

    addIdComponentsToUpdate.add(hospitalNumberContainer);
    addIdComponentsToUpdate.add(renalRegistryNumberContainer);
    addIdComponentsToUpdate.add(ukTransplantNumberContainer);
    addIdComponentsToUpdate.add(republicOfIrelandIdContainer);
    addIdComponentsToUpdate.add(isleOfManIdContainer);
    addIdComponentsToUpdate.add(channelIslandsIdContainer);
    addIdComponentsToUpdate.add(indiaIdContainer);

    for (Component component : Arrays.asList(hospitalNumberContainer, renalRegistryNumberContainer,
            ukTransplantNumberContainer, republicOfIrelandIdContainer, isleOfManIdContainer,
            channelIslandsIdContainer, indiaIdContainer)) {
        component.setOutputMarkupPlaceholderTag(true);
    }

    form.add(hospitalNumberContainer, nhsNumberContainer, renalRegistryNumberContainer,
            ukTransplantNumberContainer);
    form.add(republicOfIrelandIdContainer, isleOfManIdContainer, channelIslandsIdContainer, indiaIdContainer);

    // Consultant and renal unit
    final ClinicianDropDown clinician = new ClinicianDropDown("clinician", user, form.getModelObject());
    form.add(clinician);

    Label sourceUnitCodeLabel = new Label("sourceUnitCodeLabel", "Linked to") {
        @Override
        public boolean isVisible() {
            return model.getObject().isLinked();

        }

    };

    String sourceUnitNameLabelValue = model.getObject().getPatientLinkUnitCode() != null
            ? utilityManager.getCentre(model.getObject().getPatientLinkUnitCode()).getName()
            : "";

    Label sourceUnitCode = new Label("sourceUnitCode", sourceUnitNameLabelValue) {
        @Override
        public boolean isVisible() {
            return model.getObject().isLinked();

        }
    };
    form.add(sourceUnitCodeLabel, sourceUnitCode);

    final DropDownChoice<Centre> renalUnit = new PatientCentreDropDown("renalUnit", user, patient, form,
            componentsToUpdateList);

    renalUnit.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Patient patient = model.getObject();
            if (patient != null) {
                clinician.updateCentre(
                        patient.getRenalUnit() != null ? patient.getRenalUnit().getUnitCode() : null);
            }

            // re-render the component
            clinician.clearInput();
            target.add(clinician);
        }
    });

    form.add(renalUnit);

    final IModel<String> consentUserModel = new Model<String>(
            utilityManager.getUserFullName(patient.getRadarConsentConfirmedByUserId()));

    final Label tickConsentUser = new Label("radarConsentConfirmedByUserId", consentUserModel) {
        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(consentUserModel.getObject());
        }
    };
    tickConsentUser.setOutputMarkupId(true);
    tickConsentUser.setOutputMarkupPlaceholderTag(true);
    form.add(tickConsentUser);

    final RadarRequiredCheckBox consent = new RadarRequiredCheckBox("consent", form, componentsToUpdateList);

    consent.add(new AjaxFormComponentUpdatingBehavior("onclick") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            target.add(tickConsentUser);

            if (consent.getModel().getObject().equals(Boolean.TRUE)) {
                model.getObject()
                        .setRadarConsentConfirmedByUserId(RadarSecuredSession.get().getUser().getUserId());
                consentUserModel.setObject(RadarSecuredSession.get().getUser().getName());
                tickConsentUser.setVisible(true);

            } else {
                tickConsentUser.setVisible(false);
            }
        }
    });

    form.add(consent);

    form.add(new ExternalLink("consentFormsLink", "http://www.rarerenal.org/join/criteria-and-consent/"));

    // add generic fields
    TextField emailAddress = new TextField("emailAddress");
    TextField phone1 = new TextField("telephone1");
    TextField phone2 = new TextField("telephone2");

    nonEditableComponents.add(phone1);

    RadarTextFieldWithValidation mobile = new RadarTextFieldWithValidation("mobile",
            new PatternValidator(MetaPattern.DIGITS), form, componentsToUpdateList);

    RadarRequiredDropdownChoice genericDiagnosis = new RadarRequiredDropdownChoice("genericDiagnosisModel",
            genericDiagnosisManager.getByDiseaseGroup(patient.getDiseaseGroup()),
            new ChoiceRenderer("term", "id"), form, componentsToUpdateList);

    final IModel<Boolean> diagnosisDateVisibility = new Model<Boolean>(Boolean.FALSE);

    final CheckBox diagnosisDateSelect = new CheckBox("diagnosisDateSelect", new Model<Boolean>(Boolean.FALSE));
    model.getObject().setDiagnosisDateSelect(model.getObject().getDiagnosisDateSelect() == Boolean.TRUE);

    diagnosisDateSelect.add(new AjaxFormComponentUpdatingBehavior("onClick") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            diagnosisDateVisibility.setObject(diagnosisDateSelect.getModel().getObject());
            target.add(componentsToUpdateList.toArray(new Component[componentsToUpdateList.size()]));
        }
    });

    RadarRequiredDateTextField dateOfGenericDiagnosis = new RadarRequiredDateTextField("dateOfGenericDiagnosis",
            form, componentsToUpdateList);

    form.add(diagnosisDateSelect);

    MarkupContainer dateOfGenericDiagnosisContainer = new WebMarkupContainer(
            "dateOfGenericDiagnosisContainer") {
        @Override
        public boolean isVisible() {
            if (diagnosisDateVisibility.getObject()) {
                return false;
            } else {
                return true;
            }
        }
    };
    dateOfGenericDiagnosisContainer.add(dateOfGenericDiagnosis);
    componentsToUpdateList.add(dateOfGenericDiagnosisContainer);
    dateOfGenericDiagnosisContainer.setOutputMarkupId(true);
    dateOfGenericDiagnosisContainer.setOutputMarkupPlaceholderTag(true);

    this.dateOfGenericDiagnosisContainer = dateOfGenericDiagnosisContainer;

    TextArea otherClinicianAndContactInfo = new TextArea("otherClinicianAndContactInfo");
    TextArea comments = new TextArea("comments");

    form.add(emailAddress, phone1, phone2, mobile, genericDiagnosis, dateOfGenericDiagnosisContainer,
            otherClinicianAndContactInfo, comments);

    RadioGroup<Patient.RRTModality> rrtModalityRadioGroup = new RadioGroup<Patient.RRTModality>(
            "rrtModalityEunm");
    rrtModalityRadioGroup.add(new Radio("hd", new Model(Patient.RRTModality.HD)));
    rrtModalityRadioGroup.add(new Radio("pd", new Model(Patient.RRTModality.PD)));
    rrtModalityRadioGroup.add(new Radio("tx", new Model(Patient.RRTModality.Tx)));
    rrtModalityRadioGroup.add(new Radio("none", new Model(Patient.RRTModality.NONE)));

    form.add(rrtModalityRadioGroup);

    RadarComponentFactory.getSuccessMessageLabel("successMessage", form, componentsToUpdateList);

    RadarComponentFactory.getSuccessMessageLabel("successMessageUp", form, componentsToUpdateList);

    RadarComponentFactory.getMessageLabel("errorMessage", form, messageModel, componentsToUpdateList);
    RadarComponentFactory.getMessageLabel("errorMessageUp", form, messageModel, componentsToUpdateList);

    AjaxSubmitLink ajaxSubmitLinkTop = new AjaxSubmitLink("saveTop") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
        }
    };

    AjaxSubmitLink ajaxSubmitLinkBottom = new AjaxSubmitLink("saveBottom") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
        }
    };

    form.add(ajaxSubmitLinkTop);
    form.add(ajaxSubmitLinkBottom);

    if (patient.isLinked()) {
        for (Component component : nonEditableComponents) {
            component.setEnabled(false);
        }
    }

}

From source file:org.patientview.radar.web.panels.HospitalisationPanel.java

License:Open Source License

public HospitalisationPanel(String id, final IModel<Long> radarNumberModel) {
    super(id);/*from  ww  w .j  av  a 2  s .  com*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // Add container for the form, it is not shown on first visit
    final MarkupContainer hospitalisationContainer = new WebMarkupContainer("hospitalisationContainer");
    hospitalisationContainer.setVisible(false);
    hospitalisationContainer.setOutputMarkupId(true);
    hospitalisationContainer.setOutputMarkupPlaceholderTag(true);
    add(hospitalisationContainer);

    // Set up models for the previous results switcher
    final IModel<Hospitalisation> hospitalisationModel = new Model<Hospitalisation>();

    IModel<List<Hospitalisation>> hospitalisations = new AbstractReadOnlyModel<List<Hospitalisation>>() {
        @Override
        public List<Hospitalisation> getObject() {
            if (radarNumberModel.getObject() == null) {
                return Collections.emptyList();
            } else {
                return hospitalisationManager.getHospitalisationsByRadarNumber(radarNumberModel.getObject());
            }
        }
    };

    // Previous results switcher
    final DropDownChoice<Hospitalisation> hospitilisationSwitcher = new DropDownChoice<Hospitalisation>(
            "hospitilisationSwitcher", hospitalisationModel, hospitalisations,
            new DateChoiceRenderer("dateOfAdmission", "id") {
                @Override
                protected Date getDate(Object object) {
                    return ((Hospitalisation) object).getDateOfAdmission();
                }
            });
    add(hospitilisationSwitcher);

    // Add ajax behaviour to update form
    hospitilisationSwitcher.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            hospitalisationContainer.setVisible(true);
            target.add(hospitalisationContainer);
        }
    });

    // Add ajax add new
    add(new AjaxLink("addNew") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            hospitalisationContainer.setVisible(true);
            hospitalisationModel.setObject(new Hospitalisation());
            hospitilisationSwitcher.clearInput();
            target.add(hospitalisationContainer, hospitilisationSwitcher);
        }
    });

    final List<Component> componentsToUpdate = new ArrayList<Component>();
    componentsToUpdate.add(hospitilisationSwitcher);

    // Set up the form
    Form<Hospitalisation> form = new Form<Hospitalisation>("form",
            new CompoundPropertyModel<Hospitalisation>(hospitalisationModel)) {
        @Override
        protected void onValidateModelObjects() {
            super.onValidateModelObjects();
            Hospitalisation hospitalisation = getModelObject();
            Date dateofAdmission = hospitalisation.getDateOfAdmission();
            Date dateofDischarge = hospitalisation.getDateOfDischarge();
            if (dateofAdmission != null && dateofDischarge != null
                    && dateofAdmission.compareTo(dateofDischarge) != -1) {
                get("dateOfDischarge").error("Date has to be after admission date");
            }
        }

        @Override
        protected void onSubmit() {
            Hospitalisation hospitalisation = getModelObject();
            hospitalisation.setRadarNumber(radarNumberModel.getObject());
            hospitalisationManager.saveHospitilsation(hospitalisation);
        }
    };

    Label successLabel = RadarComponentFactory.getSuccessMessageLabel("successMessage", form,
            componentsToUpdate);
    Label successLabelDown = RadarComponentFactory.getSuccessMessageLabel("successMessageDown", form,
            componentsToUpdate);

    Label errorLabel = RadarComponentFactory.getErrorMessageLabel("errorMessage", form, componentsToUpdate);
    Label errorLabelDown = RadarComponentFactory.getErrorMessageLabel("errorMessageDown", form,
            componentsToUpdate);

    // General details
    TextField<Long> radarNumber = new TextField<Long>("radarNumber", radarNumberModel);
    radarNumber.setEnabled(false);
    form.add(radarNumber);

    form.add(new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager)));

    form.add(new TextField("diagnosis", new PropertyModel(
            RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation")));

    form.add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager)));
    form.add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager)));
    form.add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager),
            RadarApplication.DATE_PATTERN));

    form.add(new RadarRequiredDateTextField("dateOfAdmission", form, componentsToUpdate));
    form.add(new RadarDateTextField("dateOfDischarge", form, componentsToUpdate));
    form.add(new TextArea("reason"));
    form.add(new TextArea("comments"));
    form.add(new HospitilisationAjaxSubmitLink("save") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    });

    form.add(new HospitilisationAjaxSubmitLink("saveDown") {
        @Override
        protected List<? extends Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    });
    hospitalisationContainer.add(form);
}

From source file:org.patientview.radar.web.panels.NonAlportGeneticsPanel.java

License:Open Source License

public NonAlportGeneticsPanel(final String id, final Patient patient) {
    super(id);//from   w  w w  .j a  v a  2s.  c o m

    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    Genetics genetics = null;

    if (patient.hasValidId()) {
        genetics = geneticsManager.get(patient.getRadarNo());
    }

    if (genetics == null) {
        genetics = new Genetics();
        genetics.setRadarNo(patient.getRadarNo());
    }

    // main model for this tab
    final IModel<Genetics> model = new Model<Genetics>(genetics);

    // components to update on ajax refresh
    final List<Component> componentsToUpdateList = new ArrayList<Component>();

    // general feedback for messages that are not to do with a certain component in the form
    final FeedbackPanel formFeedback = new FeedbackPanel("formFeedbackPanel");
    formFeedback.setOutputMarkupId(true);
    formFeedback.setOutputMarkupPlaceholderTag(true);
    componentsToUpdateList.add(formFeedback);

    Form<Genetics> form = new Form<Genetics>("form", new CompoundPropertyModel<Genetics>(model)) {
        @Override
        protected void onSubmit() {
            Genetics genetics = getModelObject();

            if (genetics.getLabWhereTestWasDone() != null && genetics.getLabWhereTestWasDone().length() > 150) {
                error("Laboratory where sent/done is limited to 150 characters.");
            }

            // requirement is to limit to 20 lines of text -> 130 chars per line ~ 2500 chars
            if (genetics.getWhatResultsShowed() != null && genetics.getWhatResultsShowed().length() > 2500) {
                error("Laboratory where sent/done is limited to 2500 characters.");
            }

            if (genetics.getTestsDone() == null) {
                error("Please select if a sample been sent for Genetic analysis");
            }

            if (Genetics.TestsDone.YES_IN_THIS_PATIENT.equals(genetics.getTestsDone())) {
                if (genetics.getDateSent() == null) {
                    error("Please select Date Sent if a sample been sent.");
                }
            }

            if (!hasError()) {
                genetics.setRadarNo(patient.getRadarNo());
                geneticsManager.save(genetics);
            }
        }
    };

    add(form);

    // have to set the generic feedback panel to only pick up msgs for them form
    ComponentFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(form);
    formFeedback.setFilter(filter);
    form.add(formFeedback);

    // add the patient detail bar to the tab
    PatientDetailPanel patientDetail = new PatientDetailPanel("patientDetail", patient, "Genetics");
    patientDetail.setOutputMarkupId(true);
    form.add(patientDetail);
    componentsToUpdateList.add(patientDetail);

    // Date picker
    final DateTextField dateSent = new RadarRequiredDateTextField("dateSent", form, componentsToUpdateList);
    componentsToUpdateList.add(dateSent);
    MarkupContainer dateSentLabel = new WebMarkupContainer("dateSentLabel") {
        @Override
        public boolean isVisible() {
            Genetics genetics = model.getObject();
            if (genetics.getTestsDone() == null || genetics.getTestsDone().equals(Genetics.TestsDone.NO)) {
                return false;
            } else {
                return true;
            }
        }
    };
    dateSentLabel.setOutputMarkupId(true);
    dateSentLabel.add(dateSent);
    dateSentLabel.setOutputMarkupPlaceholderTag(true);

    form.add(dateSentLabel);
    componentsToUpdateList.add(dateSentLabel);

    //        if (genetics.getTestsDone() == null || genetics.getTestsDone().equals(Genetics.TestsDone.NO)){
    //            dateSent.setVisible(false);
    //            dateSentLabel.setVisible(false);
    //        }

    RadioGroup<Genetics.TestsDone> testsDoneRadioGroup = new RadioGroup<Genetics.TestsDone>("testsDone");
    form.add(testsDoneRadioGroup);

    Radio testsDoneNo = new Radio<Genetics.TestsDone>("testsDoneNo",
            new Model<Genetics.TestsDone>(Genetics.TestsDone.NO));
    testsDoneRadioGroup.add(testsDoneNo);
    testsDoneNo.add(new AjaxEventBehavior("onchange") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            model.getObject().setTestsDone(Genetics.TestsDone.NO);
            target.add(componentsToUpdateList.toArray(new Component[componentsToUpdateList.size()]));
        }
    });
    Radio testsDoneYes = new Radio<Genetics.TestsDone>("testsDoneYes",
            new Model<Genetics.TestsDone>(Genetics.TestsDone.YES_IN_THIS_PATIENT));
    testsDoneRadioGroup.add(testsDoneYes);
    testsDoneYes.add(new AjaxEventBehavior("onchange") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            model.getObject().setTestsDone(Genetics.TestsDone.YES_IN_THIS_PATIENT);
            target.add(componentsToUpdateList.toArray(new Component[componentsToUpdateList.size()]));
        }
    });

    form.add(new TextArea<String>("labWhereTestWasDone"));
    form.add(new TextField<String>("referenceNumber"));
    form.add(new TextArea<String>("whatResultsShowed"));

    Label successMessageTop = RadarComponentFactory.getSuccessMessageLabel("successMessageTop", form,
            componentsToUpdateList);
    Label errorMessageTop = RadarComponentFactory.getErrorMessageLabel("errorMessageTop", form,
            componentsToUpdateList);

    Label successMessageBottom = RadarComponentFactory.getSuccessMessageLabel("successMessageBottom", form,
            componentsToUpdateList);
    Label errorMessageBottom = RadarComponentFactory.getErrorMessageLabel("errorMessageBottom", form,
            componentsToUpdateList);

    form.add(new AjaxSubmitLink("saveTop") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
            target.add(formFeedback);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.add(formFeedback);
        }
    });

    form.add(new AjaxSubmitLink("saveBottom") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
            target.add(formFeedback);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.add(formFeedback);
        }
    });
}

From source file:org.patientview.radar.web.panels.PathologyPanel.java

License:Open Source License

public PathologyPanel(String id, final IModel<Long> radarNumberModel) {
    super(id);/*w  w w  .j a v a2  s . co m*/
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    // Model for tha pathology container, the pathology ID
    final IModel<Pathology> pathologyModel = new Model<Pathology>();

    IModel pathologiesListModel = new AbstractReadOnlyModel<List>() {
        @Override
        public List getObject() {
            if (radarNumberModel.getObject() != null) {
                List list = pathologyManager.getPathologyByRadarNumber(radarNumberModel.getObject());
                return !list.isEmpty() ? list : Collections.emptyList();
            }
            return Collections.emptyList();
        }
    };

    // Container for form, so we can hide and first then show
    final MarkupContainer pathologyContainer = new WebMarkupContainer("pathologyContainer");
    pathologyContainer.setVisible(false);
    pathologyContainer.setOutputMarkupId(true);
    pathologyContainer.setOutputMarkupPlaceholderTag(true);
    add(pathologyContainer);

    // Switcheroo
    final DropDownChoice<Pathology> pathologySwitcher = new DropDownChoice<Pathology>("pathologySwitcher",
            pathologyModel, pathologiesListModel, new DateChoiceRenderer("biopsyDate", "id") {
                @Override
                protected Date getDate(Object object) {
                    return ((Pathology) object).getBiopsyDate();
                }
            });
    pathologySwitcher.setOutputMarkupId(true);
    pathologySwitcher.setOutputMarkupPlaceholderTag(true);
    add(pathologySwitcher);

    // Add new
    add(new AjaxLink("addNew") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            pathologyContainer.setVisible(true);
            pathologyModel.setObject(new Pathology());
            pathologySwitcher.clearInput();
            target.add(pathologyContainer, pathologySwitcher);
        }
    });

    // Add Ajax behaviour to switch the container on change
    pathologySwitcher.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            pathologyContainer.setVisible(true);
            target.add(pathologyContainer);
        }
    });

    final List<Component> componentsToUpdate = new ArrayList<Component>();
    componentsToUpdate.add(pathologySwitcher);

    // Set up model
    Form<Pathology> form = new Form<Pathology>("form", new CompoundPropertyModel<Pathology>(pathologyModel)) {
        @Override
        protected void onSubmit() {
            Pathology pathology = getModelObject();
            pathology.setRadarNumber(radarNumberModel.getObject());
            try {
                pathologyManager.savePathology(pathology);
            } catch (InvalidModelException e) {
                for (String message : e.getErrors()) {
                    if (message.equals(PathologyManager.TOTAL_ERROR)) {
                        get("totalNumber").error(PathologyManager.TOTAL_ERROR);
                    }
                }
            }
        }
    };
    pathologyContainer.add(form);

    RadarComponentFactory.getSuccessMessageLabel("successMessage", form, componentsToUpdate);
    RadarComponentFactory.getSuccessMessageLabel("successMessageDown", form, componentsToUpdate);

    RadarComponentFactory.getErrorMessageLabel("errorMessage", form, componentsToUpdate);
    RadarComponentFactory.getErrorMessageLabel("errorMessageDown", form, componentsToUpdate);

    // General details
    TextField<Long> radarNumber = new TextField<Long>("radarNumber", radarNumberModel);
    radarNumber.setEnabled(false);
    form.add(radarNumber);

    form.add(new TextField("hospitalNumber",
            RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager)));

    form.add(new TextField("diagnosis", new PropertyModel(
            RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation")));

    form.add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager)));
    form.add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager)));
    form.add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager),
            RadarApplication.DATE_PATTERN));

    // Add inputs
    form.add(new RadarRequiredDateTextField("biopsyDate", form, componentsToUpdate));

    RadioGroup<KidneyTransplantedNative> kideneyTransplant = new RadioGroup<KidneyTransplantedNative>(
            "KidneyTransplantedNative");

    kideneyTransplant.add(new Radio<KidneyTransplantedNative>("native",
            new Model<KidneyTransplantedNative>(KidneyTransplantedNative.NATIVE)));
    kideneyTransplant.add(new Radio<KidneyTransplantedNative>("txKidney",
            new Model<KidneyTransplantedNative>(KidneyTransplantedNative.TRANSPLANTED)));

    form.add(kideneyTransplant);

    RadioGroup<Pathology.Side> side = new RadioGroup<Pathology.Side>("side");
    side.add(new Radio<Pathology.Side>("left", new Model<Pathology.Side>(Pathology.Side.LEFT)));
    side.add(new Radio<Pathology.Side>("right", new Model<Pathology.Side>(Pathology.Side.RIGHT)));
    form.add(side);

    form.add(new TextField("sampleLabNumber"));
    form.add(new TextArea("interstitalInflmatoryInfilitrate"));
    form.add(new TextArea("arterialAbnormalities"));
    form.add(new TextArea("immunohistologicalFindings"));
    form.add(new TextArea("electronMicroscopicFindings"));

    form.add(new RadarTextFieldWithValidation("estimatedTubules", new RangeValidator<Double>(0.0, 100.0), form,
            componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("measuredTubules", new RangeValidator<Double>(0.0, 100.0), form,
            componentsToUpdate));
    form.add(new TextArea("tubulesOtherFeature"));

    form.add(new TextField("imageUrl1"));
    form.add(new TextField("imageUrl2"));
    form.add(new TextField("imageUrl3"));
    form.add(new TextField("imageUrl4"));
    form.add(new TextField("imageUrl5"));

    form.add(new RadarTextFieldWithValidation("totalNumber", new RangeValidator<Integer>(0, 150), form,
            componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberSclerosed", new RangeValidator<Integer>(0, 150), form,
            componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberSegmentallySclerosed", new RangeValidator<Integer>(0, 150),
            form, componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberCellularCrescents", new RangeValidator<Integer>(0, 150),
            form, componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberFibrousCrescents", new RangeValidator<Integer>(0, 150),
            form, componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberEndocapillaryHypercelluarity",
            new RangeValidator<Integer>(0, 150), form, componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("numberFibrinoidNecrosis", new RangeValidator<Integer>(0, 150),
            form, componentsToUpdate));

    form.add(new TextArea("otherFeature"));

    form.add(new TextArea("histologicalSummary"));

    form.add(new PathologySubmitLink("save", form) {
        @Override
        protected List<Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    });

    form.add(new PathologySubmitLink("saveDown", form) {
        @Override
        protected List<Component> getComponentsToUpdate() {
            return componentsToUpdate;
        }
    });
}