Skip to content

Commit

Permalink
BAH-4062 | Refactor. Move privilege creation to config.xml (#72)
Browse files Browse the repository at this point in the history
* BAH-4062 | Refactor. Extract privilege creation to config.xml

* BAH-4062 | Fix. Error messages for privilege check failures
  • Loading branch information
mohan-13 authored Aug 21, 2024
1 parent ebd616e commit 8639e40
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 67 deletions.
61 changes: 1 addition & 60 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -467,64 +467,5 @@
'2024-04-11 19:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID());
</sql>
</changeSet>
<changeSet id="ipd-edit-medication-tasks" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Edit Medication Tasks'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Edit Medication Tasks"/>
<column name="description" value="Edit Medication Tasks description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="ipd-delete-medication-tasks" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Delete Medication Tasks'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Delete Medication Tasks"/>
<column name="description" value="Delete Medication Tasks description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="ipd-edit-adhoc-medication-tasks" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Edit adhoc medication tasks'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Edit adhoc medication tasks"/>
<column name="description" value="Edit adhoc medication tasks description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="ipd-edit-medication-administration-tasks" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Edit Medication Administration'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Edit Medication Administration"/>
<column name="description" value="Edit Medication Administration description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="ipd-get-medication-administration" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Get Medication Administration'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Get Medication Administration"/>
<column name="description" value="Get Medication Administration description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="ipd-get-medication-tasks" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Get Medication Tasks'</sqlCheck>
</preConditions>
<insert tableName="privilege">
<column name="privilege" value="Get Medication Tasks"/>
<column name="description" value="Get Medication Tasks description"/>
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public ResponseEntity<Object> createScheduledMedicationAdministration(@RequestBo
@ResponseBody
public ResponseEntity<Object> createAdhocMedicationAdministration(@RequestBody MedicationAdministrationRequest medicationAdministrationRequest) {
try {
if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION)) {
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", "+PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION), FORBIDDEN);
if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS)) {
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS), FORBIDDEN);
}
MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.saveAdhocMedicationAdministration(medicationAdministrationRequest);
MedicationAdministrationResponse medicationAdministrationResponse = medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ResponseEntity<Object> getMedicationSlotsByDate(@RequestParam(value = "pa
@RequestParam(value = "view", required = false) String view) {
try {
if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) {
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
}
; if (startTime != null && endTime != null) {
LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime);
Expand All @@ -123,7 +123,7 @@ public ResponseEntity<Object> getMedicationSlotsByOrderUuids(@RequestParam(value
@RequestParam(value = "orderUuids", required = false) List<String> orderUuids) {
try {
if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) {
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
}
List<Slot> slots;
if (orderUuids == null || orderUuids.isEmpty()) {
Expand Down Expand Up @@ -177,4 +177,4 @@ private List<MedicationScheduleResponse> constructResponse(List<Slot> slots, Vis
return slotsBySchedule.entrySet().stream().map(entry -> createFrom(entry.getKey(), entry.getValue())).collect(Collectors.toList());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ResponseEntity<Object> getVisitWiseMedications (
@PathVariable("visitUuid") String visitUuid,
@RequestParam(value = "includes", required = false) List<String> includes) throws ParseException {
if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) {
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN);
}
List<IPDDrugOrder> prescribedOrders = ipdVisitService.getPrescribedOrders(visitUuid, true, null, null, null, false);
List<IPDDrugOrderResponse> prescribedOrderResponse = prescribedOrders.stream().map(IPDDrugOrderResponse::createFrom).collect(Collectors.toList());
Expand Down
26 changes: 25 additions & 1 deletion omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,31 @@
<defaultValue>true</defaultValue>
<description>Feature toggle to decide whether to stop slots associated when drug order is stopped</description>
</globalProperty>


<privilege>
<name>Edit Medication Tasks</name>
<description>Allows to Edit Medication Schedules and Slots</description>
</privilege>
<privilege>
<name>Delete Medication Tasks</name>
<description>Allows to Delete Medication Schedules and Slots</description>
</privilege>
<privilege>
<name>Edit adhoc medication tasks</name>
<description>Allows to Edit Emergency Medication Tasks</description>
</privilege>
<privilege>
<name>Edit Medication Administration</name>
<description>Allows to Edit Medication Administrations</description>
</privilege>
<privilege>
<name>Get Medication Administration</name>
<description>Allows to Get Medication Administrations</description>
</privilege>
<privilege>
<name>Get Medication Tasks</name>
<description>Allows to Get Medication Tasks</description>
</privilege>
<activator>org.openmrs.module.ipd.api.IPDActivator</activator>
</module>

0 comments on commit 8639e40

Please sign in to comment.