Example usage for com.google.gwt.user.client Window getClientWidth

List of usage examples for com.google.gwt.user.client Window getClientWidth

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window getClientWidth.

Prototype

public static int getClientWidth() 

Source Link

Usage

From source file:org.ednovo.gooru.client.mvp.folder.toc.FolderTocView.java

License:Open Source License

/**
 * This method will give the margin value based on the window width and it will set to the main div (For Responsive UI)
 * @return//from   w  ww.j  a  va  2 s  .  c  o m
 */
public int getTotalViewableWidth() {
    int totalClientWidth = Window.getClientWidth();
    int getMargin = 0;
    if (totalClientWidth > 767) {
        getMargin = 35;
    } else {
        getMargin = 10;
    }
    return getMargin;
}

From source file:org.ednovo.gooru.client.mvp.play.collection.end.study.CollectionHomeMetadataView.java

License:Open Source License

/**
 * /*from  w ww  .  j a  va2 s  . c  om*/
 * @function oncustomizeCollectionBtnClicked 
 * 
 * @created_date : 11-Dec-2013
 * 
 * @description
 * 
 * 
 * @parm(s) : @param clickEvent
 * 
 * @return : void
 *
 * @throws : <Mentioned if any exceptions>
 *
 */
@UiHandler("shareCollectionBtn")
public void onshareCollectionBtnClicked(ClickEvent clickEvent) {
    final Map<String, String> params = StringUtil.splitQuery(Window.Location.getHref());
    String collectionId = collectionDo.getGooruOid();
    //   Window.enableScrolling(false);
    //final Map<String,String> params = new HashMap<String,String>();
    AssignPopupVc successPopupVc = new AssignPopupVc(collectionId, collectionDo.getTitle(),
            collectionDo.getGoals()) {
        @Override
        public void closePoup() {
            Window.enableScrolling(true);
            this.hide();
            params.remove("assign");
            PlaceRequest placeRequest = AppClientFactory.getPlaceManager()
                    .preparePlaceRequest(AppClientFactory.getCurrentPlaceToken(), params);
            AppClientFactory.getPlaceManager().revealPlace(false, placeRequest, true);
        }
    };
    //Window.scrollTo(0, 0);
    int clientHeight = Window.getClientHeight();
    //successPopupVc.setWidth("500px");
    //successPopupVc.setHeight("658px");
    /*if(clientHeight>625){
       clientHeight=625;
       successPopupVc.getAssignContainer().getElement().setAttribute("style", "max-height:"+clientHeight+"px;width:500px;overflow-x:hidden;overflow-y:scroll");
    }else{
       successPopupVc.getAssignContainer().getElement().setAttribute("style", "max-height:"+clientHeight+"px;width:500px;overflow-x:hidden;overflow-y:scroll");
    }*/
    successPopupVc.show();
    int left = (Window.getClientWidth() - 500) >> 1;
    int top = (Window.getClientHeight() - clientHeight) >> 1;
    successPopupVc.setHeight("658px");
    successPopupVc.setPopupPosition(Math.max(Window.getScrollLeft() + left, 0),
            Math.max(Window.getScrollTop() + 5, 0));

    //successPopupVc.center();
    //successPopupVc.setPopupPosition(successPopupVc.getAbsoluteLeft(), 10);

    //            if(!successPopupVc.isVisible()){
    //               successPopupVc.show();
    //               successPopupVc.center();
    //            }
    //            Window.enableScrolling(false);
    //            if (AppClientFactory.isAnonymous()){
    //               successPopupVc.setPopupPosition(successPopupVc.getAbsoluteLeft(), 10);
    //            }
    //            else{
    //successPopupVc.setPopupPosition(successPopupVc.getAbsoluteLeft(), 10);
    //            }
    params.put("assign", "yes");
    PlaceRequest placeRequest = AppClientFactory.getPlaceManager()
            .preparePlaceRequest(AppClientFactory.getCurrentPlaceToken(), params);
    AppClientFactory.getPlaceManager().revealPlace(false, placeRequest, true);

    //      final String collectionId = clickEvent.getRelativeElement().getAttribute("collectionId");
    //
    //            if(!isSharePopup){
    //               isSharePopup=true;
    //
    //            SharePlayerVc successPopupVc = new SharePlayerVc(collectionId) {
    //
    //               @Override
    //               public void closePoup() {
    //                  Window.enableScrolling(true);
    //                  this.hide();   
    //                  isSharePopup = false;
    //               }
    //               public void triggerShareEvent(String shareType,boolean confirmStatus){
    //                  getUiHandlers().triggerCollectionShareDataEvent(collectionId,PlayerDataLogEvents.COLLECTION,shareType,confirmStatus);
    //               }
    //            };
    //            Window.scrollTo(0, 0);
    //            successPopupVc.setWidth("500px");
    //            successPopupVc.setHeight("350px");
    //            successPopupVc.show();
    //            successPopupVc.center();
    //         }

}

From source file:org.ednovo.gooru.client.mvp.play.collection.share.email.SummaryPageEmailShareUc.java

License:Open Source License

@UiHandler("btnSend")
public void onSendBtnClickEvent(ClickEvent event) {
    isvalid = true;//www  .java  2  s .  com
    if (fromTxt.isVisible()) {
        if (fromTxt.getText().equals("")) {
            fromValidation.setVisible(true);
            isvalid = false;
        }
        if ((fromTxt.getText() != null && !fromTxt.getText().isEmpty())
                && !fromTxt.getText().contains(AT_SYMBOL)) {

            fromValidation.setText(GL1027);
            fromValidation.setVisible(true);
            isvalid = false;
        }
    }

    if (toTxt.getText().equals("")) {
        toValidation.setVisible(true);
        isvalid = false;
    }
    if ((toTxt.getText() != null && !toTxt.getText().isEmpty()) && !toTxt.getText().contains(AT_SYMBOL)) {

        toValidation.setText(GL1027);
        toValidation.setVisible(true);
        isvalid = false;
    }
    if (isvalid) {
        final Map<String, String> parms = new HashMap<String, String>();
        parms.put("text", subTxt.getValue());
        AppClientFactory.getInjector().getResourceService().checkProfanity(parms,
                new SimpleAsyncCallback<Boolean>() {
                    @Override
                    public void onSuccess(Boolean value) {
                        isHavingBadWordsInTextbox = value;
                        if (value) {
                            SetStyleForProfanity.SetStyleForProfanityForTextBox(subTxt, mandatoryErrorLbl,
                                    value);
                        } else {
                            parms.put("text", msgTxa.getText());
                            AppClientFactory.getInjector().getResourceService().checkProfanity(parms,
                                    new SimpleAsyncCallback<Boolean>() {

                                        @Override
                                        public void onSuccess(Boolean result) {
                                            isHavingBadWordsInRichText = result;
                                            if (result) {
                                                SetStyleForProfanity.SetStyleForProfanityForRichTextArea(msgTxa,
                                                        mandatoryErrorRichTextArea, result);
                                            } else {
                                                if (!isHavingBadWordsInRichText && !isHavingBadWordsInTextbox) {
                                                    String fromEmail = "";
                                                    if (fromTxt.isVisible()) {
                                                        fromEmail = fromTxt.getText();
                                                    } else {
                                                        fromEmail = fromLbl.getText();
                                                    }
                                                    AppClientFactory.getInjector().getPlayerAppService()
                                                            .sendEmailWithPdf(toTxt.getText(), fromEmail, cfm,
                                                                    subTxt.getText(), msgTxa.getHTML(), pdfUrl,
                                                                    cpAttachmentContainer.getText(),
                                                                    new SimpleAsyncCallback<String>() {
                                                                        @Override
                                                                        public void onSuccess(String result) {
                                                                            if (result.equalsIgnoreCase(
                                                                                    "success")) {
                                                                                closeEmailpanel();
                                                                                ThankYouToolTip thankYouToolTip = new ThankYouToolTip();
                                                                                thankYouToolTip.setTitleData(
                                                                                        GL0222,
                                                                                        toTxt.getText());
                                                                                thankYouToolTip
                                                                                        .setPopupPosition(
                                                                                                (Window.getClientWidth()
                                                                                                        - 400)
                                                                                                        / 2,
                                                                                                (Window.getClientHeight()
                                                                                                        - 165)
                                                                                                        / 2
                                                                                                        + Window.getScrollTop());
                                                                                thankYouToolTip.show();
                                                                            }
                                                                        }
                                                                    });
                                                }
                                            }
                                        }
                                    });
                        }
                    }
                });
    }
    /*if (isvalid  && !isHavingBadWordsInRichText && !isHavingBadWordsInTextbox) {
       String fromEmail = "";
       if(fromTxt.isVisible()) {
    fromEmail = fromTxt.getText();
       } else {
    fromEmail = fromLbl.getText();
       }
               
       AppClientFactory.getInjector().getPlayerAppService().sendEmailWithPdf(toTxt.getText(),fromEmail,cfm,subTxt.getText(), msgTxa.getHTML(), pdfUrl,cpAttachmentContainer.getText(),new SimpleAsyncCallback<String>(){
            
    @Override
    public void onSuccess(String result) {
            
       if(result.equalsIgnoreCase("success")) {
            
          closeEmailpanel();
            
          ThankYouToolTip thankYouToolTip=new ThankYouToolTip();
            
          thankYouToolTip.setTitleData("Email to Friend", toTxt.getText());
            
          thankYouToolTip.setPopupPosition((Window.getClientWidth()-400)/2,(Window.getClientHeight()-165)/2+Window.getScrollTop());
            
          thankYouToolTip.show();   
            
       }
            
    }
            
            
            
       });
               
    //         playerRpcService.sendEmailWithPdf(restEndPoint, session, toTxt.getText(), fromEmail, cfm, subTxt.getText(), msgTxa.getHTML(), pdfUrl, cpAttachmentContainer.getText(), new AsyncCallback<String>() {
    //            @Override
    //            public void onSuccess(String response) {
    //               if(response.equalsIgnoreCase("success")) {
    //                  closeEmailpanel();
    //                  ThankYouToolTip thankYouToolTip=new ThankYouToolTip();
    //                  thankYouToolTip.setTitleData("Email to Friend", toTxt.getText());
    //                  thankYouToolTip.setPopupPosition((Window.getClientWidth()-400)/2,(Window.getClientHeight()-165)/2+Window.getScrollTop());
    //                  thankYouToolTip.show();                  
    //               }
    //            }
    //            @Override
    //            public void onFailure(Throwable arg0) {
    //            }
    //         });
    }*/
}

From source file:org.ednovo.gooru.client.mvp.shelf.collection.CollectionShareAlertPopup.java

License:Open Source License

public void showPopup() {
    this.setGlassEnabled(true);
    Window.enableScrolling(false);
    AppClientFactory.fireEvent(new SetHeaderZIndexEvent(99, false));
    if (isPrivateResource) {
        int top = Window.getClientHeight();
        int left = Window.getClientWidth();
        left = (left - 450) / 2;/*  w  ww  . jav a  2 s. c om*/
        top = ((top - 400) / 2) + Window.getScrollTop();
        this.setPopupPosition(left, top);
    } else {
        this.center();
    }
    this.show();

}

From source file:org.ednovo.gooru.client.mvp.shelf.ShelfPresenter.java

License:Open Source License

public void increaseGlassHeight(Element glass) {

    Style style = glass.getStyle();

    int winWidth = Window.getClientWidth();
    int winHeight = Window.getClientHeight();

    // Hide the glass while checking the document size. Otherwise it would
    // interfere with the measurement.
    style.setDisplay(Display.NONE);/*from   w ww  .  ja v  a 2 s  . co m*/
    style.setWidth(0, Unit.PX);
    style.setHeight(0, Unit.PX);

    int width = Document.get().getScrollWidth();
    int height = Document.get().getScrollHeight();

    // Set the glass size to the larger of the window's client size or the
    // document's scroll size.
    style.setWidth(Math.max(width, winWidth), Unit.PX);
    style.setHeight(Math.max(height, winHeight), Unit.PX);

    // The size is set. Show the glass again.
    style.setDisplay(Display.BLOCK);
}

From source file:org.eurekastreams.web.client.ui.common.dialog.Dialog.java

License:Apache License

/**
 * Centers the modal for fixed positioning.
 *///from  w  ww  .j  av  a  2  s. co m
public void center() {
    int offsetTop = (Window.getClientHeight() - popupPanel.getElement().getScrollHeight()) / 2;
    int offsetLeft = (Window.getClientWidth() - popupPanel.getElement().getScrollWidth()) / 2;
    popupPanel.setPopupPosition(offsetLeft, offsetTop);
}

From source file:org.fourthline.konto.client.KontoEntryPoint.java

License:Open Source License

protected void enableDemo() {
    final PopupPanel panel = new PopupPanel(true, true);
    panel.setGlassEnabled(true);/*  w ww  . ja  v  a  2s  . co m*/

    VerticalPanel msgPanel = new VerticalPanel();
    SafeHtmlBuilder msg = new SafeHtmlBuilder();
    msg.appendHtmlConstant("<p>").appendEscaped("This is a demo instance of Konto.").appendHtmlConstant("</p>");
    msg.appendHtmlConstant("<p>").appendEscaped("You can make any changes you like.")
            .appendHtmlConstant("</p>");
    msg.appendHtmlConstant("<p>").appendEscaped("This instance will reset itself every hour.")
            .appendHtmlConstant("</p>");

    msgPanel.add(new HTMLPanel(msg.toSafeHtml()));

    panel.add(msgPanel);
    panel.setWidth("250px");
    panel.setHeight("120px");
    panel.setPopupPosition(Window.getClientWidth() / 2 - 250, Window.getClientHeight() / 2 - 120);
    panel.show();
}

From source file:org.freemedsoftware.gwt.client.screen.MainScreen.java

License:Open Source License

protected void initTopHeaderNavPanel() {

    shortCutsPanel.clear();//  ww w . j a v a 2 s .  co  m

    shortCutsPanel.setStyleName(AppConstants.STYLE_HEADER_PANEL);
    // adding current page help link
    PushButton helpButton = new PushButton();
    helpButton.setTitle(_("help"));
    helpButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
    helpButton.getUpFace().setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/help.16x16.png"));
    helpButton.getDownFace().setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/help.16x16.png"));
    helpButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (Util.getProgramMode() == ProgramMode.STUBBED) {
                Window.alert("Running in stubbed mode");
            } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
                CustomIFrame customIFrame = new CustomIFrame(Util.getHelpRequest(),
                        (int) (Window.getClientWidth() * .60), (int) (Window.getClientHeight() * .60));
                shortCutsPanel.add(customIFrame);
                customIFrame.show();
                customIFrame.center();
            }
        }
    });
    Util.attachHelp(helpButton, _("Help Icon"), _("Help for the currently selected tab."), true);
    shortCutsPanel.add(helpButton);

    HTML separator = null;
    if (CurrentState.isMenuAllowed(AppConstants.SYSTEM_CATEGORY, AppConstants.SCHEDULER)) {
        // Adding spacer
        separator = new HTML("|");
        separator.setWidth("8px");
        separator.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        shortCutsPanel.add(separator);

        // adding scheduler link
        PushButton schedulerButton = new PushButton();
        schedulerButton.setTitle(_("scheduler"));
        schedulerButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
        schedulerButton.getUpFace()
                .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/scheduler.16x16.png"));
        schedulerButton.getDownFace()
                .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/scheduler.16x16.png"));
        schedulerButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                Util.spawnTab(AppConstants.SCHEDULER, SchedulerScreen.getInstance());
            }
        });
        Util.attachHelp(schedulerButton, _("Scheduler"), _("View and book appointments."), true);
        shortCutsPanel.add(schedulerButton);
    }

    if (CurrentState.isMenuAllowed(AppConstants.PATIENT_CATEGORY, AppConstants.SEARCH)) {
        // Adding spacer
        separator = new HTML("|");
        separator.setWidth("8px");
        separator.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        shortCutsPanel.add(separator);

        // adding Patient Search Link
        PushButton ptSearchButton = new PushButton();
        ptSearchButton.setTitle(_("search patient"));
        ptSearchButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
        ptSearchButton.getUpFace()
                .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/patient_icon.16x16.png"));
        ptSearchButton.getDownFace()
                .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/patient_icon.16x16.png"));
        ptSearchButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                Util.spawnTab(AppConstants.SEARCH, PatientSearchScreen.getInstance());
            }
        });
        Util.attachHelp(ptSearchButton, _("Patient Search"), _("Search for patients."), true);
        shortCutsPanel.add(ptSearchButton);
    }
    // Adding spacer
    separator = new HTML("|");
    separator.setWidth("8px");
    separator.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    shortCutsPanel.add(separator);
    // Adding preferences link
    PushButton preferencesButton = new PushButton();
    preferencesButton.setTitle(_("preferences"));
    preferencesButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
    preferencesButton.getUpFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/preferences.16x16.png"));
    preferencesButton.getDownFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/preferences.16x16.png"));
    preferencesButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // logout event when clicked on logout link
            // if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // Window.alert("Running in stubbed mode");
            // } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            final PreferencesScreen preferencesScreen = PreferencesScreen.getInstance();
            Util.spawnTab(_("Preferences"), preferencesScreen);
            // }
        }
    });
    Util.attachHelp(preferencesButton, _("Preferences"), _("Set your user prefereneces."), true);
    shortCutsPanel.add(preferencesButton);
    separator = new HTML("|");
    separator.setWidth("8px");
    separator.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    shortCutsPanel.add(separator);

    // Adding support link
    PushButton supportButton = new PushButton();
    supportButton.setTitle(_("support"));
    supportButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
    supportButton.getUpFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/support.16x16.png"));
    supportButton.getDownFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/support.16x16.png"));
    supportButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            InfoDialog d = new InfoDialog();
            d.setCaption("Support");
            d.setContent(new HTML(
                    "Commercial support is available for <b>FreeMED</b> through the Foundation's commercial support partners."
                            + "<br/><br/>"
                            + "More information is available at <a href=\"http://freemedsoftware.org/commercial_support\" target=\"_new\">http://freemedsoftware.org/commercial_support</a>."
                            + "<br/><br/>" + "<hr/>" + "<br/></br>"
                            + "Community support is available on the FreeMED group at "
                            + "<a href=\"http://groups.google.com/group/freemed-support?hl=en\">http://groups.google.com/group/freemed-support?hl=en</a>."));
            d.center();
        }
    });
    Util.attachHelp(supportButton, _("Support"), _("More information about support."), true);
    shortCutsPanel.add(supportButton);
    // Adding logout link
    separator = new HTML("|");
    separator.setWidth("8px");
    separator.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    shortCutsPanel.add(separator);

    // Adding logout link
    PushButton logoutButton = new PushButton();
    logoutButton.setTitle(_("logout"));
    logoutButton.setStyleName(AppConstants.STYLE_BUTTON_SIMPLE);
    logoutButton.getUpFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/logout.16x16.png"));
    logoutButton.getDownFace()
            .setImage(new Image(GWT.getHostPageBaseURL() + "resources/images/logout.16x16.png"));
    logoutButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // logout event when clicked on logout link
            if (Util.getProgramMode() == ProgramMode.STUBBED) {
                Window.alert("Running in stubbed mode");
            } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
                // dashboard.saveArrangement();
                Util.logout(new Command() {
                    @Override
                    public void execute() {
                        // TODO Auto-generated method stub
                        notifications.stop();
                    }
                });
            }
        }
    });
    Util.attachHelp(logoutButton, _("Logout"), _("Logout of FreeMED."), true);
    shortCutsPanel.add(logoutButton);
}

