-
Notifications
You must be signed in to change notification settings - Fork 110
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-130:Adding support for the FHIR Media resource #328
Draft
tendomart
wants to merge
31
commits into
openmrs:master
Choose a base branch
from
tendomart:FM2-130
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d785e97
FM2-130:Adding support for the FHIR Media resource
tendomart 68e5bd4
Refining Media Complex Obs Handler
tendomart d508846
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 39be2b1
Adding Search params , Service and Translator Layers
tendomart 0aca54d
Doing more refining
tendomart b28be07
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 53d8ff7
Implementing fhir media translator
tendomart ba5c351
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 027f483
Doing cleaning
tendomart 9fda48d
Removing duplicate code
tendomart 5041fa2
Doing more refactorings and adding unit tests for Tranlator , service…
tendomart f4a4bed
Fine tuning Media search params doing other changes
tendomart 1ba904b
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart dd4b80e
Doing more refactoring
tendomart da7d841
Removing commented out lines
tendomart aea79f8
Doing more rectifications
tendomart b26adb3
Adding search params and FhirMediaDaoImplTest
tendomart d2625e6
Adding Media element translators
tendomart 74103bc
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 119fb76
Deleting unnecessary Media Translators
tendomart 619d08b
Refining Translators
tendomart ee13f88
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 86e2ca9
Refining MediaContentTranslator and Accompanying tests
tendomart a8c2605
Refactoring translators
tendomart 3933575
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 93f2f45
Rectifying project build failure
tendomart 9c843e8
Doing more fixes
tendomart bb9dbdf
Dealing with FhirMediaDaoImplTest failing tests
tendomart b6888be
Making FhirMediaDaoImpl CRUD methods work
tendomart 6d2e407
Merge branch 'master' of https://github.com/openmrs/openmrs-module-fh…
tendomart 5c79a15
Removing redundant code
tendomart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
30 changes: 30 additions & 0 deletions
30
api/src/main/java/org/openmrs/module/fhir2/api/FhirMediaService.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,30 @@ | ||
/* | ||
* 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.HashSet; | ||
|
||
import ca.uhn.fhir.model.api.Include; | ||
import ca.uhn.fhir.rest.api.SortSpec; | ||
import ca.uhn.fhir.rest.api.server.IBundleProvider; | ||
import ca.uhn.fhir.rest.param.DateRangeParam; | ||
import ca.uhn.fhir.rest.param.ReferenceAndListParam; | ||
import ca.uhn.fhir.rest.param.StringAndListParam; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import org.hl7.fhir.r4.model.Media; | ||
|
||
public interface FhirMediaService extends FhirService<Media> { | ||
|
||
IBundleProvider searchForMedia(TokenAndListParam status, TokenAndListParam type, ReferenceAndListParam subject, | ||
ReferenceAndListParam encounterReference, DateRangeParam createdDateTime, TokenAndListParam contentType, | ||
TokenAndListParam id, StringAndListParam contentDataType, StringAndListParam contentTitle, | ||
DateRangeParam contentCreated, DateRangeParam lastUpdated, HashSet<Include> includes, | ||
HashSet<Include> revIncludes, SortSpec sort); | ||
} |
39 changes: 39 additions & 0 deletions
39
api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirMediaDao.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 @@ | ||
/* | ||
* 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 javax.annotation.Nonnull; | ||
|
||
import java.util.List; | ||
|
||
import org.openmrs.Obs; | ||
import org.openmrs.annotation.Authorized; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.util.PrivilegeConstants; | ||
|
||
public interface FhirMediaDao extends FhirDao<Obs> { | ||
|
||
@Override | ||
@Authorized(PrivilegeConstants.GET_OBS) | ||
Obs get(@Nonnull String uuid); | ||
|
||
@Override | ||
@Authorized(PrivilegeConstants.ADD_OBS) | ||
Obs createOrUpdate(@Nonnull Obs newEntry); | ||
|
||
@Override | ||
@Authorized(PrivilegeConstants.DELETE_OBS) | ||
Obs delete(@Nonnull String uuid); | ||
|
||
@Override | ||
@Authorized(PrivilegeConstants.GET_OBS) | ||
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams); | ||
|
||
} |
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
119 changes: 119 additions & 0 deletions
119
api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMediaDaoImpl.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 @@ | ||
/* | ||
* 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 static org.hibernate.criterion.Restrictions.eq; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import ca.uhn.fhir.rest.param.DateParam; | ||
import ca.uhn.fhir.rest.param.ReferenceAndListParam; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import lombok.AccessLevel; | ||
import lombok.Setter; | ||
import org.hibernate.Criteria; | ||
import org.openmrs.Obs; | ||
import org.openmrs.api.ObsService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.fhir2.FhirConstants; | ||
import org.openmrs.module.fhir2.api.dao.FhirMediaDao; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Setter(AccessLevel.PACKAGE) | ||
public class FhirMediaDaoImpl extends BaseFhirDao<Obs> implements FhirMediaDao{ | ||
|
||
private ObsService obsService = Context.getObsService(); | ||
|
||
@Override | ||
public Obs get(@Nonnull String uuid) { | ||
return obsService.getObsByUuid(uuid); | ||
} | ||
|
||
@Override | ||
public Obs createOrUpdate(@Nonnull Obs newEntry) { | ||
return newEntry; | ||
} | ||
|
||
@Override | ||
public Obs delete(@Nonnull String uuid) { | ||
return obsService.getObsByUuid(uuid); | ||
} | ||
|
||
@Override | ||
public List<Obs> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids) { | ||
return resourceUuids.stream().map(obsService::getObsByUuid).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { | ||
theParams.getParameters().forEach(entry -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, we'll want to ensure that we're only searching ComplexObs and not just any Obs. This looks like it could be done as something like: if (lacksAlias(criteria, "c")) {
criteria.createAlias("concept", "c");
}
if (lacksAlias(criteria, "cdt")) {
criteria.createAlias("c.datatype", "cdt");
}
criteria.add(eq("cdt.hl7_abbreviation", "ED")); |
||
switch (entry.getKey()) { | ||
case FhirConstants.MEDIA_STATUS: | ||
entry.getValue().forEach(status -> handleStatus(criteria, (TokenAndListParam) status.getParam())); | ||
break; | ||
case FhirConstants.MEDIA_TYPE: | ||
entry.getValue().forEach(type -> handleMediaType(criteria, (TokenAndListParam) type.getParam())); | ||
break; | ||
case FhirConstants.MEDIA_SUBJECT: | ||
entry.getValue() | ||
.forEach(subject -> handleMediaSubject(criteria, (ReferenceAndListParam) subject.getParam())); | ||
break; | ||
case FhirConstants.MEDIA_ENCOUNTER_REFERENCE: | ||
break; | ||
case FhirConstants.MEDIA_CREATED_DATE_TIME: | ||
entry.getValue().forEach( | ||
createdTime -> handleDate(createdTime.getPropertyName(), (DateParam) createdTime.getParam()) | ||
.ifPresent(criteria::add)); | ||
break; | ||
case FhirConstants.MEDIA_CONTENT_TYPE: | ||
break; | ||
case FhirConstants.CONTENT_DATA: | ||
break; | ||
case FhirConstants.CONTENT_TITLE: | ||
break; | ||
case FhirConstants.CONTENT_DATE_OF_CREATION: | ||
entry.getValue().forEach(contentDateOfCreation -> handleDate(contentDateOfCreation.getPropertyName(), | ||
(DateParam) contentDateOfCreation.getParam())); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
private void handleStatus(Criteria criteria, TokenAndListParam status) { | ||
// handleAndListParam(status, (data) -> propertyLike("status", status)).ifPresent(criteria::add); | ||
} | ||
|
||
private void handleMediaType(Criteria criteria, TokenAndListParam mediaType) { | ||
if (mediaType != null) { | ||
if (lacksAlias(criteria, "mt")) { | ||
criteria.createAlias("mediaType", "mt"); | ||
handleAndListParam(mediaType, (tag) -> Optional.of(eq("mt.type", tag.getValue()))).ifPresent(criteria::add); | ||
} | ||
} | ||
} | ||
|
||
private void handleMediaSubject(Criteria criteria, ReferenceAndListParam mediaSubject) { | ||
if (mediaSubject != null) { | ||
if (lacksAlias(criteria, "ms")) { | ||
criteria.createAlias("mediaSubject", "ms"); | ||
handleAndListParam(mediaSubject, (tag) -> Optional.of(eq("ms.subject", tag.getValue()))) | ||
.ifPresent(criteria::add); | ||
|
||
} | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirMediaServiceImpl.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,77 @@ | ||
/* | ||
* 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.HashSet; | ||
|
||
import ca.uhn.fhir.model.api.Include; | ||
import ca.uhn.fhir.rest.api.SortSpec; | ||
import ca.uhn.fhir.rest.api.server.IBundleProvider; | ||
import ca.uhn.fhir.rest.param.DateRangeParam; | ||
import ca.uhn.fhir.rest.param.ReferenceAndListParam; | ||
import ca.uhn.fhir.rest.param.StringAndListParam; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hl7.fhir.r4.model.Media; | ||
import org.openmrs.Obs; | ||
import org.openmrs.module.fhir2.FhirConstants; | ||
import org.openmrs.module.fhir2.api.FhirMediaService; | ||
import org.openmrs.module.fhir2.api.dao.FhirMediaDao; | ||
import org.openmrs.module.fhir2.api.search.SearchQuery; | ||
import org.openmrs.module.fhir2.api.search.SearchQueryInclude; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.module.fhir2.api.translators.MediaTranslator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@Transactional | ||
@Getter(AccessLevel.PROTECTED) | ||
@Setter(AccessLevel.MODULE) | ||
public class FhirMediaServiceImpl extends BaseFhirService<Media, Obs> implements FhirMediaService { | ||
|
||
@Autowired | ||
private FhirMediaDao dao; | ||
|
||
@Autowired | ||
private MediaTranslator translator; | ||
|
||
@Autowired | ||
private SearchQuery<Obs, Media, FhirMediaDao, MediaTranslator, SearchQueryInclude<Media>> searchQuery; | ||
|
||
@Autowired | ||
private SearchQueryInclude<Media> searchQueryInclude; | ||
|
||
@Override | ||
public IBundleProvider searchForMedia(TokenAndListParam status, TokenAndListParam type, ReferenceAndListParam subject, | ||
ReferenceAndListParam encounterReference, DateRangeParam createdDateTime, TokenAndListParam contentType, | ||
TokenAndListParam id, StringAndListParam contentDataType, StringAndListParam contentTitle, | ||
DateRangeParam contentCreated, DateRangeParam lastUpdated, HashSet<Include> includes, | ||
HashSet<Include> revIncludes, SortSpec sort) { | ||
|
||
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.MEDIA_STATUS, status) | ||
.addParameter(FhirConstants.MEDIA_TYPE, type).addParameter(FhirConstants.MEDIA_SUBJECT, subject) | ||
.addParameter(FhirConstants.MEDIA_ENCOUNTER_REFERENCE, encounterReference) | ||
.addParameter(FhirConstants.MEDIA_CREATED_DATE_TIME, createdDateTime) | ||
.addParameter(FhirConstants.MEDIA_CONTENT_TYPE, contentType) | ||
.addParameter(FhirConstants.CONTENT_DATA, contentDataType) | ||
.addParameter(FhirConstants.CONTENT_TITLE, contentTitle) | ||
.addParameter(FhirConstants.CONTENT_DATE_OF_CREATION, contentCreated) | ||
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, id) | ||
tendomart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated) | ||
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, includes) | ||
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, revIncludes).setSortSpec(sort); | ||
|
||
return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
api/src/main/java/org/openmrs/module/fhir2/api/translators/MediaContentTranslator.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,37 @@ | ||
/* | ||
* 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.translators; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.hl7.fhir.r4.model.Media; | ||
import org.openmrs.Obs; | ||
|
||
public interface MediaContentTranslator extends OpenmrsFhirUpdatableTranslator<Obs, Media> { | ||
|
||
/** | ||
* Maps an {@link org.openmrs.Obs} to a corresponding {@link org.hl7.fhir.r4.model.Type} | ||
* | ||
* @param data the obs data to translate | ||
* @return the corresponding FHIR base64 encoded version of the data | ||
*/ | ||
@Override | ||
Media toFhirResource(@Nonnull Obs data); | ||
|
||
/** | ||
* Maps an {@link org.hl7.fhir.r4.model.Type} to a existing {@link org.openmrs.Obs} | ||
* | ||
* @param existingObject the obs data to update | ||
* @param resource the FHIR base64 encoded version of the data to map | ||
* @return an updated version of the obs data | ||
*/ | ||
@Override | ||
Obs toOpenmrsType(@Nonnull Obs existingObject, @Nonnull Media resource); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This doesn't seem right to me. Why did you change the example query?