This page is part of the FHIR Specification (v1.0.2: DSTU 2). The current version which supercedes this version is 5.0.0. For a full list of available versions, see the Directory of published versions
Search TestScript Example (id = "search")
<TestScript xmlns="http://hl7.org/fhir"> <id value="search"/> <text><status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: search</p><p><b>name</b>: Read, Search and Conditional Create and Delete</p><p><b>description</b>: Test Script for testing search, read, and conditional create and delete</p><h3>Fixtures</h3><table><tr><td>-</td><td><b>Resource</b></td></tr><tr><td>*</td><td><a>Patient/patient-example.xml</a></td></tr></table><blockquote><p><b>variable</b></p><p><b>name</b>: V1</p><p><b>sourceId</b>: R1</p><p><b>headerField</b>: Location</p></blockquote><blockquote><p><b>variable</b></p><p><b>name</b>: V2</p><p><b>sourceId</b>: R3</p><p><b>path</b>: fhir:Patient/fhir:name/fhir:given/@value</p></blockquote><blockquote><p><b>setup</b></p><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td><td><b>Type</b></td><td><b>Resource</b></td><td><b>Params</b></td></tr><tr><td>*</td><td>delete</td><td>Patient</td><td>given=John&family=Doe</td></tr></table></blockquote></blockquote><blockquote><p><b>test</b></p><p><b>name</b>: Create</p><p><b>description</b>: Create, read, search, conditional create, conditional delete.</p><blockquote><p><b>metadata</b></p><h3>Links</h3><table><tr><td>-</td><td><b>Url</b></td><td><b>Description</b></td></tr><tr><td>*</td><td><a>http://hl7.org/implement/standards/FHIR-Develop/patient.html</a></td><td>FHIR Patient</td></tr></table><blockquote><p><b>operation</b></p><p><b>type</b>: create</p><p><b>resource</b>: Patient</p><p><b>description</b>: Conditional Create Operation</p><p><b>link</b>: <a>http://hl7-fhir.github.io/http.html#2.1.0.13.1</a></p><p><b>required</b>: true</p><p><b>validated</b>: true</p></blockquote><blockquote><p><b>operation</b></p><p><b>type</b>: delete</p><p><b>resource</b>: Patient</p><p><b>description</b>: Conditional Delete Operation</p><p><b>link</b>: <a>http://hl7-fhir.github.io/http.html#2.1.0.12.1</a></p><p><b>required</b>: true</p><p><b>validated</b>: true</p></blockquote><blockquote><p><b>operation</b></p><p><b>type</b>: read</p><p><b>resource</b>: Patient</p><p><b>description</b>: Patient Read Operation</p><p><b>link</b>: <a>http://hl7.org/implement/standards/FHIR-Develop/http.html#read</a></p><p><b>validated</b>: true</p></blockquote><blockquote><p><b>operation</b></p><p><b>type</b>: search</p><p><b>resource</b>: Patient</p><p><b>description</b>: Patient Search Operation</p><p><b>link</b>: <a>http://hl7-fhir.github.io/http.html#2.1.0.14</a></p><p><b>validated</b>: true</p></blockquote></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Operations</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>action</b></p><h3>Asserts</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote></blockquote></div></text> <url value="http://hl7.org/fhir/TestScript/search"/> <name value="Read, Search and Conditional Create and Delete"/> <status value="draft"/> <description value="Test Script for testing search, read, and conditional create and delete"/> <metadata> <capability> <required value="true"/> <description value="Patient Create and Read Operations"/> <link value="http://hl7.org/implement/standards/FHIR-Develop/http.html#create"/> <link value="http://hl7.org/implement/standards/FHIR-Develop/http.html#read"/> <conformance> <reference value="Conformance/example"/> </conformance> </capability> <capability> <required value="true"/> <description value="Patient Conditional Delete Operation"/> <link value="http://hl7-fhir.github.io/http.html#2.1.0.12.1"/> <conformance> <reference value="Conformance/example"/> </conformance> </capability> <capability> <required value="true"/> <description value="Patient Conditional Create Operation"/> <link value="http://hl7-fhir.github.io/http.html#2.1.0.13.1"/> <conformance> <reference value="Conformance/example"/> </conformance> </capability> </metadata> <fixture id="example-patient"> <resource> <reference value="Patient/example"/> </resource> </fixture> <variable> <name value="V1"/> <headerField value="Location"/> <sourceId value="R1"/> </variable> <variable> <name value="V2"/> <path value="fhir:Patient/fhir:name/fhir:given/@value"/> <sourceId value="R3"/> </variable> <setup> <!-- Conditional Delete --> <action> <operation> <type> <code value="delete"/> </type> <resource value="Patient"/> <params value="given=John&family=Doe"/> </operation> </action> </setup> <test id="Test1"> <name value="Create"/> <description value="Create, read, search, conditional create, conditional delete."/> <metadata> <link> <url value="http://hl7.org/implement/standards/FHIR-Develop/patient.html"/> <description value="FHIR Patient"/> </link> <capability> <validated value="true"/> <description value="Patient Search Operation"/> <link value="http://hl7.org/implement/standards/FHIR-Develop/http.html#search"/> <conformance> <reference value="Conformance/example"/> </conformance> </capability> </metadata> <!-- Create the patient using fixture --> <action> <operation> <type> <code value="create"/> </type> <sourceId value="example-patient"/> </operation> </action> <action> <assert> <responseCode value="201"/> </assert> </action> <!-- Patient search by name. Save the responseBody in 'F1' fixture. Save the responseHeader in H1 --> <action> <operation> <type> <code value="search"/> </type> <resource value="Patient"/> <contentType value="json"/> <params value="?given=John&family=Doe"/> <responseId value="R1"/> </operation> </action> <!-- Verify that the Location in response-header is valid --> <action> <assert> <headerField value="Location"/> <operator value="notEmpty"/> <warningOnly value="true"/> </assert> </action> <!-- Verify that the birthdate got persisted and is being returned properly --> <action> <assert> <operator value="equals"/> <path value="fhir:Patient/fhir:birthDate/@value"/> <sourceId value="R1"/> <value value="1974-12-31"/> </assert> </action> <!-- Verify that the navigation links are valid --> <action> <assert> <navigationLinks value="true"/> <warningOnly value="true"/> </assert> </action> <!-- Use the Location returned earlier to grab the resource to verify that Location was pointing to correct resource. --> <action> <operation> <type> <code value="search"/> </type> <accept value="json"/> <responseId value="R2"/> <url value="${V1}"/> </operation> </action> <action> <assert> <contentType value="json"/> </assert> </action> <action> <assert> <response value="okay"/> </assert> </action> <!-- Search for the resource but this time using the birthdate as a search parameter to make sure search by birthDate works --> <action> <operation> <type> <code value="search"/> </type> <resource value="Patient"/> <accept value="json"/> <params value="?given=John&family=Doe&birthdate=1974-12-31"/> <responseId value="R3"/> </operation> </action> <action> <assert> <contentType value="json"/> </assert> </action> <action> <assert> <response value="okay"/> </assert> </action> <!-- Verify that the birthDate matches expectations --> <action> <assert> <compareToSourceId value="R2"/> <compareToSourcePath value="fhir:Patient/fhir:birthDate/@value"/> <path value="fhir:Patient/fhir:birthDate/@value"/> <sourceId value="R3"/> </assert> </action> <!-- Verify that the name matches expectations --> <action> <assert> <path value="fhir:Patient/fhir:name/fhir:given/@value"/> <sourceId value="R3"/> <value value="John"/> </assert> </action> <!-- Conditional Create --> <action> <operation> <type> <code value="create"/> </type> <requestHeader> <field value="If-None-Exist"/> <value value="Patient?given=John&Doe&birthdate=1974-12-31"/> </requestHeader> <sourceId value="F1"/> </operation> </action> <!-- The response code of 200 verifies that the resource already exists and did not get created --> <action> <assert> <responseCode value="200"/> </assert> </action> <!-- Conditional Delete --> <action> <operation> <type> <code value="delete"/> </type> <resource value="Patient"/> <params value="?given=John&family=Doe&birthdate=1974-12-31"/> </operation> </action> <!-- Search again and make sure the patient has been deleted. This time perform read by id using variable --> <action> <operation> <type> <code value="read"/> </type> <resource value="Patient"/> <params value="/${V2}"/> </operation> </action> <action> <assert> <responseCode value="410"/> </assert> </action> </test> </TestScript>
Usage note: every effort has been made to ensure that the examples are correct and useful, but they are not a normative part of the specification.