public void buildTabs(final WebMarkupContainer arkContextMarkup) {
    ArkModule arkModule =
        iArkCommonService.getArkModuleByName(au.org.theark.core.Constants.ARK_MODULE_PHENOTYPIC);
    List<ArkFunction> arkFunctionList = iArkCommonService.getModuleFunction(arkModule);
    for (final ArkFunction menuArkFunction : arkFunctionList) {
      AbstractTab tab =
          new AbstractTab(new StringResourceModel(menuArkFunction.getResourceKey(), this, null)) {
            @Override
            public Panel getPanel(final String panelId) {
              return panelToReturn(menuArkFunction, panelId);
            }
          };
      moduleSubTabsList.add(tab);
    }

    ArkAjaxTabbedPanel moduleTabbedPanel =
        new ArkAjaxTabbedPanel(Constants.PHENOTYPIC_SUBMENU, moduleSubTabsList);
    add(moduleTabbedPanel);
  }
  @SuppressWarnings({"serial", "unchecked"})
  public void buildTabs() {

    List<ITab> moduleSubTabsList = new ArrayList<ITab>();

    ArkModule arkModule = iArkCommonService.getArkModuleByName(Constants.ARK_MODULE_SUBJECT);
    List<ArkFunction> arkFunctionList =
        iArkCommonService.getModuleFunction(
            arkModule); // Gets a list of ArkFunctions for the given Module

    for (final ArkFunction menuArkFunction : arkFunctionList) {

      moduleSubTabsList.add(
          new AbstractTab(new StringResourceModel(menuArkFunction.getResourceKey(), this, null)) {
            @Override
            public Panel getPanel(String panelId) {
              Panel panelToReturn = null; // Set
              if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn =
                    new SubjectContainerPanel(
                        panelId, arkContextMarkup, null, null); // Note the constructor
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHONE)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new PhoneContainerPanel(panelId);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_ADDRESS)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new AddressContainerPanel(panelId);
              }
              // Add contact panel
              else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_CONTACT)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new ContactContainerPanel(panelId);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_CONSENT)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new ConsentContainerPanel(panelId);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_ATTACHMENT)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new AttachmentsContainerPanel(panelId);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY_STUDY_DATA_UPLOAD)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new SubjectUploadContainerPanel(panelId, menuArkFunction);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CORRESPONDENCE)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new CorrespondenceContainerPanel(panelId);
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                // useCustomFieldDisplay = true
                panelToReturn =
                    new CustomFieldContainerPanel(
                        panelId,
                        true,
                        iArkCommonService.getArkFunctionByName(
                            au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD));
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_DATA)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn = new SubjectCustomDataContainerPanel(panelId).initialisePanel();
              } else if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants
                          .FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD_UPLOAD)) {
                processAuthorizationCache(
                    au.org.theark.core.Constants.ARK_MODULE_SUBJECT, menuArkFunction);
                panelToReturn =
                    new CustomFieldUploadContainerPanel(
                        panelId,
                        iArkCommonService.getArkFunctionByName(
                            au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT));
              }
              return panelToReturn;
            }

            @Override
            public boolean isVisible() {
              // Subject Upload only visible to parent studies
              if (menuArkFunction
                  .getName()
                  .equalsIgnoreCase(
                      au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY_STUDY_DATA_UPLOAD)) {
                return (!childStudy);
              }
              return true;
            }
          });
    }

    ArkAjaxTabbedPanel moduleTabbedPanel =
        new ArkAjaxTabbedPanel(Constants.MENU_SUBJECT_SUBMENU, moduleSubTabsList);
    add(moduleTabbedPanel);
  }