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

LBAC-3 Added implementation for assigning the patients to the locations on registration #4

Merged
merged 1 commit into from Jul 3, 2018

Conversation

@suthagar23
Copy link
Member

@suthagar23 suthagar23 commented May 23, 2018

Description

Added implementation for assigning the users to the locations on registration.

  • PatientControlImpl - Contains the code base to register locations for the persons
  • Constants - Included some constants variables for the code usage

Ticket

Ticekt : https://issues.openmrs.org/browse/LBAC-3

Others

  • I was able to compile the project without any failures.
@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 2 times, most recently from f7baf60 to 3a86fc1 May 26, 2018
@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented May 26, 2018

@dkayiwa I have changed this PR with the whole code base for the location assignment while patients registering on the system. Please have a look at here.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from 3a86fc1 to 41eb5cf May 26, 2018
@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented May 26, 2018

Have you tested this from the end user's perspective and proved that it works?

@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented May 27, 2018

Yes @dkayiwa, This implementation is enough to create a personAttribute with accessLocation value in the database.

This implementation will work as shown below,

  • Fetch the accessLocation personAttribute from the logged in user and assign that location to the patient.
  • If the logged in user doesn't have any accessLocation personAttribute(for only beginning), then it will fetch the first location from the system as default.

We can improve this to select the locations by the user for the patients, and can improve to find a default location as well.

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented May 27, 2018

