Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions python/orchestrate/_internal/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

ConvertCombinedFhirR4BundlesResponse = Bundle

ConvertStandardizeFHIRR4BundleResponse = Bundle

ConvertFhirDstu2ToFhirR4Response = Bundle

ConvertFhirStu3ToFhirR4Response = Bundle
Expand Down Expand Up @@ -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

<https://rosetta-api.docs.careevolution.com/convert/standardize_bundle.html>
"""
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,
Expand Down
2 changes: 2 additions & 0 deletions python/orchestrate/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ConvertFhirR4ToOmopResponse,
ConvertX12ToFhirR4Response,
ConvertCombinedFhirR4BundlesResponse,
ConvertStandardizeFHIRR4BundleResponse,
ConvertFhirDstu2ToFhirR4Response,
ConvertFhirStu3ToFhirR4Response,
ConvertFhirR4ToHealthLakeResponse,
Expand All @@ -24,6 +25,7 @@
"ConvertFhirR4ToOmopResponse",
"ConvertX12ToFhirR4Response",
"ConvertCombinedFhirR4BundlesResponse",
"ConvertStandardizeFHIRR4BundleResponse",
"ConvertFhirDstu2ToFhirR4Response",
"ConvertFhirStu3ToFhirR4Response",
"ConvertFhirR4ToHealthLakeResponse",
Expand Down
53 changes: 53 additions & 0 deletions python/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions typescript/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -75,6 +82,8 @@ export function generateConvertCombinedFhirBundlesRequestFromBundles(fhirBundles

export type ConvertCombineFhirR4BundlesResponse = Bundle;

export type ConvertStandardizeFhirR4BundleResponse = Bundle;

export type ConvertX12ToFhirR4Request = {
content: string;
patientID?: string;
Expand Down Expand Up @@ -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<ConvertStandardizeFhirR4BundleResponse> {
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
Expand Down
54 changes: 54 additions & 0 deletions typescript/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading