-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FM2-428: Add support for Batch Bundles
- Loading branch information
Showing
9 changed files
with
423 additions
and
2 deletions.
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
27 changes: 27 additions & 0 deletions
27
api/src/main/java/org/openmrs/module/fhir2/api/FhirBatchService.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,27 @@ | ||
/* | ||
* 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 ca.uhn.fhir.model.api.Include; | ||
import ca.uhn.fhir.rest.annotation.Sort; | ||
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.QuantityAndListParam; | ||
import ca.uhn.fhir.rest.param.ReferenceAndListParam; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
|
||
import java.util.HashSet; | ||
|
||
public interface FhirBatchService extends FhirService<Bundle> { | ||
|
||
IBundleProvider searchBatches(TokenAndListParam identifier, TokenAndListParam batchType); | ||
} |
25 changes: 25 additions & 0 deletions
25
api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirBatchDao.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,25 @@ | ||
/* | ||
* 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 org.openmrs.BaseOpenmrsData; | ||
import org.openmrs.annotation.Authorized; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.module.fhir2.model.FhirBatch; | ||
import org.openmrs.module.fhir2.model.FhirDiagnosticReport; | ||
import org.openmrs.util.PrivilegeConstants; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface FhirBatchDao extends FhirDao<FhirBatch> { | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirBatchDaoImpl.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,43 @@ | ||
/* | ||
* 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 ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import org.hibernate.Criteria; | ||
import org.openmrs.module.fhir2.FhirConstants; | ||
import org.openmrs.module.fhir2.api.dao.FhirBatchDao; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.module.fhir2.model.FhirBatch; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.hibernate.criterion.Restrictions.eq; | ||
|
||
public class FhirBatchDaoImpl extends BaseFhirDao<FhirBatch> implements FhirBatchDao { | ||
|
||
|
||
@Override | ||
protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { | ||
theParams.getParameters().forEach(entry -> { | ||
switch (entry.getKey()) { | ||
case FhirConstants.OPENMRS_FHIR_EXT_BATCH_IDENTIFIER: | ||
handleCommonSearchParameters(entry.getValue()).ifPresent(criteria::add); | ||
break; | ||
case FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER: | ||
entry.getValue() | ||
.forEach(param -> handleAndListParam((TokenAndListParam) param.getParam(), | ||
t -> Optional.of(eq("et.uuid", t.getValue()))) | ||
.ifPresent(t -> criteria.createAlias("encounterType", "et").add(t))); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirBatchServiceImpl.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,51 @@ | ||
/* | ||
* 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 ca.uhn.fhir.rest.api.server.IBundleProvider; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.openmrs.BaseOpenmrsData; | ||
import org.openmrs.module.fhir2.FhirConstants; | ||
import org.openmrs.module.fhir2.api.FhirBatchService; | ||
import org.openmrs.module.fhir2.api.dao.FhirDao; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.module.fhir2.api.translators.OpenmrsFhirTranslator; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@Transactional | ||
@Setter(AccessLevel.PACKAGE) | ||
@Getter(AccessLevel.PROTECTED) | ||
public class FhirBatchServiceImpl extends BaseFhirService<Bundle, org.openmrs.BaseOpenmrsData> implements FhirBatchService { | ||
|
||
@Override | ||
public IBundleProvider searchBatches(TokenAndListParam identifier, TokenAndListParam batchType) { | ||
SearchParameterMap theParams = new SearchParameterMap() | ||
.addParameter(FhirConstants.OPENMRS_FHIR_EXT_BATCH_IDENTIFIER, identifier) | ||
.addParameter(FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER, batchType); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected FhirDao<BaseOpenmrsData> getDao() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected OpenmrsFhirTranslator<BaseOpenmrsData, Bundle> getTranslator() { | ||
return null; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
api/src/main/java/org/openmrs/module/fhir2/model/FhirBatch.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,40 @@ | ||
/* | ||
* 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 lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.openmrs.BaseOpenmrsData; | ||
import org.openmrs.BaseOpenmrsMetadata; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) | ||
@Entity | ||
@Table(name = "fhir_batch") | ||
public class FhirBatch extends BaseOpenmrsMetadata { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@EqualsAndHashCode.Include | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "diagnostic_report_id") | ||
private Integer id; | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
api/src/main/java/org/openmrs/module/fhir2/providers/r3/BatchFhirResourceProvider.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,104 @@ | ||
/* | ||
* 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.providers.r3; | ||
|
||
import static lombok.AccessLevel.PACKAGE; | ||
|
||
import ca.uhn.fhir.rest.annotation.Create; | ||
import ca.uhn.fhir.rest.annotation.Delete; | ||
import ca.uhn.fhir.rest.annotation.IdParam; | ||
import ca.uhn.fhir.rest.annotation.OperationParam; | ||
import ca.uhn.fhir.rest.annotation.OptionalParam; | ||
import ca.uhn.fhir.rest.annotation.Read; | ||
import ca.uhn.fhir.rest.annotation.ResourceParam; | ||
import ca.uhn.fhir.rest.annotation.Search; | ||
import ca.uhn.fhir.rest.annotation.Update; | ||
import ca.uhn.fhir.rest.api.MethodOutcome; | ||
import ca.uhn.fhir.rest.api.server.IBundleProvider; | ||
import ca.uhn.fhir.rest.param.TokenAndListParam; | ||
import ca.uhn.fhir.rest.server.IResourceProvider; | ||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; | ||
import lombok.Setter; | ||
import org.hl7.fhir.convertors.conv30_40.Bundle30_40; | ||
import org.hl7.fhir.convertors.conv30_40.DiagnosticReport30_40; | ||
import org.hl7.fhir.convertors.conv30_40.Observation30_40; | ||
import org.hl7.fhir.dstu3.model.DiagnosticReport; | ||
import org.hl7.fhir.dstu3.model.IdType; | ||
import org.hl7.fhir.dstu3.model.Observation; | ||
import org.hl7.fhir.dstu3.model.OperationOutcome; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.dstu3.model.Bundle; | ||
import org.openmrs.module.fhir2.api.FhirBatchService; | ||
import org.openmrs.module.fhir2.api.annotations.R3Provider; | ||
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper; | ||
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component("batchFhirResourceProvider") | ||
@R3Provider | ||
@Setter(PACKAGE) | ||
public class BatchFhirResourceProvider implements IResourceProvider { | ||
|
||
@Autowired | ||
FhirBatchService batchService; | ||
|
||
@Override | ||
public Class<? extends IBaseResource> getResourceType() {return Bundle.class;} | ||
|
||
@Read | ||
@SuppressWarnings("unused") | ||
public Bundle getBatchById(@IdParam @Nonnull IdType id) { | ||
org.hl7.fhir.r4.model.Bundle batch = batchService.get(id.getIdPart()); | ||
if (batch == null) { | ||
throw new ResourceNotFoundException("Could not find observation with Id " + id.getIdPart()); | ||
} | ||
|
||
return Bundle30_40.convertBundle(batch); | ||
} | ||
|
||
@Create | ||
@SuppressWarnings("unused") | ||
public MethodOutcome createBatch(@ResourceParam Bundle bundle) { | ||
return FhirProviderUtils.buildCreate(Bundle30_40.convertBundle(batchService.create(Bundle30_40.convertBundle(bundle)))); | ||
} | ||
|
||
@Update | ||
@SuppressWarnings("unused") | ||
public MethodOutcome updateBatch(@IdParam IdType id, @ResourceParam Bundle bundle) { | ||
String idPart = null; | ||
|
||
if (id != null) { | ||
idPart = id.getIdPart(); | ||
} | ||
|
||
return FhirProviderUtils.buildUpdate(Bundle30_40.convertBundle(batchService.update(idPart, Bundle30_40.convertBundle(bundle)))); | ||
} | ||
|
||
@Delete | ||
@SuppressWarnings("unused") | ||
public OperationOutcome deleteBatch(@IdParam @Nonnull IdType id) { | ||
org.hl7.fhir.r4.model.Bundle batch = batchService.delete(id.getIdPart()); | ||
if (batch == null) { | ||
throw new ResourceNotFoundException("Could not find medication to delete with id " + id.getIdPart()); | ||
} | ||
|
||
return FhirProviderUtils.buildDelete(Bundle30_40.convertBundle(batch)); | ||
} | ||
|
||
@Search | ||
public IBundleProvider searchForBatch( | ||
@OptionalParam(name = Bundle.SP_IDENTIFIER) TokenAndListParam identifier, | ||
@OptionalParam(name = Bundle.SP_TYPE) TokenAndListParam batchType) { | ||
return new SearchQueryBundleProviderR3Wrapper(batchService.searchBatches(identifier, batchType)); | ||
} | ||
} |
Oops, something went wrong.