Can you list for me the steps to test this out (from the end user's perspective)?

@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented May 27, 2018

Sure,
Just clone this branch and load this module into the reference application.
Then register a new patient using patient registration form in the dashboard.
(I have disabled the logs here, so you need to check this personAttribute using the database)
Query : select * from person_attribute where person_attribute_type_id=(select * from person_attribute_type A where A.name='accessLocation')

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented May 27, 2018

How do i specify a location, as an end user?

@@ -46,5 +46,10 @@
<file>messages_es.properties</file>
</messages>
<!-- /Internationalization -->

<advice>
<point>org.openmrs.api.PatientService</point>

This comment has been minimized.

@dkayiwa

dkayiwa May 27, 2018
Member

Shouldn't this be on PersonService?

This comment has been minimized.

@suthagar23

suthagar23 May 28, 2018
Author Member

Yes correct, Actually I plan to change it to PersonService while implementing the user location management(To address Patients and Users). I addressed this PR as only for Patients, So I handle only with high-level PatientService.

I will change it to Persons and will update the PR content.

This comment has been minimized.

@dkayiwa

dkayiwa May 29, 2018
Member

I thought PersonService would automatically deal with patients because they are persons. Not so?

This comment has been minimized.

@suthagar23

suthagar23 Jun 18, 2018
Author Member

Nope, AFAIK We need to access this PatientService

/**
* It will used to implement the AOP Methods for PatientServiceImpl class
*/
public class PatientControlImpl extends StaticMethodMatcherPointcutAdvisor implements Advisor {

This comment has been minimized.

@dkayiwa

dkayiwa May 27, 2018
Member

Shouldn't this be named PersonServiceAdvisor?

This comment has been minimized.

@suthagar23

suthagar23 May 28, 2018
Author Member

I will change it to Persons and will update the PR content as I addressed above


public static final String PATIENT_OBJ_NAME = "PATIENT";

public static final String SAVE_PATIENT_METHOD_NAME = "savePatient";

This comment has been minimized.

@suthagar23

suthagar23 May 28, 2018
Author Member

This need to be updated as saveUser to make those changes.

This comment has been minimized.

@dkayiwa

dkayiwa May 29, 2018
Member

We have not yet got to the ticket which deals with users.


public static final String ACCESS_LOCATION_PERSON_ATTRIBUTE_TYPE_NAME = "accessLocation";

public static final String PATIENT_OBJ_NAME = "PATIENT";

This comment has been minimized.

@suthagar23

suthagar23 May 28, 2018
Author Member

This need to be updated as USER to make those changes(To deal with PersonService).

This comment has been minimized.

@dkayiwa

dkayiwa May 29, 2018
Member

Not handled users yet

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from 41eb5cf to 03ec06d Jun 10, 2018
@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jun 10, 2018

@dkayiwa Finally I came up with this PR,

  • If the user already customized their patient registration dashboard with the custom location selection dashboard, then It will automatically save the person attribute (No need of AOP).

  • If the user didn't customize their patient registration dashboard, then the default access location for the new patients will be fetched from the logged in user session location(Using AOP).

Please use this App definition to customize the patient dashboard - https://gist.github.com/suthagar23/f0b92381aec5d0ad6d70e4eb40eb308d

You need the updated appui module to run this part!

image

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 2 times, most recently from 0bb457c to d8fccd4 Jun 10, 2018
@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jun 10, 2018

You are still doing more than what i asked, for the first pass.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 2 times, most recently from 5e8a9e2 to eeeef83 Jun 10, 2018
@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jun 12, 2018

Oh @dkayiwa

I have removed the AOP implementation from this PR. It has a simple implementation to assign the access locations through patient registration dashboard now.

Please use this App definition to customize the patient dashboard - https://gist.github.com/suthagar23/f0b92381aec5d0ad6d70e4eb40eb308d

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jun 12, 2018

No need of any AOP to assign access locations. I think you are still complicating the use case. Let me state this again.

  1. Person attributes are stored normally using the patient registration form which you have configured as such.
  2. When i log in a certain location, i should only see those patients whose person attribute point to that location.

As simple as that. I do not want to see code which implements any thing apart from just that. This is a very simple use case which we can even demonstrate to the client, as concrete progress update.
Does it make sense?

@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jun 12, 2018

Yes @dkayiwa. I totally understood.

It will be a solution for the Case-1.

Then shall I create another ticket for case-2?

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jun 12, 2018

When you ask me about use cases 2 when you are not yet even done with use case 1, i start to think that you are not prioritizing as you should.

@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jun 15, 2018

Oh, I think, you missed my point in the last comment 😁,

I have mentioned
UseCase - 1 as,
Person attributes are stored normally using the patient registration form which you have configured as such.

And Usecase-2 as,
When i log in a certain location, i should only see those patients whose person attribute point to that location

This PR will be a solution for usecase-1 and, I will work to create another PR for usecase-2. Is it alright?

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jun 15, 2018

You pull request title "Added implementation for assigning the patients to the locations on registration" says it is assigning patients to locations. Isn't that supposed to be automatically done by the patient registration form? Do you need it in your pull request?

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from eeeef83 to e0deb09 Jun 16, 2018
@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jun 16, 2018

Ohh @dkayiwa , 😄 I thought to use this PR for only create that accessLocation fragment.

So then, I have updated this PR with filters for PatientSearch. Please have a look again here.

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jun 16, 2018

This pull request still has too much more than the first use case that we are dealing with.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 3 times, most recently from 1ed360a to 0122c94 Jun 22, 2018
return false;
}
else {
if(!personAttribute.getValue().equals(location.getUuid())) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 24, 2018
Member

Is it efficient to call location.getUuid() for each and every patient?

This comment has been minimized.

@suthagar23

suthagar23 Jun 24, 2018
Author Member

We can improve it by replacing UUID.

This comment has been minimized.

@suthagar23

suthagar23 Jun 24, 2018
Author Member

Changed

return patientList;
}

public Boolean isPatientConstainsLocation(Location location, PersonAttribute personAttribute ) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 24, 2018
Member

This method name is still confusing based on its parameters. The grammar of the name is also not correct.
Just get rid of it.

This comment has been minimized.

@suthagar23

suthagar23 Jun 24, 2018
Author Member

Oh, Sorry small mistake on Contains. Let me know if there are any issues with this fixed method name.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 2 times, most recently from cf38324 to f3dc711 Jun 24, 2018
return patientList;
}

public Boolean isPatientContainsLocation(String locationUuid, PersonAttribute personAttribute ) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 24, 2018
Member

Looking at the method name, is there anything in this method that has to do with patient?

This comment has been minimized.

@suthagar23

suthagar23 Jun 24, 2018
Author Member

That's why I thought to replace by isPatientAttributeContainsLocation(). Wha do you think about this name?

This comment has been minimized.

@dkayiwa

dkayiwa Jun 24, 2018
Member

Can you just do a 10 minutes google search about good method names?

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from f3dc711 to ff5d5ed Jun 25, 2018
return patientList;
}

public Boolean compare(String value1, String value2) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 25, 2018
Member

Do we have to make this public?
Can we also reduce the number of return statements in this method?

This comment has been minimized.

@suthagar23

suthagar23 Jun 25, 2018
Author Member

We can make it as private.
I have fixed it as well and reduced the number of returns.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from ff5d5ed to 931e8ed Jun 25, 2018

