diff --git a/python/orchestrate/_internal/convert.py b/python/orchestrate/_internal/convert.py index 9fa385e..b4efffb 100644 --- a/python/orchestrate/_internal/convert.py +++ b/python/orchestrate/_internal/convert.py @@ -21,6 +21,8 @@ ConvertCombinedFhirR4BundlesResponse = Bundle +ConvertStandardizeFHIRR4BundleResponse = Bundle + ConvertFhirDstu2ToFhirR4Response = Bundle ConvertFhirStu3ToFhirR4Response = Bundle @@ -317,6 +319,48 @@ def combine_fhir_r4_bundles( parameters=parameters, ) + def standardize_fhir_r4_bundle( + self, + content: Bundle, + patient_id: Optional[str] = None, + patient_identifier: Optional[str] = None, + patient_identifier_system: Optional[str] = None, + ) -> ConvertStandardizeFHIRR4BundleResponse: + """ + This operation standardizes a FHIR R4 bundle. + + ### Parameters + + - `fhir_bundle`: The FHIR R4 bundle to standardize + - `patient_id`: The patient ID to use for the FHIR bundle + - `patient_identifier`: A patient identifier to add to identifier list of patient resource in the FHIR bundle. Must be specified along with patient_identifier_system + - `patient_identifier_system`: The system providing the patient identifier. Must be specified along with patient_identifier + + ### Returns + + A single FHIR R4 Bundle containing the standardized data from the input. + + ### Documentation + + + """ + parameters = _get_id_dependent_parameters("patientId", patient_id) + parameters = { + **parameters, + **_get_id_dependent_parameters("patientIdentifier", patient_identifier), + } + parameters = { + **parameters, + **_get_id_dependent_parameters( + "patientIdentifierSystem", patient_identifier_system + ), + } + return self.__http_handler.post( + path="/convert/v1/standardizefhirr4bundle", + body=content, + parameters=parameters, + ) + def fhir_dstu2_to_fhir_r4( self, content: Bundle, diff --git a/python/orchestrate/convert.py b/python/orchestrate/convert.py index 70abeec..44115e0 100644 --- a/python/orchestrate/convert.py +++ b/python/orchestrate/convert.py @@ -6,6 +6,7 @@ ConvertFhirR4ToOmopResponse, ConvertX12ToFhirR4Response, ConvertCombinedFhirR4BundlesResponse, + ConvertStandardizeFHIRR4BundleResponse, ConvertFhirDstu2ToFhirR4Response, ConvertFhirStu3ToFhirR4Response, ConvertFhirR4ToHealthLakeResponse, @@ -24,6 +25,7 @@ "ConvertFhirR4ToOmopResponse", "ConvertX12ToFhirR4Response", "ConvertCombinedFhirR4BundlesResponse", + "ConvertStandardizeFHIRR4BundleResponse", "ConvertFhirDstu2ToFhirR4Response", "ConvertFhirStu3ToFhirR4Response", "ConvertFhirR4ToHealthLakeResponse", diff --git a/python/tests/test_api.py b/python/tests/test_api.py index cd2f863..f620a40 100644 --- a/python/tests/test_api.py +++ b/python/tests/test_api.py @@ -704,6 +704,59 @@ def test_convert_combined_fhir_r4_bundles_with_patient_identifier_and_system_sho ) +def test_convert_standardize_fhir_r4_bundle_should_standardize(): + result = TEST_API.convert.standardize_fhir_r4_bundle(content=R4_BUNDLE) + + assert result is not None + assert result["resourceType"] == "Bundle" + assert len(result["entry"]) == 1 + + +def test_convert_standardize_fhir_r4_bundle_with_person_should_standardize(): + result = TEST_API.convert.standardize_fhir_r4_bundle( + content=R4_BUNDLE, patient_id="1234" + ) + + assert result is not None + assert result["resourceType"] == "Bundle" + assert len(result["entry"]) == 1 + patient_resource = next( + ( + entry["resource"] + for entry in result["entry"] + if entry["resource"]["resourceType"] == "Patient" + ) + ) + assert patient_resource["id"] == "1234" + + +def test_convert_standardize_fhir_r4_bundle_with_patient_identifier_and_system_should_standardize(): + + result = TEST_API.convert.standardize_fhir_r4_bundle( + content=R4_BUNDLE, + patient_identifier="1234", + patient_identifier_system="GoodHealthClinic", + ) + + assert result is not None + assert result["resourceType"] == "Bundle" + assert len(result["entry"]) == 1 + patient_resource = next( + ( + entry["resource"] + for entry in result["entry"] + if entry["resource"]["resourceType"] == "Patient" + ) + ) + assert ( + "identifier" in patient_resource + and len(patient_resource["identifier"]) > 0 + and "GoodHealthClinic" in patient_resource["identifier"][0]["system"] + and patient_resource["identifier"][0]["use"] == "usual" + and patient_resource["identifier"][0]["value"] == "1234" + ) + + def test_convert_x12_to_fhir_r4_should_return_a_bundle(): result = TEST_API.convert.x12_to_fhir_r4(content=X12_DOCUMENT) diff --git a/typescript/src/convert.ts b/typescript/src/convert.ts index d9bbfb2..ff7b677 100644 --- a/typescript/src/convert.ts +++ b/typescript/src/convert.ts @@ -47,6 +47,13 @@ export type ConvertCombineFhirR4BundlesRequest = { patientIdentifierSystem?: string; }; +export type ConvertStandardizeFhirR4BundleRequest = { + content: Bundle; + patientID?: string; + patientIdentifier?: string; + patientIdentifierSystem?: string; +}; + export type ConvertFhirDstu2ToFhirR4Request = { content: unknown; }; @@ -75,6 +82,8 @@ export function generateConvertCombinedFhirBundlesRequestFromBundles(fhirBundles export type ConvertCombineFhirR4BundlesResponse = Bundle; +export type ConvertStandardizeFhirR4BundleResponse = Bundle; + export type ConvertX12ToFhirR4Request = { content: string; patientID?: string; @@ -247,6 +256,31 @@ export class ConvertApi { return this.httpHandler.post(route, request.content, headers); } + + /** + * This operation aggregates information retrieved from prior Convert API requests into a single entry. + * @param request A FHIR R4 Bundle + * @returns A single FHIR R4 Bundle containing the standardized data from the input. + * @link https://rosetta-api.docs.careevolution.com/convert/standardize_bundle.html + */ + standardizeFhirR4Bundle(request: ConvertStandardizeFhirR4BundleRequest): Promise { + const parameters = new URLSearchParams(); + if (request.patientID) { + parameters.append("patientId", request.patientID); + } + if (request.patientIdentifier) { + parameters.append("patientIdentifier", request.patientIdentifier); + } + if (request.patientIdentifierSystem) { + parameters.append("patientIdentifierSystem", request.patientIdentifierSystem); + } + let route = "/convert/v1/standardizefhirr4bundle"; + if (parameters.size) { + route += `?${parameters.toString()}`; + } + return this.httpHandler.post(route, request.content); + } + /** * Converts an X12 document into a FHIR R4 bundle. * @param request A standard version 5010 X12 document diff --git a/typescript/tests/api.test.ts b/typescript/tests/api.test.ts index a02607f..f16164e 100644 --- a/typescript/tests/api.test.ts +++ b/typescript/tests/api.test.ts @@ -780,6 +780,60 @@ ${JSON.stringify(fhir)} ).toBe(true); }); +describe("convert standardize fhir r4 bundles", () => { + it("should standardize fhir bundle", async () => { + const bundle = JSON.stringify(fhir); + + const result = await orchestrate.convert.standardizeFhirR4Bundle({ + content: bundle, + }); + + expect(result).toBeDefined(); + expect(result.resourceType).toBe("Bundle"); + expect(result.entry?.length).toBeGreaterThan(0); + }); + + it("should standardize fhir r4 bundle with patient", async () => { + const bundle = JSON.stringify(fhir); + + const result = await orchestrate.convert.standardizeFhirR4Bundle({ + content: bundle, + patientID: "1234", + }); + + expect(result).toBeDefined(); + expect(result.resourceType).toBe("Bundle"); + expect(result.entry?.length).toBeGreaterThan(0); + const patientResource = result.entry?.find((entry) => entry.resource?.resourceType === "Patient"); + expect(patientResource).toBeDefined(); + expect(patientResource?.resource?.id).toBe("1234"); + }); +}); + +it("should standardize fhir r4 bundle with patientIdentifierAndSystem", async () => { + const bundle = JSON.stringify(fhir); + + const result = await orchestrate.convert.standardizeFhirR4Bundle({ + content: bundle, + patientIdentifier: "1234", + patientIdentifierSystem: "GoodHealthClinic", + }); + expect(result).toBeDefined(); + expect(result.resourceType).toBe("Bundle"); + expect(result.entry?.length).toBeGreaterThan(0); + const patientResource = result.entry?.find((entry) => entry.resource?.resourceType === "Patient"); + + expect(patientResource).toBeDefined(); + const patient = patientResource?.resource as Patient; + expect(patient).toBeDefined(); + + expect( + patient.identifier?.[0]?.use === "usual" && + patient.identifier?.[0]?.system?.includes("GoodHealthClinic") && + patient.identifier?.[0]?.value === "1234" + ).toBe(true); +}); + describe("convert fhir stu3 to fhir r4", () => { it("should convert", async () => { const result = await orchestrate.convert.fhirStu3ToFhirR4({