Skip to content

Commit

Permalink
ZM: Alpha Release 2.0.0a
Browse files Browse the repository at this point in the history
  • Loading branch information
zohaibmk committed May 16, 2017
1 parent 6484989 commit 4f05937
Show file tree
Hide file tree
Showing 24 changed files with 324 additions and 274 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>teammodule</artifactId>
<version>2.0.0</version>
<version>2.0.0A</version>
</parent>

<artifactId>teammodule-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
public interface TeamMemberLogService extends OpenmrsService {

public void saveTeamMemberLog(TeamMemberLog teamMemberLog);


public void updateTeamMemberLog(TeamMemberLog teamMemberLog);

public TeamMemberLog getTeamMemberLog(int id);

public TeamMemberLog getTeamMemberLog(String uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface TeamMemberLogDAO {

public void saveTeamMemberLog(TeamMemberLog teamMemberLog);

public void updateTeamMemberLog(TeamMemberLog teamMemberlog);

public TeamMemberLog getTeamMemberLog(int id);

public TeamMemberLog getTeamMemberLog(String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void saveTeamMemberLog(TeamMemberLog teamMemberLog) {
sessionFactory.getCurrentSession().saveOrUpdate(teamMemberLog);
}

public void updateTeamMemberLog(TeamMemberLog teamMemberLog) {
sessionFactory.getCurrentSession().update(teamMemberLog);
}

public TeamMemberLog getTeamMemberLog(int id) {
return (TeamMemberLog)sessionFactory.getCurrentSession().createQuery("from TeamMemberLog teamMemberLog where teamMemberLog.logId = :id").setInteger("id", id).uniqueResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void saveTeamMemberLog(TeamMemberLog teamMemberlog) {
dao.saveTeamMemberLog(teamMemberlog);
}

public void updateTeamMemberLog(TeamMemberLog teamMemberlog) {
dao.updateTeamMemberLog(teamMemberlog);
}

public List<TeamMemberLog> getAllLogs(Integer offset, Integer pageSize) {
return dao.getAllLogs(offset, pageSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void updateTeam(Team team) {

@Override
public Team getTeam(String teamName, int locationid) {
// TODO Auto-generated method stub
return dao.getTeam(teamName,locationid);
}

Expand Down
2 changes: 1 addition & 1 deletion omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>teammodule</artifactId>
<version>2.0.0</version>
<version>2.0.0A</version>
</parent>

<artifactId>teammodule-omod</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public Map<String, String> getLinks() {
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
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/addRole.form", "New Team Hierarchy (Role)");
map.put("module/teammodule/team.form", "Manage Teams");
map.put("module/teammodule/teamMemberView.form", "Manage Team Members");
map.put("module/teammodule/teamRole.form", "Manage Team Hierarchy (Roles)");
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ public String showForm(Model model, HttpServletRequest request) {

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(HttpSession httpSession, @ModelAttribute("anyRequestObject") Object anyRequestObject, HttpServletRequest request,
@ModelAttribute("roleData") TeamRole teamRole, Model model) {

@ModelAttribute("roleData") TeamRole teamRole, Model model) {
String reportsToUuid = request.getParameter("reportsTo");
System.out.println("reportsTo: " + reportsToUuid);
TeamRole tr = Context.getService(TeamRoleService.class).getTeamRoleByUuid(reportsToUuid);
if(tr!=null) { teamRole.setReportTo(tr); }
teamRole.setUuid(UUID.randomUUID().toString());
Context.getService(TeamRoleService.class).saveTeamRole(teamRole);
String saved = "Role saved successfully";
String saved = "Role Saved Successfully";
model.addAttribute("saved", saved);
List<TeamRole> roles = Context.getService(TeamRoleService.class).getAllTeamRole();
model.addAttribute("reportsTo", roles);
Expand All @@ -86,4 +89,4 @@ public String onSubmit(HttpSession httpSession, @ModelAttribute("anyRequestObjec



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
package org.openmrs.module.teammodule.web.controller;

import java.util.List;
import java.util.UUID;

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.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;
Expand Down Expand Up @@ -46,11 +43,19 @@ public class RoleEditFormController {
* @return String form view name
*/
@RequestMapping(method = RequestMethod.GET)
public String showForm(Model model, HttpServletRequest request,@RequestParam(value = "roleId", required = true) int id, @ModelAttribute("teamData") Team team) {
public String showForm(Model model, HttpServletRequest request,@RequestParam(value = "roleId", required = true) String uuid, @ModelAttribute("teamData") Team team) {

TeamRole roleData = Context.getService(TeamRoleService.class).getTeamRoleById(id);
System.out.println(uuid);
TeamRole roleData = Context.getService(TeamRoleService.class).getTeamRoleByUuid(uuid);
List<TeamRole> roles = Context.getService(TeamRoleService.class).getAllTeamRole();
model.addAttribute("reportsTo", roles);


System.out.println(uuid);
System.out.println(roles);
System.out.println(roleData);

model.addAttribute("reportsToOptions", roles);
model.addAttribute("reportsTo", roleData.getReportTo());
model.addAttribute("roleData", roleData);

return SUCCESS_FORM_VIEW;
Expand All @@ -69,18 +74,21 @@ public String showForm(Model model, HttpServletRequest request,@RequestParam(val
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(HttpSession httpSession, @ModelAttribute("anyRequestObject") Object anyRequestObject, HttpServletRequest request,
@ModelAttribute("roleData") TeamRole teamRole, Model model) {

teamRole.setUuid(UUID.randomUUID().toString());
String reportsToUuid = request.getParameter("reportsTo");
System.out.println("reportsTo: " + reportsToUuid);
TeamRole tr = Context.getService(TeamRoleService.class).getTeamRoleByUuid(reportsToUuid);
if(tr!=null) { teamRole.setReportTo(tr); }
//teamRole.setUuid(UUID.randomUUID().toString());
Context.getService(TeamRoleService.class).saveTeamRole(teamRole);
String saved = "Role saved successfully";
String saved = "Role Updated Successfully";
model.addAttribute("saved", saved);
TeamRole roleData = Context.getService(TeamRoleService.class).getTeamRoleById(teamRole.getTeamRoleId());
model.addAttribute("roleData", roleData);

List<TeamRole> roles = Context.getService(TeamRoleService.class).getAllTeamRole();
model.addAttribute("reportsTo", roles);

return "redirect:/module/teammodule/editRole.form?teamId=" + teamRole.getTeamRoleId();
return SUCCESS_FORM_VIEW;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public String showFormEidt(Model model, HttpServletRequest request, @RequestPara
teamData = Context.getService(TeamService.class).getTeam(teamId);
String error = request.getParameter("error");
model.addAttribute("error", error);
model.addAttribute("defaultLocation", teamData.getLocation());
String edit = request.getParameter("edit");
model.addAttribute("edit", edit);
model.addAttribute("teamData", teamData);
Expand All @@ -60,6 +61,12 @@ public String showFormEdit(Model model, HttpServletRequest request, @RequestPara
Location location = Context.getLocationService().getLocationByUuid(locationUuid);
teamData = Context.getService(TeamService.class).getTeam(teamName, location.getLocationId());
String error = request.getParameter("error");
System.out.println(teamData);
System.out.println(teamData.getLocation());
System.out.println(teamData.getLocation());
model.addAttribute("defaultLocation", location);
model.addAttribute("locations", Context.getLocationService().getAllLocations());

model.addAttribute("error", error);
String edit = request.getParameter("edit");
model.addAttribute("edit", edit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
Expand All @@ -30,15 +32,48 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
DelegatingResourceDescription description = null;
if (Context.isAuthenticated()) {
description = new DelegatingResourceDescription();
description.addProperty("logId");
if (rep instanceof DefaultRepresentation) {
description.addProperty("display");
description.addProperty("teamMember");
description.addProperty("action");
description.addProperty("dataNew");
description.addProperty("dataOld");
description.addProperty("log");
description.addProperty("dateCreated");
} else if (rep instanceof FullRepresentation) {
description.addProperty("display");
description.addProperty("teamMember");
description.addProperty("action");
description.addProperty("dataNew");
description.addProperty("dataOld");
description.addProperty("log");
description.addProperty("auditInfo");
description.addSelfLink();
}
}

return description;
}

@Override
public DelegatingResourceDescription getCreatableProperties() {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("display");
description.addProperty("teamMember");
description.addProperty("action");
description.addProperty("dataNew");
description.addProperty("dataOld");
description.addProperty("log");
return description;
}

@Override
public DelegatingResourceDescription getUpdatableProperties() {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("display");
description.addProperty("teamMember");
description.addProperty("action");
description.addProperty("dataNew");
description.addProperty("dataOld");
description.addProperty("log");
return description;
}

Expand All @@ -48,18 +83,22 @@ public TeamMemberLog newDelegate() {
}

@Override
public TeamMemberLog save(TeamMemberLog teamLog) {
return null;
public TeamMemberLog save(TeamMemberLog delegate) {
try {
if(delegate.getId() != null && delegate.getId() > 0) { Context.getService(TeamMemberLogService.class).updateTeamMemberLog(delegate); return delegate; }
else { Context.getService(TeamMemberLogService.class).saveTeamMemberLog(delegate); return delegate; }
}
catch(Exception e) { e.printStackTrace(); throw new RuntimeException(e); }
}

@Override
protected void delete(TeamMemberLog teamMemberLog, String reason, RequestContext context) throws ResponseException {
// TODO Auto-generated method stub
protected void delete(TeamMemberLog delegate, String reason, RequestContext context) throws ResponseException {
Context.getService(TeamMemberLogService.class).purgeTeamMemberLog(delegate);
}

@Override
public void purge(TeamMemberLog arg0, RequestContext arg1) throws ResponseException {
// TODO Auto-generated method stub
public void purge(TeamMemberLog delegate, RequestContext arg1) throws ResponseException {
Context.getService(TeamMemberLogService.class).purgeTeamMemberLog(delegate);
}

@Override
Expand All @@ -69,17 +108,13 @@ public SimpleObject search(RequestContext context) {
}

@PropertyGetter("display")
public List<TeamMemberLog> getDisplayString(int team) {
return Context.getService(TeamMemberLogService.class).searchTeamMemberLogByTeamMember(team);
public String getDisplayString(TeamMemberLog teamMemberLog) {
if (teamMemberLog == null) { return ""; } return teamMemberLog.getTeamMember().getPerson().getPersonName().toString();
}

@Override
public TeamMemberLog getByUniqueId(String uniqueId) {
return Context.getService(TeamMemberLogService.class).getTeamMemberLog(uniqueId);
}

public TeamMemberLog getById(Integer id) {
return Context.getService(TeamMemberLogService.class).getTeamMemberLog(id);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
description.addProperty("teamRole", Representation.DEFAULT);
description.addProperty("locations", Representation.DEFAULT);
description.addProperty("patients", Representation.DEFAULT);

} else if (rep instanceof FullRepresentation) {
description.addProperty("display");
description.addProperty("identifier");
Expand Down Expand Up @@ -259,8 +258,9 @@ public String getDisplayString(TeamMember teamMember) {
}

@PropertyGetter("subTeams")
public String getSubTeam(TeamMember teamMember) {
List<Team> 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; }
public List<Team> getSubTeam(TeamMember teamMember) {
List<Team> 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; }
if(teams == null) return null; else { return teams; }
}

@PropertyGetter("subTeamRoles")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,18 @@ else if(context.getParameter("supervisor")!=null) {
listTeam.add(team);
return new NeedsPaging<Team>(listTeam, context).toSimpleObject(this);
}
else if(context.getParameter("teamName")!=null && context.getParameter("locationId")!=null && context.getParameter("identifier")!=null) {
Location l = Context.getLocationService().getLocationByUuid(context.getParameter("locationId"));
Team team = (Context.getService(TeamService.class).searchTeam(context.getParameter("teamName"))).get(0);
team.setTeamIdentifier(context.getParameter("identifier"));
team.setLocation(l);
Context.getService(TeamService.class).updateTeam(team);
List<Team> listTeam = new ArrayList<>();
listTeam.add(team);
return new NeedsPaging<Team>(listTeam, context).toSimpleObject(this);
}
else if(context.getParameter("teamName")!=null && context.getParameter("locationId")!=null) {
Team team = Context.getService(TeamService.class).getTeam(context.getParameter("teamName"),Integer.parseInt(context.getParameter("locationId")));
Team team = Context.getService(TeamService.class).getTeam(context.getParameter("teamName"), Integer.parseInt(context.getParameter("locationId")));
List<Team> listTeam = new ArrayList<>();
listTeam.add(team);
return new NeedsPaging<Team>(listTeam, context).toSimpleObject(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
description.addProperty("uuid");
description.addProperty("name");
description.addProperty("ownsTeam");
description.addProperty("reportTo");
description.addProperty("reportToName");
description.addProperty("reportByName");
} else if (rep instanceof FullRepresentation) {
description.addProperty("display");
description.addProperty("name");
description.addProperty("uuid");
description.addProperty("ownsTeam");
description.addProperty("reportTo");
description.addProperty("reportToName");
description.addProperty("reportByName");
description.addProperty("auditInfo");
description.addSelfLink();
Expand Down Expand Up @@ -93,7 +93,7 @@ public String getDisplayString(TeamRole teamRole) {
if(teamRole == null) { return ""; } return teamRole.getName();
}

@PropertyGetter("reportTo")
@PropertyGetter("reportToName")
public String getReportToName(TeamRole teamRole) {
if(teamRole == null || teamRole.getReportTo() == null) { return ""; } return teamRole.getReportTo().getName();
}
Expand Down
Loading

0 comments on commit 4f05937

Please sign in to comment.