Skip to content

Commit

Permalink
Added rules 6-8, 10-12
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSmCraft committed Jul 30, 2024
1 parent 9593944 commit ce05f9b
Show file tree
Hide file tree
Showing 18 changed files with 1,045 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.vscode
.vscode
.env
231 changes: 229 additions & 2 deletions test/execution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('MMR Rule 4 Tests ', () => {
});

describe('MMR Rule 5 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be > 12 mon AND < 4 yr, Single does of MMR administered at 12 - 15 mon of age, Recommendation should be Schedule 2nd dose 4-6 yr of age', async () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be > 12 mon AND < 4 yr, Single does of MMR administered at < 12 mon OR > 15 mon and current date must be >= 4 weeks since last admin date, Recommendation should be Administer 2nd Dose', async () => {
const rule = elms.MMR5regular12months_4yrs_OneDoseOutOf12to15MonRecommendation;
const patient = patientBundles.MMR5regular12months_4yrs_OneDoseOutOf12to15MonRecommendation1.entry[0].resource;

Expand Down Expand Up @@ -260,7 +260,7 @@ describe('MMR Rule 5 Tests ', () => {
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('Administer 2nd dose MMR'));
});
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be > 12 mon AND < 4 yr, Single does of MMR administered at 12 - 15 mon of age, Recommendation should be Schedule 2nd dose 4-6 yr of age', async () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be > 12 mon AND < 4 yr, Single does of MMR administered at < 12 mon OR > 15 mon and current date must be >= 4 weeks since last admin date, Recommendation should be Administer 2nd Dose', async () => {
const rule = elms.MMR5regular12months_4yrs_OneDoseOutOf12to15MonRecommendation;
const patient = patientBundles.MMR5regular12months_4yrs_OneDoseOutOf12to15MonRecommendation2.entry[0].resource;

Expand Down Expand Up @@ -310,6 +310,148 @@ describe('MMR Rule 5 Tests ', () => {

});

describe('MMR Rule 6 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be > 12 mon AND < 4 yr, Single does of MMR administered at < 12 mon OR > 15 mon and current date must be < 4 weeks since last admin date, Recommendation should be Schedule 2nd dose >= 4 wk of 1st dose', async () => {
const rule = elms.MMR6regular12months_4yrs_OneDoseOutOf12to15MonRecommendation;
const patient = patientBundles.MMR6regular12months_4yrs_OneDoseOutOf12to15MonRecommendation1.entry[0].resource;

const immunization = patientBundles.MMR6regular12months_4yrs_OneDoseOutOf12to15MonRecommendation1.entry[1].resource;
const immBundle = {
resourceType: 'Bundle',
entry: [{ resource: immunization }],
};
const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true);
const result = await executeCql(patient, rule, libraries, { Imm: immBundle }, codeService, API_KEY);

const patientResult = result[patient.id];

const patientBod = new Date(patient.birthDate);
const immunizationAdminDate = new Date(immunization.occurrenceDateTime);

const now = new Date();
const ageInMonths = getNumberOfMonths(patientBod, now);
const adminAgeInMonths = getNumberOfMonths(patientBod, immunizationAdminDate);

const weeksSinceFirstDose = getNumberOfWeeks(immunizationAdminDate, new Date());
expect(patientResult.VaccineName)
.toEqual('Measles, Mumps, and Rubella Virus Vaccine');
expect(patientResult.InPopulation)
.toBeTruthy();
expect(ageInMonths)
.toBeLessThan(4 * 12);
expect(ageInMonths)
.toBeGreaterThan(12);

expect(adminAgeInMonths < 12 || adminAgeInMonths > 15)
.toBeTruthy();

expect(weeksSinceFirstDose)
.toBeLessThan(4);
expect(immBundle.entry)
.toHaveLength(1);
expect(patientResult.Recommendations)
.toHaveLength(1);
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('Schedule 2nd dose >= 4 wk of 1st dose'));
});
});

