Skip to content

Commit

Permalink
fix person countries
Browse files Browse the repository at this point in the history
  • Loading branch information
levine12 committed Jun 26, 2020
1 parent e8d4a80 commit 5456d57
Show file tree
Hide file tree
Showing 28 changed files with 1,109 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist;

import org.openmrs.BaseOpenmrsData;

/**
* @author levine
*/
public class AllCountriesRESTWithCountryCode extends BaseOpenmrsData {

String countriesWithCountryCode; // return comma list as: NIGERIA/+234,UGANDA/+235, ...

public String getCountriesWithCountryCode() {
return countriesWithCountryCode;
}

public void setCountriesWithCountryCode(String countriesWithCountryCode) {
this.countriesWithCountryCode = countriesWithCountryCode;
}

@Override
public Integer getId() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setId(Integer intgr) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
52 changes: 52 additions & 0 deletions api/src/main/java/org/openmrs/module/patientlist/Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.openmrs.module.patientlist;

import java.io.Serializable;
import java.util.Date;
import org.openmrs.BaseOpenmrsData;

/**
* @author levine
*/
public class Country extends BaseOpenmrsData implements Serializable {

private int id;

private String name;

private String countryCode;

private Date dateCreated;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}

public Date getDateCreated() {
return dateCreated;
}

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist;

import org.springframework.stereotype.Component;

/**
* @author levine
*/

@Component("patientlist.CountryConfig")
public class CountryConfig {

public final static String MODULE_PRIVILEGE = "App: patient list";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist;

import java.io.Serializable;
import org.openmrs.BaseOpenmrsData;

/**
* @author levine
*/
public class PersonCountry extends BaseOpenmrsData implements Serializable {

private Integer id;

private Integer personId;

private Integer countryId;

private int isVoid;

public int getIsVoid() {
return isVoid;
}

public void setIsVoid(int isVoid) {
this.isVoid = isVoid;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Integer getPersonId() {
return personId;
}

public void setPersonId(Integer personId) {
this.personId = personId;
}

public Integer getCountryId() {
return countryId;
}

public void setCountryId(Integer countryId) {
this.countryId = countryId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist;

import org.springframework.stereotype.Component;

@Component("patientlist.PersonCountryConfig")
public class PersonCountryConfig {

public final static String MODULE_PRIVILEGE = "App: patient list";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist.api;

import java.util.List;
import org.openmrs.annotation.Authorized;
import org.openmrs.api.APIException;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.patientlist.Country;
import org.openmrs.module.patientlist.CountryConfig;
import org.springframework.transaction.annotation.Transactional;

/**
* @author levine
*/

@Transactional
public interface CountryService extends OpenmrsService {

/**
* Saves a patient list item. Sets the owner to superuser, if it is not set. It can be called by
* users with this module's privilege. It is executed in a transaction.
*
* @param item
* @return
* @throws APIException
*/
@Authorized(CountryConfig.MODULE_PRIVILEGE)
@Transactional
Country saveCountry(Country item) throws APIException;

/**
* Get a {@link Country} object by primary key id.
*
* @param id the primary key integer id to look up on
* @return the found Country object which matches the row with the given id. If no row with the
* given id exists, null is returned.
*/
@Authorized()
@Transactional(readOnly = true)
public Country getCountry(Integer id);

@Authorized()
@Transactional(readOnly = true)
public List<Country> getAllCountry();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist.api;

import java.util.List;
import org.openmrs.annotation.Authorized;
import org.openmrs.api.APIException;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.patientlist.PersonCountry;
import org.openmrs.module.patientlist.PersonCountryConfig;
import org.springframework.transaction.annotation.Transactional;

/**
* @author levine
*/
@Transactional
public interface PersonCountryService extends OpenmrsService {

@Authorized(PersonCountryConfig.MODULE_PRIVILEGE)
@Transactional
PersonCountry savePersonCountry(PersonCountry item) throws APIException;

/**
* Get a {@link PersonCountry} object by primary key id.
*
* @param id the primary key integer id to look up on
* @return the found PersonCountry object which matches the row with the given id. If no row
* with the given id exists, null is returned.
*/
@Authorized()
@Transactional(readOnly = true)
public PersonCountry getPersonCountry(Integer id);

@Authorized()
@Transactional(readOnly = true)
public List<PersonCountry> getAllPersonCountryForPerson(Integer personId);

@Authorized()
@Transactional(readOnly = true)
public List<PersonCountry> getAllPersonCountry();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist.api.db;

import java.util.List;
import org.openmrs.api.APIException;
import org.openmrs.module.patientlist.Country;

/**
* @author levine
*/
public interface CountryDao {

Country saveCountry(Country item) throws APIException;

public Country getCountry(Integer id);

public List<Country> getAllCountry();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openmrs.module.patientlist.api.db;

import java.util.List;
import org.openmrs.api.APIException;
import org.openmrs.module.patientlist.PersonCountry;

/**
* @author levine
*/
public interface PersonCountryDao {

PersonCountry savePersonCountry(PersonCountry item) throws APIException;

public PersonCountry getPersonCountry(Integer id);

public List<PersonCountry> getAllPersonCountryForPerson(Integer personId);

public List<PersonCountry> getAllPersonCountry();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
package org.openmrs.module.patientlist.api.db;

import java.util.List;
import org.openmrs.annotation.Authorized;
import org.openmrs.api.APIException;
import org.openmrs.module.patientlist.SpecialtyTypeItem;
import org.springframework.transaction.annotation.Transactional;

/**
* @author levine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.openmrs.module.patientlist.api.db.hibernate;

import java.util.List;
import org.hibernate.Criteria;
import org.openmrs.api.APIException;
import org.openmrs.api.db.hibernate.DbSessionFactory;
import org.openmrs.module.patientlist.Country;
import org.openmrs.module.patientlist.api.db.CountryDao;

/**
* @author levine
*/
public class HibernateCountryDAO implements CountryDao {

private DbSessionFactory sessionFactory;

public void setSessionFactory(DbSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Override
public Country saveCountry(Country item) throws APIException {
sessionFactory.getCurrentSession().saveOrUpdate(item);
return item;
}

@Override
public Country getCountry(Integer id) {
return (Country) sessionFactory.getCurrentSession().get(Country.class, id);
}

@Override
public List<Country> getAllCountry() {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Country.class);
return crit.list();
}
}
Loading

0 comments on commit 5456d57

Please sign in to comment.