Search in sources :

Example 51 with Provider

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;
}
Also used : Criteria(org.hibernate.Criteria) ProviderAttributeType(org.openmrs.ProviderAttributeType) Provider(org.openmrs.Provider)

Example 52 with Provider

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;
}
Also used : Concept(org.openmrs.Concept) DataSetColumn(org.openmrs.module.reporting.dataset.DataSetColumn) User(org.openmrs.User) SimpleDataSet(org.openmrs.module.reporting.dataset.SimpleDataSet) SQLQuery(org.hibernate.SQLQuery) Date(java.util.Date) Provider(org.openmrs.Provider) NonCodedDiagnosisDataSetDefinition(org.openmrs.module.pihcore.reporting.dataset.definition.NonCodedDiagnosisDataSetDefinition) PatientIdentifierType(org.openmrs.PatientIdentifierType) DataSetRow(org.openmrs.module.reporting.dataset.DataSetRow)

Example 53 with Provider

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;
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person) Provider(org.openmrs.Provider)

Aggregations

Provider (org.openmrs.Provider)53 Test (org.junit.Test)40 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 Encounter (org.openmrs.Encounter)16 Date (java.util.Date)14 Person (org.openmrs.Person)12 Patient (org.openmrs.Patient)9 EncounterType (org.openmrs.EncounterType)8 EncounterRole (org.openmrs.EncounterRole)7 Location (org.openmrs.Location)7 PersonName (org.openmrs.PersonName)7 User (org.openmrs.User)6 TestOrder (org.openmrs.TestOrder)5 Message (ca.uhn.hl7v2.model.Message)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 Concept (org.openmrs.Concept)4 DrugOrder (org.openmrs.DrugOrder)4 Order (org.openmrs.Order)4 OrderUtilTest (org.openmrs.order.OrderUtilTest)4 HashSet (java.util.HashSet)3