describe('MMR Rule 7 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be >= 12 4 yr AND <= 18 yr, Single does of MMR administered and current date must be >= 4 weeks since last admin date, Recommendation should be Administer 2nd dose', async () => {
const rule = elms.MMR7regular4_18yrs_OneDoseRecommendation;
const patient = patientBundles.MMR7regular4_18yrs_OneDoseRecommendation.entry[0].resource;

const immunization = patientBundles.MMR7regular4_18yrs_OneDoseRecommendation.entry[1].resource;
const immBundle = {
resourceType: 'Bundle',
entry: [{ resource: immunization }],
};
const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true);
const result = await executeCql(patient, rule, libraries, { Imm: immBundle }, codeService, API_KEY);

const patientResult = result[patient.id];

const patientBod = new Date(patient.birthDate);
const immunizationAdminDate = new Date(immunization.occurrenceDateTime);

const now = new Date();
const ageInMonths = getNumberOfMonths(patientBod, now);

const weeksSinceFirstDose = getNumberOfWeeks(immunizationAdminDate, new Date());
expect(patientResult.VaccineName)
.toEqual('Measles, Mumps, and Rubella Virus Vaccine');
expect(patientResult.InPopulation)
.toBeTruthy();
expect(ageInMonths)
.toBeLessThanOrEqual(18 * 12);
expect(ageInMonths)
.toBeGreaterThanOrEqual(4 * 12);

expect(weeksSinceFirstDose)
.toBeGreaterThanOrEqual(4);
expect(immBundle.entry)
.toHaveLength(1);
expect(patientResult.Recommendations)
.toHaveLength(1);
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('Administer 2nd dose MMR'));
});
});

describe('MMR Rule 8 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, Patient birthdate should be >= 12 4 yr AND <= 18 yr, Single does of MMR administered and current date must be < 4 weeks since last admin date, Recommendation should be Schedule 2nd dose MMR >= 4 weeks from 1st dose', async () => {
const rule = elms.MMR8regular4_18yrs_OneDoseRecommendation;
const patient = patientBundles.MMR8regular4_18yrs_OneDoseRecommendation.entry[0].resource;

const immunization = patientBundles.MMR8regular4_18yrs_OneDoseRecommendation.entry[1].resource;
const immBundle = {
resourceType: 'Bundle',
entry: [{ resource: immunization }],
};
const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true);
const result = await executeCql(patient, rule, libraries, { Imm: immBundle }, codeService, API_KEY);

const patientResult = result[patient.id];

const patientBod = new Date(patient.birthDate);
const immunizationAdminDate = new Date(immunization.occurrenceDateTime);

const now = new Date();
const ageInMonths = getNumberOfMonths(patientBod, now);

const weeksSinceFirstDose = getNumberOfWeeks(immunizationAdminDate, new Date());
expect(patientResult.VaccineName)
.toEqual('Measles, Mumps, and Rubella Virus Vaccine');
expect(patientResult.InPopulation)
.toBeTruthy();
expect(ageInMonths)
.toBeLessThanOrEqual(18 * 12);
expect(ageInMonths)
.toBeGreaterThanOrEqual(4 * 12);

expect(weeksSinceFirstDose)
.toBeLessThan(4);
expect(immBundle.entry)
.toHaveLength(1);
expect(patientResult.Recommendations)
.toHaveLength(1);
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('Schedule 2nd dose MMR >= 4 weeks from 1st dose'));
});
});

describe('MMR Rule 9 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, with Pregnancy Condition, No previous dose, Recommendation should be Schedule/admin 1st dose after pregnancy AND Schedule 2nd dose >= 4 wk of 1st dose', async () => {

Expand Down Expand Up @@ -340,3 +482,88 @@ describe('MMR Rule 9 Tests ', () => {
});
});

describe('MMR Rule 10 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, with Pregnancy Condition, One previous dose, Recommendation should be Schedule/admin 2nd dose after pregnancy, >= 4 wk of 1st dose', async () => {

const rule = elms.MMR10MedicalContraPrecautionMMRRecommendation;
const patient = patientBundles.MMR10MedicalContraPrecautionMMRRecommendation.entry[0].resource;

// const patient = firstPatientBundle.entry[0].resource;
const condition = patientBundles.MMR10MedicalContraPrecautionMMRRecommendation.entry[1].resource;
const immunization = patientBundles.MMR10MedicalContraPrecautionMMRRecommendation.entry[2].resource;

const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true, true);
const result = await executeCql(patient, rule, libraries, {
Imm: [immunization],
Conditions: [condition],
}, codeService, API_KEY);
const patientResult = result[patient.id];

expect(patientResult.Recommendations)
.toHaveLength(1);
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('Schedule/admininster 2nd dose after pregnancy, >= 4 wk of 1st dose'));

});
});

describe('MMR Rule 11 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, with Immunocompromised Condition, Recommendation should be DO NOT ADMINISTER OR SCHEDULE MMR', async () => {

const rule = elms.MMR11MedicalContraPrecautionMMRRecommendation_Immunocompromised;
const patient = patientBundles.MMR11MedicalContraPrecautionMMRRecommendation_Immunocompromised.entry[0].resource;

// const patient = firstPatientBundle.entry[0].resource;
const condition = patientBundles.MMR11MedicalContraPrecautionMMRRecommendation_Immunocompromised.entry[1].resource;

const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true, true);
const result = await executeCql(patient, rule, libraries, {
Conditions: [condition],
}, codeService, API_KEY);
const patientResult = result[patient.id];

expect(patientResult.Recommendations)
.toHaveLength(1);
expect(patientResult.Recommendations[0].recommendation)
.toEqual(expect.stringContaining('DO NOT ADMINISTER OR SCHEDULE MMR'));

});
});

describe('MMR Rule 12 Tests ', () => {
test('VaccineName should be Measles, Mumps, and Rubella Virus Vaccine, with Immunocompromised Condition, Recommendation should be DO NOT ADMINISTER OR SCHEDULE MMR', async () => {

const rule = elms.MMR12MedicalContraPrecautionMMRRecommendation_HIVImmunocompromised;
const patient = patientBundles.MMR12MedicalContraPrecautionMMRRecommendation_HIVImmunocompromised.entry[0].resource;

// const patient = firstPatientBundle.entry[0].resource;
const condition = patientBundles.MMR12MedicalContraPrecautionMMRRecommendation_HIVImmunocompromised.entry[1].resource;

const libraries = {
FHIRHelpers: elms.FHIRHelpers,
Common: elms.MMR_Common_Library,
};
const codeService = new vsac.CodeService(VALUESETS_CACHE, true, true);
const result = await executeCql(patient, rule, libraries, {
Conditions: [condition],
Observations: []
}, codeService, API_KEY);
const patientResult = result[patient.id];

console.log(JSON.stringify(patientResult, null, 2));
// expect(patientResult.Recommendations)
// .toHaveLength(1);
// expect(patientResult.Recommendations[0].recommendation)
// .toEqual(expect.stringContaining('DO NOT ADMINISTER OR SCHEDULE MMR'));

});
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
library "MMR10MedicalContraPrecautionMMRRecommendation" version '1'

include "MMR_Common_Library" version '1' called Common

using FHIR version '4.0.1'

include "FHIRHelpers" version '4.0.1' called FHIRHelpers


parameter Imm List<Immunization>
parameter Conditions List<Condition>

context Patient


define "MMR_Vaccine_OneDose":
Count(Common.FindValidVaccines(Imm)) = 1


define "Pregnant_Exist":
Count(Common.FindValidPregnantCondition(Conditions)) > 0




define "InPopulation":
MMR_Vaccine_OneDose and Pregnant_Exist


/*
rationale
If patient does not have MMR or MMRV records and patient is pregnant, schedule 1st dose of MMR after pregnancy and 2nd dose after 4 weeks of the 1st dose
*/



define "Recommendation1":
if InPopulation then
'Schedule/admininster 2nd dose after pregnancy, >= 4 wk of 1st dose'
else null

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library "MMR11MedicalContraPrecautionMMRRecommendation_Immunocompromised" version '1'

include "MMR_Common_Library" version '1' called Common

using FHIR version '4.0.1'

include "FHIRHelpers" version '4.0.1' called FHIRHelpers


parameter Conditions List<Condition>




context Patient

define "InPopulation":
Count(Common.FindValidImmunocompromisedCondition(Conditions)) > 0


/*
rationale
If patient does not have MMR or MMRV records and patient is pregnant, schedule 1st dose of MMR after pregnancy and 2nd dose after 4 weeks of the 1st dose
*/

define "Recommendation1":
if InPopulation then
'DO NOT ADMINISTER OR SCHEDULE MMR'
else
null


Loading

0 comments on commit ce05f9b

Please sign in to comment.