-
Notifications
You must be signed in to change notification settings - Fork 104
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
FM2-606: Mapping ContactPoints to OpenMRS #517
Changes from all commits
edeafcb
fbe72ff
e28bba9
b689239
8ae6f7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.fhir2.api; | ||
|
||
import java.util.Optional; | ||
|
||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.attribute.BaseAttributeType; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
|
||
public interface FhirContactPointMapService { | ||
|
||
Optional<FhirContactPointMap> getFhirContactPointMapForPersonAttributeType(PersonAttributeType attributeType); | ||
|
||
Optional<FhirContactPointMap> getFhirContactPointMapForAttributeType(BaseAttributeType<?> attributeType); | ||
|
||
FhirContactPointMap saveFhirContactPointMap(FhirContactPointMap contactPointMap); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.fhir2.api.dao; | ||
|
||
import java.util.Optional; | ||
|
||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.attribute.BaseAttributeType; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
|
||
public interface FhirContactPointMapDao { | ||
|
||
Optional<FhirContactPointMap> getFhirContactPointMapForPersonAttributeType(PersonAttributeType attributeType); | ||
|
||
Optional<FhirContactPointMap> getFhirContactPointMapForAttributeType(BaseAttributeType<?> attributeType); | ||
|
||
FhirContactPointMap saveFhirContactPointMap(FhirContactPointMap contactPointMap); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.fhir2.api.dao.impl; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.Optional; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.hibernate.SessionFactory; | ||
import org.openmrs.LocationAttributeType; | ||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.ProviderAttributeType; | ||
import org.openmrs.attribute.BaseAttributeType; | ||
import org.openmrs.module.fhir2.api.dao.FhirContactPointMapDao; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Setter(AccessLevel.PACKAGE) | ||
public class FhirContactPointMapDaoImpl implements FhirContactPointMapDao { | ||
|
||
@Autowired | ||
@Qualifier("sessionFactory") | ||
private SessionFactory sessionFactory; | ||
|
||
@Override | ||
public Optional<FhirContactPointMap> getFhirContactPointMapForPersonAttributeType( | ||
@Nonnull PersonAttributeType attributeType) { | ||
if (attributeType == null) { | ||
return Optional.empty(); | ||
Check warning on line 42 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L42
|
||
} | ||
|
||
return Optional.ofNullable((FhirContactPointMap) sessionFactory.getCurrentSession().createQuery( | ||
"from FhirContactPointMap fcp where fcp.attributeTypeDomain = 'person' and fcp.attributeTypeId = :attribute_type_id") | ||
.setParameter("attribute_type_id", attributeType.getId()).uniqueResult()); | ||
} | ||
|
||
@Override | ||
public Optional<FhirContactPointMap> getFhirContactPointMapForAttributeType( | ||
@Nonnull BaseAttributeType<?> attributeType) { | ||
if (attributeType == null) { | ||
return Optional.empty(); | ||
Check warning on line 54 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L54
|
||
} | ||
|
||
String attributeTypeClassName = attributeType.getClass().getSimpleName(); | ||
if (attributeTypeClassName == null || "".equals(attributeTypeClassName) | ||
|| !attributeTypeClassName.endsWith("AttributeType")) { | ||
return Optional.empty(); | ||
Check warning on line 60 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L60
|
||
} | ||
|
||
String attributeTypeDomain = StringUtils.removeEnd(attributeTypeClassName.toLowerCase(), "attributetype"); | ||
if (attributeType instanceof LocationAttributeType) { | ||
attributeTypeDomain = "location"; | ||
} else if (attributeType instanceof ProviderAttributeType) { | ||
attributeTypeDomain = "provider"; | ||
} | ||
|
||
if (attributeTypeDomain == null) { | ||
return Optional.empty(); | ||
Check warning on line 71 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L71
|
||
} | ||
|
||
return Optional.ofNullable((FhirContactPointMap) sessionFactory.getCurrentSession().createQuery( | ||
"from FhirContactPointMap fcp where fcp.attributeTypeDomain = :attribute_type_domain and fcp.attributeTypeId = :attribute_type_id") | ||
.setParameter("attribute_type_domain", attributeTypeDomain) | ||
.setParameter("attribute_type_id", attributeType.getId()).uniqueResult()); | ||
} | ||
|
||
@Override | ||
public FhirContactPointMap saveFhirContactPointMap(@Nonnull FhirContactPointMap contactPointMap) { | ||
FhirContactPointMap existingContactPointMap = (FhirContactPointMap) sessionFactory.getCurrentSession().createQuery( | ||
Check warning on line 82 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L82
|
||
"from FhirContactPointMap fcp where fcp.attributeTypeDomain = :attribute_type_domain and fcp.attributeTypeId = :attribute_type_id") | ||
.setParameter("attribute_type_domain", contactPointMap.getAttributeTypeDomain()) | ||
.setParameter("attribute_type_id", contactPointMap.getAttributeTypeId()).uniqueResult(); | ||
Check warning on line 85 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L84-L85
|
||
|
||
if (existingContactPointMap != null) { | ||
existingContactPointMap.setSystem(contactPointMap.getSystem()); | ||
existingContactPointMap.setUse(contactPointMap.getUse()); | ||
existingContactPointMap.setRank(contactPointMap.getRank()); | ||
sessionFactory.getCurrentSession().merge(existingContactPointMap); | ||
return existingContactPointMap; | ||
Check warning on line 92 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L88-L92
|
||
} else { | ||
sessionFactory.getCurrentSession().saveOrUpdate(contactPointMap); | ||
return contactPointMap; | ||
Check warning on line 95 in api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java Codecov / codecov/patchapi/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImpl.java#L94-L95
|
||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.fhir2.api.impl; | ||
|
||
import java.util.Optional; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.attribute.BaseAttributeType; | ||
import org.openmrs.module.fhir2.api.FhirContactPointMapService; | ||
import org.openmrs.module.fhir2.api.dao.FhirContactPointMapDao; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@Transactional | ||
@Setter(AccessLevel.PACKAGE) | ||
public class FhirContactPointMapServiceImpl implements FhirContactPointMapService { | ||
|
||
@Autowired | ||
private FhirContactPointMapDao dao; | ||
|
||
@Transactional(readOnly = true) | ||
@Override | ||
public Optional<FhirContactPointMap> getFhirContactPointMapForPersonAttributeType(PersonAttributeType attributeType) { | ||
return dao.getFhirContactPointMapForPersonAttributeType(attributeType); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
@Override | ||
public Optional<FhirContactPointMap> getFhirContactPointMapForAttributeType(BaseAttributeType<?> attributeType) { | ||
return dao.getFhirContactPointMapForAttributeType(attributeType); | ||
} | ||
|
||
@Override | ||
public FhirContactPointMap saveFhirContactPointMap(FhirContactPointMap contactPointMap) { | ||
return dao.saveFhirContactPointMap(contactPointMap); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.fhir2.model; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem; | ||
import org.hl7.fhir.r4.model.ContactPoint.ContactPointUse; | ||
import org.openmrs.BaseOpenmrsData; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) | ||
@Entity | ||
@Table(name = "fhir_contact_point_map") | ||
@NoArgsConstructor | ||
public class FhirContactPointMap extends BaseOpenmrsData { | ||
|
||
private static final long serialVersionUID = 1742113L; | ||
|
||
@EqualsAndHashCode.Include | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "fhir_contact_point_map_id") | ||
private Integer id; | ||
|
||
@Column(name = "attribute_type_domain", nullable = false) | ||
private String attributeTypeDomain; | ||
|
||
@Column(name = "attribute_type_id", nullable = false) | ||
private Integer attributeTypeId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(length = 50) | ||
private ContactPointSystem system; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(length = 50) | ||
private ContactPointUse use; | ||
|
||
private Integer rank; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a better implementation here (because we can support more than just hard-coded values):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!