Manually adding `relevantHistory` entries to `Serv...
# support
j
Hi ya'll — is there a way to manually add a provenance to the relevantHistory of a ServiceRequest? I want to add an entry describing from who and when an order was received, and I figured the best way to do that (besides data extension) would be to include it as an entry in the relevant history. Not sure if anybody has a better suggestion in terms of how to do that! For reference I tried to create a Provenance object (using GraphQL rn): https://www.medplum.com/docs/api/fhir/resources/provenance but the returned object is empty and I'm not seeing the Provenance object within the relevant history of the ServiceRequest.
r
Hi @jasonwa.ng , I'm sorry to hear that this wasn't working. Just so you know, in general Medplum recommends avoiding provenance resources if there is a better field to record your information, as Provenance is mainly used by legacy systems. In this case,
ServiceRequest.requester
and
ServiceRequest.authoredOn
are probably the most appropriate
However, we would still expect your GraphQL query to work. Were you following the mutations guide here? https://www.medplum.com/docs/graphql/mutations
Also wanted to let you know that medplum does track the change history for each resource, which can be accessed using the history API (https://www.medplum.com/docs/sdk/classes/MedplumClient#readhistory)
j
That makes sense — we're already using
requester
and
authoredOn
to track the actual ordering physician + when the order was signed
In addition to those pieces of info we also want to track if we receive a verbal order / a signed order, who sent it to us and when, which is why I'm asking about additional fields to contain that information
Is there a good place to store that besides provenance? I was thinking maybe the
note
field if that makes sense
There's also data extensions I suppose
r
I see, sorry for the confusion. After consulting the FHIR forums, Provenance actually might be the way to go on this one
Let's figure out why your provenance creation didn't work. Would you mind posting the details on how you made your creation query? What HTTP request you made, and what tool you used?
Also FYI, once the Provenance is created, it won't automatically update the ServiceRequest. You'll have to update the ServiceRequest.relevantHistory element with another call to create the reference
j
Got it — right now no
relevantHistory
item is being returned at all, actually
after creation — let me send you the query + request info
Copy code
mutation CREATE_ORDER(
    $categoryCode: String!
    $codingSystem: String!
    $categoryDisplay: String!
    $orderDate: String!
    $requestedOn: String!
    $becameActiveOn: String
    $orderingPhysicianRef: String!
    $orderInstructions: String
    $patientRef: String!
    $cnaRefs: [ReferenceCreate!]!
    $orderStatus: String!
    $isVerbalOrder: Boolean!
    $receivedFrom: String!
    $receivedAt: String!
  ) {
    ServiceRequestCreate(
      res: {
        resourceType: "ServiceRequest"
        code: { coding: [{ system: $codingSystem, code: $categoryCode, display: $categoryDisplay }] }
        category: [{ coding: [{ system: $codingSystem, code: $categoryCode, display: $categoryDisplay }] }]
        occurrenceDateTime: $orderDate
        requester: { reference: $orderingPhysicianRef }
        orderDetail: { text: $orderInstructions }
        extension: [
          {
            # Extension for verbal order status
            url: "https://blah.org/fhir/StructureDefinition/verbal-order"
            valueBoolean: $isVerbalOrder
          }
          {
            # Extension for requested on date
            url: "https://blah.org/fhir/StructureDefinition/requested-on"
            valueDateTime: $requestedOn
          }
        ]
        authoredOn: $becameActiveOn
        note: [
          { 
            time: $receivedAt, 
            text: $receivedFrom, 
            extension: [{ 
              url: "https://blah.org/fhir/StructureDefinition/blah-note-code", 
              valueString: "received_from" 
            }] 
          }
        ]
        
        # Additional (potentially required) fields
        status: $orderStatus
        intent: "order"
        subject: { reference: $patientRef }
        priority: "routine"
        performer: $cnaRefs
      }
    ) {
      id
    }
  }
Here was the response:
Copy code
{
  "data": {
    "ServiceRequestCreate": {
      "id": "86560382-db5a-4ff5-af79-2009736c0e94"
    }
  }
}
r
I think the problem lies in this section at the the bottom:
Copy code
{
      id
    }
With graphQL mutations (https://graphql.org/learn/queries/#mutations), this section specifies which fields from the newly created resource are returned to the client. E.g.
Copy code
mutation {    
    ServiceRequestCreate(
      res: {
        resourceType: "ServiceRequest",
        status: "active",
        intent: "order",
        subject: {reference: "Patient/123"}
      }        
        ) {
          id
          
        }
    }
returns
Copy code
{
  "data": {
    "newOrder": {
      "id": "a14eb5ae-58d2-4322-a4e7-82c232ab4033"
    }
  }
}
and
Copy code
mutation {    
    ServiceRequestCreate(
      res: {
        resourceType: "ServiceRequest",
        status: "active",
        intent: "order",
        subject: {reference: "Patient/123"}
      }        
        ) {
          id
          relevantHistory {
            reference
          } 
        }
    }
returns
Copy code
{
  "data": {
    "ServiceRequestCreate": {
      "id": "0807db8a-20c5-412c-b3ea-12520359533c",
      "relevantHistory": null
    }
  }
}
You'll still have to create the Provenance resources separately and add the reference during your
CREATE_ORDER
mutation
Let me know if this helps! We'll also go ahead and update the docs
156 Views