use of org.openmrs.Provider in project openmrs-core by openmrs.
the class HibernateProviderDAO method getProviders.
/**
* @see org.openmrs.api.db.ProviderDAO#getProviders(String, Map, Integer, Integer, boolean)
*/
@Override
public List<Provider> getProviders(String name, Map<ProviderAttributeType, String> serializedAttributeValues, Integer start, Integer length, boolean includeRetired) {
Criteria criteria = prepareProviderCriteria(name, includeRetired);
if (start != null) {
criteria.setFirstResult(start);
}
if (length != null) {
criteria.setMaxResults(length);
}
if (includeRetired) {
// push retired Provider to the end of the returned list
criteria.addOrder(Order.asc("retired"));
}
List<Provider> providers = criteria.list();
if (serializedAttributeValues != null) {
CollectionUtils.filter(providers, new AttributeMatcherPredicate<Provider, ProviderAttributeType>(serializedAttributeValues));
}
return providers;
}
use of org.openmrs.Provider in project openmrs-module-pihcore by PIH.
the class NonCodedDiagnosisDataSetEvaluator method evaluate.
@Override
public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context) throws EvaluationException {
Long startTime = new Date().getTime();
NonCodedDiagnosisDataSetDefinition dsd = (NonCodedDiagnosisDataSetDefinition) dataSetDefinition;
Date fromDate = ObjectUtil.nvl(dsd.getFromDate(), DateUtils.addDays(new Date(), -7));
Date toDate = ObjectUtil.nvl(dsd.getToDate(), new Date());
fromDate = DateUtil.getStartOfDay(fromDate);
toDate = DateUtil.getEndOfDay(toDate);
String nonCoded = ObjectUtil.nvl(dsd.getNonCoded(), null);
Provider provider = ObjectUtil.nvl(dsd.getProvider(), null);
Integer userId = null;
if (provider != null) {
List<User> users = userService.getUsersByPerson(provider.getPerson(), true);
if (users != null && users.size() > 0) {
userId = users.get(0).getId();
}
}
PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
Concept nonCodedConcept = emrApiProperties.getDiagnosisMetadata().getNonCodedDiagnosisConcept();
StringBuilder sqlQuery = new StringBuilder("select " + " o.value_text as 'nonCodedDiagnosis', " + " o.creator as 'creatorId', " + " n.given_name as 'creatorFirstName', " + " n.family_name as 'creatorLastName', " + " o.date_created as 'dateCreated', " + " o.person_id as 'patientId', " + " id1.identifier as 'patientIdentifier', " + " o.obs_id as 'obsId', " + " e.visit_id as 'visitId', " + " e.encounter_datetime as 'encounterDateTime', " + " n1.given_name as 'patientFirstName', " + " n1.family_name as 'patientLastName'");
sqlQuery.append(" from obs o ");
sqlQuery.append(" inner join patient_identifier as id1 on (o.person_id = id1.patient_id and id1.identifier_type = :primaryIdentifierType ) ");
sqlQuery.append(" inner join encounter as e on (o.encounter_id = e.encounter_id) ");
sqlQuery.append(" inner join users as u on (o.creator = u.user_id) ");
sqlQuery.append(" inner join person_name as n on (u.person_id = n.person_id and n.voided=0) ");
sqlQuery.append(" inner join person_name as n1 on (o.person_id = n1.person_id and n1.voided=0) ");
sqlQuery.append(" ");
sqlQuery.append(" where o.voided = 0 ");
sqlQuery.append(" and o.concept_id = :nonCodedConcept ");
if (fromDate != null) {
sqlQuery.append(" and o.date_created > :startDate ");
}
if (toDate != null) {
sqlQuery.append(" and o.date_created < :endDate ");
}
if (userId != null) {
sqlQuery.append(" and o.creator = :userId ");
}
if (StringUtils.isNotBlank(nonCoded)) {
sqlQuery.append(" and o.value_text like '%").append(nonCoded).append("%'");
}
SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery.toString());
query.setInteger("primaryIdentifierType", primaryIdentifierType.getId());
query.setInteger("nonCodedConcept", nonCodedConcept.getId());
if (fromDate != null) {
query.setTimestamp("startDate", fromDate);
}
if (toDate != null) {
query.setTimestamp("endDate", toDate);
}
if (userId != null) {
query.setInteger("userId", userId);
}
List<Object[]> list = query.list();
SimpleDataSet dataSet = new SimpleDataSet(dataSetDefinition, context);
for (Object[] o : list) {
DataSetRow row = new DataSetRow();
row.addColumnValue(new DataSetColumn("nonCodedDiagnosis", "nonCodedDiagnosis", String.class), o[0]);
row.addColumnValue(new DataSetColumn("creatorId", "creatorId", String.class), o[1]);
row.addColumnValue(new DataSetColumn("creatorFirstName", "creatorFirstName", String.class), o[2]);
row.addColumnValue(new DataSetColumn("creatorLastName", "creatorLastName", String.class), o[3]);
row.addColumnValue(new DataSetColumn("dateCreated", "dateCreated", String.class), o[4]);
row.addColumnValue(new DataSetColumn("patientId", "patientId", String.class), o[5]);
row.addColumnValue(new DataSetColumn("patientIdentifier", "patientIdentifier", String.class), o[6]);
row.addColumnValue(new DataSetColumn("obsId", "obsId", String.class), o[7]);
row.addColumnValue(new DataSetColumn("visitId", "visitId", String.class), o[8]);
row.addColumnValue(new DataSetColumn("encounterDateTime", "encounterDateTime", String.class), o[9]);
row.addColumnValue(new DataSetColumn("patientFirstName", "patientFirstName", String.class), o[10]);
row.addColumnValue(new DataSetColumn("patientLastName", "patientLastName", String.class), o[11]);
dataSet.addRow(row);
}
return dataSet;
}
use of org.openmrs.Provider in project openmrs-module-pihcore by PIH.
the class ConfigurationSetup method setupCommCareUser.
public User setupCommCareUser() {
User user = null;
String commCareUserName = PihCoreUtil.getSystemOrRuntimeProperty("commcare.username", null);
String commCareUserPassword = PihCoreUtil.getSystemOrRuntimeProperty("commcare.password", null);
if (StringUtils.isNotBlank(commCareUserName) && StringUtils.isNotBlank(commCareUserPassword)) {
user = Context.getUserService().getUserByUsername(commCareUserName);
if (user == null) {
// create a new user if one does not already exist
user = new User();
}
user.setUsername(commCareUserName);
Person person = user.getPerson();
if (person == null) {
person = new Person();
person.addName(new PersonName("CommCare", "", "Integration"));
person.setGender("M");
user.setPerson(person);
}
user.addRole(Context.getUserService().getRole("Authenticated"));
user.addRole(Context.getUserService().getRole("Privilege Level: Full"));
if (user.getId() == null) {
// create a new record
user = Context.getUserService().createUser(user, commCareUserPassword);
} else {
// update an existing record
user = Context.getUserService().saveUser(user);
}
person = user.getPerson();
Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
if (providers == null || providers.size() < 1) {
// if the user does not have a Provider yet then create one
Provider provider = new Provider();
provider.setUuid(PihCoreConstants.COMMCARE_PROVIDER_UUID);
provider.setPerson(person);
Context.getProviderService().saveProvider(provider);
}
}
return user;
}
Aggregations