// This module is included in the following assemblies:
// as_connecting-to-fhir.adoc

[id='adding-fhir-connection-update_{context}']
= Updating all fields in a resource on a FHIR server

In an integration, you can update a resource that is on a FHIR server. 
To provide the updated values, add a data mapper step to the flow just before 
a FHIR connection that updates a resource. It is expected that previous 
steps in the flow provide the data that you want the updated resource 
to contain. Map fields in the previous steps to fields in the target 
resource that this FHIR connection updates. 

[CAUTION] 
The updated resource contains only the fields that you map to. 
In other words, in addition to mapping the fields whose values are 
changing, you must map the fields that you want to be in the resource 
and whose values are not changing. If you do not map a particular 
resource field then the connection deletes that field from the 
updated resource.

Be sure to map the resource ID from a previous step to the resource ID 
in this connection. This is the only resource field that the connection 
does not change. If the FHIR server does not already have a resource 
that has the resource ID for the resource to be updated, then the connection 
creates a new resource with that resource ID. This is the only way to add 
a new resource that has a resource ID that you choose.

To update or create a resource, add a FHIR connection to the middle 
of a flow, or as a simple integration’s finish connection.

.Prerequisites
* You created a connection to the FHIR server on which you want to 
update or create a resource. 
* You are creating or editing a flow and {prodname} is prompting you
to add to the integration. Or, {prodname} is prompting you to  add a finish connection. 

.Procedure
. On the *Add to Integration* page, click the plus sign where you 
want to add the connection. Skip this step if {prodname} is
prompting you to choose the finish connection. 
. Click the FHIR connection that you want to use
to update a resource on a FHIR server. 
. On the *Choose an action* page, select *Update*. 
. Click in the *Resource Type* field to display a list
of FHIR resource types. Select or enter the type of resource 
that you want to update or create.
. In the *Contained Resource Types* field, if the resource type 
that you want to update or create contains other resource types, select 
them. Use the *Ctrl* key if you need to select more than one. 
+
Identifying contained resource types lets the data mapper display the fields 
that are in the contained resources. If you do not specify a contained resource 
type then you cannot map to or from any fields that are in the contained 
resource. There is no harm in selecting a resource that is not actually contained.

. Click *Next* to add this connection to the flow. 

. If this flow needs additional steps to obtain the data that you want the 
updated resource to contain, add them before this FHIR connection. 
. In the integration visualization, click the plus sign that is 
before the FHIR connection that updates a resource.
. Click *Data Mapper*. 
. In the data mapper: 
.. Map a resource ID to the target resource ID. This is the only way 
to specify the resource ID for a new resource. 
.. Map to each resource field that you want the updated or new 
resource to contain. Be sure to map fields whose values are not 
changing, as well as fields whose values need to be updated. 
.. Click *Done* to add the data mapper step to the flow. 

.Result
The connection appears in the integration visualization 
where you added it. During execution, the connection 
updates or creates a resource on the FHIR server and returns a 
*MethodOutcome* resource that includes an `id.idPart` field. 
This field contains the updated/created resource's ID, 
which you might want to map 
to a subsequent step in the flow. 
