Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,15 @@ public void execute(Encounter encounter, User currentUser, Date currentDate, Str
}

ProgramWorkflowState targetState = null;
boolean isReachedTargetGoalWeightStateFromMalnutritionStatusValue = false;

if (malnutritionStatusValue != null) {
targetState = Utils.getStateByConcept(programWorkflow, malnutritionStatusValue);
if (targetState == null) {
return;
}
if (targetState.getConcept().getUuid().equalsIgnoreCase(LampConfig.CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID)) {
isReachedTargetGoalWeightStateFromMalnutritionStatusValue = true;
}
}

if (reasonForDischargeValue != null) {
targetState = Utils.getStateByConcept(programWorkflow, reasonForDischargeValue);
if (targetState == null) {
return;
}
if (targetState.getConcept().getUuid().equalsIgnoreCase(LampConfig.CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID)) {
isReachedTargetGoalWeightStateFromMalnutritionStatusValue = false;
}
}

if (isReachedTargetGoalWeightStateFromMalnutritionStatusValue) {
targetState.setTerminal(false);
if (targetState == null) {
return;
}

PatientState patientState = patientProgram.getCurrentState(programWorkflow);
Expand Down
2 changes: 0 additions & 2 deletions api/src/main/java/org/openmrs/module/lamp/LampConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class LampConfig {

public static final String CHILD_NUTRITION_ENCOUNTER_TYPE_UUID = "a46c50d1-f8f2-4b73-9940-7e77c64bcffc";

public static final String CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID = "0a947c3b-ac0a-42af-9299-674620dc7a6d";

public static final String CONCEPT_CHILD_NUTRITION_REASON_FOR_DISCHARGE_UUID = "a7781567-2c1e-4bfd-ad3a-182915722916";

public static final String CONCEPT_CHILD_NUTRITION_MALNUTRITION_STATUS_UUID = "0ae3326d-592b-4ce0-a523-6e03bbe99b69";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openmrs.module.lamp;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -236,49 +235,7 @@ public void shouldExitWhenTargetStateFromReasonForDischargeValueIsNull() {
}

@Test
public void shouldNotSetDateCompletedWhenReachedTargetFromMalnutritionStatus() {
Encounter encounter = buildEncounter(true);
Date now = new Date();
Program program = new Program();
when(mockProgramWorkflowService.getProgramByUuid(LampConfig.PROGRAM_CHILD_NUTRITION_UUID)).thenReturn(program);

Concept malC = new Concept(101);
Concept reasonC = new Concept(102);
when(mockConceptService.getConceptByUuid(LampConfig.CONCEPT_CHILD_NUTRITION_MALNUTRITION_STATUS_UUID)).thenReturn(
malC);
when(mockConceptService.getConceptByUuid(LampConfig.CONCEPT_CHILD_NUTRITION_REASON_FOR_DISCHARGE_UUID)).thenReturn(
reasonC);

PatientProgram pp = new PatientProgram();
PowerMockito.when(
Utils.getOrCreateActiveProgramEnrollment(eq(mockProgramWorkflowService), eq(encounter.getPatient()),
eq(program), any(Date.class))).thenReturn(pp);

Concept malValue = new Concept(201);
malValue.setUuid(LampConfig.CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID);
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, malC)).thenReturn(malValue);
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, reasonC)).thenReturn(null);

ProgramWorkflow wf = new ProgramWorkflow();
PowerMockito.when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_CHILD_NUTRITION_UUID)).thenReturn(wf);

ProgramWorkflowState state = new ProgramWorkflowState();
state.setConcept(malValue);
PowerMockito.when(Utils.getStateByConcept(wf, malValue)).thenReturn(state);

childNutritionProgramStrategy.execute(encounter, new User(), now, "reason");

// dateCompleted should NOT be set because it came from malnutrition path
assertNull(pp.getDateCompleted());
assertFalse(state.getTerminal());

// transition & save
assertEquals(encounter.getLocation(), pp.getLocation());
verify(mockProgramWorkflowService, times(1)).savePatientProgram(pp);
}

@Test
public void shouldSetDateCompletedWhenReachedTargetFromReasonForDischarge() {
public void shouldSetDateCompletedWhenReachedTargetWeight() {
Encounter encounter = buildEncounter(true);
Date now = new Date();
Program program = new Program();
Expand All @@ -300,7 +257,6 @@ public void shouldSetDateCompletedWhenReachedTargetFromReasonForDischarge() {
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, malC)).thenReturn(null);

Concept reasonValue = new Concept(301);
reasonValue.setUuid(LampConfig.CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID);
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, reasonC)).thenReturn(reasonValue);

ProgramWorkflow wf = new ProgramWorkflow();
Expand Down