use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.
the class FhirConditionServiceImplTest method create_shouldCreateNewCondition.
@Test
public void create_shouldCreateNewCondition() {
when(translator.toFhirResource(obsCondition)).thenReturn(condition);
when(dao.createOrUpdate(obsCondition)).thenReturn(obsCondition);
when(translator.toOpenmrsType(condition)).thenReturn(obsCondition);
org.hl7.fhir.r4.model.Condition result = fhirConditionService.create(condition);
assertThat(result, notNullValue());
assertThat(result.getId(), notNullValue());
assertThat(result.getId(), equalTo(OBS_UUID));
}
use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.
the class FhirConditionServiceImplTest method searchConditions_shouldReturnTranslatedConditionReturnedByDao.
@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")));
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(OBS_UUID));
DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE);
SortSpec sort = new SortSpec("sort param");
HashSet<Include> includes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference).addParameter(FhirConstants.CODED_SEARCH_HANDLER, codeList).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.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obsCondition));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(obsCondition)).thenReturn(condition);
IBundleProvider result = fhirConditionService.searchConditions(patientReference, codeList, clinicalList, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes);
List<IBaseResource> resultList = get(result);
assertThat(result, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method create_shouldCreateEncounterFromOpenMrsVisit.
@Test
public void create_shouldCreateEncounterFromOpenMrsVisit() {
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.addCoding().setSystem(FhirConstants.VISIT_TYPE_SYSTEM_URI).setCode("1");
fhirEncounter.setType(Collections.singletonList(codeableConcept));
when(visitService.create(fhirEncounter)).thenReturn(fhirEncounter);
org.hl7.fhir.r4.model.Encounter result = encounterService.create(fhirEncounter);
assertThat(result, notNullValue());
assertThat(result.getId(), equalTo(ENCOUNTER_UUID));
}
use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.
the class FhirLocationServiceImplTest method getLocationByUuid_shouldGetLocationByUuid.
@Test
public void getLocationByUuid_shouldGetLocationByUuid() {
when(locationDao.get(LOCATION_UUID)).thenReturn(location);
when(locationTranslator.toFhirResource(location)).thenReturn(fhirLocation);
org.hl7.fhir.r4.model.Location result = fhirLocationService.get(LOCATION_UUID);
assertThat(result, notNullValue());
assertThat(result.getId(), equalTo(LOCATION_UUID));
assertThat(result.getName(), equalTo(LOCATION_NAME));
assertThat(result.getDescription(), equalTo(LOCATION_DESCRIPTION));
}
use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.
the class TaskVersionConverter method convertTask.
public static org.hl7.fhir.dstu3.model.Task convertTask(org.hl7.fhir.r4.model.Task src) throws FHIRException {
org.hl7.fhir.dstu3.model.Task tgt = new org.hl7.fhir.dstu3.model.Task();
VersionConvertor_30_40.copyDomainResource(src, tgt);
for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) {
tgt.addIdentifier(VersionConvertor_30_40.convertIdentifier(t));
}
// TODO: check
if (src.hasInstantiatesUri()) {
tgt.setDefinition(VersionConvertor_30_40.convertType(src.getInstantiatesUriElement()));
}
// TODO: check
if (src.hasInstantiatesCanonical()) {
tgt.setDefinition(VersionConvertor_30_40.convertType(src.getInstantiatesCanonicalElement()));
}
if (src.hasBasedOn()) {
for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) {
tgt.addBasedOn(VersionConvertor_30_40.convertReference(t));
}
}
if (src.hasGroupIdentifier()) {
tgt.setGroupIdentifier(VersionConvertor_30_40.convertIdentifier(src.getGroupIdentifier()));
}
if (src.hasPartOf()) {
for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) {
tgt.addPartOf(VersionConvertor_30_40.convertReference(t));
}
}
if (src.hasStatus()) {
tgt.setStatusElement(convertTaskStatus(src.getStatusElement()));
}
if (src.hasStatusReason()) {
tgt.setStatusReason(VersionConvertor_30_40.convertCodeableConcept(src.getStatusReason()));
}
if (src.hasBusinessStatus()) {
tgt.setBusinessStatus(VersionConvertor_30_40.convertCodeableConcept(src.getBusinessStatus()));
}
if (src.hasIntent()) {
tgt.setIntentElement(convertTaskIntent(src.getIntentElement()));
}
if (src.hasPriority()) {
tgt.setPriorityElement(convertProcedureRequestPriority(src.getPriorityElement()));
}
if (src.hasCode()) {
tgt.setCode(VersionConvertor_30_40.convertCodeableConcept(src.getCode()));
}
if (src.hasDescription()) {
tgt.setDescriptionElement(VersionConvertor_30_40.convertString(src.getDescriptionElement()));
}
if (src.hasFocus()) {
tgt.setFocus(VersionConvertor_30_40.convertReference(src.getFocus()));
}
if (src.hasFor()) {
tgt.setFor(VersionConvertor_30_40.convertReference(src.getFor()));
}
if (src.hasEncounter()) {
tgt.setContext(VersionConvertor_30_40.convertReference(src.getEncounter()));
}
if (src.hasExecutionPeriod()) {
tgt.setExecutionPeriod(VersionConvertor_30_40.convertPeriod(src.getExecutionPeriod()));
}
if (src.hasAuthoredOn()) {
tgt.setAuthoredOnElement(VersionConvertor_30_40.convertDateTime(src.getAuthoredOnElement()));
}
if (src.hasLastModified()) {
tgt.setLastModifiedElement(VersionConvertor_30_40.convertDateTime(src.getLastModifiedElement()));
}
if (src.hasRequester()) {
tgt.getRequester().setAgent(VersionConvertor_30_40.convertReference(src.getRequester()));
}
if (src.hasPerformerType()) {
for (org.hl7.fhir.r4.model.CodeableConcept t : src.getPerformerType()) tgt.addPerformerType(VersionConvertor_30_40.convertCodeableConcept(t));
}
if (src.hasOwner()) {
tgt.setOwner(VersionConvertor_30_40.convertReference(src.getOwner()));
}
if (src.hasReasonCode()) {
tgt.setReason(VersionConvertor_30_40.convertCodeableConcept(src.getReasonCode()));
}
if (src.hasNote()) {
for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(VersionConvertor_30_40.convertAnnotation(t));
}
if (src.hasRelevantHistory()) {
for (org.hl7.fhir.r4.model.Reference t : src.getRelevantHistory()) tgt.addRelevantHistory(VersionConvertor_30_40.convertReference(t));
}
if (src.hasRestriction()) {
tgt.setRestriction(convertTaskRestriction(src.getRestriction(), tgt.getRestriction()));
}
if (src.hasInput()) {
convertTaskInput(src, tgt);
}
if (src.hasOutput()) {
convertTaskOutput(src, tgt);
}
return tgt;
}
Aggregations