diff --git a/api/src/main/java/org/openmrs/module/teammodule/TeamMember.java b/api/src/main/java/org/openmrs/module/teammodule/TeamMember.java index e54c402..4625ca2 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/TeamMember.java +++ b/api/src/main/java/org/openmrs/module/teammodule/TeamMember.java @@ -33,17 +33,13 @@ public class TeamMember extends BaseOpenmrsData implements Serializable { private Date leaveDate; - private Set location = new HashSet(); + private Set locations = new HashSet(); private Set patients = new HashSet(); -// private Set subTeams = new HashSet(0); - private TeamRole teamRole; - - private String provider; - - private boolean isDataProvider; + + private Boolean isDataProvider; public TeamMember() { } @@ -89,12 +85,12 @@ public void setLeaveDate(Date leaveDate) { this.leaveDate = leaveDate; } - public Set getLocation() { - return location; + public Set getLocations() { + return locations; } - public void setLocation(Set location) { - this.location = location; + public void setLocations(Set locations) { + this.locations = locations; } public Set getPatients() { @@ -131,19 +127,11 @@ public void setTeamRole(TeamRole teamRole) { this.teamRole = teamRole; } - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - public boolean getIsDataProvider() { + public Boolean getIsDataProvider() { return isDataProvider; } - public void setIsDataProvider(boolean isDataProvider) { + public void setIsDataProvider(Boolean isDataProvider) { this.isDataProvider = isDataProvider; } } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/TeamMemberService.java b/api/src/main/java/org/openmrs/module/teammodule/api/TeamMemberService.java index 7415961..876da85 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/TeamMemberService.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/TeamMemberService.java @@ -26,10 +26,8 @@ public interface TeamMemberService extends OpenmrsService { public List getTeamMemberByPersonId(Integer personId); - public List getAllTeamMember(Integer id, boolean voided, Integer offset, Integer pageSize); - - public List getAllTeamMember( boolean voided, Integer offset, Integer pageSize); - + public List getAllTeamMember(Integer id, Boolean voided, Integer offset, Integer pageSize); + public void saveTeamMember(TeamMember teamMember); public void purgeTeamMember(TeamMember teamMember); diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleLogService.java b/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleLogService.java index fb31a19..343495d 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleLogService.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleLogService.java @@ -17,7 +17,9 @@ public interface TeamRoleLogService extends OpenmrsService { public void purgeTeamRoleLog(TeamRoleLog teamRoleLog); - public List searchTeamRoleLog(Integer teamRoleId,Integer offset, Integer pageSize); + public List searchTeamRoleLog(String teamRoleId,Integer offset, Integer pageSize); public TeamRoleLog getTeamRoleLog(String uuid); + + public List searchTeamRoleLog(Integer teamRoleId,Integer offset, Integer pageSize); } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleService.java b/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleService.java index 418fae9..6718d60 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleService.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/TeamRoleService.java @@ -3,6 +3,7 @@ import java.util.List; import org.openmrs.api.OpenmrsService; +import org.openmrs.module.teammodule.TeamMember; import org.openmrs.module.teammodule.TeamRole; import org.springframework.transaction.annotation.Transactional; @@ -19,7 +20,9 @@ public interface TeamRoleService extends OpenmrsService { public List searchTeamRoleByRole(String role); - public TeamRole getTeamRoleByUuid(String uuid); - + public TeamRole getTeamRoleByUuid(String uuid); + + public List getSubTeamRoles(TeamMember teamMember); + public List searchTeamRoleReportBy(int id); } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamMemberDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamMemberDAO.java index 99d2630..f2a181c 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamMemberDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamMemberDAO.java @@ -23,9 +23,7 @@ public interface TeamMemberDAO { public List getTeamMemberByPersonId(Integer personId); - public List getAllTeamMember(Integer id, boolean voided, Integer offset, Integer pageSize); - - public List getAllTeamMember( boolean voided, Integer offset, Integer pageSize); + public List getAllTeamMember(Integer id, Boolean voided, Integer offset, Integer pageSize); public void saveTeamMember(TeamMember teamMember); diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleDAO.java index 872b0ee..6f259bc 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleDAO.java @@ -2,6 +2,7 @@ import java.util.List; +import org.openmrs.module.teammodule.TeamMember; import org.openmrs.module.teammodule.TeamRole; public interface TeamRoleDAO { @@ -18,5 +19,7 @@ public interface TeamRoleDAO { public TeamRole getTeamRoleByUuid(String uuid); + public List getSubTeamRoles(TeamMember teamMember); + public List searchTeamRoleReportBy(int id); } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleLogDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleLogDAO.java index 6020307..0e53730 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleLogDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/TeamRoleLogDAO.java @@ -14,7 +14,9 @@ public interface TeamRoleLogDAO { public void purgeTeamRoleLog(TeamRoleLog teamRoleLog); - public List searchTeamRoleLog(Integer teamRole, Integer offset, Integer pageSize); + public List searchTeamRoleLog(String teamRole, Integer offset, Integer pageSize); public TeamRoleLog getTeamRoleLog(String uuid); + + public List searchTeamRoleLog(Integer teamRoleId, Integer offset, Integer pageSize); } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamMemberDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamMemberDAO.java index c01e11e..6888d26 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamMemberDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamMemberDAO.java @@ -59,8 +59,7 @@ public List getTeamMemberByPersonId(Integer personId) { } @Override - public List getAllTeamMember(Integer id, boolean voided, Integer offset, Integer pageSize) { - + public List getAllTeamMember(Integer id, Boolean voided, Integer offset, Integer pageSize) { if(id != null) {// id is not null if (!voided) { // get by team member id & voided Criteria criteria_member = sessionFactory.getCurrentSession().createCriteria(TeamMember.class).add(Restrictions.eq("voided", false)); @@ -153,13 +152,12 @@ public List searchTeamMemberByTeam(Integer teamId) { return sessionFactory.getCurrentSession().createQuery("from TeamMember teamMember where teamMember.team = :teamId").setInteger("teamId", teamId).list(); } - //id - TODO @Override public List searchTeamMember(String identifier, TeamMember supervisor, TeamRole teamRole, Team team, Location location, Integer offset, Integer pageSize) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(TeamMember.class); if (location != null) { - criteria.createAlias("location", "l").add(Restrictions.eq("l.locationId", location.getId())); + criteria.createAlias("locations", "l").add(Restrictions.eq("l.locationId", location.getId())); } if (teamRole != null) { @@ -167,8 +165,7 @@ public List searchTeamMember(String identifier, TeamMember superviso } if (identifier != null) { - criteria.add(Restrictions.like("identifier", "%"+identifier+"%")); - //criteria.add(Restrictions.or(Restrictions.or(Restrictions.like("identifier", "%"+identifier+"%"),Restrictions.like("identifier", "%"+identifier+"%")),Restrictions.or(Restrictions.like("identifier", "%"+identifier+"%"),Restrictions.like("identifier", "%"+identifier+"%")))); + criteria.createAlias("person", "p").createAlias("p.names", "pn").add(Restrictions.or(Restrictions.like("pn.givenName", "%"+identifier+"%"),Restrictions.or(Restrictions.like("pn.middleName", "%"+identifier+"%"),Restrictions.or(Restrictions.like("pn.familyName", "%"+identifier+"%"),Restrictions.like("identifier", "%"+identifier+"%"))))); } if (team != null) { @@ -217,13 +214,6 @@ else if (name == null && (joinDateFrom != null && joinDateTo != null)) { @Override public int count(Integer teamId) { // TODO Auto-generated method stub - return (int) sessionFactory.getCurrentSession().createQuery("from TeamMember tm where tm.team= :teamId").setInteger("teamId", teamId).list().size(); - } - - @Override - public List getAllTeamMember(boolean voided, Integer offset, - Integer pageSize) { - // TODO Auto-generated method stub - return sessionFactory.getCurrentSession().createQuery("from TeamMember").list(); + return (int) sessionFactory.getCurrentSession().createQuery("from TeamMember teammember where team= :teamId").setInteger("teamId", teamId).list().size(); } } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleDAO.java index 2446a3c..645a5d9 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleDAO.java @@ -5,6 +5,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.SessionFactory; +import org.openmrs.module.teammodule.TeamMember; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.api.db.TeamRoleDAO; @@ -52,13 +53,20 @@ public void purgeTeamRole(TeamRole TeamRole) { @SuppressWarnings("unchecked") public List searchTeamRoleByRole(String role) { - return (List)sessionFactory.getCurrentSession().createQuery("from TeamRole teamRole where teamRole.name = :role ").setString("role", role).list(); + return (List)sessionFactory.getCurrentSession().createQuery("from TeamRole teamRole where teamRole.name = :role").setString("role", role).list(); } public TeamRole getTeamRoleByUuid(String uuid) { return (TeamRole)sessionFactory.getCurrentSession().createQuery("from TeamRole teamRole where teamRole.uuid = :uuid").setString("uuid", uuid).uniqueResult(); } + @Override + @SuppressWarnings("unchecked") + public List getSubTeamRoles(TeamMember teamMember) { + return sessionFactory.getCurrentSession().createQuery("from TeamRole teamRole where teamRole.reportTo = :id").setInteger("id", teamMember.getTeamRole().getId()).list(); + } + + @SuppressWarnings("unchecked") @Override public List searchTeamRoleReportBy(int id) { // TODO Auto-generated method stub diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleLogDAO.java b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleLogDAO.java index b462bdc..ecdaea3 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleLogDAO.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/db/hibernate/HibernateTeamRoleLogDAO.java @@ -58,8 +58,8 @@ public void purgeTeamRoleLog(TeamRoleLog TeamRoleLog) { } @SuppressWarnings("unchecked") - public List searchTeamRoleLog(Integer teamRole, Integer offset, Integer pageSize) { - Query createQuery =sessionFactory.getCurrentSession().createQuery("from TeamRoleLog teamRoleLog where teamRoleLog.teamRole = :teamRole").setInteger("teamRole", teamRole); + public List searchTeamRoleLog(String teamRole, Integer offset, Integer pageSize) { + Query createQuery =sessionFactory.getCurrentSession().createQuery("from TeamRoleLog teamRoleLog where teamRoleLog.teamRole = :teamRole").setInteger("teamRole", Integer.parseInt(teamRole)); if(offset != null) { createQuery.setFirstResult(offset); } @@ -74,6 +74,15 @@ public TeamRoleLog getTeamRoleLog(String uuid) { return (TeamRoleLog) createQuery.uniqueResult(); } - - + @SuppressWarnings("unchecked") + public List searchTeamRoleLog(Integer teamRole, Integer offset, Integer pageSize) { + Query createQuery =sessionFactory.getCurrentSession().createQuery("from TeamRoleLog teamRoleLog where teamRoleLog.teamRole = :teamRole").setInteger("teamRole", teamRole); + if(offset != null) { + createQuery.setFirstResult(offset); + } + if(pageSize != null) { + createQuery.setMaxResults(pageSize); + } + return createQuery.list(); + } } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamMemberServiceImpl.java b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamMemberServiceImpl.java index a9e3de9..a27aade 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamMemberServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamMemberServiceImpl.java @@ -72,7 +72,7 @@ public List getTeamMemberByPersonId(Integer personId) { } @Override - public List getAllTeamMember(Integer id, boolean voided, Integer offset, Integer pageSize) { + public List getAllTeamMember(Integer id, Boolean voided, Integer offset, Integer pageSize) { return this.dao.getAllTeamMember(id, voided, offset, pageSize); } @@ -93,14 +93,6 @@ public List searchTeamMember(String identifier, TeamMember superviso @Override public int count(Integer teamId) { - // TODO Auto-generated method stub return this.dao.count(teamId); } - - @Override - public List getAllTeamMember(boolean voided, Integer offset, - Integer pageSize) { - // TODO Auto-generated method stub - return this.dao.getAllTeamMember(voided, offset, pageSize); - } } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleLogServiceImpl.java b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleLogServiceImpl.java index c00e5c9..179789d 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleLogServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleLogServiceImpl.java @@ -40,7 +40,7 @@ public void purgeTeamRoleLog(TeamRoleLog TeamRoleLog) { dao.purgeTeamRoleLog(TeamRoleLog); } - public List searchTeamRoleLog(Integer teamRole,Integer offset, Integer pageSize) { + public List searchTeamRoleLog(String teamRole,Integer offset, Integer pageSize) { return dao.searchTeamRoleLog(teamRole,offset, pageSize); } @@ -52,4 +52,7 @@ public TeamRoleLog getTeamRoleLog(String uuid) { return dao.getTeamRoleLog(uuid); } + public List searchTeamRoleLog(Integer teamRoleId,Integer offset, Integer pageSize) { + return dao.searchTeamRoleLog(teamRoleId, offset, pageSize); + } } diff --git a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleServiceImpl.java b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleServiceImpl.java index 1877a5a..77eb5ec 100644 --- a/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/teammodule/api/impl/TeamRoleServiceImpl.java @@ -5,6 +5,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openmrs.api.impl.BaseOpenmrsService; +import org.openmrs.module.teammodule.TeamMember; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.api.TeamRoleService; import org.openmrs.module.teammodule.api.db.TeamRoleDAO; @@ -52,10 +53,13 @@ public TeamRole getTeamRoleByUuid(String uuid) { return dao.getTeamRoleByUuid(uuid); } + @Override + public List getSubTeamRoles(TeamMember teamMember) { + return dao.getSubTeamRoles(teamMember); + } + @Override public List searchTeamRoleReportBy(int id) { - // TODO Auto-generated method stub return dao.searchTeamRoleReportBy(id); } - } diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index 9926589..5f51348 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -195,7 +195,7 @@ - + @@ -270,11 +270,8 @@ - + - - - @@ -353,19 +350,22 @@ + + + + + + - - - - - - + + + \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/teammodule/extension/html/AdminList.java b/omod/src/main/java/org/openmrs/module/teammodule/extension/html/AdminList.java index b056bba..927cee6 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/extension/html/AdminList.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/extension/html/AdminList.java @@ -34,12 +34,11 @@ public String getTitle() { */ public Map getLinks() { LinkedHashMap map = new LinkedHashMap(); - + map.put("module/teammodule/addTeam.form", "New Team"); + map.put("module/teammodule/teamMemberAddForm.form", "New Team Member"); + map.put("module/teammodule/teamRole.form", "Team Hierarchy (Roles)"); map.put("module/teammodule/team.form", "Manage Teams"); - //map.put("module/teammodule/allMember.form?searchMember=&from=&to=", "View Members"); - map.put("module/teammodule/teamMemberView.form", "View All Members"); - map.put("module/teammodule/teamMemberAddForm.form", "Add Members"); - map.put("module/teammodule/teamRole.form", "All Teams Hierarchy"); + map.put("module/teammodule/teamMemberView.form", "Manage Team Members"); return map; } } diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleAddFormController.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleAddFormController.java index dc9e6fb..720eed3 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleAddFormController.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleAddFormController.java @@ -19,17 +19,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openmrs.Location; import org.openmrs.api.context.Context; -//import org.openmrs.module.teammodule.api.TeamMemberService; -//import org.openmrs.module.teammodule.api.TeamMemberService; -import org.openmrs.module.teammodule.Team; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.api.TeamRoleService; -import org.openmrs.module.teammodule.api.TeamService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleEditFormController.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleEditFormController.java index c6a99ee..0f3a592 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleEditFormController.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/RoleEditFormController.java @@ -3,34 +3,22 @@ */ package org.openmrs.module.teammodule.web.controller; -//import java.util.ArrayList; -//import java.util.List; - -//import java.util.ArrayList; import java.util.List; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -//import net.sf.ehcache.hibernate.HibernateUtil; - - - - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openmrs.Location; import org.openmrs.api.context.Context; //import org.openmrs.module.teammodule.api.TeamMemberService; //import org.openmrs.module.teammodule.api.TeamMemberService; import org.openmrs.module.teammodule.Team; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.api.TeamRoleService; -import org.openmrs.module.teammodule.api.TeamService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamController.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamController.java index 964d94a..c0ccf23 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamController.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamController.java @@ -3,22 +3,12 @@ */ package org.openmrs.module.teammodule.web.controller; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openmrs.Location; -import org.openmrs.Privilege; -import org.openmrs.api.context.Context; import org.openmrs.module.teammodule.Team; -import org.openmrs.module.teammodule.TeamMember; -import org.openmrs.module.teammodule.api.TeamMemberService; -import org.openmrs.module.teammodule.api.TeamService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberAddForm.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberAddForm.java index cae496c..852dd8e 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberAddForm.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberAddForm.java @@ -18,9 +18,9 @@ import org.openmrs.Role; import org.openmrs.User; import org.openmrs.api.context.Context; -import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.TeamMember; import org.openmrs.module.teammodule.api.TeamRoleService; +import org.openmrs.module.teammodule.api.TeamService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -63,55 +63,17 @@ public TeamMember populateTeamMember() { */ @RequestMapping(method = RequestMethod.GET) public String showForm( @ModelAttribute("existingMember") TeamMember teamMember, Model model, HttpServletRequest request) throws IOException { - - System.out.println("\nTeam Member Add"); - - System.out.println("\n teamMember: " + teamMember + "\n"); - - String error = request.getParameter("error"); - System.out.println("\n error: " + error); - model.addAttribute("error", error); - - String saved = request.getParameter("saved"); - System.out.println("\n saved: " + saved); - model.addAttribute("saved", saved); - -// String teamId = request.getParameter("teamId"); -// System.out.println("\n teamId: " + teamId); -// model.addAttribute("teamId", teamId); -// -// Team team = Context.getService(TeamService.class).getTeam(Integer.parseInt(teamId)); -// System.out.println("\n team: " + team); -// -// Date teamDate = team.getDateCreated(); -// System.out.println("\n teamDate: " + teamDate); -// model.addAttribute("teamDate", teamDate); - - - List allRole=Context.getUserService().getAllRoles(); - System.out.println("\n allRole: " + allRole + "\n"); - model.addAttribute("allRoles",allRole); - - List allLocations = Context.getLocationService().getAllLocations(); - System.out.println("\n allLocations: " + allLocations + "\n"); + String error = request.getParameter("error"); model.addAttribute("error", error); + String saved = request.getParameter("saved"); model.addAttribute("saved", saved); + model.addAttribute("allRoles",Context.getUserService().getAllRoles()); + List allLocations = Context.getLocationService().getAllLocations(); model.addAttribute("allLocations",allLocations); - - Location location = null; - System.out.println("\n location: " + location + "\n"); model.addAttribute("location", allLocations.get(0)); - - System.out.println("\n selectedLocation: " + allLocations.get(0) + "\n"); model.addAttribute("selectedLocation",allLocations.get(0)); - - List allTeamRole = Context.getService(TeamRoleService.class).getAllTeamRole(); - System.out.println("\n allTeamRole: " + allTeamRole + "\n"); - model.addAttribute("allTeamRole",allTeamRole); - - + model.addAttribute("allTeamRole",Context.getService(TeamRoleService.class).getAllTeamRole()); + model.addAttribute("allTeams",Context.getService(TeamService.class).getAllTeams(false, null, null)); model.addAttribute("teamId",1); - System.out.println("\n teamId: 1\n"); - - //model.addAttribute("json", getHierarchyAsJson()); + //model.addAttribute("json", getRoleAsJson()); //System.out.println("\n locationWidgetType: " + Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCATION_WIDGET_TYPE, "default")) + "\n"); //model.addAttribute("locationWidgetType", Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCATION_WIDGET_TYPE, "default"))); @@ -124,7 +86,7 @@ public String showForm( @ModelAttribute("existingMember") TeamMember teamMember, public User checkUserName(Model model, HttpServletRequest request) throws IOException { String userName = request.getParameter("userName"); - //model.addAttribute("json", getHierarchyAsJson()); + //model.addAttribute("json", getRoleAsJson()); return Context.getUserService().getUserByUsername(userName); } diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberResponsibilityController.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberResponsibilityController.java index 94f41e5..3a7c6de 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberResponsibilityController.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TeamMemberResponsibilityController.java @@ -64,7 +64,7 @@ public String showTeamMemberResponsibility(Model model, HttpServletRequest reque m.put("size", tprs.size()); m.put("size", 0); m.put("memberId", teamMember.get(i).getTeamMemberId()); - Set location = teamMember.get(i).getLocation(); + Set location = teamMember.get(i).getLocations(); m.put("location",location); list.add(m); } diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TransferFormController.java b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TransferFormController.java index d0ac89e..8b0f991 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TransferFormController.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/controller/TransferFormController.java @@ -131,10 +131,10 @@ public String onSubmit(HttpSession httpSession, @ModelAttribute("anyRequestObjec /*Context.getService(TeamMemberService.class).save(teamMember);*/ Context.getService(TeamMemberService.class).saveTeamMember(teamMember); - for(int i = 0; i < teamMember.getLocation().size(); i++){ - Integer locationId = teamMember.getLocation().iterator().next().getLocationId(); + for(int i = 0; i < teamMember.getLocations().size(); i++){ + Integer locationId = teamMember.getLocations().iterator().next().getLocationId(); Location location = Context.getLocationService().getLocation(locationId); - teamMember.getLocation().add(location); + teamMember.getLocations().add(location); /*Context.getService(TeamMemberService.class).saveLocation(location);*/ Context.getLocationService().saveLocation(location); diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamLogRequestResource.java b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamLogRequestResource.java index d9e4de4..906a1f4 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamLogRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamLogRequestResource.java @@ -93,7 +93,6 @@ public List getDisplayString(int team) { @Override public TeamLog getByUniqueId(String uniqueId) { - // TODO Auto-generated method stub return Context.getService(TeamLogService.class).getTeamLog(uniqueId); } } diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamMemberRequestResource.java b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamMemberRequestResource.java index 4a3c53c..fd98f67 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamMemberRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamMemberRequestResource.java @@ -24,6 +24,7 @@ import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; @@ -44,15 +45,12 @@ public TeamMember newDelegate() { @Override public TeamMember save(TeamMember delegate) { + System.out.println(delegate.getIdentifier()); try { - if(delegate.getId() > 0){ - Context.getService(TeamMemberService.class).updateTeamMember(delegate); - return delegate; - } - Context.getService(TeamMemberService.class).saveTeamMember(delegate); + if(delegate.getId() != null && delegate.getId() > 0) { Context.getService(TeamMemberService.class).updateTeamMember(delegate); return delegate; } + else { Context.getService(TeamMemberService.class).saveTeamMember(delegate); return delegate; } } catch(Exception e) { e.printStackTrace(); throw new RuntimeException(e); } - return delegate; } @Override @@ -62,32 +60,40 @@ public DelegatingResourceDescription getRepresentationDescription(Representation if (Context.isAuthenticated()) { description = new DelegatingResourceDescription(); if (rep instanceof DefaultRepresentation) { + description.addProperty("display"); description.addProperty("identifier"); - description.addProperty("person", Representation.DEFAULT); description.addProperty("uuid"); - description.addProperty("location"); - description.addProperty("team", Representation.DEFAULT); - description.addProperty("patients", Representation.DEFAULT); description.addProperty("voided"); + description.addProperty("voidReason"); + description.addProperty("isDataProvider"); description.addProperty("subTeams"); - + description.addProperty("subTeamsCount"); + description.addProperty("subTeamRoles"); + description.addProperty("subTeamRolesCount"); + description.addProperty("person", Representation.DEFAULT); + description.addProperty("team", Representation.DEFAULT); description.addProperty("teamRole", Representation.DEFAULT); - //description.addProperty("subTeamRoles"); + description.addProperty("locations", Representation.DEFAULT); + description.addProperty("patients", Representation.DEFAULT); } else if (rep instanceof FullRepresentation) { + description.addProperty("display"); description.addProperty("identifier"); - description.addProperty("person", Representation.FULL); description.addProperty("uuid"); - description.addProperty("location"); - description.addProperty("team", Representation.FULL); - description.addProperty("patients", Representation.FULL); description.addProperty("voided"); + description.addProperty("voidReason"); + description.addProperty("isDataProvider"); description.addProperty("subTeams"); + description.addProperty("subTeamsCount"); + description.addProperty("subTeamRoles"); + description.addProperty("subTeamRolesCount"); + description.addProperty("person", Representation.FULL); + description.addProperty("team", Representation.FULL); + description.addProperty("teamRole", Representation.FULL); + description.addProperty("locations", Representation.FULL); + description.addProperty("patients", Representation.FULL); description.addProperty("auditInfo"); description.addSelfLink(); - - description.addProperty("teamRole", Representation.FULL); - //description.addProperty("subTeamRoles"); } } return description; @@ -106,38 +112,64 @@ public SimpleObject subresourceSave(TeamMember delegate, String subResource, Sim System.out.println("teamMembers: " + teamMembers); return new NeedsPaging(teamMembers, context).toSimpleObject(this); } + else if(subResource.equals("role") && post.get("role") != null) {//post.get("team") == new team id + System.out.println("subResource: " + subResource); + System.out.println("role: " + post.get("role").toString()); + delegate.setTeamRole(Context.getService(TeamRoleService.class).getTeamRoleById(Integer.parseInt(post.get("role").toString()))); + Context.getService(TeamMemberService.class).saveTeamMember(delegate); + List teamMembers = new ArrayList<>(); + teamMembers.add(delegate); + System.out.println("teamMembers: " + teamMembers); + return new NeedsPaging(teamMembers, context).toSimpleObject(this); + } else { return null; } } + @Override + public DelegatingResourceDescription getCreatableProperties() { + DelegatingResourceDescription description = new DelegatingResourceDescription(); + description.addProperty("identifier"); + description.addProperty("joinDate"); + description.addProperty("leaveDate"); + description.addProperty("isDataProvider"); + description.addProperty("patients"); + description.addRequiredProperty("team"); + description.addRequiredProperty("person"); + description.addRequiredProperty("locations"); + description.addRequiredProperty("teamRole"); + return description; + } + @Override public DelegatingResourceDescription getUpdatableProperties() { DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("identifier"); description.addProperty("person"); - description.addProperty("location"); + description.addProperty("locations"); description.addProperty("team"); description.addProperty("patients"); description.addProperty("subTeams"); description.addProperty("voided"); + description.addProperty("voidReason"); + description.addProperty("isDataProvider"); + description.addProperty("subTeamRoles"); //description.addProperty("teamRole"); - //description.addProperty("subTeamRoles"); return description; } @Override public TeamMember getByUniqueId(String uuid) { - //System.out.println("Inside"); + TeamMember tm = Context.getService(TeamMemberService.class).getTeamMemberByUuid(uuid); + if(tm != null){ + return tm; + } + Person person = Context.getPersonService().getPersonByUuid(uuid); - //System.out.println(person); if (person != null) { - Integer id = person.getPersonId(); - List tm = Context.getService(TeamMemberService.class).getTeamMemberByPersonId(id); - id = tm.get(0).getTeamMemberId(); - TeamMember member = Context.getService(TeamMemberService.class).getTeamMember(id); - return member; + List tml = Context.getService(TeamMemberService.class).getTeamMemberByPersonId(person.getPersonId()); + return tml.size() > 0 ? tml.get(0) : null; } - return Context.getService(TeamMemberService.class).getTeamMemberByUuid(uuid); - + return null; } @Override @@ -184,7 +216,7 @@ else if(context.getParameter("get").equals("filter")) { if(context.getParameter("team") != null) { teamId = context.getParameter("team"); } if(context.getParameter("location") != null) { locationId = context.getParameter("location"); } - //System.out.println("\nFrom UI: " + id + ", " + supervisorId + ", " + teamRoleId + ", " + teamId + ", " + locationId + "\n"); + System.out.println("\nFrom UI: " + id + ", " + supervisorId + ", " + teamRoleId + ", " + teamId + ", " + locationId + "\n"); if(id.equals("") ) { id = null; } if(supervisorId.equals("") ) { supervisorId = null; } @@ -197,8 +229,7 @@ else if(context.getParameter("get").equals("filter")) { TeamRole teamRole = null; if(teamRoleId != null) { teamRole = Context.getService(TeamRoleService.class).getTeamRoleById(Integer.parseInt(teamRoleId)); } Location location = null; if(locationId != null) { location = Context.getLocationService().getLocation(Integer.parseInt(locationId)); } - //System.out.println("\nTo Function: " + id + ", " + supervisorId + ", " + teamRoleId + ", " + teamId + ", " + locationId + "\n"); - + System.out.println("\nTo Function: " + id + ", " + supervisorId + ", " + teamRoleId + ", " + teamId + ", " + locationId + "\n"); List teamMembers = (List) Context.getService(TeamMemberService.class).searchTeamMember(id, supervisor, teamRole, team, location, null, null); //System.out.println("\nAFTER: " + id + ", " + supervisorId + ", " + teamRoleId + ", " + teamId + ", " + locationId + "\n"); @@ -207,309 +238,43 @@ else if(context.getParameter("get").equals("filter")) { return new NeedsPaging(teamMembers, context).toSimpleObject(this); } else { System.out.println("get: " + context.getParameter("get")); return null; } - } - /*else if(context.getParameter("update") != null) { - //UPDATE TEAM MEMBER INFO - teamMemberView.form - if(context.getParameter("update").equals("teamMemberInfo")) { - String uuid = "", identifier = "", firstName = "", middleName = "", lastName = ""; - - if(context.getParameter("uuid") != null) { uuid = context.getParameter("uuid"); } - if(context.getParameter("identifier") != null) { identifier = context.getParameter("identifier"); } - if(context.getParameter("firstName") != null) { firstName = context.getParameter("firstName"); } - if(context.getParameter("middleName") != null) { middleName = context.getParameter("middleName"); } - if(context.getParameter("lastName") != null) { lastName = context.getParameter("lastName"); } - - if(uuid.equals("") ) { uuid = null; } - if(identifier.equals("") ) { identifier = null; } - if(firstName.equals("") ) { firstName = null; } - if(middleName.equals("") ) { middleName = null; } - if(lastName.equals("") ) { lastName = null; } - - System.out.println("uuid: " + uuid); - System.out.println("identifier: " + identifier); - System.out.println("firstName: " + firstName); - System.out.println("middleName: " + middleName); - System.out.println("lastName: " + lastName); - - TeamMember teamMember = Context.getService(TeamMemberService.class).getTeamMemberByUuid(uuid); - teamMember.setIdentifier(identifier); - teamMember.getPerson().getPersonName().setGivenName(firstName); - teamMember.getPerson().getPersonName().setMiddleName(middleName); - teamMember.getPerson().getPersonName().setFamilyName(lastName); - Context.getService(TeamMemberService.class).updateTeamMember(teamMember); - - List teamMembers = new ArrayList<>(); - teamMembers.add(teamMember); - System.out.println("teamMembers: " + teamMembers); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); - } - //UPDATE TEAM MEMBER TEAM - teamMemberView.form - else if(context.getParameter("update").equals("teamMemberTeam")) { - String uuid = "", teamId = ""; - - if(context.getParameter("uuid") != null) { uuid = context.getParameter("uuid"); } - if(context.getParameter("teamId") != null) { teamId = context.getParameter("teamId"); } - - if(uuid.equals("") ) { uuid = null; } - if(teamId.equals("") ) { teamId = null; } - - System.out.println("uuid: " + uuid); - System.out.println("teamId: " + teamId); - - TeamMember teamMember = Context.getService(TeamMemberService.class).getTeamMemberByUuid(uuid); - teamMember.setTeam(Context.getService(TeamService.class).getTeam(Integer.parseInt(teamId))); - Context.getService(TeamMemberService.class).updateTeamMember(teamMember); - - List teamMembers = new ArrayList<>(); - teamMembers.add(teamMember); - System.out.println("teamMembers: " + teamMembers); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); - } - //UPDATE TEAM MEMBER ROLE - teamMemberView.form - else if(context.getParameter("update").equals("teamMemberRole")) { - String uuid = "", roleId = ""; - - if(context.getParameter("uuid") != null) { uuid = context.getParameter("uuid"); } - if(context.getParameter("roleId") != null) { roleId = context.getParameter("roleId"); } - - if(uuid.equals("") ) { uuid = null; } - if(roleId.equals("") ) { roleId = null; } - - System.out.println("uuid: " + uuid); - System.out.println("roleId: " + roleId); - - TeamMember teamMember = Context.getService(TeamMemberService.class).getTeamMemberByUuid(uuid); - teamMember.setTeamRole(Context.getService(TeamRoleService.class).getTeamRoleById(Integer.parseInt(roleId))); - Context.getService(TeamMemberService.class).updateTeamMember(teamMember); - - List teamMembers = new ArrayList<>(); - teamMembers.add(teamMember); - System.out.println("teamMembers: " + teamMembers); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); - } - else { System.out.println("update: " + context.getParameter("update")); return null; } - }*/ - /*else if(context.getParameter("post") != null) { - if(context.getParameter("post").equals("add")) { - String givenName="",familyName="",gender="",birthDate="",identifier="",joinDate="",leaveDate="",location="",voided="",voidReason="",isDataProvider="",provider="",teamRoleOption="",choice="",existingPersonId="",loginChoice="",userName="",password="",confirmPassword="",roleOption="",teamId=""; - if(context.getParameter("givenName") != null) { givenName = context.getParameter("givenName"); } - if(context.getParameter("familyName") != null) { familyName = context.getParameter("familyName"); } - if(context.getParameter("gender") != null) { gender = context.getParameter("gender"); } - if(context.getParameter("birthDate") != null) { birthDate = context.getParameter("birthDate"); } - if(context.getParameter("identifier") != null) { identifier = context.getParameter("identifier"); } - if(context.getParameter("joinDate") != null) { joinDate = context.getParameter("joinDate"); } - if(context.getParameter("leaveDate") != null) { leaveDate = context.getParameter("leaveDate"); } - if(context.getParameter("location") != null) { location = context.getParameter("location"); } - if(context.getParameter("voided") != null) { voided = context.getParameter("voided"); } - if(context.getParameter("voidReason") != null) { voidReason = context.getParameter("voidReason"); } - if(context.getParameter("isDataProvider") != null) { isDataProvider = context.getParameter("isDataProvider"); } - if(context.getParameter("provider") != null) { provider = context.getParameter("provider"); } - if(context.getParameter("teamRoleOption") != null) { teamRoleOption = context.getParameter("teamRoleOption"); } - if(context.getParameter("choice") != null) { choice = context.getParameter("choice"); } - if(context.getParameter("existingPersonId") != null) { existingPersonId = context.getParameter("existingPersonId"); } - if(context.getParameter("loginChoice") != null) { loginChoice = context.getParameter("loginChoice"); } - if(context.getParameter("userName") != null) { userName = context.getParameter("userName"); } - if(context.getParameter("password") != null) { password = context.getParameter("password"); } - if(context.getParameter("confirmPassword") != null) { confirmPassword = context.getParameter("confirmPassword"); } - if(context.getParameter("roleOption") != null) { roleOption = context.getParameter("roleOption"); } - if(context.getParameter("teamId") != null) { teamId = context.getParameter("teamId"); } - - - if(givenName.equals("")) { givenName = null; } - if(familyName.equals("")) { familyName = null; } - if(gender.equals("")) { gender = null; } - if(birthDate.equals("")) { birthDate = null; } - if(identifier.equals("")) { identifier = null; } - if(joinDate.equals("")) { joinDate = null; } - if(leaveDate.equals("")) { leaveDate = null; } - if(location.equals("")) { location = null; } - if(voided.equals("")) { voided = null; } - if(voidReason.equals("")) { voidReason = null; } - if(isDataProvider.equals("")) { isDataProvider = null; } - if(provider.equals("")) { provider = null; } - if(teamRoleOption.equals("")) { teamRoleOption = null; } - if(choice.equals("")) { choice = null; } - if(existingPersonId.equals("")) { existingPersonId = null; } - if(loginChoice.equals("")) { loginChoice = null; } - if(userName.equals("")) { userName = null; } - if(password.equals("")) { password = null; } - if(confirmPassword.equals("")) { confirmPassword = null; } - if(roleOption.equals("")) { roleOption = null; } - if(teamId.equals("")) { teamId = null; } - - System.out.println("\n givenName: " + givenName); - System.out.println("\n familyName: " + familyName); - System.out.println("\n gender: " + gender); - System.out.println("\n birthDate: " + birthDate); - System.out.println("\n identifier: " + identifier); - System.out.println("\n joinDate: " + joinDate); - System.out.println("\n leaveDate: " + leaveDate); - System.out.println("\n location: " + location); - System.out.println("\n voided: " + voided); - System.out.println("\n voidReason: " + voidReason); - System.out.println("\n isDataProvider: " + isDataProvider); - System.out.println("\n provider: " + provider); - System.out.println("\n teamRoleOption: " + teamRoleOption); - System.out.println("\n teamId: " + teamId); - - System.out.println("\n choice: " + choice); - System.out.println("\n existingPersonId: " + existingPersonId); - - System.out.println("\n loginChoice: " + loginChoice); - System.out.println("\n userName: " + userName); - System.out.println("\n password: " + password); - System.out.println("\n confirmPassword: " + confirmPassword); - System.out.println("\n roleOption: " + roleOption); - - - Person person = new Person(); - if(choice != null) { - //Choose Existing Person - checked - if(choice.equals("true")) { - Set personList = Context.getPersonService().getSimilarPeople(existingPersonId, null, null); - for (Iterator iterator = personList.iterator(); iterator.hasNext();) { - Person p = (Person) iterator.next(); - if(p.getPersonName().toString().equals(existingPersonId)) { - person = Context.getPersonService().getPerson(p.getId()); - } - } - } - //Choose Existing Person - not checked - else { - PersonName pNames = new PersonName(givenName, "", familyName); - pNames.setPreferred(true); - - Set names = new TreeSet<>(); - names.add(pNames); - - person.setGender(gender); - person.setBirthdate(new Date(birthDate)); - person.setNames(names); - Context.getPersonService().savePerson(person); - - pNames.setPerson(person); - Context.getPersonService().savePersonName(pNames); - - if(loginChoice != null) { - //Add Login Detail - checked - if(choice.equals("true")) { - Set roles = new HashSet<>(); - roles.add(Context.getUserService().getRole(roleOption)); - User user = new User(); - user.setUsername(userName); - user.setSystemId(userName); - user.setRoles(roles); - user.setPerson(person); - user = Context.getUserService().saveUser(user, password); - } - } - } - } - - TeamMember teamMember = new TeamMember(); - - if(identifier != null) { teamMember.setIdentifier(identifier); } - if(joinDate != null) { teamMember.setJoinDate(new Date(joinDate)); } - if(leaveDate != null) { teamMember.setLeaveDate(new Date(leaveDate)); } - if(voided != null) { if(voided.equals("true")) { teamMember.setVoided(true); teamMember.setVoidReason(voidReason); } else { teamMember.setVoided(false); teamMember.setVoidReason(null); } } - if(isDataProvider != null) { if(isDataProvider.equals("true")) { teamMember.setIsDataProvider(true); teamMember.setProvider(provider); } else { teamMember.setIsDataProvider(false); teamMember.setProvider(null); } } - - if(existingPersonId != null) { teamMember.setPerson(person); } else { teamMember.setPerson(null); } - if(teamRoleOption != null) { teamMember.setTeamRole(Context.getService(TeamRoleService.class).getTeamRoleById(Integer.parseInt(teamRoleOption))); } else { teamMember.setTeamRole(null); } - if(teamId != null) { teamMember.setTeam(Context.getService(TeamService.class).getTeam(Integer.parseInt(teamId))); } else { teamMember.setTeam(null); } - if(location != null) { Set locationSet = new HashSet(); locationSet.add(Context.getLocationService().getLocation(Integer.parseInt(location))); teamMember.setLocation(locationSet); } else { teamMember.setLocation(null); } - - Context.getService(TeamMemberService.class).saveTeamMember(teamMember); - List teamMembers = new ArrayList<>(); - teamMembers.add(teamMember); - System.out.println("teamMembers: " + teamMembers); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); -// return null; - } - else { return null; } - }*/ - else if(context.getParameter("teamName")!=null && context.getParameter("locationId")!=null) { - Location location = Context.getLocationService().getLocationByUuid(context.getParameter("locationId")); - Team team = Context.getService(TeamService.class).getTeam(context.getParameter("teamName"),location.getLocationId()); - List teamMembers = Context.getService(TeamMemberService.class).searchTeamMemberByTeam(team.getTeamId()); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); - } - else { return null; } + } else { return null; } } + @Override + protected PageableResult doGetAll(RequestContext context) throws ResponseException { + List teamMembers = Context.getService(TeamMemberService.class).getAllTeamMember(null, false, 0, 100); + return new NeedsPaging(teamMembers, context); + } + + @Override + public SimpleObject getAll(RequestContext context) throws ResponseException { + List teamMembers = Context.getService(TeamMemberService.class).getAllTeamMember(null, false, null, null); + return new NeedsPaging(teamMembers, context).toSimpleObject(this); + } + @PropertyGetter("display") public String getDisplayString(TeamMember teamMember) { - if (teamMember == null){ - return null; - } - - return teamMember.getPerson().getPersonName().toString(); + if (teamMember == null){ return ""; } return teamMember.getPerson().getPersonName().toString(); } @PropertyGetter("subTeams") public String getSubTeam(TeamMember teamMember) { - List teams = Context.getService(TeamService.class).getSubTeams(teamMember); - if(teams == null) { return null; } - else { - String str = ""; - for (int i = 0; i < teams.size(); i++) { - if(i==teams.size()-1) { str += teams.get(i).getTeamName(); } - else { str += teams.get(i).getTeamName() + ", "; } - } return str; - } - } - @Override - public SimpleObject getAll(RequestContext context) throws ResponseException { - List teamMembers = Context.getService(TeamMemberService.class).getAllTeamMember(true, 0, 25); - return new NeedsPaging(teamMembers, context).toSimpleObject(this); - - } - /*@PropertyGetter("subTeamRoles") - public String getSubTeamRole(TeamMember teamMember) { - List tm = Context.getService(TeamMemberService.class).getTeamMemberByPersonId(teamMember.getPerson().getId()); - if(tm == null) { return ""; } - else { String teamNames = ""; - for (int j = 0; j < tm.size(); j++) { - if(j==tm.size()-1) { teamNames += tm.get(j).getTeamRole().getName() + ""; } - else { teamNames += tm.get(j).getTeamRole().getName() + ", "; } - } return teamNames; - } + List teams = Context.getService(TeamService.class).getSubTeams(teamMember); if(teams == null) { return ""; } else { String str = ""; for (int i = 0; i < teams.size(); i++) { if(i==teams.size()-1) { str += teams.get(i).getTeamName(); } else { str += teams.get(i).getTeamName() + ", "; } } return str; } } - @PropertyGetter("teamRole") - public String getTeamRoleName(TeamMember teamMember) { - if (teamMember == null){ return ""; } - return teamMember.getTeamRole().getName().toString(); + @PropertyGetter("subTeamRoles") + public String getSubTeamRole(TeamMember teamMember) { + List teamRoles = Context.getService(TeamRoleService.class).getSubTeamRoles(teamMember); if(teamRoles == null) { return ""; } else { String str = ""; for (int i = 0; i < teamRoles.size(); i++) { if(i==teamRoles.size()-1) { str += teamRoles.get(i).getName(); } else { str += teamRoles.get(i).getName() + ", "; } } return str; } } - - @PropertyGetter("reportTo") - public String getReportTo(TeamMember teamMember) { - if (teamMember == null){ return ""; } - return teamMember.getTeamRole().getReportTo().getName(); - }*/ + @PropertyGetter("subTeamsCount") + public String getSubTeamCount(TeamMember teamMember) { + List teams = Context.getService(TeamService.class).getSubTeams(teamMember); if(teams == null) { return "0"; } else { return Integer.toString(teams.size()); } + } - - /*@PropertySetter("team") - public Team setTeam(String teamStr) { - System.out.println(); - System.out.println("teamStr: " + teamStr); - if (teamStr == null){ return null; } - else { - Team team = Context.getService(TeamService.class).getTeam(teamStr); - if(team == null) { return Context.getService(TeamService.class).getTeam(Integer.parseInt(teamStr)); } - else { return team; } - } + @PropertyGetter("subTeamRolesCount") + public String getSubTeamRoleCount(TeamMember teamMember) { + List teamRoles = Context.getService(TeamRoleService.class).getSubTeamRoles(teamMember); if(teamRoles == null) { return "0"; } else { return Integer.toString(teamRoles.size()); } } - - @Override - public void setConvertedProperties(TeamMember delegate, Map propertyMap, DelegatingResourceDescription description, boolean mustIncludeRequiredProperties) throws ConversionException { - for (Map.Entry prop : propertyMap.entrySet()) { - System.out.println("Conversion"); - System.out.println(delegate); - System.out.println(prop.getKey()); - System.out.println(prop.getValue()); - setProperty(delegate, prop.getKey(), prop.getValue()); - } - }*/ } \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRequestResource.java b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRequestResource.java index a2834ac..68ea575 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRequestResource.java @@ -44,23 +44,28 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description = new DelegatingResourceDescription(); if (rep instanceof DefaultRepresentation) { description.addProperty("display"); + description.addProperty("uuid"); description.addProperty("teamName"); description.addProperty("teamIdentifier"); - description.addProperty("uuid"); - description.addProperty("location"); + description.addProperty("supervisor"); + description.addProperty("supervisorUuid"); + description.addProperty("voided"); + description.addProperty("members"); + description.addProperty("location", Representation.DEFAULT); } else if (rep instanceof FullRepresentation) { description.addProperty("display"); - description.addProperty("teamIdentifier"); + description.addProperty("uuid"); description.addProperty("teamName"); + description.addProperty("teamIdentifier"); description.addProperty("supervisor"); + description.addProperty("supervisorUuid"); description.addProperty("voided"); - description.addProperty("location"); - description.addProperty("uuid"); + description.addProperty("location", Representation.FULL); description.addProperty("members"); description.addProperty("auditInfo"); + description.addSelfLink(); } - } - return description; + } return description; } @Override @@ -122,32 +127,23 @@ else if(context.getParameter("teamName")!=null && context.getParameter("location @PropertyGetter("display") public String getDisplayString(Team team) { - if (team == null){ - return ""; - } - return team.getTeamName(); + if (team == null) { return ""; } return team.getTeamName(); } @PropertyGetter("members") public int getNumberOfMember(Team team) { - try{ - return Context.getService(TeamMemberService.class).count(team.getTeamId()); - }catch(Exception ex) - { - return 0; - } - } + if (team == null) { return 0; } return Context.getService(TeamMemberService.class).count(team.getTeamId()); + } @PropertyGetter("supervisor") - public TeamMember getSuperVisor(Team team) { - try{ - TeamMember teamMember = (TeamMember) Context.getService(TeamMemberService.class).searchTeamMember(null, team.getSupervisor(), null, null, null, null, null); - return teamMember; - }catch(Exception ex) - { - return null; - } - } + public String getSuperVisor(Team team) { + if (team == null || team.getSupervisor() == null) { return ""; } return team.getSupervisor().getPerson().getPersonName().toString(); + } + + @PropertyGetter("supervisorUuid") + public String getSuperVisorUuid(Team team) { + if (team == null || team.getSupervisor() == null) { return ""; } return team.getSupervisor().getUuid(); + } @Override protected PageableResult doGetAll(RequestContext context) diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleLogRequestResource.java b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleLogRequestResource.java index 1324010..49e5848 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleLogRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleLogRequestResource.java @@ -2,7 +2,6 @@ import java.util.List; -import org.apache.poi.hssf.record.formula.functions.If; import org.openmrs.api.context.Context; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.TeamRoleLog; @@ -12,7 +11,6 @@ import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; -import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; import org.openmrs.module.webservices.rest.web.annotation.Resource; import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; diff --git a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleRequestResource.java b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleRequestResource.java index 49fab0b..200bc30 100644 --- a/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/teammodule/web/resource/TeamRoleRequestResource.java @@ -3,10 +3,8 @@ import java.util.List; import org.openmrs.api.context.Context; -import org.openmrs.module.teammodule.Team; import org.openmrs.module.teammodule.TeamRole; import org.openmrs.module.teammodule.api.TeamRoleService; -import org.openmrs.module.teammodule.api.TeamService; import org.openmrs.module.teammodule.rest.v1_0.resource.TeamModuleResourceController; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -37,16 +35,19 @@ public DelegatingResourceDescription getRepresentationDescription(Representation if (rep instanceof DefaultRepresentation) { description.addProperty("display"); description.addProperty("uuid"); + description.addProperty("name"); description.addProperty("ownsTeam"); + description.addProperty("reportTo"); + description.addProperty("reportByName"); } else if (rep instanceof FullRepresentation) { description.addProperty("display"); description.addProperty("name"); description.addProperty("uuid"); description.addProperty("ownsTeam"); - description.addProperty("ReportToName"); - description.addProperty("ReportByName", Representation.FULL); + description.addProperty("reportTo"); + description.addProperty("reportByName"); description.addProperty("auditInfo"); - + description.addSelfLink(); } } @@ -75,7 +76,6 @@ public void purge(TeamRole teamRole, RequestContext arg1) throws ResponseExcepti Context.getService(TeamRoleService.class).purgeTeamRole(teamRole); } - @SuppressWarnings("unchecked") @Override public SimpleObject search(RequestContext context) { if(context.getParameter("q")!=null) @@ -90,18 +90,17 @@ public SimpleObject search(RequestContext context) { @PropertyGetter("display") public String getDisplayString(TeamRole teamRole) { - return teamRole.getName(); + if(teamRole == null) { return ""; } return teamRole.getName(); } - @PropertyGetter("ReportToName") + @PropertyGetter("reportTo") public String getReportToName(TeamRole teamRole) { - return teamRole.getReportTo().getName(); + if(teamRole == null || teamRole.getReportTo() == null) { return ""; } return teamRole.getReportTo().getName(); } - @PropertyGetter("ReportByName") + @PropertyGetter("reportByName") public List getReportByName(TeamRole teamRole) { - List teamRoles = Context.getService(TeamRoleService.class).searchTeamRoleReportBy(teamRole.getTeamRoleId()); - return teamRoles; + List teamRoles = Context.getService(TeamRoleService.class).searchTeamRoleReportBy(teamRole.getTeamRoleId()); if(teamRoles == null) { return null; } else { return teamRoles; } } @Override diff --git a/omod/src/main/resources/team_member.hbm.xml b/omod/src/main/resources/team_member.hbm.xml index 441857f..3346a02 100644 --- a/omod/src/main/resources/team_member.hbm.xml +++ b/omod/src/main/resources/team_member.hbm.xml @@ -10,11 +10,10 @@ - - + - + @@ -31,6 +30,13 @@ + + + + + + + \ No newline at end of file diff --git a/omod/src/main/webapp/team.jsp b/omod/src/main/webapp/team.jsp index 6641e08..eb9b7da 100644 --- a/omod/src/main/webapp/team.jsp +++ b/omod/src/main/webapp/team.jsp @@ -74,9 +74,11 @@ if(teams[i].supervisor!=null) { var cell = row.insertCell(-1); - cell.innerHTML = ""+teams[i].supervisor+"" ; + //cell.innerHTML = ""+teams[i].supervisor+"" ; + cell.innerHTML = ""+teams[i].supervisor+"" ; var cell = row.insertCell(-1); - cell.innerHTML = ""+teams[i].supervisor.team+"" ; + //cell.innerHTML = ""+teams[i].supervisor.team+"" ; + cell.innerHTML = ""+teams[i].teamName+"" ; } else { diff --git a/omod/src/main/webapp/teamMemberAddForm.jsp b/omod/src/main/webapp/teamMemberAddForm.jsp index 7553edf..9e5c914 100644 --- a/omod/src/main/webapp/teamMemberAddForm.jsp +++ b/omod/src/main/webapp/teamMemberAddForm.jsp @@ -16,6 +16,11 @@

${error}

${saved}

-

Add Member

+

Add Team Member

@@ -350,28 +431,31 @@ Choose Existing Person + - + + style="padding-left: 5em"

Existing Person

- + --> + + + + + + + + - + - + - - + + - - - - - - - - - - - - - - - - - - <%-- - - - --%> diff --git a/omod/src/main/webapp/teamMemberView.jsp b/omod/src/main/webapp/teamMemberView.jsp index c368581..424b3f1 100644 --- a/omod/src/main/webapp/teamMemberView.jsp +++ b/omod/src/main/webapp/teamMemberView.jsp @@ -12,8 +12,9 @@ -

Team Members

+

Team Members


${error}

${saved}

@@ -325,7 +411,7 @@ +
- Name +

+ Existing Person +

-
+
- Member Name + First Name: @@ -385,7 +469,7 @@
- Member Middle Name + Middle Name: @@ -395,7 +479,7 @@
- Member Family Name + Family Name: @@ -403,6 +487,33 @@ Min 3 and max 20.Alphabets,[-.] are allowed
+ Birth Date: + + + + * + + + Date shouldn't be in future + +
+ Gender: + + + + Male + Female + + * +
Add Login Detail @@ -440,57 +551,58 @@
- Role: + User Role: -
- Gender + Member Identifier: - - - Male - Female - + * + Min 3 and max 20.All data types and [-_] are allowed
- Birth Date + Team: - - - * - - - Date shouldn't be in future - + + *
- Member Identifier + Team Role: - + * - Min 3 and max 20.All data types and [-_] are allowed
- Join Date + Join Date: @@ -499,7 +611,7 @@
- Leave Date + Leave Date: @@ -508,7 +620,7 @@
- Location + Assigned Locations: @@ -516,73 +628,16 @@
- Retire Member ? - - -
- Reason must be written
Retire Reason - -
- Is Data Provider ? + Is Data Provider?
- Member Role - - -
- -
-
Filter By: - +
+Add New Member
- -
+
+
+Back to Team List +
+
<%@ include file="/WEB-INF/template/footer.jsp"%>