in converter/dicom-cast/src/Microsoft.Health.DicomCast.Core/Features/Worker/FhirTransaction/EndpointPipelineStep.cs [36:102]
public async Task PrepareRequestAsync(FhirTransactionContext context, CancellationToken cancellationToken)
{
EnsureArg.IsNotNull(context, nameof(context));
string queryParameter = $"name={FhirTransactionConstants.EndpointName}&connection-type={FhirTransactionConstants.EndpointConnectionTypeSystem}|{FhirTransactionConstants.EndpointConnectionTypeCode}";
Endpoint endpoint = await _fhirService.RetrieveEndpointAsync(queryParameter, cancellationToken);
FhirTransactionRequestMode requestMode = FhirTransactionRequestMode.None;
if (endpoint == null)
{
endpoint = new Endpoint()
{
Name = FhirTransactionConstants.EndpointName,
Status = Endpoint.EndpointStatus.Active,
ConnectionType = new Coding()
{
System = FhirTransactionConstants.EndpointConnectionTypeSystem,
Code = FhirTransactionConstants.EndpointConnectionTypeCode,
},
Address = _dicomWebEndpoint,
PayloadType = new List<CodeableConcept>
{
new CodeableConcept(string.Empty, string.Empty, FhirTransactionConstants.EndpointPayloadTypeText),
},
PayloadMimeType = new string[]
{
FhirTransactionConstants.DicomMimeType,
},
};
requestMode = FhirTransactionRequestMode.Create;
}
else
{
// Make sure the address matches.
if (!string.Equals(endpoint.Address, _dicomWebEndpoint, StringComparison.Ordinal))
{
// We have found an endpoint with matching name and connection-type but the address does not match.
throw new FhirResourceValidationException(DicomCastCoreResource.MismatchEndpointAddress);
}
}
Bundle.RequestComponent request = requestMode switch
{
FhirTransactionRequestMode.Create => new Bundle.RequestComponent()
{
Method = Bundle.HTTPVerb.POST,
IfNoneExist = queryParameter,
Url = ResourceType.Endpoint.GetLiteral(),
},
_ => null,
};
IResourceId resourceId = requestMode switch
{
FhirTransactionRequestMode.Create => new ClientResourceId(),
_ => endpoint.ToServerResourceId(),
};
context.Request.Endpoint = new FhirTransactionRequestEntry(
requestMode,
request,
resourceId,
endpoint);
}