Skip to content

Commit

Permalink
Add alcohol use, intake, and comment (#3043)
Browse files Browse the repository at this point in the history
* init

* Add alcohol use, intake, and comment.

* remove bad change

* Update to evaluateValue

* pr comments

* PR comment

* Fix ? to &&

* Upgrade fhir-converter to v18

* update snap

* one last snap update

* ugh

* fix integration test

* change to correct release

* update to next release

* Fix orch pin multipart

* update fastapi

* undo

* increase timeout

* revert snap
  • Loading branch information
lina-roth authored Dec 17, 2024
1 parent 744ea3f commit 8a4842b
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 5 deletions.
4 changes: 3 additions & 1 deletion containers/ecr-viewer/src/app/api/fhirPath.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ patientCurrentJobTitle: "Bundle.entry.resource.where(resourceType='Observation')
patientTobaccoUse: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.code='72166-2').where(category.coding.code='social-history').value"
patientHomelessStatus: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.code='75274-1').where(category.coding.code='social-history').value"
patientPregnancyStatus: "Bundle.entry.resource.where(resourceType='Observation').where(meta.profile='http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-pregnancy-status-observation').value"
patientAlcoholUse: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.code='11331-6').where(category.coding.code='social-history').value"
patientAlcoholUse: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.where(code='11331-6' and system = 'http://loinc.org')).value"
patientAlcoholIntake: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.where(code='74013-4' and system = 'http://loinc.org')).value"
patientAlcoholComment: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.display='Alcohol Comment').value"
patientSexualOrientation: "Bundle.entry.resource.where(resourceType='Observation').where(code.coding.code='76690-7').value"
patientGenderIdentity: "Bundle.entry.resource.where(resourceType = 'Patient').extension.where(url='http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-genderidentity-extension').value"
patientReligion: "Bundle.entry.resource.where(resourceType = 'Patient').extension.where(url='http://hl7.org/fhir/StructureDefinition/patient-religion').value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DisplayDataProps } from "@/app/view-data/components/DataDisplay";
import { evaluateTravelHistoryTable } from "./socialHistoryService";
import { Path } from "fhirpath";
import { returnTableFromJson } from "../view-data/components/common";
import { toSentenceCase } from "./formatService";

/**
* Evaluates patient name from the FHIR bundle and formats it into structured data for display.
Expand Down Expand Up @@ -197,6 +198,39 @@ export const calculatePatientAgeAtDeath = (
}
};

/**
* Evaluates alcohol use information from the FHIR bundle and formats it into structured data for display.
* @param fhirBundle - The FHIR bundle containing alcohol use data.
* @param fhirMappings - The object containing the fhir paths.
* @returns An array of evaluated and formatted alcohol use data.
*/
export const evaluateAlcoholUse = (
fhirBundle: Bundle,
fhirMappings: PathMappings,
) => {
const alcoholUse = evaluateValue(fhirBundle, fhirMappings.patientAlcoholUse);
const alcoholIntake = evaluateValue(
fhirBundle,
fhirMappings.patientAlcoholIntake,
);
let alcoholComment: string | undefined = evaluateValue(
fhirBundle,
fhirMappings.patientAlcoholComment,
);

if (alcoholComment) {
alcoholComment = toSentenceCase(alcoholComment);
}

return [
alcoholUse ? `Use: ${alcoholUse}` : null,
alcoholIntake ? `Intake (standard drinks/week): ${alcoholIntake}` : null,
alcoholComment ? `Comment: ${alcoholComment}` : null,
]
.filter(Boolean) // Removes null or undefined lines
.join("\n"); // Joins the remaining lines with newlines
};

