Compare commits

...

10 Commits

Author SHA1 Message Date
proshanto
17b54f1077 catchment area 2024-12-12 14:16:24 +06:00
proshanto
4c910f0267 aloclinic user catchment 2024-11-19 19:51:35 +06:00
proshanto
b154534ea2 add outreach 2024-11-19 14:44:05 +06:00
Mehedi Hasan
61496fbde9 Merged in feature (pull request #13)
add location api

Approved-by: Proshanto kumar sarker
2024-08-20 08:54:30 +00:00
Mehedi
da7b878d2f Merge branch 'unicef_dghs' of bitbucket.org:mpowersocial/ha-dashboard into feature 2024-08-20 14:52:24 +06:00
Mehedi
4d043482ab add location api 2024-08-20 14:49:06 +06:00
Proshanto kumar sarker
e4ed535313 Merged in sbk (pull request #12)
Sbk
2024-08-13 06:53:16 +00:00
tafseer
9aa9592e5b sbk center api 2024-07-31 19:05:15 +06:00
tafseer
b906c0134f update sbk count 2024-07-27 21:09:58 +06:00
tafseer
23b42494af sbk view fixed 2024-07-18 18:10:32 +06:00
16 changed files with 275 additions and 16 deletions

View File

@ -11,6 +11,10 @@ openmrs.password=Admin123
project.entity=ec_
project.woman=ec_woman
opensrp.url=http://localhost:8080/opensrp/
#opensrp.url=http://192.168.19.146:9003/opensrp/
opensrp.username=admin
opensrp.password=admin
openmrs.login.location.tag.id=b8bbf83e-645f-451f-8efe-a0db56f09676
openmrs.visit.location.tag.id=475d8fa3-5572-11e6-8be9-0800270d80ce

View File

@ -42,6 +42,7 @@ public class UserDTO {
private Integer paurasava;
private List<Integer> paurasavs;
private List<Integer> upazilas;
private List<String> outreach;
public boolean isTeamMember() {
return teamMember;
}
@ -252,6 +253,14 @@ public class UserDTO {
this.upazilas = upazilas;
}
public List<String> getOutreach() {
return outreach;
}
public void setOutreach(List<String> outreach) {
this.outreach = outreach;
}
@Override
public String toString() {
return "UserDTO [id=" + id + ", firstName=" + firstName + ", lastName="

View File

@ -51,6 +51,9 @@ public class SbkCenter implements Serializable{
private Date updated = new Date();
private String mobile;
@Column(name = "server_version")
private Long ServerVersion;
public int getId() {
return id;
@ -124,5 +127,13 @@ public class SbkCenter implements Serializable{
this.upazila = upazila;
}
public Long getServerVersion() {
return ServerVersion;
}
public void setServerVersion(Long serverVersion) {
ServerVersion = serverVersion;
}
}

View File

@ -20,6 +20,7 @@ import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
@ -155,6 +156,8 @@ public class User implements UserDetails {
private Integer district;
@Column(name = "paurasava_id")
private Integer paurasava;
public User() {
}
@ -453,6 +456,9 @@ public class User implements UserDetails {
this.upazila = upazila;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", uuid=" + uuid

View File

@ -1141,4 +1141,45 @@ public class LocationService {
results = query.list();
return results;
}
@SuppressWarnings({ "rawtypes", "deprecation", "unchecked" })
@Transactional
public List<LocationDTO> getFacilityLocatons(Integer parentLocationId) {
Session session = sessionFactory.getCurrentSession();
List<LocationDTO> locations = new ArrayList<>();
String hql = "with recursive loc_tree as ( "
+ " select * from core.location as l where l.parent_location_id=:parentLocationId "
+ " union all select loc2.* from core.location loc2 join loc_tree lt on lt.id = loc2.parent_location_id ) "
+ " select l.id,split_part(l.name, ':', 1) \"name\",l.code,split_part(l.description, ':', 1) description,l.location_tag_id locationTagId,l.parent_location_id parentLocationId "
+ " from loc_tree l ";
Query query = session.createSQLQuery(hql).addScalar("id", StandardBasicTypes.INTEGER)
.addScalar("name", StandardBasicTypes.STRING).addScalar("code", StandardBasicTypes.STRING)
.addScalar("description", StandardBasicTypes.STRING).addScalar("locationTagId", StandardBasicTypes.INTEGER)
.addScalar("parentLocationId", StandardBasicTypes.INTEGER).setInteger("parentLocationId", parentLocationId)
.setResultTransformer(new AliasToBeanResultTransformer(LocationDTO.class));
locations = query.list();
return locations;
}
@Transactional
public List<LocationDTO> getLocationUpToUpazila() {
Session session = sessionFactory.getCurrentSession();
List<LocationDTO> locations = new ArrayList<>();
String hql = "select l.id,split_part(l.name, ':', 1) \"name\",l.code,split_part(l.description, ':', 1) description,l.location_tag_id locationTagId,l.parent_location_id parentLocationId from "
+ " core.\"location\" as l where l.location_tag_id = any(array[10,11,12,13])";
Query query = session.createSQLQuery(hql).addScalar("id", StandardBasicTypes.INTEGER)
.addScalar("name", StandardBasicTypes.STRING).addScalar("code", StandardBasicTypes.STRING)
.addScalar("description", StandardBasicTypes.STRING).addScalar("locationTagId", StandardBasicTypes.INTEGER)
.addScalar("parentLocationId", StandardBasicTypes.INTEGER)
.setResultTransformer(new AliasToBeanResultTransformer(LocationDTO.class));
locations = query.list();
return locations;
}
}

View File

@ -4,6 +4,7 @@
package org.opensrp.core.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -11,6 +12,11 @@ import java.util.Map;
import javax.transaction.Transactional;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.hibernate.type.StandardBasicTypes;
import org.opensrp.common.interfaces.DatabaseRepository;
import org.opensrp.core.entity.LocationTag;
import org.opensrp.core.entity.User;
@ -29,7 +35,8 @@ public class LocationTagService {
@Autowired
private DatabaseRepository repository;
@Autowired
private SessionFactory sessionFactory;
@Autowired
private OpenMRSServiceFactory openMRSServiceFactory;
@ -126,4 +133,20 @@ public class LocationTagService {
}
return sameName;
}
@Transactional
public List<LocationTag> getLocationTags() {
Session session = sessionFactory.getCurrentSession();
List<LocationTag> locationsTags = new ArrayList<>();
String hql = "select lt.id,lt.\"name\",lt.description from core.location_tag as lt ";
Query query = session.createSQLQuery(hql).addScalar("id", StandardBasicTypes.INTEGER)
.addScalar("name", StandardBasicTypes.STRING).addScalar("description", StandardBasicTypes.STRING)
.setResultTransformer(new AliasToBeanResultTransformer(LocationTag.class));
locationsTags = query.list();
return locationsTags;
}
}

View File

@ -72,7 +72,7 @@ public class OutreachService extends CommonService {
camp = findById(id, "id", Outreach.class);
}
camp.setProvider(provider);
// camp.setProvider(provider);
camp.setDate(DateUtil.getDateTFromString(date));
camp.setCenterName(row[2].trim());
@ -407,6 +407,20 @@ public class OutreachService extends CommonService {
return res;
}
@Transactional
public int deleteAllByProvider(String provider) {
Session session = getSessionFactory();
String hql = "delete from core.outreach where provider=:provider";
Query query = session.createSQLQuery(hql);
int res = query.setString("provider", provider).executeUpdate();
return res;
}
@Transactional
public List<Outreach> findByProvider(String provider){
System.err.println(findAllByKey(provider, "provider", Outreach.class));
return findAllByKey(provider, "provider", Outreach.class);
}
}

View File

@ -70,7 +70,7 @@ public class SbkCenterService extends CommonService {
String district = row[1].trim();
System.err.println("dis "+ district+"\n");
// System.err.println(division.toUpperCase()+""+ district);
System.err.println(division.toUpperCase()+""+ district);
String upazila = row[2].trim();
String ReferralFacility = row[3].trim();
String code = row[4].trim();
@ -79,6 +79,12 @@ public class SbkCenterService extends CommonService {
Location findDivision = locationService.findByKey(division.toUpperCase(), "name", Location.class);
Location findDistrict = locationService.findByKey(district.toUpperCase(), "name", Location.class);
if (findDivision == null || findDistrict == null) {
msg += "Division or district not found for row " + position + ". ";
position++;
continue;
}
SbkCenter sbkcenter=findByKey(code, "code", SbkCenter.class);
if(sbkcenter==null){
sbkcenter = new SbkCenter();
@ -89,8 +95,14 @@ public class SbkCenterService extends CommonService {
sbkcenter.setDistrictId(findDistrict.getId());
sbkcenter.setReferralFacility(ReferralFacility);
sbkcenter.setCode(code);
sbkcenter.setUpazila(upazila);
// sbkcenter.setUpazila(upazila);
if (upazila != null && !upazila.isEmpty()) {
sbkcenter.setUpazila(upazila);
} else {
sbkcenter.setUpazila(""); // Handle as needed
}
sbkcenter.setMobile(mobile);
sbkcenter.setServerVersion(System.currentTimeMillis());
getSessionFactory().save(sbkcenter);
}
@ -104,7 +116,7 @@ public class SbkCenterService extends CommonService {
public List<String> getPostList(JSONObject jo) {
Session session = getSessionFactory();
List<String> campList = new ArrayList<String>();
String hql = "select * from core.get_sbk_center_list('" + jo + "')";
String hql = "select * from core.sbk_center_list('" + jo + "')";
Query query = session.createSQLQuery(hql);
campList = query.list();
return campList;

View File

@ -44,6 +44,7 @@ import org.opensrp.core.entity.Facility;
import org.opensrp.core.entity.FacilityWorker;
import org.opensrp.core.entity.FacilityWorkerType;
import org.opensrp.core.entity.Location;
import org.opensrp.core.entity.Outreach;
import org.opensrp.core.entity.ProviderInitialCatchment;
import org.opensrp.core.entity.Role;
import org.opensrp.core.entity.Team;
@ -105,7 +106,8 @@ public class UserService {
@Autowired
private ProviderInitialCatchmentService initialCatchmentService;
@Autowired
private OutreachService outreachService;
@Autowired
private TeamMemberMapper teamMemberMapper;
@Autowired
@ -948,12 +950,25 @@ public class UserService {
public String saveWithProviderLcation(UserDTO userDTO){
TeamMember teamMember = new TeamMember();
String userNameUniqueError = "";
Outreach outreach= new Outreach();
List<Outreach> outreachList=new ArrayList<Outreach>();
try {
if(userDTO.getId()!=0){
User user= findById(userDTO.getId(), "id", User.class);
user = userMapper.map(userDTO, user);
List<String> outreachs = userDTO.getOutreach();
if(outreachs!=null){
for (String name : outreachs) {
Outreach ou = new Outreach();
ou.setCampName(name);
ou.setCenterName(name);
ou.setProvider(userDTO.getUsername());
outreachList.add(ou);
}
}
update(user);
}else{
boolean isExists = isUserExist(userDTO.getUsername());
@ -961,12 +976,28 @@ public class UserService {
if (!isExists) {
User user = userMapper.map(userDTO, new User());
//save(user, false);
List<String> outreachs = userDTO.getOutreach();
if(outreachs!=null){
for (String name : outreachs) {
Outreach ou = new Outreach();
ou.setCenterName(name);
ou.setCampName(name);
ou.setProvider(userDTO.getUsername());
outreachList.add(ou);
}
}
repository.save(user);
} else {
userNameUniqueError = "User name already taken.";
}
}
outreachService.deleteAllByProvider(userDTO.getUsername());
for (Outreach theOutreach : outreachList) {
outreachService.save(theOutreach);
}
}
catch (Exception e) {

View File

@ -6,6 +6,7 @@ import java.util.Set;
import org.opensrp.common.dto.UserDTO;
import org.opensrp.core.entity.Location;
import org.opensrp.core.entity.Outreach;
import org.opensrp.core.entity.Role;
import org.opensrp.core.entity.Team;
import org.opensrp.core.entity.User;
@ -89,6 +90,7 @@ public class UserMapper {
}
Team team = teamService.findById(userDTO.getTeam(), "id", Team.class);
user.setTeam(team);

View File

@ -26,6 +26,7 @@ import org.opensrp.common.service.impl.DatabaseServiceImpl;
import org.opensrp.core.entity.Facility;
import org.opensrp.core.entity.FacilityWorker;
import org.opensrp.core.entity.Location;
import org.opensrp.core.entity.Outreach;
import org.opensrp.core.entity.Permission;
import org.opensrp.core.entity.Role;
import org.opensrp.core.entity.Team;
@ -35,6 +36,7 @@ import org.opensrp.core.service.EmailService;
import org.opensrp.core.service.FacilityService;
import org.opensrp.core.service.FacilityWorkerService;
import org.opensrp.core.service.LocationService;
import org.opensrp.core.service.OutreachService;
import org.opensrp.core.service.RoleService;
import org.opensrp.core.service.TeamMemberService;
import org.opensrp.core.service.UserService;
@ -121,7 +123,8 @@ public class UserController {
@Autowired
private FacilityHelperUtil facilityHelperUtil;
@Autowired
private OutreachService outreachService;
@Autowired
private DatabaseRepository repository;
@Value("#{opensrp['submenu.selected.color']}")
@ -177,8 +180,11 @@ public class UserController {
//for adding location and team
model.addAttribute("teamMember", new TeamMember());
String personName = "";
JSONObject tags= new JSONObject();
tags.put("ids", 22);
String personName = "";
model.addAttribute("catchments", locationServiceImpl.getLocationsByTagId(22));
model.addAttribute("divisions", locationServiceImpl.getDivisionList());
int[] locations = new int[0];
teamMemberServiceImpl.setSessionAttribute(session, teamMember, personName, locations);
@ -299,7 +305,30 @@ public class UserController {
model.addAttribute("user", "block");
model.addAttribute("userSubmenu", submenuSelectedColor);
model.addAttribute("getCatchment", outreachService.findByProvider(account.getUsername()));
//return new ModelAndView("user/edit", "command", teamMember);
List<Location> catchments = locationServiceImpl.getLocationsByTagId(22);
List<Outreach> getCatchment=outreachService.findByProvider(account.getUsername());
for (Location location : catchments) {
if(getCatchment!=null){
for (Outreach theCatchment : getCatchment) {
if(theCatchment.getCampName().equalsIgnoreCase(location.getName())){
location.setCode("222");
}
}
}
}
model.addAttribute("catchments", catchments);
return new ModelAndView("user/edit", "command", account);
}

View File

@ -12,10 +12,12 @@ import org.json.JSONObject;
import org.opensrp.common.dto.LocationDTO;
import org.opensrp.common.util.LocationColumn;
import org.opensrp.core.entity.Location;
import org.opensrp.core.entity.LocationTag;
import org.opensrp.core.entity.Role;
import org.opensrp.core.entity.TeamMember;
import org.opensrp.core.entity.User;
import org.opensrp.core.service.LocationService;
import org.opensrp.core.service.LocationTagService;
import org.opensrp.core.service.TeamMemberService;
import org.opensrp.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@ -24,6 +26,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
@RequestMapping("admin/rest/api/v1/location")
@RestController
public class LocationRestController {
@ -36,6 +41,9 @@ public class LocationRestController {
@Autowired
private TeamMemberService teamMemberService;
@Autowired
private LocationTagService locationTagService;
@RequestMapping(value = "/search", method = RequestMethod.GET)
public String getLocationNameAndId(Model model, HttpSession session, @RequestParam String name) throws JSONException {
@ -121,4 +129,35 @@ public class LocationRestController {
JSONObject response = locationServiceImpl.getLocationDataOfDataTable(draw, totalLocation, locations);
return new ResponseEntity<>(response.toString(), OK);
}
@RequestMapping(value = "/facility-locations", method = RequestMethod.GET)
public ResponseEntity<String> getFacilityLcoations(@RequestParam("parentLocation") Integer parentLocationId) {
Gson gson = new Gson();
List<LocationDTO> locations = locationServiceImpl.getFacilityLocatons(parentLocationId);
JsonObject ob = new JsonObject();
ob.add("locations", gson.toJsonTree(locations).getAsJsonArray());
return new ResponseEntity<>(ob.toString(), OK);
}
@RequestMapping(value = "/tags", method = RequestMethod.GET)
public ResponseEntity<String> getLocationTgas() {
Gson gson = new Gson();
List<LocationTag> locationsTags = locationTagService.getLocationTags();
System.err.println(locationsTags);
JsonObject ob = new JsonObject();
ob.add("locations", gson.toJsonTree(locationsTags).getAsJsonArray());
return new ResponseEntity<>(ob.toString(), OK);
}
@RequestMapping(value = "/upto-upazila", method = RequestMethod.GET)
public ResponseEntity<String> syncBMCLocations() {
Gson gson = new Gson();
List<LocationDTO> locations = locationServiceImpl.getLocationUpToUpazila();
JsonObject ob = new JsonObject();
ob.add("locations", gson.toJsonTree(locations).getAsJsonArray());
return new ResponseEntity<>(ob.toString(), OK);
}
}

View File

@ -1,6 +1,7 @@
jdbc.driverClassName=org.postgresql.Driver
#jdbc.url=jdbc:postgresql://172.16.17.67/opensrp?createDatabaseIfNotExist=true
jdbc.url=jdbc:postgresql://localhost/opensrphatraining?createDatabaseIfNotExist=true
# jdbc.url=jdbc:postgresql://localhost/opensrphatraining?createDatabaseIfNotExist=true/
jdbc.url=jdbc:postgresql://192.168.19.143/opensrphatraining?createDatabaseIfNotExist=true
jdbc.user=opensrp_admin
jdbc.pass=admin

View File

@ -113,7 +113,7 @@
<tr><th>SI</th>
<th>Division</th>
<th>District</th>
<th>Upazila</th>
<th>GAVI/CBE/REMEN</th>
<th>Referral Facility</th>
<th>code</th>
<th>Mobile</th>

View File

@ -263,9 +263,23 @@ Map<Integer, String> teams = (Map<Integer, String>)session.getAttribute("teams"
</select>
</div>
<div class="col-sm-6">
<label class="control-label" for="inputPassword6">Catchment Area <span class="required" id="reqoutreach"> </span></label>
<select multiple="multiple" class="form-control mx-sm-3 select22" id="outreachId" name="outreachId" >
<option value=""><spring:message code="lbl.pleaseSelect"/></option>
<c:forEach items="${catchments}" var="location">
<option value="${location.name}">${location.name}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group error" id="error" style="display:none; color:red;">
@ -355,6 +369,7 @@ Map<Integer, String> teams = (Map<Integer, String>)session.getAttribute("teams"
"division":$('#divisionId').val(),
"district":$('#districtId').val(),
"paurasavs":$('#paurasavaId').val(),
"outreach":$('#outreachId').val(),
};

View File

@ -314,7 +314,28 @@ Map<Integer, String> teams = (Map<Integer, String>)session.getAttribute("teams"
</c:forEach>
</select>
</div>
</div>
<div class="col-sm-6">
<label class="control-label" for="inputPassword6">Catchment Area <span class="required" id="reqoutreach"> </span></label>
<select multiple="multiple" class="form-control mx-sm-3 select22" id="outreachId" name="outreachId" >
<option value=""><spring:message code="lbl.pleaseSelect"/></option>
<c:forEach items="${catchments}" var="location">
<c:choose>
<c:when test="${location.code =='222' }">
<option selected value="${location.name}">${location.name}</option>
</c:when>
<c:otherwise>
<option value="${location.name}">${location.name}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</div>
</div>
@ -409,7 +430,8 @@ Map<Integer, String> teams = (Map<Integer, String>)session.getAttribute("teams"
"ward" : 0,
"division":$('#divisionId').val(),
"district":$('#districtId').val(),
"paurasavs":$('#paurasavaId').val()
"paurasavs":$('#paurasavaId').val(),
"outreach":$('#outreachId').val()
};