@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/esm/index.js CHANGED
@@ -1902,7 +1902,7 @@ class MedplumClient extends EventTarget {
1902
1902
  }
1903
1903
  }
1904
1904
  }
1905
- SearchParameterList(base: "${encodeURIComponent(resourceType)}") {
1905
+ SearchParameterList(base: "${encodeURIComponent(resourceType)}", _count: 100) {
1906
1906
  base,
1907
1907
  code,
1908
1908
  type,
@@ -1992,6 +1992,50 @@ class MedplumClient extends EventTarget {
1992
1992
  }
1993
1993
  return this.post(this.fhirUrl(resource.resourceType), resource);
1994
1994
  }
1995
+ /**
1996
+ * Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server.
1997
+ *
1998
+ * The return value is the existing resource or the newly created resource, including the ID and meta.
1999
+ *
2000
+ * Example:
2001
+ *
2002
+ * ```typescript
2003
+ * const result = await medplum.createResourceIfNoneExist(
2004
+ * 'Patient?identifier=123',
2005
+ * {
2006
+ * resourceType: 'Patient',
2007
+ * identifier: [{
2008
+ * system: 'http://example.com/mrn',
2009
+ * value: '123'
2010
+ * }]
2011
+ * name: [{
2012
+ * family: 'Smith',
2013
+ * given: ['John']
2014
+ * }]
2015
+ * });
2016
+ * console.log(result.id);
2017
+ * ```
2018
+ *
2019
+ * This method is syntactic sugar for:
2020
+ *
2021
+ * ```typescript
2022
+ * return searchOne(query) ?? createResource(resource);
2023
+ * ```
2024
+ *
2025
+ * The query parameter only contains the search parameters (what would be in the URL following the "?").
2026
+ *
2027
+ * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
2028
+ *
2029
+ * @param resource The FHIR resource to create.
2030
+ * @param query The search query for an equivalent resource.
2031
+ * @returns The result of the create operation.
2032
+ */
2033
+ createResourceIfNoneExist(resource, query) {
2034
+ var _a;
2035
+ return __awaiter(this, void 0, void 0, function* () {
2036
+ return (_a = (yield this.searchOne(`${resource.resourceType}?${query}`))) !== null && _a !== void 0 ? _a : this.createResource(resource);
2037
+ });
2038
+ }
1995
2039
  /**
1996
2040
  * Creates a FHIR `Binary` resource with the provided data content.
1997
2041
  *