use of org.hl7.fhir.r4b.model.IdType in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toFhirResource_shouldAddProvenanceResources.
@Test
public void toFhirResource_shouldAddProvenanceResources() {
FhirTask task = new FhirTask();
task.setUuid(TASK_UUID);
Provenance provenance = new Provenance();
provenance.setId(new IdType(FhirUtils.newUuid()));
when(provenanceTranslator.getCreateProvenance(task)).thenReturn(provenance);
when(provenanceTranslator.getUpdateProvenance(task)).thenReturn(provenance);
org.hl7.fhir.r4.model.Task result = taskTranslator.toFhirResource(task);
assertThat(result, notNullValue());
assertThat(result.getContained(), not(empty()));
assertThat(result.getContained().size(), greaterThanOrEqualTo(2));
assertThat(result.getContained().stream().anyMatch(resource -> resource.getResourceType().name().equals(Provenance.class.getSimpleName())), is(true));
}
use of org.hl7.fhir.r4b.model.IdType in project openmrs-module-fhir2 by openmrs.
the class ConditionTranslatorImplTest method shouldAddProvenanceToConditionResource.
@Test
public void shouldAddProvenanceToConditionResource() {
Provenance provenance = new Provenance();
provenance.setId(new IdType(FhirUtils.newUuid()));
when(provenanceTranslator.getCreateProvenance(openmrsCondition)).thenReturn(provenance);
when(provenanceTranslator.getUpdateProvenance(openmrsCondition)).thenReturn(provenance);
org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(openmrsCondition);
List<Resource> resources = result.getContained();
assertThat(resources, Matchers.notNullValue());
assertThat(resources, Matchers.not(empty()));
assertThat(resources.stream().findAny().isPresent(), CoreMatchers.is(true));
assertThat(resources.stream().findAny().get().isResource(), CoreMatchers.is(true));
assertThat(resources.stream().findAny().get().getResourceType().name(), Matchers.equalTo(Provenance.class.getSimpleName()));
}
use of org.hl7.fhir.r4b.model.IdType in project elexis-server by elexis.
the class ObservationResourceProvider method createObservation.
@Create
public MethodOutcome createObservation(@ResourceParam Observation observation) {
MethodOutcome outcome = new MethodOutcome();
Optional<IObservation> exists = getTransformer().getLocalObject(observation);
if (exists.isPresent()) {
outcome.setCreated(false);
outcome.setId(new IdType(observation.getId()));
} else {
Optional<IObservation> created = getTransformer().createLocalObject(observation);
if (created.isPresent()) {
outcome.setCreated(true);
outcome.setId(new IdType(created.get().getId()));
} else {
throw new InternalErrorException("Creation failed");
}
}
return outcome;
}
use of org.hl7.fhir.r4b.model.IdType in project elexis-server by elexis.
the class ResourceProviderUtil method updateResource.
protected <T extends BaseResource, U extends Identifiable> MethodOutcome updateResource(IdType theId, IFhirTransformer<T, U> transformer, T fhirObject, Logger log) {
String versionId = theId.getVersionIdPart();
Optional<U> localObject = transformer.getLocalObject(fhirObject);
MethodOutcome outcome = new MethodOutcome();
if (localObject.isPresent()) {
if (versionId == null) {
log.warn("Version agnostic update on {}", localObject.get());
}
if (versionId != null && !versionId.equals(localObject.get().getLastupdate().toString())) {
throw new ResourceVersionConflictException("Expected version " + localObject.get().getLastupdate().toString());
}
try {
transformer.updateLocalObject(fhirObject, localObject.get());
} catch (IFhirTransformerException e) {
OperationOutcome opOutcome = generateOperationOutcome(e);
throw new PreconditionFailedException(e.getMessage(), opOutcome);
}
Optional<T> updatedObject = transformer.getFhirObject(localObject.get());
if (updatedObject.isPresent()) {
outcome.setId(updatedObject.get().getIdElement());
outcome.setResource(updatedObject.get());
return outcome;
}
log.warn("Object update failed [{}]", fhirObject);
throw new InternalErrorException("Object update failed");
} else {
OperationOutcome issueOutcome = new OperationOutcome();
issueOutcome.addIssue().setDiagnostics("No local object found");
outcome.setOperationOutcome(issueOutcome);
}
return outcome;
}
use of org.hl7.fhir.r4b.model.IdType in project elexis-server by elexis.
the class ServiceRequestResourceProvider method createProcedureRequest.
@Create
public MethodOutcome createProcedureRequest(@ResourceParam ServiceRequest procedureRequest) {
MethodOutcome outcome = new MethodOutcome();
Optional<IProcedureRequest> exists = getTransformer().getLocalObject(procedureRequest);
if (exists.isPresent()) {
outcome.setCreated(false);
outcome.setId(new IdType(procedureRequest.getId()));
} else {
Optional<IProcedureRequest> created = getTransformer().createLocalObject(procedureRequest);
if (created.isPresent()) {
outcome.setCreated(true);
outcome.setId(new IdType(created.get().getId()));
} else {
throw new InternalErrorException("Creation failed");
}
}
return outcome;
}
Aggregations