Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RA-1257]- New Patient Registrations report completed #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,6 +46,8 @@
import org.openmrs.module.referencemetadata.ReferenceMetadataConstants;
import org.openmrs.module.referencemetadata.ReferenceMetadataProperties;
import org.openmrs.module.registrationcore.RegistrationCoreConstants;
import org.openmrs.module.reporting.report.manager.ReportManager;
import org.openmrs.module.reporting.report.manager.ReportManagerUtil;
import org.openmrs.scheduler.SchedulerService;
import org.openmrs.scheduler.TaskDefinition;
import org.openmrs.scheduler.tasks.ProcessHL7InQueueTask;
Expand Down Expand Up @@ -105,6 +107,9 @@ public void started() {
setupTagLocation(ReferenceMetadataConstants.VISIT_LOCATION_TAG_UUID);
setupHtmlForms();
setupHL7ProcessingTask(schedulerService);

//setup built-in reports from #org.openmrs.module.referenceapplication.reports
ReportManagerUtil.setupAllReports(ReportManager.class);
}
catch (Exception e) {
Module mod = ModuleFactory.getModuleById(ReferenceApplicationConstants.MODULE_ID);
Expand Down
@@ -0,0 +1,64 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.referenceapplication.reporting.definition.library;

import org.openmrs.module.referenceapplication.reporting.definition.util.ParameterFactory;
import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
import org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition;
import org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition;
import org.openmrs.module.reporting.common.ObjectUtil;
import org.openmrs.module.reporting.definition.library.BaseDefinitionLibrary;
import org.openmrs.module.reporting.definition.library.DocumentedDefinition;
import org.springframework.stereotype.Component;
import java.util.Map;

@Component
public class CohortDefinitionLibrary extends BaseDefinitionLibrary<CohortDefinition> {

@Override
public Class<? super CohortDefinition> getDefinitionType() {
return CohortDefinition.class;
}

@Override
public String getKeyPrefix() {
return null;
}

@DocumentedDefinition(value = "activePatientRegistrationsByDatePeriod")
public CohortDefinition getActivePatientRegistrationsByDatePeriod() {

//By default it will return only active patients
SqlCohortDefinition def = new SqlCohortDefinition();
def.setQuery(getPatientCreatedQuery());
def.addParameter(ParameterFactory.getStartDate("Start Date for registrations"));
def.addParameter(ParameterFactory.getEndDate("End Date for registrations"));

return convert(def, ObjectUtil.toMap("startDate=startDate,endDate=endDate"));
}

private String getPatientCreatedQuery(){
StringBuilder sb = new StringBuilder();
sb.append("SELECT p.patient_id ")
.append("FROM patient p ")
.append("WHERE p.date_created >= :startDate ")
.append("AND p.date_created <= :endDate ");

return sb.toString();
}

public CohortDefinition convert(CohortDefinition cd, Map<String, String> renamedParameters) {
return new MappedParametersCohortDefinition(cd, renamedParameters);
}
}
@@ -0,0 +1,100 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.referenceapplication.reporting.definition.library;

import org.openmrs.PatientIdentifier;
import org.openmrs.PatientIdentifierType;
import org.openmrs.module.metadatadeploy.MetadataUtils;
import org.openmrs.module.referenceapplication.reporting.definition.util.MetadataConstants;
import org.openmrs.module.reporting.common.ObjectUtil;
import org.openmrs.module.reporting.data.converter.DataConverter;
import org.openmrs.module.reporting.data.converter.PropertyConverter;
import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition;
import org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition;
import org.openmrs.module.reporting.data.patient.definition.PersonToPatientDataDefinition;
import org.openmrs.module.reporting.data.patient.definition.PreferredIdentifierDataDefinition;
import org.openmrs.module.reporting.data.patient.definition.SqlPatientDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.library.BaseDefinitionLibrary;
import org.openmrs.module.reporting.definition.library.DocumentedDefinition;
import org.openmrs.module.reporting.evaluation.parameter.Parameter;
import org.openmrs.module.reporting.evaluation.parameter.ParameterizableUtil;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

@Component
public class PatientDataDefinitionLibrary extends BaseDefinitionLibrary<PatientDataDefinition> {

@Override
public Class<? super PatientDataDefinition> getDefinitionType() {
return null;
}

@Override
public String getKeyPrefix() {
return null;
}

@DocumentedDefinition("date_created")
public PatientDataDefinition getDateCreated() {
SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition();
sqlPatientDataDefinition.addParameter(new Parameter("startDate", "Start Date for date_created", Date.class));
sqlPatientDataDefinition.addParameter(new Parameter("endDate", "End Date for date_created", Date.class));
sqlPatientDataDefinition.setSql(getDateCreatedDefinitionSQLQuery());

return convert(sqlPatientDataDefinition, ObjectUtil.toMap("startDate=startDate,endDate=endDate"), null);
}

private String getDateCreatedDefinitionSQLQuery(){
StringBuilder sb = new StringBuilder();
sb.append("SELECT patient_id, date_created ")
.append("FROM patient ")
.append("WHERE date_created >= :startDate ")
.append("AND date_created <= :endDate");

return sb.toString();
}

@DocumentedDefinition("openmrsId")
public PatientDataDefinition getOpenmrsId() {
PreferredIdentifierDataDefinition def = new PreferredIdentifierDataDefinition();
def.setIdentifierType(MetadataUtils.existing(PatientIdentifierType.class, MetadataConstants.OPENMRS_ID));
return convert(def, new PropertyConverter(PatientIdentifier.class, "identifier"));
}

public PatientDataDefinition convert(PatientDataDefinition pdd, Map<String, String> renamedParameters, DataConverter converter) {
ConvertedPatientDataDefinition convertedDefinition = new ConvertedPatientDataDefinition();
convertedDefinition.setDefinitionToConvert(ParameterizableUtil.copyAndMap(pdd, convertedDefinition, renamedParameters));
if (converter != null) {
convertedDefinition.setConverters(Arrays.asList(converter));
}
return convertedDefinition;
}

public PatientDataDefinition convert(PatientDataDefinition pdd, DataConverter converter) {
return convert(pdd, null, converter);
}

public PatientDataDefinition convert(PersonDataDefinition pdd, Map<String, String> renamedParameters, DataConverter converter) {
return convert(new PersonToPatientDataDefinition(pdd), renamedParameters, converter);
}

public PatientDataDefinition convert(PersonDataDefinition pdd, DataConverter converter) {
return convert(pdd, null, converter);
}

}
@@ -0,0 +1,22 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.referenceapplication.reporting.definition.util;


public class MetadataConstants {

// Identifier Types
public static final String OPENMRS_ID = "05a29f94-c0ed-11e2-94be-8c13b969e334";

}
@@ -0,0 +1,29 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.referenceapplication.reporting.definition.util;

import org.openmrs.module.reporting.evaluation.parameter.Parameter;

import java.util.Date;

public class ParameterFactory {

public static Parameter getStartDate(String label){
return new Parameter("startDate", label, Date.class);
}

public static Parameter getEndDate(String label){
return new Parameter("endDate", label, Date.class);
}
}
@@ -0,0 +1,97 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.referenceapplication.reporting.reports;

import org.openmrs.module.reporting.ReportingConstants;
import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition;
import org.openmrs.module.reporting.evaluation.parameter.Mapped;
import org.openmrs.module.reporting.evaluation.parameter.Parameter;
import org.openmrs.module.reporting.report.ReportDesign;
import org.openmrs.module.reporting.report.definition.ReportDefinition;
import org.openmrs.module.reporting.report.manager.BaseReportManager;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ListOfDiagnosis extends BaseReportManager {

public ListOfDiagnosis() {
}

@Override
public String getUuid() {
return "e451ae04-4881-11e7-a919-92ebcb67fe33";
}

@Override
public String getName() {
return "List of Diagnosis";
}

@Override
public String getDescription() {
return "List all diagnosis's for a given date range along with the count";
}

@Override
public List<Parameter> getParameters() {
List<Parameter> parameterArrayList = new ArrayList<Parameter>();
parameterArrayList.add(ReportingConstants.START_DATE_PARAMETER);
parameterArrayList.add(ReportingConstants.END_DATE_PARAMETER);
return parameterArrayList;
}

@Override
public ReportDefinition constructReportDefinition() {
ReportDefinition reportDef = new ReportDefinition();
reportDef.setUuid(getUuid());
reportDef.setName(getName());
reportDef.setDescription(getDescription());
reportDef.setParameters(getParameters());

SqlDataSetDefinition sqlDataDef = new SqlDataSetDefinition();
sqlDataDef.setName(getName());
sqlDataDef.addParameters(getParameters());
sqlDataDef.setSqlQuery(getSQLQuery());

reportDef.addDataSetDefinition("listOfDiagnosis", Mapped.mapStraightThrough(sqlDataDef));


return reportDef;
}

@Override
public List<ReportDesign> constructReportDesigns(ReportDefinition reportDefinition) {
return null;
}

@Override
public String getVersion() {
return "1.0";
}

private String getSQLQuery(){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("select cn.name, count(*) as 'count' ");
stringBuilder.append("from obs, concept_name cn ");
stringBuilder.append("where obs.concept_id = (select concept_id from concept where uuid='1284AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') ");
stringBuilder.append("and value_coded= cn.concept_id and ");
stringBuilder.append("locale='en' and ");
stringBuilder.append("locale_preferred = '1' ");
stringBuilder.append("and obs.date_created >= :startDate ");
stringBuilder.append("and obs.date_created <= :endDate ");
stringBuilder.append("group by value_coded, cn.name ");
stringBuilder.append("order by count(*) desc ");

return stringBuilder.toString();
}
}