@medplum/core 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1908,7 +1908,7 @@
1908
1908
  }
1909
1909
  }
1910
1910
  }
1911
- SearchParameterList(base: "${encodeURIComponent(resourceType)}") {
1911
+ SearchParameterList(base: "${encodeURIComponent(resourceType)}", _count: 100) {
1912
1912
  base,
1913
1913
  code,
1914
1914
  type,
@@ -1998,6 +1998,50 @@
1998
1998
  }
1999
1999
  return this.post(this.fhirUrl(resource.resourceType), resource);
2000
2000
  }
2001
+ /**
2002
+ * Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server.
2003
+ *
2004
+ * The return value is the existing resource or the newly created resource, including the ID and meta.
2005
+ *
2006
+ * Example:
2007
+ *
2008
+ * ```typescript
2009
+ * const result = await medplum.createResourceIfNoneExist(
2010
+ * 'Patient?identifier=123',
2011
+ * {
2012
+ * resourceType: 'Patient',
2013
+ * identifier: [{
2014
+ * system: 'http://example.com/mrn',
2015
+ * value: '123'
2016
+ * }]
2017
+ * name: [{
2018
+ * family: 'Smith',
2019
+ * given: ['John']
2020
+ * }]
2021
+ * });
2022
+ * console.log(result.id);
2023
+ * ```
2024
+ *
2025
+ * This method is syntactic sugar for:
2026
+ *
2027
+ * ```typescript
2028
+ * return searchOne(query) ?? createResource(resource);
2029
+ * ```
2030
+ *
2031
+ * The query parameter only contains the search parameters (what would be in the URL following the "?").
2032
+ *
2033
+ * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
2034
+ *
2035
+ * @param resource The FHIR resource to create.
2036
+ * @param query The search query for an equivalent resource.
2037
+ * @returns The result of the create operation.
2038
+ */
2039
+ createResourceIfNoneExist(resource, query) {
2040
+ var _a;
2041
+ return __awaiter(this, void 0, void 0, function* () {
2042
+ return (_a = (yield this.searchOne(`${resource.resourceType}?${query}`))) !== null && _a !== void 0 ? _a : this.createResource(resource);
2043
+ });
2044
+ }
2001
2045
  /**
2002
2046
  * Creates a FHIR `Binary` resource with the provided data content.
2003
2047
  *