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

BAH-3413 | Upgrading OpenMRS version to 2.5.7 and Bahmni java util version #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement-api</artifactId>
<version>1.1.3</version>
<version>2.13.0</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement-api</artifactId>
<version>1.1.3</version>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.openmrs.module.bahmniendtb;

import org.apache.commons.collections.CollectionUtils;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.PatientProgramAttribute;
import org.bahmni.module.bahmnicore.service.BahmniProgramServiceValidator;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.openmrs.PatientProgram;
import org.openmrs.PatientProgramAttribute;
import org.openmrs.api.APIException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -25,19 +24,19 @@ public EndTbProgramServiceValidator(BahmniProgramWorkflowService bahmniProgramWo

@Override
public void validate(PatientProgram patientProgram) throws APIException {
for (PatientProgramAttribute patientProgramAttribute : ((BahmniPatientProgram) patientProgram).getAttributes()) {
for (PatientProgramAttribute patientProgramAttribute : patientProgram.getAttributes()) {
if (PROGRAM_ATTRIBUTE_REG_NO.equals(patientProgramAttribute.getAttributeType().getName())) {
List<BahmniPatientProgram> bahmniPatientPrograms = bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(PROGRAM_ATTRIBUTE_REG_NO, (String) patientProgramAttribute.getValue());
if (isPatientProgramPresent(patientProgram, bahmniPatientPrograms)) {
List<PatientProgram> patientPrograms = bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(PROGRAM_ATTRIBUTE_REG_NO, (String) patientProgramAttribute.getValue());
if (isPatientProgramPresent(patientProgram, patientPrograms)) {
throw new APIException("Registration number is already used for another Treatment");
}
}
}
}

private boolean isPatientProgramPresent(PatientProgram patientProgram, List<BahmniPatientProgram> bahmniPatientPrograms) {
private boolean isPatientProgramPresent(PatientProgram patientProgram, List<PatientProgram> bahmniPatientPrograms) {
if(CollectionUtils.isNotEmpty(bahmniPatientPrograms)) {
for(BahmniPatientProgram bahmniPatientProgram : bahmniPatientPrograms) {
for(PatientProgram bahmniPatientProgram : bahmniPatientPrograms) {
if(!bahmniPatientProgram.getUuid().equals(patientProgram.getUuid())) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.bahmni.csv.EntityPersister;
import org.bahmni.csv.Messages;
import org.bahmni.module.admin.csv.persister.EncounterPersister;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.openmrs.Patient;
import org.openmrs.PatientProgram;
import org.openmrs.Visit;
import org.openmrs.api.VisitService;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -84,22 +84,22 @@ public Messages persist(SaeEncounterRow saeEncounterRow) {

importConditions(saeEncounterRow);

List<BahmniPatientProgram> bahmniPatientPrograms = bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(REGISTRATION_NUMBER, saeEncounterRow.registrationNumber);
List<PatientProgram> patientPrograms = bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(REGISTRATION_NUMBER, saeEncounterRow.registrationNumber);

if(CollectionUtils.isEmpty(bahmniPatientPrograms)) {
if(CollectionUtils.isEmpty(patientPrograms)) {
return noMatchingPatientProgramFound(saeEncounterRow);
}

BahmniPatientProgram bahmniPatientProgram = bahmniPatientPrograms.get(0);
Patient patient = bahmniPatientProgram.getPatient();
PatientProgram patientProgram = patientPrograms.get(0);
Patient patient = patientProgram.getPatient();
List<Visit> visits = visitService.getVisitsByPatient(patient, false, false);
Visit latestVisit = visits.get(0);

BahmniEncounterTransaction bahmniEncounterTransaction = bahmniSaeEncounterTransactionImportService.getSaeEncounterTransaction(saeEncounterRow, patient, bahmniPatientProgram.getUuid());
BahmniEncounterTransaction bahmniEncounterTransaction = bahmniSaeEncounterTransactionImportService.getSaeEncounterTransaction(saeEncounterRow, patient, patientProgram.getUuid());
if(bahmniEncounterTransaction == null) {
return noMatchingSaeFormFound(saeEncounterRow);
}
bahmniEncounterTransaction.setPatientProgramUuid(bahmniPatientProgram.getUuid());
bahmniEncounterTransaction.setPatientProgramUuid(patientProgram.getUuid());
bahmniEncounterTransaction.setLocationUuid(loginUuid);
bahmniEncounterTransactionService.save(bahmniEncounterTransaction, patient, latestVisit.getStartDatetime(), latestVisit.getStopDatetime());
return new Messages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import org.apache.commons.lang3.StringUtils;
import org.bahmni.flowsheet.ui.FlowsheetUI;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.openmrs.Concept;
import org.openmrs.OrderType;
import org.openmrs.PatientIdentifierType;
import org.openmrs.PatientProgram;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.ConceptService;
import org.openmrs.api.OrderService;
Expand Down Expand Up @@ -61,13 +61,13 @@ public class PatientMonitoringFlowsheetController extends BaseRestController {
public FlowsheetUI retrievePatientFlowSheet(@RequestParam("patientProgramUuid") String patientProgramUuid,
@RequestParam(value="startDate", required = false) String startDateStr,
@RequestParam(value="stopDate", required = false) String endDateStr) throws Exception {
BahmniPatientProgram bahmniPatientProgram = (BahmniPatientProgram) Context.getService(BahmniProgramWorkflowService.class).getPatientProgramByUuid(patientProgramUuid);
PatientProgram patientPrograms = Context.getService(BahmniProgramWorkflowService.class).getPatientProgramByUuid(patientProgramUuid);


Date startDate = StringUtils.isNotEmpty(startDateStr) ? new SimpleDateFormat("yyyy-MM-dd").parse(startDateStr) : null;
Date endDate = StringUtils.isNotEmpty(endDateStr) ? new SimpleDateFormat("yyyy-MM-dd").parse(endDateStr) : null;

return patientMonitoringFlowsheetService.getFlowsheetForPatientProgram(bahmniPatientProgram, startDate, endDate, Context.getAdministrationService().getGlobalProperty(PATIENT_MONITORING_CONFIG_LOCATION));
return patientMonitoringFlowsheetService.getFlowsheetForPatientProgram(patientPrograms, startDate, endDate, Context.getAdministrationService().getGlobalProperty(PATIENT_MONITORING_CONFIG_LOCATION));
}

@RequestMapping(value= baseUrl + "/patientFlowsheetAttributes", method = RequestMethod.GET)
Expand All @@ -76,13 +76,13 @@ public FlowsheetAttribute retrieveFlowsheetAttributes(@RequestParam("patientProg

PatientIdentifierType primaryIdentifierType = patientService.getPatientIdentifierTypeByUuid(administrationService.getGlobalProperty(EMR_PRIMARY_IDENTIFIER_TYPE));
OrderType orderType = orderService.getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
BahmniPatientProgram bahmniPatientProgram = (BahmniPatientProgram) Context.getService(BahmniProgramWorkflowService.class).getPatientProgramByUuid(patientProgramUuid);
PatientProgram patientPrograms = Context.getService(BahmniProgramWorkflowService.class).getPatientProgramByUuid(patientProgramUuid);

Set<Concept> conceptsForDrugs = new HashSet<>();
conceptsForDrugs.add(conceptService.getConceptByName(EndTBConstants.DRUG_BDQ));
conceptsForDrugs.add(conceptService.getConceptByName(EndTBConstants.DRUG_DELAMANID));

return patientMonitoringFlowsheetService.getFlowsheetAttributesForPatientProgram(bahmniPatientProgram, primaryIdentifierType, orderType, conceptsForDrugs);
return patientMonitoringFlowsheetService.getFlowsheetAttributesForPatientProgram(patientPrograms, primaryIdentifierType, orderType, conceptsForDrugs);
}

@RequestMapping(value= baseUrl + "/startDateForDrugs", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bahmni.flowsheet.config.FlowsheetConfig;
import org.bahmni.flowsheet.definition.models.FlowsheetDefinition;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.openmrs.Concept;
import org.openmrs.OrderType;
import org.openmrs.PatientIdentifierType;
Expand All @@ -16,7 +15,7 @@
public interface PatientMonitoringFlowsheetService {
FlowsheetUI getFlowsheetForPatientProgram(PatientProgram patientProgram, Date startDate, Date endDate, String configFilePath) throws Exception;

FlowsheetAttribute getFlowsheetAttributesForPatientProgram(BahmniPatientProgram bahmniPatientProgram, PatientIdentifierType patientIdentifierType, OrderType orderType, Set<Concept> concepts);
FlowsheetAttribute getFlowsheetAttributesForPatientProgram(PatientProgram patientPrograms, PatientIdentifierType patientIdentifierType, OrderType orderType, Set<Concept> concepts);

Date getStartDateForDrugConcepts(String patientProgramUuid, Set<String> drugConcepts, OrderType orderType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.bahmni.flowsheet.definition.models.QuestionDefinition;
import org.bahmni.module.bahmnicore.dao.ObsDao;
import org.bahmni.module.bahmnicore.dao.OrderDao;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.PatientProgramAttribute;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.openmrs.*;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -136,22 +134,22 @@ public FlowsheetDefinition getFlowsheetDefinitionFromConfig(FlowsheetConfig flow


@Override
public FlowsheetAttribute getFlowsheetAttributesForPatientProgram(BahmniPatientProgram bahmniPatientProgram, PatientIdentifierType primaryIdentifierType, OrderType orderType, Set<Concept> concepts) {
public FlowsheetAttribute getFlowsheetAttributesForPatientProgram(PatientProgram patientPrograms, PatientIdentifierType primaryIdentifierType, OrderType orderType, Set<Concept> concepts) {
FlowsheetAttribute flowsheetAttribute = new FlowsheetAttribute();
List<Obs> startDateConceptObs = obsDao.getObsByPatientProgramUuidAndConceptNames(bahmniPatientProgram.getUuid(), Arrays.asList(EndTBConstants.TI_TREATMENT_START_DATE), null, null, null, null);
List<Obs> startDateConceptObs = obsDao.getObsByPatientProgramUuidAndConceptNames(patientPrograms.getUuid(), Arrays.asList(EndTBConstants.TI_TREATMENT_START_DATE), null, null, null, null);
Date startDate = null;
if (CollectionUtils.isNotEmpty(startDateConceptObs)) {
startDate = startDateConceptObs.get(0).getValueDate();
}
Date newDrugTreatmentStartDate = getNewDrugTreatmentStartDate(bahmniPatientProgram.getUuid(), orderType, concepts);
List<Obs> consentForEndTbStudyObs = obsDao.getObsByPatientProgramUuidAndConceptNames(bahmniPatientProgram.getUuid(), Arrays.asList(EndTBConstants.FSN_TI_ENDTB_STUDY_CONSENT_QUESTION), null, null, null, null);
Date newDrugTreatmentStartDate = getNewDrugTreatmentStartDate(patientPrograms.getUuid(), orderType, concepts);
List<Obs> consentForEndTbStudyObs = obsDao.getObsByPatientProgramUuidAndConceptNames(patientPrograms.getUuid(), Arrays.asList(EndTBConstants.FSN_TI_ENDTB_STUDY_CONSENT_QUESTION), null, null, null, null);
String consentForEndTbStudy = null;

if (CollectionUtils.isNotEmpty(consentForEndTbStudyObs)) {
consentForEndTbStudy = consentForEndTbStudyObs.get(0).getValueCoded().getShortNameInLocale(Context.getUserContext().getLocale()).getName();
}

List<Obs> hivSeroStatusObs = obsDao.getObsByPatientProgramUuidAndConceptNames(bahmniPatientProgram.getUuid(), Arrays.asList(EndTBConstants.BASLINE_HIV_SEROSTATUS_RESULT, EndTBConstants.LAB_HIV_TEST_RESULT), null, null, null, null);
List<Obs> hivSeroStatusObs = obsDao.getObsByPatientProgramUuidAndConceptNames(patientPrograms.getUuid(), Arrays.asList(EndTBConstants.BASLINE_HIV_SEROSTATUS_RESULT, EndTBConstants.LAB_HIV_TEST_RESULT), null, null, null, null);
String hivStatus = null;

if (CollectionUtils.isNotEmpty(hivSeroStatusObs)) {
Expand All @@ -164,14 +162,14 @@ public FlowsheetAttribute getFlowsheetAttributesForPatientProgram(BahmniPatientP
if (startDate != null) {
Date minDate = DateUtils.addDays(startDate, -90);
Date maxDate = DateUtils.addDays(startDate, 30);
List<Obs> baslineXrayObs = obsDao.getObsByPatientProgramUuidAndConceptNames(bahmniPatientProgram.getUuid(), Arrays.asList(EndTBConstants.XRAY_EXTENT_OF_DISEASE), null, null, null, null);
List<Obs> baslineXrayObs = obsDao.getObsByPatientProgramUuidAndConceptNames(patientPrograms.getUuid(), Arrays.asList(EndTBConstants.XRAY_EXTENT_OF_DISEASE), null, null, null, null);
baselineXRayStatus = isObsDatePresentWithinDateRange(minDate, maxDate, baslineXrayObs);
}

flowsheetAttribute.setNewDrugTreatmentStartDate(newDrugTreatmentStartDate);
flowsheetAttribute.setMdrtbTreatmentStartDate(startDate);
flowsheetAttribute.setTreatmentRegistrationNumber(getProgramAttribute(bahmniPatientProgram, EndTBConstants.PROGRAM_ATTRIBUTE_REG_NO));
flowsheetAttribute.setPatientEMRID(bahmniPatientProgram.getPatient().getPatientIdentifier(primaryIdentifierType).getIdentifier());
flowsheetAttribute.setTreatmentRegistrationNumber(getProgramAttribute(patientPrograms, EndTBConstants.PROGRAM_ATTRIBUTE_REG_NO));
flowsheetAttribute.setPatientEMRID(patientPrograms.getPatient().getPatientIdentifier(primaryIdentifierType).getIdentifier());
flowsheetAttribute.setConsentForEndtbStudy(consentForEndTbStudy);
flowsheetAttribute.setHivStatus(hivStatus);
flowsheetAttribute.setBaselineXRayStatus(baselineXRayStatus);
Expand Down Expand Up @@ -236,8 +234,8 @@ private Date getNewDrugTreatmentStartDate(String patientProgramUuid, OrderType o
return null;
}

private String getProgramAttribute(BahmniPatientProgram bahmniPatientProgram, String attribute) {
for (PatientProgramAttribute patientProgramAttribute : bahmniPatientProgram.getActiveAttributes()) {
private String getProgramAttribute(PatientProgram patientPrograms, String attribute) {
for (PatientProgramAttribute patientProgramAttribute : patientPrograms.getActiveAttributes()) {
if (patientProgramAttribute.getAttributeType().getName().equals(attribute))
return patientProgramAttribute.getValueReference();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.openmrs.module.bahmniendtb;

import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.PatientProgramAttribute;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.ProgramAttributeType;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.openmrs.PatientProgram;
import org.openmrs.PatientProgramAttribute;
import org.openmrs.ProgramAttributeType;
import org.openmrs.api.APIException;

import java.util.Arrays;
Expand All @@ -33,7 +32,7 @@ public void setUp() {

@Test(expected=APIException.class)
public void shouldThrowExceptionIfRegistrationNumberAlreadyPresentForAProgram() {
when(bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(any(String.class), any(String.class))).thenReturn(Arrays.asList((BahmniPatientProgram) getPatientProgram()));
when(bahmniProgramWorkflowService.getPatientProgramByAttributeNameAndValue(any(String.class), any(String.class))).thenReturn(Arrays.asList(getPatientProgram()));
endTbProgramServiceValidator.validate(getPatientProgram());
}

Expand All @@ -45,9 +44,9 @@ private PatientProgram getPatientProgram() {
patientProgramAttribute.setValue("123");
patientProgramAttribute.setAttributeType(programAttributeType);

BahmniPatientProgram bahmniPatientProgram = new BahmniPatientProgram();
bahmniPatientProgram.setAttribute(patientProgramAttribute);
PatientProgram patientPrograms = new PatientProgram();
patientPrograms.setAttribute(patientProgramAttribute);

return bahmniPatientProgram;
return patientPrograms;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.bahmni.flowsheet.api.models.Milestone;
import org.bahmni.flowsheet.ui.FlowsheetUI;
import org.bahmni.module.bahmnicore.model.bahmniPatientProgram.BahmniPatientProgram;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -61,14 +60,14 @@ public void setUp() throws Exception {

@Test
public void shouldSetFlowsheetAttributes() {
BahmniPatientProgram bahmniPatientProgram = (BahmniPatientProgram) bahmniProgramWorkflowService.getPatientProgramByUuid("dfdfoifo-dkcd-475d-b939-6d82327f36a3");
PatientProgram patientPrograms = bahmniProgramWorkflowService.getPatientProgramByUuid("dfdfoifo-dkcd-475d-b939-6d82327f36a3");
PatientIdentifierType patientIdentifierType = patientService.getPatientIdentifierTypeByUuid(administrationService.getGlobalProperty(BAHMNI_PRIMARY_IDENTIFIER_TYPE));
OrderType orderType = orderService.getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
Set<Concept> conceptsForDrugs = new HashSet<>();
conceptsForDrugs.add(conceptService.getConceptByName(EndTBConstants.DRUG_BDQ));
conceptsForDrugs.add(conceptService.getConceptByName(EndTBConstants.DRUG_DELAMANID));

FlowsheetAttribute flowsheetAttribute = patientMonitoringFlowsheetService.getFlowsheetAttributesForPatientProgram(bahmniPatientProgram, patientIdentifierType, orderType, conceptsForDrugs);
FlowsheetAttribute flowsheetAttribute = patientMonitoringFlowsheetService.getFlowsheetAttributesForPatientProgram(patientPrograms, patientIdentifierType, orderType, conceptsForDrugs);

assertEquals("ARM10021", flowsheetAttribute.getPatientEMRID());
assertEquals("2016-09-16 00:00:00.0", flowsheetAttribute.getMdrtbTreatmentStartDate().toString());
Expand Down
Loading