-
Notifications
You must be signed in to change notification settings - Fork 226
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-842: Add Appointments tag #302
Conversation
@@ -28,6 +28,9 @@ | |||
import org.openmrs.Relationship; | |||
import org.openmrs.api.ObsService; | |||
import org.openmrs.api.context.Context; | |||
import org.openmrs.module.appointments.model.Appointment; | |||
import org.openmrs.module.appointments.model.AppointmentStatus; | |||
import org.openmrs.module.appointments.service.AppointmentsService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure these imports don't cause problems when HFE is run in an environment that does not have the appointments module loaded? I would be concerned that this might be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point, thanks @mseaton
api/src/main/java/org/openmrs/module/htmlformentry/FormSubmissionActions.java
Show resolved
Hide resolved
// first, get all scheduled appointments for this patient | ||
AppointmentSearchRequest request = new AppointmentSearchRequest(); | ||
request.setPatientUuid(patient.getUuid()); | ||
request.setStartDate(new DateTime().minusYears(1000).toDate()); // hack, we want all appts for patient regardless of start date, but the search method always returns null if start date is null; this will start to fail in a thousand years |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like something we should ticket and fix in the appointments module - can you ticket that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appointments.sort(Comparator.comparing(Appointment::getStartDateTime).reversed()); | ||
|
||
// in VIEW mode, only show appointments linked to encounter; in EDIT mode show those linked to encounter and all scheduled appts | ||
appointments.removeIf(appointment -> (context.getMode() == FormEntryContext.Mode.VIEW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure, reading this, that this does what the comment says it should do. Even if it does, I'd favor code that is easier to understand, even if it takes more statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will break up into a VIEW and a ENTER/EDIT component
// this is to ensure that this widget consistently increments the field name sequential value only once, | ||
// otherwise, if the number of matches appointments changed between when the form was opened and the form was saved, | ||
// widget names would be inconsistent, wreaking havoc on the form | ||
int i = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused as to why you would use a sequential integer here that you have to hope is the same on render and submission. Why not just use the primary key of the appointment itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair... will correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// this is to ensure that this widget consistently increments the field name sequential value only once, | ||
// otherwise, if the number of matches appointments changed between when the form was opened and the form was saved, | ||
// widget names would be inconsistent, wreaking havoc on the form | ||
int i = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair... will correct.
// first, get all scheduled appointments for this patient | ||
AppointmentSearchRequest request = new AppointmentSearchRequest(); | ||
request.setPatientUuid(patient.getUuid()); | ||
request.setStartDate(new DateTime().minusYears(1000).toDate()); // hack, we want all appts for patient regardless of start date, but the search method always returns null if start date is null; this will start to fail in a thousand years |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appointments.sort(Comparator.comparing(Appointment::getStartDateTime).reversed()); | ||
|
||
// in VIEW mode, only show appointments linked to encounter; in EDIT mode show those linked to encounter and all scheduled appts | ||
appointments.removeIf(appointment -> (context.getMode() == FormEntryContext.Mode.VIEW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will break up into a VIEW and a ENTER/EDIT component
* Entry Session to avoid runtime class loading issues in instances where the Appointments module is | ||
* not present | ||
*/ | ||
public class AppointmentsAbstractor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to take suggestions of a better name for this class!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, just one or two things that I noticed that should be fixed. Nice work!
@@ -19,6 +19,7 @@ | |||
import org.openmrs.ProgramWorkflowState; | |||
import org.openmrs.Relationship; | |||
import org.openmrs.api.context.Context; | |||
import org.openmrs.module.appointments.model.Appointment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have this stray import here. Can you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, I noticed a couple days ago that my editor wasn't removing all imports, not quite sure what is going on
&& appointment.getFulfillingEncounters().contains(context.getExistingEncounter())) { | ||
checkboxWidget.setInitialValue(appointment.getUuid()); | ||
} | ||
context.registerWidget(checkboxWidget, fieldName + "_" + appointment.getUuid()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have just used appointment.id, rather than uuid, as it is more concise and if you need to use it in JS on the client side there will be less issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough
Thanks for all the comments, I had to fix one Github Copilot AI autocomplete error as well... :) Merging in... |
Description of what I changed
Issue I worked on
see https://issues.openmrs.org/browse/HTML-
Checklist: I completed these to help reviewers :)
My pull request only contains ONE single commit
(the number above, next to the 'Commits' tab is 1).
No? -> read here on how to squash multiple commits into one
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master