-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API to Create CareTeam & Its Participants
- Loading branch information
Showing
19 changed files
with
886 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.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,14 @@ | ||
package org.openmrs.module.ipd.api.dao; | ||
|
||
import org.openmrs.Visit; | ||
import org.openmrs.api.db.DAOException; | ||
import org.openmrs.module.ipd.api.model.CareTeam; | ||
import org.openmrs.module.ipd.api.model.Schedule; | ||
|
||
public interface CareTeamDAO { | ||
|
||
CareTeam saveCareTeam(CareTeam careTeam) throws DAOException; | ||
|
||
CareTeam getCareTeamByVisit(Visit visit) throws DAOException; | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAO.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,41 @@ | ||
package org.openmrs.module.ipd.api.dao.impl; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.hibernate.query.Query; | ||
import org.openmrs.Visit; | ||
import org.openmrs.api.db.DAOException; | ||
import org.openmrs.module.ipd.api.dao.CareTeamDAO; | ||
import org.openmrs.module.ipd.api.model.CareTeam; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class HibernateCareTeamDAO implements CareTeamDAO { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(HibernateCareTeamDAO.class); | ||
private final SessionFactory sessionFactory; | ||
|
||
@Autowired | ||
public HibernateCareTeamDAO(SessionFactory sessionFactory) { | ||
this.sessionFactory = sessionFactory; | ||
} | ||
|
||
@Override | ||
public CareTeam saveCareTeam(CareTeam careTeam) throws DAOException { | ||
sessionFactory.getCurrentSession().saveOrUpdate(careTeam); | ||
return careTeam; | ||
} | ||
|
||
@Override | ||
public CareTeam getCareTeamByVisit(Visit visit) throws DAOException { | ||
Query query = sessionFactory.getCurrentSession() | ||
.createQuery("FROM CareTeam careteam " + | ||
"WHERE careteam.visit = :visit "); | ||
|
||
query.setParameter("visit", visit); | ||
|
||
return (CareTeam) query.uniqueResult(); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.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,105 @@ | ||
package org.openmrs.module.ipd.api.model; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.openmrs.BaseChangeableOpenmrsData; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Visit; | ||
|
||
import javax.persistence.*; | ||
import java.util.Date; | ||
import java.util.Set; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) | ||
@Entity | ||
@Table(name = "care_team") | ||
public class CareTeam extends BaseChangeableOpenmrsData { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "care_team_id") | ||
private Integer careTeamId; | ||
|
||
/** | ||
* FHIR:subject | ||
* Patient for Whom care team is for | ||
*/ | ||
@ManyToOne(optional = true) | ||
@JoinColumn(name = "patient_id") | ||
private Patient patient; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "visit_id", referencedColumnName = "visit_id") | ||
private Visit visit; | ||
|
||
/** | ||
* FHIR:period.start | ||
* Starting time with inclusive boundary | ||
*/ | ||
@Column(name = "start_time") | ||
private Date startTime; | ||
|
||
/** | ||
* FHIR:period.end | ||
* Ending time with inclusive boundary, if not ongoing | ||
*/ | ||
@Column(name = "end_time") | ||
private Date endTime; | ||
|
||
/** | ||
* FHIR:performer | ||
* @see <a href="https://build.fhir.org/careteam-definitions.html#CareTeam.participant"> | ||
* https://build.fhir.org/careteam-definitions.html#CareTeam.participant | ||
* </a>Identifies all people and organizations who are expected to be involved in the care team. | ||
*/ | ||
@OneToMany(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "care_team_id") | ||
private Set<CareTeamParticipant> participants; | ||
|
||
|
||
@Override | ||
public Integer getId() { | ||
return this.careTeamId; | ||
} | ||
|
||
@Override | ||
public void setId(Integer careTeamId) { | ||
this.careTeamId=careTeamId; | ||
} | ||
|
||
public Patient getPatient() { | ||
return patient; | ||
} | ||
|
||
public void setPatient(Patient patient) { | ||
this.patient = patient; | ||
} | ||
|
||
public Visit getVisit() { | ||
return visit; | ||
} | ||
|
||
public void setVisit(Visit visit) { | ||
this.visit = visit; | ||
} | ||
|
||
public Date getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(Date startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public Date getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public void setEndTime(Date endTime) { | ||
this.endTime = endTime; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
api/src/main/java/org/openmrs/module/ipd/api/model/CareTeamParticipant.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,119 @@ | ||
package org.openmrs.module.ipd.api.model; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.openmrs.BaseChangeableOpenmrsData; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Provider; | ||
|
||
import javax.persistence.*; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) | ||
@Entity | ||
@Table(name = "care_team_participant") | ||
public class CareTeamParticipant extends BaseChangeableOpenmrsData { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "care_team_participant_id") | ||
private Integer careTeamParticipantId; | ||
|
||
/** | ||
* FHIR:member | ||
* Indicates Who is involved . | ||
*/ | ||
@OneToOne(optional = false) | ||
@JoinColumn(name = "provider_id") | ||
private Provider provider; | ||
|
||
/** | ||
* FHIR:function | ||
* @see <a href="https://hl7.org/fhir/valueset-participant-role.html"> | ||
* https://hl7.org/fhir/valueset-participant-role.html | ||
* </a> | ||
* i.e. performer, verifier, witness | ||
*/ | ||
@ManyToOne(optional = true) | ||
@JoinColumn(name = "role") | ||
private Concept role; | ||
|
||
/** | ||
* FHIR:coverage.coveragePeriod.start | ||
* Starting time with inclusive boundary | ||
*/ | ||
@Column(name = "start_time") | ||
private Date startTime; | ||
|
||
/** | ||
* FHIR:coverage.coveragePeriod.end | ||
* Ending time with inclusive boundary, if not ongoing | ||
*/ | ||
@Column(name = "end_time") | ||
private Date endTime; | ||
|
||
@Override | ||
public Integer getId() { | ||
return getCareTeamParticipantId(); | ||
} | ||
|
||
@Override | ||
public void setId(Integer careTeamParticipantId) { | ||
this.careTeamParticipantId=careTeamParticipantId; | ||
} | ||
|
||
public Provider getProvider() { | ||
return provider; | ||
} | ||
|
||
public void setProvider(Provider provider) { | ||
this.provider = provider; | ||
} | ||
|
||
public Concept getRole() { | ||
return role; | ||
} | ||
|
||
public void setRole(Concept role) { | ||
this.role = role; | ||
} | ||
|
||
public Date getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(Date startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public Date getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public void setEndTime(Date endTime) { | ||
this.endTime = endTime; | ||
} | ||
|
||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} else if (obj != null && this.getClass() == obj.getClass()) { | ||
CareTeamParticipant other = (CareTeamParticipant) obj; | ||
return Objects.equals(this.getUuid(), other.getUuid()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public int hashCode() { | ||
int hash = Objects.hash(new Object[]{this.getUuid()}); | ||
return hash; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/org/openmrs/module/ipd/api/service/CareTeamService.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,18 @@ | ||
package org.openmrs.module.ipd.api.service; | ||
|
||
import org.openmrs.Visit; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.module.ipd.api.model.CareTeam; | ||
import org.openmrs.module.ipd.api.model.Schedule; | ||
import org.springframework.stereotype.Service; | ||
import org.openmrs.api.OpenmrsService; | ||
|
||
|
||
@Service | ||
public interface CareTeamService extends OpenmrsService { | ||
|
||
CareTeam saveCareTeam(CareTeam careTeam) throws APIException; | ||
|
||
CareTeam getCareTeamByVisit(Visit visit) throws APIException; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
api/src/main/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImpl.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,39 @@ | ||
package org.openmrs.module.ipd.api.service.impl; | ||
|
||
|
||
import org.openmrs.Visit; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.api.impl.BaseOpenmrsService; | ||
import org.openmrs.module.ipd.api.dao.CareTeamDAO; | ||
import org.openmrs.module.ipd.api.model.CareTeam; | ||
import org.openmrs.module.ipd.api.model.Schedule; | ||
import org.openmrs.module.ipd.api.service.CareTeamService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
public class CareTeamServiceImpl extends BaseOpenmrsService implements CareTeamService { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(CareTeamServiceImpl.class); | ||
|
||
private final CareTeamDAO careTeamDAO; | ||
|
||
@Autowired | ||
public CareTeamServiceImpl(CareTeamDAO careTeamDAO) { | ||
this.careTeamDAO = careTeamDAO; | ||
} | ||
|
||
@Override | ||
public CareTeam saveCareTeam(CareTeam careTeam) throws APIException { | ||
return careTeamDAO.saveCareTeam(careTeam); | ||
} | ||
|
||
@Override | ||
public CareTeam getCareTeamByVisit(Visit visit) throws APIException { | ||
return careTeamDAO.getCareTeamByVisit(visit); | ||
} | ||
} |
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
Oops, something went wrong.