Hi all! I just wanted to give you a heads up that...
# announcements
r
Hi all! I just wanted to give you a heads up that we’re planning on merging this PR EOD Wednesday. As noted, earlier This PR is the next step towards FHIR transaction and rollback support. Once merged, transaction and rollback support will be available behind a feature flag - please contact us if you would like this feature enabled on your project(s). This PR does have a breaking change with respect to performing “upserts”. The old recommendation of using a bundle with a POST followed by a PUT will no longer work. Instead, you’ll need to update your code to use the “conditional update” syntax shown below.
Old Method:
Copy code
{
    resourceType: 'Bundle',
    type: 'transaction',
    entry: [
      // Create the patient if it doesn't exist
      {
        request: {
          method: 'POST',
          url: 'Patient',
          ifNoneExist: 'identifier=http://example-hospital.org/mrns|234543',
        },
        fullUrl: 'urn:uuid:ffcda8f9-e517-412f-afde-5488cd176f68',
        resource: {
          resourceType: 'Patient',
          identifier: [
            {
              system: 'http://example-hospital.org/mrns',
              value: '234543',
            },
          ],
          name: [
            {
              family: 'Simpson',
              given: ['Homer', 'Jay'],
            },
          ],
          gender: 'male',
          birthDate: '1956-05-12',
        },
      },

      // Update the patient in-place
      {
        request: {
          method: 'PUT',
          url: 'urn:uuid:ffcda8f9-e517-412f-afde-5488cd176f68',
        },
        resource: {
          resourceType: 'Patient',
          id: 'urn:uuid:ffcda8f9-e517-412f-afde-5488cd176f68',
          identifier: [
            {
              system: 'http://example-hospital.org/mrns',
              value: '234543',
            },
          ],
          name: [
            {
              family: 'Simpson',
              given: ['Homer', 'Jay'],
            },
          ],
          gender: 'male',
          birthDate: '1956-05-12',
        },
      },
    ],
  };
New Method
Copy code
{
    resourceType: 'Bundle',
    type: 'batch',
    entry: [
      // Create the patient if it doesn't exist
      {
        request: {
          method: 'PUT',
          // *NOTE THIS URL*
          url: 'Patient?identifier=http://example-hospital.org/mrns|234543',
        },
        fullUrl: 'urn:uuid:ffcda8f9-e517-412f-afde-5488cd176f68',
        resource: {
          resourceType: 'Patient',
          identifier: [
            {
              system: 'http://example-hospital.org/mrns',
              value: '234543',
            },
          ],
          name: [
            {
              family: 'Simpson',
              given: ['Homer', 'Jay'],
            },
          ],
          gender: 'male',
          birthDate: '1956-05-12',
        },
      },      
    ],
  };
OR:
Copy code
// An "upsert" (i.e. update/insert) will either update the resource in place if it
// already exists, otherwise is will be created.  This is performed in a single,
// transactional request to guarantee data consistency.
const updatedPatient = medplum.upsertResource(patient, 'identifier=http://example-hospital.org/mrns|234543');
179 Views