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

HTML-715 EnrollInProgramTag to support program attributes from 2.2. #167

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

gitcliff
Copy link

@gitcliff gitcliff commented Mar 21, 2020

@OpenmrsProfile(openmrsPlatformVersion = "2.2.*")
public class EnrollInPogramTagHandlerSupport2_2 implements EnrollInPogramTagHandlerSupport {

@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe javadocs could be added here too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure,will add them


public void setPatientProgrmAttributes(FormEntryContext context, Map<String, String> parameters) {

if ("true".equalsIgnoreCase(parameters.get("patientprogramattributes"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitcliff what does the HTML Tag usage look like?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @ssmusoke i did expand the existing <enrollInProgram/> tag to add program attributes to a patient already enrolled

@mks-d mks-d changed the title HTML-715:Add progrm attribute tag to enable setting and updating of v… HTML-715: Add program attribute tag. May 28, 2020
@mks-d mks-d self-requested a review May 28, 2020 07:32
@mks-d mks-d marked this pull request as draft May 28, 2020 07:39
@mks-d mks-d changed the title HTML-715: Add program attribute tag. HTML-715: New restrictToSupportedVisitLocations attribute to EncounterLocation tag. May 28, 2020
@mks-d mks-d changed the title HTML-715: New restrictToSupportedVisitLocations attribute to EncounterLocation tag. HTML-715 New program attribute tag. May 28, 2020
Comment on lines 1 to 129

@RunWith(PowerMockRunner.class)
@PrepareForTest(Context.class)
public class EnrollInProgramTagTest2_2 {

EnrollInProgramElement2_2 element;

private MockHttpServletRequest request;

private Map<String, String> parameters;


private TextFieldWidget patientprogramattrWidget;


@Mock
private FormEntrySession session;

@Mock
private FormEntryContext context;

@Mock
private ProgramWorkflowService programWorkflowService;

@Mock
private PatientService ps;

@Before
public void setup() {
// Stub services
mockStatic(Context.class);
when(Context.getProgramWorkflowService()).thenReturn(programWorkflowService);

// Setup html form session context
when(context.getMode()).thenReturn(Mode.ENTER);
request = new MockHttpServletRequest();
when(session.getContext()).thenReturn(context);


// setup condition element
element = spy(new EnrollInProgramElement2_2(context, parameters));

}

@Test
public void enrollInProgram_shouldGetPatientProgrmAttribute() throws Exception {
//set up
when(patientprogramattrWidget.getValue(context, request)).thenReturn("d7477c21-bfc3-4922-9591-e89d8b9c8efb");

//replay
element.setPatientProgrmAttributes(context, parameters);

Assert.assertNotNull(
programWorkflowService.getPatientProgramAttributeByUuid("d7477c21-bfc3-4922-9591-e89d8b9c8efb"));

//verify
verify(programWorkflowService, times(1))
.getPatientProgramAttributeByUuid("d7477c21-bfc3-4922-9591-e89d8b9c8efb");

}

@Test
public void enrollInProgram_shouldGetPatientProgrmAttributeWithAnInvalidUuid() throws Exception {
// set up
when(patientprogramattrWidget.getValue(context, request)).thenReturn("sjnjfrjvjnwejnfjsbdladmojervje");

// replay
element.setPatientProgrmAttributes(context, parameters);

Assert.assertNull(programWorkflowService.getPatientProgramAttributeByUuid("sjnjfrjvjnwejnfjsbdladmojervje"));

}

@Test
public void handleSubmission_shouldNotCreatePatientProgramAttributeInViewMode() {
// setup
when(context.getMode()).thenReturn(Mode.VIEW);

// replay
element.handleSubmission(session, request);

// verify
verify(programWorkflowService, never())
.getPatientProgramAttributeByUuid("d7477c21-bfc3-4922-9591-e89d8b9c8efb");
}

@Test
public void handleSubmission_shouldNotAddPatientProgramAttributeToAPatientWhoIsNull() {
// setup
when(context.getExistingPatient()).thenReturn(null);

// replay
element.handleSubmission(session, request);

// verify
verify(ps, never()).savePatient(any(Patient.class));

}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitcliff can you work your way to a context-sensitive test like this one?

Your first test would have to show that a program attribute can be set to patient's program.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mks-d thanks,,let me adopt that

@mks-d mks-d changed the title HTML-715 New program attribute tag. HTML-715 EnrollInProgramTag to support program attribute from 2.2. May 28, 2020
@mks-d mks-d changed the title HTML-715 EnrollInProgramTag to support program attribute from 2.2. HTML-715 EnrollInProgramTag to support program attributes from 2.2. May 28, 2020
import org.openmrs.module.htmlformentry.element.EnrollInProgramElement;

@OpenmrsProfile(openmrsPlatformVersion = "2.2.*")
public class EnrollInPogramTagHandlerSupport2_2 implements EnrollInPogramTagHandlerSupport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo → EnrollInProgramTagHandlerSupport2_2 (the typo is "Pogram").

@gitcliff gitcliff force-pushed the HTML-715 branch 2 times, most recently from 7e5133e to 646c762 Compare June 7, 2020 17:30
@gitcliff gitcliff force-pushed the HTML-715 branch 2 times, most recently from f5e5373 to b0195ce Compare June 18, 2020 15:04
@gitcliff gitcliff marked this pull request as ready for review June 29, 2020 12:23
@gracepotma
Copy link

@gitcliff we would like to finish up this work. Can you address the conflicts, and then ask for a reviewer? (You're also welcome to unassign yourself if you have too much other work right now, or ask for help.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants