Skip to content

BED-23: Bed Tags should be uniquely identified by name#89

Closed
jwnasambu wants to merge 33 commits intoopenmrs:masterfrom
jwnasambu:new-BED-23
Closed

BED-23: Bed Tags should be uniquely identified by name#89
jwnasambu wants to merge 33 commits intoopenmrs:masterfrom
jwnasambu:new-BED-23

Conversation

@jwnasambu
Copy link
Copy Markdown
Contributor

Description of what changed
I added a BedTagValidator to enforce validation rules on BedTag objects. This prevents creating two active bed tags with the same name, while still allowing duplicate names if the bed tags is expired. The validator also checks that the name is not null/empty/whitespace and respects field length constraints.

Issued worked on
https://openmrs.atlassian.net/browse/BED-23

return;
}

List<BedTag> allTags = (List<BedTag>) bedManagementService.getAllBedTags();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to the cast here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wikumChamith Thanks for the review. I have made a fix.

Comment on lines +17 to +19
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we try to avoid using PowerMock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wikumChamith Kindly feel free to review my PR with the proposed changes at your convinient time please!


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wikumChamith Thanks for the point out. I have fixed the proposed changes. Kindly feel free to review my PR at your convinient time please!


List<BedTag> existingTags = bedManagementService.getAllBedTags();
for (BedTag existingTag : existingTags) {
boolean isVoidedOrExpired = existingTag.isVoided() || existingTag.getDateVoided() != null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should be sufficient just to check this:

Suggested change
boolean isVoidedOrExpired = existingTag.isVoided() || existingTag.getDateVoided() != null;
boolean isVoided = existingTag.getVoided();

There's no reasonable case where dateVoided is not null but the tag isn't voided.

Copy link
Copy Markdown
Contributor Author

@jwnasambu jwnasambu Oct 1, 2025

Choose a reason for hiding this comment

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

@ibacher after fixing this proposed changes, I get a build failure which I belief is because the validator treats the expired tag as active. The getVoided() method does not correctly reflect that dateVoided is set and by replacing existingTag.getVoided() with existingTag.getDateVoided() != null to properly detect expired/voided tags which solves the build failure. I stand to be corrected.

BedTag tag = (BedTag) target;

if (tag.getName() == null || tag.getName().trim().isEmpty()) {
errors.rejectValue("name", "bedtag.name.required", "Name is required");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The strings added here should be added to the messages.properties or else they will never properly be translatable.

@jwnasambu jwnasambu force-pushed the new-BED-23 branch 2 times, most recently from 2da590a to 940e7ed Compare October 1, 2025 15:04
@jwnasambu
Copy link
Copy Markdown
Contributor Author

@ibacher I Kindly need your guidance on one of the requests please?

@jwnasambu jwnasambu force-pushed the new-BED-23 branch 2 times, most recently from 70b24f8 to c7fdf98 Compare October 7, 2025 15:09
Comment on lines +56 to +58
if (existingTag.getDateVoided() != null) {
isVoided = true;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again this shouldn't be needed.

Comment on lines +60 to +63
if (!isVoided && existingTag.getName().equals(tag.getName())) {
errors.rejectValue("name", "bedtag.name.exists");
break;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to verify that the existingTag is different from the tag that we are validating. That's why the test is failing...

@jwnasambu jwnasambu force-pushed the new-BED-23 branch 4 times, most recently from e6c8513 to ac0c752 Compare October 7, 2025 21:40
@jwnasambu
Copy link
Copy Markdown
Contributor Author

@ibacher, @wikumChamith Kindly I have fixed all the proposed changes. Feel free to review my PR at your convinient time please!

@jwnasambu jwnasambu force-pushed the new-BED-23 branch 2 times, most recently from ddb1b92 to 493fc39 Compare October 7, 2025 22:10
import org.springframework.validation.Validator;

@Handler(supports = {BedTag.class}, order = 50)
public class BedTagValidator implements Validator {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, this class also need to be registered as a bean in the applicationContext.xml.

@jwnasambu jwnasambu marked this pull request as draft October 17, 2025 13:56
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most of the reformatting here is harmless, but this line is incorrect.

return bedTagMapDao.getBedTagByUuid(bedTagUuid);
}

@Override
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@Override
@Override

@Authorized(value = { "Get Bed Tags", "Get Beds" }, requireAll = true)
BedTag getBedTagByUuid(String bedTagUuid);

BedTag getBedTagByName(String name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this have an @Authorized annotation? But also, I don't think it belongs in this class at all.


BedTag existing = bedManagementService.getBedTagByName(tag.getName().trim());

if (existing != null && existing.getDateVoided() == null && !existing.getUuid().equals(tag.getUuid())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still think we should be checking existing.getVoided(). The dateVoided property is informational, but not the determining factor for whether a value is voided or not.

@jwnasambu jwnasambu requested a review from ibacher November 26, 2025 21:41
@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa, @ibacher kindly feel free to review my pull request at your convenient time please!

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa Kindly feel free to review my PR at your convinient time please!

@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Nov 30, 2025

Can you discard the formatting changes?

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa Kindly feel free to review my PR at your convinient time please!

@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Dec 3, 2025

Can you remove all those formatting changes?

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa Kindly feel free to review my PR at your convinient time please!

this.sessionFactory = sessionFactory;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you remove all these formatting changes?

@jwnasambu jwnasambu force-pushed the new-BED-23 branch 2 times, most recently from 20046b3 to 958884e Compare December 4, 2025 22:07
@jwnasambu jwnasambu marked this pull request as draft December 4, 2025 22:49
@jwnasambu
Copy link
Copy Markdown
Contributor Author

jwnasambu commented Dec 10, 2025

@dkayiwa I’ve tried resolving the requested changes, but each time I update the files, more formatting changes keep appearing in the commits. Could you please advise on the best way to handle or remove these formatting changes? I tried to create a new commit but still facing the same challenge as reflected on this link https://github.com/openmrs/openmrs-module-bedmanagement/compare/master...jwnasambu:BED-23b?expand=1

@jwnasambu jwnasambu closed this Dec 11, 2025
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