Skip to content

Commit

Permalink
FM2-428: Add support for Batch Bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsereko committed Feb 9, 2022
1 parent 1ef6fa9 commit be4826f
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ private FhirConstants() {
public static final String OPENMRS_FHIR_EXT_NON_CODED_CONDITION = OPENMRS_FHIR_EXT_PREFIX + "/non-coded-condition";

public static final String OPENMRS_FHIR_EXT_MEDICINE = OPENMRS_FHIR_EXT_PREFIX + "/medicine";

public static final String OPENMRS_FHIR_EXT_TASK_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/task/identifier";


public static final String OPENMRS_FHIR_EXT_BATCH_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/bundle/identifier";

public static final String OPENMRS_FHIR_EXT_USER_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/user/identifier";

public static final String OPENMRS_FHIR_EXT_PROVIDER_IDENTIFIER = OPENMRS_FHIR_EXT_PREFIX + "/provider/identifier";
Expand Down
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);
}
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> {

}
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;
}
});
}

}
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 api/src/main/java/org/openmrs/module/fhir2/model/FhirBatch.java
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;

}
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));
}
}

0 comments on commit be4826f

Please sign in to comment.