request method
REQUEST after creating a request with the above constructors, they can be called to interact with the server by using this method. If necessary, authorization or other headers can be passed in as well
Implementation
Future<Resource> request({Map<String, String>? headers}) async => map(
/// READ
read: (FhirReadRequest request) async => _request(
RestfulRequest.get_,
uri(parameters: parameters),
headers,
'Read',
accept,
mimeType: mimeType,
),
/// VREAD
vRead: (FhirVReadRequest request) async => _request(
RestfulRequest.get_,
uri(parameters: parameters),
headers,
'Vread',
accept,
mimeType: mimeType,
),
/// UPDATE
update: (FhirUpdateRequest request) async => _request(
RestfulRequest.put_,
uri(parameters: parameters),
headers,
'Update',
accept,
resource: (this as FhirUpdateRequest).resource,
mimeType: mimeType,
),
/// PATCH
patch: (FhirPatchRequest request) async => _request(
RestfulRequest.patch_,
uri(parameters: parameters),
headers,
'Patch',
accept,
resource: (this as FhirPatchRequest).resource,
mimeType: mimeType,
),
/// DELETE
delete: (FhirDeleteRequest request) async => _request(
RestfulRequest.delete_,
uri(parameters: parameters),
headers,
'Delete',
accept,
mimeType: mimeType,
),
/// CREATE
create: (FhirCreateRequest request) async => _request(
RestfulRequest.post_,
uri(parameters: parameters),
headers,
'Create',
accept,
resource: (this as FhirCreateRequest).resource,
mimeType: mimeType,
),
/// SEARCH
search: (FhirSearchRequest request) async => _request(
(this as FhirSearchRequest).usePost
? RestfulRequest.post_
: RestfulRequest.get_,
(this as FhirSearchRequest).usePost
? url
: uri(parameters: parameters),
headers,
'Search',
accept,
formData: (this as FhirSearchRequest).usePost
? (this as FhirSearchRequest).formData(parameters: parameters)
: null,
mimeType: mimeType,
),
/// SEARCHALL
searchAll: (FhirSearchAllRequest request) async => _request(
RestfulRequest.get_,
uri(parameters: parameters),
headers,
'Search All',
accept,
mimeType: mimeType,
),
/// CAPABILITIES
capabilities: (FhirCapabilitiesRequest request) async => _request(
RestfulRequest.get_,
uri(parameters: parameters),
headers,
'Capabilities',
accept,
mimeType: mimeType,
),
/// TRANSACTION
transaction: (FhirTransactionRequest request) async {
if ((this as FhirTransactionRequest).bundle.type.toString() !=
'transaction') {
return _operationOutcome(
'A Transaction request was made, but no Bundle was included.');
}
if ((this as FhirTransactionRequest).bundle.entry != null) {
for (final BundleEntry entry
in (this as FhirTransactionRequest).bundle.entry!) {
if (entry.request == null) {
return _operationOutcome(
'Each bundle entry requires a request, but at least one of '
'the entries in this bundle is missing a request.');
} else if (entry.request?.method == null) {
return _operationOutcome(
'Each bundle entry request needs a method type specified, but'
' at least one entry in this bundle is missing a method');
}
}
}
return _request(
RestfulRequest.post_,
uri(),
headers,
'Transaction',
accept,
resource: (this as FhirTransactionRequest).bundle,
mimeType: mimeType,
);
},
/// BATCH
batch: (FhirBatchRequest request) async {
if ((this as FhirBatchRequest).bundle.type.toString() != 'batch') {
return _operationOutcome(
'A Batch request was made, but the included Bundle is not a'
' batch type.');
}
if ((this as FhirBatchRequest).bundle.entry != null) {
for (final BundleEntry entry
in (this as FhirBatchRequest).bundle.entry!) {
if (entry.request == null) {
return _operationOutcome(
'Each bundle entry requires a request, but at least one of '
'the entries in this bundle is missing a request.');
} else if (entry.request?.method == null) {
return _operationOutcome(
'Each bundle entry request needs a method type specified, but'
' at least one entry in this bundle is missing a method');
}
}
}
return _request(
RestfulRequest.post_,
uri(),
headers,
'Batch',
accept,
resource: (this as FhirBatchRequest).bundle,
mimeType: mimeType,
);
},
/// HISTORY
history: (FhirHistoryRequest request) async {
final List<String> parameterList = <String>[];
final List<String> hxList = _hxParameters(
(this as FhirHistoryRequest).count,
(this as FhirHistoryRequest).since,
(this as FhirHistoryRequest).at,
(this as FhirHistoryRequest).reference);
if (hxList.isNotEmpty) {
parameterList.addAll(hxList);
}
if (parameters.isNotEmpty) {
parameterList.addAll(parameters);
}
return _request(
RestfulRequest.get_,
uri(parameters: parameterList),
headers,
'History',
accept,
mimeType: mimeType,
);
},
/// HISTORYTYPE
historyType: (FhirHistoryTypeRequest request) async {
final List<String> parameterList = <String>[];
final List<String> hxList = _hxParameters(
(this as FhirHistoryTypeRequest).count,
(this as FhirHistoryTypeRequest).since,
(this as FhirHistoryTypeRequest).at,
(this as FhirHistoryTypeRequest).reference);
if (hxList.isNotEmpty) {
parameterList.addAll(hxList);
}
if (parameters.isNotEmpty) {
parameterList.addAll(parameters);
}
return _request(
RestfulRequest.get_,
uri(parameters: parameterList),
headers,
'History Type',
accept,
mimeType: mimeType,
);
},
/// HISTORYALL
historyAll: (FhirHistoryAllRequest request) async {
final List<String> parameterList = <String>[];
final List<String> hxList = _hxParameters(
(this as FhirHistoryAllRequest).count,
(this as FhirHistoryAllRequest).since,
(this as FhirHistoryAllRequest).at,
(this as FhirHistoryAllRequest).reference);
if (hxList.isNotEmpty) {
parameterList.addAll(hxList);
}
if (parameters.isNotEmpty) {
parameterList.addAll(parameters);
}
return _request(
RestfulRequest.get_,
uri(parameters: parameterList),
headers,
'History all',
accept,
mimeType: mimeType,
);
},
/// OPERATION
operation: (FhirOperationRequest request) async => _request(
(this as FhirOperationRequest).usePost ||
(this as FhirOperationRequest).fhirParameter != null
? RestfulRequest.post_
: RestfulRequest.get_,
(this as FhirOperationRequest).usePost ||
(this as FhirOperationRequest).fhirParameter != null
? url
: uri(parameters: parameters),
headers,
'Operation',
accept,
resource: ((this as FhirOperationRequest).usePost &&
!(this as FhirOperationRequest).useFormData) ||
(this as FhirOperationRequest).fhirParameter != null
? (this as FhirOperationRequest).fhirParameter
: null,
formData: (this as FhirOperationRequest).usePost &&
(this as FhirOperationRequest).useFormData
? (this as FhirOperationRequest)
.formData(parameters: parameters)
: null,
mimeType: mimeType,
));