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

[id='adding-fhir-connection-create_{context}']
= Creating a resource on a FHIR server

In an integration, you can create and add a resource to a FHIR server.
When you configure the connection's *Create* action, you specify the 
type of the resource that you want to create. 
For example, you might want to add a new patient resource to a FHIR server. 
To create a resource,  
add a FHIR connection to the middle of a flow, or as a simple 
integration's finish connection. 

To populate the values in the new resource, add a data mapper 
step to the flow just before the FHIR connection that you are 
adding in this procedure. It is expected that the previous steps 
in the flow provide the data that you want the new resource to 
contain. Map fields in the previous steps to fields in the target 
resource that this FHIR connection is creating. The new resource 
contains only the fields that you map to. 

When a connection performs the *Create* action to create a new resource on a FHIR server, 
the new resource has an automatically-generated FHIR resource ID. 
If you want to specify the resource 
ID for a new resource, instead of selecting the *Create* action choose the 
xref:adding-fhir-connection-update_fhir[*Update* action] for the connection to perform. 

.Prerequisites
* You created a connection to the FHIR server that you want to add 
a resource to. 
* 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 to the server that you want to add a resource to.  
. On the *Choose an action* page, select *Create*. 
. 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 create.
. In the *Contained Resource Types* field, if the resource type 
that you want to 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. 

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

.Next steps
If this flow needs additional steps to obtain the data that you want 
the new resource to contain, add them before this FHIR connection. 
After those steps are in place, 
add a data mapper step to the flow just before the FHIR connection 
that creates a new resource. In the data mapper step, map to the 
fields in the resource to be created. 

[CAUTION]
Without a data mapper step just 
before a FHIR connection that creates a new resource, the connection 
tries to create an empty resource. Depending on the FHIR server configuration,
this might or might not work.  
