forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bindu | BAH-3117 | Ability to add, display and update Notes section i…
…n OT Scheduling (#224) * Notes First Commit * Bindu | Add note save, get and update API's * Bindu | BAH-3117 | fix testcases * Bindu | BAH-3117 | get note by voided false and make delete reason as optional query parameter * Bindu | BAH-3117 | handle feedback change
- Loading branch information
Showing
19 changed files
with
1,118 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/NoteRequestResponse.java
This file contains 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,69 @@ | ||
package org.bahmni.module.bahmnicore.contract; | ||
|
||
import java.util.Date; | ||
|
||
public class NoteRequestResponse { | ||
|
||
private String uuid; | ||
|
||
private Integer noteId; | ||
|
||
private String noteText; | ||
|
||
private String noteTypeName; | ||
|
||
private Date noteDate; | ||
|
||
private String LocationName; | ||
|
||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public Integer getNoteId() { | ||
return noteId; | ||
} | ||
|
||
public void setNoteId(Integer noteId) { | ||
this.noteId = noteId; | ||
} | ||
|
||
public String getNoteText() { | ||
return noteText; | ||
} | ||
|
||
public void setNoteText(String noteText) { | ||
this.noteText = noteText; | ||
} | ||
|
||
public Date getNoteDate() { | ||
return noteDate; | ||
} | ||
|
||
public void setNoteDate(Date noteDate) { | ||
this.noteDate = noteDate; | ||
} | ||
|
||
public String getNoteTypeName() { | ||
return noteTypeName; | ||
} | ||
|
||
public void setNoteTypeName(String noteTypeName) { | ||
this.noteTypeName = noteTypeName; | ||
} | ||
|
||
public String getLocationName() { | ||
return LocationName; | ||
} | ||
|
||
public void setLocationName(String locationName) { | ||
LocationName = locationName; | ||
} | ||
} | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/NoteDao.java
This file contains 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,29 @@ | ||
package org.bahmni.module.bahmnicore.dao; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.bahmni.module.bahmnicore.model.Note; | ||
import org.bahmni.module.bahmnicore.model.NoteType; | ||
import org.openmrs.api.db.DAOException; | ||
|
||
public interface NoteDao { | ||
|
||
Note createNote(Note note); | ||
|
||
Note getNoteById(Integer noteId); | ||
|
||
Note updateNote(Note note); | ||
|
||
void deleteNote(Note note); | ||
|
||
Note voidNote(Note note); | ||
|
||
Note getNote(Date noteDate, String noteType); | ||
|
||
NoteType getNoteType(String name); | ||
|
||
List<Note> getNotes(Date startDate, Date endDate, String noteType); | ||
|
||
Note getNoteByUuid(String uuid); | ||
} |
106 changes: 106 additions & 0 deletions
106
bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/impl/NoteDaoImpl.java
This file contains 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,106 @@ | ||
package org.bahmni.module.bahmnicore.dao.impl; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.bahmni.module.bahmnicore.dao.NoteDao; | ||
import org.bahmni.module.bahmnicore.model.Note; | ||
import org.bahmni.module.bahmnicore.model.NoteType; | ||
import org.hibernate.query.Query; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.openmrs.api.APIException; | ||
|
||
public class NoteDaoImpl implements NoteDao { | ||
|
||
protected final static Log log = LogFactory.getLog(NoteDaoImpl.class); | ||
|
||
private SessionFactory sessionFactory; | ||
|
||
public NoteDaoImpl() { | ||
} | ||
|
||
public void setSessionFactory(SessionFactory sessionFactory) { | ||
this.sessionFactory = sessionFactory; | ||
} | ||
|
||
public Note getNoteById(Integer id) { | ||
log.info("Get note " + id); | ||
return (Note) sessionFactory.getCurrentSession().get(Note.class, id); | ||
} | ||
|
||
public Note createNote(Note note) { | ||
log.debug("Creating new note"); | ||
sessionFactory.getCurrentSession().save(note); | ||
return note; | ||
} | ||
|
||
public NoteType getNoteType(String name){ | ||
List<NoteType> noteType = new ArrayList<>(); | ||
Session currentSession = sessionFactory.getCurrentSession(); | ||
Query query = currentSession.createQuery("select noteType from NoteType noteType " + | ||
"where noteType.name = :name"); | ||
query.setParameter("name", name); | ||
noteType.addAll(query.list()); | ||
return CollectionUtils.isEmpty(noteType) ? null : noteType.get(0); | ||
|
||
} | ||
|
||
public Note updateNote(Note note) { | ||
log.debug("Updating existing note"); | ||
sessionFactory.getCurrentSession().save(note); | ||
return note; | ||
} | ||
|
||
public void deleteNote(Note note) { | ||
log.debug("Deleting existing note"); | ||
sessionFactory.getCurrentSession().delete(note); | ||
} | ||
|
||
public Note voidNote(Note note) throws APIException { | ||
sessionFactory.getCurrentSession().save(note); | ||
return note; | ||
} | ||
|
||
@Override | ||
public Note getNote(Date noteDate, String noteType) { | ||
List<Note> notes = new ArrayList<>(); | ||
StringBuilder query = new StringBuilder("select note from Note note " + | ||
"where note.noteDate = :noteDate " + | ||
"and note.noteType.name = :noteType " + | ||
"and note.voided = false"); | ||
|
||
Query queryToGetNotes = sessionFactory.getCurrentSession().createQuery(query.toString()); | ||
queryToGetNotes.setParameter("noteDate", noteDate); | ||
queryToGetNotes.setParameter("noteType", noteType); | ||
|
||
notes.addAll(queryToGetNotes.list()); | ||
return CollectionUtils.isEmpty(notes) ? null : notes.get(0); | ||
} | ||
|
||
@Override | ||
public List<Note> getNotes(Date startDate, Date endDate, String noteType) { | ||
List<Note> notes = new ArrayList<>(); | ||
Session currentSession = sessionFactory.getCurrentSession(); | ||
Query query = currentSession.createQuery( | ||
"select note from Note note " + | ||
"where note.noteDate between :startDate and :endDate " + | ||
"and note.noteType.name = :noteType" + | ||
" and note.voided = false"); | ||
query.setParameter("startDate", startDate); | ||
query.setParameter("endDate", endDate); | ||
query.setParameter("noteType", noteType); | ||
notes.addAll(query.list()); | ||
return notes; | ||
|
||
} | ||
@Override | ||
public Note getNoteByUuid(String uuid) { | ||
return (Note)this.sessionFactory.getCurrentSession().createQuery("from Note note where note.uuid = :uuid").setParameter("uuid", uuid).uniqueResult(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/mapper/NoteMapper.java
This file contains 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,34 @@ | ||
package org.bahmni.module.bahmnicore.mapper; | ||
|
||
import org.bahmni.module.bahmnicore.contract.NoteRequestResponse; | ||
import org.bahmni.module.bahmnicore.model.Note; | ||
import org.bahmni.module.bahmnicore.service.NoteService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NoteMapper { | ||
|
||
@Autowired | ||
private NoteService noteService; | ||
|
||
public NoteRequestResponse mapResponse(Note note){ | ||
NoteRequestResponse noteResponse = new NoteRequestResponse(); | ||
noteResponse.setNoteId(note.getNoteId()); | ||
noteResponse.setNoteDate(note.getNoteDate()); | ||
noteResponse.setNoteText(note.getNoteText()); | ||
noteResponse.setUuid(note.getUuid()); | ||
noteResponse.setNoteTypeName(note.getNoteType().getName()); | ||
return noteResponse; | ||
} | ||
|
||
public Note mapRequest(NoteRequestResponse noteRequest){ | ||
Note note = new Note(); | ||
note.setNoteId(noteRequest.getNoteId()); | ||
note.setNoteDate(noteRequest.getNoteDate()); | ||
note.setNoteText(noteRequest.getNoteText()); | ||
note.setUuid(noteRequest.getUuid()); | ||
note.setNoteType(noteService.getNoteType(noteRequest.getNoteTypeName())); | ||
return note; | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/model/Note.java
This file contains 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,127 @@ | ||
package org.bahmni.module.bahmnicore.model; | ||
|
||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnore; | ||
import org.openmrs.Auditable; | ||
import org.openmrs.BaseOpenmrsData; | ||
import org.openmrs.Patient; | ||
import org.openmrs.User; | ||
|
||
public class Note extends BaseOpenmrsData implements Auditable, Serializable { | ||
|
||
private Integer noteId; | ||
|
||
private String noteText; | ||
|
||
private Date dateChanged; | ||
|
||
private Date dateCreated; | ||
|
||
private NoteType noteType; | ||
|
||
private Date noteDate; | ||
|
||
private Integer locationId; | ||
|
||
private User creator; | ||
|
||
private User changedBy; | ||
|
||
|
||
public Note() { | ||
} | ||
|
||
@Override | ||
public void setId(Integer id) { | ||
setNoteId(id); | ||
} | ||
|
||
@Override | ||
public Integer getId() { | ||
return getNoteId(); | ||
} | ||
|
||
public Date getDateChanged() { | ||
return dateChanged; | ||
} | ||
|
||
public void setDateChanged(Date dateChanged) { | ||
this.dateChanged = dateChanged; | ||
} | ||
|
||
@Override | ||
public Date getDateCreated() { | ||
return dateCreated; | ||
} | ||
|
||
@Override | ||
public void setDateCreated(Date dateCreated) { | ||
this.dateCreated = dateCreated; | ||
} | ||
|
||
public Integer getNoteId() { | ||
return noteId; | ||
} | ||
|
||
public void setNoteId(Integer noteId) { | ||
this.noteId = noteId; | ||
} | ||
|
||
public Integer getLocationId() { | ||
return locationId; | ||
} | ||
|
||
public void setLocationId(Integer locationId) { | ||
this.locationId = locationId; | ||
} | ||
|
||
public Date getNoteDate() { | ||
return noteDate; | ||
} | ||
|
||
public void setNoteDate(Date noteDate) { | ||
this.noteDate = noteDate; | ||
} | ||
|
||
public NoteType getNoteType() { | ||
return noteType; | ||
} | ||
|
||
public void setNoteType(NoteType noteType) { | ||
this.noteType = noteType; | ||
} | ||
|
||
public String getNoteText() { | ||
return noteText; | ||
} | ||
|
||
public void setNoteText(String noteText) { | ||
this.noteText = noteText; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public User getCreator() { | ||
return creator; | ||
} | ||
|
||
@Override | ||
public void setCreator(User creator) { | ||
this.creator = creator; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public User getChangedBy() { | ||
return changedBy; | ||
} | ||
|
||
@Override | ||
public void setChangedBy(User changedBy) { | ||
this.changedBy = changedBy; | ||
} | ||
} |
Oops, something went wrong.