Skip to content

Commit be4826f

Browse files
committed
FM2-428: Add support for Batch Bundles
1 parent 1ef6fa9 commit be4826f

File tree

9 files changed

+423
-2
lines changed

9 files changed

+423
-2
lines changed

api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ private FhirConstants() {
9393
public static final String OPENMRS_FHIR_EXT_NON_CODED_CONDITION = OPENMRS_FHIR_EXT_PREFIX + "/non-coded-condition";
9494

9595
public static final String OPENMRS_FHIR_EXT_MEDICINE = OPENMRS_FHIR_EXT_PREFIX + "/medicine";
96-
96+
9797
public static final String OPENMRS_FHIR_EXT_TASK_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/task/identifier";
98-
98+
99+
public static final String OPENMRS_FHIR_EXT_BATCH_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/bundle/identifier";
100+
99101
public static final String OPENMRS_FHIR_EXT_USER_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/user/identifier";
100102

101103
public static final String OPENMRS_FHIR_EXT_PROVIDER_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/provider/identifier";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.api;
11+
12+
import ca.uhn.fhir.model.api.Include;
13+
import ca.uhn.fhir.rest.annotation.Sort;
14+
import ca.uhn.fhir.rest.api.SortSpec;
15+
import ca.uhn.fhir.rest.api.server.IBundleProvider;
16+
import ca.uhn.fhir.rest.param.DateRangeParam;
17+
import ca.uhn.fhir.rest.param.QuantityAndListParam;
18+
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
19+
import ca.uhn.fhir.rest.param.TokenAndListParam;
20+
import org.hl7.fhir.r4.model.Bundle;
21+
22+
import java.util.HashSet;
23+
24+
public interface FhirBatchService extends FhirService<Bundle> {
25+
26+
IBundleProvider searchBatches(TokenAndListParam identifier, TokenAndListParam batchType);
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.api.dao;
11+
12+
import org.openmrs.BaseOpenmrsData;
13+
import org.openmrs.annotation.Authorized;
14+
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
15+
import org.openmrs.module.fhir2.model.FhirBatch;
16+
import org.openmrs.module.fhir2.model.FhirDiagnosticReport;
17+
import org.openmrs.util.PrivilegeConstants;
18+
19+
import javax.annotation.Nonnull;
20+
import java.util.Collection;
21+
import java.util.List;
22+
23+
public interface FhirBatchDao extends FhirDao<FhirBatch> {
24+
25+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.api.dao.impl;
11+
12+
import ca.uhn.fhir.rest.param.TokenAndListParam;
13+
import org.hibernate.Criteria;
14+
import org.openmrs.module.fhir2.FhirConstants;
15+
import org.openmrs.module.fhir2.api.dao.FhirBatchDao;
16+
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
17+
import org.openmrs.module.fhir2.model.FhirBatch;
18+
19+
import java.util.Optional;
20+
21+
import static org.hibernate.criterion.Restrictions.eq;
22+
23+
public class FhirBatchDaoImpl extends BaseFhirDao<FhirBatch> implements FhirBatchDao {
24+
25+
26+
@Override
27+
protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) {
28+
theParams.getParameters().forEach(entry -> {
29+
switch (entry.getKey()) {
30+
case FhirConstants.OPENMRS_FHIR_EXT_BATCH_IDENTIFIER:
31+
handleCommonSearchParameters(entry.getValue()).ifPresent(criteria::add);
32+
break;
33+
case FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER:
34+
entry.getValue()
35+
.forEach(param -> handleAndListParam((TokenAndListParam) param.getParam(),
36+
t -> Optional.of(eq("et.uuid", t.getValue())))
37+
.ifPresent(t -> criteria.createAlias("encounterType", "et").add(t)));
38+
break;
39+
}
40+
});
41+
}
42+
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.api.impl;
11+
12+
import ca.uhn.fhir.rest.api.server.IBundleProvider;
13+
import ca.uhn.fhir.rest.param.TokenAndListParam;
14+
import lombok.AccessLevel;
15+
import lombok.Getter;
16+
import lombok.Setter;
17+
import org.hl7.fhir.r4.model.Bundle;
18+
import org.openmrs.BaseOpenmrsData;
19+
import org.openmrs.module.fhir2.FhirConstants;
20+
import org.openmrs.module.fhir2.api.FhirBatchService;
21+
import org.openmrs.module.fhir2.api.dao.FhirDao;
22+
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
23+
import org.openmrs.module.fhir2.api.translators.OpenmrsFhirTranslator;
24+
import org.springframework.stereotype.Component;
25+
import org.springframework.transaction.annotation.Transactional;
26+
27+
@Component
28+
@Transactional
29+
@Setter(AccessLevel.PACKAGE)
30+
@Getter(AccessLevel.PROTECTED)
31+
public class FhirBatchServiceImpl extends BaseFhirService<Bundle, org.openmrs.BaseOpenmrsData> implements FhirBatchService {
32+
33+
@Override
34+
public IBundleProvider searchBatches(TokenAndListParam identifier, TokenAndListParam batchType) {
35+
SearchParameterMap theParams = new SearchParameterMap()
36+
.addParameter(FhirConstants.OPENMRS_FHIR_EXT_BATCH_IDENTIFIER, identifier)
37+
.addParameter(FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER, batchType);
38+
39+
return null;
40+
}
41+
42+
@Override
43+
protected FhirDao<BaseOpenmrsData> getDao() {
44+
return null;
45+
}
46+
47+
@Override
48+
protected OpenmrsFhirTranslator<BaseOpenmrsData, Bundle> getTranslator() {
49+
return null;
50+
}
51+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.model;
11+
12+
import lombok.Data;
13+
import lombok.EqualsAndHashCode;
14+
import lombok.NoArgsConstructor;
15+
import org.openmrs.BaseOpenmrsData;
16+
import org.openmrs.BaseOpenmrsMetadata;
17+
18+
import javax.persistence.Column;
19+
import javax.persistence.Entity;
20+
import javax.persistence.GeneratedValue;
21+
import javax.persistence.GenerationType;
22+
import javax.persistence.Id;
23+
import javax.persistence.Table;
24+
25+
@Data
26+
@NoArgsConstructor
27+
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
28+
@Entity
29+
@Table(name = "fhir_batch")
30+
public class FhirBatch extends BaseOpenmrsMetadata {
31+
32+
private static final long serialVersionUID = 1L;
33+
34+
@EqualsAndHashCode.Include
35+
@Id
36+
@GeneratedValue(strategy = GenerationType.AUTO)
37+
@Column(name = "diagnostic_report_id")
38+
private Integer id;
39+
40+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.fhir2.providers.r3;
11+
12+
import static lombok.AccessLevel.PACKAGE;
13+
14+
import ca.uhn.fhir.rest.annotation.Create;
15+
import ca.uhn.fhir.rest.annotation.Delete;
16+
import ca.uhn.fhir.rest.annotation.IdParam;
17+
import ca.uhn.fhir.rest.annotation.OperationParam;
18+
import ca.uhn.fhir.rest.annotation.OptionalParam;
19+
import ca.uhn.fhir.rest.annotation.Read;
20+
import ca.uhn.fhir.rest.annotation.ResourceParam;
21+
import ca.uhn.fhir.rest.annotation.Search;
22+
import ca.uhn.fhir.rest.annotation.Update;
23+
import ca.uhn.fhir.rest.api.MethodOutcome;
24+
import ca.uhn.fhir.rest.api.server.IBundleProvider;
25+
import ca.uhn.fhir.rest.param.TokenAndListParam;
26+
import ca.uhn.fhir.rest.server.IResourceProvider;
27+
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
28+
import lombok.Setter;
29+
import org.hl7.fhir.convertors.conv30_40.Bundle30_40;
30+
import org.hl7.fhir.convertors.conv30_40.DiagnosticReport30_40;
31+
import org.hl7.fhir.convertors.conv30_40.Observation30_40;
32+
import org.hl7.fhir.dstu3.model.DiagnosticReport;
33+
import org.hl7.fhir.dstu3.model.IdType;
34+
import org.hl7.fhir.dstu3.model.Observation;
35+
import org.hl7.fhir.dstu3.model.OperationOutcome;
36+
import org.hl7.fhir.instance.model.api.IBaseResource;
37+
import org.hl7.fhir.dstu3.model.Bundle;
38+
import org.openmrs.module.fhir2.api.FhirBatchService;
39+
import org.openmrs.module.fhir2.api.annotations.R3Provider;
40+
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
41+
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
42+
import org.springframework.beans.factory.annotation.Autowired;
43+
import org.springframework.stereotype.Component;
44+
45+
import javax.annotation.Nonnull;
46+
47+
@Component("batchFhirResourceProvider")
48+
@R3Provider
49+
@Setter(PACKAGE)
50+
public class BatchFhirResourceProvider implements IResourceProvider {
51+
52+
@Autowired
53+
FhirBatchService batchService;
54+
55+
@Override
56+
public Class<? extends IBaseResource> getResourceType() {return Bundle.class;}
57+
58+
@Read
59+
@SuppressWarnings("unused")
60+
public Bundle getBatchById(@IdParam @Nonnull IdType id) {
61+
org.hl7.fhir.r4.model.Bundle batch = batchService.get(id.getIdPart());
62+
if (batch == null) {
63+
throw new ResourceNotFoundException("Could not find observation with Id " + id.getIdPart());
64+
}
65+
66+
return Bundle30_40.convertBundle(batch);
67+
}
68+
69+
@Create
70+
@SuppressWarnings("unused")
71+
public MethodOutcome createBatch(@ResourceParam Bundle bundle) {
72+
return FhirProviderUtils.buildCreate(Bundle30_40.convertBundle(batchService.create(Bundle30_40.convertBundle(bundle))));
73+
}
74+
75+
@Update
76+
@SuppressWarnings("unused")
77+
public MethodOutcome updateBatch(@IdParam IdType id, @ResourceParam Bundle bundle) {
78+
String idPart = null;
79+
80+
if (id != null) {
81+
idPart = id.getIdPart();
82+
}
83+
84+
return FhirProviderUtils.buildUpdate(Bundle30_40.convertBundle(batchService.update(idPart, Bundle30_40.convertBundle(bundle))));
85+
}
86+
87+
@Delete
88+
@SuppressWarnings("unused")
89+
public OperationOutcome deleteBatch(@IdParam @Nonnull IdType id) {
90+
org.hl7.fhir.r4.model.Bundle batch = batchService.delete(id.getIdPart());
91+
if (batch == null) {
92+
throw new ResourceNotFoundException("Could not find medication to delete with id " + id.getIdPart());
93+
}
94+
95+
return FhirProviderUtils.buildDelete(Bundle30_40.convertBundle(batch));
96+
}
97+
98+
@Search
99+
public IBundleProvider searchForBatch(
100+
@OptionalParam(name = Bundle.SP_IDENTIFIER) TokenAndListParam identifier,
101+
@OptionalParam(name = Bundle.SP_TYPE) TokenAndListParam batchType) {
102+
return new SearchQueryBundleProviderR3Wrapper(batchService.searchBatches(identifier, batchType));
103+
}
104+
}

0 commit comments

Comments
 (0)