> ## Documentation Index
> Fetch the complete documentation index at: https://docs.junction.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Importing an Order

> Import externally-placed lab orders into Junction for centralized tracking and result delivery using the correct sample or requisition ID.

<Card horizontal icon="person-digging" color="#57164A">
  This feature is in **closed beta**.

  Interested in this feature? Get in touch with your Customer Success Manager.
</Card>

If you want to track orders with Junction that weren't originally placed with Junction, you can import an order.

<Warning>
  It's crucial that imported orders are created with the correct sample ID. This is the **requisition number** or **control number** for Labcorp orders, or the **lab reference ID** for Quest orders. If in doubt, contact your Junction Customer Success Manager to confirm what you should supply for the sample ID.

  The sample ID must also uniquely identify the order. If you supply an ID that clashes with an existing order, that will result in a validation error.
</Warning>

An imported order can be cancelled, receive results, and function similarly to orders originally placed with Junction, but with one important exception: a requisition will not be created. This means you cannot use the [endpoint to retrieve the requisition](/api-reference/lab-testing/requisition-pdf) for an imported order since Junction does not have access to it.

After an order is successfully imported, it will be in the `requisition_bypassed` state (for example, an imported testkit order would have a `received.testkit.requisition_bypassed` status). This status supports transitioning to the same states that `requisition_created` does.

<Info>
  Since import skips the regular order creation flow, no communications are sent to patients about the order being created, but communications are sent for subsequent events that might occur (order completion, for example).
</Info>

### Example

<CodeGroup>
  ```python Python theme={null}
  from junction import Billing, Gender, Junction, LabTestCollectionMethod, OrderSetRequest, PatientAddress, PatientDetailsWithValidation, PhysicianCreateRequest
  from junction.environment import JunctionEnvironment

  client = Junction(
      api_key="YOUR_API_KEY",
      environment=JunctionEnvironment.SANDBOX,
  )

  data = client.lab_tests.import_order(
      user_id="<user_id>",
      billing_type=Billing.CLIENT_BILL,
      order_set=OrderSetRequest(lab_test_ids=["<lab_test_id>"]),
      collection_method=LabTestCollectionMethod.WALK_IN_TEST,
      physician=PhysicianCreateRequest(first_name="Jane", last_name="Doe", npi=""),
      patient_details=PatientDetailsWithValidation(
          first_name="John",
          last_name="Doe",
          dob="2020-01-01",
          gender=Gender.MALE,
          phone_number="+1123456789",
          email="email@email.com",
      ),
      patient_address=PatientAddress(
          receiver_name="John Doe",
          first_line="123 Main St.",
          second_line="Apt. 208",
          city="San Francisco",
          state="CA",
          zip="91189",
          country="US",
          phone_number="+1123456789",
      ),
      sample_id="1234567890",
  )
  ```

  ```typescript TypeScript theme={null}
  import { JunctionClient, JunctionEnvironment } from "@junction-api/sdk";

  const client = new JunctionClient({
      apiKey: "YOUR_API_KEY",
      environment: JunctionEnvironment.Sandbox,
  });

  const data = await client.labTests.importOrder({
      userId: "<user_id>",
      billingType: "client_bill",
      orderSet: { labTestIds: ["<lab_test_id>"] },
      collectionMethod: "walk_in_test",
      physician: { firstName: "Jane", lastName: "Doe", npi: "" },
      patientDetails: {
          firstName: "John",
          lastName: "Doe",
          dob: "2020-01-01",
          gender: "male",
          phoneNumber: "+1123456789",
          email: "email@email.com",
      },
      patientAddress: {
          receiverName: "John Doe",
          firstLine: "123 Main St.",
          secondLine: "Apt. 208",
          city: "San Francisco",
          state: "CA",
          zip: "91189",
          country: "US",
          phoneNumber: "+1123456789",
      },
      sampleId: "1234567890",
  });
  ```

  ```java Java theme={null}
  import com.junction.api.Junction;
  import com.junction.api.core.Environment;
  import com.junction.api.resources.labtests.requests.ImportOrderBody;
  import com.junction.api.types.Billing;
  import com.junction.api.types.Gender;
  import com.junction.api.types.LabTestCollectionMethod;
  import com.junction.api.types.OrderSetRequest;
  import com.junction.api.types.PatientAddress;
  import com.junction.api.types.PatientDetailsWithValidation;
  import com.junction.api.types.PhysicianCreateRequest;
  import java.util.List;

  Junction client = Junction.builder()
      .apiKey("YOUR_API_KEY")
      .environment(Environment.SANDBOX)
      .build();

  var data = client.labTests().importOrder(
      ImportOrderBody.builder()
          .userId("<user_id>")
          .billingType(Billing.CLIENT_BILL)
          .orderSet(OrderSetRequest.builder()
              .labTestIds(List.of("<lab_test_id>"))
              .build())
          .collectionMethod(LabTestCollectionMethod.WALK_IN_TEST)
          .patientDetails(PatientDetailsWithValidation.builder()
              .firstName("John")
              .lastName("Doe")
              .dob("2020-01-01")
              .gender(Gender.MALE)
              .phoneNumber("+1123456789")
              .email("email@email.com")
              .build())
          .patientAddress(PatientAddress.builder()
              .receiverName("John Doe")
              .firstLine("123 Main St.")
              .city("San Francisco")
              .state("CA")
              .zip("91189")
              .country("US")
              .build())
          .sampleId("1234567890")
          .physician(PhysicianCreateRequest.builder()
              .firstName("Jane")
              .lastName("Doe")
              .npi("")
              .build())
          .build()
  );
  ```

  ```go Go theme={null}
  import (
      "context"

      junction "github.com/junction-api/junction-go"
      "github.com/junction-api/junction-go/client"
      "github.com/junction-api/junction-go/option"
  )

  c := client.NewClient(
      option.WithApiKey("YOUR_API_KEY"),
      option.WithBaseURL(junction.Environments.Sandbox),
  )

  response, err := c.LabTests.ImportOrder(context.TODO(), &junction.ImportOrderBody{
      UserId:           "<user_id>",
      BillingType:      junction.BillingClientBill,
      OrderSet:         &junction.OrderSetRequest{LabTestIds: []string{"<lab_test_id>"}},
      CollectionMethod: junction.LabTestCollectionMethodWalkInTest,
      Physician: &junction.PhysicianCreateRequest{
          FirstName: "Jane",
          LastName:  "Doe",
          Npi:       "",
      },
      PatientDetails: &junction.PatientDetailsWithValidation{
          FirstName:   "John",
          LastName:    "Doe",
          Dob:         "2020-01-01",
          Gender:      junction.GenderMale,
          PhoneNumber: "+1123456789",
          Email:       "email@email.com",
      },
      PatientAddress: &junction.PatientAddress{
          ReceiverName: "John Doe",
          FirstLine:    "123 Main St.",
          City:         "San Francisco",
          State:        "CA",
          Zip:          "91189",
          Country:      "US",
      },
      SampleId: "1234567890",
  })
  if err != nil {
      return err
  }
  fmt.Printf("Received data %s\n", response)
  ```
</CodeGroup>

This example assumes you provide your own physician. The physician must be provided if your team configuration is set up as delegated. The billing type provided must also be appropriate to your team configuration. These aspects will be validated when making the request.

Since the request represents an existing order, we don't perform strict address validation on the patient address, to make it easier to import orders exactly as they were placed in the original interface.

The response object schema is the same as [creating an order](/api-reference/lab-testing/create-order).
