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-842: Add Appointments tag #302

Merged
merged 7 commits into from
May 24, 2024
Merged

HTML-842: Add Appointments tag #302

merged 7 commits into from
May 24, 2024

Conversation

mogoodrich
Copy link
Member

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 and
    added 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

@mogoodrich mogoodrich marked this pull request as draft May 21, 2024 21:44
@mogoodrich mogoodrich changed the title Html 842 HTML-842: Add Appointments tag May 21, 2024
@mogoodrich mogoodrich marked this pull request as ready for review May 21, 2024 22:35
@mogoodrich mogoodrich requested a review from mseaton May 21, 2024 22:35
@@ -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;
Copy link
Member

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.

Copy link
Member Author

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

// 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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair... will correct.

Copy link
Member Author

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Ready for re-review.

Initial screenshot, though I am assuming we may tweak with layout, working on that next:
2024-05-24_15-37

// 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;
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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 {
Copy link
Member Author

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!

@mogoodrich mogoodrich requested a review from mseaton May 24, 2024 19:47
Copy link
Member

@mseaton mseaton left a 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;
Copy link
Member

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?

Copy link
Member Author

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());
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

fair enough

@mogoodrich
Copy link
Member Author

Thanks for all the comments, I had to fix one Github Copilot AI autocomplete error as well... :) Merging in...

@mogoodrich mogoodrich merged commit aa38901 into master May 24, 2024
1 check passed
@mogoodrich mogoodrich deleted the HTML-842 branch May 24, 2024 21:29
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.

2 participants