From fb5fd966371ecc527d3f96ae1cdd1a2c34f48699 Mon Sep 17 00:00:00 2001 From: Luthfi Bustillos-Francis Date: Tue, 4 Oct 2022 15:40:21 -0400 Subject: [PATCH] add logic to add recorder field (#93) Still need to: - [x] Decide what we are going to show in the the display field - [x] Decide what nulling a recording field looks like, or how to do that in the fhir post - [x] Get my practitioner id to actually return a valid id, currently still get empty practitioner id despite the fact that I do have a practitioner associated with my role --- .changeset/tricky-experts-drop.md | 5 +++++ src/components/content/forms/conditions.ts | 14 +++++++++++++- src/fhir/action-helper.ts | 5 ++--- src/fhir/search-helpers.ts | 4 ++-- src/fhir/system-urls.ts | 2 ++ 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .changeset/tricky-experts-drop.md diff --git a/.changeset/tricky-experts-drop.md b/.changeset/tricky-experts-drop.md new file mode 100644 index 000000000..01f91390a --- /dev/null +++ b/.changeset/tricky-experts-drop.md @@ -0,0 +1,5 @@ +--- +"@zus-health/ctw-component-library": minor +--- + +When user edits or adds a condition, practitioner id will now be used to set the recorder field automatically. If no practitioner id is found then recorder will be nulled else the current practitioner id for the user will be used. diff --git a/src/components/content/forms/conditions.ts b/src/components/content/forms/conditions.ts index 2e4664388..27c80c4f0 100644 --- a/src/components/content/forms/conditions.ts +++ b/src/components/content/forms/conditions.ts @@ -1,9 +1,11 @@ import { createOrEditFhirResource } from "@/fhir/action-helper"; +import { getClaims } from "@/fhir/client"; import { isFhirError } from "@/fhir/errors"; import { dateToISO } from "@/fhir/formatters"; import { SYSTEM_CONDITION_CLINICAL, SYSTEM_CONDITION_VERIFICATION_STATUS, + SYSTEM_PRACTITIONER_ID, SYSTEM_SNOMED, } from "@/fhir/system-urls"; import { ConditionModel } from "@/models/conditions"; @@ -43,6 +45,11 @@ export const conditionSchema = z.object({ note: z.string().optional(), }); +const setRecorderField = (practitionerId: string) => ({ + reference: `Practitioner/${practitionerId}`, + type: "Practitioner", +}); + export const createOrEditCondition = async ( data: FormData, patientID: string, @@ -53,10 +60,15 @@ export const createOrEditCondition = async ( return result; } + const fhirClient = await getCTWFhirClient(); + const practitionerId = result.data.id + ? (getClaims(fhirClient)[SYSTEM_PRACTITIONER_ID] as string) + : ""; // Some fields will need to be set as they are required. const fhirCondition: fhir4.Condition = { resourceType: "Condition", id: result.data.id, + ...(practitionerId && { recorder: setRecorderField(practitionerId) }), clinicalStatus: { coding: [ { @@ -96,7 +108,7 @@ export const createOrEditCondition = async ( const response = await createOrEditFhirResource({ resourceModel: conditionModel, - getCTWFhirClient, + fhirClient, }); if (isFhirError(response)) { diff --git a/src/fhir/action-helper.ts b/src/fhir/action-helper.ts index c417b8386..00efd28e1 100644 --- a/src/fhir/action-helper.ts +++ b/src/fhir/action-helper.ts @@ -10,14 +10,13 @@ export interface FhirResourceBase { type CreateOrEditData = { resourceModel: T; - getCTWFhirClient: () => Promise; + fhirClient: Client; }; export async function createOrEditFhirResource({ resourceModel, - getCTWFhirClient, + fhirClient, }: CreateOrEditData) { - const fhirClient = await getCTWFhirClient(); try { if (resourceModel.id) { return await fhirClient.update({ diff --git a/src/fhir/search-helpers.ts b/src/fhir/search-helpers.ts index be1416fbd..8e37bdf9d 100644 --- a/src/fhir/search-helpers.ts +++ b/src/fhir/search-helpers.ts @@ -71,8 +71,8 @@ export async function searchBuilderRecords( searchParams?: SearchParams ): Promise> { const nonBuilderTags = [...THIRD_PARTY_TAGS, ...LENS_TAGS, SUMMARY_TAGS]; - const jwt = getClaims(fhirClient); - const builderTag = `${SYSTEM_ZUS_OWNER}|builder/${jwt[SYSTEM_ZUS_BUILDER_ID]}`; + const claims = getClaims(fhirClient); + const builderTag = `${SYSTEM_ZUS_OWNER}|builder/${claims[SYSTEM_ZUS_BUILDER_ID]}`; return searchAllRecords(resourceType, fhirClient, { ...searchParams, _tag: builderTag, diff --git a/src/fhir/system-urls.ts b/src/fhir/system-urls.ts index 17005cc26..6f9c4d4db 100644 --- a/src/fhir/system-urls.ts +++ b/src/fhir/system-urls.ts @@ -18,6 +18,8 @@ export const SYSTEM_ICD10_CM = "http://hl7.org/fhir/sid/icd-10-cm"; export const SYSTEM_MARITAL_STATUS = "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus"; +export const SYSTEM_PRACTITIONER_ID = "https://zusapi.com/practitioner_id"; + export const SYSTEM_RELATIONSHIP = "http://terminology.hl7.org/CodeSystem/v2-0131";