Skip to content

Commit

Permalink
add translation function: vsac --> internal valueset (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Mitchell <[email protected]>
  • Loading branch information
fzhao99 and robertandremitchell authored Oct 22, 2024
1 parent 09795b4 commit ffbe1cd
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 2 deletions.
22 changes: 22 additions & 0 deletions query-connector/src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ export interface ValueSet {
concepts: Concept[];
}

export const DEFAULT_ERSD_VERSION = "3";

type DibbsConceptType = "labs" | "medications" | "conditions";
export type ErsdConceptType =
| "ostc"
| "lotc"
| "lrtc"
| "mrtc"
| "dxtc"
| "sdtc";

export const ersdToDibbsConceptMap: {
[k in ErsdConceptType]: DibbsConceptType;
} = {
ostc: "labs",
lotc: "labs",
lrtc: "labs",
mrtc: "medications",
dxtc: "conditions",
sdtc: "conditions",
};

/*
* The expected type of ValueSets grouped by dibbsConceptType for the purpose of display.
*/
Expand Down
45 changes: 43 additions & 2 deletions query-connector/src/app/database-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"use server";
import { Pool, PoolConfig, QueryResultRow } from "pg";
import { Bundle, OperationOutcome } from "fhir/r4";
import { Bundle, OperationOutcome, ValueSet as FhirValueSet } from "fhir/r4";
import {
Concept,
DEFAULT_ERSD_VERSION,
ErsdConceptType,
ValueSet,
ersdToDibbsConceptMap,
} from "./constants";
import { encode } from "base-64";
import { ValueSet } from "./constants";

const getQuerybyNameSQL = `
select q.query_name, q.id, qtv.valueset_id, vs.name as valueset_name, vs.version, vs.author as author, vs.type, vs.dibbs_concept_type as dibbs_concept_type, qic.concept_id, qic.include, c.code, c.code_system, c.display
Expand Down Expand Up @@ -166,3 +172,38 @@ export async function getVSACValueSet(
} as OperationOutcome;
}
}

/**
* Translates a VSAC FHIR bundle to our internal ValueSet struct
* @param fhirValueset - The FHIR ValueSet response from VSAC
* @param ersdConceptType - The associated clinical concept type from ERSD
* @returns An object of type InternalValueSet
*/
export async function translateVSACToInternalValueSet(
fhirValueset: FhirValueSet,
ersdConceptType: ErsdConceptType,
) {
const id = fhirValueset.id;
const version = DEFAULT_ERSD_VERSION;

const name = fhirValueset.title;
const author = fhirValueset.publisher;

const bundleConceptData = fhirValueset?.compose?.include[0];
const system = bundleConceptData?.system;
const concepts = bundleConceptData?.concept?.map((fhirConcept) => {
return { ...fhirConcept, include: false } as Concept;
});

return {
valueSetId: id,
valueSetVersion: version,
valueSetName: name,
author: author,
system: system,
ersdConceptType: ersdConceptType,
dibbsConceptType: ersdToDibbsConceptMap[ersdConceptType],
includeValueSet: false,
concepts: concepts,
} as ValueSet;
}
174 changes: 174 additions & 0 deletions query-connector/src/app/tests/assets/VSACValueSet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"resourceType": "ValueSet",
"id": "2.16.840.1.113762.1.4.1146.170",
"meta": {
"versionId": "58",
"lastUpdated": "2023-12-21T17:43:03.000-05:00",
"profile": [
"http://hl7.org/fhir/StructureDefinition/shareablevalueset",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/computable-valueset-cqfm",
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/publishable-valueset-cqfm"
]
},
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/valueset-author",
"valueContactDetail": {
"name": "CSTE Author"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/valueset-keyWord",
"valueString": "Chlamydia,G_STI,Trigger"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/resource-lastReviewDate",
"valueDate": "2024-06-05"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/valueset-effectiveDate",
"valueDate": "2023-06-02"
}
],
"url": "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.170",
"identifier": [
{
"system": "urn:ietf:rfc:3986",
"value": "urn:oid:2.16.840.1.113762.1.4.1146.170"
}
],
"version": "20230602",
"name": "ChlamydiaTrachomatisInfectionOrganismOrSubstanceInLabResults",
"title": "Chlamydia trachomatis Infection (Organism or Substance in Lab Results)",
"status": "active",
"date": "2023-06-02T01:03:51-04:00",
"publisher": "CSTE Steward",
"jurisdiction": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
}
],
"purpose": "(Clinical Focus: This set of values contains organisms or substances relevant for reporting Chlamydia),(Data Element Scope: Organism names reported in laboratory results),(Inclusion Criteria: Chlamydia trachomatis organism or Chlamydia trachomatis substance),(Exclusion Criteria: antibody substances)",
"compose": {
"include": [
{
"system": "http://snomed.info/sct",
"concept": [
{
"code": "115289001",
"display": "Chlamydia trachomatis, serotype A (organism)"
},
{
"code": "115290005",
"display": "Chlamydia trachomatis, serotype B (organism)"
},
{
"code": "115291009",
"display": "Chlamydia trachomatis, serotype Ba (organism)"
},
{
"code": "115292002",
"display": "Chlamydia trachomatis, serotype C (organism)"
},
{
"code": "115293007",
"display": "Chlamydia trachomatis, serotype D (organism)"
},
{
"code": "115294001",
"display": "Chlamydia trachomatis, serotype E (organism)"
},
{
"code": "115295000",
"display": "Chlamydia trachomatis, serotype F (organism)"
},
{
"code": "115296004",
"display": "Chlamydia trachomatis, serotype I (organism)"
},
{
"code": "115297008",
"display": "Chlamydia trachomatis, serotype J (organism)"
},
{
"code": "115298003",
"display": "Chlamydia trachomatis, serotype K (organism)"
},
{
"code": "115299006",
"display": "Chlamydia trachomatis, serotype L (organism)"
},
{
"code": "115300003",
"display": "Chlamydia trachomatis, serotype L1 (organism)"
},
{
"code": "115301004",
"display": "Chlamydia trachomatis, serotype L2 (organism)"
},
{
"code": "115318000",
"display": "Chlamydia trachomatis, serotype L3 (organism)"
},
{
"code": "115319008",
"display": "Chlamydia trachomatis, serotype G (organism)"
},
{
"code": "115328009",
"display": "Chlamydia trachomatis, serotype H (organism)"
},
{
"code": "121002007",
"display": "Antigen of Chlamydia trachomatis (substance)"
},
{
"code": "121015003",
"display": "Antigen of Chlamydia trachomatis serotype F (substance)"
},
{
"code": "121016002",
"display": "Antigen of Chlamydia trachomatis serotype G (substance)"
},
{
"code": "121017006",
"display": "Antigen of Chlamydia trachomatis serotype K (substance)"
},
{
"code": "121106008",
"display": "Ribosomal ribonucleic acid of Chlamydia trachomatis (substance)"
},
{
"code": "121181000",
"display": "Deoxyribonucleic acid of Chlamydia trachomatis (substance)"
},
{
"code": "442505006",
"display": "Chlamydia trachomatis, serotype Ja (organism)"
},
{
"code": "454431000124102",
"display": "Chlamydia trachomatis nucleic acid detected (finding)"
},
{
"code": "59134003",
"display": "Lymphogranuloma venereum antigen (substance)"
},
{
"code": "63938009",
"display": "Chlamydia trachomatis (organism)"
},
{
"code": "708219005",
"display": "Deoxyribonucleic acid of Chlamydia trachomatis L2 (substance)"
}
]
}
]
}
}
29 changes: 29 additions & 0 deletions query-connector/src/app/tests/integration/translation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DEFAULT_ERSD_VERSION, ValueSet } from "@/app/constants";
import ExampleVsacValueSet from "../assets/VSACValueSet.json";
import { translateVSACToInternalValueSet } from "../../database-service";
import { ValueSet as FhirValueSet } from "fhir/r4";

const EXPECTED_INTERNAL_VALUESET: ValueSet = {
valueSetId: ExampleVsacValueSet.id,
valueSetVersion: DEFAULT_ERSD_VERSION,
valueSetName: ExampleVsacValueSet.title,
author: ExampleVsacValueSet.publisher,
system: ExampleVsacValueSet.compose.include[0].system,
ersdConceptType: "ostc",
dibbsConceptType: "labs",
includeValueSet: false,
concepts: ExampleVsacValueSet.compose.include[0].concept.map((c) => {
return { ...c, include: false };
}),
};

describe("VSAC FHIR response to internal application type", () => {
it("translate to expected fixture", async () => {
const translationResult = await translateVSACToInternalValueSet(
ExampleVsacValueSet as FhirValueSet,
"ostc",
);

expect(translationResult).toEqual(EXPECTED_INTERNAL_VALUESET);
});
});

0 comments on commit ffbe1cd

Please sign in to comment.