diff --git a/api-2.1/pom.xml b/api-2.1/pom.xml deleted file mode 100644 index d1cc83a7e0..0000000000 --- a/api-2.1/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - fhir2 - org.openmrs.module - 1.12.0-SNAPSHOT - - 4.0.0 - - fhir2-api-2.1 - jar - FHIR2 API 2.1 - API 2.1 for FHIR2 - - - - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.parent.version} - provided - - - org.openmrs.api - openmrs-api - - - org.projectlombok - lombok - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - - - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - - - - 2.1.4 - - - diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/FhirCohortMembershipDao.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/FhirCohortMembershipDao.java deleted file mode 100644 index 1beb1a4779..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/FhirCohortMembershipDao.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.Collection; -import java.util.List; - -import org.openmrs.CohortMembership; -import org.openmrs.annotation.Authorized; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.util.PrivilegeConstants; - -public interface FhirCohortMembershipDao extends FhirDao { - - @Override - @Authorized(PrivilegeConstants.GET_PATIENT_COHORTS) - CohortMembership get(@Nonnull String uuid); - - @Override - @Authorized(PrivilegeConstants.GET_PATIENT_COHORTS) - List get(@Nonnull Collection uuids); - - @Override - @Authorized(PrivilegeConstants.ADD_COHORTS) - CohortMembership createOrUpdate(@Nonnull CohortMembership newEntry); - - @Override - @Authorized(PrivilegeConstants.DELETE_COHORTS) - CohortMembership delete(@Nonnull String uuid); - - @Override - @Authorized(PrivilegeConstants.GET_PATIENT_COHORTS) - List getSearchResults(@Nonnull SearchParameterMap theParams); -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl.java deleted file mode 100644 index 85a43386bf..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 org.hibernate.Criteria; -import org.openmrs.CohortMembership; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.dao.FhirCohortMembershipDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.springframework.stereotype.Component; - -@Component -public class FhirCohortMembershipDaoImpl extends BaseFhirDao implements FhirCohortMembershipDao { - - @Override - protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { - theParams.getParameters().forEach(entry -> { - if (FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER.equals(entry.getKey())) { - entry.getValue().forEach(param -> handleGroupMembers(criteria, (String) param.getParam())); - } - }); - } - - private void handleGroupMembers(Criteria criteria, String groupUuid) { - if (groupUuid != null) { - if ((lacksAlias(criteria, "_c"))) { - criteria.createAlias("cohort", "_c"); - } - criteria.add(eq("_c.uuid", groupUuid)); - } - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1.java deleted file mode 100644 index 30b2562ceb..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 javax.annotation.Nonnull; - -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import org.openmrs.CohortMembership; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirGroupMemberService; -import org.openmrs.module.fhir2.api.dao.FhirCohortMembershipDao; -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.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.model.GroupMember; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -@Primary -@Component -@Transactional -@Setter(AccessLevel.PACKAGE) -@Getter(AccessLevel.PROTECTED) -@OpenmrsProfile(openmrsPlatformVersion = "2.1.0 - 2.*") -public class FhirGroupMemberService_2_1 implements FhirGroupMemberService { - - @Autowired - private FhirCohortMembershipDao fhirCohortMembershipDao; - - @Autowired - private GroupMemberTranslator_2_1 groupMemberTranslator21; - - @Autowired - private SearchQueryInclude searchQueryInclude; - - @Autowired - private SearchQuery> searchQuery; - - @Override - public IBundleProvider getGroupMembers(@Nonnull String groupUuid) { - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER, - groupUuid); - return searchQuery.getQueryResults(theParams, fhirCohortMembershipDao, groupMemberTranslator21, searchQueryInclude); - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupComponentTranslator.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupComponentTranslator.java deleted file mode 100644 index 9f1a04c5f3..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupComponentTranslator.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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 org.hl7.fhir.r4.model.Group; -import org.openmrs.module.fhir2.model.GroupMember; - -public interface GroupComponentTranslator extends OpenmrsFhirTranslator {} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupMemberTranslator_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupMemberTranslator_2_1.java deleted file mode 100644 index d795249efa..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/GroupMemberTranslator_2_1.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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 org.openmrs.CohortMembership; -import org.openmrs.module.fhir2.model.GroupMember; - -public interface GroupMemberTranslator_2_1 extends OpenmrsFhirUpdatableTranslator {} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImpl.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImpl.java deleted file mode 100644 index bde9e2b05b..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.impl; - -import javax.annotation.Nonnull; - -import org.hl7.fhir.r4.model.Group; -import org.openmrs.module.fhir2.api.translators.GroupComponentTranslator; -import org.openmrs.module.fhir2.model.GroupMember; -import org.springframework.stereotype.Component; - -@Component -public class GroupComponentTranslatorImpl implements GroupComponentTranslator { - - @Override - public Group.GroupMemberComponent toFhirResource(@Nonnull GroupMember member) { - Group.GroupMemberComponent component = new Group.GroupMemberComponent(); - component.setId(member.getId()); - component.setEntity(member.getEntity()); - component.setEntityTarget(member.getEntityTarget()); - component.setInactive(member.getInactive()); - component.setPeriod(member.getPeriod()); - return component; - } - - @Override - public GroupMember toOpenmrsType(@Nonnull Group.GroupMemberComponent component) { - GroupMember member = new GroupMember(); - - if (component.hasId()) { - member.setId(component.getId()); - } - - member.setEntity(component.getEntity()); - member.setEntityTarget(component.getEntityTarget()); - member.setInactive(component.getInactive()); - member.setPeriod(component.getPeriod()); - return member; - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1.java deleted file mode 100644 index 99443ea728..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.impl; - -import static org.apache.commons.lang3.Validate.notNull; - -import javax.annotation.Nonnull; - -import lombok.AccessLevel; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.hl7.fhir.r4.model.Period; -import org.openmrs.CohortMembership; -import org.openmrs.Patient; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.dao.FhirPatientDao; -import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; -import org.openmrs.module.fhir2.model.GroupMember; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -@Slf4j -@Primary -@Component -@Setter(AccessLevel.MODULE) -@OpenmrsProfile(openmrsPlatformVersion = "2.1.* - 2.*") -public class GroupMemberTranslatorImpl_2_1 implements GroupMemberTranslator_2_1 { - - @Autowired - private PatientReferenceTranslator patientReferenceTranslator; - - @Autowired - private FhirPatientDao patientDao; - - @Override - public GroupMember toFhirResource(@Nonnull CohortMembership cohortMember) { - notNull(cohortMember, "CohortMember object should not be null"); - GroupMember groupMember = new GroupMember(); - groupMember.setId(cohortMember.getUuid()); - groupMember.setInactive(!cohortMember.isActive()); - - Patient patient = patientDao.getPatientById(cohortMember.getPatientId()); - if (patient != null) { - groupMember.setEntity(patientReferenceTranslator.toFhirResource(patient)); - } - - Period period = new Period(); - period.setStart(cohortMember.getStartDate()); - period.setEnd(cohortMember.getEndDate()); - groupMember.setPeriod(period); - - return groupMember; - } - - @Override - public CohortMembership toOpenmrsType(@Nonnull GroupMember groupMember) { - notNull(groupMember, "GroupMember object should not be null"); - return toOpenmrsType(new CohortMembership(), groupMember); - } - - @Override - public CohortMembership toOpenmrsType(@Nonnull CohortMembership existingCohort, @Nonnull GroupMember groupMember) { - notNull(groupMember, "groupMemberReference object should not be null"); - notNull(existingCohort, "ExistingCohort object should not be null"); - - if (groupMember.hasEntity()) { - existingCohort.setPatientId(patientReferenceTranslator.toOpenmrsType(groupMember.getEntity()).getPatientId()); - } - - if (groupMember.hasPeriod()) { - existingCohort.setStartDate(groupMember.getPeriod().getStart()); - existingCohort.setEndDate(groupMember.getPeriod().getEnd()); - } - - if (groupMember.hasInactive()) { - existingCohort.setVoided(groupMember.getInactive()); - } - - return existingCohort; - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1.java deleted file mode 100644 index 7ec498603d..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.impl; - -import static org.apache.commons.lang3.Validate.notNull; -import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getLastUpdated; -import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getVersionId; - -import javax.annotation.Nonnull; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.hl7.fhir.r4.model.Group; -import org.openmrs.Cohort; -import org.openmrs.CohortMembership; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.translators.GroupComponentTranslator; -import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.api.translators.GroupTranslator; -import org.openmrs.module.fhir2.model.GroupMember; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -@Setter(AccessLevel.MODULE) -@OpenmrsProfile(openmrsPlatformVersion = "2.1.* - 2.*") -public class GroupTranslatorImpl_2_1 extends BaseGroupTranslator implements GroupTranslator { - - @Autowired - private GroupMemberTranslator_2_1 groupMemberTranslator21; - - @Autowired - private GroupComponentTranslator componentTranslator; - - @Override - public Group toFhirResource(@Nonnull Cohort cohort) { - notNull(cohort, "Cohort object should not be null"); - Group group = super.toFhirResource(cohort); - - Collection memberships = cohort.getMemberships(); - log.info("Number of members {} ", memberships.size()); - group.setQuantity(memberships.size()); - memberships.forEach(membership -> group - .addMember(componentTranslator.toFhirResource(groupMemberTranslator21.toFhirResource(membership)))); - - group.getMeta().setLastUpdated(getLastUpdated(cohort)); - group.getMeta().setVersionId(getVersionId(cohort)); - - return group; - } - - @Override - public Cohort toOpenmrsType(@Nonnull Group group) { - notNull(group, "Group resource should not be null"); - return toOpenmrsType(new Cohort(), group); - } - - @Override - public Cohort toOpenmrsType(@Nonnull Cohort existingCohort, @Nonnull Group group) { - notNull(group, "group resource object should not be null"); - notNull(existingCohort, "ExistingCohort object should not be null"); - - Cohort finalExistingCohort = super.toOpenmrsType(existingCohort, group); - - if (group.hasMember()) { - Set memberships = new HashSet<>(); - group.getMember().forEach( - member -> memberships.add(this.setCohort(existingCohort, componentTranslator.toOpenmrsType(member)))); - existingCohort.setMemberships(memberships); - } - - return finalExistingCohort; - } - - private CohortMembership setCohort(Cohort cohort, GroupMember groupMember) { - CohortMembership cohortMembership = groupMemberTranslator21.toOpenmrsType(groupMember); - cohortMembership.setCohort(cohort); - return cohortMembership; - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1.java deleted file mode 100644 index 5625d5d01c..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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.impl; - -import javax.annotation.Nonnull; - -import org.apache.commons.lang.WordUtils; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.openmrs.Obs; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.springframework.stereotype.Component; - -@Component -@OpenmrsProfile(openmrsPlatformVersion = "2.1.* - 2.*") -public class ObservationInterpretationTranslatorImpl_2_1 extends ObservationInterpretationTranslatorImpl { - - @Override - public CodeableConcept toFhirResource(@Nonnull Obs obs) { - if (obs.getInterpretation() == null) { - return null; - } - - CodeableConcept interpretation = new CodeableConcept(); - switch (obs.getInterpretation()) { - case NORMAL: - interpretation.addCoding(addInterpretationCoding("N", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case ABNORMAL: - interpretation.addCoding(addInterpretationCoding("A", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case CRITICALLY_ABNORMAL: - interpretation.addCoding(addInterpretationCoding("AA", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case CRITICALLY_HIGH: - interpretation.addCoding(addInterpretationCoding("HH", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case CRITICALLY_LOW: - interpretation.addCoding(addInterpretationCoding("LL", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case HIGH: - interpretation.addCoding(addInterpretationCoding("H", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case LOW: - interpretation.addCoding(addInterpretationCoding("L", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case OFF_SCALE_LOW: - interpretation.addCoding(addInterpretationCoding("<", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case OFF_SCALE_HIGH: - interpretation.addCoding(addInterpretationCoding(">", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case SIGNIFICANT_CHANGE_DOWN: - interpretation.addCoding(addInterpretationCoding("D", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case SIGNIFICANT_CHANGE_UP: - interpretation.addCoding(addInterpretationCoding("U", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case RESISTANT: - interpretation.addCoding(addInterpretationCoding("R", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case SUSCEPTIBLE: - interpretation.addCoding(addInterpretationCoding("S", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case INTERMEDIATE: - interpretation.addCoding(addInterpretationCoding("I", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case POSITIVE: - interpretation.addCoding(addInterpretationCoding("POS", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case NEGATIVE: - interpretation.addCoding(addInterpretationCoding("NEG", obs.getInterpretation())); - setText(interpretation, obs.getInterpretation()); - break; - case VERY_SUSCEPTIBLE: - interpretation.addCoding(new Coding().setSystem(FhirConstants.OPENMRS_FHIR_EXT_VS_INTERPRETATION) - .setCode("VS").setDisplay("Very Susceptible")); - setText(interpretation, obs.getInterpretation()); - break; - default: - return interpretation; - - } - return interpretation; - } - - @Override - public Obs toOpenmrsType(@Nonnull Obs openmrsObs, @Nonnull CodeableConcept interpretation) { - if (interpretation.getCoding().size() == 0) { - return null; - } - switch (interpretation.getCoding().get(0).getCode()) { - case "N": - openmrsObs.setInterpretation(Obs.Interpretation.NORMAL); - break; - case "A": - openmrsObs.setInterpretation(Obs.Interpretation.ABNORMAL); - break; - case "AA": - openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_ABNORMAL); - break; - case "HH": - openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_HIGH); - break; - case "LL": - openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_LOW); - break; - case "H": - openmrsObs.setInterpretation(Obs.Interpretation.HIGH); - break; - case "L": - openmrsObs.setInterpretation(Obs.Interpretation.LOW); - break; - case "<": - openmrsObs.setInterpretation(Obs.Interpretation.OFF_SCALE_LOW); - break; - case ">": - openmrsObs.setInterpretation(Obs.Interpretation.OFF_SCALE_HIGH); - break; - case "D": - openmrsObs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN); - break; - case "U": - openmrsObs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_UP); - break; - case "R": - openmrsObs.setInterpretation(Obs.Interpretation.RESISTANT); - break; - case "S": - openmrsObs.setInterpretation(Obs.Interpretation.SUSCEPTIBLE); - break; - case "I": - openmrsObs.setInterpretation(Obs.Interpretation.INTERMEDIATE); - break; - case "POS": - openmrsObs.setInterpretation(Obs.Interpretation.POSITIVE); - break; - case "NEG": - openmrsObs.setInterpretation(Obs.Interpretation.NEGATIVE); - break; - case "VS": - openmrsObs.setInterpretation(Obs.Interpretation.VERY_SUSCEPTIBLE); - break; - default: - openmrsObs.setInterpretation(null); - break; - } - return openmrsObs; - } - - private Coding addInterpretationCoding(String code, Obs.Interpretation display) { - Coding coding = new Coding(); - coding.setSystem(FhirConstants.INTERPRETATION_SYSTEM_URI); - coding.setCode(code); - coding.setDisplay(WordUtils.capitalizeFully(display.toString().replaceAll("_", " "))); - return coding; - } - - private void setText(CodeableConcept interpretation, Obs.Interpretation text) { - interpretation.setText(WordUtils.capitalizeFully(text.toString().replaceAll("_", " "))); - } -} diff --git a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1.java b/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1.java deleted file mode 100644 index be67000daf..0000000000 --- a/api-2.1/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.impl; - -import javax.annotation.Nonnull; - -import org.hl7.fhir.r4.model.Observation; -import org.openmrs.Obs; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.translators.ObservationStatusTranslator; -import org.springframework.stereotype.Component; - -@Component -@OpenmrsProfile(openmrsPlatformVersion = "2.1.* - 2.*") -public class ObservationStatusTranslatorImpl_2_1 implements ObservationStatusTranslator { - - @Override - public Observation.ObservationStatus toFhirResource(@Nonnull Obs obs) { - return Observation.ObservationStatus.valueOf(obs.getStatus().toString()); - } - - @Override - public Obs toOpenmrsType(@Nonnull Obs observation, @Nonnull Observation.ObservationStatus observationStatus) { - if (observationStatus.equals(Observation.ObservationStatus.PRELIMINARY) - || observationStatus.equals(Observation.ObservationStatus.FINAL) - || observationStatus.equals(Observation.ObservationStatus.AMENDED)) { - observation.setStatus(Obs.Status.valueOf(observationStatus.toString())); - } - return observation; - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java deleted file mode 100644 index 76129d6a40..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource({ "classpath:applicationContext-service.xml", "classpath*:moduleApplicationContext.xml" }) -public class TestFhirSpringConfiguration { - -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl_2_1Test.java deleted file mode 100644 index c298e3831d..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirCohortMembershipDaoImpl_2_1Test.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.CohortMembership; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirCohortMembershipDaoImpl_2_1Test extends BaseModuleContextSensitiveTest { - - private static final String COHORT_MEMBER_UUID = "745ff1a2-c2ef-49fd-836f-8a1d936d9ef9"; - - private static final String BAD_UUID = "111ff1a2-c2ef-49fd-836f-8a1d936d9ef0"; - - private static final String COHORT_MEMBER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortMemberDaoImplTest_initial_data.xml"; - - private FhirCohortMembershipDaoImpl dao; - - @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; - - @Before - public void setup() throws Exception { - dao = new FhirCohortMembershipDaoImpl(); - dao.setSessionFactory(sessionFactory); - executeDataSet(COHORT_MEMBER_INITIAL_DATA_XML); - } - - @Test - public void shouldGetCohortMembershipByUUID() { - CohortMembership cohortMembership = dao.get(COHORT_MEMBER_UUID); - assertThat(cohortMembership, notNullValue()); - assertThat(cohortMembership.getUuid(), equalTo(COHORT_MEMBER_UUID)); - assertThat(cohortMembership.getCohort().getCohortId(), equalTo(1)); - } - - @Test - public void shouldReturnNullCohortMembershipWhenGetByBadUuid() { - CohortMembership cohortMembership = dao.get(BAD_UUID); - assertThat(cohortMembership, nullValue()); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImpl_2_1Test.java deleted file mode 100644 index 5ffadb4d2a..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImpl_2_1Test.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.Cohort; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirGroupDaoImpl_2_1Test extends BaseModuleContextSensitiveTest { - - private static final String COHORT_UUID = "1d64befb-3b2e-48e5-85f5-353d43e23e46"; - - private static final String NEW_COHORT_UUID = "111ff1a2-c2ef-49fd-836f-8a1d936d9ef0"; - - private static final String BAD_COHORT_UUID = "005ff1a0-c2ef-49fd-836f-8a1d936d9ef7"; - - private static final String COHORT_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml"; - - private static final String COHORT_NAME = "Covid19 patients"; - - private FhirGroupDaoImpl dao; - - @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; - - @Before - public void setup() throws Exception { - dao = new FhirGroupDaoImpl(); - dao.setSessionFactory(sessionFactory); - executeDataSet(COHORT_INITIAL_DATA_XML); - } - - @Test - public void getByUuid_shouldReturnMatchingCohort() { - Cohort cohort = dao.get(COHORT_UUID); - assertThat(cohort, notNullValue()); - assertThat(cohort.getUuid(), equalTo(COHORT_UUID)); - assertThat(cohort.getName(), equalTo(COHORT_NAME)); - } - - @Test - public void getByWithWrongUuid_shouldReturnNullCohort() { - Cohort cohort = dao.get(BAD_COHORT_UUID); - assertThat(cohort, nullValue()); - } - - @Test - public void shouldSaveGroup() { - Cohort cohort = new Cohort(); - cohort.setUuid(NEW_COHORT_UUID); - cohort.setName(COHORT_NAME); - cohort.setDescription("Test cohort"); - - Cohort result = dao.createOrUpdate(cohort); - assertThat(result, notNullValue()); - assertThat(result.getUuid(), equalTo(NEW_COHORT_UUID)); - assertThat(result.getName(), equalTo(COHORT_NAME)); - } - - @Test - public void shouldUpdateGroupCorrectly() { - Cohort cohort = dao.get(COHORT_UUID); - cohort.setName("Update cohort name"); - - Cohort result = dao.createOrUpdate(cohort); - assertThat(result, notNullValue()); - assertThat(result.getName(), equalTo("Update cohort name")); - } - - @Test - public void shouldDeleteGroup() { - Cohort result = dao.delete(COHORT_UUID); - - assertThat(result, notNullValue()); - assertThat(result.getVoided(), is(true)); - assertThat(result.getVoidReason(), equalTo("Voided via FHIR API")); - } - - @Test - public void shouldReturnNullIfGroupToDeleteDoesNotExist() { - Cohort result = dao.delete(BAD_COHORT_UUID); - - assertThat(result, nullValue()); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1Test.java deleted file mode 100644 index 93f46d5144..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberService_2_1Test.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.hamcrest.Matchers; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.CohortMembership; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; -import org.openmrs.module.fhir2.api.dao.FhirCohortMembershipDao; -import org.openmrs.module.fhir2.api.search.SearchQuery; -import org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider; -import org.openmrs.module.fhir2.api.search.SearchQueryInclude; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.model.GroupMember; - -@RunWith(MockitoJUnitRunner.class) -public class FhirGroupMemberService_2_1Test { - - private static final Integer GROUP_MEMBER_ID = 123; - - private static final String GROUP_MEMBER_UUID = "1359f03d-55d9-4961-b8f8-9a59eddc1f59"; - - private static final String BAD_GROUP_MEMBER_UUID = "02ed36f0-6167-4372-a641-d27b92f7deae"; - - @Mock - private FhirCohortMembershipDao dao; - - @Mock - private GroupMemberTranslator_2_1 translator; - - @Mock - private FhirGlobalPropertyService globalPropertyService; - - @Mock - private SearchQueryInclude searchQueryInclude; - - @Mock - private SearchQuery> searchQuery; - - private FhirGroupMemberService_2_1 groupMemberService; - - private static final int START_INDEX = 0; - - private static final int END_INDEX = 10; - - @Before - public void setup() { - groupMemberService = new FhirGroupMemberService_2_1(); - groupMemberService.setFhirCohortMembershipDao(dao); - groupMemberService.setGroupMemberTranslator21(translator); - groupMemberService.setSearchQuery(searchQuery); - groupMemberService.setSearchQueryInclude(searchQueryInclude); - } - - private List get(IBundleProvider results) { - return results.getResources(START_INDEX, END_INDEX); - } - - @Test - public void shouldSearchForGroupMembersByGroupUuid() { - GroupMember groupMember = mock(GroupMember.class); - CohortMembership cohortMembership = mock(CohortMembership.class); - - List memberships = new ArrayList<>(); - memberships.add(cohortMembership); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER, - GROUP_MEMBER_UUID); - - when(dao.getSearchResults(any())).thenReturn(memberships); - when(translator.toFhirResource(cohortMembership)).thenReturn(groupMember); - when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( - new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude)); - when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); - - IBundleProvider results = groupMemberService.getGroupMembers(GROUP_MEMBER_UUID); - - List resultList = get(results); - - assertThat(results, Matchers.notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(1)); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/search/GroupMemberSearchQueryTest.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/search/GroupMemberSearchQueryTest.java deleted file mode 100644 index 1287c87dd2..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/search/GroupMemberSearchQueryTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.search; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; - -import java.util.List; - -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.dao.FhirCohortMembershipDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.model.GroupMember; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class GroupMemberSearchQueryTest extends BaseModuleContextSensitiveTest { - - private static final String COHORT_MEMBER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortMemberDaoImplTest_initial_data.xml"; - - private static final int START_INDEX = 0; - - private static final int END_INDEX = 10; - - @Autowired - private FhirCohortMembershipDao dao; - - @Autowired - private GroupMemberTranslator_2_1 translator; - - @Autowired - private SearchQueryInclude searchQueryInclude; - - @Autowired - SearchQuery> searchQuery; - - private List get(IBundleProvider results) { - return results.getResources(START_INDEX, END_INDEX); - } - - private IBundleProvider search(SearchParameterMap theParams) { - return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); - } - - @Before - public void setup() throws Exception { - executeDataSet(COHORT_MEMBER_INITIAL_DATA_XML); - } - - @Test - public void searchForGroupMembers_shouldSearchForGroupMembersByGroupUuid() { - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER, - "2d64befb-3b2e-48e5-85f5-353d43e23e48"); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize((6))); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImplTest.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImplTest.java deleted file mode 100644 index 0655e8cc79..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupComponentTranslatorImplTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.impl; - -import static org.exparity.hamcrest.date.DateMatchers.sameDay; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Date; - -import org.hl7.fhir.r4.model.Group; -import org.hl7.fhir.r4.model.Period; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.Resource; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openmrs.module.fhir2.model.GroupMember; - -public class GroupComponentTranslatorImplTest { - - public static final String PATIENT_REF = "Patient/787e12bd-314e-4cc4-9b4d-1cdff9be9545"; - - private GroupComponentTranslatorImpl translator; - - private GroupMember member; - - private Group.GroupMemberComponent component; - - @Before - public void setup() { - translator = new GroupComponentTranslatorImpl(); - component = new Group.GroupMemberComponent(); - member = new GroupMember(); - } - - @Test - public void shouldTranslateEntityToFhirType() { - Reference patientRef = new Reference(PATIENT_REF); - member.setEntity(patientRef); - - Group.GroupMemberComponent result = translator.toFhirResource(member); - assertThat(result.getEntity().getReference(), is(PATIENT_REF)); - } - - @Test - public void shouldTranslateInactiveToFhirType() { - member.setInactive(false); - - assertThat(translator.toFhirResource(member).getInactive(), is(false)); - } - - @Test - public void shouldTranslateEntityToOpenmrsType() { - Reference patientRef = new Reference(PATIENT_REF); - component.setEntity(patientRef); - - GroupMember result = translator.toOpenmrsType(component); - assertThat(result.getEntity().getReference(), is(PATIENT_REF)); - } - - @Test - public void shouldTranslateInactiveToOpenmrsType() { - component.setInactive(false); - - assertThat(translator.toOpenmrsType(component).getInactive(), is(false)); - } - - @Test - public void shouldTranslateEntityTargetToFhirType() { - Resource resource = Mockito.mock(Resource.class); - member.setEntityTarget(resource); - - when(resource.getId()).thenReturn(String.valueOf(1)); - - Group.GroupMemberComponent result = translator.toFhirResource(member); - assertThat(result.getEntityTarget().getId(), is("1")); - } - - @Test - public void shouldTranslatePeriodToFhirType() { - Period period = mock(Period.class); - member.setPeriod(period); - - when(period.getStart()).thenReturn(new Date()); - when(period.getEnd()).thenReturn(new Date()); - - assertThat(translator.toFhirResource(member).getPeriod().getStart(), sameDay(new Date())); - assertThat(translator.toFhirResource(member).getPeriod().getEnd(), sameDay(new Date())); - } - - @Test - public void shouldTranslateEntityTargetToOpenmrsType() { - Resource resource = Mockito.mock(Resource.class); - component.setEntityTarget(resource); - - when(resource.getId()).thenReturn(String.valueOf(1)); - - GroupMember result = translator.toOpenmrsType(component); - assertThat(result.getEntityTarget().getId(), is("1")); - } - - @Test - public void shouldTranslatePeriodToOpenmrsType() { - Period period = mock(Period.class); - component.setPeriod(period); - - when(period.getStart()).thenReturn(new Date()); - when(period.getEnd()).thenReturn(new Date()); - - assertThat(translator.toOpenmrsType(component).getPeriod().getStart(), sameDay(new Date())); - assertThat(translator.toOpenmrsType(component).getPeriod().getEnd(), sameDay(new Date())); - } - -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1Test.java deleted file mode 100644 index 163c398d20..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl_2_1Test.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.Date; - -import org.exparity.hamcrest.date.DateMatchers; -import org.hl7.fhir.r4.model.Period; -import org.hl7.fhir.r4.model.Reference; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.CohortMembership; -import org.openmrs.Patient; -import org.openmrs.module.fhir2.api.dao.FhirPatientDao; -import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; -import org.openmrs.module.fhir2.model.GroupMember; - -@RunWith(MockitoJUnitRunner.class) -public class GroupMemberTranslatorImpl_2_1Test { - - private static final String COHORT_UUID = "787e12bd-314e-4cc4-9b4d-1cdff9be9545"; - - private static final String COHORT_NAME = " John's patientList"; - - @Mock - private PatientReferenceTranslator patientReferenceTranslator; - - @Mock - private FhirPatientDao patientDao; - - private GroupMemberTranslatorImpl_2_1 groupMemberTranslator; - - @Before - public void setup() { - groupMemberTranslator = new GroupMemberTranslatorImpl_2_1(); - groupMemberTranslator.setPatientDao(patientDao); - groupMemberTranslator.setPatientReferenceTranslator(patientReferenceTranslator); - } - - @Test - public void shouldTranslateCohortMemberUuidToFHIRType() { - CohortMembership cohortMembership = mock(CohortMembership.class); - Patient patient = mock(Patient.class); - Reference patientReference = mock(Reference.class); - - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference); - when(patientDao.getPatientById(anyInt())).thenReturn(patient); - when(cohortMembership.getUuid()).thenReturn(COHORT_UUID); - when(patientReference.getReference()).thenReturn(COHORT_UUID); - - GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership); - assertThat(component, notNullValue()); - assertThat(component.hasId(), notNullValue()); - assertThat(component.getEntity().getReference(), is(COHORT_UUID)); - } - - @Test - public void shouldTranslateCohortMemberInactiveToFHIRType() { - CohortMembership cohortMembership = mock(CohortMembership.class); - Patient patient = mock(Patient.class); - Reference patientReference = mock(Reference.class); - - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference); - when(patientDao.getPatientById(anyInt())).thenReturn(patient); - when(cohortMembership.isActive()).thenReturn(true); - - GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership); - assertThat(component, notNullValue()); - assertThat(component.hasInactive(), is(true)); - assertThat(component.getInactive(), is(false)); - } - - @Test - public void shouldTranslateCohortMemberStartDateToFHIRType() { - CohortMembership cohortMembership = mock(CohortMembership.class); - Patient patient = mock(Patient.class); - Reference patientReference = mock(Reference.class); - - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference); - when(patientDao.getPatientById(anyInt())).thenReturn(patient); - when(cohortMembership.getStartDate()).thenReturn(Date.from(Instant.now())); - - GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership); - assertThat(component, notNullValue()); - assertThat(component.hasPeriod(), is(true)); - assertThat(component.getPeriod().getStart(), notNullValue()); - assertThat(Date.from(Instant.now()), DateMatchers.sameDay(component.getPeriod().getStart())); - } - - @Test - public void shouldTranslateCohortMemberEndDateToFHIRType() { - CohortMembership cohortMembership = mock(CohortMembership.class); - Patient patient = mock(Patient.class); - Reference patientReference = mock(Reference.class); - - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference); - when(patientDao.getPatientById(anyInt())).thenReturn(patient); - when(cohortMembership.getEndDate()).thenReturn(Date.from(Instant.now())); - - GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership); - assertThat(component, notNullValue()); - assertThat(component.hasPeriod(), is(true)); - assertThat(component.getPeriod().getEnd(), notNullValue()); - assertThat(Date.from(Instant.now()), DateMatchers.sameDay(component.getPeriod().getEnd())); - } - - @Test - public void shouldTranslateCohortMemberToFHIRGroupEntity() { - CohortMembership cohortMembership = mock(CohortMembership.class); - Patient patient = mock(Patient.class); - Reference patientReference = mock(Reference.class); - - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference); - when(patientDao.getPatientById(anyInt())).thenReturn(patient); - when(cohortMembership.getPatientId()).thenReturn(1); - - GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership); - assertThat(component, notNullValue()); - assertThat(component.hasEntity(), is(true)); - assertThat(component.getEntity(), is(patientReference)); - } - - @Test - public void shouldGroupEntityToCohortPatientIdOpenMRSType() { - Reference patientReference = mock(Reference.class); - Patient patient = mock(Patient.class); - GroupMember groupMember = mock(GroupMember.class); - - when(groupMember.hasEntity()).thenReturn(true); - when(groupMember.getEntity()).thenReturn(patientReference); - when(patient.getPatientId()).thenReturn(1); - when(patientReferenceTranslator.toOpenmrsType(patientReference)).thenReturn(patient); - - CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember); - assertThat(membership, notNullValue()); - assertThat(membership.getPatientId(), notNullValue()); - assertThat(membership.getPatientId(), equalTo(1)); - } - - @Test - public void shouldGroupPeriodToCohortStartAndEndDateOpenMRSType() { - Period period = mock(Period.class); - GroupMember groupMember = mock(GroupMember.class); - - when(groupMember.hasPeriod()).thenReturn(true); - when(groupMember.getPeriod()).thenReturn(period); - when(period.getStart()).thenReturn(Date.from(Instant.now())); - when(period.getEnd()).thenReturn(Date.from(Instant.now())); - - CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember); - assertThat(membership, notNullValue()); - assertThat(membership.getStartDate(), notNullValue()); - assertThat(membership.getEndDate(), notNullValue()); - assertThat(membership.getStartDate(), DateMatchers.sameDay(Date.from(Instant.now()))); - assertThat(membership.getEndDate(), DateMatchers.sameDay(Date.from(Instant.now()))); - } - - @Test - public void shouldUpdatedGroupEntityOrCohortMembersOpenMRSType() { - Reference patientReference = mock(Reference.class); - Patient patient = mock(Patient.class); - GroupMember groupMember = mock(GroupMember.class); - - when(groupMember.hasEntity()).thenReturn(true); - when(groupMember.getEntity()).thenReturn(patientReference); - when(patient.getPatientId()).thenReturn(4); - when(patientReferenceTranslator.toOpenmrsType(patientReference)).thenReturn(patient); - - //Existing cohortMembership with patient id 3 - CohortMembership cohortMembership = new CohortMembership(); - cohortMembership.setPatientId(3); - - CohortMembership membership = groupMemberTranslator.toOpenmrsType(cohortMembership, groupMember); - assertThat(membership, notNullValue()); - assertThat(membership.getPatientId(), notNullValue()); - // Updated cohortMembership with patient id 4 - assertThat(membership.getPatientId(), equalTo(4)); - } - - @Test - public void shouldUpdateCohortMembershipEndDate() { - Period period = mock(Period.class); - GroupMember groupMember = mock(GroupMember.class); - - // Existing cohortMembership - CohortMembership cohortMembership = new CohortMembership(); - cohortMembership.setEndDate(Date.from(Instant.parse("2020-12-04T08:07:00Z"))); - - when(groupMember.hasPeriod()).thenReturn(true); - when(groupMember.getPeriod()).thenReturn(period); - - // Mocked updated date is today - when(period.getEnd()).thenReturn(Date.from(Instant.now())); - - CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember); - assertThat(membership, notNullValue()); - assertThat(membership.getEndDate(), notNullValue()); - assertThat(membership.getEndDate(), DateMatchers.sameDay(Date.from(Instant.now()))); - } - - @Test - public void shouldUpdateCohortMembershipStartDate() { - Period period = mock(Period.class); - GroupMember groupMember = mock(GroupMember.class); - - // Existing cohortMembership - CohortMembership cohortMembership = new CohortMembership(); - cohortMembership.setStartDate(Date.from(Instant.parse("2020-12-04T08:07:00Z"))); - - when(groupMember.hasPeriod()).thenReturn(true); - when(groupMember.getPeriod()).thenReturn(period); - - // Mocked updated date is today - when(period.getStart()).thenReturn(Date.from(Instant.now())); - - CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember); - assertThat(membership, notNullValue()); - assertThat(membership.getStartDate(), notNullValue()); - assertThat(membership.getStartDate(), DateMatchers.sameDay(Date.from(Instant.now()))); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1Test.java deleted file mode 100644 index d757cf07a3..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl_2_1Test.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.exparity.hamcrest.date.DateMatchers; -import org.hamcrest.Matchers; -import org.hl7.fhir.r4.model.Group; -import org.hl7.fhir.r4.model.Period; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.Resource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.Cohort; -import org.openmrs.CohortMembership; -import org.openmrs.User; -import org.openmrs.module.fhir2.api.translators.GroupComponentTranslator; -import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator_2_1; -import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; -import org.openmrs.module.fhir2.model.GroupMember; - -@RunWith(MockitoJUnitRunner.class) -public class GroupTranslatorImpl_2_1Test { - - private static final String COHORT_UUID = "787e12bd-314e-4cc4-9b4d-1cdff9be9545"; - - private static final String NEW_COHORT_UUID = "787e12bd-314e-4cc4-9b4d-1cdff9be9545"; - - private static final String COHORT_NAME = "Patient with VL > 2"; - - @Mock - private GroupMemberTranslator_2_1 groupMemberTranslator21; - - @Mock - private GroupComponentTranslator componentTranslator; - - @Mock - private PractitionerReferenceTranslator practitionerReferenceTranslator; - - private GroupTranslatorImpl_2_1 groupTranslator; - - @Before - public void setup() { - groupTranslator = new GroupTranslatorImpl_2_1(); - groupTranslator.setGroupMemberTranslator21(groupMemberTranslator21); - groupTranslator.setComponentTranslator(componentTranslator); - groupTranslator.setPractitionerReferenceTranslator(practitionerReferenceTranslator); - } - - @Test - public void shouldTranslateUuidToIdFHIRType() { - Cohort cohort = mock(Cohort.class); - when(cohort.getUuid()).thenReturn(COHORT_UUID); - - Group group = groupTranslator.toFhirResource(cohort); - assertThat(group, notNullValue()); - assertThat(group.getId(), is(COHORT_UUID)); - } - - @Test - public void shouldTranslateNameToNameFHIRType() { - Cohort cohort = mock(Cohort.class); - when(cohort.getName()).thenReturn(COHORT_NAME); - - Group group = groupTranslator.toFhirResource(cohort); - assertThat(group, notNullValue()); - assertThat(group.getName(), is(COHORT_NAME)); - } - - @Test - public void shouldTranslateNameOpenMRSTypeToNameFHIRType() { - Group group = mock(Group.class); - when(group.hasName()).thenReturn(true); - when(group.getName()).thenReturn("Mr. Moon's patient list"); - - Cohort cohort = groupTranslator.toOpenmrsType(group); - assertThat(cohort, notNullValue()); - assertThat(cohort.getName(), notNullValue()); - assertThat(cohort.getName(), is("Mr. Moon's patient list")); - } - - @Test - public void shouldReturnUpdatedNameOpenMRSType() { - Cohort cohort = new Cohort(); - cohort.setName("Moon's patient list"); - - Group group = mock(Group.class); - when(group.hasName()).thenReturn(true); - when(group.getName()).thenReturn("Mr. Moon's patient list"); - - Cohort updateCohort = groupTranslator.toOpenmrsType(cohort, group); - assertThat(updateCohort, notNullValue()); - assertThat(updateCohort.getName(), notNullValue()); - assertThat(updateCohort.getName(), is("Mr. Moon's patient list")); - } - - @Test - public void shouldTranslateIsVoidedToIsActiveFHIRType() { - Cohort cohort = mock(Cohort.class); - when(cohort.getVoided()).thenReturn(false); - - Group group = groupTranslator.toFhirResource(cohort); - assertThat(group, notNullValue()); - assertThat(group.getActive(), is(true)); - } - - @Test - public void shouldTranslateActiveFHIRTypeToIsVoidedOpenMRSType() { - Group group = mock(Group.class); - when(group.hasActive()).thenReturn(true); - when(group.getActive()).thenReturn(true); - - Cohort cohort = groupTranslator.toOpenmrsType(group); - assertThat(cohort, notNullValue()); - assertThat(cohort.getVoided(), is(false)); - } - - @Test - public void shouldUpdateIsVoidedOpenMRSType() { - Cohort cohort = new Cohort(); - cohort.setVoided(false); - - Group group = mock(Group.class); - when(group.hasActive()).thenReturn(true); - when(group.getActive()).thenReturn(false); - - Cohort updateCohort = groupTranslator.toOpenmrsType(cohort, group); - assertThat(updateCohort, notNullValue()); - assertThat(updateCohort.getVoided(), is(true)); - } - - @Test - public void shouldTranslateGroupTypeToAlwaysPerson() { - Cohort cohort = mock(Cohort.class); - - Group group = groupTranslator.toFhirResource(cohort); - assertThat(group, notNullValue()); - assertThat(group.getType(), is(Group.GroupType.PERSON)); - } - - @Test - public void shouldTranslateCohortMembersToFHIRGroupMembers() { - Cohort cohort = mock(Cohort.class); - CohortMembership cohortMembership = mock(CohortMembership.class); - Reference patientReference = mock(Reference.class); - - GroupMember member = new GroupMember(); - member.setId("12"); - member.setEntity(mock(Reference.class)); - member.setEntityTarget(mock(Resource.class)); - member.setInactive(false); - member.setPeriod(mock(Period.class)); - - Group.GroupMemberComponent component = mock(Group.GroupMemberComponent.class); - component.setId("12"); - component.setEntity(mock(Reference.class)); - component.setEntityTarget(mock(Resource.class)); - component.setInactive(false); - component.setPeriod(mock(Period.class)); - - when(cohort.getMemberships()).thenReturn(Arrays.asList(cohortMembership, cohortMembership)); - when(groupMemberTranslator21.toFhirResource(cohortMembership)).thenReturn(member); - when(componentTranslator.toFhirResource(member)).thenReturn(component); - when(component.getEntity()).thenReturn(patientReference); - - Group group = groupTranslator.toFhirResource(cohort); - assertThat(group, notNullValue()); - assertThat(group.hasMember(), is(true)); - - List members = group.getMember(); - - assertThat(members, hasSize(2)); - assertThat(members, everyItem(hasProperty("entity", is(patientReference)))); - } - - @Test - public void shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers() { - Group group = mock(Group.class); - CohortMembership cohortMembership = mock(CohortMembership.class); - GroupMember groupMember = mock(GroupMember.class); - Group.GroupMemberComponent groupMemberComponent = mock(Group.GroupMemberComponent.class); - - when(group.hasMember()).thenReturn(true); - when(group.getMember()).thenReturn(Arrays.asList(groupMemberComponent, groupMemberComponent)); - when(groupMemberTranslator21.toOpenmrsType(groupMember)).thenReturn(cohortMembership); - when(componentTranslator.toOpenmrsType(groupMemberComponent)).thenReturn(groupMember); - - Cohort cohort = groupTranslator.toOpenmrsType(group); - assertThat(cohort, notNullValue()); - assertThat(cohort.getMemberships().isEmpty(), is(false)); - assertThat(cohort.getMemberships(), hasSize(1)); - assertThat(cohort.getMemberships().iterator().next(), is(cohortMembership)); - } - - @Test - public void shouldTranslateManagingEntityToCreatorOpenMRSType() { - User user = mock(User.class); - Group group = mock(Group.class); - Reference practitionerRef = mock(Reference.class); - when(practitionerReferenceTranslator.toOpenmrsType(practitionerRef)).thenReturn(user); - when(group.hasManagingEntity()).thenReturn(true); - when(group.getManagingEntity()).thenReturn(practitionerRef); - - group.setManagingEntity(practitionerRef); - - Cohort result = groupTranslator.toOpenmrsType(group); - assertThat(result, notNullValue()); - assertThat(result.getCreator(), notNullValue()); - assertThat(result.getCreator(), is(user)); - } - - @Test - public void shouldTranslateCreatorToManagingEntityFHIRType() { - User user = mock(User.class); - Cohort cohort = new Cohort(); - cohort.setUuid(COHORT_UUID); - cohort.setName(COHORT_NAME); - cohort.setCreator(user); - - Reference practitionerRef = mock(Reference.class); - when(practitionerReferenceTranslator.toFhirResource(user)).thenReturn(practitionerRef); - - Group result = groupTranslator.toFhirResource(cohort); - assertThat(result, notNullValue()); - assertThat(result.hasManagingEntity(), is(true)); - assertThat(result.getManagingEntity(), is(practitionerRef)); - } - - @Test - public void shouldUpdateMemberList() { - CohortMembership cohortMembership = mock(CohortMembership.class); - GroupMember groupMember = mock(GroupMember.class); - Group.GroupMemberComponent component = new Group.GroupMemberComponent(); - component.setId("12"); - component.setEntity(mock(Reference.class)); - component.setEntityTarget(mock(Resource.class)); - component.setInactive(false); - component.setPeriod(mock(Period.class)); - - Cohort existingCohort = new Cohort(); - existingCohort.setUuid(COHORT_UUID); - existingCohort.setVoided(false); - existingCohort.setMemberships(Arrays.asList(cohortMembership, cohortMembership)); - - Group group = mock(Group.class); - when(group.hasMember()).thenReturn(true); - when(groupMemberTranslator21.toOpenmrsType(groupMember)).thenReturn(cohortMembership); - when(group.getMember()).thenReturn(Arrays.asList(component, component)); - when(componentTranslator.toOpenmrsType(component)).thenReturn(groupMember); - - Cohort updateCohort = groupTranslator.toOpenmrsType(existingCohort, group); - assertThat(updateCohort, notNullValue()); - assertThat(updateCohort.getMemberships(), notNullValue()); - assertThat(updateCohort.getMemberships(), hasSize(1)); - } - - @Test - public void shouldTranslateOpenMrsDateChangedToLastUpdated() { - org.openmrs.Cohort cohort = new org.openmrs.Cohort(); - cohort.setDateChanged(new Date()); - - org.hl7.fhir.r4.model.Group result = groupTranslator.toFhirResource(cohort); - - assertThat(result, Matchers.notNullValue()); - assertThat(result.getMeta().getLastUpdated(), DateMatchers.sameDay(new Date())); - } - - @Test - public void shouldTranslateOpenMrsDateChangedToVersionId() { - org.openmrs.Cohort cohort = new org.openmrs.Cohort(); - cohort.setDateChanged(new Date()); - - org.hl7.fhir.r4.model.Group result = groupTranslator.toFhirResource(cohort); - - assertThat(result, Matchers.notNullValue()); - assertThat(result.getMeta().getVersionId(), Matchers.notNullValue()); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1Test.java deleted file mode 100644 index e6fb9594c6..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl_2_1Test.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.Obs; -import org.openmrs.module.fhir2.FhirConstants; - -@RunWith(MockitoJUnitRunner.class) -public class ObservationInterpretationTranslatorImpl_2_1Test { - - private ObservationInterpretationTranslatorImpl_2_1 observationInterpretationTranslator; - - private Obs obs; - - private CodeableConcept interpretation; - - @Before - public void setUp() { - observationInterpretationTranslator = new ObservationInterpretationTranslatorImpl_2_1(); - obs = new Obs(); - interpretation = new CodeableConcept(); - } - - @Test - public void toFhirResource_shouldTranslateNormalInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.NORMAL); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("N")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Normal")); - assertThat(interpretation.getText(), is("Normal")); - } - - @Test - public void toFhirResource_shouldTranslateAbnormalInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.ABNORMAL); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("A")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Abnormal")); - assertThat(interpretation.getText(), is("Abnormal")); - } - - @Test - public void toFhirResource_shouldTranslateCriticallyAbnormalInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.CRITICALLY_ABNORMAL); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("AA")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Critically Abnormal")); - assertThat(interpretation.getText(), is("Critically Abnormal")); - } - - @Test - public void toFhirResource_shouldTranslateCriticallyHighInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.CRITICALLY_HIGH); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("HH")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Critically High")); - assertThat(interpretation.getText(), is("Critically High")); - } - - @Test - public void toFhirResource_shouldTranslateCriticallyLowInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.CRITICALLY_LOW); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("LL")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Critically Low")); - assertThat(interpretation.getText(), is("Critically Low")); - } - - @Test - public void toFhirResource_shouldTranslateHighInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.HIGH); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("H")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("High")); - assertThat(interpretation.getText(), is("High")); - } - - @Test - public void toFhirResource_shouldTranslateLowInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.LOW); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("L")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Low")); - assertThat(interpretation.getText(), is("Low")); - } - - @Test - public void toFhirResource_shouldTranslateOffScaleLowInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.OFF_SCALE_LOW); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("<")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Off Scale Low")); - assertThat(interpretation.getText(), is("Off Scale Low")); - } - - @Test - public void toFhirResource_shouldTranslateOffScaleHighInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.OFF_SCALE_HIGH); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is(">")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Off Scale High")); - assertThat(interpretation.getText(), is("Off Scale High")); - } - - @Test - public void toFhirResource_shouldTranslateSignificantChangeDownInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("D")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Significant Change Down")); - assertThat(interpretation.getText(), is("Significant Change Down")); - } - - @Test - public void toFhirResource_shouldTranslateSignificantChangeUpInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_UP); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("U")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Significant Change Up")); - assertThat(interpretation.getText(), is("Significant Change Up")); - } - - @Test - public void toFhirResource_shouldTranslateResistantInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.RESISTANT); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("R")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Resistant")); - assertThat(interpretation.getText(), is("Resistant")); - } - - @Test - public void toFhirResource_shouldTranslateSusceptibleInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.SUSCEPTIBLE); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("S")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Susceptible")); - assertThat(interpretation.getText(), is("Susceptible")); - } - - @Test - public void toFhirResource_shouldTranslateIntermediateInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.INTERMEDIATE); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("I")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Intermediate")); - assertThat(interpretation.getText(), is("Intermediate")); - } - - @Test - public void toFhirResource_shouldTranslatePositiveInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.POSITIVE); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("POS")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Positive")); - assertThat(interpretation.getText(), is("Positive")); - } - - @Test - public void toFhirResource_shouldTranslateNegativeInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.NEGATIVE); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("NEG")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Negative")); - assertThat(interpretation.getText(), is("Negative")); - } - - @Test - public void toFhirResource_shouldTranslateVerySusceptibleInterpretationCorrectly() { - obs.setInterpretation(Obs.Interpretation.VERY_SUSCEPTIBLE); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, notNullValue()); - assertThat(interpretation.getCoding().get(0).getCode(), is("VS")); - assertThat(interpretation.getCoding().get(0).getDisplay(), is("Very Susceptible")); - assertThat(interpretation.getText(), is("Very Susceptible")); - assertThat(interpretation.getCoding().get(0).getSystem(), is(FhirConstants.OPENMRS_FHIR_EXT_VS_INTERPRETATION)); - } - - @Test - public void toFhirResource_shouldReturnNoFhirInterpretationWhenObsInterpretationIsNull() { - obs.setInterpretation(null); - CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); - assertThat(interpretation, nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnNullIfInterpretationSizeIsZero() { - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldTranslateNormalCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("N"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.NORMAL)); - } - - @Test - public void toOpenmrsType_shouldTranslateAbnormalCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("A"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.ABNORMAL)); - } - - @Test - public void toOpenmrsType_shouldTranslateCriticallyAbnormalCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("AA"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.CRITICALLY_ABNORMAL)); - } - - @Test - public void toOpenmrsType_shouldTranslateCriticallyHighCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("HH"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.CRITICALLY_HIGH)); - } - - @Test - public void toOpenmrsType_shouldTranslateCriticallyLowCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("LL"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.CRITICALLY_LOW)); - } - - @Test - public void toOpenmrsType_shouldTranslateHighCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("H"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.HIGH)); - } - - @Test - public void toOpenmrsType_shouldTranslateLowCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("L"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.LOW)); - } - - @Test - public void toOpenmrsType_shouldTranslateOffScaleLowCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("<"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.OFF_SCALE_LOW)); - } - - @Test - public void toOpenmrsType_shouldTranslateOffScaleHighCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode(">"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.OFF_SCALE_HIGH)); - } - - @Test - public void toOpenmrsType_shouldTranslateSignificantChangeDownCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("D"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN)); - } - - @Test - public void toOpenmrsType_shouldTranslateSignificantChangeUpCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("U"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.SIGNIFICANT_CHANGE_UP)); - } - - @Test - public void toOpenmrsType_shouldTranslateResistantCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("R"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.RESISTANT)); - } - - @Test - public void toOpenmrsType_shouldTranslateSusceptibleCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("S"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.SUSCEPTIBLE)); - } - - @Test - public void toOpenmrsType_shouldTranslateIntermediateCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("I"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.INTERMEDIATE)); - } - - @Test - public void toOpenmrsType_shouldTranslatePositiveCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("POS"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.POSITIVE)); - } - - @Test - public void toOpenmrsType_shouldTranslateNegativeCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("NEG"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.NEGATIVE)); - } - - @Test - public void toOpenmrsType_shouldTranslateVerySusceptibleCodeCorrectly() { - Coding coding = new Coding(); - coding.setCode("VS"); - interpretation.addCoding(coding); - observationInterpretationTranslator.toOpenmrsType(obs, interpretation); - assertThat(obs.getInterpretation(), notNullValue()); - assertThat(obs.getInterpretation(), is(Obs.Interpretation.VERY_SUSCEPTIBLE)); - } -} diff --git a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1Test.java b/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1Test.java deleted file mode 100644 index 0f3c9cba35..0000000000 --- a/api-2.1/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl_2_1Test.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -import org.hl7.fhir.r4.model.Observation; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.Obs; - -@RunWith(MockitoJUnitRunner.class) -public class ObservationStatusTranslatorImpl_2_1Test { - - private static final Obs.Status OBS_STATUS = Obs.Status.FINAL; - - private ObservationStatusTranslatorImpl_2_1 observationStatusTranslator; - - private Obs obs; - - @Before - public void setUp() { - observationStatusTranslator = new ObservationStatusTranslatorImpl_2_1(); - obs = new Obs(); - obs.setStatus(OBS_STATUS); - } - - @Test - public void toFhirResource_shouldTranslateObsStatusToFhirObservationStatus() { - Observation.ObservationStatus status = observationStatusTranslator.toFhirResource(obs); - assertThat(status, notNullValue()); - assertThat(status, is(Observation.ObservationStatus.valueOf(OBS_STATUS.toString()))); - } - - @Test - public void toOpenmrsType_shouldTranslatePreliminaryFhirObservationStatusToObsStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.PRELIMINARY; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), notNullValue()); - assertThat(obs.getStatus(), is(Obs.Status.PRELIMINARY)); - } - - @Test - public void toOpenmrsType_shouldTranslateFinalFhirObservationStatusToObsStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.FINAL; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), notNullValue()); - assertThat(obs.getStatus(), is(Obs.Status.FINAL)); - } - - @Test - public void toOpenmrsType_shouldTranslateAmendedFhirObservationStatusToObsStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.AMENDED; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), notNullValue()); - assertThat(obs.getStatus(), is(Obs.Status.AMENDED)); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedRegisteredStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.REGISTERED; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedCorrectedStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.CORRECTED; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedCancelledStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.CANCELLED; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedEnteredInErrorStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.ENTEREDINERROR; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedUnknownStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.UNKNOWN; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } - - @Test - public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedNullStatus() { - Observation.ObservationStatus status = Observation.ObservationStatus.NULL; - obs.setStatus(null); - observationStatusTranslator.toOpenmrsType(obs, status); - assertThat(obs.getStatus(), nullValue()); - } -} diff --git a/api-2.2/pom.xml b/api-2.2/pom.xml deleted file mode 100644 index dcd52c05a1..0000000000 --- a/api-2.2/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - fhir2 - org.openmrs.module - 1.12.0-SNAPSHOT - - 4.0.0 - - fhir2-api-2.2 - jar - FHIR2 API 2.2 - API 2.2 for FHIR2 - - - - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.parent.version} - provided - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.1 - ${project.parent.version} - provided - - - org.openmrs.api - openmrs-api - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - org.projectlombok - lombok - - - com.google.guava - guava - provided - - - - - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - - - - 2.2.0 - - - diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2.java deleted file mode 100644 index 51ffa5f792..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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 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 lombok.AccessLevel; -import lombok.Setter; -import org.hibernate.Criteria; -import org.hibernate.criterion.Criterion; -import org.openmrs.Condition; -import org.openmrs.ConditionClinicalStatus; -import org.openmrs.annotation.Authorized; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.dao.FhirConditionDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.util.PrivilegeConstants; -import org.springframework.stereotype.Component; - -@Component -@Setter(AccessLevel.PROTECTED) -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class FhirConditionDaoImpl_2_2 extends BaseFhirDao implements FhirConditionDao { - - @Override - @Authorized(PrivilegeConstants.GET_CONDITIONS) - public Condition get(@Nonnull String uuid) { - return super.get(uuid); - } - - @Override - @Authorized(PrivilegeConstants.EDIT_CONDITIONS) - public Condition createOrUpdate(@Nonnull Condition newEntry) { - return super.createOrUpdate(newEntry); - } - - @Override - @Authorized(PrivilegeConstants.DELETE_CONDITIONS) - public Condition delete(@Nonnull String uuid) { - return super.delete(uuid); - } - - @Override - @Authorized(PrivilegeConstants.GET_CONDITIONS) - public List getSearchResults(@Nonnull SearchParameterMap theParams) { - return super.getSearchResults(theParams); - } - - private ConditionClinicalStatus convertStatus(String status) { - if ("active".equalsIgnoreCase(status)) { - return ConditionClinicalStatus.ACTIVE; - } - return ConditionClinicalStatus.INACTIVE; - } - - @Override - public boolean hasDistinctResults() { - return false; - } - - @Override - protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { - theParams.getParameters().forEach(entry -> { - switch (entry.getKey()) { - case FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER: - entry.getValue() - .forEach(param -> handlePatientReference(criteria, (ReferenceAndListParam) param.getParam())); - break; - case FhirConstants.CODED_SEARCH_HANDLER: - entry.getValue().forEach(param -> handleCode(criteria, (TokenAndListParam) param.getParam())); - break; - case FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER: - entry.getValue().forEach(param -> handleClinicalStatus(criteria, (TokenAndListParam) param.getParam())); - break; - case FhirConstants.DATE_RANGE_SEARCH_HANDLER: - entry.getValue() - .forEach(param -> handleDateRange(param.getPropertyName(), (DateRangeParam) param.getParam()) - .ifPresent(criteria::add)); - break; - case FhirConstants.QUANTITY_SEARCH_HANDLER: - entry.getValue().forEach(param -> handleOnsetAge(criteria, (QuantityAndListParam) param.getParam())); - break; - case FhirConstants.COMMON_SEARCH_HANDLER: - handleCommonSearchParameters(entry.getValue()).ifPresent(criteria::add); - break; - } - }); - } - - private void handleCode(Criteria criteria, TokenAndListParam code) { - if (code != null) { - criteria.createAlias("condition.coded", "cd"); - handleCodeableConcept(criteria, code, "cd", "map", "term").ifPresent(criteria::add); - } - } - - private void handleClinicalStatus(Criteria criteria, TokenAndListParam status) { - handleAndListParam(status, tokenParam -> Optional.of(eq("clinicalStatus", convertStatus(tokenParam.getValue())))) - .ifPresent(criteria::add); - } - - private void handleOnsetAge(Criteria criteria, QuantityAndListParam onsetAge) { - handleAndListParam(onsetAge, onsetAgeParam -> handleAgeByDateProperty("onsetDate", onsetAgeParam)) - .ifPresent(criteria::add); - } - - @Override - protected Optional handleLastUpdated(DateRangeParam param) { - return super.handleLastUpdatedImmutable(param); - } - - @Override - protected String paramToProp(@Nonnull String param) { - switch (param) { - case org.hl7.fhir.r4.model.Condition.SP_ONSET_DATE: - return "onsetDate"; - case org.hl7.fhir.r4.model.Condition.SP_RECORDED_DATE: - return "dateCreated"; - } - - return super.paramToProp(param); - } -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2.java deleted file mode 100644 index afa228decb..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 lombok.AccessLevel; -import lombok.Setter; -import org.apache.commons.lang3.StringUtils; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.openmrs.Order; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.dao.FhirEncounterDao; -import org.springframework.stereotype.Component; - -@Component -@Setter(AccessLevel.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class FhirEncounterDaoImpl_2_2 extends FhirEncounterDaoImpl implements FhirEncounterDao { - - @Override - protected Criterion generateNotCompletedOrderQuery(String path) { - if (StringUtils.isNotBlank(path)) { - path = path + "."; - } - - return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"), - Restrictions.ne(path + "fulfillerStatus", org.openmrs.Order.FulfillerStatus.COMPLETED)); - - } - - @Override - protected Criterion generateFulfillerStatusRestriction(String path, String fulfillerStatus) { - - if (StringUtils.isNotBlank(path)) { - path = path + "."; - } - - return Restrictions.eq(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase())); - } - - @Override - protected Criterion generateNotFulfillerStatusRestriction(String path, String fulfillerStatus) { - - if (StringUtils.isNotBlank(path)) { - path = path + "."; - } - - return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"), - Restrictions.ne(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase()))); - } -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_2_2.java deleted file mode 100644 index 2e4673f4b8..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_2_2.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 java.util.Optional; - -import ca.uhn.fhir.rest.param.TokenAndListParam; -import lombok.AccessLevel; -import lombok.Setter; -import org.apache.commons.lang3.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.openmrs.Order; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.springframework.stereotype.Component; - -@Component -@Setter(AccessLevel.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class FhirMedicationRequestDaoImpl_2_2 extends FhirMedicationRequestDaoImpl implements FhirMedicationRequestDao { - - @Override - protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { - theParams.getParameters().forEach(entry -> { - switch (entry.getKey()) { - case FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER: - entry.getValue().forEach( - param -> handleFulfillerStatus((TokenAndListParam) param.getParam()).ifPresent(criteria::add)); - } - }); - super.setupSearchParams(criteria, theParams); - } - - private Optional handleFulfillerStatus(TokenAndListParam tokenAndListParam) { - return handleAndListParam(tokenAndListParam, token -> { - if (token.getValue() != null) { - return Optional.of( - generateFulfillerStatusRestriction(Order.FulfillerStatus.valueOf(token.getValue().toUpperCase()))); - } - return Optional.empty(); - }); - } - - protected Criterion generateFulfillerStatusRestriction(Order.FulfillerStatus fulfillerStatus) { - return generateFulfillerStatusRestriction("", fulfillerStatus); - } - - protected Criterion generateFulfillerStatusRestriction(String path, Order.FulfillerStatus fulfillerStatus) { - if (StringUtils.isNotBlank(path)) { - path = path + "."; - } - - return Restrictions.eq(path + "fulfillerStatus", fulfillerStatus); - } - -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2.java deleted file mode 100644 index 3e53d9b9df..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import org.hl7.fhir.r4.model.Condition; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirConditionService; -import org.openmrs.module.fhir2.api.dao.FhirConditionDao; -import org.openmrs.module.fhir2.api.search.SearchQuery; -import org.openmrs.module.fhir2.api.search.SearchQueryInclude; -import org.openmrs.module.fhir2.api.search.SearchQueryInclude_2_2; -import org.openmrs.module.fhir2.api.search.param.ConditionSearchParams; -import org.openmrs.module.fhir2.api.translators.ConditionTranslator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -@Component -@Transactional -@Setter(AccessLevel.PACKAGE) -@Getter(AccessLevel.PROTECTED) -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class FhirConditionServiceImpl_2_2 extends BaseFhirService implements FhirConditionService { - - @Autowired - private FhirConditionDao dao; - - @Autowired - private ConditionTranslator translator; - - @Autowired - private SearchQueryInclude_2_2 searchQueryInclude; - - @Autowired - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; - - @Override - public IBundleProvider searchConditions(ConditionSearchParams conditionSearchParams) { - conditionSearchParams.toSearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", - conditionSearchParams.getOnsetDate()); - - return searchQuery.getQueryResults(conditionSearchParams.toSearchParameterMap(), dao, translator, - searchQueryInclude); - } -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude_2_2.java deleted file mode 100644 index 81c770af95..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude_2_2.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.search; - -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import ca.uhn.fhir.model.api.Include; -import lombok.NoArgsConstructor; -import org.apache.commons.collections.CollectionUtils; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Condition; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirPatientService; -import org.openmrs.module.fhir2.api.search.param.PropParam; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -@NoArgsConstructor -public class SearchQueryInclude_2_2 extends SearchQueryInclude { - - @Autowired - private FhirPatientService patientService; - - @Override - @SuppressWarnings("unchecked") - public Set getIncludedResources(List resourceList, SearchParameterMap theParams) { - Set includedResourcesSet = new HashSet<>(); - - List> includeParamList = theParams.getParameters(FhirConstants.INCLUDE_SEARCH_HANDLER); - - if (CollectionUtils.isEmpty(includeParamList)) { - return includedResourcesSet; - } - - Set includeSet = (HashSet) includeParamList.get(0).getParam(); - includeSet.forEach(includeParam -> { - switch (includeParam.getParamName()) { - case FhirConstants.INCLUDE_PATIENT_PARAM: - includedResourcesSet.addAll(handlePatientInclude(resourceList, includeParam.getParamType())); - break; - } - }); - - return includedResourcesSet; - } - - private Set handlePatientInclude(List resourceList, String paramType) { - Set includedResources = new HashSet<>(); - Set uniquePatientUUIDs = new HashSet<>(); - - switch (paramType) { - case FhirConstants.CONDITION: - resourceList.forEach(resource -> uniquePatientUUIDs.add(getIdFromReference(resource.getSubject()))); - break; - } - - uniquePatientUUIDs.removeIf(Objects::isNull); - includedResources.addAll(patientService.get(uniquePatientUUIDs)); - - return includedResources; - } - -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2.java deleted file mode 100644 index 283f300cb2..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.impl; - -import static org.apache.commons.lang3.Validate.notNull; -import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getLastUpdated; -import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getVersionId; - -import javax.annotation.Nonnull; - -import java.util.Optional; - -import lombok.AccessLevel; -import lombok.Setter; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.DateTimeType; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.StringType; -import org.openmrs.CodedOrFreeText; -import org.openmrs.Condition; -import org.openmrs.ConditionClinicalStatus; -import org.openmrs.ConditionVerificationStatus; -import org.openmrs.User; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.translators.ConceptTranslator; -import org.openmrs.module.fhir2.api.translators.ConditionClinicalStatusTranslator; -import org.openmrs.module.fhir2.api.translators.ConditionTranslator; -import org.openmrs.module.fhir2.api.translators.ConditionVerificationStatusTranslator; -import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; -import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Setter(AccessLevel.PACKAGE) -@Component -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class ConditionTranslatorImpl_2_2 implements ConditionTranslator { - - @Autowired - private PatientReferenceTranslator patientReferenceTranslator; - - @Autowired - private ConditionClinicalStatusTranslator clinicalStatusTranslator; - - @Autowired - private ConditionVerificationStatusTranslator verificationStatusTranslator; - - @Autowired - private PractitionerReferenceTranslator practitionerReferenceTranslator; - - @Autowired - private ConceptTranslator conceptTranslator; - - @Override - public org.hl7.fhir.r4.model.Condition toFhirResource(@Nonnull Condition condition) { - notNull(condition, "The Openmrs Condition object should not be null"); - - org.hl7.fhir.r4.model.Condition fhirCondition = new org.hl7.fhir.r4.model.Condition(); - fhirCondition.setId(condition.getUuid()); - fhirCondition.setSubject(patientReferenceTranslator.toFhirResource(condition.getPatient())); - fhirCondition.setClinicalStatus(clinicalStatusTranslator.toFhirResource(condition.getClinicalStatus())); - fhirCondition.setVerificationStatus(verificationStatusTranslator.toFhirResource(condition.getVerificationStatus())); - - CodedOrFreeText codedOrFreeTextCondition = condition.getCondition(); - if (codedOrFreeTextCondition != null) { - fhirCondition.setCode(conceptTranslator.toFhirResource(codedOrFreeTextCondition.getCoded())); - if (codedOrFreeTextCondition.getNonCoded() != null) { - Extension extension = new Extension(); - extension.setUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION); - extension.setValue(new StringType(codedOrFreeTextCondition.getNonCoded())); - fhirCondition.addExtension(extension); - } - } - - fhirCondition.setOnset(new DateTimeType().setValue(condition.getOnsetDate())); - if (condition.getEndDate() != null) { - fhirCondition.setAbatement(new DateTimeType().setValue(condition.getEndDate())); - } - - fhirCondition.setRecorder(practitionerReferenceTranslator.toFhirResource(condition.getCreator())); - fhirCondition.setRecordedDate(condition.getDateCreated()); - - fhirCondition.getMeta().setLastUpdated(getLastUpdated(condition)); - fhirCondition.getMeta().setVersionId(getVersionId(condition)); - - return fhirCondition; - } - - @Override - public Condition toOpenmrsType(@Nonnull org.hl7.fhir.r4.model.Condition condition) { - notNull(condition, "The Condition object should not be null"); - return this.toOpenmrsType(new Condition(), condition); - } - - @Override - public Condition toOpenmrsType(@Nonnull Condition existingCondition, - @Nonnull org.hl7.fhir.r4.model.Condition condition) { - notNull(existingCondition, "The existing Openmrs Condition object should not be null"); - notNull(condition, "The Condition object should not be null"); - - if (condition.hasId()) { - existingCondition.setUuid(condition.getIdElement().getIdPart()); - } - - existingCondition.setPatient(patientReferenceTranslator.toOpenmrsType(condition.getSubject())); - existingCondition.setClinicalStatus(clinicalStatusTranslator.toOpenmrsType(condition.getClinicalStatus())); - existingCondition - .setVerificationStatus(verificationStatusTranslator.toOpenmrsType(condition.getVerificationStatus())); - - CodeableConcept codeableConcept = condition.getCode(); - CodedOrFreeText conditionCodedOrText = new CodedOrFreeText(); - Optional extension = Optional - .ofNullable(condition.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION)); - extension.ifPresent(value -> conditionCodedOrText.setNonCoded(String.valueOf(value.getValue()))); - conditionCodedOrText.setCoded(conceptTranslator.toOpenmrsType(codeableConcept)); - existingCondition.setCondition(conditionCodedOrText); - - if (condition.hasOnsetDateTimeType()) { - existingCondition.setOnsetDate(condition.getOnsetDateTimeType().getValue()); - } else if (condition.hasOnsetPeriod()) { - existingCondition.setOnsetDate(condition.getOnsetPeriod().getStart()); - } - - if (condition.hasAbatementDateTimeType()) { - existingCondition.setEndDate(condition.getAbatementDateTimeType().getValue()); - } else if (condition.hasAbatementPeriod()) { - existingCondition.setEndDate(condition.getAbatementPeriod().getEnd()); - } - - existingCondition.setCreator(practitionerReferenceTranslator.toOpenmrsType(condition.getRecorder())); - - return existingCondition; - } -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2.java deleted file mode 100644 index 2b6cfaa54a..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.impl; - -import javax.annotation.Nonnull; - -import org.hl7.fhir.r4.model.MedicationRequest; -import org.openmrs.DrugOrder; -import org.openmrs.Order; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.translators.MedicationRequestStatusTranslator; -import org.springframework.stereotype.Component; - -@Component -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class MedicationRequestStatusTranslatorImpl_2_2 implements MedicationRequestStatusTranslator { - - @Override - public MedicationRequest.MedicationRequestStatus toFhirResource(@Nonnull DrugOrder drugOrder) { - if (drugOrder == null) { - return null; - } - - if (drugOrder.getFulfillerStatus() != null - && drugOrder.getFulfillerStatus().equals(Order.FulfillerStatus.COMPLETED)) { - return MedicationRequest.MedicationRequestStatus.COMPLETED; - } else if (drugOrder.isActive()) { - return MedicationRequest.MedicationRequestStatus.ACTIVE; - } else if (drugOrder.isDiscontinuedRightNow() || drugOrder.getVoided()) { - return MedicationRequest.MedicationRequestStatus.CANCELLED; - } else if (drugOrder.isExpired()) { - return MedicationRequest.MedicationRequestStatus.STOPPED; - } - return MedicationRequest.MedicationRequestStatus.UNKNOWN; - } - -} diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2.java b/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2.java deleted file mode 100644 index 951da0a295..0000000000 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.impl; - -import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; - -import javax.annotation.Nonnull; - -import org.hl7.fhir.r4.model.CodeType; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.openmrs.DrugOrder; -import org.openmrs.Order; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator; -import org.springframework.stereotype.Component; - -@Component -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class MedicationRequestTranslatorImpl_2_2 extends MedicationRequestTranslatorImpl implements MedicationRequestTranslator { - - @Override - public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) { - MedicationRequest medicationRequest = super.toFhirResource(drugOrder); - - if (drugOrder.getFulfillerStatus() != null) { - Extension extension = new Extension(); - extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); - extension.setValue(new CodeType(drugOrder.getFulfillerStatus().toString())); - medicationRequest.addExtension(extension); - } - - return medicationRequest; - } - - @Override - public DrugOrder toOpenmrsType(@Nonnull MedicationRequest medicationRequest) { - return toOpenmrsType(new DrugOrder(), medicationRequest); - - } - - @Override - public DrugOrder toOpenmrsType(@Nonnull DrugOrder existingDrugOrder, @Nonnull MedicationRequest medicationRequest) { - DrugOrder drugOrder = super.toOpenmrsType(existingDrugOrder, medicationRequest); - - if (medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS) != null) { - if (!medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue() - .isEmpty()) { - drugOrder.setFulfillerStatus(Order.FulfillerStatus - .valueOf(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS) - .getValue().toString().toUpperCase())); - } else { - drugOrder.setFulfillerStatus(null); - } - } - - return drugOrder; - } - -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java deleted file mode 100644 index 36e2d2b379..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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; - -import org.mockito.Mockito; -import org.openmrs.module.fhir2.api.util.LocalDateTimeFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class MockedCalendarFactoryConfiguration { - - @Bean - @Primary - public LocalDateTimeFactory getCalendarFactory() { - return Mockito.mock(LocalDateTimeFactory.class); - } - -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java deleted file mode 100644 index 76129d6a40..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/TestFhirSpringConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource({ "classpath:applicationContext-service.xml", "classpath*:moduleApplicationContext.xml" }) -public class TestFhirSpringConfiguration { - -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test.java deleted file mode 100644 index 0be0bc2f7e..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * 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.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.openmrs.test.OpenmrsMatchers.hasId; - -import java.util.List; - -import ca.uhn.fhir.rest.param.HasAndListParam; -import ca.uhn.fhir.rest.param.HasOrListParam; -import ca.uhn.fhir.rest.param.HasParam; -import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.DrugOrder; -import org.openmrs.Encounter; -import org.openmrs.Order; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirEncounterDaoImpl_2_2Test extends BaseModuleContextSensitiveTest { - - private static final Integer ENCOUNTER_WITH_DRUG_ORDERS_ID = 3; - - private static final String ENCOUNTER_WITH_DRUG_ORDERS = "6519d653-393b-4118-9c83-a3715b82d4ac"; // 3 in standard test dataset - - private static final Integer ENCOUNTER_WITH_NO_DRUG_ORDERS_ID = 4; - - private static final String ENCOUNTER_WITH_NO_DRUG_ORDERS = "eec646cb-c847-45a7-98bc-91c8c4f70add"; // 4 in standard test dataset - - private static final Integer ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER = 2003; - - private static final Integer ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER = 2004; - - private static final Integer ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER = 2005; - - private static final String ENCOUNTER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test_initial_data.xml"; - - @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; - - private FhirEncounterDaoImpl_2_2 dao; - - @Before - public void setUp() throws Exception { - dao = new FhirEncounterDaoImpl_2_2(); - dao.setSessionFactory(sessionFactory); - - executeDataSet(ENCOUNTER_INITIAL_DATA_XML); - } - - @Test - public void shouldOnlyReturnEncountersThatHaveAssociatedMedicationRequests() { - Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); - assertThat(withNoDrugOrders, notNullValue()); - assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); - - Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); - assertThat(withDrugOrders, notNullValue()); - assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); - for (Order order : withDrugOrders.getOrders()) { - assertThat(order.getClass(), equalTo(DrugOrder.class)); - } - - HasOrListParam hasOrListParam = new HasOrListParam(); - hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "intent", "order")); - HasAndListParam hasAndListParam = new HasAndListParam(); - hasAndListParam.addAnd(hasOrListParam); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, - hasAndListParam); - - List matchingResources = dao.getSearchResults(theParams); - assertThat("Encounter with Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); - assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); - assertThat("Encounter with only expired Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); - assertThat("Encounter with only completed Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER))); - assertThat("Encounter without Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); - } - - @Test - public void shouldExcludedEncountersWithOnlyCompletedMedicationRequestsWhenReturnEncountersThatHaveAssociatedMedicationRequests() { - Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); - assertThat(withNoDrugOrders, notNullValue()); - assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); - - Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); - assertThat(withDrugOrders, notNullValue()); - assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); - for (Order order : withDrugOrders.getOrders()) { - assertThat(order.getClass(), equalTo(DrugOrder.class)); - } - - HasOrListParam hasOrListParam = new HasOrListParam(); - hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "status:not", "completed")); - HasAndListParam hasAndListParam = new HasAndListParam(); - hasAndListParam.addAnd(hasOrListParam); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, - hasAndListParam); - - List matchingResources = dao.getSearchResults(theParams); - assertThat("Encounter with Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); - assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); - assertThat("Encounter with only expired Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); - assertThat("Encounter with only completed Drug Orders is returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER)))); - assertThat("Encounter without Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); - } - - @Test - public void shouldExcludedEncountersWithMedicationRequestsWithOnlyFulfillerStatusCompletedWhenReturnEncountersThatHaveAssociatedMedicationRequests() { - Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); - assertThat(withNoDrugOrders, notNullValue()); - assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); - - Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); - assertThat(withDrugOrders, notNullValue()); - assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); - for (Order order : withDrugOrders.getOrders()) { - assertThat(order.getClass(), equalTo(DrugOrder.class)); - } - - HasOrListParam hasOrListParam = new HasOrListParam(); - hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "fulfillerStatus:not", "completed")); - HasAndListParam hasAndListParam = new HasAndListParam(); - hasAndListParam.addAnd(hasOrListParam); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, - hasAndListParam); - - List matchingResources = dao.getSearchResults(theParams); - assertThat("Encounter with Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); - assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); - assertThat("Encounter with only expired Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); - assertThat("Encounter with only completed Drug Orders not is returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER)))); - assertThat("Encounter without Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); - } - - @Test - public void shouldOnlyIncludeEncountersWithMedicationRequestsWithFulfillerStatusCompletedWhenReturnEncountersThatHaveAssociatedMedicationRequests() { - Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); - assertThat(withNoDrugOrders, notNullValue()); - assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); - - Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); - assertThat(withDrugOrders, notNullValue()); - assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); - for (Order order : withDrugOrders.getOrders()) { - assertThat(order.getClass(), equalTo(DrugOrder.class)); - } - - HasOrListParam hasOrListParam = new HasOrListParam(); - hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "fulfillerStatus", "completed")); - HasAndListParam hasAndListParam = new HasAndListParam(); - hasAndListParam.addAnd(hasOrListParam); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, - hasAndListParam); - - List matchingResources = dao.getSearchResults(theParams); - assertThat("Encounter with Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID)))); - assertThat("Encounter with only cancelled Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER)))); - assertThat("Encounter with only expired Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER)))); - assertThat("Encounter with only completed Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER))); - assertThat("Encounter without Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); - } -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2Test.java deleted file mode 100644 index 890adb4789..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl_2_2Test.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * 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 static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; - -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.QuantityAndListParam; -import ca.uhn.fhir.rest.param.QuantityOrListParam; -import ca.uhn.fhir.rest.param.QuantityParam; -import ca.uhn.fhir.rest.param.ReferenceAndListParam; -import ca.uhn.fhir.rest.param.ReferenceOrListParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.Condition; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; -import org.openmrs.module.fhir2.api.dao.FhirConditionDao; -import org.openmrs.module.fhir2.api.search.SearchQuery; -import org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider; -import org.openmrs.module.fhir2.api.search.SearchQueryInclude; -import org.openmrs.module.fhir2.api.search.SearchQueryInclude_2_2; -import org.openmrs.module.fhir2.api.search.param.ConditionSearchParams; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.module.fhir2.api.translators.ConditionTranslator; - -@RunWith(MockitoJUnitRunner.class) -public class FhirConditionServiceImpl_2_2Test { - - private static final Integer CONDITION_ID = 123; - - private static final String CONDITION_UUID = "43578769-f1a4-46af-b08b-d9fe8a07066f"; - - private static final String WRONG_CONDITION_UUID = "90378769-f1a4-46af-b08b-d9fe8a09034j"; - - private static final String LAST_UPDATED_DATE = "2020-09-03"; - - private static final int START_INDEX = 0; - - private static final int END_INDEX = 10; - - @Mock - private FhirConditionDao dao; - - @Mock - private ConditionTranslator conditionTranslator; - - @Mock - private FhirGlobalPropertyService globalPropertyService; - - @Mock - private SearchQueryInclude_2_2 searchQueryInclude; - - @Mock - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; - - private FhirConditionServiceImpl_2_2 conditionService; - - private Condition openmrsCondition; - - private org.hl7.fhir.r4.model.Condition fhirCondition; - - @Before - public void setup() { - conditionService = new FhirConditionServiceImpl_2_2() { - - @Override - protected void validateObject(Condition object) { - } - }; - conditionService.setDao(dao); - conditionService.setTranslator(conditionTranslator); - conditionService.setSearchQuery(searchQuery); - conditionService.setSearchQueryInclude(searchQueryInclude); - - openmrsCondition = new Condition(); - openmrsCondition.setUuid(CONDITION_UUID); - - fhirCondition = new org.hl7.fhir.r4.model.Condition(); - fhirCondition.setId(CONDITION_UUID); - } - - private List get(IBundleProvider results) { - return results.getResources(START_INDEX, END_INDEX); - } - - @Test - public void shouldGetConditionByUuid() { - when(dao.get(CONDITION_UUID)).thenReturn(openmrsCondition); - when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(fhirCondition); - - org.hl7.fhir.r4.model.Condition condition = conditionService.get(CONDITION_UUID); - - assertThat(condition, notNullValue()); - assertThat(condition.getId(), notNullValue()); - assertThat(condition.getId(), equalTo(CONDITION_UUID)); - } - - @Test - public void shouldThrowExceptionWhenGetMissingUuid() { - assertThrows(ResourceNotFoundException.class, () -> conditionService.get(WRONG_CONDITION_UUID)); - } - - @Test - public void create_shouldCreateNewCondition() { - Condition openMrsCondition = new Condition(); - openMrsCondition.setUuid(CONDITION_UUID); - - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(CONDITION_UUID); - - when(conditionTranslator.toFhirResource(openMrsCondition)).thenReturn(condition); - when(dao.createOrUpdate(openMrsCondition)).thenReturn(openMrsCondition); - when(conditionTranslator.toOpenmrsType(condition)).thenReturn(openMrsCondition); - - org.hl7.fhir.r4.model.Condition result = conditionService.create(condition); - - assertThat(result, notNullValue()); - assertThat(result.getId(), notNullValue()); - assertThat(result.getId(), equalTo(CONDITION_UUID)); - } - - @Test - public void update_shouldUpdateExistingCondition() { - Condition openmrsCondition = new Condition(); - openmrsCondition.setUuid(CONDITION_UUID); - - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(CONDITION_UUID); - - when(dao.get(CONDITION_UUID)).thenReturn(openmrsCondition); - when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(condition); - when(dao.createOrUpdate(openmrsCondition)).thenReturn(openmrsCondition); - when(conditionTranslator.toOpenmrsType(any(Condition.class), any(org.hl7.fhir.r4.model.Condition.class))) - .thenReturn(openmrsCondition); - - org.hl7.fhir.r4.model.Condition result = conditionService.update(CONDITION_UUID, condition); - - assertThat(result, notNullValue()); - assertThat(result.getId(), notNullValue()); - assertThat(result.getId(), equalTo(CONDITION_UUID)); - } - - @Test - public void update_shouldThrowExceptionWhenIdIsNull() { - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - - assertThrows(InvalidRequestException.class, () -> conditionService.update(null, condition)); - } - - @Test - public void update_shouldThrowExceptionWhenConditionIsNull() { - assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, null)); - } - - @Test - public void update_shouldThrowExceptionWhenConditionIdIsNull() { - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - - assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, condition)); - } - - @Test - public void update_shouldThrowExceptionWhenConditionIdDoesNotMatchCurrentId() { - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(WRONG_CONDITION_UUID); - - assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, condition)); - } - - @Test - public void delete_shouldDeleteExistingCondition() { - Condition openmrsCondition = new Condition(); - openmrsCondition.setUuid(CONDITION_UUID); - - org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(CONDITION_UUID); - - when(dao.delete(CONDITION_UUID)).thenReturn(openmrsCondition); - - conditionService.delete(CONDITION_UUID); - } - - @Test - public void delete_shouldThrowExceptionWhenIdIsNull() { - assertThrows(InvalidRequestException.class, () -> conditionService.delete(null)); - } - - @Test - public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { - ReferenceAndListParam patientReference = new ReferenceAndListParam(); - patientReference.addValue(new ReferenceOrListParam().add(new ReferenceParam(Patient.SP_GIVEN, "patient name"))); - - TokenAndListParam codeList = new TokenAndListParam(); - codeList.addValue(new TokenOrListParam().add(new TokenParam("test code"))); - - TokenAndListParam clinicalList = new TokenAndListParam(); - clinicalList.addValue(new TokenOrListParam().add(new TokenParam("test clinical"))); - - DateRangeParam onsetDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01"); - - QuantityAndListParam onsetAge = new QuantityAndListParam(); - onsetAge.addValue(new QuantityOrListParam().add(new QuantityParam(12))); - - DateRangeParam recordDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01"); - - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); - - DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); - - SortSpec sort = new SortSpec("sort param"); - - HashSet includes = new HashSet<>(); - - SearchParameterMap theParams = new SearchParameterMap() - .addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference) - .addParameter(FhirConstants.CODED_SEARCH_HANDLER, codeList) - .addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, clinicalList) - .addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAge) - .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", onsetDate) - .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", recordDate) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated) - .setSortSpec(sort); - - when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(openmrsCondition)); - when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( - new SearchQueryBundleProvider<>(theParams, dao, conditionTranslator, globalPropertyService, searchQueryInclude)); - when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); - when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(fhirCondition); - - IBundleProvider result = conditionService.searchConditions(new ConditionSearchParams(patientReference, codeList, - clinicalList, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes)); - - List resultList = get(result); - - assertThat(result, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryImpl_2_2Test.java deleted file mode 100644 index 6d2100b8f0..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryImpl_2_2Test.java +++ /dev/null @@ -1,1009 +0,0 @@ -/* - * 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.search; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.when; -import static org.openmrs.test.OpenmrsMatchers.hasId; -import static org.openmrs.test.OpenmrsMatchers.hasUuid; - -import java.time.LocalDateTime; -import java.time.Month; -import java.util.HashSet; -import java.util.List; - -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.DateParam; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ParamPrefixEnum; -import ca.uhn.fhir.rest.param.QuantityAndListParam; -import ca.uhn.fhir.rest.param.QuantityOrListParam; -import ca.uhn.fhir.rest.param.QuantityParam; -import ca.uhn.fhir.rest.param.ReferenceAndListParam; -import ca.uhn.fhir.rest.param.ReferenceOrListParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; -import ca.uhn.fhir.rest.param.TokenOrListParam; -import ca.uhn.fhir.rest.param.TokenParam; -import org.hamcrest.Matchers; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.Condition; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.dao.FhirConditionDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.module.fhir2.api.translators.ConditionTranslator; -import org.openmrs.module.fhir2.api.util.LocalDateTimeFactory; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ConditionSearchQueryImpl_2_2Test extends BaseModuleContextSensitiveTest { - - private static final String CONDITION_UUID = "604953c5-b5c6-4e1e-be95-e37d8f392046"; - - private static final String CONDITION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImplTest_initial_data.xml"; - - private static final String PATIENT_UUID = "a7e04421-525f-442f-8138-05b619d16def"; - - private static final String PATIENT_WRONG_UUID = "c2299800-cca9-11e0-9572-abcdef0c9a66"; - - private static final String PATIENT_GIVEN_NAME = "Johnny"; - - private static final String PATIENT_WRONG_GIVEN_NAME = "Wrong given name"; - - private static final String PATIENT_PARTIAL_NAME = "Johnn"; - - private static final String PATIENT_FAMILY_NAME = "Doe"; - - private static final String PATIENT_WRONG_FAMILY_NAME = "Wrong family name"; - - private static final String PATIENT_NOT_FOUND_NAME = "Igor"; - - private static final String PATIENT_IDENTIFIER = "12345K"; - - private static final String PATIENT_WRONG_IDENTIFIER = "Wrong identifier"; - - private static final String ONSET_DATE_TIME = "2020-03-05T19:00:00"; - - private static final String ONSET_DATE = "2020-03-05 19:00:00"; - - private static final String ONSET_START_DATE = "2020-03-03T22:00:00"; - - private static final String ONSET_END_DATE = "2020-03-08T19:00:00"; - - private static final String RECORDED_DATE_TIME = "2020-03-14T19:32:34"; - - private static final String RECORDED_DATE = "2020-03-14 19:32:34"; - - private static final String RECORDED_START_DATE = "2020-03-12T19:32:34"; - - private static final String RECORDED_END_DATE = "2020-03-20T19:32:34"; - - private static final String STATUS_ACTIVE = "active"; - - private static final String STATUS_INACTIVE = "inactive"; - - private static final String CODE_SYSTEM_1 = "http://made_up_concepts.info/sct"; - - private static final String CODE_VALUE_1 = "CD41003"; - - private static final String CONCEPT_ID_1 = "a09ab2c5-878e-4905-b25d-5784167d0216"; - - private static final String CODE_SYSTEM_2 = "http://made_up_concepts.info/sct"; - - private static final String CODE_VALUE_2 = "WGT234"; - - private static final String CONCEPT_ID_2 = "c607c80f-1ea9-4da3-bb88-6276ce8868dd"; - - private static final String DATE_CREATED = "2020-03-14"; - - private static final String DATE_VOIDED = "2017-01-12"; - - private static final int START_INDEX = 0; - - private static final int END_INDEX = 10; - - @Autowired - private FhirConditionDao dao; - - @Autowired - private ConditionTranslator translator; - - @Autowired - private SearchQueryInclude_2_2 searchQueryInclude; - - @Autowired - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; - - @Autowired - private LocalDateTimeFactory localDateTimeFactory; - - @Before - public void setup() { - executeDataSet(CONDITION_INITIAL_DATA_XML); - } - - private IBundleProvider search(SearchParameterMap theParams) { - return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); - } - - private List get(IBundleProvider results) { - return results.getResources(START_INDEX, END_INDEX); - } - - @Test - public void searchForConditions_shouldReturnConditionByPatientIdentifier() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_IDENTIFIER, PATIENT_IDENTIFIER); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addAnd(new ReferenceOrListParam().addOr(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), - endsWith(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMultiplePatientIdentifierOr() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_IDENTIFIER); - patient.setChain(Patient.SP_IDENTIFIER); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_IDENTIFIER); - badPatient.setChain(Patient.SP_IDENTIFIER); - - referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), - endsWith(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientIdentifierAnd() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_IDENTIFIER); - patient.setChain(Patient.SP_IDENTIFIER); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_IDENTIFIER); - badPatient.setChain(Patient.SP_IDENTIFIER); - - referenceParam.addValue(new ReferenceOrListParam().add(patient)).addAnd(new ReferenceOrListParam().add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnConditionByPatientUuid() { - ReferenceParam patientReference = new ReferenceParam(null, PATIENT_UUID); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addAnd(new ReferenceOrListParam().addOr(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), - equalTo(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMultiplePatientUuidOr() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_UUID); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_UUID); - - referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), - equalTo(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientUuidAnd() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_UUID); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_UUID); - - referenceParam.addValue(new ReferenceOrListParam().add(patient)).addAnd(new ReferenceOrListParam().add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnConditionByPatientGivenName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, PATIENT_GIVEN_NAME); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), - equalTo(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldReturnUniqueConditionsByPatientGivenName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, "Horatio"); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(2)); - - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), hasId(2))); // 6 with repetitions - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_GIVEN_NAME); - patient.setChain(Patient.SP_GIVEN); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_GIVEN_NAME); - badPatient.setChain(Patient.SP_GIVEN); - - referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientGivenNameAnd() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_GIVEN_NAME); - patient.setChain(Patient.SP_GIVEN); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_GIVEN_NAME); - badPatient.setChain(Patient.SP_GIVEN); - - referenceParam.addValue(new ReferenceOrListParam().add(patient)).addAnd(new ReferenceOrListParam().add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionByPatientNotFoundName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, PATIENT_NOT_FOUND_NAME); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnConditionByPatientFamilyName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_FAMILY, PATIENT_FAMILY_NAME); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), - equalTo(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldReturnUniqueConditionsByPatientFamilyName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_FAMILY, "Hornblower"); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(2)); - - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), - hasUuid("2cc6880e-2c46-11e4-9138-a6c5e4d20fb7"))); // 9 with repetitions - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMultiplePatientFamilyNameOr() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_FAMILY_NAME); - patient.setChain(Patient.SP_FAMILY); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_FAMILY_NAME); - badPatient.setChain(Patient.SP_FAMILY); - - referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientFamilyNameAnd() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_FAMILY_NAME); - patient.setChain(Patient.SP_FAMILY); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_WRONG_FAMILY_NAME); - badPatient.setChain(Patient.SP_FAMILY); - - referenceParam.addValue(new ReferenceOrListParam().add(patient)).addAnd(new ReferenceOrListParam().add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnConditionByPatientName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_NAME, PATIENT_PARTIAL_NAME); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), - equalTo(PATIENT_UUID)); - } - - @Test - public void searchForConditions_shouldReturnUniqueConditionsByPatientName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_NAME, "Horatio Hornblower"); - ReferenceAndListParam patientList = new ReferenceAndListParam(); - patientList.addValue(new ReferenceOrListParam().add(patientReference)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - patientList); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(2)); - - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), - hasUuid("2cc6880e-2c46-11e4-9138-a6c5e4d20fb7"))); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMultiplePatientNameOr() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_PARTIAL_NAME); - patient.setChain(Patient.SP_NAME); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_NOT_FOUND_NAME); - badPatient.setChain(Patient.SP_NAME); - - referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientNameAnd() { - ReferenceAndListParam referenceParam = new ReferenceAndListParam(); - ReferenceParam patient = new ReferenceParam(); - - patient.setValue(PATIENT_PARTIAL_NAME); - patient.setChain(Patient.SP_NAME); - - ReferenceParam badPatient = new ReferenceParam(); - - badPatient.setValue(PATIENT_NOT_FOUND_NAME); - badPatient.setChain(Patient.SP_NAME); - - referenceParam.addValue(new ReferenceOrListParam().add(patient)).addAnd(new ReferenceOrListParam().add(badPatient)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, - referenceParam); - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetDate() { - DateRangeParam onsetDate = new DateRangeParam(new DateParam("eq" + ONSET_DATE_TIME)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "onsetDate", onsetDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), - containsString(ONSET_DATE)); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetDateRange() { - DateRangeParam onsetDate = new DateRangeParam(new DateParam(ONSET_START_DATE), new DateParam(ONSET_END_DATE)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "onsetDate", onsetDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat( - ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), - containsString(ONSET_DATE)); - } - - @Test - public void searchForConditions_shouldReturnConditionByUnboundedOnsetDate() { - DateRangeParam onsetDate = new DateRangeParam(new DateParam("gt" + ONSET_START_DATE)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "onsetDate", onsetDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetAgeLessThanHour() { - QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "h")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(CONDITION_UUID)); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetAgeEqualHour() { - QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.EQUAL, 3, "", "h")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(CONDITION_UUID)); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetAgeIntervalDay() { - QuantityOrListParam orListLower = new QuantityOrListParam(); - QuantityOrListParam orListUpper = new QuantityOrListParam(); - orListLower.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 11, "", "d")); - orListUpper.addOr(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 8, "", "d")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orListLower).addAnd(orListUpper); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 22, 22, 0, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - assertThat(results, notNullValue()); - assertThat(resultList, hasSize(1)); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(CONDITION_UUID)); - } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetAgeOrWeekMonthYear() { - QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 4, "", "a")); - orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 3, "", "mo")); - orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 2, "", "wk")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test(expected = IllegalArgumentException.class) - public void searchForConditions_shouldReturnConditionByOnsetAgeExceptionForWrongUnit() { - QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "WRONG_UNIT")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - get(results); - } - - @Test - public void searchForConditions_shouldReturnConditionByRecordedDate() { - DateRangeParam recordedDate = new DateRangeParam(new DateParam("eq" + RECORDED_DATE_TIME)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "dateCreated", recordedDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getRecordedDate().toString(), - containsString(RECORDED_DATE)); - } - - @Test - public void searchForConditions_shouldReturnConditionByRecordedDateRange() { - DateRangeParam onsetDate = new DateRangeParam(new DateParam(RECORDED_START_DATE), new DateParam(RECORDED_END_DATE)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "dateCreated", onsetDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getRecordedDate().toString(), - containsString(RECORDED_DATE)); - } - - @Test - public void searchForConditions_shouldReturnConditionByUnboundedRecordedDate() { - DateRangeParam onsetDate = new DateRangeParam(new DateParam("gt" + RECORDED_START_DATE)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "dateCreated", onsetDate); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnConditionByClinicalStatusActive() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_ACTIVE))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, - listParam); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), greaterThanOrEqualTo(1)); - } - - @Test - public void searchForConditions_shouldReturnConditionByClinicalStatusInactive() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_INACTIVE))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, - listParam); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), greaterThanOrEqualTo(1)); - } - - @Test - public void searchForConditions_shouldReturnConditionByClinicalStatusAll() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_ACTIVE)).add(new TokenParam(STATUS_INACTIVE))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, - listParam); - - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(5)); - } - - @Test - public void searchForConditions_shouldReturnConditionByCode() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(CODE_SYSTEM_1, CODE_VALUE_1))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getCode().getCodingFirstRep().getCode(), - equalTo(CONCEPT_ID_1)); - } - - @Test - public void searchForConditions_shouldReturnMultipleConditionsByCodeList() { - TokenAndListParam listParam = new TokenAndListParam(); - - // Adding codes concept_id=5497 and concept_id=5089. - listParam.addValue(new TokenOrListParam().add(new TokenParam(CODE_SYSTEM_1, CODE_VALUE_1)) - .add(new TokenParam(CODE_SYSTEM_2, CODE_VALUE_2))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldReturnConditionByCodeAndNoSystem() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(CONCEPT_ID_1))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getCode().getCodingFirstRep().getCode(), - equalTo(CONCEPT_ID_1)); - } - - @Test - public void searchForConditions_shouldReturnMultipleConditionsByCodeListAndNoSystem() { - TokenAndListParam listParam = new TokenAndListParam(); - listParam.addValue(new TokenOrListParam().add(new TokenParam(CONCEPT_ID_1)).add(new TokenParam(CONCEPT_ID_2))); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByUuid() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, - FhirConstants.ID_PROPERTY, uuid); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(CONDITION_UUID)); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByLastUpdatedDateCreated() { - DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, - FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(1))); - } - - @Test - public void searchForConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); - DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED); - - SearchParameterMap theParams = new SearchParameterMap() - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(CONDITION_UUID)); - } - - @Test - public void searchForConditions_shouldReturnEmptyListByMismatchingUuidAndLastUpdated() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); - DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_VOIDED).setLowerBound(DATE_VOIDED); - - SearchParameterMap theParams = new SearchParameterMap() - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, empty()); - } - - @Test - public void searchForConditions_shouldAddNotNullPatientToReturnedResults() { - HashSet includes = new HashSet<>(); - Include include = new Include("Condition:patient"); - includes.add(include); - - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid); - - IBundleProvider results = search(theParams); - assertThat(results.size(), Matchers.equalTo(1)); - - List resultList = get(results); - - assertThat(results, Matchers.notNullValue()); - assertThat(resultList.size(), Matchers.equalTo(2)); // included resource added as part of the result list - - org.hl7.fhir.r4.model.Condition returnedCondition = (org.hl7.fhir.r4.model.Condition) resultList.iterator().next(); - assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), - hasProperty("id", Matchers.equalTo(returnedCondition.getSubject().getReferenceElement().getIdPart()))))); - } -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryImpl_2_2Test.java deleted file mode 100644 index 05e2f79835..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryImpl_2_2Test.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.search; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; - -import java.util.List; -import java.util.stream.Collectors; - -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.TokenAndListParam; -import ca.uhn.fhir.rest.param.TokenParam; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.DrugOrder; -import org.openmrs.api.OrderService; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class MedicationRequestSearchQueryImpl_2_2Test extends BaseModuleContextSensitiveTest { - - private static final String INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test_initial_data.xml"; - - private static final String DRUG_ORDER_WITH_FULFILLER_STATUS_COMPLETED_UUID = "ac463525-9b1a-44f2-99f1-0d6a10d5b60d"; - - @Autowired - private MedicationRequestTranslator translator; - - @Autowired - private FhirMedicationRequestDao dao; - - @Autowired - private SearchQueryInclude searchQueryInclude; - - @Autowired - private OrderService orderService; - - @Autowired - private SearchQuery> searchQuery; - - @Before - public void setup() throws Exception { - executeDataSet(INITIAL_DATA_XML); - } - - @Test - public void searchForMedicationRequests_shouldSearchForMedicationRequestsByFulfillerStatus() { - // there are no tests in the test data set with "received" fulfiller status - TokenAndListParam fulfillerStatus = new TokenAndListParam().addAnd(new TokenParam("received")); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, - "fulfillerStatus", fulfillerStatus); - IBundleProvider results = search(theParams); - - assertThat(results, notNullValue()); - List resultList = get(results); - assertThat(resultList, hasSize(equalTo(0))); - - // there is one tests in the test data set with "completed" fulfiller status - fulfillerStatus = new TokenAndListParam().addAnd(new TokenParam("completed")); - theParams = new SearchParameterMap().addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, "fulfillerStatus", - fulfillerStatus); - results = search(theParams); - - assertThat(results, notNullValue()); - resultList = get(results); - assertThat(resultList, hasSize(equalTo(1))); - assertThat(resultList.get(0).getId(), equalTo(DRUG_ORDER_WITH_FULFILLER_STATUS_COMPLETED_UUID)); - } - - private IBundleProvider search(SearchParameterMap theParams) { - return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); - } - - private List get(IBundleProvider results) { - return results.getAllResources().stream().filter(it -> it instanceof MedicationRequest) - .map(it -> (MedicationRequest) it).collect(Collectors.toList()); - } - -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2Test.java deleted file mode 100644 index 385c9d9395..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl_2_2Test.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * 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.impl; - -import static org.exparity.hamcrest.date.DateMatchers.sameDay; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.Date; - -import org.hamcrest.Matchers; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.Condition; -import org.hl7.fhir.r4.model.DateTimeType; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.StringType; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.CodedOrFreeText; -import org.openmrs.Concept; -import org.openmrs.ConditionClinicalStatus; -import org.openmrs.ConditionVerificationStatus; -import org.openmrs.Patient; -import org.openmrs.User; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.translators.ConceptTranslator; -import org.openmrs.module.fhir2.api.translators.ConditionClinicalStatusTranslator; -import org.openmrs.module.fhir2.api.translators.ConditionVerificationStatusTranslator; -import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; -import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; - -@RunWith(MockitoJUnitRunner.class) -public class ConditionTranslatorImpl_2_2Test { - - private static final String CONDITION_UUID = "36aa91ad-66f3-455b-b28a-71beb6ca3195"; - - private static final String PATIENT_UUID = "fc8b217b-2ed4-4dde-b9f7-a5334347e7ca"; - - private static final String PATIENT_REF = "Patient/" + PATIENT_UUID; - - private static final String ACTIVE = "active"; - - private static final String SYSTEM = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; - - private static final Integer CODE = 102309; - - private static final Integer CONDITION_NON_CODED = 5622; - - private static final String CONDITION_NON_CODED_TEXT = "condition non coded"; - - private static final String CONDITION_NON_CODED_VALUE = "Other"; - - private static final String CONCEPT_UUID = "31d754f5-3e9e-4ca3-805c-87f97a1f5e4b"; - - private static final String PRACTITIONER_UUID = "2ffb1a5f-bcd3-4243-8f40-78edc2642789"; - - private static final String PRACTITIONER_REFERENCE = FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID; - - @Mock - private PatientReferenceTranslator patientReferenceTranslator; - - private static final String CONFIRMED = "confirmed"; - - private static final String PROVISIONAL = "provisional"; - - @Mock - private ConditionClinicalStatusTranslator clinicalStatusTranslator; - - @Mock - private ConditionVerificationStatusTranslator verificationStatusTranslator; - - @Mock - private ConceptTranslator conceptTranslator; - - @Mock - private PractitionerReferenceTranslator creatorReferenceTranslator; - - private ConditionTranslatorImpl_2_2 conditionTranslator; - - private Condition fhirCondition; - - private org.openmrs.Condition openmrsCondition; - - private Patient patient; - - private Reference patientRef; - - @Before - public void setup() { - conditionTranslator = new ConditionTranslatorImpl_2_2(); - conditionTranslator.setPatientReferenceTranslator(patientReferenceTranslator); - conditionTranslator.setClinicalStatusTranslator(clinicalStatusTranslator); - conditionTranslator.setVerificationStatusTranslator(verificationStatusTranslator); - conditionTranslator.setConceptTranslator(conceptTranslator); - conditionTranslator.setPractitionerReferenceTranslator(creatorReferenceTranslator); - - patient = new Patient(); - patient.setUuid(PATIENT_UUID); - - patientRef = new Reference(); - patientRef.setReference(PATIENT_REF); - - Concept concept = new Concept(); - concept.setUuid(CONDITION_UUID); - concept.setConceptId(CODE); - - CodedOrFreeText conditionCoded = new CodedOrFreeText(); - conditionCoded.setCoded(concept); - - openmrsCondition = new org.openmrs.Condition(); - openmrsCondition.setUuid(CONDITION_UUID); - openmrsCondition.setPatient(patient); - openmrsCondition.setCondition(conditionCoded); - - fhirCondition = new Condition(); - fhirCondition.setId(CONDITION_UUID); - fhirCondition.setSubject(patientRef); - } - - @Test - public void shouldTranslateConditionIdToFhirType() { - Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getId(), equalTo(CONDITION_UUID)); - } - - @Test - public void shouldTranslateConditionUuidToOpenMrsType() { - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getUuid(), equalTo(CONDITION_UUID)); - } - - @Test(expected = NullPointerException.class) - public void toFhirResource_shouldThrowExceptionIfConditionToTranslateIsNull() { - conditionTranslator.toFhirResource(null); - } - - @Test - public void shouldTranslateConditionSubjectToOpenMrsType() { - when(patientReferenceTranslator.toOpenmrsType(patientRef)).thenReturn(patient); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getPatient(), notNullValue()); - assertThat(condition.getPatient().getUuid(), equalTo(PATIENT_UUID)); - } - - @Test - public void shouldTranslateConditionPatientToFhirType() { - when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientRef); - Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getSubject(), notNullValue()); - assertThat(condition.getSubject(), equalTo(patientRef)); - assertThat(condition.getSubject().getReference(), equalTo(PATIENT_REF)); - } - - @Test - public void shouldTranslateConditionClinicalStatusToOpenMrsType() { - CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.addCoding(new Coding().setCode(ACTIVE).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); - fhirCondition.setClinicalStatus(codeableConcept); - when(clinicalStatusTranslator.toOpenmrsType(codeableConcept)).thenReturn(ConditionClinicalStatus.ACTIVE); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - - assertThat(condition, notNullValue()); - assertThat(condition.getClinicalStatus(), notNullValue()); - assertThat(condition.getClinicalStatus(), equalTo(ConditionClinicalStatus.ACTIVE)); - - } - - @Test - public void shouldTranslateConditionClinicalStatusToFhirType() { - CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.addCoding(new Coding().setCode(ACTIVE).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); - openmrsCondition.setClinicalStatus(ConditionClinicalStatus.ACTIVE); - when(clinicalStatusTranslator.toFhirResource(ConditionClinicalStatus.ACTIVE)).thenReturn(codeableConcept); - - Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getClinicalStatus(), notNullValue()); - assertThat(condition.getClinicalStatus(), equalTo(codeableConcept)); - } - - @Test - public void shouldTranslateConditionVerificationStatusToFhirType() { - CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.addCoding(new Coding().setCode(CONFIRMED).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); - openmrsCondition.setVerificationStatus(ConditionVerificationStatus.CONFIRMED); - when(verificationStatusTranslator.toFhirResource(ConditionVerificationStatus.CONFIRMED)).thenReturn(codeableConcept); - Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getVerificationStatus(), equalTo(codeableConcept)); - assertThat(condition.getVerificationStatus().getCodingFirstRep().getCode().toLowerCase(), equalTo(CONFIRMED)); - } - - @Test - public void shouldTranslateConditionVerificationStatusToOpenMrsType() { - CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.addCoding(new Coding().setCode(PROVISIONAL).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); - fhirCondition.setVerificationStatus(codeableConcept); - when(verificationStatusTranslator.toOpenmrsType(codeableConcept)) - .thenReturn(ConditionVerificationStatus.PROVISIONAL); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getVerificationStatus(), equalTo(ConditionVerificationStatus.PROVISIONAL)); - } - - @Test - public void shouldTranslateOpenMrsConditionOnsetDateToFhirType() { - openmrsCondition.setOnsetDate(new Date()); - - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - - assertThat(condition, notNullValue()); - assertThat(condition.hasOnsetDateTimeType(), is(true)); - assertThat(condition.getOnsetDateTimeType().getValue(), sameDay(new Date())); - } - - @Test - public void shouldTranslateFhirConditionOnsetToOpenMrsOnsetDate() { - DateTimeType theDateTime = new DateTimeType(); - theDateTime.setValue(new Date()); - fhirCondition.setOnset(theDateTime); - - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - - assertThat(condition, notNullValue()); - assertThat(condition.getOnsetDate(), notNullValue()); - assertThat(condition.getOnsetDate(), sameDay(new Date())); - } - - @Test - public void shouldTranslateOpenMrsConditionEndDateToFhirType() { - openmrsCondition.setEndDate(new Date()); - - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - - assertThat(condition, notNullValue()); - assertThat(condition.hasAbatementDateTimeType(), is(true)); - assertThat(condition.getAbatementDateTimeType().getValue(), notNullValue()); - assertThat(condition.getAbatementDateTimeType().getValue(), sameDay(new Date())); - } - - @Test - public void shouldTranslateFhirConditionAbatementDateToOpenMrsEndDate() { - DateTimeType theDateTime = new DateTimeType(); - theDateTime.setValue(new Date()); - fhirCondition.setAbatement(theDateTime); - - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - - assertThat(condition, notNullValue()); - assertThat(condition.getEndDate(), notNullValue()); - assertThat(condition.getEndDate(), sameDay(new Date())); - } - - @Test - public void shouldTranslateConditionCodeToOpenMrsConcept() { - CodeableConcept codeableConcept = new CodeableConcept(); - Coding coding = new Coding(); - coding.setCode(CODE.toString()); - coding.setSystem(SYSTEM); - codeableConcept.addCoding(coding); - fhirCondition.setCode(codeableConcept); - Concept concept = new Concept(); - concept.setUuid(CONCEPT_UUID); - concept.setConceptId(CODE); - when(conceptTranslator.toOpenmrsType(codeableConcept)).thenReturn(concept); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getCondition(), notNullValue()); - assertThat(condition.getCondition().getCoded().getConceptId(), equalTo(CODE)); - } - - @Test - public void shouldTranslateConditionConceptToFhirType() { - Concept concept = new Concept(); - concept.setUuid(CONCEPT_UUID); - concept.setConceptId(CODE); - CodeableConcept codeableConcept = new CodeableConcept(); - Coding coding = new Coding(); - coding.setCode(CODE.toString()); - coding.setSystem(SYSTEM); - codeableConcept.addCoding(coding); - CodedOrFreeText conceptCodeOrFreeText = new CodedOrFreeText(); - conceptCodeOrFreeText.setCoded(concept); - openmrsCondition.setCondition(conceptCodeOrFreeText); - when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept); - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getCode(), notNullValue()); - assertThat(condition.getCode().getCoding(), not(Collections.emptyList())); - assertThat(condition.getCode().getCoding().get(0).getCode(), equalTo(CODE.toString())); - assertThat(condition.getCode().getCoding().get(0).getSystem(), equalTo(SYSTEM)); - } - - @Test - public void shouldTranslateConditionNonCodedToOpenMrsType() { - CodeableConcept codeableConcept = new CodeableConcept(); - Coding coding = new Coding(); - coding.setCode(String.valueOf(CONDITION_NON_CODED)); - coding.setDisplay(CONDITION_NON_CODED_VALUE); - codeableConcept.addCoding(coding); - Concept concept = new Concept(); - concept.setConceptId(CONDITION_NON_CODED); - fhirCondition.setCode(codeableConcept); - fhirCondition.addExtension(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION, - new StringType(CONDITION_NON_CODED_TEXT)); - when(conceptTranslator.toOpenmrsType(codeableConcept)).thenReturn(concept); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getCondition().getCoded(), equalTo(concept)); - assertThat(condition.getCondition().getNonCoded(), notNullValue()); - assertThat(condition.getCondition().getNonCoded(), equalTo(CONDITION_NON_CODED_TEXT)); - } - - @Test - public void shouldTranslateConditionNonCodedToFhirType() { - CodeableConcept codeableConcept = new CodeableConcept(); - Coding coding = new Coding(); - coding.setCode(String.valueOf(CONDITION_NON_CODED)); - coding.setDisplay(CONDITION_NON_CODED_VALUE); - codeableConcept.addCoding(coding); - - Concept concept = new Concept(); - concept.setConceptId(CONDITION_NON_CODED); - CodedOrFreeText conditionNonCoded = new CodedOrFreeText(); - conditionNonCoded.setCoded(concept); - conditionNonCoded.setNonCoded(CONDITION_NON_CODED_TEXT); - openmrsCondition.setCondition(conditionNonCoded); - - when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept); - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getCode(), notNullValue()); - assertThat(condition.getCode().getCoding(), not(Collections.emptyList())); - assertThat(condition.getCode().getCoding().get(0).getCode(), equalTo(CONDITION_NON_CODED.toString())); - assertThat(condition.getCode().getCoding().get(0).getDisplay(), equalTo(CONDITION_NON_CODED_VALUE)); - - Extension extension = condition.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION); - assertThat(extension, notNullValue()); - assertThat(extension.getValue().toString(), equalTo(CONDITION_NON_CODED_TEXT)); - } - - @Test - public void shouldTranslateConditionDateCreatedToRecordedDateFhirType() { - openmrsCondition.setDateCreated(new Date()); - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getRecordedDate(), notNullValue()); - assertThat(condition.getRecordedDate(), sameDay(new Date())); - } - - @Test - public void shouldTranslateConditionRecorderToOpenmrsUser() { - Reference userRef = new Reference(); - userRef.setReference(FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID); - fhirCondition.setRecorder(userRef); - User user = new User(); - user.setUuid(PRACTITIONER_UUID); - when(creatorReferenceTranslator.toOpenmrsType(userRef)).thenReturn(user); - org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getCreator(), notNullValue()); - assertThat(condition.getCreator().getUuid(), equalTo(PRACTITIONER_UUID)); - } - - @Test - public void shouldTranslateConditionCreatorToRecorderFhirType() { - User user = new User(); - user.setUuid(PRACTITIONER_UUID); - Reference userRef = new Reference(); - userRef.setReference(PRACTITIONER_REFERENCE); - openmrsCondition.setCreator(user); - when(creatorReferenceTranslator.toFhirResource(user)).thenReturn(userRef); - org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); - assertThat(condition, notNullValue()); - assertThat(condition.getRecorder(), notNullValue()); - assertThat(condition.getRecorder().getReference(), equalTo(PRACTITIONER_REFERENCE)); - } - - @Test - public void shouldTranslateOpenMrsDateChangedToLastUpdatedDate() { - org.openmrs.Condition condition = new org.openmrs.Condition(); - condition.setDateChanged(new Date()); - - org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(condition); - - assertThat(result, Matchers.notNullValue()); - assertThat(result.getMeta().getLastUpdated(), Matchers.notNullValue()); - } - - @Test - public void shouldTranslateOpenMrsDateChangedToVersionId() { - org.openmrs.Condition condition = new org.openmrs.Condition(); - condition.setDateChanged(new Date()); - - org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(condition); - - assertThat(result, Matchers.notNullValue()); - assertThat(result.getMeta().getVersionId(), Matchers.notNullValue()); - } -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2Test.java deleted file mode 100644 index e179c98f82..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl_2_2Test.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; - -import java.lang.reflect.Field; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.hl7.fhir.r4.model.MedicationRequest; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.DrugOrder; -import org.openmrs.Order; - -public class MedicationRequestStatusTranslatorImpl_2_2Test { - - private static final String DRUG_ORDER_UUID = "44fdc8ad-fe4d-499b-93a8-8a991c1d477e"; - - private MedicationRequestStatusTranslatorImpl_2_2 statusTranslator; - - private DrugOrder drugOrder; - - @Before - public void setup() { - statusTranslator = new MedicationRequestStatusTranslatorImpl_2_2(); - - drugOrder = new DrugOrder(); - drugOrder.setUuid(DRUG_ORDER_UUID); - drugOrder.setDateActivated(new Date()); - } - - @Test - public void toFhirResource_shouldTranslateToActiveStatus() { - MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); - assertThat(status, notNullValue()); - assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.ACTIVE)); - } - - @Test - public void toFhirResource_shouldTranslateExpiredOrderToStoppedStatus() throws ParseException { - drugOrder.setAutoExpireDate(new SimpleDateFormat("YYYY-MM-DD").parse("2000-10-10")); - - MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); - assertThat(status, notNullValue()); - assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.STOPPED)); - } - - @Test - public void toFhirResource_shouldTranslateDiscontinueOrderToCancelledStatus() - throws NoSuchFieldException, ParseException, IllegalAccessException { - Field dateStopped = Order.class.getDeclaredField("dateStopped"); - dateStopped.setAccessible(true); - dateStopped.set(drugOrder, new SimpleDateFormat("YYYY-MM-DD").parse("2000-10-10")); - - MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); - assertThat(status, notNullValue()); - assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.CANCELLED)); - } - - @Test - public void toFhirResource_shouldTranslateVoidedOrderToCancelled() { - drugOrder.setVoided(true); - MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); - assertThat(status, notNullValue()); - assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.CANCELLED)); - } - - @Test - public void toFhirResource_shouldTranslatedOrderWithFulfillerStatusCompletedToCompleted() { - drugOrder.setFulfillerStatus(Order.FulfillerStatus.COMPLETED); - MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); - assertThat(status, notNullValue()); - assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.COMPLETED)); - } - -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2Test.java b/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2Test.java deleted file mode 100644 index dce87af8d9..0000000000 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl_2_2Test.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; - -import org.hl7.fhir.r4.model.CodeType; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.DrugOrder; -import org.openmrs.Encounter; -import org.openmrs.Order; -import org.openmrs.Provider; -import org.openmrs.module.fhir2.api.translators.ConceptTranslator; -import org.openmrs.module.fhir2.api.translators.DosageTranslator; -import org.openmrs.module.fhir2.api.translators.EncounterReferenceTranslator; -import org.openmrs.module.fhir2.api.translators.MedicationReferenceTranslator; -import org.openmrs.module.fhir2.api.translators.MedicationRequestDispenseRequestComponentTranslator; -import org.openmrs.module.fhir2.api.translators.MedicationRequestPriorityTranslator; -import org.openmrs.module.fhir2.api.translators.MedicationRequestStatusTranslator; -import org.openmrs.module.fhir2.api.translators.OrderIdentifierTranslator; -import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; -import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; - -@RunWith(MockitoJUnitRunner.class) -public class MedicationRequestTranslatorImpl_2_2Test { - - private MedicationRequestTranslatorImpl_2_2 medicationRequestTranslator; - - @Mock - private MedicationRequestStatusTranslator medicationRequestStatusTranslator; - - @Mock - private PractitionerReferenceTranslator practitionerReferenceTranslator; - - @Mock - private MedicationRequestPriorityTranslator medicationRequestPriorityTranslator; - - @Mock - private MedicationReferenceTranslator medicationReferenceTranslator; - - @Mock - private EncounterReferenceTranslator encounterReferenceTranslator; - - @Mock - private PatientReferenceTranslator patientReferenceTranslator; - - @Mock - private ConceptTranslator conceptTranslator; - - @Mock - private DosageTranslator dosageTranslator; - - @Mock - private OrderIdentifierTranslator orderIdentifierTranslator; - - @Mock - private MedicationRequestDispenseRequestComponentTranslator medicationRequestDispenseRequestComponentTranslator; - - @Before - public void setup() { - medicationRequestTranslator = new MedicationRequestTranslatorImpl_2_2(); - medicationRequestTranslator.setStatusTranslator(medicationRequestStatusTranslator); - medicationRequestTranslator.setPractitionerReferenceTranslator(practitionerReferenceTranslator); - medicationRequestTranslator.setMedicationRequestPriorityTranslator(medicationRequestPriorityTranslator); - medicationRequestTranslator.setMedicationReferenceTranslator(medicationReferenceTranslator); - medicationRequestTranslator.setEncounterReferenceTranslator(encounterReferenceTranslator); - medicationRequestTranslator.setPatientReferenceTranslator(patientReferenceTranslator); - medicationRequestTranslator.setConceptTranslator(conceptTranslator); - medicationRequestTranslator.setDosageTranslator(dosageTranslator); - medicationRequestTranslator.setOrderIdentifierTranslator(orderIdentifierTranslator); - medicationRequestTranslator - .setMedicationRequestDispenseRequestComponentTranslator(medicationRequestDispenseRequestComponentTranslator); - - } - - @Test - public void toFhirResource_shouldTranslateToFulfillerStatusExtenstion() { - DrugOrder drugOrder = new DrugOrder(); - drugOrder.setFulfillerStatus(Order.FulfillerStatus.COMPLETED); - MedicationRequest medicationRequest = medicationRequestTranslator.toFhirResource(drugOrder); - assertThat(medicationRequest, notNullValue()); - assertThat( - medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), - equalTo("COMPLETED")); - } - - @Test - public void toOpenmrsType_shouldTranslateFulfillerStatusExtension() { - MedicationRequest medicationRequest = new MedicationRequest(); - - Extension extension = new Extension(); - extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); - extension.setValue(new CodeType("COMPLETED")); - - medicationRequest.addExtension(extension); - - DrugOrder drugOrder = medicationRequestTranslator.toOpenmrsType(medicationRequest); - assertThat(drugOrder, notNullValue()); - assertThat(drugOrder.getFulfillerStatus(), equalTo(Order.FulfillerStatus.COMPLETED)); - - } - - @Test - public void toOpenmrsType_shouldTranslateNullFulfillerStatusExtension() { - MedicationRequest medicationRequest = new MedicationRequest(); - - Extension extension = new Extension(); - extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); - extension.setValue(new CodeType(null)); - - medicationRequest.addExtension(extension); - - DrugOrder drugOrder = medicationRequestTranslator.toOpenmrsType(medicationRequest); - assertThat(drugOrder, notNullValue()); - assertThat(drugOrder.getFulfillerStatus(), equalTo(null)); - - } -} diff --git a/api-2.5/pom.xml b/api-2.5/pom.xml index 83eae9d052..7fd2dcd756 100644 --- a/api-2.5/pom.xml +++ b/api-2.5/pom.xml @@ -1,84 +1,72 @@ - - - - fhir2 - org.openmrs.module - 1.12.0-SNAPSHOT - - 4.0.0 - - fhir2-api-2.5 - jar - FHIR2 API 2.5 - API 2.5 for FHIR2 - - - - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.parent.version} - provided - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.1 - ${project.parent.version} - provided - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.2 - ${project.parent.version} - provided - - - org.openmrs.api - openmrs-api - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - org.projectlombok - lombok - - - com.google.guava - guava - test - - - - - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - - - - 2.5.0 - - - + + + + fhir2 + org.openmrs.module + 2.0.0-SNAPSHOT + + 4.0.0 + + fhir2-api-2.5 + jar + FHIR2 API 2.5 + API 2.5 for FHIR2 + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + provided + + + org.openmrs.api + openmrs-api + + + ${project.parent.groupId} + ${project.parent.artifactId}-test-data + ${project.parent.version} + test + + + org.projectlombok + lombok + + + com.google.guava + guava + test + + + + + + + org.jacoco + jacoco-maven-plugin + + + org.commonjava.maven.plugins + directory-maven-plugin + + + com.mycila + license-maven-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + net.revelc.code + impsort-maven-plugin + + + + + + 2.5.0 + + + diff --git a/api-2.6/pom.xml b/api-2.6/pom.xml index 7cd9657475..84aec3c52f 100644 --- a/api-2.6/pom.xml +++ b/api-2.6/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 @@ -19,18 +19,6 @@ ${project.parent.version} provided - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.1 - ${project.parent.version} - provided - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.2 - ${project.parent.version} - provided - ${project.parent.groupId} ${project.parent.artifactId}-api-2.5 diff --git a/api-2.6/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl_2_6Test.java b/api-2.6/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl_2_6Test.java index 605e58daf1..cc9a8f1073 100644 --- a/api-2.6/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl_2_6Test.java +++ b/api-2.6/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl_2_6Test.java @@ -16,7 +16,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/pom.xml b/api/pom.xml index 21d3e162fa..e1958cd6a3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module fhir2 - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT fhir2-api diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl.java index 26384df9d0..75219a7dd6 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl.java @@ -23,65 +23,70 @@ import lombok.AccessLevel; import lombok.Setter; import org.hibernate.Criteria; -import org.hibernate.SessionFactory; import org.hibernate.criterion.Criterion; -import org.openmrs.Obs; +import org.openmrs.Condition; +import org.openmrs.ConditionClinicalStatus; import org.openmrs.annotation.Authorized; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.dao.FhirConditionDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.util.PrivilegeConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @Component -@Setter(AccessLevel.PUBLIC) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") -public class FhirConditionDaoImpl extends BaseFhirDao implements FhirConditionDao { - - @Qualifier("sessionFactory") - @Autowired - private SessionFactory sessionFactory; +@Setter(AccessLevel.PROTECTED) +public class FhirConditionDaoImpl extends BaseFhirDao implements FhirConditionDao { @Override - @Authorized(PrivilegeConstants.GET_OBS) - public Obs get(@Nonnull String uuid) { + @Authorized(PrivilegeConstants.GET_CONDITIONS) + public Condition get(@Nonnull String uuid) { return super.get(uuid); } @Override - @Authorized(PrivilegeConstants.EDIT_OBS) - public Obs createOrUpdate(@Nonnull Obs newEntry) { + @Authorized(PrivilegeConstants.EDIT_CONDITIONS) + public Condition createOrUpdate(@Nonnull Condition newEntry) { return super.createOrUpdate(newEntry); } @Override - @Authorized(PrivilegeConstants.DELETE_OBS) - public Obs delete(@Nonnull String uuid) { + @Authorized(PrivilegeConstants.DELETE_CONDITIONS) + public Condition delete(@Nonnull String uuid) { return super.delete(uuid); } @Override - @Authorized(PrivilegeConstants.GET_OBS) - public List getSearchResults(@Nonnull SearchParameterMap theParams) { + @Authorized(PrivilegeConstants.GET_CONDITIONS) + public List getSearchResults(@Nonnull SearchParameterMap theParams) { return super.getSearchResults(theParams); } + private ConditionClinicalStatus convertStatus(String status) { + if ("active".equalsIgnoreCase(status)) { + return ConditionClinicalStatus.ACTIVE; + } + return ConditionClinicalStatus.INACTIVE; + } + + @Override + public boolean hasDistinctResults() { + return false; + } + @Override protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { - criteria.createAlias("concept", "c"); - criteria.add(eq("c.uuid", FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)); theParams.getParameters().forEach(entry -> { switch (entry.getKey()) { case FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER: - entry.getValue().forEach( - param -> handlePatientReference(criteria, (ReferenceAndListParam) param.getParam(), "person")); + entry.getValue() + .forEach(param -> handlePatientReference(criteria, (ReferenceAndListParam) param.getParam())); break; case FhirConstants.CODED_SEARCH_HANDLER: entry.getValue().forEach(param -> handleCode(criteria, (TokenAndListParam) param.getParam())); break; + case FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER: + entry.getValue().forEach(param -> handleClinicalStatus(criteria, (TokenAndListParam) param.getParam())); + break; case FhirConstants.DATE_RANGE_SEARCH_HANDLER: entry.getValue() .forEach(param -> handleDateRange(param.getPropertyName(), (DateRangeParam) param.getParam()) @@ -99,13 +104,18 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams private void handleCode(Criteria criteria, TokenAndListParam code) { if (code != null) { - criteria.createAlias("valueCoded", "vc"); - handleCodeableConcept(criteria, code, "vc", "map", "term").ifPresent(criteria::add); + criteria.createAlias("condition.coded", "cd"); + handleCodeableConcept(criteria, code, "cd", "map", "term").ifPresent(criteria::add); } } + private void handleClinicalStatus(Criteria criteria, TokenAndListParam status) { + handleAndListParam(status, tokenParam -> Optional.of(eq("clinicalStatus", convertStatus(tokenParam.getValue())))) + .ifPresent(criteria::add); + } + private void handleOnsetAge(Criteria criteria, QuantityAndListParam onsetAge) { - handleAndListParam(onsetAge, onsetAgeParam -> handleAgeByDateProperty("obsDatetime", onsetAgeParam)) + handleAndListParam(onsetAge, onsetAgeParam -> handleAgeByDateProperty("onsetDate", onsetAgeParam)) .ifPresent(criteria::add); } @@ -118,7 +128,7 @@ protected Optional handleLastUpdated(DateRangeParam param) { protected String paramToProp(@Nonnull String param) { switch (param) { case org.hl7.fhir.r4.model.Condition.SP_ONSET_DATE: - return "obsDatetime"; + return "onsetDate"; case org.hl7.fhir.r4.model.Condition.SP_RECORDED_DATE: return "dateCreated"; } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl.java index 906fce204f..fc65ca0322 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl.java @@ -26,10 +26,13 @@ import ca.uhn.fhir.rest.param.TokenAndListParam; import lombok.AccessLevel; import lombok.Setter; +import org.apache.commons.lang3.StringUtils; import org.hibernate.Criteria; +import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Projections; +import org.hibernate.criterion.Restrictions; import org.openmrs.Encounter; -import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.Order; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.dao.FhirEncounterDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; @@ -38,7 +41,6 @@ @Component @Setter(AccessLevel.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") public class FhirEncounterDaoImpl extends BaseEncounterDao implements FhirEncounterDao { @Override @@ -108,4 +110,36 @@ protected String paramToProp(@Nonnull String param) { return null; } } + + @Override + protected Criterion generateNotCompletedOrderQuery(String path) { + if (StringUtils.isNotBlank(path)) { + path = path + "."; + } + + return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"), + Restrictions.ne(path + "fulfillerStatus", org.openmrs.Order.FulfillerStatus.COMPLETED)); + + } + + @Override + protected Criterion generateFulfillerStatusRestriction(String path, String fulfillerStatus) { + + if (StringUtils.isNotBlank(path)) { + path = path + "."; + } + + return Restrictions.eq(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase())); + } + + @Override + protected Criterion generateNotFulfillerStatusRestriction(String path, String fulfillerStatus) { + + if (StringUtils.isNotBlank(path)) { + path = path + "."; + } + + return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"), + Restrictions.ne(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase()))); + } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl.java index 7dce8df01a..162754e768 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl.java @@ -9,6 +9,8 @@ */ package org.openmrs.module.fhir2.api.dao.impl; +import static org.hibernate.criterion.Restrictions.ne; + import javax.annotation.Nonnull; import java.util.Collection; @@ -20,13 +22,13 @@ import ca.uhn.fhir.rest.param.TokenAndListParam; import lombok.AccessLevel; import lombok.Setter; +import org.apache.commons.lang3.StringUtils; import org.hibernate.Criteria; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; import org.hl7.fhir.r4.model.MedicationRequest; import org.openmrs.DrugOrder; import org.openmrs.Order; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; @@ -35,7 +37,6 @@ @Component @Setter(AccessLevel.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") public class FhirMedicationRequestDaoImpl extends BaseFhirDao implements FhirMedicationRequestDao { @Override @@ -60,23 +61,14 @@ public List get(@Nonnull Collection uuids) { } } - @Override - public List getSearchResults(@Nonnull SearchParameterMap theParams) { - List results = super.getSearchResults(theParams); - if (results == null) { - return results; - } else { - return results.stream() - .filter(order -> order.getAction() == null || order.getAction() != Order.Action.DISCONTINUE) - .collect(Collectors.toList()); - } - - } - @Override protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) { theParams.getParameters().forEach(entry -> { switch (entry.getKey()) { + case FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER: + entry.getValue().forEach( + param -> handleFulfillerStatus((TokenAndListParam) param.getParam()).ifPresent(criteria::add)); + break; case FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER: entry.getValue() .forEach(e -> handleEncounterReference(criteria, (ReferenceAndListParam) e.getParam(), "e")); @@ -104,6 +96,7 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams break; } }); + excludeDiscontinueOrders(criteria); } @@ -125,6 +118,28 @@ private Optional handleStatus(TokenAndListParam tokenAndListParam) { }); } + private Optional handleFulfillerStatus(TokenAndListParam tokenAndListParam) { + return handleAndListParam(tokenAndListParam, token -> { + if (token.getValue() != null) { + return Optional.of( + generateFulfillerStatusRestriction(Order.FulfillerStatus.valueOf(token.getValue().toUpperCase()))); + } + return Optional.empty(); + }); + } + + protected Criterion generateFulfillerStatusRestriction(Order.FulfillerStatus fulfillerStatus) { + return generateFulfillerStatusRestriction("", fulfillerStatus); + } + + protected Criterion generateFulfillerStatusRestriction(String path, Order.FulfillerStatus fulfillerStatus) { + if (StringUtils.isNotBlank(path)) { + path = path + "."; + } + + return Restrictions.eq(path + "fulfillerStatus", fulfillerStatus); + } + private void handleCodedConcept(Criteria criteria, TokenAndListParam code) { if (code != null) { if (lacksAlias(criteria, "c")) { @@ -137,6 +152,6 @@ private void handleCodedConcept(Criteria criteria, TokenAndListParam code) { private void excludeDiscontinueOrders(Criteria criteria) { // exclude "discontinue" orders, see: https://issues.openmrs.org/browse/FM2-532 - criteria.add(Restrictions.ne("action", Order.Action.DISCONTINUE)); + criteria.add(ne("action", Order.Action.DISCONTINUE)); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl.java index 62437c8987..b767946356 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImpl.java @@ -9,16 +9,11 @@ */ package org.openmrs.module.fhir2.api.impl; -import javax.transaction.Transactional; - import ca.uhn.fhir.rest.api.server.IBundleProvider; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import org.hl7.fhir.r4.model.Condition; -import org.openmrs.Obs; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirConditionService; import org.openmrs.module.fhir2.api.dao.FhirConditionDao; import org.openmrs.module.fhir2.api.search.SearchQuery; @@ -27,31 +22,28 @@ import org.openmrs.module.fhir2.api.translators.ConditionTranslator; 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.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") -public class FhirConditionServiceImpl extends BaseFhirService implements FhirConditionService { +@Getter(AccessLevel.PROTECTED) +public class FhirConditionServiceImpl extends BaseFhirService implements FhirConditionService { @Autowired - private FhirConditionDao dao; + private FhirConditionDao dao; @Autowired - private ConditionTranslator translator; + private ConditionTranslator translator; @Autowired - private SearchQueryInclude searchQueryInclude; + private SearchQueryInclude searchQueryInclude; @Autowired - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; + private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; @Override public IBundleProvider searchConditions(ConditionSearchParams conditionSearchParams) { - conditionSearchParams.toSearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "obsDatetime", - conditionSearchParams.getOnsetDate()); - return searchQuery.getQueryResults(conditionSearchParams.toSearchParameterMap(), dao, translator, searchQueryInclude); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberServiceImpl.java index 0b14499c19..be12d58a93 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupMemberServiceImpl.java @@ -12,14 +12,12 @@ import javax.annotation.Nonnull; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.api.FhirGroupMemberService; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @Component @Transactional -@OpenmrsProfile(openmrsPlatformVersion = "2.0.0 - 2.0.*") public class FhirGroupMemberServiceImpl implements FhirGroupMemberService { @Override diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImpl.java index da99051dec..6fc29814cc 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImpl.java @@ -16,7 +16,6 @@ import lombok.Setter; import org.hl7.fhir.r4.model.Group; import org.openmrs.Cohort; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirGroupService; import org.openmrs.module.fhir2.api.dao.FhirGroupDao; @@ -32,7 +31,6 @@ @Transactional @Setter(AccessLevel.PACKAGE) @Getter(AccessLevel.PROTECTED) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.0 - 2.*") public class FhirGroupServiceImpl extends BaseFhirService implements FhirGroupService { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl.java index b94d8328e6..2cc28d86f3 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImpl.java @@ -33,7 +33,7 @@ @Transactional @Setter(AccessLevel.PACKAGE) @Getter(AccessLevel.PROTECTED) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.5.*") +@OpenmrsProfile(openmrsPlatformVersion = "2.* - 2.5.*") public class FhirMedicationDispenseServiceImpl implements FhirMedicationDispenseService { @Override diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java index fefb9686a8..cbd9d9b34c 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java @@ -287,15 +287,14 @@ private IBundleProvider handleEncounterReverseInclude(ReferenceAndListParam para HashSet recursiveIncludes, HashSet recursiveRevIncludes) { switch (targetType) { case FhirConstants.OBSERVATION: - ObservationSearchParams observationSearchParams = new ObservationSearchParams(); - observationSearchParams.setEncounter(params); - return observationService.searchForObservations(observationSearchParams); + return observationService + .searchForObservations(ObservationSearchParams.builder().encounterReference(params).build()); case FhirConstants.DIAGNOSTIC_REPORT: return diagnosticReportService.searchForDiagnosticReports( - new DiagnosticReportSearchParams(params, null, null, null, null, null, null, null, null)); + DiagnosticReportSearchParams.builder().encounterReference(params).build()); case FhirConstants.MEDICATION_REQUEST: - return medicationRequestService.searchForMedicationRequests(new MedicationRequestSearchParams(null, params, - null, null, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes)); + return medicationRequestService.searchForMedicationRequests(MedicationRequestSearchParams.builder() + .encounterReference(params).includes(recursiveIncludes).revIncludes(recursiveRevIncludes).build()); case FhirConstants.PROCEDURE_REQUEST: case FhirConstants.SERVICE_REQUEST: return serviceRequestService.searchForServiceRequests(null, null, params, null, null, null, null, null); diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ConditionSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ConditionSearchParams.java index db4cb428fa..3b8f1bc90c 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ConditionSearchParams.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ConditionSearchParams.java @@ -61,6 +61,7 @@ public SearchParameterMap toSearchParameterMap() { return baseSearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, getPatientParam()) .addParameter(FhirConstants.CODED_SEARCH_HANDLER, getCode()) .addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, getClinicalStatus()) + .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", getOnsetDate()) .addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, getOnsetAge()) .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", getRecordedDate()); } diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl.java similarity index 90% rename from api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2.java rename to api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl.java index 03ca73ce44..f05a0aad25 100644 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl.java @@ -14,14 +14,12 @@ import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.openmrs.ConditionClinicalStatus; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.translators.ConditionClinicalStatusTranslator; import org.springframework.stereotype.Component; @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class ConditionClinicalStatusTranslatorImpl_2_2 implements ConditionClinicalStatusTranslator { +public class ConditionClinicalStatusTranslatorImpl implements ConditionClinicalStatusTranslator { @Override public CodeableConcept toFhirResource(@Nonnull ConditionClinicalStatus clinicalStatus) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl.java index f99585aff3..0faf0ce8d1 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImpl.java @@ -15,25 +15,24 @@ import javax.annotation.Nonnull; -import java.util.Date; +import java.util.Optional; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import lombok.AccessLevel; import lombok.Setter; -import org.hibernate.proxy.HibernateProxy; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.DateTimeType; -import org.openmrs.Concept; -import org.openmrs.Obs; -import org.openmrs.Patient; -import org.openmrs.Person; +import org.hl7.fhir.r4.model.Extension; +import org.hl7.fhir.r4.model.StringType; +import org.openmrs.CodedOrFreeText; +import org.openmrs.Condition; +import org.openmrs.ConditionClinicalStatus; +import org.openmrs.ConditionVerificationStatus; import org.openmrs.User; -import org.openmrs.annotation.OpenmrsProfile; -import org.openmrs.api.ConceptService; -import org.openmrs.api.db.hibernate.HibernateUtil; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.translators.ConceptTranslator; +import org.openmrs.module.fhir2.api.translators.ConditionClinicalStatusTranslator; import org.openmrs.module.fhir2.api.translators.ConditionTranslator; +import org.openmrs.module.fhir2.api.translators.ConditionVerificationStatusTranslator; import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; import org.springframework.beans.factory.annotation.Autowired; @@ -41,87 +40,101 @@ @Setter(AccessLevel.PACKAGE) @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") -public class ConditionTranslatorImpl implements ConditionTranslator { +public class ConditionTranslatorImpl implements ConditionTranslator { @Autowired private PatientReferenceTranslator patientReferenceTranslator; @Autowired - private PractitionerReferenceTranslator practitionerReferenceTranslator; + private ConditionClinicalStatusTranslator clinicalStatusTranslator; @Autowired - private ConceptTranslator conceptTranslator; + private ConditionVerificationStatusTranslator verificationStatusTranslator; + + @Autowired + private PractitionerReferenceTranslator practitionerReferenceTranslator; @Autowired - private ConceptService conceptService; + private ConceptTranslator conceptTranslator; @Override - public org.hl7.fhir.r4.model.Condition toFhirResource(@Nonnull Obs obsCondition) { - notNull(obsCondition, "The Openmrs Condition object should not be null"); + public org.hl7.fhir.r4.model.Condition toFhirResource(@Nonnull Condition condition) { + notNull(condition, "The Openmrs Condition object should not be null"); org.hl7.fhir.r4.model.Condition fhirCondition = new org.hl7.fhir.r4.model.Condition(); - fhirCondition.setId(obsCondition.getUuid()); + fhirCondition.setId(condition.getUuid()); + fhirCondition.setSubject(patientReferenceTranslator.toFhirResource(condition.getPatient())); + fhirCondition.setClinicalStatus(clinicalStatusTranslator.toFhirResource(condition.getClinicalStatus())); + fhirCondition.setVerificationStatus(verificationStatusTranslator.toFhirResource(condition.getVerificationStatus())); - Person obsPerson = obsCondition.getPerson(); - if (obsPerson != null) { - if (obsPerson instanceof HibernateProxy) { - obsPerson = HibernateUtil.getRealObjectFromProxy(obsPerson); - } - - if (obsPerson instanceof Patient) { - fhirCondition.setSubject(patientReferenceTranslator.toFhirResource((Patient) obsPerson)); + CodedOrFreeText codedOrFreeTextCondition = condition.getCondition(); + if (codedOrFreeTextCondition != null) { + fhirCondition.setCode(conceptTranslator.toFhirResource(codedOrFreeTextCondition.getCoded())); + if (codedOrFreeTextCondition.getNonCoded() != null) { + Extension extension = new Extension(); + extension.setUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION); + extension.setValue(new StringType(codedOrFreeTextCondition.getNonCoded())); + fhirCondition.addExtension(extension); } } - if (obsCondition.getValueCoded() != null) { - fhirCondition.setCode(conceptTranslator.toFhirResource(obsCondition.getValueCoded())); + fhirCondition.setOnset(new DateTimeType().setValue(condition.getOnsetDate())); + if (condition.getEndDate() != null) { + fhirCondition.setAbatement(new DateTimeType().setValue(condition.getEndDate())); } - fhirCondition.setOnset(new DateTimeType().setValue(obsCondition.getObsDatetime())); - fhirCondition.setRecorder(practitionerReferenceTranslator.toFhirResource(obsCondition.getCreator())); - fhirCondition.setRecordedDate(obsCondition.getDateCreated()); + fhirCondition.setRecorder(practitionerReferenceTranslator.toFhirResource(condition.getCreator())); + fhirCondition.setRecordedDate(condition.getDateCreated()); - fhirCondition.getMeta().setLastUpdated(getLastUpdated(obsCondition)); - fhirCondition.getMeta().setVersionId(getVersionId(obsCondition)); + fhirCondition.getMeta().setLastUpdated(getLastUpdated(condition)); + fhirCondition.getMeta().setVersionId(getVersionId(condition)); return fhirCondition; } @Override - public Obs toOpenmrsType(@Nonnull org.hl7.fhir.r4.model.Condition condition) { + public Condition toOpenmrsType(@Nonnull org.hl7.fhir.r4.model.Condition condition) { notNull(condition, "The Condition object should not be null"); - return this.toOpenmrsType(new Obs(), condition); + return this.toOpenmrsType(new Condition(), condition); } @Override - public Obs toOpenmrsType(@Nonnull Obs existingObsCondition, @Nonnull org.hl7.fhir.r4.model.Condition condition) { - notNull(existingObsCondition, "The existing Openmrs Obs Condition object should not be null"); + public Condition toOpenmrsType(@Nonnull Condition existingCondition, + @Nonnull org.hl7.fhir.r4.model.Condition condition) { + notNull(existingCondition, "The existing Openmrs Condition object should not be null"); notNull(condition, "The Condition object should not be null"); if (condition.hasId()) { - existingObsCondition.setUuid(condition.getIdElement().getIdPart()); + existingCondition.setUuid(condition.getIdElement().getIdPart()); } + existingCondition.setPatient(patientReferenceTranslator.toOpenmrsType(condition.getSubject())); + existingCondition.setClinicalStatus(clinicalStatusTranslator.toOpenmrsType(condition.getClinicalStatus())); + existingCondition + .setVerificationStatus(verificationStatusTranslator.toOpenmrsType(condition.getVerificationStatus())); + CodeableConcept codeableConcept = condition.getCode(); - existingObsCondition.setValueCoded(conceptTranslator.toOpenmrsType(codeableConcept)); - existingObsCondition.setPerson(patientReferenceTranslator.toOpenmrsType(condition.getSubject())); - Concept problemList = conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID); - if (problemList != null) { - existingObsCondition.setConcept(problemList); - } else { - throw new InternalErrorException( - "Concept " + FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID + " ProblemList Not found"); + CodedOrFreeText conditionCodedOrText = new CodedOrFreeText(); + Optional extension = Optional + .ofNullable(condition.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION)); + extension.ifPresent(value -> conditionCodedOrText.setNonCoded(String.valueOf(value.getValue()))); + conditionCodedOrText.setCoded(conceptTranslator.toOpenmrsType(codeableConcept)); + existingCondition.setCondition(conditionCodedOrText); + + if (condition.hasOnsetDateTimeType()) { + existingCondition.setOnsetDate(condition.getOnsetDateTimeType().getValue()); + } else if (condition.hasOnsetPeriod()) { + existingCondition.setOnsetDate(condition.getOnsetPeriod().getStart()); } - Date onsetTime = condition.getOnsetDateTimeType().getValue(); - Date recordTime = condition.getRecordedDateElement().getValue(); - if (onsetTime != null) { - existingObsCondition.setObsDatetime(onsetTime); - } else if (recordTime != null) { - existingObsCondition.setObsDatetime(recordTime); + + if (condition.hasAbatementDateTimeType()) { + existingCondition.setEndDate(condition.getAbatementDateTimeType().getValue()); + } else if (condition.hasAbatementPeriod()) { + existingCondition.setEndDate(condition.getAbatementPeriod().getEnd()); } - existingObsCondition.setCreator(practitionerReferenceTranslator.toOpenmrsType(condition.getRecorder())); - return existingObsCondition; + existingCondition.setCreator(practitionerReferenceTranslator.toOpenmrsType(condition.getRecorder())); + + return existingCondition; } } diff --git a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl.java similarity index 90% rename from api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2.java rename to api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl.java index 4cffda345b..219221fb66 100644 --- a/api-2.2/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl.java @@ -16,14 +16,12 @@ import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.openmrs.ConditionVerificationStatus; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.translators.ConditionVerificationStatusTranslator; import org.springframework.stereotype.Component; @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.2.* - 2.*") -public class ConditionVerificationStatusTranslatorImpl_2_2 implements ConditionVerificationStatusTranslator { +public class ConditionVerificationStatusTranslatorImpl implements ConditionVerificationStatusTranslator { @Override public CodeableConcept toFhirResource(@Nonnull ConditionVerificationStatus verificationStatus) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl.java index a36b864607..9e7c324340 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupMemberTranslatorImpl.java @@ -15,7 +15,6 @@ import lombok.AccessLevel; import lombok.Setter; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.api.dao.FhirPatientDao; import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator; import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; @@ -25,7 +24,6 @@ @Component @Setter(AccessLevel.MODULE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.* - 2.0.*") public class GroupMemberTranslatorImpl implements GroupMemberTranslator { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl.java index ecf31a4b77..789bd46eac 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/GroupTranslatorImpl.java @@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j; import org.hl7.fhir.r4.model.Group; import org.openmrs.Cohort; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.api.translators.GroupMemberTranslator; import org.openmrs.module.fhir2.api.translators.GroupTranslator; import org.openmrs.module.fhir2.model.GroupMember; @@ -32,7 +31,6 @@ @Slf4j @Component @Setter(AccessLevel.MODULE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.* - 2.0.*") public class GroupTranslatorImpl extends BaseGroupTranslator implements GroupTranslator { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl.java index b3439ea561..dbf5d0e670 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImpl.java @@ -13,12 +13,11 @@ import org.hl7.fhir.r4.model.MedicationRequest; import org.openmrs.DrugOrder; -import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.Order; import org.openmrs.module.fhir2.api.translators.MedicationRequestStatusTranslator; import org.springframework.stereotype.Component; @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") public class MedicationRequestStatusTranslatorImpl implements MedicationRequestStatusTranslator { @Override @@ -27,7 +26,10 @@ public MedicationRequest.MedicationRequestStatus toFhirResource(@Nonnull DrugOrd return null; } - if (drugOrder.isActive()) { + if (drugOrder.getFulfillerStatus() != null + && drugOrder.getFulfillerStatus().equals(Order.FulfillerStatus.COMPLETED)) { + return MedicationRequest.MedicationRequestStatus.COMPLETED; + } else if (drugOrder.isActive()) { return MedicationRequest.MedicationRequestStatus.ACTIVE; } else if (drugOrder.isDiscontinuedRightNow() || drugOrder.getVoided()) { return MedicationRequest.MedicationRequestStatus.CANCELLED; @@ -36,4 +38,5 @@ public MedicationRequest.MedicationRequestStatus toFhirResource(@Nonnull DrugOrd } return MedicationRequest.MedicationRequestStatus.UNKNOWN; } + } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java index 6465529e28..29db918872 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java @@ -10,6 +10,7 @@ package org.openmrs.module.fhir2.api.translators.impl; import static org.apache.commons.lang3.Validate.notNull; +import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getLastUpdated; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getVersionId; @@ -21,7 +22,9 @@ import lombok.Setter; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.r4.model.Annotation; +import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.MedicationRequest; import org.openmrs.Concept; import org.openmrs.Drug; @@ -29,7 +32,6 @@ import org.openmrs.Encounter; import org.openmrs.Order; import org.openmrs.Provider; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.api.translators.ConceptTranslator; import org.openmrs.module.fhir2.api.translators.DosageTranslator; import org.openmrs.module.fhir2.api.translators.EncounterReferenceTranslator; @@ -46,7 +48,6 @@ @Component @Setter(AccessLevel.PACKAGE) -@OpenmrsProfile(openmrsPlatformVersion = "2.0.5 - 2.1.*") public class MedicationRequestTranslatorImpl extends BaseReferenceHandlingTranslator implements MedicationRequestTranslator { @Autowired @@ -121,6 +122,13 @@ public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) { .setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())))); } + if (drugOrder.getFulfillerStatus() != null) { + Extension extension = new Extension(); + extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); + extension.setValue(new CodeType(drugOrder.getFulfillerStatus().toString())); + medicationRequest.addExtension(extension); + } + medicationRequest.getMeta().setLastUpdated(getLastUpdated(drugOrder)); medicationRequest.getMeta().setVersionId(getVersionId(drugOrder)); @@ -171,6 +179,17 @@ public DrugOrder toOpenmrsType(@Nonnull DrugOrder existingDrugOrder, @Nonnull Me medicationRequestDispenseRequestComponentTranslator.toOpenmrsType(existingDrugOrder, medicationRequest.getDispenseRequest()); + if (medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS) != null) { + if (!medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue() + .isEmpty()) { + existingDrugOrder.setFulfillerStatus(Order.FulfillerStatus + .valueOf(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS) + .getValue().toString().toUpperCase())); + } else { + existingDrugOrder.setFulfillerStatus(null); + } + } + return existingDrugOrder; } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl.java index 4ef1321fdc..69967de62d 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImpl.java @@ -11,23 +11,174 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.WordUtils; import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Coding; import org.openmrs.Obs; -import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.translators.ObservationInterpretationTranslator; import org.springframework.stereotype.Component; @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.0.* - 2.0.*") public class ObservationInterpretationTranslatorImpl implements ObservationInterpretationTranslator { @Override public CodeableConcept toFhirResource(@Nonnull Obs obs) { - return null; + if (obs.getInterpretation() == null) { + return null; + } + + CodeableConcept interpretation = new CodeableConcept(); + switch (obs.getInterpretation()) { + case NORMAL: + interpretation.addCoding(addInterpretationCoding("N", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case ABNORMAL: + interpretation.addCoding(addInterpretationCoding("A", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case CRITICALLY_ABNORMAL: + interpretation.addCoding(addInterpretationCoding("AA", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case CRITICALLY_HIGH: + interpretation.addCoding(addInterpretationCoding("HH", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case CRITICALLY_LOW: + interpretation.addCoding(addInterpretationCoding("LL", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case HIGH: + interpretation.addCoding(addInterpretationCoding("H", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case LOW: + interpretation.addCoding(addInterpretationCoding("L", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case OFF_SCALE_LOW: + interpretation.addCoding(addInterpretationCoding("<", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case OFF_SCALE_HIGH: + interpretation.addCoding(addInterpretationCoding(">", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case SIGNIFICANT_CHANGE_DOWN: + interpretation.addCoding(addInterpretationCoding("D", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case SIGNIFICANT_CHANGE_UP: + interpretation.addCoding(addInterpretationCoding("U", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case RESISTANT: + interpretation.addCoding(addInterpretationCoding("R", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case SUSCEPTIBLE: + interpretation.addCoding(addInterpretationCoding("S", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case INTERMEDIATE: + interpretation.addCoding(addInterpretationCoding("I", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case POSITIVE: + interpretation.addCoding(addInterpretationCoding("POS", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case NEGATIVE: + interpretation.addCoding(addInterpretationCoding("NEG", obs.getInterpretation())); + setText(interpretation, obs.getInterpretation()); + break; + case VERY_SUSCEPTIBLE: + interpretation.addCoding(new Coding().setSystem(FhirConstants.OPENMRS_FHIR_EXT_VS_INTERPRETATION) + .setCode("VS").setDisplay("Very Susceptible")); + setText(interpretation, obs.getInterpretation()); + break; + default: + return interpretation; + + } + return interpretation; } @Override - public Obs toOpenmrsType(@Nonnull Obs existingObs, @Nonnull CodeableConcept resource) { - return existingObs; + public Obs toOpenmrsType(@Nonnull Obs openmrsObs, @Nonnull CodeableConcept interpretation) { + if (interpretation.getCoding().size() == 0) { + return null; + } + switch (interpretation.getCoding().get(0).getCode()) { + case "N": + openmrsObs.setInterpretation(Obs.Interpretation.NORMAL); + break; + case "A": + openmrsObs.setInterpretation(Obs.Interpretation.ABNORMAL); + break; + case "AA": + openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_ABNORMAL); + break; + case "HH": + openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_HIGH); + break; + case "LL": + openmrsObs.setInterpretation(Obs.Interpretation.CRITICALLY_LOW); + break; + case "H": + openmrsObs.setInterpretation(Obs.Interpretation.HIGH); + break; + case "L": + openmrsObs.setInterpretation(Obs.Interpretation.LOW); + break; + case "<": + openmrsObs.setInterpretation(Obs.Interpretation.OFF_SCALE_LOW); + break; + case ">": + openmrsObs.setInterpretation(Obs.Interpretation.OFF_SCALE_HIGH); + break; + case "D": + openmrsObs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN); + break; + case "U": + openmrsObs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_UP); + break; + case "R": + openmrsObs.setInterpretation(Obs.Interpretation.RESISTANT); + break; + case "S": + openmrsObs.setInterpretation(Obs.Interpretation.SUSCEPTIBLE); + break; + case "I": + openmrsObs.setInterpretation(Obs.Interpretation.INTERMEDIATE); + break; + case "POS": + openmrsObs.setInterpretation(Obs.Interpretation.POSITIVE); + break; + case "NEG": + openmrsObs.setInterpretation(Obs.Interpretation.NEGATIVE); + break; + case "VS": + openmrsObs.setInterpretation(Obs.Interpretation.VERY_SUSCEPTIBLE); + break; + default: + openmrsObs.setInterpretation(null); + break; + } + return openmrsObs; + } + + private Coding addInterpretationCoding(String code, Obs.Interpretation display) { + Coding coding = new Coding(); + coding.setSystem(FhirConstants.INTERPRETATION_SYSTEM_URI); + coding.setCode(code); + coding.setDisplay(WordUtils.capitalizeFully(display.toString().replaceAll("_", " "))); + return coding; + } + + private void setText(CodeableConcept interpretation, Obs.Interpretation text) { + interpretation.setText(WordUtils.capitalizeFully(text.toString().replaceAll("_", " "))); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl.java index 7b1a79c395..815d99bf1f 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImpl.java @@ -13,21 +13,24 @@ import org.hl7.fhir.r4.model.Observation; import org.openmrs.Obs; -import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.module.fhir2.api.translators.ObservationStatusTranslator; import org.springframework.stereotype.Component; @Component -@OpenmrsProfile(openmrsPlatformVersion = "2.0.* - 2.0.*") public class ObservationStatusTranslatorImpl implements ObservationStatusTranslator { @Override - public Observation.ObservationStatus toFhirResource(@Nonnull Obs observation) { - return Observation.ObservationStatus.UNKNOWN; + public Observation.ObservationStatus toFhirResource(@Nonnull Obs obs) { + return Observation.ObservationStatus.valueOf(obs.getStatus().toString()); } @Override public Obs toOpenmrsType(@Nonnull Obs observation, @Nonnull Observation.ObservationStatus observationStatus) { + if (observationStatus.equals(Observation.ObservationStatus.PRELIMINARY) + || observationStatus.equals(Observation.ObservationStatus.FINAL) + || observationStatus.equals(Observation.ObservationStatus.AMENDED)) { + observation.setStatus(Obs.Status.valueOf(observationStatus.toString())); + } return observation; } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImplTest.java deleted file mode 100644 index 790d5ba7a1..0000000000 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImplTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.openmrs.test.OpenmrsMatchers.hasId; - -import java.util.Collection; -import java.util.Date; -import java.util.List; - -import ca.uhn.fhir.rest.param.TokenAndListParam; -import ca.uhn.fhir.rest.param.TokenParam; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.Obs; -import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.dao.FhirConditionDao; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirConditionDaoImplTest extends BaseModuleContextSensitiveTest { - - private static final Integer VOIDED_OBS_CONDITION_ID = 33; - - private static final String EXISTING_OBS_CONDITION_UUID = "86sgf-1f7d-4394-a316-0a458edf28c4"; - - private static final String WRONG_OBS_CONDITION_UUID = "430bbb70-6a9c-4e1e-badb-9d1034b1b5e9"; - - private static final String NEW_OBS_CONDITION_UUID = "NEWbbb70-6a9c-4e1e-badb-9d1034b1b5e9"; - - private static final String OBS_CONDITION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml"; - - private static final String OBS_CONDITION_CONCEPT_ID = "116128"; - - private static final String OBS_CONDITION_CODED_CONCEPT_ID = "1284"; - - private static final String WORNG_OBS_CONDITION_CONCEPT_ID = "116145"; - - private static final Integer PATIENT_ID = 6; - - @Autowired - private FhirConditionDao dao; - - @Autowired - private ConceptService conceptService; - - @Autowired - private PatientService patientService; - - @Before - public void setUp() throws Exception { - executeDataSet(OBS_CONDITION_INITIAL_DATA_XML); - } - - @Test - public void get_shouldGetObsConditionByUuid() { - Obs result = dao.get(EXISTING_OBS_CONDITION_UUID); - assertThat(result, notNullValue()); - assertThat(result.getUuid(), equalTo(EXISTING_OBS_CONDITION_UUID)); - } - - @Test - public void get_shouldReturnNullIfObsNotFoundByUuid() { - Obs result = dao.get(WRONG_OBS_CONDITION_UUID); - assertThat(result, nullValue()); - } - - @Test - public void search_shouldReturnConditonResourceUuidsWithObsCoded_1284() { - TokenAndListParam code = new TokenAndListParam(); - TokenParam codingToken = new TokenParam(); - codingToken.setValue(OBS_CONDITION_CONCEPT_ID); - code.addAnd(codingToken); - - SearchParameterMap theParams = new SearchParameterMap(); - theParams.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code); - - List matchingResources = dao.getSearchResults(theParams); - assertThat(matchingResources, hasSize(2)); - } - - @Test - public void search_shouldReturnNoConditonResourceUuidsWhenNoWrongConceptIdIsUsed() { - TokenAndListParam code = new TokenAndListParam(); - TokenParam codingToken = new TokenParam(); - codingToken.setValue(WORNG_OBS_CONDITION_CONCEPT_ID); - code.addAnd(codingToken); - - SearchParameterMap theParams = new SearchParameterMap(); - theParams.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code); - - List matchingResources = dao.getSearchResults(theParams); - assertThat(matchingResources, hasSize(0)); - } - - @Test - public void search_shouldReturnNoVoidedConditionResourceUuids() { - TokenAndListParam code = new TokenAndListParam(); - TokenParam codingToken = new TokenParam(); - codingToken.setValue(OBS_CONDITION_CONCEPT_ID); - code.addAnd(codingToken); - - SearchParameterMap theParams = new SearchParameterMap(); - theParams.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code); - - List matchingResources = dao.getSearchResults(theParams); - assertThat(matchingResources, not(hasItem(hasId(VOIDED_OBS_CONDITION_ID)))); - } - - @Test - public void search_shouldReturnSearchQuery() { - TokenAndListParam code = new TokenAndListParam(); - TokenParam codingToken = new TokenParam(); - codingToken.setValue(OBS_CONDITION_CONCEPT_ID); - code.addAnd(codingToken); - - SearchParameterMap theParams = new SearchParameterMap(); - theParams.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code); - - Collection obs = dao.getSearchResults(theParams); - assertThat(obs, notNullValue()); - assertThat(obs, hasSize(2)); - } - - @Test - public void shouldSaveNewObsCondition() { - Obs obsCondition = new Obs(); - obsCondition.setUuid(NEW_OBS_CONDITION_UUID); - obsCondition.setObsDatetime(new Date()); - obsCondition.setConcept(conceptService.getConcept(OBS_CONDITION_CODED_CONCEPT_ID)); - - org.openmrs.Patient patient = patientService.getPatient(PATIENT_ID); - obsCondition.setPerson(patient); - obsCondition.setValueCoded(conceptService.getConcept(OBS_CONDITION_CONCEPT_ID)); - - dao.createOrUpdate(obsCondition); - - Obs result = dao.get(NEW_OBS_CONDITION_UUID); - assertThat(result, notNullValue()); - assertThat(result.getUuid(), equalTo(NEW_OBS_CONDITION_UUID)); - } - - @Test - public void shouldDeleteObsCondition() { - Obs result = dao.delete(EXISTING_OBS_CONDITION_UUID); - - assertThat(result, notNullValue()); - assertThat(result.getUuid(), equalTo(EXISTING_OBS_CONDITION_UUID)); - assertThat(result.getVoided(), equalTo(true)); - - } -} diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2Test.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java similarity index 96% rename from api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2Test.java rename to api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java index 55870daf16..298e6755d3 100644 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_2_2Test.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java @@ -33,7 +33,7 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirConditionDaoImpl_2_2Test extends BaseModuleContextSensitiveTest { +public class FhirConditionDaoImpl_Test extends BaseModuleContextSensitiveTest { private static final String CONDITION_UUID = "2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"; @@ -62,11 +62,11 @@ public class FhirConditionDaoImpl_2_2Test extends BaseModuleContextSensitiveTest @Autowired private ConceptService conceptService; - private FhirConditionDaoImpl_2_2 dao; + private FhirConditionDaoImpl dao; @Before public void setUp() { - dao = new FhirConditionDaoImpl_2_2(); + dao = new FhirConditionDaoImpl(); dao.setSessionFactory(sessionFactory); executeDataSet(CONDITION_INITIAL_DATA_XML); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java index 9566102cb4..c3a8601f1e 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java @@ -58,7 +58,9 @@ public class FhirEncounterDaoImplTest extends BaseModuleContextSensitiveTest { private static final Integer ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER = 2004; - private static final String ENCOUNTER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest_initial_data.xml"; + private static final Integer ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER = 2005; + + private static final String ENCOUNTER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test_initial_data.xml"; @Autowired @Qualifier("sessionFactory") @@ -89,37 +91,6 @@ public void shouldReturnNullWithUnknownEncounterUuid() { assertThat(encounter, nullValue()); } - @Test - public void shouldOnlyReturnEncountersThatHaveAssociatedMedicationRequests() { - Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); - assertThat(withNoDrugOrders, notNullValue()); - assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); - - Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); - assertThat(withDrugOrders, notNullValue()); - assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); - for (Order order : withDrugOrders.getOrders()) { - assertThat(order.getClass(), equalTo(DrugOrder.class)); - } - - HasOrListParam hasOrListParam = new HasOrListParam(); - hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "intent", "order")); - HasAndListParam hasAndListParam = new HasAndListParam(); - hasAndListParam.addAnd(hasOrListParam); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, - hasAndListParam); - - List matchingResources = dao.getSearchResults(theParams); - assertThat("Encounter with Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); - assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); - assertThat("Encounter with only expired Drug Orders is returned", matchingResources, - hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); - assertThat("Encounter without Drug Orders is not returned", matchingResources, - not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); - } - @Test public void shouldOnlyReturnEncountersThatHaveAssociatedActiveMedicationRequests() { @@ -208,4 +179,136 @@ public void delete_shouldVoidEncounterAndUnderlyingObservations() { assertThat(encounter.getVoidReason(), equalTo("Voided via FHIR API")); assertThat(encounter.getObs().size(), equalTo(0)); // "getObs" does not return voided obs, so if all obs are voided, this count should be 0 } + + @Test + public void shouldOnlyReturnEncountersThatHaveAssociatedMedicationRequests() { + Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); + assertThat(withNoDrugOrders, notNullValue()); + assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); + + Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); + assertThat(withDrugOrders, notNullValue()); + assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); + for (Order order : withDrugOrders.getOrders()) { + assertThat(order.getClass(), equalTo(DrugOrder.class)); + } + + HasOrListParam hasOrListParam = new HasOrListParam(); + hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "intent", "order")); + HasAndListParam hasAndListParam = new HasAndListParam(); + hasAndListParam.addAnd(hasOrListParam); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, + hasAndListParam); + + List matchingResources = dao.getSearchResults(theParams); + assertThat("Encounter with Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); + assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); + assertThat("Encounter with only expired Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); + assertThat("Encounter with only completed Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER))); + assertThat("Encounter without Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); + } + + @Test + public void shouldExcludedEncountersWithOnlyCompletedMedicationRequestsWhenReturnEncountersThatHaveAssociatedMedicationRequests() { + Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); + assertThat(withNoDrugOrders, notNullValue()); + assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); + + Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); + assertThat(withDrugOrders, notNullValue()); + assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); + for (Order order : withDrugOrders.getOrders()) { + assertThat(order.getClass(), equalTo(DrugOrder.class)); + } + + HasOrListParam hasOrListParam = new HasOrListParam(); + hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "status:not", "completed")); + HasAndListParam hasAndListParam = new HasAndListParam(); + hasAndListParam.addAnd(hasOrListParam); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, + hasAndListParam); + + List matchingResources = dao.getSearchResults(theParams); + assertThat("Encounter with Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); + assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); + assertThat("Encounter with only expired Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); + assertThat("Encounter with only completed Drug Orders is returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER)))); + assertThat("Encounter without Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); + } + + @Test + public void shouldExcludedEncountersWithMedicationRequestsWithOnlyFulfillerStatusCompletedWhenReturnEncountersThatHaveAssociatedMedicationRequests() { + Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); + assertThat(withNoDrugOrders, notNullValue()); + assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); + + Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); + assertThat(withDrugOrders, notNullValue()); + assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); + for (Order order : withDrugOrders.getOrders()) { + assertThat(order.getClass(), equalTo(DrugOrder.class)); + } + + HasOrListParam hasOrListParam = new HasOrListParam(); + hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "fulfillerStatus:not", "completed")); + HasAndListParam hasAndListParam = new HasAndListParam(); + hasAndListParam.addAnd(hasOrListParam); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, + hasAndListParam); + + List matchingResources = dao.getSearchResults(theParams); + assertThat("Encounter with Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID))); + assertThat("Encounter with only cancelled Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER))); + assertThat("Encounter with only expired Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER))); + assertThat("Encounter with only completed Drug Orders not is returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER)))); + assertThat("Encounter without Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); + } + + @Test + public void shouldOnlyIncludeEncountersWithMedicationRequestsWithFulfillerStatusCompletedWhenReturnEncountersThatHaveAssociatedMedicationRequests() { + Encounter withNoDrugOrders = dao.get(ENCOUNTER_WITH_NO_DRUG_ORDERS); + assertThat(withNoDrugOrders, notNullValue()); + assertThat("Orders is empty", withNoDrugOrders.getOrders().isEmpty()); + + Encounter withDrugOrders = dao.get(ENCOUNTER_WITH_DRUG_ORDERS); + assertThat(withDrugOrders, notNullValue()); + assertThat("Orders is not empty", !withDrugOrders.getOrders().isEmpty()); + for (Order order : withDrugOrders.getOrders()) { + assertThat(order.getClass(), equalTo(DrugOrder.class)); + } + + HasOrListParam hasOrListParam = new HasOrListParam(); + hasOrListParam.add(new HasParam("MedicationRequest", "encounter", "fulfillerStatus", "completed")); + HasAndListParam hasAndListParam = new HasAndListParam(); + hasAndListParam.addAnd(hasOrListParam); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, + hasAndListParam); + + List matchingResources = dao.getSearchResults(theParams); + assertThat("Encounter with Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_DRUG_ORDERS_ID)))); + assertThat("Encounter with only cancelled Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_ONLY_CANCELlED_DRUG_ORDER)))); + assertThat("Encounter with only expired Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_ONLY_EXPIRED_DRUG_ORDER)))); + assertThat("Encounter with only completed Drug Orders is returned", matchingResources, + hasItem(hasId(ENCOUNTER_WITH_ONLY_COMPLETED_DRUG_ORDER))); + assertThat("Encounter without Drug Orders is not returned", matchingResources, + not(hasItem(hasId(ENCOUNTER_WITH_NO_DRUG_ORDERS_ID)))); + } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java index deec253021..aec3665eb2 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java @@ -236,13 +236,13 @@ public void saveTask_shouldUpdateInput() throws Exception { toUpdate.setInput(Collections.singleton(input)); - FhirTask result = dao.get(TASK_UUID); + FhirTask updatedInput = dao.createOrUpdate(toUpdate); - assertThat(result.getInput(), notNullValue()); - assertThat(result.getInput(), not(empty())); + assertThat(updatedInput.getInput(), notNullValue()); + assertThat(updatedInput.getInput(), not(empty())); - assertThat(result.getInput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID))))); - assertThat(result.getInput(), hasItem(hasProperty("valueNumeric", equalTo(someNumericVal)))); + assertThat(updatedInput.getInput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID))))); + assertThat(updatedInput.getInput(), hasItem(hasProperty("valueNumeric", equalTo(someNumericVal)))); } @Test @@ -255,6 +255,8 @@ public void saveTask_shouldUpdateOutput() throws Exception { FhirTask toUpdate = dao.get(TASK_UUID); + assertThat(toUpdate, notNullValue()); + FhirReference outputReference = new FhirReference(); outputReference.setType(FhirConstants.DIAGNOSTIC_REPORT); outputReference.setReference(DIAGNOSTIC_REPORT_UUID); @@ -274,13 +276,13 @@ public void saveTask_shouldUpdateOutput() throws Exception { toUpdate.setOutput(Collections.singleton(output)); - FhirTask result = dao.get(TASK_UUID); + FhirTask updatedOutput = dao.createOrUpdate(toUpdate); - assertThat(result.getOutput(), notNullValue()); - assertThat(result.getOutput(), not(empty())); + assertThat(updatedOutput.getOutput(), notNullValue()); + assertThat(updatedOutput.getOutput(), not(empty())); - assertThat(result.getOutput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID))))); - assertThat(result.getOutput(), + assertThat(updatedOutput.getOutput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID))))); + assertThat(updatedOutput.getOutput(), hasItem(hasProperty("valueReference", hasProperty("reference", equalTo(DIAGNOSTIC_REPORT_UUID))))); } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirAllergyIntoleranceServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirAllergyIntoleranceServiceImplTest.java index c191139184..d5dcdb8fcb 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirAllergyIntoleranceServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirAllergyIntoleranceServiceImplTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImplTest.java index 151b79c2c1..f79c35adb7 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirConditionServiceImplTest.java @@ -9,14 +9,14 @@ */ package org.openmrs.module.fhir2.api.impl; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -40,13 +40,13 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Condition; +import org.hl7.fhir.r4.model.Patient; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.Obs; +import org.openmrs.Condition; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.dao.FhirConditionDao; @@ -60,11 +60,11 @@ @RunWith(MockitoJUnitRunner.class) public class FhirConditionServiceImplTest { - private static final Integer OBS_ID = 12345; + private static final Integer CONDITION_ID = 123; - private static final String OBS_UUID = "12345-abcde-12345"; + private static final String CONDITION_UUID = "43578769-f1a4-46af-b08b-d9fe8a07066f"; - private static final String WRONG_OBS_CONDITION_UUID = "90378769-f1a4-46af-034j"; + private static final String WRONG_CONDITION_UUID = "90378769-f1a4-46af-b08b-d9fe8a09034j"; private static final String LAST_UPDATED_DATE = "2020-09-03"; @@ -73,45 +73,44 @@ public class FhirConditionServiceImplTest { private static final int END_INDEX = 10; @Mock - private FhirConditionDao dao; + private FhirConditionDao dao; @Mock - private FhirGlobalPropertyService globalPropertyService; + private ConditionTranslator conditionTranslator; @Mock - private SearchQueryInclude searchQueryInclude; + private FhirGlobalPropertyService globalPropertyService; @Mock - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; + private SearchQueryInclude searchQueryInclude; @Mock - private ConditionTranslator translator; + private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; - private FhirConditionServiceImpl fhirConditionService; + private FhirConditionServiceImpl conditionService; - private Obs obsCondition; + private Condition openmrsCondition; - private org.hl7.fhir.r4.model.Condition condition; + private org.hl7.fhir.r4.model.Condition fhirCondition; @Before public void setup() { - fhirConditionService = new FhirConditionServiceImpl() { + conditionService = new FhirConditionServiceImpl() { @Override - protected void validateObject(Obs object) { + protected void validateObject(Condition object) { } }; + conditionService.setDao(dao); + conditionService.setTranslator(conditionTranslator); + conditionService.setSearchQuery(searchQuery); + conditionService.setSearchQueryInclude(searchQueryInclude); - fhirConditionService.setDao(dao); - fhirConditionService.setTranslator(translator); - fhirConditionService.setSearchQueryInclude(searchQueryInclude); - fhirConditionService.setSearchQuery(searchQuery); - - obsCondition = new Obs(); - obsCondition.setUuid(OBS_UUID); + openmrsCondition = new Condition(); + openmrsCondition.setUuid(CONDITION_UUID); - condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(OBS_UUID); + fhirCondition = new org.hl7.fhir.r4.model.Condition(); + fhirCondition.setId(CONDITION_UUID); } private List get(IBundleProvider results) { @@ -119,88 +118,118 @@ private List get(IBundleProvider results) { } @Test - public void getObsConditionByUuid_shouldReturnConditionByUuid() { - when(dao.get(OBS_UUID)).thenReturn(obsCondition); - when(translator.toFhirResource(obsCondition)).thenReturn(condition); + public void shouldGetConditionByUuid() { + when(dao.get(CONDITION_UUID)).thenReturn(openmrsCondition); + when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(fhirCondition); - Condition result = fhirConditionService.get(OBS_UUID); - assertThat(result, notNullValue()); - assertThat(result.getId(), equalTo(OBS_UUID)); + org.hl7.fhir.r4.model.Condition condition = conditionService.get(CONDITION_UUID); + + assertThat(condition, notNullValue()); + assertThat(condition.getId(), notNullValue()); + assertThat(condition.getId(), equalTo(CONDITION_UUID)); } @Test public void shouldThrowExceptionWhenGetMissingUuid() { - assertThrows(ResourceNotFoundException.class, () -> fhirConditionService.get(WRONG_OBS_CONDITION_UUID)); + assertThrows(ResourceNotFoundException.class, () -> conditionService.get(WRONG_CONDITION_UUID)); } @Test public void create_shouldCreateNewCondition() { - when(translator.toFhirResource(obsCondition)).thenReturn(condition); - when(dao.createOrUpdate(obsCondition)).thenReturn(obsCondition); - when(translator.toOpenmrsType(condition)).thenReturn(obsCondition); + Condition openMrsCondition = new Condition(); + openMrsCondition.setUuid(CONDITION_UUID); - org.hl7.fhir.r4.model.Condition result = fhirConditionService.create(condition); + org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); + condition.setId(CONDITION_UUID); + + when(conditionTranslator.toFhirResource(openMrsCondition)).thenReturn(condition); + when(dao.createOrUpdate(openMrsCondition)).thenReturn(openMrsCondition); + when(conditionTranslator.toOpenmrsType(condition)).thenReturn(openMrsCondition); + + org.hl7.fhir.r4.model.Condition result = conditionService.create(condition); assertThat(result, notNullValue()); assertThat(result.getId(), notNullValue()); - assertThat(result.getId(), equalTo(OBS_UUID)); + assertThat(result.getId(), equalTo(CONDITION_UUID)); } @Test - public void update_shouldUpdateExistingObsCondition() { - when(dao.get(OBS_UUID)).thenReturn(obsCondition); - when(translator.toFhirResource(obsCondition)).thenReturn(condition); - when(dao.createOrUpdate(obsCondition)).thenReturn(obsCondition); - when(translator.toOpenmrsType(any(Obs.class), any(org.hl7.fhir.r4.model.Condition.class))).thenReturn(obsCondition); + public void update_shouldUpdateExistingCondition() { + Condition openmrsCondition = new Condition(); + openmrsCondition.setUuid(CONDITION_UUID); + + org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); + condition.setId(CONDITION_UUID); + + when(dao.get(CONDITION_UUID)).thenReturn(openmrsCondition); + when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(condition); + when(dao.createOrUpdate(openmrsCondition)).thenReturn(openmrsCondition); + when(conditionTranslator.toOpenmrsType(any(Condition.class), any(org.hl7.fhir.r4.model.Condition.class))) + .thenReturn(openmrsCondition); - org.hl7.fhir.r4.model.Condition result = fhirConditionService.update(OBS_UUID, condition); + org.hl7.fhir.r4.model.Condition result = conditionService.update(CONDITION_UUID, condition); assertThat(result, notNullValue()); assertThat(result.getId(), notNullValue()); - assertThat(result.getId(), equalTo(OBS_UUID)); + assertThat(result.getId(), equalTo(CONDITION_UUID)); } @Test public void update_shouldThrowExceptionWhenIdIsNull() { org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - assertThrows(InvalidRequestException.class, () -> fhirConditionService.update(null, condition)); + assertThrows(InvalidRequestException.class, () -> conditionService.update(null, condition)); } @Test public void update_shouldThrowExceptionWhenConditionIsNull() { - assertThrows(InvalidRequestException.class, () -> fhirConditionService.update(OBS_UUID, null)); + assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, null)); + } + + @Test + public void update_shouldThrowExceptionWhenConditionIdIsNull() { + org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); + + assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, condition)); } @Test public void update_shouldThrowExceptionWhenConditionIdDoesNotMatchCurrentId() { org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); - condition.setId(OBS_UUID); + condition.setId(WRONG_CONDITION_UUID); - assertThrows(InvalidRequestException.class, () -> fhirConditionService.update(WRONG_OBS_CONDITION_UUID, condition)); + assertThrows(InvalidRequestException.class, () -> conditionService.update(CONDITION_UUID, condition)); } @Test public void delete_shouldDeleteExistingCondition() { - when(dao.delete(OBS_UUID)).thenReturn(obsCondition); + Condition openmrsCondition = new Condition(); + openmrsCondition.setUuid(CONDITION_UUID); - fhirConditionService.delete(OBS_UUID); + org.hl7.fhir.r4.model.Condition condition = new org.hl7.fhir.r4.model.Condition(); + condition.setId(CONDITION_UUID); + + when(dao.delete(CONDITION_UUID)).thenReturn(openmrsCondition); + + conditionService.delete(CONDITION_UUID); } @Test public void delete_shouldThrowExceptionWhenIdIsNull() { - assertThrows(InvalidRequestException.class, () -> fhirConditionService.delete(null)); + assertThrows(InvalidRequestException.class, () -> conditionService.delete(null)); } @Test public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { ReferenceAndListParam patientReference = new ReferenceAndListParam(); - patientReference.addValue( - new ReferenceOrListParam().add(new ReferenceParam(org.hl7.fhir.r4.model.Patient.SP_GIVEN, "patient name"))); + patientReference.addValue(new ReferenceOrListParam().add(new ReferenceParam(Patient.SP_GIVEN, "patient name"))); TokenAndListParam codeList = new TokenAndListParam(); codeList.addValue(new TokenOrListParam().add(new TokenParam("test code"))); + TokenAndListParam clinicalList = new TokenAndListParam(); + clinicalList.addValue(new TokenOrListParam().add(new TokenParam("test clinical"))); + DateRangeParam onsetDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01"); QuantityAndListParam onsetAge = new QuantityAndListParam(); @@ -208,7 +237,7 @@ public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { DateRangeParam recordDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01"); - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_UUID)); + TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); @@ -219,6 +248,7 @@ public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { SearchParameterMap theParams = new SearchParameterMap() .addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference) .addParameter(FhirConstants.CODED_SEARCH_HANDLER, codeList) + .addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, clinicalList) .addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAge) .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", onsetDate) .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", recordDate) @@ -226,14 +256,14 @@ public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated) .setSortSpec(sort); - when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obsCondition)); + when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(openmrsCondition)); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( - new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude)); + new SearchQueryBundleProvider<>(theParams, dao, conditionTranslator, globalPropertyService, searchQueryInclude)); when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); - when(translator.toFhirResource(obsCondition)).thenReturn(condition); + when(conditionTranslator.toFhirResource(openmrsCondition)).thenReturn(fhirCondition); - IBundleProvider result = fhirConditionService.searchConditions(new ConditionSearchParams(patientReference, codeList, - null, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes)); + IBundleProvider result = conditionService.searchConditions(new ConditionSearchParams(patientReference, codeList, + clinicalList, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes)); List resultList = get(result); @@ -241,5 +271,4 @@ public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() { assertThat(resultList, not(empty())); assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } - } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImplTest.java index 9f0a9d1c38..ccae8275dc 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGroupServiceImplTest.java @@ -17,7 +17,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImplTest.java index 2de5027f6f..2de9b28df3 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationDispenseServiceImplTest.java @@ -11,7 +11,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collections; import java.util.List; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationRequestServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationRequestServiceImplTest.java index 20b2803242..93d7f65382 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationRequestServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationRequestServiceImplTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationServiceImplTest.java index 3696a819c4..f5e33a68d7 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirMedicationServiceImplTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java index 6b1d9a20f4..d07e0bfa15 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java @@ -937,23 +937,23 @@ public void getPatientIdentifierTypeByIdentifier_shouldReturnNullWhenSystemAndId assertFalse(identifier.hasType()); assertNull(result); } - + @Test public void getPatientIdentifierTypeByIdentifier_shouldReturnNullWhenIdentifierTypeIsNull() { Identifier identifier = new Identifier(); identifier.setType(null); - + PatientIdentifierType result = patientService.getPatientIdentifierTypeByIdentifier(identifier); assertNull(identifier.getSystem()); assertTrue(identifier.getType().isEmpty()); assertNull(result); } - + @Test public void getPatientIdentifierTypeByIdentifier_shouldReturnNullWhenIdentifierTypeTextIsNull() { Identifier identifier = new Identifier(); identifier.setType(new CodeableConcept().setText(null)); - + PatientIdentifierType result = patientService.getPatientIdentifierTypeByIdentifier(identifier); assertNull(identifier.getSystem()); assertTrue(identifier.getType().isEmpty()); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirRelatedPersonServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirRelatedPersonServiceImplTest.java index d3e8c3041d..544fd26fe9 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirRelatedPersonServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirRelatedPersonServiceImplTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java index 640c76165e..78dd6219e6 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java @@ -24,9 +24,9 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; import static org.openmrs.test.OpenmrsMatchers.hasId; +import static org.openmrs.test.OpenmrsMatchers.hasUuid; import java.time.LocalDateTime; import java.time.Month; @@ -49,13 +49,10 @@ import ca.uhn.fhir.rest.param.TokenParam; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.Patient; import org.junit.Before; import org.junit.Test; -import org.openmrs.Obs; -import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; +import org.openmrs.Condition; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirConditionDao; @@ -69,59 +66,55 @@ @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) public class ConditionSearchQueryTest extends BaseModuleContextSensitiveTest { - private static final String OBS_CONDITION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml"; + private static final String CONDITION_UUID = "604953c5-b5c6-4e1e-be95-e37d8f392046"; - private static final int START_INDEX = 0; - - private static final int END_INDEX = 10; + private static final String CONDITION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImplTest_initial_data.xml"; - private static final String PATIENT_IDENTIFIER = "6TS-4"; - - private static final String PATIENT_WRONG_IDENTIFIER = "Wrong Identifier"; - - private static final String PATIENT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; + private static final String PATIENT_UUID = "a7e04421-525f-442f-8138-05b619d16def"; private static final String PATIENT_WRONG_UUID = "c2299800-cca9-11e0-9572-abcdef0c9a66"; - private static final String PATIENT_GIVEN_NAME = "Collet"; + private static final String PATIENT_GIVEN_NAME = "Johnny"; private static final String PATIENT_WRONG_GIVEN_NAME = "Wrong given name"; - private static final String PATIENT_PARTIAL_NAME = "Test"; + private static final String PATIENT_PARTIAL_NAME = "Johnn"; - private static final String PATIENT_FAMILY_NAME = "Chebaskwony"; + private static final String PATIENT_FAMILY_NAME = "Doe"; private static final String PATIENT_WRONG_FAMILY_NAME = "Wrong family name"; private static final String PATIENT_NOT_FOUND_NAME = "Igor"; - private static final String ONSET_DATE_TIME = "2008-07-01T00:00:00"; + private static final String PATIENT_IDENTIFIER = "12345K"; + + private static final String PATIENT_WRONG_IDENTIFIER = "Wrong identifier"; - private static final String ONSET_START_DATE = "2008-05-01T00:00:00"; + private static final String ONSET_DATE_TIME = "2020-03-05T19:00:00"; - private static final String ONSET_END_DATE = "2008-08-01T00:00:00"; + private static final String ONSET_DATE = "2020-03-05 19:00:00"; - private static final String ONSET_DATE = "2008-07-01"; + private static final String ONSET_START_DATE = "2020-03-03T22:00:00"; - private static final String RECORDED_DATE_TIME = "2008-08-18T14:09:35.0"; + private static final String ONSET_END_DATE = "2020-03-08T19:00:00"; - private static final String DATE_CREATED = "2008-08-18T14:09:35.0"; + private static final String RECORDED_DATE_TIME = "2020-03-14T19:32:34"; - private static final String RECORDED_START_DATE = "2008-05-18T14:09:35.0"; + private static final String RECORDED_DATE = "2020-03-14 19:32:34"; - private static final String RECORDED_END_DATE = "2008-10-18T14:09:35.0"; + private static final String RECORDED_START_DATE = "2020-03-12T19:32:34"; - private static final String DATE_VOIDED = "2008-12-18T14:09:35.0"; + private static final String RECORDED_END_DATE = "2020-03-20T19:32:34"; - private static final String RECORDED_DATE = "2008-08-18"; + private static final String STATUS_ACTIVE = "active"; - private static final String EXISTING_OBS_CONDITION_UUID = "86sgf-1f7d-4394-a316-0a458edf28c4"; + private static final String STATUS_INACTIVE = "inactive"; private static final String CODE_SYSTEM_1 = "http://made_up_concepts.info/sct"; - private static final String CODE_VALUE_1 = "C00"; + private static final String CODE_VALUE_1 = "CD41003"; - private static final String CONCEPT_ID_1 = "116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + private static final String CONCEPT_ID_1 = "a09ab2c5-878e-4905-b25d-5784167d0216"; private static final String CODE_SYSTEM_2 = "http://made_up_concepts.info/sct"; @@ -129,30 +122,32 @@ public class ConditionSearchQueryTest extends BaseModuleContextSensitiveTest { private static final String CONCEPT_ID_2 = "c607c80f-1ea9-4da3-bb88-6276ce8868dd"; - @Autowired - private FhirConditionDao dao; + private static final String DATE_CREATED = "2020-03-14"; - @Autowired - private ConditionTranslator translator; + private static final String DATE_VOIDED = "2017-01-12"; + + private static final int START_INDEX = 0; + + private static final int END_INDEX = 10; @Autowired - private SearchQueryInclude searchQueryInclude; + private FhirConditionDao dao; @Autowired - private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; + private ConditionTranslator translator; @Autowired - PatientService patientService; + private SearchQueryInclude searchQueryInclude; @Autowired - ConceptService conceptService; + private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; @Autowired private LocalDateTimeFactory localDateTimeFactory; @Before - public void setup() throws Exception { - executeDataSet(OBS_CONDITION_INITIAL_DATA_XML); + public void setup() { + executeDataSet(CONDITION_INITIAL_DATA_XML); } private IBundleProvider search(SearchParameterMap theParams) { @@ -164,7 +159,7 @@ private List get(IBundleProvider results) { } @Test - public void searchForObsConditions_shouldReturnConditionByPatientIdentifier() { + public void searchForConditions_shouldReturnConditionByPatientIdentifier() { ReferenceParam patientReference = new ReferenceParam(Patient.SP_IDENTIFIER, PATIENT_IDENTIFIER); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addAnd(new ReferenceOrListParam().addOr(patientReference)); @@ -178,13 +173,13 @@ public void searchForObsConditions_shouldReturnConditionByPatientIdentifier() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), endsWith(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientIdentifierOr() { + public void searchForConditions_shouldSearchForConditionsByMultiplePatientIdentifierOr() { ReferenceAndListParam referenceParam = new ReferenceAndListParam(); ReferenceParam patient = new ReferenceParam(); @@ -207,13 +202,13 @@ public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientIde assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), endsWith(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldReturnEmptyListOfConditionsByMultiplePatientIdentifierAnd() { + public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientIdentifierAnd() { ReferenceAndListParam referenceParam = new ReferenceAndListParam(); ReferenceParam patient = new ReferenceParam(); @@ -238,7 +233,7 @@ public void searchForObsConditions_shouldReturnEmptyListOfConditionsByMultiplePa } @Test - public void searchForObsConditions_shouldReturnConditionByPatientUuid() { + public void searchForConditions_shouldReturnConditionByPatientUuid() { ReferenceParam patientReference = new ReferenceParam(null, PATIENT_UUID); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addAnd(new ReferenceOrListParam().addOr(patientReference)); @@ -252,14 +247,14 @@ public void searchForObsConditions_shouldReturnConditionByPatientUuid() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientUuidOr() { + public void searchForConditions_shouldSearchForConditionsByMultiplePatientUuidOr() { ReferenceAndListParam referenceParam = new ReferenceAndListParam(); ReferenceParam patient = new ReferenceParam(); @@ -280,14 +275,14 @@ public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientUui assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldReturnEmptyListOfConditionsByMultiplePatientUuidAnd() { + public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatientUuidAnd() { ReferenceAndListParam referenceParam = new ReferenceAndListParam(); ReferenceParam patient = new ReferenceParam(); @@ -310,7 +305,7 @@ public void searchForObsConditions_shouldReturnEmptyListOfConditionsByMultiplePa } @Test - public void searchForObsConditions_shouldReturnConditionByPatientGivenName() { + public void searchForConditions_shouldReturnConditionByPatientGivenName() { ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, PATIENT_GIVEN_NAME); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addValue(new ReferenceOrListParam().add(patientReference)); @@ -324,15 +319,15 @@ public void searchForObsConditions_shouldReturnConditionByPatientGivenName() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldReturnUniqueConditionsByPatientGivenName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, PATIENT_GIVEN_NAME); + public void searchForConditions_shouldReturnUniqueConditionsByPatientGivenName() { + ReferenceParam patientReference = new ReferenceParam(Patient.SP_GIVEN, "Horatio"); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addValue(new ReferenceOrListParam().add(patientReference)); @@ -344,12 +339,12 @@ public void searchForObsConditions_shouldReturnUniqueConditionsByPatientGivenNam assertThat(results, notNullValue()); assertThat(results.size(), equalTo(2)); - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasId(30), hasId(31))); + List resultSet = dao.getSearchResults(theParams); + assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), hasId(2))); // 6 with repetitions } @Test - public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr() { + public void searchForConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr() { ReferenceAndListParam referenceParam = new ReferenceAndListParam(); ReferenceParam patient = new ReferenceParam(); @@ -371,8 +366,7 @@ public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientGiv assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertEquals(resultList.size(), 2); - + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } @Test @@ -432,15 +426,15 @@ public void searchForConditions_shouldReturnConditionByPatientFamilyName() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID)); } @Test - public void searchForObsConditions_shouldReturnUniqueConditionsByPatientFamilyName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_FAMILY, PATIENT_FAMILY_NAME); + public void searchForConditions_shouldReturnUniqueConditionsByPatientFamilyName() { + ReferenceParam patientReference = new ReferenceParam(Patient.SP_FAMILY, "Hornblower"); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addValue(new ReferenceOrListParam().add(patientReference)); @@ -452,8 +446,9 @@ public void searchForObsConditions_shouldReturnUniqueConditionsByPatientFamilyNa assertThat(results, notNullValue()); assertThat(results.size(), equalTo(2)); - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasId(30), hasId(31))); + List resultSet = dao.getSearchResults(theParams); + assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), + hasUuid("2cc6880e-2c46-11e4-9138-a6c5e4d20fb7"))); // 9 with repetitions } @Test @@ -479,7 +474,7 @@ public void searchForConditions_shouldSearchForConditionsByMultiplePatientFamily assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } @Test @@ -508,7 +503,7 @@ public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatie } @Test - public void searchForObsConditions_shouldReturnConditionByPatientName() { + public void searchForConditions_shouldReturnConditionByPatientName() { ReferenceParam patientReference = new ReferenceParam(Patient.SP_NAME, PATIENT_PARTIAL_NAME); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addValue(new ReferenceOrListParam().add(patientReference)); @@ -522,15 +517,15 @@ public void searchForObsConditions_shouldReturnConditionByPatientName() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID)); - assertThat(resultList.size(), equalTo(2)); } @Test public void searchForConditions_shouldReturnUniqueConditionsByPatientName() { - ReferenceParam patientReference = new ReferenceParam(Patient.SP_NAME, PATIENT_PARTIAL_NAME); + ReferenceParam patientReference = new ReferenceParam(Patient.SP_NAME, "Horatio Hornblower"); ReferenceAndListParam patientList = new ReferenceAndListParam(); patientList.addValue(new ReferenceOrListParam().add(patientReference)); @@ -542,8 +537,9 @@ public void searchForConditions_shouldReturnUniqueConditionsByPatientName() { assertThat(results, notNullValue()); assertThat(results.size(), equalTo(2)); - List resultSet = dao.getSearchResults(theParams); - assertThat(resultSet, containsInAnyOrder(hasId(30), hasId(31))); + List resultSet = dao.getSearchResults(theParams); + assertThat(resultSet, containsInAnyOrder(hasUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"), + hasUuid("2cc6880e-2c46-11e4-9138-a6c5e4d20fb7"))); } @Test @@ -569,7 +565,7 @@ public void searchForConditions_shouldSearchForConditionsByMultiplePatientNameOr assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } @Test @@ -598,11 +594,11 @@ public void searchForConditions_shouldReturnEmptyListOfConditionsByMultiplePatie } @Test - public void searchForObsConditions_shouldReturnConditionByOnsetDate() { + public void searchForConditions_shouldReturnConditionByOnsetDate() { DateRangeParam onsetDate = new DateRangeParam(new DateParam("eq" + ONSET_DATE_TIME)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "obsDatetime", onsetDate); + "onsetDate", onsetDate); IBundleProvider results = search(theParams); @@ -610,10 +606,10 @@ public void searchForObsConditions_shouldReturnConditionByOnsetDate() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), containsString(ONSET_DATE)); - assertThat(resultList.size(), equalTo(2)); } @Test @@ -621,7 +617,7 @@ public void searchForConditions_shouldReturnConditionByOnsetDateRange() { DateRangeParam onsetDate = new DateRangeParam(new DateParam(ONSET_START_DATE), new DateParam(ONSET_END_DATE)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "obsDatetime", onsetDate); + "onsetDate", onsetDate); IBundleProvider results = search(theParams); @@ -629,10 +625,10 @@ public void searchForConditions_shouldReturnConditionByOnsetDateRange() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat( ((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), containsString(ONSET_DATE)); - assertThat(resultList.size(), equalTo(2)); } @Test @@ -640,7 +636,7 @@ public void searchForConditions_shouldReturnConditionByUnboundedOnsetDate() { DateRangeParam onsetDate = new DateRangeParam(new DateParam("gt" + ONSET_START_DATE)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, - "obsDatetime", onsetDate); + "onsetDate", onsetDate); IBundleProvider results = search(theParams); @@ -648,7 +644,107 @@ public void searchForConditions_shouldReturnConditionByUnboundedOnsetDate() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); + } + + @Test + public void searchForConditions_shouldReturnConditionByOnsetAgeLessThanHour() { + QuantityOrListParam orList = new QuantityOrListParam(); + orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "h")); + QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); + + when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, + onsetAgeParam); + + IBundleProvider results = search(theParams); + + List resultList = get(results); + + assertThat(results, notNullValue()); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); + assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), + equalTo(CONDITION_UUID)); + } + + @Test + public void searchForConditions_shouldReturnConditionByOnsetAgeEqualHour() { + QuantityOrListParam orList = new QuantityOrListParam(); + orList.addOr(new QuantityParam(ParamPrefixEnum.EQUAL, 3, "", "h")); + QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); + + when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, + onsetAgeParam); + + IBundleProvider results = search(theParams); + + List resultList = get(results); + + assertThat(results, notNullValue()); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); + assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), + equalTo(CONDITION_UUID)); + } + + @Test + public void searchForConditions_shouldReturnConditionByOnsetAgeIntervalDay() { + QuantityOrListParam orListLower = new QuantityOrListParam(); + QuantityOrListParam orListUpper = new QuantityOrListParam(); + orListLower.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 11, "", "d")); + orListUpper.addOr(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 8, "", "d")); + QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orListLower).addAnd(orListUpper); + + when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 22, 22, 0, 0)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, + onsetAgeParam); + + IBundleProvider results = search(theParams); + + List resultList = get(results); + assertThat(results, notNullValue()); + assertThat(resultList, hasSize(1)); + assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), + equalTo(CONDITION_UUID)); + } + + @Test + public void searchForConditions_shouldReturnConditionByOnsetAgeOrWeekMonthYear() { + QuantityOrListParam orList = new QuantityOrListParam(); + orList.addOr(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 4, "", "a")); + orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 3, "", "mo")); + orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 2, "", "wk")); + QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); + + when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, + onsetAgeParam); + + IBundleProvider results = search(theParams); + + List resultList = get(results); + + assertThat(results, notNullValue()); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); + } + + @Test(expected = IllegalArgumentException.class) + public void searchForConditions_shouldReturnConditionByOnsetAgeExceptionForWrongUnit() { + QuantityOrListParam orList = new QuantityOrListParam(); + orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "WRONG_UNIT")); + QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); + + when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, + onsetAgeParam); + + IBundleProvider results = search(theParams); + get(results); } @Test @@ -664,9 +760,9 @@ public void searchForConditions_shouldReturnConditionByRecordedDate() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getRecordedDate().toString(), containsString(RECORDED_DATE)); - assertThat(resultList.size(), equalTo(2)); } @Test @@ -682,14 +778,71 @@ public void searchForConditions_shouldReturnConditionByRecordedDateRange() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getRecordedDate().toString(), containsString(RECORDED_DATE)); - assertThat(resultList.size(), equalTo(2)); + } + + @Test + public void searchForConditions_shouldReturnConditionByUnboundedRecordedDate() { + DateRangeParam onsetDate = new DateRangeParam(new DateParam("gt" + RECORDED_START_DATE)); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, + "dateCreated", onsetDate); + + IBundleProvider results = search(theParams); + + List resultList = get(results); + + assertThat(results, notNullValue()); + assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); + } + + @Test + public void searchForConditions_shouldReturnConditionByClinicalStatusActive() { + TokenAndListParam listParam = new TokenAndListParam(); + listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_ACTIVE))); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, + listParam); + + IBundleProvider results = search(theParams); + assertThat(results, notNullValue()); + assertThat(results.size(), greaterThanOrEqualTo(1)); } @Test - public void searchForObsConditions_shouldReturnConditionByCode() { + public void searchForConditions_shouldReturnConditionByClinicalStatusInactive() { + TokenAndListParam listParam = new TokenAndListParam(); + listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_INACTIVE))); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, + listParam); + + IBundleProvider results = search(theParams); + + assertThat(results, notNullValue()); + assertThat(results.size(), greaterThanOrEqualTo(1)); + } + + @Test + public void searchForConditions_shouldReturnConditionByClinicalStatusAll() { + TokenAndListParam listParam = new TokenAndListParam(); + listParam.addValue(new TokenOrListParam().add(new TokenParam(STATUS_ACTIVE)).add(new TokenParam(STATUS_INACTIVE))); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CONDITION_CLINICAL_STATUS_HANDLER, + listParam); + + IBundleProvider results = search(theParams); + + assertThat(results, notNullValue()); + assertThat(results.size(), equalTo(5)); + } + + @Test + public void searchForConditions_shouldReturnConditionByCode() { TokenAndListParam listParam = new TokenAndListParam(); listParam.addValue(new TokenOrListParam().add(new TokenParam(CODE_SYSTEM_1, CODE_VALUE_1))); @@ -701,15 +854,16 @@ public void searchForObsConditions_shouldReturnConditionByCode() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getCode().getCodingFirstRep().getCode(), equalTo(CONCEPT_ID_1)); - assertThat(resultList.size(), equalTo(2)); } @Test - public void searchForObsConditions_shouldReturnMultipleConditionsByCodeList() { + public void searchForConditions_shouldReturnMultipleConditionsByCodeList() { TokenAndListParam listParam = new TokenAndListParam(); + // Adding codes concept_id=5497 and concept_id=5089. listParam.addValue(new TokenOrListParam().add(new TokenParam(CODE_SYSTEM_1, CODE_VALUE_1)) .add(new TokenParam(CODE_SYSTEM_2, CODE_VALUE_2))); @@ -721,11 +875,11 @@ public void searchForObsConditions_shouldReturnMultipleConditionsByCodeList() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } @Test - public void searchForObsConditions_shouldReturnConditionByCodeAndNoSystem() { + public void searchForConditions_shouldReturnConditionByCodeAndNoSystem() { TokenAndListParam listParam = new TokenAndListParam(); listParam.addValue(new TokenOrListParam().add(new TokenParam(CONCEPT_ID_1))); @@ -737,13 +891,13 @@ public void searchForObsConditions_shouldReturnConditionByCodeAndNoSystem() { assertThat(results, notNullValue()); assertThat(resultList, not(empty())); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getCode().getCodingFirstRep().getCode(), equalTo(CONCEPT_ID_1)); - assertThat(resultList.size(), equalTo(2)); } @Test - public void searchForObsConditions_shouldReturnMultipleConditionsByCodeListAndNoSystem() { + public void searchForConditions_shouldReturnMultipleConditionsByCodeListAndNoSystem() { TokenAndListParam listParam = new TokenAndListParam(); listParam.addValue(new TokenOrListParam().add(new TokenParam(CONCEPT_ID_1)).add(new TokenParam(CONCEPT_ID_2))); @@ -755,12 +909,12 @@ public void searchForObsConditions_shouldReturnMultipleConditionsByCodeListAndNo assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); } @Test - public void searchForObsConditions_shouldSearchForConditionsByUuid() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID)); + public void searchForConditions_shouldSearchForConditionsByUuid() { + TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid); @@ -773,11 +927,11 @@ public void searchForObsConditions_shouldSearchForConditionsByUuid() { assertThat(resultList, not(empty())); assertThat(resultList, hasSize(equalTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(EXISTING_OBS_CONDITION_UUID)); + equalTo(CONDITION_UUID)); } @Test - public void searchForObsConditions_shouldSearchForConditionsByLastUpdatedDateCreated() { + public void searchForConditions_shouldSearchForConditionsByLastUpdatedDateCreated() { DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, @@ -789,12 +943,12 @@ public void searchForObsConditions_shouldSearchForConditionsByLastUpdatedDateCre assertThat(results, notNullValue()); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(2))); + assertThat(resultList, hasSize(equalTo(1))); } @Test - public void searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID)); + public void searchForConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated() { + TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED); SearchParameterMap theParams = new SearchParameterMap() @@ -809,12 +963,12 @@ public void searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLas assertThat(resultList, not(empty())); assertThat(resultList, hasSize(equalTo(1))); assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(EXISTING_OBS_CONDITION_UUID)); + equalTo(CONDITION_UUID)); } @Test - public void searchForObsConditions_shouldReturnEmptyListByMismatchingUuidAndLastUpdated() { - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID)); + public void searchForConditions_shouldReturnEmptyListByMismatchingUuidAndLastUpdated() { + TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_VOIDED).setLowerBound(DATE_VOIDED); SearchParameterMap theParams = new SearchParameterMap() @@ -830,12 +984,12 @@ public void searchForObsConditions_shouldReturnEmptyListByMismatchingUuidAndLast } @Test - public void searchForObsConditions_shouldAddNotNullPatientToReturnedResults() { + public void searchForConditions_shouldAddNotNullPatientToReturnedResults() { HashSet includes = new HashSet<>(); Include include = new Include("Condition:patient"); includes.add(include); - TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID)); + TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(CONDITION_UUID)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes) .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid); @@ -852,25 +1006,4 @@ public void searchForObsConditions_shouldAddNotNullPatientToReturnedResults() { assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), hasProperty("id", Matchers.equalTo(returnedCondition.getSubject().getReferenceElement().getIdPart()))))); } - - @Test - public void searchForConditions_shouldReturnConditionByOnsetAgeEqualHour() { - QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.EQUAL, 2, "", "h")); - QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2008, Month.JULY, 1, 3, 0, 0)); - - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, - onsetAgeParam); - - IBundleProvider results = search(theParams); - - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, hasSize(greaterThanOrEqualTo(1))); - assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), - equalTo(EXISTING_OBS_CONDITION_UUID)); - } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java index 7a22302e05..6f79e60069 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java @@ -73,7 +73,9 @@ @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) public class MedicationRequestSearchQueryTest extends BaseModuleContextSensitiveTest { - private static final String MEDICATION_REQUEST_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml"; + private static final String MEDICATION_REQUEST_DATA_XMLS = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml"; + + private static final String DATA_XMLS = "org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImpl_2_2Test_initial_data.xml"; private static final String MEDICATION_REQUEST_UUID = "6d0ae116-707a-4629-9850-f15206e63ab0"; @@ -81,6 +83,8 @@ public class MedicationRequestSearchQueryTest extends BaseModuleContextSensitive private static final String NON_ACTIVE_ORDER_UUID = "dfca4077-493c-496b-8312-856ee5d1cc26"; + private static final String DRUG_ORDER_WITH_FULFILLER_STATUS_COMPLETED_UUID = "ac463525-9b1a-44f2-99f1-0d6a10d5b60d"; + private static final String PATIENT_UUID = "86526ed5-3c11-11de-a0ba-001e3766667a"; private static final String PATIENT_GIVEN_NAME = "Moody"; @@ -145,7 +149,7 @@ public class MedicationRequestSearchQueryTest extends BaseModuleContextSensitive @Before public void setup() throws Exception { - executeDataSet(MEDICATION_REQUEST_DATA_XML); + executeDataSet(MEDICATION_REQUEST_DATA_XMLS); } @Test @@ -1278,4 +1282,28 @@ private List get(IBundleProvider results) { .map(it -> (MedicationRequest) it).collect(Collectors.toList()); } + @Test + public void searchForMedicationRequests_shouldSearchForMedicationRequestsByFulfillerStatus() { + executeDataSet(DATA_XMLS); + TokenAndListParam fulfillerStatus = new TokenAndListParam().addAnd(new TokenParam("received")); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, + "fulfillerStatus", fulfillerStatus); + IBundleProvider results = search(theParams); + + assertThat(results, notNullValue()); + List resultList = get(results); + assertThat(resultList, hasSize(equalTo(4))); + + // there is one tests in the test data set with "completed" fulfiller status + fulfillerStatus = new TokenAndListParam().addAnd(new TokenParam("completed")); + theParams = new SearchParameterMap().addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, "fulfillerStatus", + fulfillerStatus); + results = search(theParams); + + assertThat(results, notNullValue()); + resultList = get(results); + assertThat(resultList, hasSize(equalTo(1))); + assertThat(resultList.get(0).getId(), equalTo(DRUG_ORDER_WITH_FULFILLER_STATUS_COMPLETED_UUID)); + } + } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java index e5effbc4ef..eb88447973 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java @@ -158,6 +158,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptId() IBundleProvider results = search(theParams); assertThat(results, notNullValue()); + assertThat(results.size(), equalTo(4)); List resultList = get(results); diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2Test.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImplTest.java similarity index 95% rename from api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2Test.java rename to api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImplTest.java index 0cd5752f10..b438f77a54 100644 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImpl_2_2Test.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionClinicalStatusTranslatorImplTest.java @@ -21,17 +21,17 @@ import org.openmrs.ConditionClinicalStatus; import org.openmrs.module.fhir2.FhirConstants; -public class ConditionClinicalStatusTranslatorImpl_2_2Test { +public class ConditionClinicalStatusTranslatorImplTest { private static final String ACTIVE = "active"; private static final String INACTIVE = "inactive"; - private ConditionClinicalStatusTranslatorImpl_2_2 clinicalStatusTranslator; + private ConditionClinicalStatusTranslatorImpl clinicalStatusTranslator; @Before public void setUp() { - this.clinicalStatusTranslator = new ConditionClinicalStatusTranslatorImpl_2_2(); + this.clinicalStatusTranslator = new ConditionClinicalStatusTranslatorImpl(); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImplTest.java index e2623c2c04..a7b836e44c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionTranslatorImplTest.java @@ -9,35 +9,40 @@ */ package org.openmrs.module.fhir2.api.translators.impl; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.exparity.hamcrest.date.DateMatchers.sameDay; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Mockito.when; import java.util.Collections; import java.util.Date; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.exparity.hamcrest.date.DateMatchers; import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.DateTimeType; +import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Reference; +import org.hl7.fhir.r4.model.StringType; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.CodedOrFreeText; import org.openmrs.Concept; -import org.openmrs.Obs; +import org.openmrs.ConditionClinicalStatus; +import org.openmrs.ConditionVerificationStatus; import org.openmrs.Patient; import org.openmrs.User; -import org.openmrs.api.ConceptService; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.translators.ConceptTranslator; +import org.openmrs.module.fhir2.api.translators.ConditionClinicalStatusTranslator; +import org.openmrs.module.fhir2.api.translators.ConditionVerificationStatusTranslator; import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; @@ -46,16 +51,22 @@ public class ConditionTranslatorImplTest { private static final String CONDITION_UUID = "36aa91ad-66f3-455b-b28a-71beb6ca3195"; - private static final Integer CONDITION_ID = 1284; - private static final String PATIENT_UUID = "fc8b217b-2ed4-4dde-b9f7-a5334347e7ca"; private static final String PATIENT_REF = "Patient/" + PATIENT_UUID; + private static final String ACTIVE = "active"; + private static final String SYSTEM = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; private static final Integer CODE = 102309; + private static final Integer CONDITION_NON_CODED = 5622; + + private static final String CONDITION_NON_CODED_TEXT = "condition non coded"; + + private static final String CONDITION_NON_CODED_VALUE = "Other"; + private static final String CONCEPT_UUID = "31d754f5-3e9e-4ca3-805c-87f97a1f5e4b"; private static final String PRACTITIONER_UUID = "2ffb1a5f-bcd3-4243-8f40-78edc2642789"; @@ -65,8 +76,15 @@ public class ConditionTranslatorImplTest { @Mock private PatientReferenceTranslator patientReferenceTranslator; + private static final String CONFIRMED = "confirmed"; + + private static final String PROVISIONAL = "provisional"; + + @Mock + private ConditionClinicalStatusTranslator clinicalStatusTranslator; + @Mock - ConceptService conceptService; + private ConditionVerificationStatusTranslator verificationStatusTranslator; @Mock private ConceptTranslator conceptTranslator; @@ -78,21 +96,20 @@ public class ConditionTranslatorImplTest { private Condition fhirCondition; - private Obs openmrsCondition; + private org.openmrs.Condition openmrsCondition; private Patient patient; private Reference patientRef; - private Concept concept; - @Before public void setup() { conditionTranslator = new ConditionTranslatorImpl(); conditionTranslator.setPatientReferenceTranslator(patientReferenceTranslator); + conditionTranslator.setClinicalStatusTranslator(clinicalStatusTranslator); + conditionTranslator.setVerificationStatusTranslator(verificationStatusTranslator); conditionTranslator.setConceptTranslator(conceptTranslator); conditionTranslator.setPractitionerReferenceTranslator(creatorReferenceTranslator); - conditionTranslator.setConceptService(conceptService); patient = new Patient(); patient.setUuid(PATIENT_UUID); @@ -100,19 +117,17 @@ public void setup() { patientRef = new Reference(); patientRef.setReference(PATIENT_REF); - concept = new Concept(); - concept.setUuid(CONDITION_UUID); - concept.setConceptId(CONDITION_ID); - - Concept valueCoded = new Concept(); + Concept concept = new Concept(); concept.setUuid(CONDITION_UUID); concept.setConceptId(CODE); - openmrsCondition = new Obs(); + CodedOrFreeText conditionCoded = new CodedOrFreeText(); + conditionCoded.setCoded(concept); + + openmrsCondition = new org.openmrs.Condition(); openmrsCondition.setUuid(CONDITION_UUID); - openmrsCondition.setPerson(patient); - openmrsCondition.setConcept(concept); - openmrsCondition.setValueCoded(valueCoded); + openmrsCondition.setPatient(patient); + openmrsCondition.setCondition(conditionCoded); fhirCondition = new Condition(); fhirCondition.setId(CONDITION_UUID); @@ -128,10 +143,9 @@ public void shouldTranslateConditionIdToFhirType() { @Test public void shouldTranslateConditionUuidToOpenMrsType() { - when(conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)).thenReturn(concept); - Obs obsCondition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(obsCondition, notNullValue()); - assertThat(obsCondition.getUuid(), equalTo(CONDITION_UUID)); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getUuid(), equalTo(CONDITION_UUID)); } @Test(expected = NullPointerException.class) @@ -139,23 +153,13 @@ public void toFhirResource_shouldThrowExceptionIfConditionToTranslateIsNull() { conditionTranslator.toFhirResource(null); } - @Test(expected = InternalErrorException.class) - public void toFhirOpenmrsType_shouldThrowExceptionIfConceptProblemListIsNotFound() { - when(patientReferenceTranslator.toOpenmrsType(patientRef)).thenReturn(patient); - Obs obsCondition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(obsCondition, notNullValue()); - assertThat(obsCondition.getPerson(), notNullValue()); - assertThat(obsCondition.getPerson().getUuid(), equalTo(PATIENT_UUID)); - } - @Test public void shouldTranslateConditionSubjectToOpenMrsType() { - when(conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)).thenReturn(concept); when(patientReferenceTranslator.toOpenmrsType(patientRef)).thenReturn(patient); - Obs obsCondition = conditionTranslator.toOpenmrsType(fhirCondition); - assertThat(obsCondition, notNullValue()); - assertThat(obsCondition.getPerson(), notNullValue()); - assertThat(obsCondition.getPerson().getUuid(), equalTo(PATIENT_UUID)); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getPatient(), notNullValue()); + assertThat(condition.getPatient().getUuid(), equalTo(PATIENT_UUID)); } @Test @@ -168,25 +172,104 @@ public void shouldTranslateConditionPatientToFhirType() { assertThat(condition.getSubject().getReference(), equalTo(PATIENT_REF)); } + @Test + public void shouldTranslateConditionClinicalStatusToOpenMrsType() { + CodeableConcept codeableConcept = new CodeableConcept(); + codeableConcept.addCoding(new Coding().setCode(ACTIVE).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); + fhirCondition.setClinicalStatus(codeableConcept); + when(clinicalStatusTranslator.toOpenmrsType(codeableConcept)).thenReturn(ConditionClinicalStatus.ACTIVE); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + + assertThat(condition, notNullValue()); + assertThat(condition.getClinicalStatus(), notNullValue()); + assertThat(condition.getClinicalStatus(), equalTo(ConditionClinicalStatus.ACTIVE)); + + } + + @Test + public void shouldTranslateConditionClinicalStatusToFhirType() { + CodeableConcept codeableConcept = new CodeableConcept(); + codeableConcept.addCoding(new Coding().setCode(ACTIVE).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); + openmrsCondition.setClinicalStatus(ConditionClinicalStatus.ACTIVE); + when(clinicalStatusTranslator.toFhirResource(ConditionClinicalStatus.ACTIVE)).thenReturn(codeableConcept); + + Condition condition = conditionTranslator.toFhirResource(openmrsCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getClinicalStatus(), notNullValue()); + assertThat(condition.getClinicalStatus(), equalTo(codeableConcept)); + } + + @Test + public void shouldTranslateConditionVerificationStatusToFhirType() { + CodeableConcept codeableConcept = new CodeableConcept(); + codeableConcept.addCoding(new Coding().setCode(CONFIRMED).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); + openmrsCondition.setVerificationStatus(ConditionVerificationStatus.CONFIRMED); + when(verificationStatusTranslator.toFhirResource(ConditionVerificationStatus.CONFIRMED)).thenReturn(codeableConcept); + Condition condition = conditionTranslator.toFhirResource(openmrsCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getVerificationStatus(), equalTo(codeableConcept)); + assertThat(condition.getVerificationStatus().getCodingFirstRep().getCode().toLowerCase(), equalTo(CONFIRMED)); + } + + @Test + public void shouldTranslateConditionVerificationStatusToOpenMrsType() { + CodeableConcept codeableConcept = new CodeableConcept(); + codeableConcept.addCoding(new Coding().setCode(PROVISIONAL).setSystem(FhirConstants.OPENMRS_FHIR_PREFIX)); + fhirCondition.setVerificationStatus(codeableConcept); + when(verificationStatusTranslator.toOpenmrsType(codeableConcept)) + .thenReturn(ConditionVerificationStatus.PROVISIONAL); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getVerificationStatus(), equalTo(ConditionVerificationStatus.PROVISIONAL)); + } + @Test public void shouldTranslateOpenMrsConditionOnsetDateToFhirType() { - openmrsCondition.setObsDatetime(new Date()); + openmrsCondition.setOnsetDate(new Date()); + org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); + assertThat(condition, notNullValue()); - assertThat(condition.getOnsetDateTimeType().getValue(), notNullValue()); - assertThat(condition.getOnsetDateTimeType().getValue(), DateMatchers.sameDay(new Date())); + assertThat(condition.hasOnsetDateTimeType(), is(true)); + assertThat(condition.getOnsetDateTimeType().getValue(), sameDay(new Date())); } @Test public void shouldTranslateFhirConditionOnsetToOpenMrsOnsetDate() { - when(conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)).thenReturn(concept); DateTimeType theDateTime = new DateTimeType(); theDateTime.setValue(new Date()); fhirCondition.setOnset(theDateTime); - Obs condition = conditionTranslator.toOpenmrsType(fhirCondition); + + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + + assertThat(condition, notNullValue()); + assertThat(condition.getOnsetDate(), notNullValue()); + assertThat(condition.getOnsetDate(), sameDay(new Date())); + } + + @Test + public void shouldTranslateOpenMrsConditionEndDateToFhirType() { + openmrsCondition.setEndDate(new Date()); + + org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); + assertThat(condition, notNullValue()); - assertThat(condition.getObsDatetime(), notNullValue()); - assertThat(condition.getObsDatetime(), DateMatchers.sameDay(new Date())); + assertThat(condition.hasAbatementDateTimeType(), is(true)); + assertThat(condition.getAbatementDateTimeType().getValue(), notNullValue()); + assertThat(condition.getAbatementDateTimeType().getValue(), sameDay(new Date())); + } + + @Test + public void shouldTranslateFhirConditionAbatementDateToOpenMrsEndDate() { + DateTimeType theDateTime = new DateTimeType(); + theDateTime.setValue(new Date()); + fhirCondition.setAbatement(theDateTime); + + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + + assertThat(condition, notNullValue()); + assertThat(condition.getEndDate(), notNullValue()); + assertThat(condition.getEndDate(), sameDay(new Date())); } @Test @@ -200,12 +283,11 @@ public void shouldTranslateConditionCodeToOpenMrsConcept() { Concept concept = new Concept(); concept.setUuid(CONCEPT_UUID); concept.setConceptId(CODE); - when(conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)).thenReturn(concept); when(conceptTranslator.toOpenmrsType(codeableConcept)).thenReturn(concept); - Obs condition = conditionTranslator.toOpenmrsType(fhirCondition); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); assertThat(condition, notNullValue()); - assertThat(condition.getValueCoded(), notNullValue()); - assertThat(condition.getValueCoded().getConceptId(), equalTo(CODE)); + assertThat(condition.getCondition(), notNullValue()); + assertThat(condition.getCondition().getCoded().getConceptId(), equalTo(CODE)); } @Test @@ -218,7 +300,9 @@ public void shouldTranslateConditionConceptToFhirType() { coding.setCode(CODE.toString()); coding.setSystem(SYSTEM); codeableConcept.addCoding(coding); - openmrsCondition.setValueCoded(concept); + CodedOrFreeText conceptCodeOrFreeText = new CodedOrFreeText(); + conceptCodeOrFreeText.setCoded(concept); + openmrsCondition.setCondition(conceptCodeOrFreeText); when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept); org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); assertThat(condition, notNullValue()); @@ -228,13 +312,61 @@ public void shouldTranslateConditionConceptToFhirType() { assertThat(condition.getCode().getCoding().get(0).getSystem(), equalTo(SYSTEM)); } + @Test + public void shouldTranslateConditionNonCodedToOpenMrsType() { + CodeableConcept codeableConcept = new CodeableConcept(); + Coding coding = new Coding(); + coding.setCode(String.valueOf(CONDITION_NON_CODED)); + coding.setDisplay(CONDITION_NON_CODED_VALUE); + codeableConcept.addCoding(coding); + Concept concept = new Concept(); + concept.setConceptId(CONDITION_NON_CODED); + fhirCondition.setCode(codeableConcept); + fhirCondition.addExtension(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION, + new StringType(CONDITION_NON_CODED_TEXT)); + when(conceptTranslator.toOpenmrsType(codeableConcept)).thenReturn(concept); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getCondition().getCoded(), equalTo(concept)); + assertThat(condition.getCondition().getNonCoded(), notNullValue()); + assertThat(condition.getCondition().getNonCoded(), equalTo(CONDITION_NON_CODED_TEXT)); + } + + @Test + public void shouldTranslateConditionNonCodedToFhirType() { + CodeableConcept codeableConcept = new CodeableConcept(); + Coding coding = new Coding(); + coding.setCode(String.valueOf(CONDITION_NON_CODED)); + coding.setDisplay(CONDITION_NON_CODED_VALUE); + codeableConcept.addCoding(coding); + + Concept concept = new Concept(); + concept.setConceptId(CONDITION_NON_CODED); + CodedOrFreeText conditionNonCoded = new CodedOrFreeText(); + conditionNonCoded.setCoded(concept); + conditionNonCoded.setNonCoded(CONDITION_NON_CODED_TEXT); + openmrsCondition.setCondition(conditionNonCoded); + + when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept); + org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); + assertThat(condition, notNullValue()); + assertThat(condition.getCode(), notNullValue()); + assertThat(condition.getCode().getCoding(), not(Collections.emptyList())); + assertThat(condition.getCode().getCoding().get(0).getCode(), equalTo(CONDITION_NON_CODED.toString())); + assertThat(condition.getCode().getCoding().get(0).getDisplay(), equalTo(CONDITION_NON_CODED_VALUE)); + + Extension extension = condition.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_NON_CODED_CONDITION); + assertThat(extension, notNullValue()); + assertThat(extension.getValue().toString(), equalTo(CONDITION_NON_CODED_TEXT)); + } + @Test public void shouldTranslateConditionDateCreatedToRecordedDateFhirType() { openmrsCondition.setDateCreated(new Date()); org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition); assertThat(condition, notNullValue()); assertThat(condition.getRecordedDate(), notNullValue()); - assertThat(condition.getRecordedDate(), DateMatchers.sameDay(new Date())); + assertThat(condition.getRecordedDate(), sameDay(new Date())); } @Test @@ -244,9 +376,8 @@ public void shouldTranslateConditionRecorderToOpenmrsUser() { fhirCondition.setRecorder(userRef); User user = new User(); user.setUuid(PRACTITIONER_UUID); - when(conceptService.getConceptByUuid(FhirConstants.CONDITION_OBSERVATION_CONCEPT_UUID)).thenReturn(concept); when(creatorReferenceTranslator.toOpenmrsType(userRef)).thenReturn(user); - Obs condition = conditionTranslator.toOpenmrsType(fhirCondition); + org.openmrs.Condition condition = conditionTranslator.toOpenmrsType(fhirCondition); assertThat(condition, notNullValue()); assertThat(condition.getCreator(), notNullValue()); assertThat(condition.getCreator().getUuid(), equalTo(PRACTITIONER_UUID)); @@ -268,10 +399,10 @@ public void shouldTranslateConditionCreatorToRecorderFhirType() { @Test public void shouldTranslateOpenMrsDateChangedToLastUpdatedDate() { - org.openmrs.Obs obsCondition = new org.openmrs.Obs(); - obsCondition.setDateChanged(new Date()); + org.openmrs.Condition condition = new org.openmrs.Condition(); + condition.setDateChanged(new Date()); - org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(obsCondition); + org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(condition); assertThat(result, Matchers.notNullValue()); assertThat(result.getMeta().getLastUpdated(), Matchers.notNullValue()); @@ -279,10 +410,10 @@ public void shouldTranslateOpenMrsDateChangedToLastUpdatedDate() { @Test public void shouldTranslateOpenMrsDateChangedToVersionId() { - org.openmrs.Obs obsCondition = new org.openmrs.Obs(); - obsCondition.setDateChanged(new Date()); + org.openmrs.Condition condition = new org.openmrs.Condition(); + condition.setDateChanged(new Date()); - org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(obsCondition); + org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(condition); assertThat(result, Matchers.notNullValue()); assertThat(result.getMeta().getVersionId(), Matchers.notNullValue()); diff --git a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2Test.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImplTest.java similarity index 95% rename from api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2Test.java rename to api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImplTest.java index 65a2d080e6..84ca349ac0 100644 --- a/api-2.2/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImpl_2_2Test.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ConditionVerificationStatusTranslatorImplTest.java @@ -22,7 +22,7 @@ import org.openmrs.ConditionVerificationStatus; import org.openmrs.module.fhir2.FhirConstants; -public class ConditionVerificationStatusTranslatorImpl_2_2Test { +public class ConditionVerificationStatusTranslatorImplTest { private static final String FHIR_CONFIRMED = "confirmed"; @@ -30,11 +30,11 @@ public class ConditionVerificationStatusTranslatorImpl_2_2Test { private static final String FHIR_ENTERED_IN_ERROR = "entered-in-error"; - private ConditionVerificationStatusTranslatorImpl_2_2 verificationStatusTranslator; + private ConditionVerificationStatusTranslatorImpl verificationStatusTranslator; @Before public void setup() { - verificationStatusTranslator = new ConditionVerificationStatusTranslatorImpl_2_2(); + verificationStatusTranslator = new ConditionVerificationStatusTranslatorImpl(); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImplTest.java index 2e1f6520fa..4a13b6f8ca 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestStatusTranslatorImplTest.java @@ -21,12 +21,9 @@ import org.hl7.fhir.r4.model.MedicationRequest; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.DrugOrder; import org.openmrs.Order; -@RunWith(MockitoJUnitRunner.class) public class MedicationRequestStatusTranslatorImplTest { private static final String DRUG_ORDER_UUID = "44fdc8ad-fe4d-499b-93a8-8a991c1d477e"; @@ -79,4 +76,13 @@ public void toFhirResource_shouldTranslateVoidedOrderToCancelled() { assertThat(status, notNullValue()); assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.CANCELLED)); } + + @Test + public void toFhirResource_shouldTranslatedOrderWithFulfillerStatusCompletedToCompleted() { + drugOrder.setFulfillerStatus(Order.FulfillerStatus.COMPLETED); + MedicationRequest.MedicationRequestStatus status = statusTranslator.toFhirResource(drugOrder); + assertThat(status, notNullValue()); + assertThat(status, equalTo(MedicationRequest.MedicationRequestStatus.COMPLETED)); + } + } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java index 41dcd48c82..f998a32b72 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java @@ -18,6 +18,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; import java.lang.reflect.Field; import java.util.Date; @@ -26,9 +27,11 @@ import org.exparity.hamcrest.date.DateMatchers; import org.hl7.fhir.r4.model.Annotation; import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Dosage; +import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.MedicationRequest; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; @@ -142,10 +145,10 @@ public void setup() { medicationRequestTranslator.setPractitionerReferenceTranslator(providerPractitionerReferenceTranslator); medicationRequestTranslator.setMedicationRequestPriorityTranslator(medicationRequestPriorityTranslator); medicationRequestTranslator.setMedicationReferenceTranslator(medicationReferenceTranslator); - medicationRequestTranslator.setConceptTranslator(conceptTranslator); - medicationRequestTranslator.setDosageTranslator(dosageTranslator); medicationRequestTranslator.setEncounterReferenceTranslator(encounterReferenceTranslator); medicationRequestTranslator.setPatientReferenceTranslator(patientReferenceTranslator); + medicationRequestTranslator.setConceptTranslator(conceptTranslator); + medicationRequestTranslator.setDosageTranslator(dosageTranslator); medicationRequestTranslator.setOrderIdentifierTranslator(new OrderIdentifierTranslatorImpl()); medicationRequestTranslator .setMedicationRequestDispenseRequestComponentTranslator(dispenseRequestComponentTranslator); @@ -659,6 +662,49 @@ public void toFhirResource_shouldTranslateOpenMrsDateChangedToVersionId() { assertThat(medicationRequest.getMeta().getVersionId(), notNullValue()); } + @Test + public void toFhirResource_shouldTranslateToFulfillerStatusExtenstion() { + DrugOrder drugOrder = new DrugOrder(); + drugOrder.setFulfillerStatus(Order.FulfillerStatus.COMPLETED); + MedicationRequest medicationRequest = medicationRequestTranslator.toFhirResource(drugOrder); + assertThat(medicationRequest, notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + equalTo("COMPLETED")); + } + + @Test + public void toOpenmrsType_shouldTranslateFulfillerStatusExtension() { + MedicationRequest medicationRequest = new MedicationRequest(); + + Extension extension = new Extension(); + extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); + extension.setValue(new CodeType("COMPLETED")); + + medicationRequest.addExtension(extension); + + DrugOrder drugOrder = medicationRequestTranslator.toOpenmrsType(medicationRequest); + assertThat(drugOrder, notNullValue()); + assertThat(drugOrder.getFulfillerStatus(), equalTo(Order.FulfillerStatus.COMPLETED)); + + } + + @Test + public void toOpenmrsType_shouldTranslateNullFulfillerStatusExtension() { + MedicationRequest medicationRequest = new MedicationRequest(); + + Extension extension = new Extension(); + extension.setUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS); + extension.setValue(new CodeType(null)); + + medicationRequest.addExtension(extension); + + DrugOrder drugOrder = medicationRequestTranslator.toOpenmrsType(medicationRequest); + assertThat(drugOrder, notNullValue()); + assertThat(drugOrder.getFulfillerStatus(), equalTo(null)); + + } + @SneakyThrows private void setOrderNumberByReflection(DrugOrder order, String orderNumber) { Class clazz = order.getClass(); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImplTest.java index cbccda3d97..92b15b0ef0 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationInterpretationTranslatorImplTest.java @@ -9,41 +9,385 @@ */ package org.openmrs.module.fhir2.api.translators.impl; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; - +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Coding; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.Obs; +import org.openmrs.module.fhir2.FhirConstants; @RunWith(MockitoJUnitRunner.class) public class ObservationInterpretationTranslatorImplTest { - @Mock - private ObservationInterpretationTranslatorImpl interpretationTranslator; + private ObservationInterpretationTranslatorImpl observationInterpretationTranslator; + + private Obs obs; + + private CodeableConcept interpretation; @Before public void setUp() { - interpretationTranslator = new ObservationInterpretationTranslatorImpl(); + observationInterpretationTranslator = new ObservationInterpretationTranslatorImpl(); + obs = new Obs(); + interpretation = new CodeableConcept(); + } + + @Test + public void toFhirResource_shouldTranslateNormalInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.NORMAL); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("N")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Normal")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Normal")); + } + + @Test + public void toFhirResource_shouldTranslateAbnormalInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.ABNORMAL); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("A")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Abnormal")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Abnormal")); + } + + @Test + public void toFhirResource_shouldTranslateCriticallyAbnormalInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.CRITICALLY_ABNORMAL); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("AA")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Critically Abnormal")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Critically Abnormal")); + } + + @Test + public void toFhirResource_shouldTranslateCriticallyHighInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.CRITICALLY_HIGH); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("HH")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Critically High")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Critically High")); + } + + @Test + public void toFhirResource_shouldTranslateCriticallyLowInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.CRITICALLY_LOW); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("LL")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Critically Low")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Critically Low")); + } + + @Test + public void toFhirResource_shouldTranslateHighInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.HIGH); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("H")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("High")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("High")); + } + + @Test + public void toFhirResource_shouldTranslateLowInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.LOW); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("L")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Low")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Low")); + } + + @Test + public void toFhirResource_shouldTranslateOffScaleLowInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.OFF_SCALE_LOW); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("<")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Off Scale Low")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Off Scale Low")); + } + + @Test + public void toFhirResource_shouldTranslateOffScaleHighInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.OFF_SCALE_HIGH); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is(">")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Off Scale High")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Off Scale High")); + } + + @Test + public void toFhirResource_shouldTranslateSignificantChangeDownInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("D")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Significant Change Down")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Significant Change Down")); + } + + @Test + public void toFhirResource_shouldTranslateSignificantChangeUpInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.SIGNIFICANT_CHANGE_UP); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("U")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Significant Change Up")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Significant Change Up")); + } + + @Test + public void toFhirResource_shouldTranslateResistantInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.RESISTANT); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("R")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Resistant")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Resistant")); + } + + @Test + public void toFhirResource_shouldTranslateSusceptibleInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.SUSCEPTIBLE); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("S")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Susceptible")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Susceptible")); + } + + @Test + public void toFhirResource_shouldTranslateIntermediateInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.INTERMEDIATE); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("I")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Intermediate")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Intermediate")); + } + + @Test + public void toFhirResource_shouldTranslatePositiveInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.POSITIVE); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("POS")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Positive")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Positive")); + } + + @Test + public void toFhirResource_shouldTranslateNegativeInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.NEGATIVE); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("NEG")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Negative")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Negative")); + } + + @Test + public void toFhirResource_shouldTranslateVerySusceptibleInterpretationCorrectly() { + obs.setInterpretation(Obs.Interpretation.VERY_SUSCEPTIBLE); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.notNullValue()); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getCode(), Matchers.is("VS")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getDisplay(), Matchers.is("Very Susceptible")); + MatcherAssert.assertThat(interpretation.getText(), Matchers.is("Very Susceptible")); + MatcherAssert.assertThat(interpretation.getCoding().get(0).getSystem(), + Matchers.is(FhirConstants.OPENMRS_FHIR_EXT_VS_INTERPRETATION)); + } + + @Test + public void toFhirResource_shouldReturnNoFhirInterpretationWhenObsInterpretationIsNull() { + obs.setInterpretation(null); + CodeableConcept interpretation = observationInterpretationTranslator.toFhirResource(obs); + MatcherAssert.assertThat(interpretation, Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnNullIfInterpretationSizeIsZero() { + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldTranslateNormalCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("N"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.NORMAL)); + } + + @Test + public void toOpenmrsType_shouldTranslateAbnormalCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("A"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.ABNORMAL)); + } + + @Test + public void toOpenmrsType_shouldTranslateCriticallyAbnormalCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("AA"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.CRITICALLY_ABNORMAL)); + } + + @Test + public void toOpenmrsType_shouldTranslateCriticallyHighCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("HH"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.CRITICALLY_HIGH)); + } + + @Test + public void toOpenmrsType_shouldTranslateCriticallyLowCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("LL"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.CRITICALLY_LOW)); + } + + @Test + public void toOpenmrsType_shouldTranslateHighCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("H"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.HIGH)); + } + + @Test + public void toOpenmrsType_shouldTranslateLowCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("L"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.LOW)); + } + + @Test + public void toOpenmrsType_shouldTranslateOffScaleLowCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("<"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.OFF_SCALE_LOW)); + } + + @Test + public void toOpenmrsType_shouldTranslateOffScaleHighCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode(">"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.OFF_SCALE_HIGH)); + } + + @Test + public void toOpenmrsType_shouldTranslateSignificantChangeDownCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("D"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.SIGNIFICANT_CHANGE_DOWN)); + } + + @Test + public void toOpenmrsType_shouldTranslateSignificantChangeUpCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("U"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.SIGNIFICANT_CHANGE_UP)); + } + + @Test + public void toOpenmrsType_shouldTranslateResistantCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("R"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.RESISTANT)); + } + + @Test + public void toOpenmrsType_shouldTranslateSusceptibleCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("S"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.SUSCEPTIBLE)); + } + + @Test + public void toOpenmrsType_shouldTranslateIntermediateCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("I"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.INTERMEDIATE)); + } + + @Test + public void toOpenmrsType_shouldTranslatePositiveCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("POS"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.POSITIVE)); } @Test - public void toFhirResource_shouldReturnNull() { - Obs obs = new Obs(); - CodeableConcept intepretation = interpretationTranslator.toFhirResource(obs); - assertThat(intepretation, nullValue()); + public void toOpenmrsType_shouldTranslateNegativeCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("NEG"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.NEGATIVE)); } @Test - public void toOpenmrsType_shouldReturnObsAtIsWasPassed() { - Obs obs = new Obs(); - Obs result = interpretationTranslator.toOpenmrsType(obs, new CodeableConcept()); - assertThat(result, equalTo(obs)); - + public void toOpenmrsType_shouldTranslateVerySusceptibleCodeCorrectly() { + Coding coding = new Coding(); + coding.setCode("VS"); + interpretation.addCoding(coding); + observationInterpretationTranslator.toOpenmrsType(obs, interpretation); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getInterpretation(), Matchers.is(Obs.Interpretation.VERY_SUSCEPTIBLE)); } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImplTest.java index bef9089dbc..eb17e90075 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationStatusTranslatorImplTest.java @@ -10,39 +10,120 @@ package org.openmrs.module.fhir2.api.translators.impl; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.Observation; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.Obs; +@RunWith(MockitoJUnitRunner.class) public class ObservationStatusTranslatorImplTest { + private static final Obs.Status OBS_STATUS = Obs.Status.FINAL; + private ObservationStatusTranslatorImpl observationStatusTranslator; + private Obs obs; + @Before - public void setup() { + public void setUp() { observationStatusTranslator = new ObservationStatusTranslatorImpl(); + obs = new Obs(); + obs.setStatus(OBS_STATUS); } @Test - public void shouldMapObservationStatusToUnknown() { - Obs obs = new Obs(); - - Observation.ObservationStatus result = observationStatusTranslator.toFhirResource(obs); - - assertThat(result, is(Observation.ObservationStatus.UNKNOWN)); + public void toFhirResource_shouldTranslateObsStatusToFhirObservationStatus() { + Observation.ObservationStatus status = observationStatusTranslator.toFhirResource(obs); + MatcherAssert.assertThat(status, Matchers.notNullValue()); + MatcherAssert.assertThat(status, Matchers.is(Observation.ObservationStatus.valueOf(OBS_STATUS.toString()))); + } + + @Test + public void toOpenmrsType_shouldTranslatePreliminaryFhirObservationStatusToObsStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.PRELIMINARY; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getStatus(), Matchers.is(Obs.Status.PRELIMINARY)); + } + + @Test + public void toOpenmrsType_shouldTranslateFinalFhirObservationStatusToObsStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.FINAL; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getStatus(), Matchers.is(Obs.Status.FINAL)); + } + + @Test + public void toOpenmrsType_shouldTranslateAmendedFhirObservationStatusToObsStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.AMENDED; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.notNullValue()); + MatcherAssert.assertThat(obs.getStatus(), Matchers.is(Obs.Status.AMENDED)); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedRegisteredStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.REGISTERED; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedCorrectedStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.CORRECTED; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedCancelledStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.CANCELLED; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedEnteredInErrorStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.ENTEREDINERROR; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedUnknownStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.UNKNOWN; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); + } + + @Test + public void toOpenmrsType_shouldReturnObsWithNullStatusWhenCalledWithUnsupportedNullStatus() { + Observation.ObservationStatus status = Observation.ObservationStatus.NULL; + obs.setStatus(null); + observationStatusTranslator.toOpenmrsType(obs, status); + MatcherAssert.assertThat(obs.getStatus(), Matchers.nullValue()); } @Test - public void shouldMapFhirRepresentationToNull() { + public void toOpenmrsType_shouldMapFhirRepresentationToNull() { Obs obs = new Obs(); Observation.ObservationStatus observationStatus = Observation.ObservationStatus.FINAL; - Obs result = observationStatusTranslator.toOpenmrsType(obs, observationStatus); - assertThat(result, notNullValue()); } } diff --git a/e2e-tests/pom.xml b/e2e-tests/pom.xml index 2f5f1b3e6f..0deca7011e 100644 --- a/e2e-tests/pom.xml +++ b/e2e-tests/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/integration-tests-2.1/pom.xml b/integration-tests-2.1/pom.xml deleted file mode 100644 index cbf8b719ea..0000000000 --- a/integration-tests-2.1/pom.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - fhir2 - org.openmrs.module - 1.12.0-SNAPSHOT - - 4.0.0 - - fhir2-integration-tests-2.1 - FHIR2 Integration Tests 2.1 - - - - org.projectlombok - lombok - - - ${project.parent.groupId} - ${project.parent.artifactId}-omod - ${project.parent.version} - test - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.2 - - - com.fasterxml.jackson.core - jackson-databind - - - - - ${project.parent.groupId} - ${project.parent.artifactId}-integration-tests - ${project.parent.version} - test-jar - test - - - org.openmrs.web - openmrs-web - ${openmrsPlatformVersion} - - - org.openmrs.web - openmrs-web - ${openmrsPlatformVersion} - test-jar - test - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - javax.servlet - javax.servlet-api - - - ca.uhn.hapi.fhir - hapi-fhir-validation - - - ca.uhn.hapi.fhir - hapi-fhir-validation-resources-r4 - - - ca.uhn.hapi.fhir - hapi-fhir-validation-resources-dstu3 - - - com.fasterxml.jackson.core - jackson-databind - 2.9.10.8 - provided - - - - - - org.apache.maven.plugins - maven-jar-plugin - - true - - - - - test-jar - - - - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - - - 2.1.4 - - diff --git a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/GroupResourceProviderIntegrationTest.java b/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/GroupResourceProviderIntegrationTest.java deleted file mode 100644 index c957ccd805..0000000000 --- a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/GroupResourceProviderIntegrationTest.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * 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 java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.util.Objects; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.hl7.fhir.dstu3.model.Group; -import org.hl7.fhir.dstu3.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.BaseFhirIntegrationTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -public class GroupResourceProviderIntegrationTest extends BaseFhirR3IntegrationTest { - - private static final String COHORT_UUID = "1d64befb-3b2e-48e5-85f5-353d43e23e46"; - - private static final String BAD_COHORT_UUID = "5c9d032b-6092-4052-93d2-a04202b98462"; - - private static final String COHORT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortMemberDaoImplTest_initial_data.xml"; - - private static final String PATIENT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml"; - - private static final String JSON_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.json"; - - private static final String XML_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.xml"; - - private static final String JSON_UPDATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_update.json"; - - private static final String XML_UPDATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_update.xml"; - - @Autowired - @Getter(AccessLevel.PUBLIC) - private GroupFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - executeDataSet(COHORT_DATA_XML); - executeDataSet(PATIENT_DATA_XML); - } - - @Test - public void shouldReturnExistingGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - assertThat(group, validResource()); - - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(group.getMember().size(), equalTo(1)); - } - - @Test - public void shouldThrow404ForNonExistingGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + BAD_COHORT_UUID) - .accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - } - - @Test - public void shouldReturnExistingGroupAsXML() throws Exception { - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - assertThat(group, validResource()); - - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(group.getMember().size(), equalTo(1)); - } - - @Test - public void shouldThrow404ForNonExistingGroupAsXML() throws Exception { - MockHttpServletResponse response = get("/Group/" + BAD_COHORT_UUID) - .accept(BaseFhirIntegrationTest.FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - } - - @Test - public void shouldCreateNewGroupAsJson() throws Exception { - // read JSON record - String jsonGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - jsonGroup = inputStreamToString(is, UTF_8); - } - - // create group - MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.JSON).jsonContent(jsonGroup).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - assertThat(group, notNullValue()); - assertThat(group.getActive(), is(true)); - assertThat(group.hasMember(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - } - - @Test - public void shouldCreateNewGroupAsXML() throws Exception { - // read JSON record - String xmlGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - xmlGroup = inputStreamToString(is, UTF_8); - } - - // create group - MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - assertThat(group, notNullValue()); - assertThat(group.getActive(), is(true)); - assertThat(group.hasMember(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - } - - @Test - @Transactional(readOnly = true) - public void shouldUpdateExistingGroupAsJson() throws Exception { - //Before update - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group, validResource()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - - // Get existing group with updated name - String jsonGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - jsonGroup = inputStreamToString(is, UTF_8); - } - - //Update - response = put("/Group/" + COHORT_UUID).jsonContent(jsonGroup).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - // read updated record - group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - assertThat(group.getActive(), is(true)); - assertThat(group, validResource()); - - // Double-check via get - response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - - Group updatedGroup = readResponse(response); - - assertThat(updatedGroup, validResource()); - assertThat(updatedGroup, notNullValue()); - assertThat(updatedGroup.getActive(), is(true)); - } - - @Test - @Transactional(readOnly = true) - public void shouldUpdateExistingGroupAsXML() throws Exception { - //Before update - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group, validResource()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - - // Get existing group with updated name - String xmlGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_UPDATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - xmlGroup = inputStreamToString(is, UTF_8); - } - - //Update - response = put("/Group/" + COHORT_UUID).xmlContent(xmlGroup).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - // read updated record - group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID)); - assertThat(group.getActive(), is(true)); - assertThat(group, validResource()); - - // Double-check via get - response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go(); - - Group updatedGroup = readResponse(response); - - assertThat(updatedGroup, validResource()); - assertThat(updatedGroup, notNullValue()); - assertThat(updatedGroup.getActive(), is(true)); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_COHORT_UUID); - - // send the update to the server - response = put("/Group/" + COHORT_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_COHORT_UUID); - - // send the update to the server - response = put("/Group/" + BAD_COHORT_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_COHORT_UUID); - - // send the update to the server - response = put("/Group/" + COHORT_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_COHORT_UUID); - - // send the update to the server - response = put("/Group/" + BAD_COHORT_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldDeleteExistingGroup() throws Exception { - MockHttpServletResponse response = delete("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentGroup() throws Exception { - MockHttpServletResponse response = delete("/Group/" + BAD_COHORT_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } -} diff --git a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java b/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java deleted file mode 100644 index 86cea738cd..0000000000 --- a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java +++ /dev/null @@ -1,584 +0,0 @@ -/* - * 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 java.nio.charset.StandardCharsets.UTF_8; -import static org.exparity.hamcrest.date.DateMatchers.sameOrAfter; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.math.BigDecimal; -import java.net.URL; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.dstu3.model.Bundle; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.FhirConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; - -public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR3IntegrationTest { - - private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml"; - - private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.json"; - - private static final String XML_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.xml"; - - private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0"; - - private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - - private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure"; - - private static final String CIEL_SYSTEM_URI = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; - - private static final String OBS_CONCEPT_CIEL_ID = "5085"; - - private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0); - - private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0); - - private static final BigDecimal OBS_HIGH_REFERENCE_RANGE = BigDecimal.valueOf(250.0); - - private static final String OBS_PATIENT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; - - private static final String OBS_ENCOUNTER_UUID = "6519d653-393b-4118-9c83-a3715b82d4ac"; - - private static final String WRONG_OBS_UUID = "121b73a6-e1a4-4424-8610-d5765bf2fdf7"; - - @Autowired - @Getter(AccessLevel.PUBLIC) - private ObservationFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - - executeDataSet(OBS_DATA_XML); - } - - @Test - public void shouldReturnExistingObservationAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - // verify expected codings - assertThat(observation.getCode().getCoding(), - hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); - assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); - assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); - - // verify expected value - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE)); - - // verify reference ranges - assertThat(observation.getReferenceRange(), notNullValue()); - assertThat(observation.getReferenceRange(), not(empty())); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE))))); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE))))); - - // verify expected patient - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), containsString("Patient/")); - assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID)); - - //verify expected encounter - assertThat(observation.getContext(), notNullValue()); - assertThat(observation.getContext().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID)); - - assertThat(observation, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenObservationNotFoundAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.getIssue(), hasSize(greaterThanOrEqualTo(1))); - assertThat(operationOutcome.getIssue(), - hasItem(hasProperty("severity", equalTo(OperationOutcome.IssueSeverity.ERROR)))); - } - - @Test - public void shouldReturnExistingObservationAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - // verify expected codings - assertThat(observation.getCode().getCoding(), - hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); - assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); - assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); - - // verify expected value - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE)); - - // verify reference ranges - assertThat(observation.getReferenceRange(), notNullValue()); - assertThat(observation.getReferenceRange(), not(empty())); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE))))); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE))))); - - // verify expected patient - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), containsString("Patient/")); - assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID)); - - //verify expected encounter - assertThat(observation.getContext(), notNullValue()); - assertThat(observation.getContext().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID)); - - assertThat(observation, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenObservationNotFoundAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.getIssue(), hasSize(greaterThanOrEqualTo(1))); - assertThat(operationOutcome.getIssue(), - hasItem(hasProperty("severity", equalTo(OperationOutcome.IssueSeverity.ERROR)))); - } - - @Test - public void shouldCreateNewObservationAsJson() throws Exception { - // read JSON record - String jsonObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_OBS_DOCUMENT)) { - Objects.requireNonNull(is); - jsonObs = inputStreamToString(is, UTF_8); - } - - // create obs - MockHttpServletResponse response = post("/Observation").accept(FhirMediaTypes.JSON).jsonContent(jsonObs).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), notNullValue()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation.getIdElement().getIdPart(), notNullValue()); - assertThat(observation.getCode(), notNullValue()); - assertThat(observation.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), endsWith("5946f880-b197-400b-9caa-a3c661d23041")); - assertThat(observation.getContext(), notNullValue()); - assertThat(observation.getContext().getReference(), endsWith("6519d653-393b-4118-9c83-a3715b82d4ac")); - assertThat(observation.getValue(), notNullValue()); - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(BigDecimal.valueOf(156.0))); - assertThat(observation.getValueQuantity().getUnit(), equalTo("cm")); - assertThat(observation, validResource()); - - // try to fetch the new observation - response = get("/Observation/" + observation.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - Observation newObservation = readResponse(response); - - assertThat(newObservation.getId(), equalTo(observation.getId())); - } - - @Test - public void shouldCreateNewObservationAsXML() throws Exception { - // read JSON record - String xmlObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_OBS_DOCUMENT)) { - Objects.requireNonNull(is); - xmlObs = inputStreamToString(is, UTF_8); - } - - // create obs - MockHttpServletResponse response = post("/Observation").accept(FhirMediaTypes.XML).xmlContent(xmlObs).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), notNullValue()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation.getIdElement().getIdPart(), notNullValue()); - assertThat(observation.getCode(), notNullValue()); - assertThat(observation.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), endsWith("5946f880-b197-400b-9caa-a3c661d23041")); - assertThat(observation.getContext(), notNullValue()); - assertThat(observation.getContext().getReference(), endsWith("6519d653-393b-4118-9c83-a3715b82d4ac")); - assertThat(observation.getValue(), notNullValue()); - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(BigDecimal.valueOf(156.0))); - assertThat(observation.getValueQuantity().getUnit(), equalTo("cm")); - assertThat(observation, validResource()); - - // try to fetch the new observation - response = get("/Observation/" + observation.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - - Observation newObservation = readResponse(response); - - assertThat(newObservation.getId(), equalTo(observation.getId())); - } - - @Test - public void shouldDeleteExistingObservation() throws Exception { - MockHttpServletResponse response = delete("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentObservation() throws Exception { - MockHttpServletResponse response = delete("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldSearchForExistingObservationsAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForFilteredObservationsAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, - everyItem(hasResource(hasProperty("subject", hasProperty("reference", endsWith(OBS_PATIENT_UUID)))))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForExistingObservationsAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForFilteredObservationsAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, - everyItem(hasResource(hasProperty("subject", hasProperty("reference", endsWith(OBS_PATIENT_UUID)))))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldReturnCorrectInterpretationAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - assertThat(observation.getInterpretation().getCodingFirstRep().getSystem(), - equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); - assertThat(observation.getInterpretation().getCodingFirstRep().getCode(), equalTo("N")); - assertThat(observation.getInterpretation().getCodingFirstRep().getDisplay(), equalTo("Normal")); - } - - @Test - public void shouldReturnCorrectInterpretationAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - assertThat(observation.getInterpretation().getCodingFirstRep().getSystem(), - equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); - assertThat(observation.getInterpretation().getCodingFirstRep().getCode(), equalTo("N")); - assertThat(observation.getInterpretation().getCodingFirstRep().getDisplay(), equalTo("Normal")); - } - - @Test - public void shouldReturnCorrectStatusAsJSON() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); - } - - @Test - public void shouldReturnCorrectStatusAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); - } - - @Test - public void shouldSupportMultiplePagesAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()); - - Bundle.BundleLinkComponent link = results.getLink("next"); - while (link != null) { - String nextUrl = link.getUrl(); - URL url = new URL(nextUrl); - - // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query - // string - response = get("?" + url.getQuery()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList())); - - link = results.getLink("next"); - } - - assertThat(observations, hasSize(equalTo(results.getTotal()))); - for (int i = 1; i < observations.size(); i++) { - assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), - sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue())); - } - } - - @Test - public void shouldSupportMultiplePagesAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()); - - Bundle.BundleLinkComponent link = results.getLink("next"); - while (link != null) { - String nextUrl = link.getUrl(); - URL url = new URL(nextUrl); - - // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query - // string - response = get("?" + url.getQuery()).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList())); - - link = results.getLink("next"); - } - - assertThat(observations, hasSize(equalTo(results.getTotal()))); - for (int i = 1; i < observations.size(); i++) { - assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), - sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue())); - } - } -} diff --git a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupResourceProviderIntegrationTest.java b/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupResourceProviderIntegrationTest.java deleted file mode 100644 index bd815144c0..0000000000 --- a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupResourceProviderIntegrationTest.java +++ /dev/null @@ -1,539 +0,0 @@ -/* - * 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.r4; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.util.List; -import java.util.Objects; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.Group; -import org.hl7.fhir.r4.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.BaseFhirIntegrationTest; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.model.GroupMember; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -public class GroupResourceProviderIntegrationTest extends BaseFhirR4IntegrationTest { - - private static final String GROUP_UUID = "1d64befb-3b2e-48e5-85f5-353d43e23e46"; - - private static final String GROUP_WITH_MORE_MEMBERS = "2d64befb-3b2e-48e5-85f5-353d43e23e48"; - - private static final String BAD_GROUP_UUID = "5c9d032b-6092-4052-93d2-a04202b98462"; - - private static final String COHORT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortMemberDaoImplTest_initial_data.xml"; - - private static final String PATIENT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml"; - - private static final String JSON_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.json"; - - private static final String XML_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.xml"; - - private static final String JSON_UPDATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_update.json"; - - private static final String XML_UPDATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_update.xml"; - - @Autowired - @Getter(AccessLevel.PUBLIC) - private GroupFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - getFhirContext().registerCustomType(GroupMember.class); - executeDataSet(PATIENT_DATA_XML); - executeDataSet(COHORT_DATA_XML); - } - - @Test - public void shouldReturnExistingGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(group, validResource()); - - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(group.getMember().size(), equalTo(1)); - } - - @Test - public void shouldThrow404ForNonExistingGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + BAD_GROUP_UUID) - .accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - } - - @Test - public void shouldReturnExistingGroupAsXML() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(group, validResource()); - - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(group.getMember().size(), equalTo(1)); - } - - @Test - public void shouldThrow404ForNonExistingGroupAsXML() throws Exception { - MockHttpServletResponse response = get("/Group/" + BAD_GROUP_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML) - .go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - } - - @Test - public void shouldCreateNewGroupAsJson() throws Exception { - // read JSON record - String jsonGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - jsonGroup = inputStreamToString(is, UTF_8); - } - - // create group - MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.JSON).jsonContent(jsonGroup).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - assertThat(group, notNullValue()); - assertThat(group.getActive(), is(true)); - assertThat(group.hasMember(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - - } - - @Test - public void shouldCreateNewGroupAsXML() throws Exception { - // read JSON record - String xmlGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - xmlGroup = inputStreamToString(is, UTF_8); - } - - // create group - MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - assertThat(group, notNullValue()); - assertThat(group.getActive(), is(true)); - assertThat(group.hasMember(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - } - - @Test - @Transactional(readOnly = true) - public void shouldUpdateExistingGroupAsJson() throws Exception { - //Before update - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - Extension descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(group, notNullValue()); - assertThat(group, validResource()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(descExtension.getValue().toString(), equalTo("cohort voided")); - - // Get existing group with updated name - String jsonGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - jsonGroup = inputStreamToString(is, UTF_8); - } - - //Update - response = put("/Group/" + GROUP_UUID).jsonContent(jsonGroup).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - // read updated record - group = readResponse(response); - descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(group.getActive(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter")); - assertThat(group, validResource()); - - // Double-check via get - response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - Group updatedGroup = readResponse(response); - descExtension = updatedGroup.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(updatedGroup, validResource()); - assertThat(updatedGroup, notNullValue()); - assertThat(updatedGroup.getActive(), is(true)); - assertThat(group.getMember(), notNullValue()); - assertThat(group.getQuantity(), equalTo(1)); - assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter")); - } - - @Test - @Transactional(readOnly = true) - public void shouldUpdateExistingGroupAsXML() throws Exception { - //Before update - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - Extension descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(group, notNullValue()); - assertThat(group, validResource()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(descExtension.getValue().toString(), equalTo("cohort voided")); - - // Get existing group with updated name - String xmlGroup; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_UPDATE_GROUP_DOCUMENT)) { - Objects.requireNonNull(is); - xmlGroup = inputStreamToString(is, UTF_8); - } - - //Update - response = put("/Group/" + GROUP_UUID).xmlContent(xmlGroup).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - // read updated record - group = readResponse(response); - descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(group, notNullValue()); - assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID)); - assertThat(group.getActive(), is(true)); - assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter")); - assertThat(group, validResource()); - - // Double-check via get - response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.XML).go(); - - Group updatedGroup = readResponse(response); - descExtension = updatedGroup.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION); - - assertThat(updatedGroup, validResource()); - assertThat(updatedGroup, notNullValue()); - assertThat(updatedGroup.getActive(), is(true)); - assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter")); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.XML).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_GROUP_UUID); - - // send the update to the server - response = put("/Group/" + GROUP_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.XML).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_GROUP_UUID); - - // send the update to the server - response = put("/Group/" + BAD_GROUP_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_GROUP_UUID); - - // send the update to the server - response = put("/Group/" + GROUP_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON() throws Exception { - // get the existing record - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - Group group = readResponse(response); - - // update the existing record - group.setId(BAD_GROUP_UUID); - - // send the update to the server - response = put("/Group/" + BAD_GROUP_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldDeleteExistingGroup() throws Exception { - MockHttpServletResponse response = delete("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentGroup() throws Exception { - MockHttpServletResponse response = delete("/Group/" + BAD_GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnPaginatedListOfGroupMembersAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID + "/$members").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle groupMembers = readBundleResponse(response); - - assertThat(groupMembers, notNullValue()); - assertThat(groupMembers.getEntry(), not(empty())); - assertThat(groupMembers.getTotal(), is(1)); - - List entries = groupMembers.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/")))); - assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class)))); - assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/")))))); - } - - @Test - public void shouldReturnPaginatedListOfGroupMembersAsXml() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID + "/$members").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle groupMembers = readBundleResponse(response); - - assertThat(groupMembers, notNullValue()); - assertThat(groupMembers.getEntry(), not(empty())); - assertThat(groupMembers.getTotal(), is(1)); - - List entries = groupMembers.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/")))); - assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class)))); - assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/")))))); - } - - @Test - public void shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_WITH_MORE_MEMBERS + "/$members").accept(FhirMediaTypes.JSON) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle groupMembers = readBundleResponse(response); - - assertThat(groupMembers, notNullValue()); - assertThat(groupMembers.getEntry(), not(empty())); - assertThat(groupMembers.getTotal(), is(6)); - - List entries = groupMembers.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/")))); - assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class)))); - assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/")))))); - } - - @Test - public void shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsXml() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_WITH_MORE_MEMBERS + "/$members").accept(FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle groupMembers = readBundleResponse(response); - - assertThat(groupMembers, notNullValue()); - assertThat(groupMembers.getEntry(), not(empty())); - assertThat(groupMembers.getTotal(), is(6)); - - List entries = groupMembers.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/")))); - assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class)))); - assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/")))))); - } - - @Test - public void shouldReturnAnEtagHeaderWhenRetrievingAnExistingGroup() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), startsWith(FhirMediaTypes.JSON.toString())); - - assertThat(response.getHeader("etag"), notNullValue()); - assertThat(response.getHeader("etag"), startsWith("W/")); - - assertThat(response.getContentAsString(), notNullValue()); - - Group group = readResponse(response); - - assertThat(group, notNullValue()); - assertThat(group.getMeta().getVersionId(), notNullValue()); - assertThat(group, validResource()); - } - - @Test - public void shouldReturnNotModifiedWhenRetrievingAnExistingGroupWithAnEtag() throws Exception { - MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), startsWith(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - assertThat(response.getHeader("etag"), notNullValue()); - - String etagValue = response.getHeader("etag"); - - response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).ifNoneMatchHeader(etagValue).go(); - - assertThat(response, isOk()); - assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); - } - -} diff --git a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java b/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java deleted file mode 100644 index a0f97e69f6..0000000000 --- a/integration-tests-2.1/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java +++ /dev/null @@ -1,583 +0,0 @@ -/* - * 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.r4; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.exparity.hamcrest.date.DateMatchers.sameOrAfter; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.math.BigDecimal; -import java.net.URL; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Observation; -import org.hl7.fhir.r4.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.FhirConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; - -public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4IntegrationTest { - - private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml"; - - private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create.json"; - - private static final String XML_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create.xml"; - - private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0"; - - private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - - private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure"; - - private static final String CIEL_SYSTEM_URN = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; - - private static final String OBS_CONCEPT_CIEL_ID = "5085"; - - private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0); - - private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0); - - private static final BigDecimal OBS_HIGH_REFERENCE_RANGE = BigDecimal.valueOf(250.0); - - private static final String OBS_PATIENT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; - - private static final String OBS_ENCOUNTER_UUID = "6519d653-393b-4118-9c83-a3715b82d4ac"; - - private static final String WRONG_OBS_UUID = "121b73a6-e1a4-4424-8610-d5765bf2fdf7"; - - @Autowired - @Getter(AccessLevel.PUBLIC) - private ObservationFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - - executeDataSet(OBS_DATA_XML); - } - - @Test - public void shouldReturnExistingObservationAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - // verify expected codings - assertThat(observation.getCode().getCoding(), - hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); - assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); - assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); - - // verify expected value - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE)); - - // verify reference ranges - assertThat(observation.getReferenceRange(), notNullValue()); - assertThat(observation.getReferenceRange(), not(empty())); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE))))); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE))))); - - // verify expected patient - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getType(), equalTo("Patient")); - assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID)); - - //verify expected encounter - assertThat(observation.getEncounter(), notNullValue()); - assertThat(observation.getEncounter().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID)); - - assertThat(observation, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenObservationNotFoundAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.getIssue(), hasSize(greaterThanOrEqualTo(1))); - assertThat(operationOutcome.getIssue(), - hasItem(hasProperty("severity", equalTo(OperationOutcome.IssueSeverity.ERROR)))); - } - - @Test - public void shouldReturnExistingObservationAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - // verify expected codings - assertThat(observation.getCode().getCoding(), - hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); - assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); - assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); - - // verify expected value - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE)); - - // verify reference ranges - assertThat(observation.getReferenceRange(), notNullValue()); - assertThat(observation.getReferenceRange(), not(empty())); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE))))); - assertThat(observation.getReferenceRange(), - hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE))))); - - // verify expected patient - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getType(), equalTo("Patient")); - assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID)); - - //verify expected encounter - assertThat(observation.getEncounter(), notNullValue()); - assertThat(observation.getEncounter().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID)); - - assertThat(observation, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenObservationNotFoundAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.getIssue(), hasSize(greaterThanOrEqualTo(1))); - assertThat(operationOutcome.getIssue(), - hasItem(hasProperty("severity", equalTo(OperationOutcome.IssueSeverity.ERROR)))); - } - - @Test - public void shouldCreateNewObservationAsJson() throws Exception { - // read JSON record - String jsonObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_OBS_DOCUMENT)) { - Objects.requireNonNull(is); - jsonObs = inputStreamToString(is, UTF_8); - } - - // create obs - MockHttpServletResponse response = post("/Observation").accept(FhirMediaTypes.JSON).jsonContent(jsonObs).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), notNullValue()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation.getIdElement().getIdPart(), notNullValue()); - assertThat(observation.getCode(), notNullValue()); - assertThat(observation.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), endsWith("5946f880-b197-400b-9caa-a3c661d23041")); - assertThat(observation.getEncounter(), notNullValue()); - assertThat(observation.getEncounter().getReference(), endsWith("6519d653-393b-4118-9c83-a3715b82d4ac")); - assertThat(observation.getValue(), notNullValue()); - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(BigDecimal.valueOf(156.0))); - assertThat(observation.getValueQuantity().getUnit(), equalTo("cm")); - assertThat(observation, validResource()); - - // try to fetch the new observation - response = get("/Observation/" + observation.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - Observation newObservation = readResponse(response); - - assertThat(newObservation.getId(), equalTo(observation.getId())); - } - - @Test - public void shouldCreateNewObservationAsXML() throws Exception { - // read JSON record - String xmlObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_OBS_DOCUMENT)) { - Objects.requireNonNull(is); - xmlObs = inputStreamToString(is, UTF_8); - } - - // create obs - MockHttpServletResponse response = post("/Observation").accept(FhirMediaTypes.XML).xmlContent(xmlObs).go(); - - // verify created correctly - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), notNullValue()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation.getIdElement().getIdPart(), notNullValue()); - assertThat(observation.getCode(), notNullValue()); - assertThat(observation.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(observation.getSubject(), notNullValue()); - assertThat(observation.getSubject().getReference(), endsWith("5946f880-b197-400b-9caa-a3c661d23041")); - assertThat(observation.getEncounter(), notNullValue()); - assertThat(observation.getEncounter().getReference(), endsWith("6519d653-393b-4118-9c83-a3715b82d4ac")); - assertThat(observation.getValue(), notNullValue()); - assertThat(observation.getValueQuantity(), notNullValue()); - assertThat(observation.getValueQuantity().getValue(), equalTo(BigDecimal.valueOf(156.0))); - assertThat(observation.getValueQuantity().getUnit(), equalTo("cm")); - assertThat(observation, validResource()); - - // try to fetch the new observation - response = get("/Observation/" + observation.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - - Observation newObservation = readResponse(response); - - assertThat(newObservation.getId(), equalTo(observation.getId())); - } - - @Test - public void shouldDeleteExistingObservation() throws Exception { - MockHttpServletResponse response = delete("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentObservation() throws Exception { - MockHttpServletResponse response = delete("/Observation/" + WRONG_OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldSearchForExistingObservationsAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForFilteredObservationsAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, - everyItem(hasResource(hasProperty("subject", hasProperty("reference", endsWith(OBS_PATIENT_UUID)))))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForExistingObservationsAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSearchForFilteredObservationsAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); - assertThat(entries, - everyItem(hasResource(hasProperty("subject", hasProperty("reference", endsWith(OBS_PATIENT_UUID)))))); - assertThat(entries, everyItem(hasResource(validResource()))); - } - - @Test - public void shouldSupportMultiplePagesAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()); - - Bundle.BundleLinkComponent link = results.getLink("next"); - while (link != null) { - String nextUrl = link.getUrl(); - URL url = new URL(nextUrl); - - // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query - // string - response = get("?" + url.getQuery()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList())); - - link = results.getLink("next"); - } - - assertThat(observations, hasSize(equalTo(results.getTotal()))); - for (int i = 1; i < observations.size(); i++) { - assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), - sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue())); - } - } - - @Test - public void shouldReturnCorrectInterpretationAsJson() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getSystem(), - equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getCode(), equalTo("N")); - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getDisplay(), equalTo("Normal")); - } - - @Test - public void shouldReturnCorrectInterpretationAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getSystem(), - equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getCode(), equalTo("N")); - assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getDisplay(), equalTo("Normal")); - } - - @Test - public void shouldReturnCorrectStatusAsJSON() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); - } - - @Test - public void shouldReturnCorrectStatusAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation observation = readResponse(response); - - assertThat(observation, notNullValue()); - assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); - assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); - } - - @Test - public void shouldSupportMultiplePagesAsXML() throws Exception { - MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date") - .accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()); - - Bundle.BundleLinkComponent link = results.getLink("next"); - while (link != null) { - String nextUrl = link.getUrl(); - URL url = new URL(nextUrl); - - // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query - // string - response = get("?" + url.getQuery()).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource) - .filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList())); - - link = results.getLink("next"); - } - - assertThat(observations, hasSize(equalTo(results.getTotal()))); - for (int i = 1; i < observations.size(); i++) { - assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), - sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue())); - } - } -} diff --git a/integration-tests-2.2/pom.xml b/integration-tests-2.2/pom.xml deleted file mode 100644 index fcaf7a3a07..0000000000 --- a/integration-tests-2.2/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - fhir2 - org.openmrs.module - 1.12.0-SNAPSHOT - - 4.0.0 - - fhir2-integration-tests-2.2 - FHIR2 Integration Tests 2.2 - - - - org.projectlombok - lombok - - - ${project.parent.groupId} - ${project.parent.artifactId}-omod - ${project.parent.version} - test - - - com.fasterxml.jackson.core - jackson-databind - - - - - ${project.parent.groupId} - ${project.parent.artifactId}-integration-tests - ${project.parent.version} - test-jar - test - - - org.openmrs.web - openmrs-web - ${openmrsPlatformVersion} - - - org.openmrs.web - openmrs-web - ${openmrsPlatformVersion} - test-jar - test - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - javax.servlet - javax.servlet-api - - - ca.uhn.hapi.fhir - hapi-fhir-validation - - - ca.uhn.hapi.fhir - hapi-fhir-validation-resources-r4 - - - ca.uhn.hapi.fhir - hapi-fhir-validation-resources-dstu3 - - - com.fasterxml.jackson.core - jackson-databind - 2.12.6.1 - provided - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - true - - - - - test-jar - - - - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - - - - 2.2.0 - - - diff --git a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java b/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java deleted file mode 100644 index 3674618caf..0000000000 --- a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.provider.r3; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.util.Objects; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.dstu3.model.Extension; -import org.hl7.fhir.dstu3.model.MedicationRequest; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.BaseFhirIntegrationTest; -import org.openmrs.module.fhir2.providers.r3.BaseFhirR3IntegrationTest; -import org.openmrs.module.fhir2.providers.r3.MedicationRequestFhirResourceProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mock.web.MockHttpServletResponse; - -public class MedicationRequestFhirResourceProvider_2_2IntegrationTest extends BaseFhirR3IntegrationTest { - - private static final String MEDICATION_REQUEST_UUID = "546ba5a6-5aa6-4325-afc0-50bc00d5ffa1"; - - private static final String MEDICATION_REQUEST_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequest_2_2_initial_data.xml"; - - private static final String JSON_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_patch.json"; - - @Getter(AccessLevel.PUBLIC) - @Autowired - private MedicationRequestFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - executeDataSet(MEDICATION_REQUEST_DATA_XML); - } - - @Test - public void shouldReturnExistingMedicationRequestAsJson() throws Exception { - MockHttpServletResponse response = get("/MedicationRequest/" + MEDICATION_REQUEST_UUID) - .accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the new fulfiller extension has been added - Extension extension = null; - for (Extension e : medicationRequest.getExtension()) { - if (e.getUrl().equalsIgnoreCase(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS)) { - extension = e; - break; - } - } - - assertThat(extension, notNullValue()); - assertThat(extension.getValue().toString(), is("RECEIVED")); - - } - - @Test - public void shouldPatchExistingMedicationRequestViaJson() throws Exception { - String jsonMedicationRequestPatch; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_MEDICATION_REQUEST_PATH)) { - Objects.requireNonNull(is); - jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) - .jsonMergePatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the fulfiller extension has been updated - Extension extension = null; - for (Extension e : medicationRequest.getExtension()) { - if (e.getUrl().equalsIgnoreCase(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS)) { - extension = e; - break; - } - } - - assertThat(extension, notNullValue()); - assertThat(extension.getValue().toString(), is("COMPLETED")); - } -} diff --git a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java b/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java deleted file mode 100644 index 0e2bae6c01..0000000000 --- a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/MedicationRequestFhirResourceProvider_2_2IntegrationTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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.provider.r4; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.util.Objects; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.module.fhir2.providers.r4.BaseFhirR4IntegrationTest; -import org.openmrs.module.fhir2.providers.r4.MedicationRequestFhirResourceProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mock.web.MockHttpServletResponse; - -public class MedicationRequestFhirResourceProvider_2_2IntegrationTest extends BaseFhirR4IntegrationTest { - - private static final String MEDICATION_REQUEST_UUID = "546ba5a6-5aa6-4325-afc0-50bc00d5ffa1"; - - private static final String MEDICATION_REQUEST_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequest_2_2_initial_data.xml"; - - private static final String JSON_MERGE_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_patch.json"; - - private static final String JSON_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_json_patch.json"; - - private static final String XML_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_xml_patch.xml"; - - @Getter(AccessLevel.PUBLIC) - @Autowired - private MedicationRequestFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - executeDataSet(MEDICATION_REQUEST_DATA_XML); - } - - @Test - public void shouldReturnExistingMedicationRequestAsJson() throws Exception { - MockHttpServletResponse response = get("/MedicationRequest/" + MEDICATION_REQUEST_UUID).accept(FhirMediaTypes.JSON) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the new fulfiller extension has been added - assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), - notNullValue()); - assertThat( - medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), - is("RECEIVED")); - - } - - @Test - public void shouldPatchExistingMedicationRequestUsingJsonMergePatch() throws Exception { - String jsonMedicationRequestPatch; - try (InputStream is = this.getClass().getClassLoader() - .getResourceAsStream(JSON_MERGE_PATCH_MEDICATION_REQUEST_PATH)) { - Objects.requireNonNull(is); - jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) - .jsonMergePatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the fulfiller extension has been updated - assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), - notNullValue()); - assertThat( - medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), - is("COMPLETED")); - } - - @Test - public void shouldPatchExistingMedicationRequestUsingJsonPatch() throws Exception { - String jsonMedicationRequestPatch; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_MEDICATION_REQUEST_PATH)) { - Objects.requireNonNull(is); - jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) - .jsonPatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the fulfiller extension has been updated - assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), - notNullValue()); - assertThat( - medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), - is("COMPLETED")); - } - - @Test - public void shouldPatchExistingMedicationRequestUsingXmlPatch() throws Exception { - String xmlMedicationRequestPatch; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_MEDICATION_REQUEST_PATH)) { - Objects.requireNonNull(is); - xmlMedicationRequestPatch = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) - .xmlPatch(xmlMedicationRequestPatch).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - MedicationRequest medicationRequest = readResponse(response); - - assertThat(medicationRequest, notNullValue()); - assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); - assertThat(medicationRequest, validResource()); - - // confirm that the fulfiller extension has been updated - assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), - notNullValue()); - assertThat( - medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), - is("COMPLETED")); - } -} diff --git a/integration-tests-2.6/pom.xml b/integration-tests-2.6/pom.xml index ff40333b9d..aa8afee47b 100644 --- a/integration-tests-2.6/pom.xml +++ b/integration-tests-2.6/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/integration-tests-2.7/pom.xml b/integration-tests-2.7/pom.xml index baa623dca2..97ef150dda 100644 --- a/integration-tests-2.7/pom.xml +++ b/integration-tests-2.7/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 568cd38495..26ec62de98 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 @@ -21,16 +21,6 @@ ${project.parent.artifactId}-omod ${project.parent.version} test - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.1 - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.2 - - org.openmrs.web diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/DelegatingWebApplicationContext.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/DelegatingWebApplicationContext.java index 72bb75f834..0de729b40c 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/DelegatingWebApplicationContext.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/DelegatingWebApplicationContext.java @@ -21,11 +21,13 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; +import org.springframework.core.ResolvableType; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.web.context.WebApplicationContext; @@ -112,6 +114,16 @@ public T getBean(Class requiredType, Object... args) throws BeansExceptio return applicationContext.getBean(requiredType, args); } + @Override + public ObjectProvider getBeanProvider(Class aClass) { + return applicationContext.getBeanProvider(aClass); + } + + @Override + public ObjectProvider getBeanProvider(ResolvableType resolvableType) { + return applicationContext.getBeanProvider(resolvableType); + } + @Override public boolean containsBean(String name) { return applicationContext.containsBean(name); @@ -127,6 +139,11 @@ public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); } + @Override + public boolean isTypeMatch(String s, ResolvableType resolvableType) throws NoSuchBeanDefinitionException { + return applicationContext.isTypeMatch(s, resolvableType); + } + @Override public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException { return applicationContext.isTypeMatch(name, targetType); @@ -137,6 +154,11 @@ public Class getType(String name) throws NoSuchBeanDefinitionException { return applicationContext.getType(name); } + @Override + public Class getType(String s, boolean b) throws NoSuchBeanDefinitionException { + return applicationContext.getType(s, b); + } + @Override public String[] getAliases(String name) { return applicationContext.getAliases(name); @@ -172,6 +194,11 @@ public void publishEvent(ApplicationEvent event) { applicationContext.publishEvent(event); } + @Override + public void publishEvent(Object o) { + applicationContext.publishEvent(o); + } + @Override public Resource[] getResources(String locationPattern) throws IOException { return applicationContext.getResources(locationPattern); @@ -197,6 +224,16 @@ public String[] getBeanDefinitionNames() { return applicationContext.getBeanDefinitionNames(); } + @Override + public String[] getBeanNamesForType(ResolvableType resolvableType) { + return applicationContext.getBeanNamesForType(resolvableType); + } + + @Override + public String[] getBeanNamesForType(ResolvableType resolvableType, boolean b, boolean b1) { + return applicationContext.getBeanNamesForType(resolvableType, b, b1); + } + @Override public String[] getBeanNamesForType(Class type) { return applicationContext.getBeanNamesForType(type); diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionFhirResourceProviderIntegrationTest.java deleted file mode 100644 index 93d0b75232..0000000000 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionFhirResourceProviderIntegrationTest.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * 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 java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.sql.Date; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.List; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.dstu3.model.Bundle; -import org.hl7.fhir.dstu3.model.Condition; -import org.hl7.fhir.dstu3.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; - -public class ConditionFhirResourceProviderIntegrationTest extends BaseFhirR3IntegrationTest { - - private static final String CONDITION_DATA_SET_FILE = "org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml"; - - private static final String JSON_CREATE_CONDITION_DOCUMENT = "org/openmrs/module/fhir2/providers/ConditionWebTest_create_r3.json"; - - private static final String XML_CREATE_CONDITION_DOCUMENT = "org/openmrs/module/fhir2/providers/ConditionWebTest_create_r3.xml"; - - private static final String CONDITION_UUID = "86sgf-1f7d-4394-a316-0a458edf28c4"; - - private static final String WRONG_CONDITION_UUID = "950d965d-a935-429f-945f-75a502a90188"; - - private static final String CONDITION_SUBJECT_UUID = "da7f524f-27ce-4bb2-86d6-6d1d05312bd5"; - - private static final String EXISTING_OBS_CONDITION_SUBJECT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; - - @Getter(AccessLevel.PUBLIC) - @Autowired - private ConditionFhirResourceProvider resourceProvider; - - @Before - @Override - public void setup() throws Exception { - super.setup(); - executeDataSet(CONDITION_DATA_SET_FILE); - } - - @Test - public void shouldReturnConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), equalTo(CONDITION_UUID)); - - assertThat(condition.getOnsetDateTimeType().getValue(), - equalTo(Date.from(LocalDateTime.of(2008, 07, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))); - - assertThat(condition.hasSubject(), is(true)); - assertThat(condition.getSubject().getReference(), equalTo("Patient/" + EXISTING_OBS_CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenConditionNotFoundAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnConditionAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), equalTo(CONDITION_UUID)); - - assertThat(condition.getOnsetDateTimeType().getValue(), - equalTo(Date.from(LocalDateTime.of(2008, 07, 01, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))); - - assertThat(condition.hasSubject(), is(true)); - assertThat(condition.getSubject().getReference(), equalTo("Patient/" + EXISTING_OBS_CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenConditionNotFoundAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldCreateNewConditionAsJson() throws Exception { - String jsonCondition; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_CONDITION_DOCUMENT)) { - assertThat(is, notNullValue()); - jsonCondition = inputStreamToString(is, UTF_8); - assertThat(jsonCondition, notNullValue()); - } - - MockHttpServletResponse response = post("/Condition").accept(FhirMediaTypes.JSON).jsonContent(jsonCondition).go(); - - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), containsString("/Condition/")); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentType(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), notNullValue()); - assertThat(condition.getCode(), notNullValue()); - assertThat(condition.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(condition.getSubject(), notNullValue()); - assertThat(condition.getSubject().getReference(), endsWith(CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - - response = get("/Condition/" + condition.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - Condition newCondition = readResponse(response); - - assertThat(newCondition.getId(), equalTo(condition.getId())); - } - - @Test - public void shouldCreateNewConditionAsXML() throws Exception { - String xmlCondition; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_CONDITION_DOCUMENT)) { - assertThat(is, notNullValue()); - xmlCondition = inputStreamToString(is, UTF_8); - assertThat(xmlCondition, notNullValue()); - } - - MockHttpServletResponse response = post("/Condition").accept(FhirMediaTypes.XML).xmlContent(xmlCondition).go(); - - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), containsString("/Condition/")); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentType(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), notNullValue()); - assertThat(condition.getOnsetDateTimeType(), notNullValue()); - assertThat(condition.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(condition.getSubject().getReference(), endsWith(CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - - response = get("/Condition/" + condition.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - Condition newCondition = readResponse(response); - - assertThat(newCondition.getId(), equalTo(condition.getId())); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchConditionIdAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + CONDITION_UUID).jsonContent(toJson(condition)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + WRONG_CONDITION_UUID).jsonContent(toJson(condition)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchConditionIdAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + CONDITION_UUID).xmlContent(toXML(condition)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentConditionAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + WRONG_CONDITION_UUID).xmlContent(toXML(condition)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldDeleteExistingCondition() throws Exception { - MockHttpServletResponse response = delete("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentCondition() throws Exception { - MockHttpServletResponse response = delete("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldSearchForAllConditionsAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Condition/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Condition.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - assertThat(entries.size(), equalTo(2)); - } - - @Test - public void shouldReturnSortedAndFilteredSearchResultsForConditionsAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition?clinical-status=active?onset-date=2008&_sort=-onset-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries.size(), equalTo(2)); - assertThat(entries, - containsInRelativeOrder( - hasResource(hasProperty( - "onsetDateTimeType", - hasProperty( - "value", - equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))), - hasResource(hasProperty("onsetDateTimeType", hasProperty("value", equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))))); - } - - @Test - public void shouldSearchForAllConditionsAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Condition/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Condition.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - assertThat(entries.size(), equalTo(2)); - } - - @Test - public void shouldReturnSortedAndFilteredSearchResultsForConditionsAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition?onset-date=2008&_sort=-onset-date").accept(FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries.size(), equalTo(2)); - assertThat(entries, - containsInRelativeOrder( - hasResource(hasProperty( - "onsetDateTimeType", - hasProperty( - "value", - equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))), - hasResource(hasProperty("onsetDateTimeType", hasProperty("value", equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))))); - } - - @Test - public void shouldReturnCountForConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition?_summary=count").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle result = readBundleResponse(response); - - assertThat(result, notNullValue()); - assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(result, hasProperty("total", equalTo(2))); - } - - @Test - public void shouldReturnCountForConditionAsXml() throws Exception { - MockHttpServletResponse response = get("/Condition?_summary=count").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle result = readBundleResponse(response); - - assertThat(result, notNullValue()); - assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(result, hasProperty("total", equalTo(2))); - } - - @Test - public void shouldReturnAnEtagHeaderWhenRetrievingAnExistingCondition() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - - assertThat(response.getHeader("etag"), notNullValue()); - assertThat(response.getHeader("etag"), startsWith("W/")); - - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getMeta().getVersionId(), notNullValue()); - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotModifiedWhenRetrievingAnExistingConditionWithAnEtag() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - assertThat(response.getHeader("etag"), notNullValue()); - - String etagValue = response.getHeader("etag"); - - response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).ifNoneMatchHeader(etagValue).go(); - - assertThat(response, isOk()); - assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); - } -} diff --git a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/ConditionResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionResourceProviderIntegrationTest.java similarity index 99% rename from integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/ConditionResourceProviderIntegrationTest.java rename to integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionResourceProviderIntegrationTest.java index 9bccd01385..c61acb8913 100644 --- a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r3/ConditionResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ConditionResourceProviderIntegrationTest.java @@ -7,7 +7,7 @@ * 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.provider.r3; +package org.openmrs.module.fhir2.providers.r3; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,8 +38,6 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.providers.r3.BaseFhirR3IntegrationTest; -import org.openmrs.module.fhir2.providers.r3.ConditionFhirResourceProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/DiagnosticReportResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/DiagnosticReportResourceProviderIntegrationTest.java index c356855b04..418bf2d16b 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/DiagnosticReportResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/DiagnosticReportResourceProviderIntegrationTest.java @@ -68,7 +68,6 @@ public class DiagnosticReportResourceProviderIntegrationTest extends BaseFhirR3I @Override public void setup() throws Exception { super.setup(); - executeDataSet(DATA_XML); } diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/MedicationRequestFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/MedicationRequestFhirResourceProviderIntegrationTest.java index af2af2fc0f..bc593b56e0 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/MedicationRequestFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/MedicationRequestFhirResourceProviderIntegrationTest.java @@ -9,6 +9,7 @@ */ package org.openmrs.module.fhir2.providers.r3; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; @@ -18,12 +19,17 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; +import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; +import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; +import java.io.InputStream; import java.util.List; +import java.util.Objects; import lombok.AccessLevel; import lombok.Getter; import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.MedicationRequest; import org.junit.Before; import org.junit.Test; @@ -36,10 +42,12 @@ public class MedicationRequestFhirResourceProviderIntegrationTest extends BaseFh private static final String MEDICATION_REQUEST_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml"; - private static final String MEDICATION_REQUEST_UUID = "6d0ae116-707a-4629-9850-f15206e63ab0"; + private static final String MEDICATION_REQUEST_UUID = "546ba5a6-5aa6-4325-afc0-50bc00d5ffa1"; private static final String WRONG_MEDICATION_REQUEST_UUID = "6d0ae116-0000-4629-9850-f15206e63ab0"; + private static final String JSON_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_patch.json"; + private static final String PATIENT_UUID = "86526ed5-3c11-11de-a0ba-001e3766667a"; @Getter(AccessLevel.PUBLIC) @@ -117,6 +125,7 @@ public void shouldSearchForExistingMedicationRequestsAsJson() throws Exception { Bundle results = readBundleResponse(response); assertThat(results, notNullValue()); + System.out.println(results.getIdElement()); assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); assertThat(results.hasEntry(), is(true)); @@ -157,7 +166,7 @@ public void shouldSearchForExistingMedicationRequestsAsXML() throws Exception { Bundle results = readBundleResponse(response); - assertThat(results, notNullValue()); + assertThat(results.getEntry(), notNullValue()); assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); assertThat(results.hasEntry(), is(true)); @@ -212,7 +221,7 @@ public void shouldReturnCountForMedicationRequestAsXml() throws Exception { Bundle result = readBundleResponse(response); - assertThat(result, notNullValue()); + assertThat(result.getTotal(), notNullValue()); assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET)); assertThat(result, hasProperty("total", equalTo(11))); } @@ -255,4 +264,37 @@ public void shouldReturnNotModifiedWhenRetrievingAnExistingMedicationRequestWith assertThat(response, isOk()); assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); } + + @Test + public void shouldPatchExistingMedicationRequestViaJson() throws Exception { + String jsonMedicationRequestPatch; + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_MEDICATION_REQUEST_PATH)) { + Objects.requireNonNull(is); + jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) + .jsonMergePatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + MedicationRequest medicationRequest = readResponse(response); + + assertThat(medicationRequest, notNullValue()); + assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); + assertThat(medicationRequest, validResource()); + + // confirm that the fulfiller extension has been updated + Extension extension = null; + for (Extension e : medicationRequest.getExtension()) { + if (e.getUrl().equalsIgnoreCase(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS)) { + extension = e; + break; + } + } + assertThat(extension, notNullValue()); + assertThat(extension.getValue().toString(), is("COMPLETED")); + } } diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java index d56a9914d6..7ee4a8281b 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/ObservationFhirResourceProviderIntegrationTest.java @@ -55,23 +55,23 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR3IntegrationTest { - private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml"; + private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml"; private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.json"; private static final String XML_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.xml"; - private static final String OBS_UUID = "39fb7f47-e80a-4056-9285-bd798be13c63"; + private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0"; - private static final String OBS_CONCEPT_UUID = "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - private static final String OBS_CONCEPT_DISPLAY_NAME = "Weight"; + private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure"; - private static final String CIEL_SYSTEM_URI = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; + private static final String CIEL_SYSTEM_URN = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; - private static final String OBS_CONCEPT_CIEL_ID = "5089"; + private static final String OBS_CONCEPT_CIEL_ID = "5085"; - private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(50.0); + private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0); private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0); @@ -94,7 +94,6 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR3In @Override public void setup() throws Exception { super.setup(); - executeDataSet(OBS_DATA_XML); } @@ -115,7 +114,7 @@ public void shouldReturnExistingObservationAsJson() throws Exception { assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); + allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); // verify expected value @@ -176,7 +175,7 @@ public void shouldReturnExistingObservationAsXML() throws Exception { assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID))))); assertThat(observation.getCode().getCoding(), hasItem( - allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); + allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID))))); assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME)); // verify expected value @@ -1402,6 +1401,74 @@ public void shouldReturnNotModifiedWhenRetrievingAnExistingObservationWithAnEtag assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); } + @Test + public void shouldReturnCorrectInterpretationAsJson() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + + assertThat(observation.getInterpretation().getCodingFirstRep().getSystem(), + equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); + assertThat(observation.getInterpretation().getCodingFirstRep().getCode(), equalTo("N")); + assertThat(observation.getInterpretation().getCodingFirstRep().getDisplay(), equalTo("Normal")); + } + + @Test + public void shouldReturnCorrectInterpretationAsXML() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + + assertThat(observation.getInterpretation().getCodingFirstRep().getSystem(), + equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); + assertThat(observation.getInterpretation().getCodingFirstRep().getCode(), equalTo("N")); + assertThat(observation.getInterpretation().getCodingFirstRep().getDisplay(), equalTo("Normal")); + } + + @Test + public void shouldReturnCorrectStatusAsJSON() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); + } + + @Test + public void shouldReturnCorrectStatusAsXML() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); + } + private int getDistinctEncounterDatetime(List resultList) { List results = resultList.stream().map(Bundle.BundleEntryComponent::getResource) .filter(it -> it instanceof Observation) diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionFhirResourceProviderIntegrationTest.java deleted file mode 100644 index bba184a1cf..0000000000 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionFhirResourceProviderIntegrationTest.java +++ /dev/null @@ -1,501 +0,0 @@ -/* - * 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.r4; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; - -import java.io.InputStream; -import java.sql.Date; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.List; - -import lombok.AccessLevel; -import lombok.Getter; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Condition; -import org.hl7.fhir.r4.model.OperationOutcome; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; - -public class ConditionFhirResourceProviderIntegrationTest extends BaseFhirR4IntegrationTest { - - private static final String CONDITION_UUID = "86sgf-1f7d-4394-a316-0a458edf28c4"; - - private static final String OBS_CONDITION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml"; - - private static final String CONDITION_SUBJECT_UUID = "da7f524f-27ce-4bb2-86d6-6d1d05312bd5"; - - private static final String EXISTING_OBS_CONDITION_SUBJECT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; - - private static final String WRONG_CONDITION_UUID = "950d965d-a935-429f-945f-75a502a90188"; - - private static final String JSON_CREATE_CONDITION_DOCUMENT = "org/openmrs/module/fhir2/providers/ConditionWebTest_create.json"; - - private static final String XML_CREATE_CONDITION_DOCUMENT = "org/openmrs/module/fhir2/providers/ConditionWebTest_create.xml"; - - @Getter(AccessLevel.PUBLIC) - @Autowired - private ConditionFhirResourceProvider resourceProvider; - - @Before - public void setUp() throws Exception { - super.setup(); - executeDataSet(OBS_CONDITION_INITIAL_DATA_XML); - } - - @Test - public void shouldReturnConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), equalTo(CONDITION_UUID)); - - assertThat(condition.getOnsetDateTimeType().getValue(), - equalTo(Date.from(LocalDateTime.of(2008, 07, 01, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))); - - assertThat(condition.hasSubject(), is(true)); - assertThat(condition.getSubject().getReference(), equalTo("Patient/" + EXISTING_OBS_CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenConditionNotFoundAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnConditionAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), equalTo(CONDITION_UUID)); - - assertThat(condition.getOnsetDateTimeType().getValue(), - equalTo(Date.from(LocalDateTime.of(2008, 07, 01, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))); - - assertThat(condition.hasSubject(), is(true)); - assertThat(condition.getSubject().getReference(), equalTo("Patient/" + EXISTING_OBS_CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotFoundWhenConditionNotFoundAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldCreateNewConditionAsJson() throws Exception { - String jsonCondition; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_CONDITION_DOCUMENT)) { - assertThat(is, notNullValue()); - jsonCondition = inputStreamToString(is, UTF_8); - assertThat(jsonCondition, notNullValue()); - } - - MockHttpServletResponse response = post("/Condition").accept(FhirMediaTypes.JSON).jsonContent(jsonCondition).go(); - - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), containsString("/Condition/")); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentType(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), notNullValue()); - assertThat(condition.getCode(), notNullValue()); - assertThat(condition.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(condition.getSubject(), notNullValue()); - assertThat(condition.getSubject().getReference(), endsWith(CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - - response = get("/Condition/" + condition.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - assertThat(response, isOk()); - Condition newCondition = readResponse(response); - assertThat(newCondition.getId(), equalTo(condition.getId())); - } - - @Test - public void shouldCreateNewConditionAsXML() throws Exception { - String xmlCondition; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_CONDITION_DOCUMENT)) { - assertThat(is, notNullValue()); - xmlCondition = inputStreamToString(is, UTF_8); - assertThat(xmlCondition, notNullValue()); - } - - MockHttpServletResponse response = post("/Condition").accept(FhirMediaTypes.XML).xmlContent(xmlCondition).go(); - - assertThat(response, isCreated()); - assertThat(response.getHeader("Location"), containsString("/Condition/")); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentType(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getIdElement().getIdPart(), notNullValue()); - assertThat(condition.getCode().getCoding(), - hasItem(hasProperty("code", equalTo("116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))); - assertThat(condition.getSubject().getReference(), endsWith(CONDITION_SUBJECT_UUID)); - - assertThat(condition, validResource()); - - response = get("/Condition/" + condition.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - Condition newCondition = readResponse(response); - - assertThat(newCondition.getId(), equalTo(condition.getId())); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchConditionIdAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + CONDITION_UUID).jsonContent(toJson(condition)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + WRONG_CONDITION_UUID).jsonContent(toJson(condition)).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchConditionIdAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + CONDITION_UUID).xmlContent(toXML(condition)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isBadRequest()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldReturnNotFoundWhenUpdatingNonExistentConditionAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), equalTo(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - condition.setId(WRONG_CONDITION_UUID); - - response = put("/Condition/" + WRONG_CONDITION_UUID).xmlContent(toXML(condition)).accept(FhirMediaTypes.XML).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldDeleteExistingCondition() throws Exception { - MockHttpServletResponse response = delete("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - - response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, statusEquals(HttpStatus.GONE)); - } - - @Test - public void shouldReturnNotFoundWhenDeletingNonExistentCondition() throws Exception { - MockHttpServletResponse response = delete("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isNotFound()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - OperationOutcome operationOutcome = readOperationOutcome(response); - - assertThat(operationOutcome, notNullValue()); - assertThat(operationOutcome.hasIssue(), is(true)); - } - - @Test - public void shouldSearchForAllConditionsAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Condition/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Condition.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - assertThat(entries.size(), equalTo(2)); - } - - @Test - public void shouldReturnSortedAndFilteredSearchResultsForConditionsAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition?clinical-status=active?onset-date=2008&_sort=-onset-date") - .accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries.size(), equalTo(2)); - assertThat(entries, - containsInRelativeOrder( - hasResource(hasProperty( - "onsetDateTimeType", - hasProperty( - "value", - equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))), - hasResource(hasProperty("onsetDateTimeType", hasProperty("value", equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))))); - } - - @Test - public void shouldSearchForAllConditionsAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Condition/")))); - assertThat(entries, everyItem(hasResource(instanceOf(Condition.class)))); - assertThat(entries, everyItem(hasResource(validResource()))); - assertThat(entries.size(), equalTo(2)); - } - - @Test - public void shouldReturnSortedAndFilteredSearchResultsForConditionsAsXML() throws Exception { - MockHttpServletResponse response = get("/Condition?&onset-date=2008&_sort=-onset-date").accept(FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle results = readBundleResponse(response); - - assertThat(results, notNullValue()); - assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(results.hasEntry(), is(true)); - - List entries = results.getEntry(); - - assertThat(entries.size(), equalTo(2)); - assertThat(entries, - containsInRelativeOrder( - hasResource(hasProperty( - "onsetDateTimeType", - hasProperty( - "value", - equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))), - hasResource(hasProperty("onsetDateTimeType", hasProperty("value", equalTo( - Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))))); - } - - @Test - public void shouldReturnCountForConditionAsJson() throws Exception { - MockHttpServletResponse response = get("/Condition?_summary=count").accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle result = readBundleResponse(response); - - assertThat(result, notNullValue()); - assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(result, hasProperty("total", equalTo(2))); - } - - @Test - public void shouldReturnCountForConditionAsXml() throws Exception { - MockHttpServletResponse response = get("/Condition?_summary=count").accept(FhirMediaTypes.XML).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Bundle result = readBundleResponse(response); - - assertThat(result, notNullValue()); - assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET)); - assertThat(result, hasProperty("total", equalTo(2))); - } - - @Test - public void shouldReturnAnEtagHeaderWhenRetrievingAnExistingCondition() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - - assertThat(response.getHeader("etag"), notNullValue()); - assertThat(response.getHeader("etag"), startsWith("W/")); - - assertThat(response.getContentAsString(), notNullValue()); - - Condition condition = readResponse(response); - - assertThat(condition, notNullValue()); - assertThat(condition.getMeta().getVersionId(), notNullValue()); - assertThat(condition, validResource()); - } - - @Test - public void shouldReturnNotModifiedWhenRetrievingAnExistingConditionWithAnEtag() throws Exception { - MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - assertThat(response.getHeader("etag"), notNullValue()); - - String etagValue = response.getHeader("etag"); - - response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).ifNoneMatchHeader(etagValue).go(); - - assertThat(response, isOk()); - assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); - } -} diff --git a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/ConditionResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionResourceProviderIntegrationTest.java similarity index 99% rename from integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/ConditionResourceProviderIntegrationTest.java rename to integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionResourceProviderIntegrationTest.java index 2a04270451..7ec1690f5a 100644 --- a/integration-tests-2.2/src/test/java/org/openmrs/module/fhir2/provider/r4/ConditionResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ConditionResourceProviderIntegrationTest.java @@ -7,7 +7,7 @@ * 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.provider.r4; +package org.openmrs.module.fhir2.providers.r4; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; @@ -39,8 +39,6 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.providers.r4.BaseFhirR4IntegrationTest; -import org.openmrs.module.fhir2.providers.r4.ConditionFhirResourceProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/MedicationRequestFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/MedicationRequestFhirResourceProviderIntegrationTest.java index 1a74c27804..2a71dadb4d 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/MedicationRequestFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/MedicationRequestFhirResourceProviderIntegrationTest.java @@ -9,6 +9,7 @@ */ package org.openmrs.module.fhir2.providers.r4; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; @@ -18,8 +19,12 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; +import static org.openmrs.module.fhir2.FhirConstants.OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS; +import static org.openmrs.module.fhir2.api.util.GeneralUtils.inputStreamToString; +import java.io.InputStream; import java.util.List; +import java.util.Objects; import lombok.AccessLevel; import lombok.Getter; @@ -39,6 +44,12 @@ public class MedicationRequestFhirResourceProviderIntegrationTest extends BaseFh private static final String WRONG_MEDICATION_REQUEST_UUID = "6d0ae116-0000-4629-9850-f15206e63ab0"; + private static final String JSON_MERGE_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_patch.json"; + + private static final String JSON_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_json_patch.json"; + + private static final String XML_PATCH_MEDICATION_REQUEST_PATH = "org/openmrs/module/fhir2/providers/MedicationRequest_xml_patch.xml"; + private static final String PATIENT_UUID = "86526ed5-3c11-11de-a0ba-001e3766667a"; @Getter(AccessLevel.PUBLIC) @@ -66,6 +77,14 @@ public void shouldReturnExistingMedicationRequestAsJson() throws Exception { assertThat(medicationRequest, notNullValue()); assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); assertThat(medicationRequest, validResource()); + + // confirm that the new fulfiller extension has been added + assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), + notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + is("RECEIVED")); + } @Test @@ -92,6 +111,13 @@ public void shouldReturnExistingMedicationRequestAsXML() throws Exception { assertThat(medicationRequest, notNullValue()); assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); assertThat(medicationRequest, validResource()); + + // confirm that the new fulfiller extension has been added + assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), + notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + is("RECEIVED")); } @Test @@ -104,6 +130,94 @@ public void shouldThrow404ForNonExistingMedicationRequestAsXML() throws Exceptio assertThat(response.getContentAsString(), notNullValue()); } + @Test + public void shouldPatchExistingMedicationRequestUsingJsonMergePatch() throws Exception { + String jsonMedicationRequestPatch; + try (InputStream is = this.getClass().getClassLoader() + .getResourceAsStream(JSON_MERGE_PATCH_MEDICATION_REQUEST_PATH)) { + Objects.requireNonNull(is); + jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) + .jsonMergePatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + MedicationRequest medicationRequest = readResponse(response); + + assertThat(medicationRequest, notNullValue()); + assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); + assertThat(medicationRequest, validResource()); + + // confirm that the fulfiller extension has been updated + assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), + notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + is("COMPLETED")); + } + + @Test + public void shouldPatchExistingMedicationRequestUsingJsonPatch() throws Exception { + String jsonMedicationRequestPatch; + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_MEDICATION_REQUEST_PATH)) { + Objects.requireNonNull(is); + jsonMedicationRequestPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) + .jsonPatch(jsonMedicationRequestPatch).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + MedicationRequest medicationRequest = readResponse(response); + + assertThat(medicationRequest, notNullValue()); + assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); + assertThat(medicationRequest, validResource()); + + // confirm that the fulfiller extension has been updated + assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), + notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + is("COMPLETED")); + } + + @Test + public void shouldPatchExistingMedicationRequestUsingXmlPatch() throws Exception { + String xmlMedicationRequestPatch; + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_MEDICATION_REQUEST_PATH)) { + Objects.requireNonNull(is); + xmlMedicationRequestPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/MedicationRequest/" + MEDICATION_REQUEST_UUID) + .xmlPatch(xmlMedicationRequestPatch).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + MedicationRequest medicationRequest = readResponse(response); + + assertThat(medicationRequest, notNullValue()); + assertThat(medicationRequest.getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID)); + assertThat(medicationRequest, validResource()); + + // confirm that the fulfiller extension has been updated + assertThat(medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS), + notNullValue()); + assertThat( + medicationRequest.getExtensionByUrl(OPENMRS_FHIR_EXT_MEDICATION_REQUEST_FULFILLER_STATUS).getValue().toString(), + is("COMPLETED")); + } + @Test public void shouldSearchForExistingMedicationRequestsAsJson() throws Exception { MockHttpServletResponse response = get("/MedicationRequest").accept(FhirMediaTypes.JSON).go(); diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java index 1c927c84c7..b2903f090d 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java @@ -55,7 +55,7 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4IntegrationTest { - private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml"; + private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml"; private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create.json"; @@ -71,17 +71,17 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4In private static final String XML_PATCH_OBSERVATION_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_xml_patch.xml"; - private static final String OBS_UUID = "39fb7f47-e80a-4056-9285-bd798be13c63"; + private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0"; - private static final String OBS_CONCEPT_UUID = "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - private static final String OBS_CONCEPT_DISPLAY_NAME = "Weight"; + private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure"; private static final String CIEL_SYSTEM_URN = "https://openconceptlab.org/orgs/CIEL/sources/CIEL"; - private static final String OBS_CONCEPT_CIEL_ID = "5089"; + private static final String OBS_CONCEPT_CIEL_ID = "5085"; - private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(50.0); + private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0); private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0); @@ -1376,29 +1376,6 @@ public void shouldReturnLastnEncountersObservationsWhenNoParamterIsGivenAsXml() assertThat(getDistinctEncounterDatetime(entries), lessThanOrEqualTo(1)); } - @Test - public void shouldUpdateExistingObservationAsJson() throws Exception { - String jsonObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(OBS_JSON_UPDATE_PATH)) { - Objects.requireNonNull(is); - jsonObs = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = put("/Observation/" + OBS_UUID).jsonContent(jsonObs).accept(FhirMediaTypes.JSON) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation updatedObservation = readResponse(response); - - assertThat(updatedObservation, notNullValue()); - assertThat(updatedObservation.getIdElement().getIdPart(), not(equalTo(OBS_UUID))); - assertThat(updatedObservation.getCode().getCodingFirstRep().getCode(), is("5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); - assertThat(updatedObservation, validResource()); - } - @Test public void shouldReturnNotFoundWhenUpdatingNonExistentObservationAsJson() throws Exception { MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); @@ -1437,29 +1414,6 @@ public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchObservationIdAsJson( assertThat(operationOutcome.hasIssue(), is(true)); } - @Test - public void shouldUpdateExistingObservationAsXml() throws Exception { - String xmlObs; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(OBS_XML_UPDATE_PATH)) { - Objects.requireNonNull(is); - xmlObs = inputStreamToString(is, UTF_8); - } - - MockHttpServletResponse response = put("/Observation/" + OBS_UUID).xmlContent(xmlObs).accept(FhirMediaTypes.XML) - .go(); - - assertThat(response, isOk()); - assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); - assertThat(response.getContentAsString(), notNullValue()); - - Observation updatedObservation = readResponse(response); - - assertThat(updatedObservation, notNullValue()); - assertThat(updatedObservation.getIdElement().getIdPart(), not(equalTo(OBS_UUID))); - assertThat(updatedObservation.getCode().getCodingFirstRep().getCode(), is("5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); - assertThat(updatedObservation, validResource()); - } - @Test public void shouldReturnNotFoundWhenUpdatingNonExistentObservationAsXml() throws Exception { MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); @@ -1606,6 +1560,74 @@ public void shouldReturnNotModifiedWhenRetrievingAnExistingObservationWithAnEtag assertThat(response, statusEquals(HttpStatus.NOT_MODIFIED)); } + @Test + public void shouldReturnCorrectInterpretationAsJson() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getSystem(), + equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getCode(), equalTo("N")); + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getDisplay(), equalTo("Normal")); + } + + @Test + public void shouldReturnCorrectInterpretationAsXML() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getSystem(), + equalTo(FhirConstants.INTERPRETATION_SYSTEM_URI)); + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getCode(), equalTo("N")); + assertThat(observation.getInterpretationFirstRep().getCodingFirstRep().getDisplay(), equalTo("Normal")); + } + + @Test + public void shouldReturnCorrectStatusAsJSON() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); + } + + @Test + public void shouldReturnCorrectStatusAsXML() throws Exception { + MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Observation observation = readResponse(response); + + assertThat(observation, notNullValue()); + assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID)); + assertThat(observation.getStatus(), equalTo(Observation.ObservationStatus.FINAL)); + } + private int getDistinctEncounterDatetime(List resultList) { List results = resultList.stream().map(Bundle.BundleEntryComponent::getResource) .filter(it -> it instanceof Observation).map(result -> encounterDao diff --git a/omod/pom.xml b/omod/pom.xml index a24d81b7ec..e6512ed458 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -1,148 +1,138 @@ - - 4.0.0 - - org.openmrs.module - fhir2 - 1.12.0-SNAPSHOT - - - fhir2-omod - jar - FHIR2 OMOD - OMOD for FHIR2 - - - - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.version} - - - ${project.parent.groupId} - ${project.parent.artifactId}-api - ${project.version} - test-jar - tests - test - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.1 - ${project.parent.version} - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.2 - ${project.parent.version} - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.5 - ${project.parent.version} - - - ${project.parent.groupId} - ${project.parent.artifactId}-api-2.6 - ${project.parent.version} - - - ${project.parent.groupId} - ${project.parent.artifactId}-test-data - ${project.parent.version} - test - - - org.openmrs.web - openmrs-web - provided - - - servlet-api - javax.servlet - - - org.javassist - javassist - - - - - ca.uhn.hapi.fhir - hapi-fhir-base - - - ca.uhn.hapi.fhir - hapi-fhir-server - - - org.apache.commons - commons-lang3 - - - com.google.guava - guava - - - org.projectlombok - lombok - - - org.thymeleaf - thymeleaf - - - com.github.ben-manes.caffeine - caffeine - - - commons-io - commons-io - - - javax.servlet - javax.servlet-api - - - com.github.java-json-tools - json-patch - - - com.fasterxml.jackson.core - jackson-databind - - - - - ${project.parent.artifactId}-${project.parent.version} - - - org.jacoco - jacoco-maven-plugin - - - org.commonjava.maven.plugins - directory-maven-plugin - - - com.mycila - license-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - net.revelc.code - impsort-maven-plugin - - - org.openmrs.maven.plugins - maven-openmrs-plugin - - - org.apache.maven.plugins - maven-dependency-plugin - - - - + + 4.0.0 + + org.openmrs.module + fhir2 + 2.0.0-SNAPSHOT + + + fhir2-omod + jar + FHIR2 OMOD + OMOD for FHIR2 + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.version} + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.version} + test-jar + tests + test + + + ${project.parent.groupId} + ${project.parent.artifactId}-api-2.5 + ${project.parent.version} + + + ${project.parent.groupId} + ${project.parent.artifactId}-api-2.6 + ${project.parent.version} + + + ${project.parent.groupId} + ${project.parent.artifactId}-test-data + ${project.parent.version} + test + + + org.openmrs.web + openmrs-web + provided + + + servlet-api + javax.servlet + + + org.javassist + javassist + + + + + ca.uhn.hapi.fhir + hapi-fhir-base + + + ca.uhn.hapi.fhir + hapi-fhir-server + + + org.apache.commons + commons-lang3 + + + com.google.guava + guava + + + org.projectlombok + lombok + + + org.thymeleaf + thymeleaf + + + com.github.ben-manes.caffeine + caffeine + + + commons-io + commons-io + + + javax.servlet + javax.servlet-api + + + com.github.java-json-tools + json-patch + + + com.fasterxml.jackson.core + jackson-databind + + + + + ${project.parent.artifactId}-${project.parent.version} + + + org.jacoco + jacoco-maven-plugin + + + org.commonjava.maven.plugins + directory-maven-plugin + + + com.mycila + license-maven-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + net.revelc.code + impsort-maven-plugin + + + org.openmrs.maven.plugins + maven-openmrs-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + + + + diff --git a/omod/src/main/java/org/openmrs/module/fhir2/web/filter/AuthenticationFilter.java b/omod/src/main/java/org/openmrs/module/fhir2/web/filter/AuthenticationFilter.java index 301c0075b6..a8ed773d12 100644 --- a/omod/src/main/java/org/openmrs/module/fhir2/web/filter/AuthenticationFilter.java +++ b/omod/src/main/java/org/openmrs/module/fhir2/web/filter/AuthenticationFilter.java @@ -24,6 +24,8 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.openmrs.api.context.Context; +import org.openmrs.api.context.UsernamePasswordAuthenticationScheme; +import org.openmrs.api.context.UsernamePasswordCredentials; public class AuthenticationFilter implements Filter { @@ -50,7 +52,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha basicAuth = basicAuth.substring(6); // remove the leading "Basic " String decoded = new String(Base64.decodeBase64(basicAuth), StandardCharsets.UTF_8); String[] userAndPass = decoded.split(":"); - Context.authenticate(userAndPass[0], userAndPass[1]); + UsernamePasswordAuthenticationScheme usernamePasswordAuthenticationScheme = new UsernamePasswordAuthenticationScheme(); + usernamePasswordAuthenticationScheme + .authenticate(new UsernamePasswordCredentials(userAndPass[0], userAndPass[1])); } catch (Exception e) { HttpServletResponse httpResponse = (HttpServletResponse) response; diff --git a/omod/src/test/java/org/openmrs/module/fhir2/narrative/MessageResolverTest.java b/omod/src/test/java/org/openmrs/module/fhir2/narrative/MessageResolverTest.java index b508d80c0b..6cbc2bd687 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/narrative/MessageResolverTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/narrative/MessageResolverTest.java @@ -12,7 +12,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doReturn; import java.util.Locale; diff --git a/omod/src/test/java/org/openmrs/module/fhir2/narrative/NarrativeGeneratorTest.java b/omod/src/test/java/org/openmrs/module/fhir2/narrative/NarrativeGeneratorTest.java index f49df10d53..8a5866fd91 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/narrative/NarrativeGeneratorTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/narrative/NarrativeGeneratorTest.java @@ -10,7 +10,7 @@ package org.openmrs.module.fhir2.narrative; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.IOException; diff --git a/pom.xml b/pom.xml index 06ae24a191..820187ce23 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module fhir2 - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT pom FHIR2 Implementation of FHIR R4 for OpenMRS @@ -38,14 +38,10 @@ test-data api - api-2.1 - api-2.2 api-2.5 api-2.6 omod integration-tests - integration-tests-2.1 - integration-tests-2.2 integration-tests-2.6 integration-tests-2.7 e2e-tests @@ -125,6 +121,10 @@ ${openmrsPlatformVersion} provided + + javax.servlet + servlet-api + javax.servlet jstl @@ -155,6 +155,10 @@ tests test + + javax.servlet + servlet-api + javax.servlet jstl @@ -372,16 +376,17 @@ xml-patch 0.3.1 + javax.servlet javax.servlet-api - 3.1.0 + 4.0.1 provided com.fasterxml.jackson.core jackson-databind - 2.13.3 + 2.11.2 org.thymeleaf @@ -409,6 +414,7 @@ caffeine 2.8.2 + junit junit @@ -875,8 +881,8 @@ UTF-8 UTF-8 1.18.26 - 2.0.5 - 2.4.0 + 2.4.1 + 2.4.1 5.4.0 1.0.3 @@ -886,8 +892,6 @@ release api - api-2.1 - api-2.2 api-2.5 api-2.6 omod diff --git a/test-data/pom.xml b/test-data/pom.xml index ba784dd7e5..952250e62c 100644 --- a/test-data/pom.xml +++ b/test-data/pom.xml @@ -3,7 +3,7 @@ fhir2 org.openmrs.module - 1.12.0-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/Immunization_metadata.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/Immunization_metadata.xml index d6060cc978..976be6641e 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/Immunization_metadata.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/Immunization_metadata.xml @@ -23,7 +23,7 @@ - + @@ -48,7 +48,7 @@ - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest_initial_data.xml index dce391c8b2..678a19975d 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest_initial_data.xml @@ -11,7 +11,7 @@ - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest_initial_data.xml index 4bda5e7bcf..640f340550 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest_initial_data.xml @@ -9,8 +9,8 @@ graphic logo is a trademark of OpenMRS Inc. --> - - + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml index a42c4f497d..651bd713d1 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml @@ -12,16 +12,16 @@ - + - - - - - + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirImmunizationDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirImmunizationDaoImplTest_initial_data.xml index 3a419b13ce..b86083f5a3 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirImmunizationDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirImmunizationDaoImplTest_initial_data.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest_initial_data.xml index 47c1293a34..d8b0157d03 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest_initial_data.xml @@ -26,7 +26,7 @@ - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml index 18e28666a9..4db16166ef 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml @@ -9,7 +9,7 @@ graphic logo is a trademark of OpenMRS Inc. --> - + @@ -26,7 +26,7 @@ - - + + + + instructions="2x daily" care_setting="1" order_action="NEW" order_number="1" date_activated="2016-02-01 00:30:00.0" + date_stopped="2018-08-15 00:00:00.0" creator="1" date_created="2016-08-19 12:20:22.0" voided="false" patient_id="102" uuid="6d0ae116-707a-4629-9850-f15206e63auy" + fulfiller_status="RECEIVED"/> - + instructions="2x daily" care_setting="1" order_action="DISCONTINUE" order_number="1" date_activated="2016-02-01 00:30:00.0" + date_stopped="2018-08-15 00:00:00.0" creator="1" date_created="2016-08-19 12:20:22.0" + voided="false" patient_id="102" uuid="b951a436-c775-4dfc-9432-e19446d18c28" + fulfiller_status="RECEIVED"/> @@ -98,19 +98,22 @@ - - - - - - + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml deleted file mode 100644 index 0b921663af..0000000000 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObsConditionDaoImplTest_initial_data.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml index 71ebc1ba7d..56bd5853a1 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml @@ -1,78 +1,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml index 5fb38a3b54..af030ddfa1 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml @@ -9,7 +9,7 @@ graphic logo is a trademark of OpenMRS Inc. --> - + @@ -57,21 +57,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml index 59fad67145..253276a3d5 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml @@ -31,7 +31,7 @@ - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml index 7cedbf9335..42e457e35f 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml @@ -9,7 +9,7 @@ graphic logo is a trademark of OpenMRS Inc. --> - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml index b3a4b02641..d39d3539fb 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml @@ -36,14 +36,14 @@ - + - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/ValueSetFhirResourceProviderIntegrationTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/ValueSetFhirResourceProviderIntegrationTest_initial_data.xml index d36c132fc9..ed022611b1 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/ValueSetFhirResourceProviderIntegrationTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/ValueSetFhirResourceProviderIntegrationTest_initial_data.xml @@ -28,7 +28,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/services/impl/FhirImmunizationService_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/services/impl/FhirImmunizationService_initial_data.xml index d5b02a84ab..088e119e4f 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/services/impl/FhirImmunizationService_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/services/impl/FhirImmunizationService_initial_data.xml @@ -14,21 +14,21 @@ - + - - - - - - + + + + + + - + - - - - - - + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.json b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.json index 17e050bad0..7029fd1767 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.json +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.json @@ -1,22 +1,22 @@ -{ - "resourceType": "Observation", - "status": "preliminary", - "code": { - "coding": [ - { - "code": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" - } - ] - }, - "subject": { - "reference": "Patient/5946f880-b197-400b-9caa-a3c661d23041" - }, - "encounter": { - "reference": "Encounter/6519d653-393b-4118-9c83-a3715b82d4ac" - }, - "effectiveDateTime": "2014-11-25T22:17:00+11:00", - "valueQuantity": { - "value": 156, - "unit": "cm" - } -} +{ + "resourceType": "Observation", + "status": "preliminary", + "code": { + "coding": [ + { + "code": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ] + }, + "subject": { + "reference": "Patient/5946f880-b197-400b-9caa-a3c661d23041" + }, + "encounter": { + "reference": "Encounter/6519d653-393b-4118-9c83-a3715b82d4ac" + }, + "effectiveDateTime": "2014-11-25T22:17:00+11:00", + "valueQuantity": { + "value": 156, + "unit": "cm" + } +} diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.xml index 6c24bfd4b3..9177bc1173 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_create.xml @@ -1,20 +1,20 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.json b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.json index 04a7532558..f3750106db 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.json +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.json @@ -1,23 +1,23 @@ -{ - "resourceType": "Observation", - "id": "39fb7f47-e80a-4056-9285-bd798be13c63", - "status": "preliminary", - "code": { - "coding": [ - { - "code": "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" - } - ] - }, - "subject": { - "reference": "Patient/5946f880-b197-400b-9caa-a3c661d23041" - }, - "encounter": { - "reference": "Encounter/6519d653-393b-4118-9c83-a3715b82d4ac" - }, - "effectiveDateTime": "2014-11-25T22:17:00+11:00", - "valueQuantity": { - "value": 156, - "unit": "cm" - } -} +{ + "resourceType": "Observation", + "id": "b0b9c14f-2123-4c0f-9a5c-918e192629f0", + "status": "preliminary", + "code": { + "coding": [ + { + "code": "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ] + }, + "subject": { + "reference": "Patient/5946f880-b197-400b-9caa-a3c661d23041" + }, + "encounter": { + "reference": "Encounter/6519d653-393b-4118-9c83-a3715b82d4ac" + }, + "effectiveDateTime": "2014-11-25T22:17:00+11:00", + "valueQuantity": { + "value": 156, + "unit": "cm" + } +} diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.xml index f37b84e4ee..b574705af7 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/ObservationWebTest_update.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +