Skip to content

Commit

Permalink
Medication Administration Feature (#7)
Browse files Browse the repository at this point in the history
* [Ritesh] | 1. Repo set up. 2. Created Slot and Schedule entity 3.Saving IPD Medication Schedule without creating slots.

* [Ritesh] | 1. Update package name 2. Added Dao and Service layer for reference 3. Minor fixes

* [Ritesh] | 1.Rename Schedule Strategy to MedicationFrequency

* [Ritesh] | 1. Migration for slot. 2. Slot creation from schedule

* [Ritesh] | 1. Refactor SlotTimeCreationService

* [Ritesh] | 1. Handle time zone issue while creating slots and schedule.

* [Ritesh] | 1. Changing the url of saving medication

* [Ritesh] | 1. Returning slots

* [Ritesh] | Get schedule for Drug chart

* [Ritesh] | Fix date time issue in slots response

* [Ritesh] | Refactoring and Added test

* [Ritesh] | 1. Change for reference id to subject reference id and by reference id to actor reference id. 2. Also added pre-condition before adding medication concept for ipd.

* [Ritesh] | 1. Refactoring ServiceType

* [Ritesh] | 1. Bug Fix return empty list if now slots are not present for a  patient on specific day.

* [Ritesh] | 1. Updated README file

* [Ritesh] | 1. Fixed time zone issue in test

* add. endpoint to get list of IPD medications scheduled for a patient

* refactor. endpoint and updated tests in DAO and service classes

* refactor. namings for schedule DAO methods

* fix. test failures in ScheduleImpl

* add. changes to create one schedule for a patient

* update. columns in Schedule and Slot table

* update. set end date as null

* fix tests for Slot and Schedule Hiberate and DAOs. Updated responses for GET calls

* fix tests Schedule DAO

* remove unnecessary fields

* API Change to accomodate Editable Remaining day slot start time for medication

* Kavitha|Kalai Add Change for Medication Administration Save

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha, Kalai | refactored patient reference param

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha, Kalai | add medication administration reference in slot db and api

* Kavitha|Kalai - Medication Administration Create API Changes

* Kavitha, Kalai | added provider mapper and time converter

* Kavitha | add adhoc and refactored scheduled medication administration

* refactored schedule from medication administration request

* Kavitha | refactored medication administration request and response

* Kavitha | refactored annotation to medicationAdministrationNote

* Kavitha | removed unused methods

---------

Co-authored-by: Ritesh Ghiya <[email protected]>
Co-authored-by: Arjun-Go <[email protected]>
Co-authored-by: Kalaiyarasan Raja <[email protected]>
  • Loading branch information
4 people authored Jan 1, 2024
1 parent e2bcd0a commit c978be7
Show file tree
Hide file tree
Showing 27 changed files with 670 additions and 25 deletions.
22 changes: 22 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
Expand All @@ -125,6 +128,25 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-omod</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bahmni.module</groupId>
<artifactId>medication-administration-api</artifactId>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import org.openmrs.module.ipd.api.model.Schedule;
import org.openmrs.api.db.DAOException;
import org.springframework.stereotype.Repository;
import org.openmrs.Concept;
import org.openmrs.module.ipd.api.model.Reference;

import java.util.List;

@Repository
public interface ScheduleDAO {

Schedule getSchedule(Integer scheduleId) throws DAOException;

Schedule saveSchedule(Schedule schedule) throws DAOException;

Schedule getScheduleByVisit(Visit visit) throws DAOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
public interface SlotDAO {

Slot getSlot(Integer slotId) throws DAOException;


Slot getSlotByUUID(String uuid) throws DAOException;

Slot saveSlot(Slot slot) throws DAOException;

List<Slot> getSlotsBySubjectReferenceIdAndForDateAndServiceType(Reference subject, LocalDate forDate, Concept serviceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public HibernateSlotDAO(SessionFactory sessionFactory) {
public Slot getSlot(Integer slotId) throws DAOException {
return sessionFactory.getCurrentSession().get(Slot.class, slotId);
}


@Override
public Slot getSlotByUUID(String uuid) throws DAOException {
Slot s = (Slot)this.sessionFactory.getCurrentSession().createQuery("from Slot s where s.uuid = :uuid").setString("uuid", uuid).uniqueResult();
return s;
}

@Override
public Slot saveSlot(Slot slot) throws DAOException {
sessionFactory.getCurrentSession().saveOrUpdate(slot);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.openmrs.module.ipd.api.model;

public enum ServiceType {
MEDICATION_REQUEST("MedicationRequest");
MEDICATION_REQUEST("MedicationRequest"),
EMERGENCY_MEDICATION_REQUEST("EmergencyMedicationRequest"),
AS_NEEDED_MEDICATION_REQUEST("AsNeededMedicationRequest");

private final String conceptName;

Expand Down
7 changes: 7 additions & 0 deletions api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public enum SlotStatus {
@Column(name = "status", nullable = false)
@Enumerated(EnumType.STRING)
private SlotStatus status = SlotStatus.SCHEDULED;

/**
* The reference of medication administration if the medication is administered
*/
@OneToOne
@JoinColumn(name = "medication_administration_id", referencedColumnName = "medication_administration_id")
private MedicationAdministration medicationAdministration;
}


Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package org.openmrs.module.ipd.api.service;

import org.openmrs.Concept;
import org.openmrs.Visit;
import org.openmrs.module.ipd.api.model.Reference;
import org.openmrs.module.ipd.api.model.Schedule;
import org.openmrs.api.APIException;
import org.openmrs.api.OpenmrsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface ScheduleService extends OpenmrsService {

// @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES })
Schedule getSchedule(Integer scheduleId) throws APIException;

// @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES })
Schedule saveSchedule(Schedule schedule) throws APIException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface SlotService extends OpenmrsService {
// @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS })
Slot getSlot(Integer slotId) throws APIException;

// @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS })
Slot getSlotByUUID(String uuid) throws APIException;

// @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS })
Slot saveSlot(Slot slot) throws APIException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.openmrs.module.ipd.api.service.impl;

import org.openmrs.Concept;
import org.openmrs.Visit;
import org.openmrs.module.ipd.api.dao.ScheduleDAO;
import org.openmrs.module.ipd.api.model.Reference;
import org.openmrs.module.ipd.api.model.Schedule;
import org.openmrs.module.ipd.api.service.ScheduleService;
import org.openmrs.api.APIException;
Expand All @@ -14,8 +12,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ScheduleServiceImpl extends BaseOpenmrsService implements ScheduleService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public SlotServiceImpl(SlotDAO slotDAO) {
public Slot getSlot(Integer slotId) throws APIException {
return slotDAO.getSlot(slotId);
}


@Override
public Slot getSlotByUUID(String uuid) throws APIException {
return slotDAO.getSlotByUUID(uuid);
}

@Override
public Slot saveSlot(Slot slot) throws APIException {
return slotDAO.saveSlot(slot);
Expand Down
58 changes: 58 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,62 @@
ALTER TABLE ipd_schedule MODIFY COLUMN end_date datetime NULL;
</sql>
</changeSet>

<changeSet id="add_medication_administration_id_202312141530" author="Bahmni">
<addColumn tableName="ipd_slot">
<column name="medication_administration_id" type="int" />
</addColumn>
<addForeignKeyConstraint baseTableName="ipd_slot" baseColumnNames="medication_administration_id"
constraintName="ipd_slot_medication_administration_fk"
referencedTableName="medication_administration" referencedColumnNames="medication_administration_id"/>
</changeSet>

<changeSet id="add_emergency_medication_concept_202312270121" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept where short_name='EmergencyMedicationRequest' and description='EmergencyMedicationRequest';
</sqlCheck>
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept_name where name ='EmergencyMedicationRequest';
</sqlCheck>
</preConditions>
<comment>Add concept for Emergency Medication Request</comment>
<sql>
insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created,
changed_by, date_changed, uuid)
values (0, 'EmergencyMedicationRequest', 'EmergencyMedicationRequest',
(select concept_datatype_id from concept_datatype where name = 'Text'),
(select concept_class_id from concept_class where name = 'Misc'),
0, 1, now(), 1, now(), uuid());
insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,
concept_name_type, voided, uuid)
values ((select concept_id from concept where short_name='EmergencyMedicationRequest'),
'EmergencyMedicationRequest', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid());
</sql>
</changeSet>

<changeSet id="add_as_needed_medication_concept_202312270121" author="Bahmni">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept where short_name='AsNeededMedicationRequest' and description='AsNeededMedicationRequest';
</sqlCheck>
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept_name where name ='AsNeededMedicationRequest';
</sqlCheck>
</preConditions>
<comment>Add concept for As Needed Medication Request</comment>
<sql>
insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created,
changed_by, date_changed, uuid)
values (0, 'AsNeededMedicationRequest', 'AsNeededMedicationRequest',
(select concept_datatype_id from concept_datatype where name = 'Text'),
(select concept_class_id from concept_class where name = 'Misc'),
0, 1, now(), 1, now(), uuid());
insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,
concept_name_type, voided, uuid)
values ((select concept_id from concept where short_name='AsNeededMedicationRequest'),
'AsNeededMedicationRequest', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid());
</sql>
</changeSet>

</databaseChangeLog>
18 changes: 18 additions & 0 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-omod</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bahmni.module</groupId>
<artifactId>medication-administration-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.openmrs.module.ipd.contract;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import java.util.Date;
import java.util.concurrent.TimeUnit;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties
public class MedicationAdministrationNoteRequest {
private String uuid;
private String authorUuid;
private Long recordedTime;
private String text;

public Date getRecordedTimeAsLocaltime() {
return this.recordedTime != null ? new Date(TimeUnit.SECONDS.toMillis(this.recordedTime)): new Date();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.openmrs.module.ipd.contract;

import lombok.*;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.openmrs.module.ipd.api.model.MedicationAdministrationNote;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.representation.Representation;

import java.util.Date;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties
public class MedicationAdministrationNoteResponse {
private String uuid;
private Object author;
private Date recordedTime;
private String text;

public static MedicationAdministrationNoteResponse createFrom(MedicationAdministrationNote openmrsObject) {
return MedicationAdministrationNoteResponse.builder()
.uuid(openmrsObject.getUuid())
.author(ConversionUtil.convertToRepresentation(openmrsObject.getAuthor(), Representation.REF))
.recordedTime(openmrsObject.getRecordedTime())
.text(openmrsObject.getText())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.openmrs.module.ipd.contract;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import java.util.Date;
import java.util.concurrent.TimeUnit;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties
public class MedicationAdministrationPerformerRequest {
private String uuid;
private String providerUuid;
private String function;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.openmrs.module.ipd.contract;

import lombok.*;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.openmrs.module.ipd.api.model.MedicationAdministrationPerformer;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.representation.Representation;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties
public class MedicationAdministrationPerformerResponse {
private String uuid;
private Object provider;
private String function;

public static MedicationAdministrationPerformerResponse createFrom(MedicationAdministrationPerformer openmrsMedicationAdministrationPerformer) {
String function = openmrsMedicationAdministrationPerformer.getFunction() != null ? openmrsMedicationAdministrationPerformer.getFunction().getDisplayString() : null;
return MedicationAdministrationPerformerResponse.builder()
.uuid(openmrsMedicationAdministrationPerformer.getUuid())
.provider(ConversionUtil.convertToRepresentation(openmrsMedicationAdministrationPerformer.getActor(), Representation.REF))
.function(function)
.build();
}
}
Loading

0 comments on commit c978be7

Please sign in to comment.