From source file:org.freemedsoftware.gwt.client.widget.BlockScreenWidget.java

License:Open Source License

public BlockScreenWidget(String msg) {
    this.setWidth("100%");
    String blockDivOuterStr = "<div style=\"border: medium none ; margin: 0pt; padding: 0pt;";
    blockDivOuterStr += " z-index: 1000; width: " + Window.getClientWidth() + "; height: "
            + Window.getClientHeight() + "; top: 0pt; left: 0pt;";
    blockDivOuterStr += " background-color: rgb(0, 0, 0); filter: alpha(opacity = 60);opacity: 0.6; cursor: wait;";
    blockDivOuterStr += "  position: absolute;\" class=\"blockUI blockOverlay\" title=\"Please wait...\"";
    blockDivOuterStr += "/>";
    blockOuterDiv = new HTML(blockDivOuterStr);
    setText(msg);/*from ww  w.j a v a 2  s  . c o  m*/
    this.add(blockOuterDiv);
}

From source file:org.freemedsoftware.gwt.client.widget.EncounterWidget.java

License:Open Source License

@SuppressWarnings("unchecked")
private void createExamTab() {
    examPanel.setSpacing(10);/* w w  w.  ja v  a  2 s.  c  om*/
    FlexTable examTable = new FlexTable();
    boolean isBillables = false;
    final String textWidth = "" + (int) (Window.getClientWidth() / 3);
    final String radWidth = "" + (int) (Window.getClientWidth() / 6);
    final String labelWidth = "" + (int) (Window.getClientWidth() / 5);
    int find_maxbillables = 0;
    try {
        find_maxbillables = Integer.parseInt(CurrentState.getSystemConfig("max_billable"));
    } catch (Exception ex) {
    }
    final int maxbillables = find_maxbillables;
    HashMap<String, HashMap<String, String>> billMap = null;
    if (templateValuesMap.get("pnotestbillable") != null
            && !templateValuesMap.get("pnotestbillable").equals("")) {
        isBillables = true;
        billMap = (HashMap<String, HashMap<String, String>>) JsonUtil.shoehornJson(
                JSONParser.parseStrict(templateValuesMap.get("pnotestbillable")),
                "HashMap<String,HashMap<String,String>>");
    } else if (templateValuesMap.get("pnotesbillable") != null
            && !templateValuesMap.get("pnotesbillable").equals("")) {
        isBillables = true;
        billMap = (HashMap<String, HashMap<String, String>>) JsonUtil.shoehornJson(
                JSONParser.parseStrict(templateValuesMap.get("pnotesbillable")),
                "HashMap<String,HashMap<String,String>>");
    }
    int loopCountMax = 0;
    if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam"))
        loopCountMax = sectionsFieldMap.get("Sections#Exam").size();
    else if (sectionsFieldMap.containsKey("Sections") && !sectionsFieldMap.containsKey("Sections#Exam"))
        loopCountMax = 0;
    else
        loopCountMax = 1;
    List<String> secList = sectionsFieldMap.get("Sections#Exam");
    for (int i = 0; i < loopCountMax; i++) {
        if ((secList != null && secList.get(i).equals("Head"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            Label lbHeadExam = new Label("Head");
            lbHeadExam.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbHeadExam);
            //headfTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(rightPanel);
            examPanel.add(hp);
            hp.setCellWidth(rightPanel, "100%");
            Label lbfreeform = new Label("Free Form Entry");
            lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

            tbHeadFreeForm = new TextArea();
            tbHeadFreeForm.setWidth(textWidth);
            HorizontalPanel freeHp = new HorizontalPanel();
            freeHp.setWidth("80%");
            freeHp.setSpacing(2);
            freeHp.add(lbfreeform);
            freeHp.add(tbHeadFreeForm);
            freeHp.setCellWidth(tbHeadFreeForm, "80%");
            rightPanel.add(freeHp);
            if (templateValuesMap.containsKey("pnotespeheadfreecmnt")) {
                tbHeadFreeForm.setText(templateValuesMap.get("pnotespeheadfreecmnt"));
            } else if (templateValuesMap.containsKey("pnotestpeheadfreecmnt")) {
                tbHeadFreeForm.setText(templateValuesMap.get("pnotestpeheadfreecmnt"));
            }

            VerticalPanel billPanel = new VerticalPanel();
            billPanel.setWidth("100%");
            billPanel.setSpacing(2);
            final BillInfoWidget biw = new BillInfoWidget();
            final CheckBox cbHeadExBill = new CheckBox("Procedure");
            cbHeadExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
            billPanel.add(cbHeadExBill);
            billPanel.add(biw);
            cbHeadExBill.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent arg0) {
                    if (cbHeadExBill.getValue()) {
                        if (maxbillables == billingFieldsWidgetsMap.size()) {
                            Window.alert("Only " + maxbillables + " procedures can be created...");
                            cbHeadExBill.setValue(false);
                        } else {
                            billingFieldsWidgetsMap.put("pnotespehead", biw);
                            biw.setVisible(true);
                        }
                    } else {
                        billingFieldsWidgetsMap.remove("pnotespehead");
                        biw.setVisible(false);
                    }
                }
            });
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespehead")) {
                    HashMap<String, String> m = billMap.get("pnotespehead");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespehead", biw);
                    cbHeadExBill.setValue(true);

                }
            }
        }
        if ((secList != null && secList.get(i).equals("Eyes"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {

            int eyeRowCount = 0;
            Label lbEyes = new Label("Eyes");
            lbEyes.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbEyes);
            final FlexTable eyeTable = new FlexTable();
            eyeTable.getElement().getStyle().setMarginLeft(30, Unit.PX);

            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(eyeTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int eyesLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Eyes"))
                eyesLoopCountMax = sectionsFieldMap.get("Sections#Exam#Eyes").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Eyes"))
                eyesLoopCountMax = 0;
            else
                eyesLoopCountMax = 1;
            List<String> eyesSecList = sectionsFieldMap.get("Sections#Exam#Eyes");
            for (int j = 0; j < eyesLoopCountMax; j++) {

                if ((eyesSecList != null && eyesSecList.get(j).equals("Conjunctivae_lids_pupils & irises"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbCLPI = new CheckBox("Conjunctivae, lids, pupils & irises");
                    cbCLPI.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radClpi = new CustomRadioButtonGroup("clpi");

                    tbClpi = new TextArea();
                    tbClpi.setEnabled(false);
                    tbClpi.setVisible(false);
                    tbClpi.setWidth(textWidth);
                    radClpi.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbClpi.setVisible(false);
                            cbCLPI.setValue(true, true);
                        }
                    });
                    radClpi.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbClpi.setVisible(true);
                            cbCLPI.setValue(true, true);
                        }
                    });
                    radClpi.setEnable(false);
                    cbCLPI.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbCLPI.getValue()) {
                                radClpi.setEnable(true);
                                tbClpi.setEnabled(true);
                            } else {
                                radClpi.setEnable(false);
                                tbClpi.setEnabled(false);
                            }
                        }

                    });
                    eyeTable.setWidget(eyeRowCount, 0, cbCLPI);
                    eyeTable.setWidget(eyeRowCount, 1, radClpi);
                    eyeTable.setWidget(eyeRowCount + 1, 0, tbClpi);
                    eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                    eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                    eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);

                    eyeRowCount = eyeRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeeyeclpistatus")) {
                        radClpi.setWidgetValue(templateValuesMap.get("pnotespeeyeclpistatus"), true);
                        tbClpi.setText(templateValuesMap.get("pnotespeeyeclpicmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeeyeclpistatus")) {
                        radClpi.setWidgetValue(templateValuesMap.get("pnotestpeeyeclpistatus"), true);
                        tbClpi.setText(templateValuesMap.get("pnotestpeeyeclpicmnt"));
                    }
                }

                if ((eyesSecList != null && eyesSecList.get(j).equals("Fundi"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    Label lbFundi = new Label("Fundi:");
                    lbFundi.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    eyeTable.setWidget(eyeRowCount, 0, lbFundi);
                    eyeRowCount++;

                    int fundiLoopCountMax = 0;
                    if (sectionsFieldMap.containsKey("Sections")
                            && sectionsFieldMap.containsKey("Sections#Exam#Eyes#Fundi"))
                        fundiLoopCountMax = sectionsFieldMap.get("Sections#Exam#Eyes#Fundi").size();
                    else if (sectionsFieldMap.containsKey("Sections")
                            && !sectionsFieldMap.containsKey("Sections#Exam#Eyes#Fundi"))
                        fundiLoopCountMax = 0;
                    else
                        fundiLoopCountMax = 1;
                    List<String> fundiSecList = sectionsFieldMap.get("Sections#Exam#Eyes#Fundi");
                    for (int k = 0; k < fundiLoopCountMax; k++) {

                        if ((fundiSecList != null && fundiSecList.get(k).equals("Disc edges sharp"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbDiscEdgeSharp = new CheckBox("Disc edges sharp");
                            cbDiscEdgeSharp.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbDiscEdgeSharp.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radDiscEdgeSharp = new CustomRadioButtonGroup("des");
                            tbDiscEdgeSharp = new TextArea();
                            tbDiscEdgeSharp.setWidth(textWidth);
                            tbDiscEdgeSharp.setVisible(false);
                            radDiscEdgeSharp.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbDiscEdgeSharp.setVisible(false);
                                    cbDiscEdgeSharp.setValue(true, true);

                                }
                            });
                            radDiscEdgeSharp.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbDiscEdgeSharp.setVisible(true);
                                    cbDiscEdgeSharp.setValue(true, true);
                                }
                            });
                            radDiscEdgeSharp.setEnable(false);
                            tbDiscEdgeSharp.setEnabled(false);
                            cbDiscEdgeSharp.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbDiscEdgeSharp.getValue()) {
                                        radDiscEdgeSharp.setEnable(true);
                                        tbDiscEdgeSharp.setEnabled(true);
                                    } else {
                                        radDiscEdgeSharp.setEnable(false);
                                        tbDiscEdgeSharp.setEnabled(false);
                                    }
                                }

                            });
                            eyeTable.setWidget(eyeRowCount, 0, cbDiscEdgeSharp);
                            eyeTable.setWidget(eyeRowCount, 1, radDiscEdgeSharp);
                            eyeTable.setWidget(eyeRowCount + 1, 0, tbDiscEdgeSharp);
                            eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);
                            eyeRowCount = eyeRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespeeyedesstatus")) {
                                radDiscEdgeSharp.setWidgetValue(templateValuesMap.get("pnotespeeyedesstatus"),
                                        true);
                                tbDiscEdgeSharp.setText(templateValuesMap.get("pnotespeeyedescmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpeeyedesstatus")) {
                                radDiscEdgeSharp.setWidgetValue(templateValuesMap.get("pnotestpeeyedesstatus"),
                                        true);
                                tbDiscEdgeSharp.setText(templateValuesMap.get("pnotestpeeyedescmnt"));
                            }
                        }
                        if ((fundiSecList != null && fundiSecList.get(k).equals("Venous pulses seen"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbVenPul = new CheckBox("Venous pulses seen");
                            cbVenPul.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbVenPul.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radVenPul = new CustomRadioButtonGroup("vps");
                            tbVenPul = new TextArea();
                            tbVenPul.setWidth(textWidth);
                            tbVenPul.setVisible(false);
                            radVenPul.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbVenPul.setVisible(false);
                                    cbVenPul.setValue(true, true);
                                }
                            });
                            radVenPul.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbVenPul.setVisible(true);
                                    cbVenPul.setValue(true, true);
                                }
                            });
                            radVenPul.setEnable(false);
                            tbVenPul.setEnabled(false);
                            cbVenPul.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbVenPul.getValue()) {
                                        radVenPul.setEnable(true);
                                        tbVenPul.setEnabled(true);
                                    } else {
                                        radVenPul.setEnable(false);
                                        tbVenPul.setEnabled(false);
                                    }
                                }

                            });
                            eyeTable.setWidget(eyeRowCount, 0, cbVenPul);
                            eyeTable.setWidget(eyeRowCount, 1, radVenPul);
                            eyeTable.setWidget(eyeRowCount + 1, 0, tbVenPul);
                            eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);
                            eyeRowCount = eyeRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespeeyevpsstatus")) {
                                radVenPul.setWidgetValue(templateValuesMap.get("pnotespeeyevpsstatus"), true);
                                tbVenPul.setText(templateValuesMap.get("pnotespeeyevpscmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpeeyevpsstatus")) {
                                radVenPul.setWidgetValue(templateValuesMap.get("pnotestpeeyevpsstatus"), true);
                                tbVenPul.setText(templateValuesMap.get("pnotestpeeyevpscmnt"));
                            }
                        }

                        if ((fundiSecList != null && fundiSecList.get(k).equals("A-V nicking"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbAVNicking = new CheckBox("A-V nicking");
                            cbAVNicking.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbAVNicking.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radAVNicking = new CustomRadioButtonGroup("avn");
                            tbAVNicking = new TextArea();
                            tbAVNicking.setVisible(false);
                            tbAVNicking.setWidth(textWidth);
                            radAVNicking.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbAVNicking.setVisible(false);
                                    cbAVNicking.setValue(true, true);
                                }
                            });
                            radAVNicking.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbAVNicking.setVisible(true);
                                    cbAVNicking.setValue(true, true);
                                }
                            });
                            radAVNicking.setEnable(false);
                            tbAVNicking.setEnabled(false);
                            cbAVNicking.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbAVNicking.getValue()) {
                                        radAVNicking.setEnable(true);
                                        tbAVNicking.setEnabled(true);
                                    } else {
                                        radAVNicking.setEnable(false);
                                        tbAVNicking.setEnabled(false);
                                    }
                                }

                            });
                            eyeTable.setWidget(eyeRowCount, 0, cbAVNicking);
                            eyeTable.setWidget(eyeRowCount, 1, radAVNicking);
                            eyeTable.setWidget(eyeRowCount + 1, 0, tbAVNicking);
                            eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);
                            eyeRowCount = eyeRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespeeyeavnstatus")) {
                                radAVNicking.setWidgetValue(templateValuesMap.get("pnotespeeyeavnstatus"),
                                        true);
                                tbAVNicking.setText(templateValuesMap.get("pnotespeeyeavncmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpeeyeavnstatus")) {
                                radAVNicking.setWidgetValue(templateValuesMap.get("pnotestpeeyeavnstatus"),
                                        true);
                                tbAVNicking.setText(templateValuesMap.get("pnotestpeeyeavncmnt"));
                            }
                        }

                        if ((fundiSecList != null && fundiSecList.get(k).equals("Hemorrhages"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbHemorrhages = new CheckBox("Hemorrhages");
                            cbHemorrhages.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbHemorrhages.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radHemorrhages = new CustomRadioButtonGroup("hom");
                            tbHemorrhages = new TextArea();
                            tbHemorrhages.setVisible(false);
                            tbHemorrhages.setWidth(textWidth);
                            radHemorrhages.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbHemorrhages.setVisible(false);
                                    cbHemorrhages.setValue(true, true);
                                }
                            });
                            radHemorrhages.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbHemorrhages.setVisible(true);
                                    cbHemorrhages.setValue(true, true);
                                }
                            });
                            radHemorrhages.setEnable(false);
                            tbHemorrhages.setEnabled(false);
                            cbHemorrhages.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbHemorrhages.getValue()) {
                                        radHemorrhages.setEnable(true);
                                        tbHemorrhages.setEnabled(true);
                                    } else {
                                        radHemorrhages.setEnable(false);
                                        tbHemorrhages.setEnabled(false);
                                    }
                                }

                            });
                            eyeTable.setWidget(eyeRowCount, 0, cbHemorrhages);
                            eyeTable.setWidget(eyeRowCount, 1, radHemorrhages);
                            eyeTable.setWidget(eyeRowCount + 1, 0, tbHemorrhages);
                            eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);
                            eyeRowCount = eyeRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespeeyehemstatus")) {
                                radHemorrhages.setWidgetValue(templateValuesMap.get("pnotespeeyehemstatus"),
                                        true);
                                tbHemorrhages.setText(templateValuesMap.get("pnotespeeyehemcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpeeyehemstatus")) {
                                radHemorrhages.setWidgetValue(templateValuesMap.get("pnotestpeeyehemstatus"),
                                        true);
                                tbHemorrhages.setText(templateValuesMap.get("pnotestpeeyehemcmnt"));
                            }
                        }

                        if ((fundiSecList != null && fundiSecList.get(k).equals("Exudates"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbExudates = new CheckBox("Exudates");
                            cbExudates.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbExudates.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radExudates = new CustomRadioButtonGroup("exu");
                            tbExudates = new TextArea();
                            tbExudates.setVisible(false);
                            tbExudates.setWidth(textWidth);
                            radExudates.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbExudates.setVisible(false);
                                    cbExudates.setValue(true, true);
                                }
                            });
                            radExudates.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbExudates.setVisible(true);
                                    cbExudates.setValue(true, true);
                                }
                            });
                            radExudates.setEnable(false);
                            tbExudates.setEnabled(false);
                            cbExudates.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbExudates.getValue()) {
                                        radExudates.setEnable(true);
                                        tbExudates.setEnabled(true);
                                    } else {
                                        radExudates.setEnable(false);
                                        tbExudates.setEnabled(false);
                                    }
                                }

                            });
                            eyeTable.setWidget(eyeRowCount, 0, cbExudates);
                            eyeTable.setWidget(eyeRowCount, 1, radExudates);
                            eyeTable.setWidget(eyeRowCount + 1, 0, tbExudates);
                            eyeTable.getFlexCellFormatter().setColSpan(eyeRowCount + 1, 0, 2);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 0, labelWidth);
                            eyeTable.getFlexCellFormatter().setWidth(eyeRowCount, 1, radWidth);
                            eyeRowCount = eyeRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespeeyeexustatus")) {
                                radExudates.setWidgetValue(templateValuesMap.get("pnotespeeyeexustatus"), true);
                                tbExudates.setText(templateValuesMap.get("pnotespeeyeexucmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpeeyeexustatus")) {
                                radExudates.setWidgetValue(templateValuesMap.get("pnotestpeeyeexustatus"),
                                        true);
                                tbExudates.setText(templateValuesMap.get("pnotestpeeyeexucmnt"));
                            }
                        }
                    }
                }

                if ((eyesSecList != null && eyesSecList.get(j).equals("Cup:disc ratio"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbCupDiscRatio = new CheckBox("Cup:disc ratio");
                    cbCupDiscRatio.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    tbCupDiscRatio = new TextBox();
                    eyeTable.setWidget(eyeRowCount, 0, cbCupDiscRatio);
                    eyeTable.setWidget(eyeRowCount, 1, tbCupDiscRatio);
                    eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    eyeTable.getFlexCellFormatter().setVerticalAlignment(eyeRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    eyeRowCount++;
                    tbCupDiscRatio.setEnabled(false);
                    cbCupDiscRatio.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbCupDiscRatio.getValue()) {
                                tbCupDiscRatio.setEnabled(true);
                            } else {
                                tbCupDiscRatio.setEnabled(false);
                            }
                        }

                    });
                    if (templateValuesMap.containsKey("pnotespeeyecupdiscratio")) {
                        tbCupDiscRatio.setText(templateValuesMap.get("pnotespeeyecupdiscratio"));
                        cbCupDiscRatio.setValue(true, true);
                    } else if (templateValuesMap.containsKey("pnotestpeeyecupdiscratio")) {
                        tbCupDiscRatio.setText(templateValuesMap.get("pnotestpeeyecupdiscratio"));
                        cbCupDiscRatio.setValue(true, true);
                    }
                }
                if ((eyesSecList != null && eyesSecList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (eyesSecList != null && eyesSecList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbEyeFreeForm = new TextArea();
                    tbEyeFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbEyeFreeForm);
                    freeHp.setCellWidth(tbEyeFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespeeyefreecmnt")) {
                        tbEyeFreeForm.setText(templateValuesMap.get("pnotespeeyefreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeeyefreecmnt")) {
                        tbEyeFreeForm.setText(templateValuesMap.get("pnotestpeeyefreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setWidth("100%");
                billPanel.setSpacing(2);
                rightPanel.add(billPanel);
                cbEyesExBill = new CheckBox("Procedure");
                cbEyesExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                // examTable.setWidget(row, 2, cbEyesExBill);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbEyesExBill);
                billPanel.add(biw);
                // examPanel.add(billPanel);
                // examTable.setWidget(row, 6, biw);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespeeyes")) {
                    HashMap<String, String> m = billMap.get("pnotespeeyes");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespeeyes", biw);
                    cbEyesExBill.setValue(true);
                }

                cbEyesExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbEyesExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbEyesExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespeeyes", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespeeyes");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("ENT"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int entRowCount = 0;
            Label lbEnt = new Label("ENT");
            lbEnt.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbEnt);
            final FlexTable entTable = new FlexTable();
            entTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(entTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int entLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#ENT"))
                entLoopCountMax = sectionsFieldMap.get("Sections#Exam#ENT").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#ENT"))
                entLoopCountMax = 0;
            else
                entLoopCountMax = 1;
            List<String> entSecList = sectionsFieldMap.get("Sections#Exam#ENT");
            for (int j = 0; j < entLoopCountMax; j++) {
                if ((entSecList != null && entSecList.get(j).equals("External canals_TMs"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbExtCanTms = new CheckBox("External canals, TMs");
                    cbExtCanTms.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radExtCanTms = new CustomRadioButtonGroup("et");
                    tbExtCanTms = new TextArea();
                    tbExtCanTms.setVisible(false);
                    tbExtCanTms.setWidth(textWidth);
                    radExtCanTms.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbExtCanTms.setVisible(false);
                            cbExtCanTms.setValue(true, true);
                        }
                    });
                    radExtCanTms.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbExtCanTms.setVisible(true);
                            cbExtCanTms.setValue(true, true);

                        }
                    });
                    radExtCanTms.setEnable(false);
                    tbExtCanTms.setEnabled(false);
                    cbExtCanTms.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbExtCanTms.getValue()) {
                                radExtCanTms.setEnable(true);
                                tbExtCanTms.setEnabled(true);
                            } else {
                                radExtCanTms.setEnable(false);
                                tbExtCanTms.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbExtCanTms);
                    entTable.setWidget(entRowCount, 1, radExtCanTms);
                    entTable.setWidget(entRowCount + 1, 0, tbExtCanTms);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeentectstatus")) {
                        radExtCanTms.setWidgetValue(templateValuesMap.get("pnotespeentectstatus"), true);
                        tbExtCanTms.setText(templateValuesMap.get("pnotespeentectcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentectstatus")) {
                        radExtCanTms.setWidgetValue(templateValuesMap.get("pnotestpeentectstatus"), true);
                        tbExtCanTms.setText(templateValuesMap.get("pnotestpeentectcmnt"));
                    }
                }

                if ((entSecList != null && entSecList.get(j).equals("Nasal mucosa_septum"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbNMS = new CheckBox("Nasal mucosa, septum");
                    cbNMS.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radNMS = new CustomRadioButtonGroup("nms");
                    tbNMS = new TextArea();
                    tbNMS.setVisible(false);
                    tbNMS.setWidth(textWidth);
                    radNMS.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbNMS.setVisible(false);
                            cbNMS.setValue(true, true);
                        }
                    });
                    radNMS.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbNMS.setVisible(true);
                            cbNMS.setValue(true, true);
                        }
                    });
                    radNMS.setEnable(false);
                    tbNMS.setEnabled(false);
                    cbNMS.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbNMS.getValue()) {
                                radNMS.setEnable(true);
                                tbNMS.setEnabled(true);
                            } else {
                                radNMS.setEnable(false);
                                tbNMS.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbNMS);
                    entTable.setWidget(entRowCount, 1, radNMS);
                    entTable.setWidget(entRowCount + 1, 0, tbNMS);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeentnmsstatus")) {
                        radNMS.setWidgetValue(templateValuesMap.get("pnotespeentnmsstatus"), true);
                        tbNMS.setText(templateValuesMap.get("pnotespeentnmscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentnmsstatus")) {
                        radNMS.setWidgetValue(templateValuesMap.get("pnotestpeentnmsstatus"), true);
                        tbNMS.setText(templateValuesMap.get("pnotestpeentnmscmnt"));
                    }
                }

                if ((entSecList != null && entSecList.get(j).equals("Lips_gums_teeth"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbLGT = new CheckBox("Lips, gums, teeth");
                    cbLGT.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radLGT = new CustomRadioButtonGroup("lgt");
                    tbLGT = new TextArea();
                    tbLGT.setVisible(false);
                    tbLGT.setWidth(textWidth);
                    radLGT.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbLGT.setVisible(false);
                            cbLGT.setValue(true, true);
                        }
                    });
                    radLGT.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbLGT.setVisible(true);
                            cbLGT.setValue(true, true);
                        }
                    });
                    radLGT.setEnable(false);
                    tbLGT.setEnabled(false);
                    cbLGT.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbLGT.getValue()) {
                                radLGT.setEnable(true);
                                tbLGT.setEnabled(true);
                            } else {
                                radLGT.setEnable(false);
                                tbLGT.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbLGT);
                    entTable.setWidget(entRowCount, 1, radLGT);
                    entTable.setWidget(entRowCount + 1, 0, tbLGT);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeentlgtstatus")) {
                        radLGT.setWidgetValue(templateValuesMap.get("pnotespeentlgtstatus"), true);
                        tbLGT.setText(templateValuesMap.get("pnotespeentlgtcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentlgtstatus")) {
                        radLGT.setWidgetValue(templateValuesMap.get("pnotestpeentlgtstatus"), true);
                        tbLGT.setText(templateValuesMap.get("pnotestpeentlgtcmnt"));
                    }
                }

                if ((entSecList != null && entSecList.get(j).equals("Oropharynx_mucosa_salivary glands"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbOMS = new CheckBox("Oropharynx, mucosa, salivary glands");
                    cbOMS.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radOMS = new CustomRadioButtonGroup("oms");
                    tbOMS = new TextArea();
                    tbOMS.setVisible(false);
                    tbOMS.setWidth(textWidth);
                    radOMS.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbOMS.setVisible(false);
                            cbOMS.setValue(true, true);
                        }
                    });
                    radOMS.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbOMS.setVisible(true);
                            cbOMS.setValue(true, true);
                        }
                    });
                    radOMS.setEnable(false);
                    tbOMS.setEnabled(false);
                    cbOMS.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbOMS.getValue()) {
                                radOMS.setEnable(true);
                                tbOMS.setEnabled(true);
                            } else {
                                radOMS.setEnable(false);
                                tbOMS.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbOMS);
                    entTable.setWidget(entRowCount, 1, radOMS);
                    entTable.setWidget(entRowCount + 1, 0, tbOMS);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeentomsgstatus")) {
                        radOMS.setWidgetValue(templateValuesMap.get("pnotespeentomsgstatus"), true);
                        tbOMS.setText(templateValuesMap.get("pnotespeentomsgcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentomsgstatus")) {
                        radOMS.setWidgetValue(templateValuesMap.get("pnotestpeentomsgstatus"), true);
                        tbOMS.setText(templateValuesMap.get("pnotestpeentomsgcmnt"));
                    }
                }

                if ((entSecList != null
                        && entSecList.get(j).equals("Hard/soft palate_tongue_tonsils_posterior pharynx"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbHTTP = new CheckBox("Hard/soft palate, tongue, tonsils, posterior pharynx");
                    cbHTTP.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radHTTP = new CustomRadioButtonGroup("http");
                    tbHTTP = new TextArea();
                    tbHTTP.setVisible(false);
                    tbHTTP.setWidth(textWidth);
                    radHTTP.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbHTTP.setVisible(false);
                            cbHTTP.setValue(true, true);
                        }
                    });
                    radHTTP.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbHTTP.setVisible(true);
                            cbHTTP.setValue(true, true);
                        }
                    });
                    radHTTP.setEnable(false);
                    tbHTTP.setEnabled(false);
                    cbHTTP.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbHTTP.getValue()) {
                                radHTTP.setEnable(true);
                                tbHTTP.setEnabled(true);
                            } else {
                                radHTTP.setEnable(false);
                                tbHTTP.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbHTTP);
                    entTable.setWidget(entRowCount, 1, radHTTP);
                    entTable.setWidget(entRowCount + 1, 0, tbHTTP);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeenthttpstatus")) {
                        radHTTP.setWidgetValue(templateValuesMap.get("pnotespeenthttpstatus"), true);
                        tbHTTP.setText(templateValuesMap.get("pnotespeenthttpcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeenthttpstatus")) {
                        radHTTP.setWidgetValue(templateValuesMap.get("pnotestpeenthttpstatus"), true);
                        tbHTTP.setText(templateValuesMap.get("pnotestpeenthttpcmnt"));
                    }
                }

                if ((entSecList != null && entSecList.get(j).equals("Thyroid"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbThyroid = new CheckBox("Thyroid");
                    cbThyroid.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radThyroid = new CustomRadioButtonGroup("thy");
                    tbThyroid = new TextArea();
                    tbThyroid.setVisible(false);
                    tbThyroid.setWidth(textWidth);
                    radThyroid.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbThyroid.setVisible(false);
                            cbThyroid.setValue(true, true);
                        }
                    });
                    radThyroid.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbThyroid.setVisible(true);
                            cbThyroid.setValue(true, true);
                        }
                    });
                    radThyroid.setEnable(false);
                    tbThyroid.setEnabled(false);
                    cbThyroid.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbThyroid.getValue()) {
                                radThyroid.setEnable(true);
                                tbThyroid.setEnabled(true);
                            } else {
                                radThyroid.setEnable(false);
                                tbThyroid.setEnabled(false);
                            }
                        }

                    });
                    entTable.setWidget(entRowCount, 0, cbThyroid);
                    entTable.setWidget(entRowCount, 1, radThyroid);
                    entTable.setWidget(entRowCount + 1, 0, tbThyroid);
                    entTable.getFlexCellFormatter().setColSpan(entRowCount + 1, 0, 2);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setVerticalAlignment(entRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 0, labelWidth);
                    entTable.getFlexCellFormatter().setWidth(entRowCount, 1, radWidth);
                    entRowCount = entRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeentthyrostatus")) {
                        radThyroid.setWidgetValue(templateValuesMap.get("pnotespeentthyrostatus"), true);
                        tbThyroid.setText(templateValuesMap.get("pnotespeentthyrocmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentthyrostatus")) {
                        radThyroid.setWidgetValue(templateValuesMap.get("pnotestpeentthyrostatus"), true);
                        tbThyroid.setText(templateValuesMap.get("pnotestpeentthyrocmnt"));
                    }
                }

                if ((entSecList != null && entSecList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (entSecList != null && entSecList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbEntFreeForm = new TextArea();
                    tbEntFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbEntFreeForm);
                    freeHp.setCellWidth(tbEntFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespeentfreecmnt")) {
                        tbEntFreeForm.setText(templateValuesMap.get("pnotespeentfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeentfreecmnt")) {
                        tbEntFreeForm.setText(templateValuesMap.get("pnotestpeentfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbEntExBill = new CheckBox("Procedure");
                cbEntExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                rightPanel.add(billPanel);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbEntExBill);
                billPanel.add(biw);
                // examPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespeent")) {
                    HashMap<String, String> m = billMap.get("pnotespeent");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespeent", biw);
                    cbEntExBill.setValue(true);

                }
                cbEntExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbEntExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbEntExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespeent", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespeent");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Neck"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int neckRowCount = 0;
            Label lbEntExam = new Label("Neck");
            lbEntExam.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbEntExam);
            final FlexTable neckTable = new FlexTable();
            neckTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(neckTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int neckLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Neck"))
                neckLoopCountMax = sectionsFieldMap.get("Sections#Exam#Neck").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Neck"))
                neckLoopCountMax = 0;
            else
                neckLoopCountMax = 1;
            List<String> neckSecList = sectionsFieldMap.get("Sections#Exam#Neck");
            for (int j = 0; j < neckLoopCountMax; j++) {

                if ((neckSecList != null && neckSecList.get(j).equals("Neck (note bruit_JVD)"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbNeck = new CheckBox("Neck (note bruit, JVD)");
                    cbNeck.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radNeck = new CustomRadioButtonGroup("neckexam");
                    tbNeckExam = new TextArea();
                    tbNeckExam.setVisible(false);
                    tbNeckExam.setWidth(textWidth);
                    radNeck.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbNeckExam.setVisible(false);
                            cbNeck.setValue(true, true);
                        }
                    });
                    radNeck.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbNeckExam.setVisible(true);
                            cbNeck.setValue(true, true);
                        }
                    });
                    radNeck.setEnable(false);
                    tbNeckExam.setEnabled(false);
                    cbNeck.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbNeck.getValue()) {
                                radNeck.setEnable(true);
                                tbNeckExam.setEnabled(true);
                            } else {
                                radNeck.setEnable(false);
                                tbNeckExam.setEnabled(false);
                            }
                        }

                    });
                    neckTable.setWidget(neckRowCount, 0, cbNeck);
                    neckTable.setWidget(neckRowCount, 1, radNeck);
                    neckTable.setWidget(neckRowCount + 1, 0, tbNeckExam);
                    neckTable.getFlexCellFormatter().setColSpan(neckRowCount + 1, 0, 2);
                    neckTable.getFlexCellFormatter().setVerticalAlignment(neckRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    neckTable.getFlexCellFormatter().setVerticalAlignment(neckRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    neckTable.getFlexCellFormatter().setWidth(neckRowCount, 0, labelWidth);
                    neckTable.getFlexCellFormatter().setWidth(neckRowCount, 1, radWidth);
                    neckRowCount = neckRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeneckbrjvdstatus")) {
                        radNeck.setWidgetValue(templateValuesMap.get("pnotespeneckbrjvdstatus"), true);
                        tbNeckExam.setText(templateValuesMap.get("pnotespeneckbrjvdcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneckbrjvdstatus")) {
                        radNeck.setWidgetValue(templateValuesMap.get("pnotestpeneckbrjvdstatus"), true);
                        tbNeckExam.setText(templateValuesMap.get("pnotestpeneckbrjvdcmnt"));
                    }
                }

                if ((neckSecList != null && neckSecList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (neckSecList != null && neckSecList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbNeckFreeForm = new TextArea();
                    tbNeckFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbNeckFreeForm);
                    freeHp.setCellWidth(tbNeckFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespeneckfreecmnt")) {
                        tbNeckFreeForm.setText(templateValuesMap.get("pnotespeneckfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneckfreecmnt")) {
                        tbNeckFreeForm.setText(templateValuesMap.get("pnotestpeneckfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbNeckExBill = new CheckBox("Procedure");
                cbNeckExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbNeckExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespeneck")) {
                    HashMap<String, String> m = billMap.get("pnotespeneck");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespeneck", biw);
                    cbNeckExBill.setValue(true);

                }
                cbNeckExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbNeckExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbNeckExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespeneck", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespeneck");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Breast"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int breastRowCount = 0;
            Label lbBreastExam = new Label("Breast");
            lbBreastExam.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbBreastExam);
            final FlexTable breastTable = new FlexTable();
            breastTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(breastTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int breastLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections")
                    && sectionsFieldMap.containsKey("Sections#Exam#Breast"))
                breastLoopCountMax = sectionsFieldMap.get("Sections#Exam#Breast").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Breast"))
                breastLoopCountMax = 0;
            else
                breastLoopCountMax = 1;
            List<String> breastSecList = sectionsFieldMap.get("Sections#Exam#Breast");
            for (int j = 0; j < breastLoopCountMax; j++) {

                if ((breastSecList != null
                        && breastSecList.get(j).equals("Breasts (note dimpling_discharge_mass)"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbBreast = new CheckBox("Breasts (note dimpling, discharge, mass)");
                    cbBreast.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radBreast = new CustomRadioButtonGroup("breastexam");
                    tbBreastExam = new TextArea();
                    tbBreastExam.setVisible(false);
                    tbBreastExam.setWidth(textWidth);
                    radBreast.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbBreastExam.setVisible(false);
                            cbBreast.setValue(true, true);
                        }
                    });
                    radBreast.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbBreastExam.setVisible(true);
                            cbBreast.setValue(true, true);
                        }
                    });
                    radBreast.setEnable(false);
                    tbBreastExam.setEnabled(false);
                    cbBreast.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbBreast.getValue()) {
                                radBreast.setEnable(true);
                                tbBreastExam.setEnabled(true);
                            } else {
                                radBreast.setEnable(false);
                                tbBreastExam.setEnabled(false);
                            }
                        }

                    });
                    breastTable.setWidget(breastRowCount, 0, cbBreast);
                    breastTable.setWidget(breastRowCount, 1, radBreast);
                    breastTable.setWidget(breastRowCount + 1, 0, tbBreastExam);
                    breastTable.getFlexCellFormatter().setColSpan(breastRowCount + 1, 0, 2);
                    breastTable.getFlexCellFormatter().setVerticalAlignment(breastRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    breastTable.getFlexCellFormatter().setVerticalAlignment(breastRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    breastTable.getFlexCellFormatter().setWidth(breastRowCount, 0, labelWidth);
                    breastTable.getFlexCellFormatter().setWidth(breastRowCount, 1, radWidth);
                    breastRowCount++;
                    if (templateValuesMap.containsKey("pnotespebrstddmstatus")) {
                        radBreast.setWidgetValue(templateValuesMap.get("pnotespebrstddmstatus"), true);
                        tbBreastExam.setText(templateValuesMap.get("pnotespebrstddmcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpebrstddmstatus")) {
                        radBreast.setWidgetValue(templateValuesMap.get("pnotestpebrstddmstatus"), true);
                        tbBreastExam.setText(templateValuesMap.get("pnotestpebrstddmcmnt"));
                    }
                }
                if ((breastSecList != null && breastSecList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (breastSecList != null && breastSecList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbBreastFreeForm = new TextArea();
                    tbBreastFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbBreastFreeForm);
                    freeHp.setCellWidth(tbBreastFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespebrstfreecmnt")) {
                        tbBreastFreeForm.setText(templateValuesMap.get("pnotespebrstfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpebrstfreecmnt")) {
                        tbBreastFreeForm.setText(templateValuesMap.get("pnotestpebrstfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbBreastExBill = new CheckBox("Procedure");
                cbBreastExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbBreastExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespechestbreast")) {
                    HashMap<String, String> m = billMap.get("pnotespechestbreast");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespechestbreast", biw);
                    cbBreastExBill.setValue(true);

                }
                cbBreastExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbBreastExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbBreastExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespechestbreast", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespechestbreast");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Resp"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int respRowCount = 0;
            Label lbRespExam = new Label("Resp");
            lbRespExam.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbRespExam);
            final FlexTable respTable = new FlexTable();
            respTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(respTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int respLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Resp"))
                respLoopCountMax = sectionsFieldMap.get("Sections#Exam#Resp").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Resp"))
                respLoopCountMax = 0;
            else
                respLoopCountMax = 1;
            List<String> respSecList = sectionsFieldMap.get("Sections#Exam#Resp");
            for (int j = 0; j < respLoopCountMax; j++) {

                if ((respSecList != null && respSecList.get(j).equals("Respiratory effort"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbRespEff = new CheckBox("Respiratory effort (note use of accessory muscles)");
                    cbRespEff.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radRespEff = new CustomRadioButtonGroup("respeff");
                    tbRespEff = new TextArea();
                    tbRespEff.setVisible(false);
                    tbRespEff.setWidth(textWidth);
                    radRespEff.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbRespEff.setVisible(false);
                            cbRespEff.setValue(true, true);
                        }
                    });
                    radRespEff.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbRespEff.setVisible(true);
                            cbRespEff.setValue(true, true);
                        }
                    });
                    radRespEff.setEnable(false);
                    tbRespEff.setEnabled(false);
                    cbRespEff.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbRespEff.getValue()) {
                                radRespEff.setEnable(true);
                                tbRespEff.setEnabled(true);
                            } else {
                                radRespEff.setEnable(false);
                                tbRespEff.setEnabled(false);
                            }
                        }

                    });
                    respTable.setWidget(respRowCount, 0, cbRespEff);
                    respTable.setWidget(respRowCount, 1, radRespEff);
                    respTable.setWidget(respRowCount + 1, 0, tbRespEff);
                    respTable.getFlexCellFormatter().setColSpan(respRowCount + 1, 0, 2);
                    respTable.getFlexCellFormatter().setVerticalAlignment(respRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    respTable.getFlexCellFormatter().setVerticalAlignment(respRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    respTable.getFlexCellFormatter().setWidth(respRowCount, 0, labelWidth);
                    respTable.getFlexCellFormatter().setWidth(respRowCount, 1, radWidth);
                    respRowCount = respRowCount + 2;

                    if (templateValuesMap.containsKey("pnotesperespeffstatus")) {
                        radRespEff.setWidgetValue(templateValuesMap.get("pnotesperespeffstatus"), true);
                        tbRespEff.setText(templateValuesMap.get("pnotesperespeffcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestperespeffstatus")) {
                        radRespEff.setWidgetValue(templateValuesMap.get("pnotestperespeffstatus"), true);
                        tbRespEff.setText(templateValuesMap.get("pnotestperespeffcmnt"));
                    }
                }

                if ((respSecList != null && respSecList.get(j).equals("Lung percussion & auscultation"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbLPA = new CheckBox("Lung percussion & auscultation");
                    cbLPA.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radLPA = new CustomRadioButtonGroup("lunper");
                    tbLPA = new TextArea();
                    tbLPA.setVisible(false);
                    tbLPA.setWidth(textWidth);
                    radLPA.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbLPA.setVisible(false);
                            cbLPA.setValue(true, true);
                        }
                    });
                    radLPA.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbLPA.setVisible(true);
                            cbLPA.setValue(true, true);
                        }
                    });
                    radLPA.setEnable(false);
                    tbLPA.setEnabled(false);
                    cbLPA.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbLPA.getValue()) {
                                radLPA.setEnable(true);
                                tbLPA.setEnabled(true);
                            } else {
                                radLPA.setEnable(false);
                                tbLPA.setEnabled(false);
                            }
                        }

                    });
                    respTable.setWidget(respRowCount, 0, cbLPA);
                    respTable.setWidget(respRowCount, 1, radLPA);
                    respTable.setWidget(respRowCount + 1, 0, tbLPA);
                    respTable.getFlexCellFormatter().setColSpan(respRowCount + 1, 0, 2);
                    respTable.getFlexCellFormatter().setVerticalAlignment(respRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    respTable.getFlexCellFormatter().setVerticalAlignment(respRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    respTable.getFlexCellFormatter().setWidth(respRowCount, 0, labelWidth);
                    respTable.getFlexCellFormatter().setWidth(respRowCount, 1, radWidth);
                    respRowCount = respRowCount + 2;
                    if (templateValuesMap.containsKey("pnotesperesplungstatus")) {
                        radLPA.setWidgetValue(templateValuesMap.get("pnotesperesplungstatus"), true);
                        tbLPA.setText(templateValuesMap.get("pnotesperesplungcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestperesplungstatus")) {
                        radLPA.setWidgetValue(templateValuesMap.get("pnotestperesplungstatus"), true);
                        tbLPA.setText(templateValuesMap.get("pnotestperesplungcmnt"));
                    }
                }
                if ((respSecList != null && respSecList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (respSecList != null && respSecList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbRespFreeForm = new TextArea();
                    tbRespFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbRespFreeForm);
                    freeHp.setCellWidth(tbRespFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotesperespfreecmnt")) {
                        tbRespFreeForm.setText(templateValuesMap.get("pnotesperespfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestperespfreecmnt")) {
                        tbRespFreeForm.setText(templateValuesMap.get("pnotestperespfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbRespExBill = new CheckBox("Procedure");
                cbRespExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbRespExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotesperesp")) {
                    HashMap<String, String> m = billMap.get("pnotesperesp");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotesperesp", biw);
                    cbRespExBill.setValue(true);

                }
                cbRespExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbRespExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbRespExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotesperesp", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotesperesp");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("CV"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int cvRowCount = 0;
            Label lbCV = new Label("CV");
            lbCV.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbCV);
            final FlexTable cvTable = new FlexTable();
            cvTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(cvTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int cvLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#CV"))
                cvLoopCountMax = sectionsFieldMap.get("Sections#Exam#CV").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#CV"))
                cvLoopCountMax = 0;
            else
                cvLoopCountMax = 1;
            List<String> cvList = sectionsFieldMap.get("Sections#Exam#CV");
            for (int j = 0; j < cvLoopCountMax; j++) {
                if ((cvList != null && cvList.get(j).equals("Auscultation"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    Label lbExtCanTms = new Label("Auscultation:");
                    lbExtCanTms.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    cvTable.setWidget(cvRowCount, 0, lbExtCanTms);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvRowCount++;
                    int auscultationLoopCountMax = 0;
                    if (sectionsFieldMap.containsKey("Sections")
                            && sectionsFieldMap.containsKey("Sections#Exam#CV#Auscultation"))
                        auscultationLoopCountMax = sectionsFieldMap.get("Sections#Exam#CV#Auscultation").size();
                    else if (sectionsFieldMap.containsKey("Sections")
                            && !sectionsFieldMap.containsKey("Sections#Exam#CV#Auscultation"))
                        auscultationLoopCountMax = 0;
                    else
                        auscultationLoopCountMax = 1;
                    List<String> auscultationSecList = sectionsFieldMap.get("Sections#Exam#CV#Auscultation");
                    for (int k = 0; k < auscultationLoopCountMax; k++) {

                        if ((auscultationSecList != null && auscultationSecList.get(k).equals("Regular rhythm"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbRegRyth = new CheckBox("Regular rhythm");
                            cbRegRyth.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbRegRyth.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radRegRyth = new CustomRadioButtonGroup("regrhy");
                            tbRegRyth = new TextArea();
                            tbRegRyth.setVisible(false);
                            tbRegRyth.setWidth(textWidth);
                            radRegRyth.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbRegRyth.setVisible(false);
                                    cbRegRyth.setValue(true, true);
                                }
                            });
                            radRegRyth.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbRegRyth.setVisible(true);
                                    cbRegRyth.setValue(true, true);

                                }
                            });
                            radRegRyth.setEnable(false);
                            tbRegRyth.setEnabled(false);
                            cbRegRyth.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbRegRyth.getValue()) {
                                        radRegRyth.setEnable(true);
                                        tbRegRyth.setEnabled(true);
                                    } else {
                                        radRegRyth.setEnable(false);
                                        tbRegRyth.setEnabled(false);
                                    }
                                }

                            });
                            cvTable.setWidget(cvRowCount, 0, cbRegRyth);
                            cvTable.setWidget(cvRowCount, 1, radRegRyth);
                            cvTable.setWidget(cvRowCount + 1, 0, tbRegRyth);
                            cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                            cvRowCount = cvRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespecvregrhystatus")) {
                                radRegRyth.setWidgetValue(templateValuesMap.get("pnotespecvregrhystatus"),
                                        true);
                                tbRegRyth.setText(templateValuesMap.get("pnotespecvregrhycmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpecvregrhystatus")) {
                                radRegRyth.setWidgetValue(templateValuesMap.get("pnotestpecvregrhystatus"),
                                        true);
                                tbRegRyth.setText(templateValuesMap.get("pnotestpecvregrhycmnt"));
                            }
                        }
                        if ((auscultationSecList != null && auscultationSecList.get(k).equals("S1 constant"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbS1Cons = new CheckBox("S1 constant");
                            cbS1Cons.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbS1Cons.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radS1Cons = new CustomRadioButtonGroup("s1cons");
                            tbS1Cons = new TextArea();
                            tbS1Cons.setVisible(false);
                            tbS1Cons.setWidth(textWidth);
                            radS1Cons.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbS1Cons.setVisible(false);
                                    cbS1Cons.setValue(true, true);
                                }
                            });
                            radS1Cons.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbS1Cons.setVisible(true);
                                    cbS1Cons.setValue(true, true);
                                }
                            });
                            radS1Cons.setEnable(false);
                            tbS1Cons.setEnabled(false);
                            cbS1Cons.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbS1Cons.getValue()) {
                                        radS1Cons.setEnable(true);
                                        tbS1Cons.setEnabled(true);
                                    } else {
                                        radS1Cons.setEnable(false);
                                        tbS1Cons.setEnabled(false);
                                    }
                                }

                            });
                            cvTable.setWidget(cvRowCount, 0, cbS1Cons);
                            cvTable.setWidget(cvRowCount, 1, radS1Cons);
                            cvTable.setWidget(cvRowCount + 1, 0, tbS1Cons);
                            cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                            cvRowCount = cvRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespecvs1consstatus")) {
                                radS1Cons.setWidgetValue(templateValuesMap.get("pnotespecvs1consstatus"), true);
                                tbS1Cons.setText(templateValuesMap.get("pnotespecvs1conscmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpecvs1consstatus")) {
                                radS1Cons.setWidgetValue(templateValuesMap.get("pnotestpecvs1consstatus"),
                                        true);
                                tbS1Cons.setText(templateValuesMap.get("pnotestpecvs1conscmnt"));
                            }
                        }

                        if ((auscultationSecList != null
                                && auscultationSecList.get(k).equals("S2 physiologic split"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbS2PhysSplit = new CheckBox("S2 physiologic split");
                            cbS2PhysSplit.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbS2PhysSplit.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radPhysSplit = new CustomRadioButtonGroup("s2phy");
                            tbPhysSplit = new TextArea();
                            tbPhysSplit.setVisible(false);
                            tbPhysSplit.setWidth(textWidth);
                            radPhysSplit.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbPhysSplit.setVisible(false);
                                    cbS2PhysSplit.setValue(true, true);
                                }
                            });
                            radPhysSplit.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbPhysSplit.setVisible(true);
                                    cbS2PhysSplit.setValue(true, true);
                                }
                            });
                            radPhysSplit.setEnable(false);
                            tbPhysSplit.setEnabled(false);
                            cbS2PhysSplit.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbS2PhysSplit.getValue()) {
                                        radPhysSplit.setEnable(true);
                                        tbPhysSplit.setEnabled(true);
                                    } else {
                                        radPhysSplit.setEnable(false);
                                        tbPhysSplit.setEnabled(false);
                                    }
                                }

                            });
                            cvTable.setWidget(cvRowCount, 0, cbS2PhysSplit);
                            cvTable.setWidget(cvRowCount, 1, radPhysSplit);
                            cvTable.setWidget(cvRowCount + 1, 0, tbPhysSplit);
                            cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                            cvRowCount = cvRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespecvs2physplstatus")) {
                                radPhysSplit.setWidgetValue(templateValuesMap.get("pnotespecvs2physplstatus"),
                                        true);
                                tbPhysSplit.setText(templateValuesMap.get("pnotespecvs2physplcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpecvs2physplstatus")) {
                                radPhysSplit.setWidgetValue(templateValuesMap.get("pnotestpecvs2physplstatus"),
                                        true);
                                tbPhysSplit.setText(templateValuesMap.get("pnotestpecvs2physplcmnt"));
                            }
                        }

                        if ((auscultationSecList != null
                                && auscultationSecList.get(k).equals("Murmur (describe)"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbMurmur = new CheckBox("Murmur (describe)");
                            cbMurmur.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbMurmur.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radMurmur = new CustomRadioButtonGroup("murmur");
                            tbMurmur = new TextArea();
                            tbMurmur.setVisible(false);
                            tbMurmur.setWidth(textWidth);
                            radMurmur.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbMurmur.setVisible(false);
                                    cbMurmur.setValue(true, true);
                                }
                            });
                            radMurmur.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbMurmur.setVisible(true);
                                    cbMurmur.setValue(true, true);
                                }
                            });
                            radMurmur.setEnable(false);
                            tbMurmur.setEnabled(false);
                            cbMurmur.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbMurmur.getValue()) {
                                        radMurmur.setEnable(true);
                                        tbMurmur.setEnabled(true);
                                    } else {
                                        radMurmur.setEnable(false);
                                        tbMurmur.setEnabled(false);
                                    }
                                }

                            });
                            cvTable.setWidget(cvRowCount, 0, cbMurmur);
                            cvTable.setWidget(cvRowCount, 1, radMurmur);
                            cvTable.setWidget(cvRowCount + 1, 0, tbMurmur);
                            cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                            cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                            cvRowCount = cvRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespecvmurstatus")) {
                                radMurmur.setWidgetValue(templateValuesMap.get("pnotespecvmurstatus"), true);
                                tbMurmur.setText(templateValuesMap.get("pnotespecvmurcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpecvmurstatus")) {
                                radMurmur.setWidgetValue(templateValuesMap.get("pnotestpecvmurstatus"), true);
                                tbMurmur.setText(templateValuesMap.get("pnotestpecvmurcmnt"));
                            }
                        }
                    }
                }

                if ((cvList != null && cvList.get(j).equals("Palpation of heart"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbPalHrt = new CheckBox("Palpation of heart");
                    cbPalHrt.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radPalHrt = new CustomRadioButtonGroup("palhrt");
                    tbPalHrt = new TextArea();
                    tbPalHrt.setVisible(false);
                    tbPalHrt.setWidth(textWidth);
                    radPalHrt.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbPalHrt.setVisible(false);
                            cbPalHrt.setValue(true, true);
                        }
                    });
                    radPalHrt.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbPalHrt.setVisible(true);
                            cbPalHrt.setValue(true, true);
                        }
                    });
                    radPalHrt.setEnable(false);
                    tbPalHrt.setEnabled(false);
                    cbPalHrt.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbPalHrt.getValue()) {
                                radPalHrt.setEnable(true);
                                tbPalHrt.setEnabled(true);
                            } else {
                                radPalHrt.setEnable(false);
                                tbPalHrt.setEnabled(false);
                            }
                        }

                    });
                    cvTable.setWidget(cvRowCount, 0, cbPalHrt);
                    cvTable.setWidget(cvRowCount, 1, radPalHrt);
                    cvTable.setWidget(cvRowCount + 1, 0, tbPalHrt);
                    cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                    cvRowCount = cvRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespecvpalhrtstatus")) {
                        radPalHrt.setWidgetValue(templateValuesMap.get("pnotespecvpalhrtstatus"), true);
                        tbPalHrt.setText(templateValuesMap.get("pnotespecvpalhrtcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpecvpalhrtstatus")) {
                        radPalHrt.setWidgetValue(templateValuesMap.get("pnotestpecvpalhrtstatus"), true);
                        tbPalHrt.setText(templateValuesMap.get("pnotestpecvpalhrtcmnt"));
                    }
                }

                if ((cvList != null && cvList.get(j).equals("Abdominal aorta"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbAbAorta = new CheckBox("Abdominal aorta");
                    cbAbAorta.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radAbAorta = new CustomRadioButtonGroup("abdaor");
                    tbAbAorta = new TextArea();
                    tbAbAorta.setVisible(false);
                    tbAbAorta.setWidth(textWidth);
                    radAbAorta.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbAbAorta.setVisible(false);
                            cbAbAorta.setValue(true, true);
                        }
                    });
                    radAbAorta.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbAbAorta.setVisible(true);
                            cbAbAorta.setValue(true, true);
                        }
                    });
                    radAbAorta.setEnable(false);
                    tbAbAorta.setEnabled(false);
                    cbAbAorta.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbAbAorta.getValue()) {
                                radAbAorta.setEnable(true);
                                tbAbAorta.setEnabled(true);
                            } else {
                                radAbAorta.setEnable(false);
                                tbAbAorta.setEnabled(false);
                            }
                        }

                    });
                    cvTable.setWidget(cvRowCount, 0, cbAbAorta);
                    cvTable.setWidget(cvRowCount, 1, radAbAorta);
                    cvTable.setWidget(cvRowCount + 1, 0, tbAbAorta);
                    cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                    cvRowCount = cvRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespecvabdaorstatus")) {
                        radAbAorta.setWidgetValue(templateValuesMap.get("pnotespecvabdaorstatus"), true);
                        tbAbAorta.setText(templateValuesMap.get("pnotespecvabdaorcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpecvabdaorstatus")) {
                        radAbAorta.setWidgetValue(templateValuesMap.get("pnotestpecvabdaorstatus"), true);
                        tbAbAorta.setText(templateValuesMap.get("pnotestpecvabdaorcmnt"));
                    }
                }

                if ((cvList != null && cvList.get(j).equals("Femoral arteries"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbFemArt = new CheckBox("Femoral arteries");
                    cbFemArt.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radFemArt = new CustomRadioButtonGroup("femart");
                    tbFemArt = new TextArea();
                    tbFemArt.setVisible(false);
                    tbFemArt.setWidth(textWidth);
                    radFemArt.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbFemArt.setVisible(false);
                            cbFemArt.setValue(true, true);
                        }
                    });
                    radFemArt.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbFemArt.setVisible(true);
                            cbFemArt.setValue(true, true);
                        }
                    });
                    radFemArt.setEnable(false);
                    tbFemArt.setEnabled(false);
                    cbFemArt.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbFemArt.getValue()) {
                                radFemArt.setEnable(true);
                                tbFemArt.setEnabled(true);
                            } else {
                                radFemArt.setEnable(false);
                                tbFemArt.setEnabled(false);
                            }
                        }

                    });
                    cvTable.setWidget(cvRowCount, 0, cbFemArt);
                    cvTable.setWidget(cvRowCount, 1, radFemArt);
                    cvTable.setWidget(cvRowCount + 1, 0, tbFemArt);
                    cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                    cvRowCount = cvRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespecvfemartstatus")) {
                        radFemArt.setWidgetValue(templateValuesMap.get("pnotespecvfemartstatus"), true);
                        tbFemArt.setText(templateValuesMap.get("pnotespecvfemartcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpecvfemartstatus")) {
                        radFemArt.setWidgetValue(templateValuesMap.get("pnotestpecvfemartstatus"), true);
                        tbFemArt.setText(templateValuesMap.get("pnotestpecvfemartcmnt"));
                    }
                }

                if ((cvList != null && cvList.get(j).equals("Pedal pulses"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbPedalPulses = new CheckBox("Pedal pulses");
                    cbPedalPulses.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radPedalPulses = new CustomRadioButtonGroup("pedpul");
                    tbPedalPulses = new TextArea();
                    tbPedalPulses.setVisible(false);
                    tbPedalPulses.setWidth(textWidth);
                    radPedalPulses.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbPedalPulses.setVisible(false);
                            cbPedalPulses.setValue(true, true);
                        }
                    });
                    radPedalPulses.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbPedalPulses.setVisible(true);
                            cbPedalPulses.setValue(true, true);
                        }
                    });
                    radPedalPulses.setEnable(false);
                    tbPedalPulses.setEnabled(false);
                    cbPedalPulses.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbPedalPulses.getValue()) {
                                radPedalPulses.setEnable(true);
                                tbPedalPulses.setEnabled(true);
                            } else {
                                radPedalPulses.setEnable(false);
                                tbPedalPulses.setEnabled(false);
                            }
                        }

                    });
                    cvTable.setWidget(cvRowCount, 0, cbPedalPulses);
                    cvTable.setWidget(cvRowCount, 1, radPedalPulses);
                    cvTable.setWidget(cvRowCount + 1, 0, tbPedalPulses);
                    cvTable.getFlexCellFormatter().setColSpan(cvRowCount + 1, 0, 2);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setVerticalAlignment(cvRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 0, labelWidth);
                    cvTable.getFlexCellFormatter().setWidth(cvRowCount, 1, radWidth);
                    cvRowCount = cvRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespecvpedpulstatus")) {
                        radPedalPulses.setWidgetValue(templateValuesMap.get("pnotespecvpedpulstatus"), true);
                        tbPedalPulses.setText(templateValuesMap.get("pnotespecvpadpulcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpecvpedpulstatus")) {
                        radPedalPulses.setWidgetValue(templateValuesMap.get("pnotestpecvpedpulstatus"), true);
                        tbPedalPulses.setText(templateValuesMap.get("pnotestpecvpadpulcmnt"));
                    }
                }
                if ((cvList != null && cvList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (cvList != null && cvList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbCVFreeForm = new TextArea();
                    tbCVFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbCVFreeForm);
                    freeHp.setCellWidth(tbCVFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespecvfreecmnt")) {
                        tbCVFreeForm.setText(templateValuesMap.get("pnotespecvfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpecvfreecmnt")) {
                        tbCVFreeForm.setText(templateValuesMap.get("pnotestpecvfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbCVExBill = new CheckBox("Procedure");
                cbCVExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbCVExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespecv")) {
                    HashMap<String, String> m = billMap.get("pnotespecv");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespecv", biw);
                    cbCVExBill.setValue(true);

                }
                cbCVExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbCVExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbCVExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespecv", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespecv");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("GI"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int giRowCount = 0;
            Label lbGI = new Label("GI");
            lbGI.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbGI);
            final FlexTable giTable = new FlexTable();
            giTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(giTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int giLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#GI"))
                giLoopCountMax = sectionsFieldMap.get("Sections#Exam#GI").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#GI"))
                giLoopCountMax = 0;
            else
                giLoopCountMax = 1;
            List<String> giList = sectionsFieldMap.get("Sections#Exam#GI");
            for (int j = 0; j < giLoopCountMax; j++) {
                if ((giList != null && giList.get(j).equals("Abdomen"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    Label lbAbd = new Label("Abdomen:");
                    lbAbd.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    giTable.setWidget(giRowCount, 0, lbAbd);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    giRowCount++;
                    int abdLoopCountMax = 0;
                    if (sectionsFieldMap.containsKey("Sections")
                            && sectionsFieldMap.containsKey("Sections#Exam#GI#Abdomen"))
                        abdLoopCountMax = sectionsFieldMap.get("Sections#Exam#GI#Abdomen").size();
                    else if (sectionsFieldMap.containsKey("Sections")
                            && !sectionsFieldMap.containsKey("Sections#Exam#GI#Abdomen"))
                        abdLoopCountMax = 0;
                    else
                        abdLoopCountMax = 1;
                    List<String> abdSecList = sectionsFieldMap.get("Sections#Exam#GI#Abdomen");

                    for (int k = 0; k < abdLoopCountMax; k++) {

                        if ((abdSecList != null && abdSecList.get(k).equals("Scars"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbScars = new CheckBox("Scars");
                            cbScars.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbScars.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radScars = new CustomRadioButtonGroup("scars");
                            tbScars = new TextArea();
                            tbScars.setVisible(false);
                            tbScars.setWidth(textWidth);
                            radScars.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbScars.setVisible(false);
                                    cbScars.setValue(true, true);
                                }
                            });
                            radScars.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbScars.setVisible(true);
                                    cbScars.setValue(true, true);
                                }
                            });
                            radScars.setEnable(false);
                            tbScars.setEnabled(false);
                            cbScars.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbScars.getValue()) {
                                        radScars.setEnable(true);
                                        tbScars.setEnabled(true);
                                    } else {
                                        radScars.setEnable(false);
                                        tbScars.setEnabled(false);
                                    }
                                }

                            });
                            giTable.setWidget(giRowCount, 0, cbScars);
                            giTable.setWidget(giRowCount, 1, radScars);
                            giTable.setWidget(giRowCount + 1, 0, tbScars);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegiscarsstatus")) {
                                radScars.setWidgetValue(templateValuesMap.get("pnotespegiscarsstatus"), true);
                                tbScars.setText(templateValuesMap.get("pnotespegiscarscmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegiscarsstatus")) {
                                radScars.setWidgetValue(templateValuesMap.get("pnotestpegiscarsstatus"), true);
                                tbScars.setText(templateValuesMap.get("pnotestpegiscarscmnt"));
                            }
                        }
                        if ((abdSecList != null && abdSecList.get(k).equals("Bruit"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbBruit = new CheckBox("Bruit");
                            cbBruit.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbBruit.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radBruit = new CustomRadioButtonGroup("bruit");
                            tbBruit = new TextArea();
                            tbBruit.setVisible(false);
                            tbBruit.setWidth(textWidth);
                            radBruit.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbBruit.setVisible(false);
                                    cbBruit.setValue(true, true);
                                }
                            });
                            radBruit.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbBruit.setVisible(true);
                                    cbBruit.setValue(true, true);
                                }
                            });
                            radBruit.setEnable(false);
                            tbBruit.setEnabled(false);
                            cbBruit.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbBruit.getValue()) {
                                        radBruit.setEnable(true);
                                        tbBruit.setEnabled(true);
                                    } else {
                                        radBruit.setEnable(false);
                                        tbBruit.setEnabled(false);
                                    }
                                }

                            });
                            giTable.setWidget(giRowCount, 0, cbBruit);
                            giTable.setWidget(giRowCount, 1, radBruit);
                            giTable.setWidget(giRowCount + 1, 0, tbBruit);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegibruitstatus")) {
                                radBruit.setWidgetValue(templateValuesMap.get("pnotespegibruitstatus"), true);
                                tbBruit.setText(templateValuesMap.get("pnotespegibruitcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegibruitstatus")) {
                                radBruit.setWidgetValue(templateValuesMap.get("pnotestpegibruitstatus"), true);
                                tbBruit.setText(templateValuesMap.get("pnotestpegibruitcmnt"));
                            }
                        }

                        if ((abdSecList != null && abdSecList.get(k).equals("Mass"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbMassExam = new CheckBox("Mass");
                            cbMassExam.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbMassExam.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radMass = new CustomRadioButtonGroup("mass");
                            tbMass = new TextArea();
                            tbMass.setVisible(false);
                            tbMass.setWidth(textWidth);
                            radMass.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbMass.setVisible(false);
                                    cbMassExam.setValue(true, true);
                                }
                            });
                            radMass.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbMass.setVisible(true);
                                    cbMassExam.setValue(true, true);
                                }
                            });
                            radMass.setEnable(false);
                            tbMass.setEnabled(false);
                            cbMassExam.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbMassExam.getValue()) {
                                        radMass.setEnable(true);
                                        tbMass.setEnabled(true);
                                    } else {
                                        radMass.setEnable(false);
                                        tbMass.setEnabled(false);
                                    }
                                }

                            });
                            giTable.setWidget(giRowCount, 0, cbMassExam);
                            giTable.setWidget(giRowCount, 1, radMass);
                            giTable.setWidget(giRowCount + 1, 0, tbMass);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegimassstatus")) {
                                radMass.setWidgetValue(templateValuesMap.get("pnotespegimassstatus"), true);
                                tbMass.setText(templateValuesMap.get("pnotespegimasscmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegimassstatus")) {
                                radMass.setWidgetValue(templateValuesMap.get("pnotestpegimassstatus"), true);
                                tbMass.setText(templateValuesMap.get("pnotestpegimasscmnt"));
                            }
                        }

                        if ((abdSecList != null && abdSecList.get(k).equals("Tenderness"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbTenderness = new CheckBox("Tenderness");
                            cbTenderness.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbTenderness.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radTenderness = new CustomRadioButtonGroup("tender");
                            tbTenderness = new TextArea();
                            tbTenderness.setVisible(false);
                            tbTenderness.setWidth(textWidth);
                            radTenderness.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbTenderness.setVisible(false);
                                    cbTenderness.setValue(true, true);
                                }
                            });
                            radTenderness.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbTenderness.setVisible(true);
                                    cbTenderness.setValue(true, true);
                                }
                            });
                            radTenderness.setEnable(false);
                            tbTenderness.setEnabled(false);
                            cbTenderness.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbTenderness.getValue()) {
                                        radTenderness.setEnable(true);
                                        tbTenderness.setEnabled(true);
                                    } else {
                                        radTenderness.setEnable(false);
                                        tbTenderness.setEnabled(false);
                                    }
                                }

                            });
                            giTable.setWidget(giRowCount, 0, cbTenderness);
                            giTable.setWidget(giRowCount, 1, radTenderness);
                            giTable.setWidget(giRowCount + 1, 0, tbTenderness);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegitendstatus")) {
                                radTenderness.setWidgetValue(templateValuesMap.get("pnotespegitendstatus"),
                                        true);
                                tbTenderness.setText(templateValuesMap.get("pnotespegitendcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegitendstatus")) {
                                radTenderness.setWidgetValue(templateValuesMap.get("pnotestpegitendstatus"),
                                        true);
                                tbTenderness.setText(templateValuesMap.get("pnotestpegitendcmnt"));
                            }
                        }
                        if ((abdSecList != null && abdSecList.get(k).equals("Hepatomegaly"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbHepatomegaly = new CheckBox("Hepatomegaly");
                            cbHepatomegaly.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbHepatomegaly.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radHepatomegaly = new CustomRadioButtonGroup("hepat");
                            tbHepatomegaly = new TextArea();
                            tbHepatomegaly.setVisible(false);
                            tbHepatomegaly.setWidth(textWidth);
                            radHepatomegaly.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbHepatomegaly.setVisible(false);
                                    cbHepatomegaly.setValue(true, true);
                                }
                            });
                            radHepatomegaly.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbHepatomegaly.setVisible(true);
                                    cbHepatomegaly.setValue(true, true);
                                }
                            });
                            radHepatomegaly.setEnable(false);
                            tbHepatomegaly.setEnabled(false);
                            cbHepatomegaly.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbHepatomegaly.getValue()) {
                                        radHepatomegaly.setEnable(true);
                                        tbHepatomegaly.setEnabled(true);
                                    } else {
                                        radHepatomegaly.setEnable(false);
                                        tbHepatomegaly.setEnabled(false);
                                    }
                                }

                            });
                            giTable.setWidget(giRowCount, 0, cbHepatomegaly);
                            giTable.setWidget(giRowCount, 1, radHepatomegaly);
                            giTable.setWidget(giRowCount + 1, 0, tbHepatomegaly);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegiheptstatus")) {
                                radHepatomegaly.setWidgetValue(templateValuesMap.get("pnotespegiheptstatus"),
                                        true);
                                tbHepatomegaly.setText(templateValuesMap.get("pnotespegiheptcmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegiheptstatus")) {
                                radHepatomegaly.setWidgetValue(templateValuesMap.get("pnotestpegiheptstatus"),
                                        true);
                                tbHepatomegaly.setText(templateValuesMap.get("pnotestpegiheptcmnt"));
                            }
                        }
                        if ((abdSecList != null && abdSecList.get(k).equals("Splenomegaly"))
                                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES
                                        && currTemplate.equals(""))) {
                            cbSplenomegaly = new CheckBox("Splenomegaly");
                            cbSplenomegaly.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbSplenomegaly.getElement().getStyle().setMarginLeft(50, Unit.PX);
                            radSplenomegaly = new CustomRadioButtonGroup("splen");
                            tbSplenomegaly = new TextArea();
                            tbSplenomegaly.setVisible(false);
                            tbSplenomegaly.setWidth(textWidth);
                            radSplenomegaly.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbSplenomegaly.setVisible(false);
                                    cbSplenomegaly.setValue(true, true);
                                }
                            });
                            radSplenomegaly.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbSplenomegaly.setVisible(true);
                                    cbSplenomegaly.setValue(true, true);
                                }
                            });
                            radSplenomegaly.setEnable(false);
                            tbSplenomegaly.setEnabled(false);
                            cbSplenomegaly.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbSplenomegaly.getValue()) {
                                        radSplenomegaly.setEnable(true);
                                        tbSplenomegaly.setEnabled(true);
                                    } else {
                                        radSplenomegaly.setEnable(false);
                                        tbSplenomegaly.setEnabled(false);
                                    }
                                }
                            });
                            giTable.setWidget(giRowCount, 0, cbSplenomegaly);
                            giTable.setWidget(giRowCount, 1, radSplenomegaly);
                            giTable.setWidget(giRowCount + 1, 0, tbSplenomegaly);
                            giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                                    HasVerticalAlignment.ALIGN_TOP);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                            giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                            giRowCount = giRowCount + 2;
                            if (templateValuesMap.containsKey("pnotespegisplenstatus")) {
                                radSplenomegaly.setWidgetValue(templateValuesMap.get("pnotespegisplenstatus"),
                                        true);
                                tbSplenomegaly.setText(templateValuesMap.get("pnotespegisplencmnt"));
                            } else if (templateValuesMap.containsKey("pnotestpegisplenstatus")) {
                                radSplenomegaly.setWidgetValue(templateValuesMap.get("pnotestpegisplenstatus"),
                                        true);
                                tbSplenomegaly.setText(templateValuesMap.get("pnotestpegisplencmnt"));
                            }
                        }
                    }
                }

                if ((giList != null && giList.get(j).equals("Anus_perineum_rectum_sphincter tone"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbAPRS = new CheckBox("Anus, perineum, rectum, sphincter tone");
                    cbAPRS.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radAPRS = new CustomRadioButtonGroup("aprst");
                    tbAPRS = new TextArea();
                    tbAPRS.setVisible(false);
                    tbAPRS.setWidth(textWidth);
                    radAPRS.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbAPRS.setVisible(false);
                            cbAPRS.setValue(true, true);
                        }
                    });
                    radAPRS.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbAPRS.setVisible(true);
                            cbAPRS.setValue(true, true);
                        }
                    });
                    radAPRS.setEnable(false);
                    tbAPRS.setEnabled(false);
                    cbAPRS.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbAPRS.getValue()) {
                                radAPRS.setEnable(true);
                                tbAPRS.setEnabled(true);
                            } else {
                                radAPRS.setEnable(false);
                                tbAPRS.setEnabled(false);
                            }
                        }
                    });
                    giTable.setWidget(giRowCount, 0, cbAPRS);
                    giTable.setWidget(giRowCount, 1, radAPRS);
                    giTable.setWidget(giRowCount + 1, 0, tbAPRS);
                    giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                    giRowCount = giRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespegiaprsstatus")) {
                        radAPRS.setWidgetValue(templateValuesMap.get("pnotespegiaprsstatus"), true);
                        tbAPRS.setText(templateValuesMap.get("pnotespegiaprscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpegiaprsstatus")) {
                        radAPRS.setWidgetValue(templateValuesMap.get("pnotestpegiaprsstatus"), true);
                        tbAPRS.setText(templateValuesMap.get("pnotestpegiaprscmnt"));
                    }
                }

                if ((giList != null && giList.get(j).equals("Bowel sounds"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbBowSnd = new CheckBox("Bowel sounds:");
                    cbBowSnd.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radBowSnd = new CustomRadioButtonGroup("bowsnd");
                    tbBowSnd = new TextArea();
                    tbBowSnd.setVisible(false);
                    tbBowSnd.setWidth(textWidth);
                    radBowSnd.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbBowSnd.setVisible(false);
                            cbBowSnd.setValue(true, true);
                        }
                    });
                    radBowSnd.addItem("High", "2", new Command() {
                        @Override
                        public void execute() {

                            tbBowSnd.setVisible(true);
                            cbBowSnd.setValue(true, true);
                        }
                    });
                    radBowSnd.addItem("Low", "3", new Command() {
                        @Override
                        public void execute() {

                            tbBowSnd.setVisible(true);
                            cbBowSnd.setValue(true, true);
                        }
                    });
                    radBowSnd.addItem("Absent", "4", new Command() {
                        @Override
                        public void execute() {

                            tbBowSnd.setVisible(true);
                            cbBowSnd.setValue(true, true);
                        }
                    });
                    radBowSnd.setEnable(false);
                    tbBowSnd.setEnabled(false);
                    cbBowSnd.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbBowSnd.getValue()) {
                                radBowSnd.setEnable(true);
                                tbBowSnd.setEnabled(true);
                            } else {
                                radBowSnd.setEnable(false);
                                tbBowSnd.setEnabled(false);
                            }
                        }
                    });
                    giTable.setWidget(giRowCount, 0, cbBowSnd);
                    giTable.setWidget(giRowCount, 1, radBowSnd);
                    giTable.setWidget(giRowCount + 1, 0, tbBowSnd);
                    giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                    giRowCount = giRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespegibowsndstatus")) {
                        radBowSnd.setWidgetValue(templateValuesMap.get("pnotespegibowsndstatus"), true);
                        tbBowSnd.setText(templateValuesMap.get("pnotespegibowsndcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpegibowsndstatus")) {
                        radBowSnd.setWidgetValue(templateValuesMap.get("pnotestpegibowsndstatus"), true);
                        tbBowSnd.setText(templateValuesMap.get("pnotestpegibowsndcmnt"));
                    }
                }

                if ((giList != null && giList.get(j).equals("Stool"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbStool = new CheckBox("Stool:");
                    cbStool.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radStool = new CustomRadioButtonGroup("stool");
                    tbStool = new TextArea();
                    tbStool.setVisible(false);
                    tbStool.setWidth(textWidth);
                    radStool.addItem("Heme positive", "1", new Command() {
                        @Override
                        public void execute() {

                            tbStool.setVisible(false);
                            cbStool.setValue(true, true);
                        }
                    });
                    radStool.addItem("Heme negative", "2", new Command() {
                        @Override
                        public void execute() {

                            tbStool.setVisible(true);
                            cbStool.setValue(true, true);
                        }
                    });
                    radStool.setEnable(false);
                    tbStool.setEnabled(false);
                    cbStool.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbStool.getValue()) {
                                radStool.setEnable(true);
                                tbStool.setEnabled(true);
                            } else {
                                radStool.setEnable(false);
                                tbStool.setEnabled(false);
                            }
                        }
                    });
                    giTable.setWidget(giRowCount, 0, cbStool);
                    giTable.setWidget(giRowCount, 1, radStool);
                    giTable.setWidget(giRowCount + 1, 0, tbStool);
                    giTable.getFlexCellFormatter().setColSpan(giRowCount + 1, 0, 2);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setVerticalAlignment(giRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 0, labelWidth);
                    giTable.getFlexCellFormatter().setWidth(giRowCount, 1, radWidth);
                    giRowCount = giRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespegistoolstatus")) {
                        radStool.setWidgetValue(templateValuesMap.get("pnotespegistoolstatus"), true);
                        tbStool.setText(templateValuesMap.get("pnotespegistoolcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpegistoolstatus")) {
                        radStool.setWidgetValue(templateValuesMap.get("pnotestpegistoolstatus"), true);
                        tbStool.setText(templateValuesMap.get("pnotestpegistoolcmnt"));
                    }
                }
                if ((giList != null && giList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (giList != null && giList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbGIFreeForm = new TextArea();
                    tbGIFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbGIFreeForm);
                    freeHp.setCellWidth(tbGIFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespegifreecmnt")) {
                        tbGIFreeForm.setText(templateValuesMap.get("pnotespegifreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpegifreecmnt")) {
                        tbGIFreeForm.setText(templateValuesMap.get("pnotestpegifreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbGIExBill = new CheckBox("Procedure");
                cbGIExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbGIExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespegiabd")) {
                    HashMap<String, String> m = billMap.get("pnotespegiabd");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespegiabd", biw);
                    cbGIExBill.setValue(true);

                }
                cbGIExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbGIExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbGIExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespegiabd", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespegiabd");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("GU"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int guRowCount = 0;
            Label lbGU = new Label("GU");
            lbGU.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbGU);
            final FlexTable guTable = new FlexTable();
            guTable.setWidth("100%");
            guTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(guTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int guLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#GU"))
                guLoopCountMax = sectionsFieldMap.get("Sections#Exam#GU").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#GU"))
                guLoopCountMax = 0;
            else
                guLoopCountMax = 1;
            List<String> guList = sectionsFieldMap.get("Sections#Exam#GU");
            for (int j = 0; j < guLoopCountMax; j++) {
                if ((guList != null && guList.get(j).equals("Gender"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    Label lbGender = new Label("Gender:");
                    lbGender.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radGender = new CustomRadioButtonGroup("gender");
                    radPenis = new CustomRadioButtonGroup("penis");
                    tbPenis = new TextArea();
                    tbPenis.setVisible(false);
                    tbPenis.setWidth(textWidth);

                    radTestes = new CustomRadioButtonGroup("testes");
                    tbTestes = new TextArea();
                    tbTestes.setVisible(false);
                    tbTestes.setWidth(textWidth);

                    radProstate = new CustomRadioButtonGroup("prostate");
                    tbProstate = new TextArea();
                    tbProstate.setVisible(false);
                    tbProstate.setWidth(textWidth);

                    radExtGen = new CustomRadioButtonGroup("extgen");
                    tbExtGen = new TextArea();
                    tbExtGen.setVisible(false);
                    tbExtGen.setWidth(textWidth);

                    radCervix = new CustomRadioButtonGroup("cervix");
                    tbCervix = new TextArea();
                    tbCervix.setVisible(false);
                    tbCervix.setWidth(textWidth);

                    radUteAdn = new CustomRadioButtonGroup("uteradn");
                    tbUteAdn = new TextArea();
                    tbUteAdn.setVisible(false);
                    tbUteAdn.setWidth(textWidth);
                    final int r1 = guRowCount;
                    radGender.addItem("Male", "1", new Command() {
                        @Override
                        public void execute() {
                            cbPenis = new CheckBox("Penis");
                            cbPenis.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbPenis.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r11 = r1 + 1;
                            radPenis.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbPenis.setVisible(false);
                                    cbPenis.setValue(true, true);
                                }
                            });
                            radPenis.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbPenis.setVisible(true);
                                    cbPenis.setValue(true, true);
                                }
                            });
                            radPenis.setEnable(false);
                            tbPenis.setEnabled(false);
                            cbPenis.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbPenis.getValue()) {
                                        radPenis.setEnable(true);
                                        tbPenis.setEnabled(true);
                                    } else {
                                        radPenis.setEnable(false);
                                        tbPenis.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r11, 0, cbPenis);
                            guTable.setWidget(r11, 1, radPenis);
                            guTable.setWidget(r11 + 1, 0, tbPenis);
                            guTable.getFlexCellFormatter().setColSpan(r11 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r11, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r11, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                            cbTestes = new CheckBox("Testes");
                            cbTestes.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbTestes.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r12 = r1 + 4;
                            radTestes.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbTestes.setVisible(false);
                                    cbTestes.setValue(true, true);
                                }
                            });
                            radTestes.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbTestes.setVisible(true);
                                    cbTestes.setValue(true, true);
                                }
                            });
                            radTestes.setEnable(false);
                            tbTestes.setEnabled(false);
                            cbTestes.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbTestes.getValue()) {
                                        radTestes.setEnable(true);
                                        tbTestes.setEnabled(true);
                                    } else {
                                        radTestes.setEnable(false);
                                        tbTestes.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r12, 0, cbTestes);
                            guTable.setWidget(r12, 1, radTestes);
                            guTable.setWidget(r12 + 1, 0, tbTestes);
                            guTable.getFlexCellFormatter().setColSpan(r12 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r12, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r12, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                            cbProstate = new CheckBox("Prostate");
                            cbProstate.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbProstate.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r13 = r1 + 6;
                            radProstate.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbProstate.setVisible(false);
                                    cbProstate.setValue(true, true);
                                }
                            });
                            radProstate.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbProstate.setVisible(true);
                                    cbProstate.setValue(true, true);
                                }
                            });
                            radProstate.setEnable(false);
                            tbProstate.setEnabled(false);
                            cbProstate.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbProstate.getValue()) {
                                        radProstate.setEnable(true);
                                        tbProstate.setEnabled(true);
                                    } else {
                                        radProstate.setEnable(false);
                                        tbProstate.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r13, 0, cbProstate);
                            guTable.setWidget(r13, 1, radProstate);
                            guTable.setWidget(r13 + 1, 0, tbProstate);
                            guTable.getFlexCellFormatter().setColSpan(r13 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r13, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r13, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                        }
                    });
                    radGender.addItem("Female", "2", new Command() {
                        @Override
                        public void execute() {
                            cbExtGen = new CheckBox("External genitalia");
                            cbExtGen.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbExtGen.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r14 = r1 + 1;
                            radExtGen.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbExtGen.setVisible(false);
                                    cbExtGen.setValue(true, true);
                                }
                            });
                            radExtGen.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {
                                    tbExtGen.setVisible(true);
                                    cbExtGen.setValue(true, true);
                                }
                            });
                            radExtGen.setEnable(false);
                            tbExtGen.setEnabled(false);
                            cbExtGen.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbExtGen.getValue()) {
                                        radExtGen.setEnable(true);
                                        tbExtGen.setEnabled(true);
                                    } else {
                                        radExtGen.setEnable(false);
                                        tbExtGen.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r14, 0, cbExtGen);
                            guTable.setWidget(r14, 1, radExtGen);
                            guTable.setWidget(r14 + 1, 0, tbExtGen);
                            guTable.getFlexCellFormatter().setColSpan(r14 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r14, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r14, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                            cbCervix = new CheckBox("Cervix");
                            cbCervix.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbCervix.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r15 = r1 + 4;
                            radCervix.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbCervix.setVisible(false);
                                    cbCervix.setValue(true, true);
                                }
                            });
                            radCervix.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbCervix.setVisible(true);
                                    cbCervix.setValue(true, true);
                                }
                            });
                            radCervix.setEnable(false);
                            tbCervix.setEnabled(false);
                            cbCervix.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbCervix.getValue()) {
                                        radCervix.setEnable(true);
                                        tbCervix.setEnabled(true);
                                    } else {
                                        radCervix.setEnable(false);
                                        tbCervix.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r15, 0, cbCervix);
                            guTable.setWidget(r15, 1, radCervix);
                            guTable.setWidget(r15 + 1, 0, tbCervix);
                            guTable.getFlexCellFormatter().setColSpan(r15 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r15, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r15, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                            cbUteAdn = new CheckBox("Uterus/adnexa");
                            cbUteAdn.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                            cbUteAdn.getElement().getStyle().setMarginLeft(50, Unit.PX);

                            final int r16 = r1 + 6;
                            radUteAdn.addItem("Normal", "1", new Command() {
                                @Override
                                public void execute() {
                                    tbUteAdn.setVisible(false);
                                    cbUteAdn.setValue(true, true);
                                }
                            });
                            radUteAdn.addItem("Abnormal", "2", new Command() {
                                @Override
                                public void execute() {

                                    tbUteAdn.setVisible(true);
                                    cbUteAdn.setValue(true, true);
                                }
                            });
                            radUteAdn.setEnable(false);
                            tbUteAdn.setEnabled(false);
                            cbUteAdn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                                    if (cbUteAdn.getValue()) {
                                        radUteAdn.setEnable(true);
                                        tbUteAdn.setEnabled(true);
                                    } else {
                                        radUteAdn.setEnable(false);
                                        tbUteAdn.setEnabled(false);
                                    }
                                }
                            });
                            guTable.setWidget(r16, 0, cbUteAdn);
                            guTable.setWidget(r16, 1, radUteAdn);
                            guTable.setWidget(r16 + 1, 0, tbUteAdn);
                            guTable.getFlexCellFormatter().setColSpan(r16 + 1, 0, 2);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r16, 0,
                                    HasVerticalAlignment.ALIGN_TOP);
                            guTable.getFlexCellFormatter().setVerticalAlignment(r16, 1,
                                    HasVerticalAlignment.ALIGN_TOP);

                        }
                    });
                    guTable.setWidget(guRowCount, 0, lbGender);
                    guTable.setWidget(guRowCount, 1, radGender);
                    guTable.getFlexCellFormatter().setVerticalAlignment(guRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    guTable.getFlexCellFormatter().setVerticalAlignment(guRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    guTable.getFlexCellFormatter().setWidth(guRowCount, 0, labelWidth);
                    guTable.getFlexCellFormatter().setWidth(guRowCount, 1, radWidth);
                    guTable.getFlexCellFormatter().setVerticalAlignment(guRowCount, 2,
                            HasVerticalAlignment.ALIGN_TOP);
                    guRowCount++;
                    if (templateValuesMap.containsKey("pnotespegugender")) {
                        if (templateValuesMap.get("pnotespegugender").equals("Male")) {
                            radGender.setWidgetValue("1", true);
                            if (templateValuesMap.containsKey("pnotespegupenisstatus")) {
                                radPenis.setWidgetValue(templateValuesMap.get("pnotespegupenisstatus"), true);
                                tbPenis.setText(templateValuesMap.get("pnotespegupeniscmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotespegutestesstatus")) {
                                radTestes.setWidgetValue(templateValuesMap.get("pnotespegutestesstatus"), true);
                                tbTestes.setText(templateValuesMap.get("pnotespegutestescmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotespeguproststatus")) {
                                radProstate.setWidgetValue(templateValuesMap.get("pnotespeguproststatus"),
                                        true);
                                tbProstate.setText(templateValuesMap.get("pnotespeguprostcmnt"));
                            }
                        } else if (templateValuesMap.get("pnotespegugender").equals("Female")) {
                            radGender.setWidgetValue("2", true);
                            if (templateValuesMap.containsKey("pnotespeguextgenstatus")) {
                                radExtGen.setWidgetValue(templateValuesMap.get("pnotespeguextgenstatus"), true);
                                tbExtGen.setText(templateValuesMap.get("pnotespeguextgencmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotespegucervixstatus")) {
                                radCervix.setWidgetValue(templateValuesMap.get("pnotespegucervixstatus"), true);
                                tbCervix.setText(templateValuesMap.get("pnotespegucervixcmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotespeguutadnstatus")) {
                                radUteAdn.setWidgetValue(templateValuesMap.get("pnotespeguutadnstatus"), true);
                                tbUteAdn.setText(templateValuesMap.get("pnotespeguutadncmnt"));
                            }
                        }
                    } else if (templateValuesMap.containsKey("pnotestpegugender")) {
                        if (templateValuesMap.get("pnotestpegugender").equals("Male")) {
                            radGender.setWidgetValue("1", true);
                            if (templateValuesMap.containsKey("pnotestpegupenisstatus")) {
                                radPenis.setWidgetValue(templateValuesMap.get("pnotestpegupenisstatus"), true);
                                tbPenis.setText(templateValuesMap.get("pnotestpegupeniscmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotestpegutestesstatus")) {
                                radTestes.setWidgetValue(templateValuesMap.get("pnotestpegutestesstatus"),
                                        true);
                                tbTestes.setText(templateValuesMap.get("pnotestpegutestescmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotestpeguproststatus")) {
                                radProstate.setWidgetValue(templateValuesMap.get("pnotestpeguproststatus"),
                                        true);
                                tbProstate.setText(templateValuesMap.get("pnotestpeguprostcmnt"));
                            }
                        } else if (templateValuesMap.get("pnotestpegugender").equals("Female")) {
                            radGender.setWidgetValue("2", true);
                            if (templateValuesMap.containsKey("pnotestpeguextgenstatus")) {
                                radExtGen.setWidgetValue(templateValuesMap.get("pnotestpeguextgenstatus"),
                                        true);
                                tbExtGen.setText(templateValuesMap.get("pnotestpeguextgencmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotestpegucervixstatus")) {
                                radCervix.setWidgetValue(templateValuesMap.get("pnotestpegucervixstatus"),
                                        true);
                                tbCervix.setText(templateValuesMap.get("pnotestpegucervixcmnt"));
                            }
                            if (templateValuesMap.containsKey("pnotestpeguutadnstatus")) {
                                radUteAdn.setWidgetValue(templateValuesMap.get("pnotestpeguutadnstatus"), true);
                                tbUteAdn.setText(templateValuesMap.get("pnotestpeguutadncmnt"));
                            }
                        }
                    }
                }
                if ((guList != null && guList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (guList != null && guList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbGUFreeForm = new TextArea();
                    tbGUFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbGUFreeForm);
                    freeHp.setCellWidth(tbGUFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespegufreecmnt")) {
                        tbGUFreeForm.setText(templateValuesMap.get("pnotespegufreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpegufreecmnt")) {
                        tbGUFreeForm.setText(templateValuesMap.get("pnotestpegufreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbGUExBill = new CheckBox("Procedure");
                cbGUExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbGUExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespegu")) {
                    HashMap<String, String> m = billMap.get("pnotespegu");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespegu", biw);
                    cbGUExBill.setValue(true);

                }
                cbGUExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbGUExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbGUExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespegu", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespegu");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Lymphatics"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int lympRowCount = 0;
            Label lbLymphatics = new Label("Lymphatics");
            lbLymphatics.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbLymphatics);
            final FlexTable lymphaticsTable = new FlexTable();
            lymphaticsTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(lymphaticsTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int lymphaticsLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections")
                    && sectionsFieldMap.containsKey("Sections#Exam#Lymphatics"))
                lymphaticsLoopCountMax = sectionsFieldMap.get("Sections#Exam#Lymphatics").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Lymphatics"))
                lymphaticsLoopCountMax = 0;
            else
                lymphaticsLoopCountMax = 1;
            List<String> lymphaticsList = sectionsFieldMap.get("Sections#Exam#Lymphatics");
            for (int j = 0; j < lymphaticsLoopCountMax; j++) {
                if ((lymphaticsList != null && lymphaticsList.get(j).equals("Lymph nodes"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbLympNode = new CheckBox("Lymph nodes");
                    cbLympNode.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radLympNode = new CustomRadioButtonGroup("lymnds");
                    tbLympNode = new TextArea();
                    tbLympNode.setVisible(false);
                    tbLympNode.setWidth(textWidth);
                    radLympNode.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbLympNode.setVisible(false);
                            cbLympNode.setValue(true, true);
                        }
                    });
                    radLympNode.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbLympNode.setVisible(true);
                            cbLympNode.setValue(true, true);
                        }
                    });
                    radLympNode.setEnable(false);
                    tbLympNode.setEnabled(false);
                    cbLympNode.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbLympNode.getValue()) {
                                radLympNode.setEnable(true);
                                tbLympNode.setEnabled(true);
                            } else {
                                radLympNode.setEnable(false);
                                tbLympNode.setEnabled(false);
                            }
                        }
                    });
                    lymphaticsTable.setWidget(lympRowCount, 0, cbLympNode);
                    lymphaticsTable.setWidget(lympRowCount, 1, radLympNode);
                    lymphaticsTable.setWidget(lympRowCount + 1, 0, tbLympNode);
                    lymphaticsTable.getFlexCellFormatter().setColSpan(lympRowCount + 1, 0, 2);
                    lymphaticsTable.getFlexCellFormatter().setVerticalAlignment(lympRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    lymphaticsTable.getFlexCellFormatter().setVerticalAlignment(lympRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    lymphaticsTable.getFlexCellFormatter().setWidth(lympRowCount, 0, labelWidth);
                    lymphaticsTable.getFlexCellFormatter().setWidth(lympRowCount, 1, radWidth);
                    lympRowCount = lympRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespelympnodesstatus")) {
                        radLympNode.setWidgetValue(templateValuesMap.get("pnotespelympnodesstatus"), true);
                        tbLympNode.setText(templateValuesMap.get("pnotespelympnodescmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpelympnodesstatus")) {
                        radLympNode.setWidgetValue(templateValuesMap.get("pnotestpelympnodesstatus"), true);
                        tbLympNode.setText(templateValuesMap.get("pnotestpelympnodescmnt"));
                    }
                }
                if ((lymphaticsList != null && lymphaticsList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (lymphaticsList != null && lymphaticsList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbLympFreeForm = new TextArea();
                    tbLympFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbLympFreeForm);
                    freeHp.setCellWidth(tbLympFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespelympfreecmnt")) {
                        tbLympFreeForm.setText(templateValuesMap.get("pnotespelympfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpelympfreecmnt")) {
                        tbLympFreeForm.setText(templateValuesMap.get("pnotestpelympfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbLympExBill = new CheckBox("Procedure");
                cbLympExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbLympExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespelymph")) {
                    HashMap<String, String> m = billMap.get("pnotespelymph");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespelymph", biw);
                    cbLympExBill.setValue(true);

                }
                cbLympExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbLympExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbLympExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespelymph", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespelymph");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Skin"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int skinRowCount = 0;
            Label lbSkin = new Label("Skin");
            lbSkin.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbSkin);
            final FlexTable skinTable = new FlexTable();
            skinTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(skinTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int skinLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Skin"))
                skinLoopCountMax = sectionsFieldMap.get("Sections#Exam#Skin").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Skin"))
                skinLoopCountMax = 0;
            else
                skinLoopCountMax = 1;
            List<String> skinList = sectionsFieldMap.get("Sections#Exam#Skin");
            for (int j = 0; j < skinLoopCountMax; j++) {
                if ((skinList != null && skinList.get(j).equals("Skin & SQ tissue"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbSkinSQTissue = new CheckBox("Skin & SQ tissue (describe any rash)");
                    cbSkinSQTissue.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radSkinSQTissue = new CustomRadioButtonGroup("sksq");
                    tbSkinSQTissue = new TextArea();
                    tbSkinSQTissue.setVisible(false);
                    tbSkinSQTissue.setWidth(textWidth);
                    radSkinSQTissue.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbSkinSQTissue.setVisible(false);
                            cbSkinSQTissue.setValue(true, true);
                        }
                    });
                    radSkinSQTissue.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbSkinSQTissue.setVisible(true);
                            cbSkinSQTissue.setValue(true, true);
                        }
                    });
                    radSkinSQTissue.setEnable(false);
                    tbSkinSQTissue.setEnabled(false);
                    cbSkinSQTissue.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbSkinSQTissue.getValue()) {
                                radSkinSQTissue.setEnable(true);
                                tbSkinSQTissue.setEnabled(true);
                            } else {
                                radSkinSQTissue.setEnable(false);
                                tbSkinSQTissue.setEnabled(false);
                            }
                        }
                    });
                    skinTable.setWidget(skinRowCount, 0, cbSkinSQTissue);
                    skinTable.setWidget(skinRowCount, 1, radSkinSQTissue);
                    skinTable.setWidget(skinRowCount + 1, 0, tbSkinSQTissue);
                    skinTable.getFlexCellFormatter().setColSpan(skinRowCount + 1, 0, 2);
                    skinTable.getFlexCellFormatter().setVerticalAlignment(skinRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    skinTable.getFlexCellFormatter().setVerticalAlignment(skinRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    skinTable.getFlexCellFormatter().setWidth(skinRowCount, 0, labelWidth);
                    skinTable.getFlexCellFormatter().setWidth(skinRowCount, 1, radWidth);
                    skinRowCount = skinRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeskintissuestatus")) {
                        radSkinSQTissue.setWidgetValue(templateValuesMap.get("pnotespeskintissuestatus"), true);
                        tbSkinSQTissue.setText(templateValuesMap.get("pnotespeskintissuecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeskintissuestatus")) {
                        radSkinSQTissue.setWidgetValue(templateValuesMap.get("pnotestpeskintissuestatus"),
                                true);
                        tbSkinSQTissue.setText(templateValuesMap.get("pnotestpeskintissuecmnt"));
                    }
                }

                if ((skinList != null && skinList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (skinList != null && skinList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbSkinFreeForm = new TextArea();
                    tbSkinFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbSkinFreeForm);
                    freeHp.setCellWidth(tbSkinFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespeskinfreecmnt")) {
                        tbSkinFreeForm.setText(templateValuesMap.get("pnotespeskinfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeskinfreecmnt")) {
                        tbSkinFreeForm.setText(templateValuesMap.get("pnotestpeskinfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbSkinExBill = new CheckBox("Procedure");
                cbSkinExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbSkinExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespeskin")) {
                    HashMap<String, String> m = billMap.get("pnotespeskin");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespeskin", biw);
                    cbSkinExBill.setValue(true);

                }
                cbSkinExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbSkinExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbSkinExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespeskin", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespeskin");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("MS"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int msRowCount = 0;
            Label lbMS = new Label("MS");
            lbMS.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbMS);
            final FlexTable msTable = new FlexTable();
            msTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(msTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int msLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#MS"))
                msLoopCountMax = sectionsFieldMap.get("Sections#Exam#MS").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#MS"))
                msLoopCountMax = 0;
            else
                msLoopCountMax = 1;
            List<String> msList = sectionsFieldMap.get("Sections#Exam#MS");
            for (int j = 0; j < msLoopCountMax; j++) {
                if ((msList != null && msList.get(j).equals("Gait & station"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbGaitStat = new CheckBox("Gait & station");
                    cbGaitStat.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radGaitStat = new CustomRadioButtonGroup("gaitsec");
                    tbGaitStat = new TextArea();
                    tbGaitStat.setVisible(false);
                    tbGaitStat.setWidth(textWidth);
                    radGaitStat.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbGaitStat.setVisible(false);
                            cbGaitStat.setValue(true, true);
                        }
                    });
                    radGaitStat.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbGaitStat.setVisible(true);
                            cbGaitStat.setValue(true, true);
                        }
                    });
                    radGaitStat.setEnable(false);
                    tbGaitStat.setEnabled(false);
                    cbGaitStat.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbGaitStat.getValue()) {
                                radGaitStat.setEnable(true);
                                tbGaitStat.setEnabled(true);
                            } else {
                                radGaitStat.setEnable(false);
                                tbGaitStat.setEnabled(false);
                            }
                        }
                    });
                    msTable.setWidget(msRowCount, 0, cbGaitStat);
                    msTable.setWidget(msRowCount, 1, radGaitStat);
                    msTable.setWidget(msRowCount + 1, 0, tbGaitStat);
                    msTable.getFlexCellFormatter().setColSpan(msRowCount + 1, 0, 2);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 0, labelWidth);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 1, radWidth);
                    msRowCount = msRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespemsgaitststatus")) {
                        radGaitStat.setWidgetValue(templateValuesMap.get("pnotespemsgaitststatus"), true);
                        tbGaitStat.setText(templateValuesMap.get("pnotespemsgaitstcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsgaitststatus")) {
                        radGaitStat.setWidgetValue(templateValuesMap.get("pnotestpemsgaitststatus"), true);
                        tbGaitStat.setText(templateValuesMap.get("pnotestpemsgaitstcmnt"));
                    }
                }

                if ((msList != null && msList.get(j).equals("Digits_nails"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbDigitsNails = new CheckBox("Digits, nails");
                    cbDigitsNails.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radDigitsNails = new CustomRadioButtonGroup("dignails");
                    tbDigitsNails = new TextArea();
                    tbDigitsNails.setVisible(false);
                    tbDigitsNails.setWidth(textWidth);
                    radDigitsNails.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbDigitsNails.setVisible(false);
                            cbDigitsNails.setValue(true, true);
                        }
                    });
                    radDigitsNails.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbDigitsNails.setVisible(true);
                            cbDigitsNails.setValue(true, true);
                        }
                    });
                    radDigitsNails.setEnable(false);
                    tbDigitsNails.setEnabled(false);
                    cbDigitsNails.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbDigitsNails.getValue()) {
                                radDigitsNails.setEnable(true);
                                tbDigitsNails.setEnabled(true);
                            } else {
                                radDigitsNails.setEnable(false);
                                tbDigitsNails.setEnabled(false);
                            }
                        }
                    });
                    msTable.setWidget(msRowCount, 0, cbDigitsNails);
                    msTable.setWidget(msRowCount, 1, radDigitsNails);
                    msTable.setWidget(msRowCount + 1, 0, tbDigitsNails);
                    msTable.getFlexCellFormatter().setColSpan(msRowCount + 1, 0, 2);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 0, labelWidth);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 1, radWidth);
                    msRowCount = msRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespemsdignlsstatus")) {
                        radDigitsNails.setWidgetValue(templateValuesMap.get("pnotespemsdignlsstatus"), true);
                        tbDigitsNails.setText(templateValuesMap.get("pnotespemsdignlscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsdignlsstatus")) {
                        radDigitsNails.setWidgetValue(templateValuesMap.get("pnotestpemsdignlsstatus"), true);
                        tbDigitsNails.setText(templateValuesMap.get("pnotestpemsdignlscmnt"));
                    }
                }

                if ((msList != null && msList.get(j).equals("ROM_stability"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbRomStability = new CheckBox("ROM, stability");
                    cbRomStability.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radRomStability = new CustomRadioButtonGroup("romstab");
                    tbRomStability = new TextArea();
                    tbRomStability.setVisible(false);
                    tbRomStability.setWidth(textWidth);
                    radRomStability.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbRomStability.setVisible(false);
                            cbRomStability.setValue(true, true);
                        }
                    });
                    radRomStability.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbRomStability.setVisible(true);
                            cbRomStability.setValue(true, true);
                        }
                    });
                    radRomStability.setEnable(false);
                    tbRomStability.setEnabled(false);
                    cbRomStability.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbRomStability.getValue()) {
                                radRomStability.setEnable(true);
                                tbRomStability.setEnabled(true);
                            } else {
                                radRomStability.setEnable(false);
                                tbRomStability.setEnabled(false);
                            }
                        }
                    });
                    msTable.setWidget(msRowCount, 0, cbRomStability);
                    msTable.setWidget(msRowCount, 1, radRomStability);
                    msTable.setWidget(msRowCount + 1, 0, tbRomStability);
                    msTable.getFlexCellFormatter().setColSpan(msRowCount + 1, 0, 2);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 0, labelWidth);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 1, radWidth);
                    msRowCount = msRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespemsromstbstatus")) {
                        radRomStability.setWidgetValue(templateValuesMap.get("pnotespemsromstbstatus"), true);
                        tbRomStability.setText(templateValuesMap.get("pnotespemsromstbcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsromstbstatus")) {
                        radRomStability.setWidgetValue(templateValuesMap.get("pnotestpemsromstbstatus"), true);
                        tbRomStability.setText(templateValuesMap.get("pnotestpemsromstbcmnt"));
                    }
                }

                if ((msList != null && msList.get(j).equals("Joints_bones_muscles"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbJntBnsMusc = new CheckBox("Joints, bones, muscles");
                    cbJntBnsMusc.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radJntBnsMusc = new CustomRadioButtonGroup("jbm");
                    tbJntBnsMusc = new TextArea();
                    tbJntBnsMusc.setVisible(false);
                    tbJntBnsMusc.setWidth(textWidth);
                    radJntBnsMusc.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbJntBnsMusc.setVisible(false);
                            cbJntBnsMusc.setValue(true, true);
                        }
                    });
                    radJntBnsMusc.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbJntBnsMusc.setVisible(true);
                            cbJntBnsMusc.setValue(true, true);
                        }
                    });
                    radJntBnsMusc.setEnable(false);
                    tbJntBnsMusc.setEnabled(false);
                    cbJntBnsMusc.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbJntBnsMusc.getValue()) {
                                radJntBnsMusc.setEnable(true);
                                tbJntBnsMusc.setEnabled(true);
                            } else {
                                radJntBnsMusc.setEnable(false);
                                tbJntBnsMusc.setEnabled(false);
                            }
                        }
                    });
                    msTable.setWidget(msRowCount, 0, cbJntBnsMusc);
                    msTable.setWidget(msRowCount, 1, radJntBnsMusc);
                    msTable.setWidget(msRowCount + 1, 0, tbJntBnsMusc);
                    msTable.getFlexCellFormatter().setColSpan(msRowCount + 1, 0, 2);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 0, labelWidth);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 1, radWidth);
                    msRowCount = msRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespemsjntbnsmusstatus")) {
                        radJntBnsMusc.setWidgetValue(templateValuesMap.get("pnotespemsjntbnsmusstatus"), true);
                        tbJntBnsMusc.setText(templateValuesMap.get("pnotespemsjntbnsmuscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsjntbnsmusstatus")) {
                        radJntBnsMusc.setWidgetValue(templateValuesMap.get("pnotestpemsjntbnsmusstatus"), true);
                        tbJntBnsMusc.setText(templateValuesMap.get("pnotestpemsjntbnsmuscmnt"));
                    }
                }

                if ((msList != null && msList.get(j).equals("Muscle strength & tone"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbMuscStrg = new CheckBox("Muscle strength & tone");
                    cbMuscStrg.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radMuscStrg = new CustomRadioButtonGroup("musstrtone");
                    tbMuscStrg = new TextArea();
                    tbMuscStrg.setVisible(false);
                    tbMuscStrg.setWidth(textWidth);
                    radMuscStrg.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbMuscStrg.setVisible(false);
                            cbMuscStrg.setValue(true, true);
                        }
                    });
                    radMuscStrg.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbMuscStrg.setVisible(true);
                            cbMuscStrg.setValue(true, true);
                        }
                    });
                    radMuscStrg.setEnable(false);
                    tbMuscStrg.setEnabled(false);
                    cbMuscStrg.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbMuscStrg.getValue()) {
                                radMuscStrg.setEnable(true);
                                tbMuscStrg.setEnabled(true);
                            } else {
                                radMuscStrg.setEnable(false);
                                tbMuscStrg.setEnabled(false);
                            }
                        }
                    });
                    msTable.setWidget(msRowCount, 0, cbMuscStrg);
                    msTable.setWidget(msRowCount, 1, radMuscStrg);
                    msTable.setWidget(msRowCount + 1, 0, tbMuscStrg);
                    msTable.getFlexCellFormatter().setColSpan(msRowCount + 1, 0, 2);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setVerticalAlignment(msRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 0, labelWidth);
                    msTable.getFlexCellFormatter().setWidth(msRowCount, 1, radWidth);
                    msRowCount = msRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespemsmusstrtnstatus")) {
                        radMuscStrg.setWidgetValue(templateValuesMap.get("pnotespemsmusstrtnstatus"), true);
                        tbMuscStrg.setText(templateValuesMap.get("pnotespemsmusstrtncmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsmusstrtnstatus")) {
                        radMuscStrg.setWidgetValue(templateValuesMap.get("pnotestpemsmusstrtnstatus"), true);
                        tbMuscStrg.setText(templateValuesMap.get("pnotestpemsmusstrtncmnt"));
                    }
                }

                if ((msList != null && msList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (msList != null && msList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbMSFreeForm = new TextArea();
                    tbMSFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbMSFreeForm);
                    freeHp.setCellWidth(tbMSFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespemsfreecmnt")) {
                        tbMSFreeForm.setText(templateValuesMap.get("pnotespemsfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpemsfreecmnt")) {
                        tbMSFreeForm.setText(templateValuesMap.get("pnotestpemsfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbMSExBill = new CheckBox("Procedure");
                cbMSExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbMSExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespems")) {
                    HashMap<String, String> m = billMap.get("pnotespems");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespems", biw);
                    cbMSExBill.setValue(true);

                }
                cbMSExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbMSExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbMSExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespems", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespems");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Neuro"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int neuroRowCount = 0;
            Label lbNeuro = new Label("Neuro");
            lbNeuro.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbNeuro);
            final FlexTable neuroTable = new FlexTable();
            neuroTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(neuroTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);
            int neuroLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Neuro"))
                neuroLoopCountMax = sectionsFieldMap.get("Sections#Exam#Neuro").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Neuro"))
                neuroLoopCountMax = 0;
            else
                neuroLoopCountMax = 1;
            List<String> neuroList = sectionsFieldMap.get("Sections#Exam#Neuro");
            for (int j = 0; j < neuroLoopCountMax; j++) {
                if ((neuroList != null && neuroList.get(j).equals("Cranial nerves (note deficits)"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbCranNerves = new CheckBox("Cranial nerves (note deficits)");
                    cbCranNerves.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radCranNerves = new CustomRadioButtonGroup("cranner");
                    tbCranNerves = new TextArea();
                    tbCranNerves.setVisible(false);
                    tbCranNerves.setWidth(textWidth);
                    radCranNerves.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbCranNerves.setVisible(false);
                            cbCranNerves.setValue(true, true);
                        }
                    });
                    radCranNerves.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbCranNerves.setVisible(true);
                            cbCranNerves.setValue(true, true);
                        }
                    });
                    radCranNerves.setEnable(false);
                    tbCranNerves.setEnabled(false);
                    cbCranNerves.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbCranNerves.getValue()) {
                                radCranNerves.setEnable(true);
                                tbCranNerves.setEnabled(true);
                            } else {
                                radCranNerves.setEnable(false);
                                tbCranNerves.setEnabled(false);
                            }
                        }
                    });
                    neuroTable.setWidget(neuroRowCount, 0, cbCranNerves);
                    neuroTable.setWidget(neuroRowCount, 1, radCranNerves);
                    neuroTable.setWidget(neuroRowCount + 1, 0, tbCranNerves);
                    neuroTable.getFlexCellFormatter().setColSpan(neuroRowCount + 1, 0, 2);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 0, labelWidth);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 1, radWidth);
                    neuroRowCount = neuroRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeneurocrnervstatus")) {
                        radCranNerves.setWidgetValue(templateValuesMap.get("pnotespeneurocrnervstatus"), true);
                        tbCranNerves.setText(templateValuesMap.get("pnotespeneurocrnervcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneurocrnervstatus")) {
                        radCranNerves.setWidgetValue(templateValuesMap.get("pnotestpeneurocrnervstatus"), true);
                        tbCranNerves.setText(templateValuesMap.get("pnotestpeneurocrnervcmnt"));
                    }
                }

                if ((neuroList != null && neuroList.get(j).equals("DTRs"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbDTRs = new CheckBox("DTRs");
                    cbDTRs.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radDTRs = new CustomRadioButtonGroup("dtrs");
                    tbDTRs = new TextArea();
                    tbDTRs.setVisible(false);
                    tbDTRs.setWidth(textWidth);
                    radDTRs.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbDTRs.setVisible(false);
                            cbDTRs.setValue(true, true);
                        }
                    });
                    radDTRs.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbDTRs.setVisible(true);
                            cbDTRs.setValue(true, true);
                        }
                    });
                    radDTRs.setEnable(false);
                    tbDTRs.setEnabled(false);
                    cbDTRs.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbDTRs.getValue()) {
                                radDTRs.setEnable(true);
                                tbDTRs.setEnabled(true);
                            } else {
                                radDTRs.setEnable(false);
                                tbDTRs.setEnabled(false);
                            }
                        }
                    });
                    neuroTable.setWidget(neuroRowCount, 0, cbDTRs);
                    neuroTable.setWidget(neuroRowCount, 1, radDTRs);
                    neuroTable.setWidget(neuroRowCount + 1, 0, tbDTRs);
                    neuroTable.getFlexCellFormatter().setColSpan(neuroRowCount + 1, 0, 2);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 0, labelWidth);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 1, radWidth);
                    neuroRowCount = neuroRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeneurodtrsstatus")) {
                        radDTRs.setWidgetValue(templateValuesMap.get("pnotespeneurodtrsstatus"), true);
                        tbDTRs.setText(templateValuesMap.get("pnotespeneurodtrscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneurodtrsstatus")) {
                        radDTRs.setWidgetValue(templateValuesMap.get("pnotestpeneurodtrsstatus"), true);
                        tbDTRs.setText(templateValuesMap.get("pnotestpeneurodtrscmnt"));
                    }
                }

                if ((neuroList != null && neuroList.get(j).equals("Motor"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbMotor = new CheckBox("Motor");
                    cbMotor.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radMotor = new CustomRadioButtonGroup("motors");
                    tbMotor = new TextArea();
                    tbMotor.setVisible(false);
                    tbMotor.setWidth(textWidth);
                    radMotor.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbMotor.setVisible(false);
                            cbMotor.setValue(true, true);
                        }
                    });
                    radMotor.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {
                            tbMotor.setVisible(true);
                            cbMotor.setValue(true, true);
                        }
                    });
                    radMotor.setEnable(false);
                    tbMotor.setEnabled(false);
                    cbMotor.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbMotor.getValue()) {
                                radMotor.setEnable(true);
                                tbMotor.setEnabled(true);
                            } else {
                                radMotor.setEnable(false);
                                tbMotor.setEnabled(false);
                            }
                        }
                    });
                    neuroTable.setWidget(neuroRowCount, 0, cbMotor);
                    neuroTable.setWidget(neuroRowCount, 1, radMotor);
                    neuroTable.setWidget(neuroRowCount + 1, 0, tbMotor);
                    neuroTable.getFlexCellFormatter().setColSpan(neuroRowCount + 1, 0, 2);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 0, labelWidth);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 1, radWidth);
                    neuroRowCount = neuroRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeneuromotorstatus")) {
                        radMotor.setWidgetValue(templateValuesMap.get("pnotespeneuromotorstatus"), true);
                        tbMotor.setText(templateValuesMap.get("pnotespeneuromotorcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneuromotorstatus")) {
                        radMotor.setWidgetValue(templateValuesMap.get("pnotestpeneuromotorstatus"), true);
                        tbMotor.setText(templateValuesMap.get("pnotestpeneuromotorcmnt"));
                    }
                }

                if ((neuroList != null && neuroList.get(j).equals("Sensation"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbSensation = new CheckBox("Sensation");
                    cbSensation.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radSensation = new CustomRadioButtonGroup("sensation");
                    tbSensation = new TextArea();
                    tbSensation.setVisible(false);
                    tbSensation.setWidth(textWidth);
                    radSensation.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbSensation.setVisible(false);
                            cbSensation.setValue(true, true);
                        }
                    });
                    radSensation.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbSensation.setVisible(true);
                            cbSensation.setValue(true, true);
                        }
                    });
                    radSensation.setEnable(false);
                    tbSensation.setEnabled(false);
                    cbSensation.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbSensation.getValue()) {
                                radSensation.setEnable(true);
                                tbSensation.setEnabled(true);
                            } else {
                                radSensation.setEnable(false);
                                tbSensation.setEnabled(false);
                            }
                        }
                    });
                    neuroTable.setWidget(neuroRowCount, 0, cbSensation);
                    neuroTable.setWidget(neuroRowCount, 1, radSensation);
                    neuroTable.setWidget(neuroRowCount + 1, 0, tbSensation);
                    neuroTable.getFlexCellFormatter().setColSpan(neuroRowCount + 1, 0, 2);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setVerticalAlignment(neuroRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 0, labelWidth);
                    neuroTable.getFlexCellFormatter().setWidth(neuroRowCount, 1, radWidth);
                    neuroRowCount = neuroRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespeneurosnststatus")) {
                        radSensation.setWidgetValue(templateValuesMap.get("pnotespeneurosnststatus"), true);
                        tbSensation.setText(templateValuesMap.get("pnotespeneurosnstcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneurosnststatus")) {
                        radSensation.setWidgetValue(templateValuesMap.get("pnotestpeneurosnststatus"), true);
                        tbSensation.setText(templateValuesMap.get("pnotestpeneurosnstcmnt"));
                    }
                }
                if ((neuroList != null && neuroList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (neuroList != null && neuroList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbNeuroFreeForm = new TextArea();
                    tbNeuroFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbNeuroFreeForm);
                    freeHp.setCellWidth(tbNeuroFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespeneurofreecmnt")) {
                        tbNeuroFreeForm.setText(templateValuesMap.get("pnotespeneurofreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpeneurofreecmnt")) {
                        tbNeuroFreeForm.setText(templateValuesMap.get("pnotestpeneurofreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbNeuroExBill = new CheckBox("Procedure");
                cbNeuroExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbNeuroExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespeneuro")) {
                    HashMap<String, String> m = billMap.get("pnotespeneuro");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespeneuro", biw);
                    cbNeuroExBill.setValue(true);

                }
                cbNeuroExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbNeuroExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbNeuroExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespeneuro", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespeneuro");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }

        if ((secList != null && secList.get(i).equals("Psych"))
                || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
            int psychRowCount = 0;
            Label lbPsych = new Label("Psych");
            lbPsych.setStyleName(AppConstants.STYLE_LABEL_HEADER_MEDIUM);
            examPanel.add(lbPsych);
            final FlexTable psychTable = new FlexTable();
            psychTable.getElement().getStyle().setMarginLeft(30, Unit.PX);
            HorizontalPanel hp = new HorizontalPanel();
            hp.setSpacing(10);
            VerticalPanel rightPanel = new VerticalPanel();
            rightPanel.setWidth("100%");
            rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
            rightPanel.setSpacing(5);
            hp.setWidth("100%");
            hp.add(psychTable);
            hp.add(rightPanel);
            hp.setCellWidth(rightPanel, "60%");
            examPanel.add(hp);

            int psychLoopCountMax = 0;
            if (sectionsFieldMap.containsKey("Sections") && sectionsFieldMap.containsKey("Sections#Exam#Psych"))
                psychLoopCountMax = sectionsFieldMap.get("Sections#Exam#Psych").size();
            else if (sectionsFieldMap.containsKey("Sections")
                    && !sectionsFieldMap.containsKey("Sections#Exam#Psych"))
                psychLoopCountMax = 0;
            else
                psychLoopCountMax = 1;
            List<String> psychList = sectionsFieldMap.get("Sections#Exam#Psych");
            for (int j = 0; j < psychLoopCountMax; j++) {
                if ((psychList != null && psychList.get(j).equals("Judgment & insight"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbJudIns = new CheckBox("Judgment & insight");
                    cbJudIns.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radJudIns = new CustomRadioButtonGroup("judins");
                    tbJudIns = new TextArea();
                    tbJudIns.setVisible(false);
                    tbJudIns.setWidth(textWidth);
                    radJudIns.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbJudIns.setVisible(false);
                            cbJudIns.setValue(true, true);
                        }
                    });
                    radJudIns.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbJudIns.setVisible(true);
                            cbJudIns.setValue(true, true);
                        }
                    });
                    radJudIns.setEnable(false);
                    tbJudIns.setEnabled(false);
                    cbJudIns.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbJudIns.getValue()) {
                                radJudIns.setEnable(true);
                                tbJudIns.setEnabled(true);
                            } else {
                                radJudIns.setEnable(false);
                                tbJudIns.setEnabled(false);
                            }
                        }
                    });
                    psychTable.setWidget(psychRowCount, 0, cbJudIns);
                    psychTable.setWidget(psychRowCount, 1, radJudIns);
                    psychTable.setWidget(psychRowCount + 1, 0, tbJudIns);
                    psychTable.getFlexCellFormatter().setColSpan(psychRowCount + 1, 0, 2);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 0, labelWidth);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 1, radWidth);
                    psychRowCount = psychRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespepsychjudinsstatus")) {
                        radJudIns.setWidgetValue(templateValuesMap.get("pnotespepsychjudinsstatus"), true);
                        tbJudIns.setText(templateValuesMap.get("pnotespepsychjudinscmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpepsychjudinsstatus")) {
                        radJudIns.setWidgetValue(templateValuesMap.get("pnotestpepsychjudinsstatus"), true);
                        tbJudIns.setText(templateValuesMap.get("pnotestpepsychjudinscmnt"));
                    }
                }

                if ((psychList != null && psychList.get(j).equals("Mood & affect"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbMoodEffect = new CheckBox("Mood & affect");
                    cbMoodEffect.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radMoodEffect = new CustomRadioButtonGroup("moodeff");
                    tbMoodEffect = new TextArea();
                    tbMoodEffect.setVisible(false);
                    tbMoodEffect.setWidth(textWidth);
                    radMoodEffect.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbMoodEffect.setVisible(false);
                            cbMoodEffect.setValue(true, true);
                        }
                    });
                    radMoodEffect.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbMoodEffect.setVisible(true);
                            cbMoodEffect.setValue(true, true);
                        }
                    });
                    radMoodEffect.setEnable(false);
                    tbMoodEffect.setEnabled(false);
                    cbMoodEffect.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbMoodEffect.getValue()) {
                                radMoodEffect.setEnable(true);
                                tbMoodEffect.setEnabled(true);
                            } else {
                                radMoodEffect.setEnable(false);
                                tbMoodEffect.setEnabled(false);
                            }
                        }
                    });
                    psychTable.setWidget(psychRowCount, 0, cbMoodEffect);
                    psychTable.setWidget(psychRowCount, 1, radMoodEffect);
                    psychTable.setWidget(psychRowCount + 1, 0, tbMoodEffect);
                    psychTable.getFlexCellFormatter().setColSpan(psychRowCount + 1, 0, 2);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 0, labelWidth);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 1, radWidth);
                    psychRowCount = psychRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespepsychmoodeffstatus")) {
                        radMoodEffect.setWidgetValue(templateValuesMap.get("pnotespepsychmoodeffstatus"), true);
                        tbMoodEffect.setText(templateValuesMap.get("pnotespepsychmoodeffcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpepsychmoodeffstatus")) {
                        radMoodEffect.setWidgetValue(templateValuesMap.get("pnotestpepsychmoodeffstatus"),
                                true);
                        tbMoodEffect.setText(templateValuesMap.get("pnotestpepsychmoodeffcmnt"));
                    }
                }

                if ((psychList != null && psychList.get(j).equals("Oriented to time_place_person"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbOrTimePlcPers = new CheckBox("Oriented to time, place, person");
                    cbOrTimePlcPers.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radOrTimePlcPers = new CustomRadioButtonGroup("ortpp");
                    tbOrTimePlcPers = new TextArea();
                    tbOrTimePlcPers.setVisible(false);
                    tbOrTimePlcPers.setWidth(textWidth);
                    radOrTimePlcPers.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbOrTimePlcPers.setVisible(false);
                            cbOrTimePlcPers.setValue(true, true);
                        }
                    });
                    radOrTimePlcPers.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbOrTimePlcPers.setVisible(true);
                            cbOrTimePlcPers.setValue(true, true);

                        }
                    });
                    radOrTimePlcPers.setEnable(false);
                    tbOrTimePlcPers.setEnabled(false);
                    cbOrTimePlcPers.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbOrTimePlcPers.getValue()) {
                                radOrTimePlcPers.setEnable(true);
                                tbOrTimePlcPers.setEnabled(true);
                            } else {
                                radOrTimePlcPers.setEnable(false);
                                tbOrTimePlcPers.setEnabled(false);
                            }
                        }
                    });
                    psychTable.setWidget(psychRowCount, 0, cbOrTimePlcPers);
                    psychTable.setWidget(psychRowCount, 1, radOrTimePlcPers);
                    psychTable.setWidget(psychRowCount + 1, 0, tbOrTimePlcPers);
                    psychTable.getFlexCellFormatter().setColSpan(psychRowCount + 1, 0, 2);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 0, labelWidth);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 1, radWidth);
                    psychRowCount = psychRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespepsychorntppstatus")) {
                        radOrTimePlcPers.setWidgetValue(templateValuesMap.get("pnotespepsychorntppstatus"),
                                true);
                        tbOrTimePlcPers.setText(templateValuesMap.get("pnotespepsychorntppcmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpepsychorntppstatus")) {
                        radOrTimePlcPers.setWidgetValue(templateValuesMap.get("pnotestpepsychorntppstatus"),
                                true);
                        tbOrTimePlcPers.setText(templateValuesMap.get("pnotestpepsychorntppcmnt"));
                    }
                }

                if ((psychList != null && psychList.get(j).equals("Memory"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    cbMemory = new CheckBox("Memory");
                    cbMemory.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                    radMemory = new CustomRadioButtonGroup("memory");
                    tbMemory = new TextArea();
                    tbMemory.setVisible(false);
                    tbMemory.setWidth(textWidth);
                    radMemory.addItem("Normal", "1", new Command() {
                        @Override
                        public void execute() {
                            tbMemory.setVisible(false);
                            cbMemory.setValue(true, true);
                        }
                    });
                    radMemory.addItem("Abnormal", "2", new Command() {
                        @Override
                        public void execute() {

                            tbMemory.setVisible(true);
                            cbMemory.setValue(true, true);
                        }
                    });
                    radMemory.setEnable(false);
                    tbMemory.setEnabled(false);
                    cbMemory.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
                            if (cbMemory.getValue()) {
                                radMemory.setEnable(true);
                                tbMemory.setEnabled(true);
                            } else {
                                radMemory.setEnable(false);
                                tbMemory.setEnabled(false);
                            }
                        }
                    });
                    psychTable.setWidget(psychRowCount, 0, cbMemory);
                    psychTable.setWidget(psychRowCount, 1, radMemory);
                    psychTable.setWidget(psychRowCount + 1, 0, tbMemory);
                    psychTable.getFlexCellFormatter().setColSpan(psychRowCount + 1, 0, 2);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 0,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setVerticalAlignment(psychRowCount, 1,
                            HasVerticalAlignment.ALIGN_TOP);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 0, labelWidth);
                    psychTable.getFlexCellFormatter().setWidth(psychRowCount, 1, radWidth);
                    psychRowCount = psychRowCount + 2;
                    if (templateValuesMap.containsKey("pnotespepsychmemorystatus")) {
                        radMemory.setWidgetValue(templateValuesMap.get("pnotespepsychmemorystatus"), true);
                        tbMemory.setText(templateValuesMap.get("pnotespepsychmemorycmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpepsychmemorystatus")) {
                        radMemory.setWidgetValue(templateValuesMap.get("pnotestpepsychmemorystatus"), true);
                        tbMemory.setText(templateValuesMap.get("pnotestpepsychmemorycmnt"));
                    }
                }
                if ((psychList != null && psychList.get(j).equals("Free Form Entry"))
                        || (formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES && currTemplate.equals(""))) {
                    if (psychList != null && psychList.size() == 1)
                        hp.setCellWidth(rightPanel, "100%");
                    Label lbfreeform = new Label("Free Form Entry");
                    lbfreeform.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);

                    tbPsychFreeForm = new TextArea();
                    tbPsychFreeForm.setWidth(textWidth);
                    HorizontalPanel freeHp = new HorizontalPanel();
                    freeHp.setWidth("80%");
                    freeHp.setSpacing(5);
                    freeHp.add(lbfreeform);
                    freeHp.add(tbPsychFreeForm);
                    freeHp.setCellWidth(tbPsychFreeForm, "80%");
                    rightPanel.add(freeHp);

                    if (templateValuesMap.containsKey("pnotespepsychfreecmnt")) {
                        tbPsychFreeForm.setText(templateValuesMap.get("pnotespepsychfreecmnt"));
                    } else if (templateValuesMap.containsKey("pnotestpepsychfreecmnt")) {
                        tbPsychFreeForm.setText(templateValuesMap.get("pnotestpepsychfreecmnt"));
                    }
                }
            }
            if (formtype == EncounterFormType.TEMPLATE_VALUES
                    || formtype == EncounterFormType.ENCOUNTER_NOTE_VALUES) {
                VerticalPanel billPanel = new VerticalPanel();
                billPanel.setSpacing(2);
                cbPsychExBill = new CheckBox("Procedure");
                cbPsychExBill.setStyleName(AppConstants.STYLE_LABEL_NORMAL_BOLD);
                final BillInfoWidget biw = new BillInfoWidget();
                billPanel.add(cbPsychExBill);
                billPanel.add(biw);
                rightPanel.add(billPanel);
                biw.setVisible(false);
                if (isBillables && billMap.containsKey("pnotespepsych")) {
                    HashMap<String, String> m = billMap.get("pnotespepsych");
                    biw.setVisible(true);
                    biw.setProceduralCode(new Integer(m.get("proccode")));
                    biw.setDiagnosisCode(new Integer(m.get("diagcode")));
                    billingFieldsWidgetsMap.put("pnotespepsych", biw);
                    cbPsychExBill.setValue(true);

                }
                cbPsychExBill.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent arg0) {
                        if (cbPsychExBill.getValue()) {
                            if (maxbillables == billingFieldsWidgetsMap.size()) {
                                Window.alert("Only " + maxbillables + " procedures can be created...");
                                cbPsychExBill.setValue(false);
                            } else {
                                billingFieldsWidgetsMap.put("pnotespepsych", biw);
                                biw.setVisible(true);
                            }
                        } else {
                            billingFieldsWidgetsMap.remove("pnotespepsych");
                            biw.setVisible(false);
                        }
                    }
                });
            }
        }
    }
    examTable.getFlexCellFormatter().setWidth(0, 0, "155px");
    examPanel.add(examTable);
}