-
Notifications
You must be signed in to change notification settings - Fork 238
HTML-886: Add new tag to record appointment service as obs #338
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39ef9b6
HTML-886: Add new tag to record appointment service as obs
chibongho 1f96bc9
Add tests + controlId, chnage obs value format to `<id> + <serviceName>`
chibongho f3ab567
Merge remote-tracking branch 'origin/master' into HTML-886
chibongho 67383dc
fix AppointmentServiceObs value not being displayed when in obsgroup
chibongho b3e9ac7
accept uuid for specialities; save appointment service uuid as obs te…
chibongho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
api/src/main/java/org/openmrs/module/htmlformentry/element/AppointmentServiceObsElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| package org.openmrs.module.htmlformentry.element; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
| import org.openmrs.Concept; | ||
| import org.openmrs.Obs; | ||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.module.appointments.model.AppointmentServiceDefinition; | ||
| import org.openmrs.module.appointments.service.AppointmentServiceDefinitionService; | ||
| import org.openmrs.module.htmlformentry.BadFormDesignException; | ||
| import org.openmrs.module.htmlformentry.FormEntryContext; | ||
| import org.openmrs.module.htmlformentry.FormEntryContext.Mode; | ||
| import org.openmrs.module.htmlformentry.FormEntrySession; | ||
| import org.openmrs.module.htmlformentry.FormSubmissionError; | ||
| import org.openmrs.module.htmlformentry.HtmlFormEntryUtil; | ||
| import org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction; | ||
| import org.openmrs.module.htmlformentry.tag.TagUtil; | ||
| import org.openmrs.module.htmlformentry.widget.DropdownWidget; | ||
| import org.openmrs.module.htmlformentry.widget.ErrorWidget; | ||
| import org.openmrs.module.htmlformentry.widget.Option; | ||
|
|
||
| public class AppointmentServiceObsElement implements HtmlGeneratorElement, FormSubmissionControllerAction { | ||
|
|
||
| private Concept concept; | ||
|
|
||
| private Obs existingObs; | ||
|
|
||
| DropdownWidget serviceWidget; | ||
|
|
||
| private ErrorWidget errorWidget; | ||
|
|
||
| private String tagControlId; | ||
|
|
||
| public AppointmentServiceObsElement(FormEntryContext context, Map<String, String> parameters) throws BadFormDesignException{ | ||
| String conceptId = parameters.get("conceptId"); | ||
| if (conceptId == null) { | ||
| throw new BadFormDesignException("appointmentServiceObs requires a conceptId parameter"); | ||
| } | ||
| concept = HtmlFormEntryUtil.getConcept(conceptId); | ||
| if (concept == null) { | ||
| throw new BadFormDesignException("Could not find concept: " + conceptId); | ||
| } | ||
|
|
||
| if (parameters.containsKey("controlId")) { | ||
| tagControlId = parameters.get("controlId"); | ||
| } | ||
|
|
||
| boolean insideObsGroup = context.getCurrentObsGroupConcepts() != null | ||
| && context.getCurrentObsGroupConcepts().size() > 0; | ||
| if (StringUtils.isNotBlank(tagControlId)) { | ||
| if (insideObsGroup) { | ||
| existingObs = context.getObsFromCurrentGroup(tagControlId); | ||
| } else { | ||
| existingObs = context.getObsFromExistingObs(concept, tagControlId); | ||
| } | ||
| } else { | ||
| if (insideObsGroup) { | ||
| existingObs = context.getObsFromCurrentGroup(concept, (Concept) null); | ||
| } else { | ||
| existingObs = context.removeExistingObs(concept, (Concept) null); | ||
| } | ||
| } | ||
| String existingValue = existingObs != null ? existingObs.getValueText() : null; | ||
|
|
||
| List<String> specialityFilter = TagUtil.parseListParameter(parameters, "specialities", String.class).stream() | ||
| .map(String::toLowerCase).map(String::trim).collect(Collectors.toList()); | ||
|
|
||
| List<AppointmentServiceDefinition> services = Context.getService(AppointmentServiceDefinitionService.class) | ||
| .getAllAppointmentServices(false); | ||
| services.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName())); | ||
|
|
||
| if (!specialityFilter.isEmpty()) { | ||
| services = services.stream() | ||
| .filter(s -> s.getSpeciality() != null | ||
| && (specialityFilter.contains(s.getSpeciality().getName().toLowerCase().trim()) | ||
| || specialityFilter.contains(s.getSpeciality().getUuid().toLowerCase().trim()))) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
mseaton marked this conversation as resolved.
|
||
|
|
||
| serviceWidget = new DropdownWidget(); | ||
| errorWidget = new ErrorWidget(); | ||
|
|
||
| serviceWidget.addOption(new Option("", "", false)); | ||
| for (AppointmentServiceDefinition svc : services) { | ||
| serviceWidget.addOption(new Option(svc.getName(), svc.getUuid(), false)); | ||
| } | ||
| if (existingValue != null) { | ||
| serviceWidget.setInitialValue(existingValue); | ||
| } | ||
|
|
||
| context.registerWidget(serviceWidget); | ||
| context.registerErrorWidget(serviceWidget, errorWidget); | ||
| } | ||
|
|
||
| @Override | ||
| public String generateHtml(FormEntryContext context) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append(serviceWidget.generateHtml(context)); | ||
| if (context.getMode() != Mode.VIEW) { | ||
| sb.append(errorWidget.generateHtml(context)); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<FormSubmissionError> validateSubmission(FormEntryContext context, HttpServletRequest submission) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| @Override | ||
| public void handleSubmission(FormEntrySession session, HttpServletRequest submission) { | ||
| if (session.getContext().getMode() == Mode.VIEW) { | ||
| return; | ||
| } | ||
|
|
||
| FormEntryContext context = session.getContext(); | ||
| String value = (String) serviceWidget.getValue(context, submission); | ||
|
|
||
| if (existingObs != null && context.getMode() == Mode.EDIT) { | ||
| session.getSubmissionActions().modifyObs(existingObs, concept, value, null, null, null, getControlFormPath(session)); | ||
| } else if (value != null && !value.isEmpty()) { | ||
| session.getSubmissionActions().createObs(concept, value, null, null, null, getControlFormPath(session)); | ||
| } | ||
| } | ||
|
|
||
| private String getControlFormPath(FormEntrySession session) { | ||
| if (StringUtils.isBlank(tagControlId)) { | ||
| return null; | ||
| } | ||
| return session.generateControlFormPath(tagControlId, 0); | ||
| } | ||
|
|
||
| } | ||
27 changes: 27 additions & 0 deletions
27
...c/main/java/org/openmrs/module/htmlformentry/handler/AppointmentServiceObsTagHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.openmrs.module.htmlformentry.handler; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.openmrs.Concept; | ||
| import org.openmrs.module.htmlformentry.BadFormDesignException; | ||
| import org.openmrs.module.htmlformentry.FormEntrySession; | ||
| import org.openmrs.module.htmlformentry.FormSubmissionController; | ||
| import org.openmrs.module.htmlformentry.element.AppointmentServiceObsElement; | ||
|
|
||
| public class AppointmentServiceObsTagHandler extends SubstitutionTagHandler { | ||
|
|
||
| @Override | ||
| protected List<AttributeDescriptor> createAttributeDescriptors() { | ||
| return Collections.singletonList(new AttributeDescriptor("conceptId", Concept.class)); | ||
|
mseaton marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| protected String getSubstitution(FormEntrySession session, FormSubmissionController controllerActions, | ||
| Map<String, String> parameters) throws BadFormDesignException { | ||
| AppointmentServiceObsElement element = new AppointmentServiceObsElement(session.getContext(), parameters); | ||
| session.getSubmissionController().addAction(element); | ||
| return element.generateHtml(session.getContext()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.