/**
* Evaluates social data from the FHIR bundle and formats it into structured data for display.
* @param fhirBundle - The FHIR bundle containing social data.
Expand Down Expand Up @@ -227,7 +261,7 @@ export const evaluateSocialData = (
},
{
title: "Alcohol Use",
value: evaluateValue(fhirBundle, mappings["patientAlcoholUse"]),
value: evaluateAlcoholUse(fhirBundle, mappings),
},
{
title: "Sexual Orientation",
Expand Down
165 changes: 165 additions & 0 deletions containers/ecr-viewer/src/app/tests/assets/BundlePatient.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,171 @@
"method": "PUT",
"url": "Patient/6b6b3c4c-4884-4a96-b6ab-c46406839cea"
}
},
{
"fullUrl": "urn:uuid:b91cab75-e4a0-2227-79ec-44c9c8ea795a",
"resource": {
"resourceType": "Observation",
"id": "b91cab75-e4a0-2227-79ec-44c9c8ea795a",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observationresults"
],
"source": "ecr"
},
"identifier": [
{
"system": "urn:oid:1.2.840.114350.1.13.66.2.7.7.698084.19222",
"value": "Z13909121"
}
],
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "social-history"
}
]
}
],
"status": "final",
"code": {
"coding": [
{
"code": "X-SDOH-19222",
"system": "urn:oid:1.2.840.114350.1.72.1.8",
"display": "Alcohol Comment"
}
]
},
"effectiveDateTime": "2022-11-04",
"valueString": "1-2 DRINKS 2 TO 4 TIMES A MONTH",
"subject": {
"reference": "Patient/5227f761-a6ea-461d-9523-8d9ee26eab84"
}
},
"request": {
"method": "PUT",
"url": "Observation/b91cab75-e4a0-2227-79ec-44c9c8ea795a"
}
},
{
"fullUrl": "urn:uuid:259df789-9da2-9b7c-bc69-a60c634860d8",
"resource": {
"resourceType": "Observation",
"id": "259df789-9da2-9b7c-bc69-a60c634860d8",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observationresults"
],
"source": "ecr"
},
"identifier": [
{
"system": "urn:oid:1.2.840.114350.1.13.66.2.7.1.1040.13",
"value": "Z13909121^54660.98^897148007"
}
],
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "social-history"
}
]
}
],
"status": "final",
"code": {
"coding": [
{
"code": "897148007",
"system": "http://snomed.info/sct",
"display": "Alcoholic beverage intake"
},
{
"code": "74013-4",
"system": "http://loinc.org",
"display": "Alcoholic drinks per day"
}
]
},
"effectiveDateTime": "2024-01-31",
"valueQuantity": {
"value": ".29",
"unit": "/d"
},
"subject": {
"reference": "Patient/5227f761-a6ea-461d-9523-8d9ee26eab84"
}
},
"request": {
"method": "PUT",
"url": "Observation/259df789-9da2-9b7c-bc69-a60c634860d8"
}
},
{
"fullUrl": "urn:uuid:b467f663-f4f5-78af-a677-05b5545d8716",
"resource": {
"resourceType": "Observation",
"id": "b467f663-f4f5-78af-a677-05b5545d8716",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observationresults"
],
"source": "ecr"
},
"identifier": [
{
"system": "urn:oid:1.2.840.114350.1.13.66.2.7.1.1040.12",
"value": "Z13909121^54660.98^897148007"
}
],
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "social-history"
}
]
}
],
"status": "final",
"code": {
"coding": [
{
"code": "897148007",
"system": "http://snomed.info/sct",
"display": "Alcoholic beverage intake"
},
{
"code": "11331-6",
"system": "http://loinc.org",
"display": "History of Alcohol Use"
}
]
},
"effectiveDateTime": "2024-01-31",
"valueCodeableConcept": {
"coding": [
{
"code": "219006",
"system": "http://snomed.info/sct",
"display": "Current drinker of alcohol (finding)"
}
]
},
"subject": {
"reference": "Patient/5227f761-a6ea-461d-9523-8d9ee26eab84"
}
},
"request": {
"method": "PUT",
"url": "Observation/b467f663-f4f5-78af-a677-05b5545d8716"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
evaluatePatientName,
evaluateDemographicsData,
evaluateEncounterCareTeamTable,
evaluateAlcoholUse,
} from "@/app/services/evaluateFhirDataService";
import { Bundle, Patient } from "fhir/r4";
import BundleWithMiscNotes from "@/app/tests/assets/BundleMiscNotes.json";
Expand Down Expand Up @@ -516,3 +517,24 @@ describe("Evaluate Patient Name", () => {
expect(actual).toEqual("ABEL CASTILLO");
});
});

describe("Evaluate Alcohol Use", () => {
it("should return the use, intake comment", () => {
const actual = evaluateAlcoholUse(
BundleWithPatient as unknown as Bundle,
mappings,
);
expect(actual).toEqual(
"Use: Current drinker of alcohol (finding)\n" +
"Intake (standard drinks/week): .29/d\n" +
"Comment: 1-2 drinks 2 to 4 times a month",
);
});
it("should empty string because there is no use, intake, or comment", () => {
const actual = evaluateAlcoholUse(
BundlePatientMultiple as unknown as Bundle,
mappings,
);
expect(actual).toEqual("");
});
});
2 changes: 1 addition & 1 deletion containers/fhir-converter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

# Download FHIR-Converter
RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch v7.0-skylight-17 --single-branch /build/FHIR-Converter
RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch v7.0-skylight-18 --single-branch /build/FHIR-Converter

WORKDIR /build/FHIR-Converter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_failed_save_to_ecr_viewer(setup, clean_up_db):
}
files = {"upload_file": ("file.zip", file)}
orchestration_response = httpx.post(
PROCESS_ZIP_ENDPOINT, data=form_data, files=files, timeout=60
PROCESS_ZIP_ENDPOINT, data=form_data, files=files, timeout=120
)
assert orchestration_response.status_code == 500

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a4842b

Please sign in to comment.