private Boolean compare(String value1, String value2) {
if (StringUtils.isNotBlank((value1)) && StringUtils.isNotBlank((value2))) {
if(value1.equals(value2)) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 25, 2018
Member

Can you also reduce the number of if statements?

This comment has been minimized.

@suthagar23

suthagar23 Jun 25, 2018
Author Member

Reduced by removing on IF condition

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from 931e8ed to 7f0ef73 Jun 25, 2018
}

private Boolean compare(String value1, String value2) {
if (StringUtils.isNotBlank((value1)) && StringUtils.isNotBlank((value2))) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 25, 2018
Member

Can you reduce to one return statement?

This comment has been minimized.

@suthagar23

suthagar23 Jun 25, 2018
Author Member

Changed

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from 7f0ef73 to fec3b88 Jun 25, 2018
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.*;

This comment has been minimized.

@suthagar23

suthagar23 Jun 25, 2018
Author Member

oh, Sorry for the mistake. I have fixed. Please check again

This comment has been minimized.

@dkayiwa

dkayiwa Jun 25, 2018
Member

Did you see my latest comments on JIRA?

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from fec3b88 to 4a57e1c Jun 25, 2018

for (Iterator<Patient> iterator = patientList.iterator(); iterator.hasNext(); ) {
Patient patient = iterator.next();
if (!compare(patient.getAttribute(personAttributeType).getValue(), sessionLocationUuid)) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 26, 2018
Member

Did you actually test these changes by compiling the module and try to search for patients?

This comment has been minimized.

@suthagar23

suthagar23 Jun 26, 2018
Author Member

Yes @dkayiwa, I have tested with my local deployment. it's working for me (I already created that person attribute type and global property)

This comment has been minimized.

@dkayiwa

dkayiwa Jun 26, 2018
Member

Have you tried searching when you have patients who did not save any value in the location person attribute?

This comment has been minimized.

@suthagar23

suthagar23 Jun 27, 2018
Author Member

Yah, there was an issue on fetching personAttribute for them. I have fixed it and updated the PR.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from 4a57e1c to f9acfe0 Jun 27, 2018
Patient patient = iterator.next();
PersonAttribute personAttribute = patient.getAttribute(personAttributeType);
if( personAttribute != null) {
if (!compare(personAttribute.getValue(), sessionLocationUuid)) {

This comment has been minimized.

@dkayiwa

dkayiwa Jun 27, 2018
Member

Combine these two if statements such that you do not duplicate iterator.remove

This comment has been minimized.

@suthagar23

suthagar23 Jun 27, 2018
Author Member

Changed.

@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch 3 times, most recently from 6f00b92 to ab9d05a Jun 27, 2018

for (Iterator<Patient> iterator = patientList.iterator(); iterator.hasNext(); ) {
Patient patient = iterator.next();
PersonAttribute personAttribute = patient.getAttribute(personAttributeType);

This comment has been minimized.

@dkayiwa

dkayiwa Jun 29, 2018
Member

While testing, i have noticed something. If some one installs the module, but with some patients who do not yet have locations, they will not be listed on search. So how are they supposed to be listed, in order to be able to edit their locations? Any ideas?

This comment has been minimized.

@suthagar23

suthagar23 Jul 2, 2018
Author Member

Updated.
So now, System Administrators can get the patients lists for the logged-in location + patients lists who haven't location attribute. So System Administrators can edit the patient location.
The code base is updated along with this check.

…ns on registration

Removed personAttribute creation

Added fixes for PR comments

PR Review fixes

Added minor fix

Added some fixes according to the PR reviews

Minor fix

Changed the locationCheck method structure

minor fix

Changed method name

Added fixes for PR reviews

Added fixes for PR reviews

Changed method to compare

Changed Compare method

Minor improvements

Minor modifications

Minor fix

Minor fix in the methods

Merged IF conditions

Removed unwanted dependencies

Added appUi to required module

Added user role check for viewing patients
@suthagar23 suthagar23 force-pushed the suthagar23:LBAC-3 branch from ab9d05a to 9d18a97 Jul 2, 2018
@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Jul 2, 2018

Can you also add some unit tests for this functionality?

@dkayiwa dkayiwa merged commit 1da91c5 into openmrs:master Jul 3, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@suthagar23
Copy link
Member Author

@suthagar23 suthagar23 commented Jul 4, 2018

I will follow the unit test methods for AOP Advices and update the unit testing for my work later.

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

Successfully merging this pull request may close these issues.

None yet

2 participants