Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BS-208 | Placement of Alert near Diagnosis #687

Merged
merged 11 commits into from
Oct 5, 2023
Merged
Prev Previous commit
BS-208 | Patrick | Add Unit tests
  • Loading branch information
nyatindopatrick committed Oct 3, 2023
commit 62a08af48143b13125627417e19d70ede332fbd4
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ angular.module('bahmni.clinical')
var cdssAlerts = drugService.sendDiagnosisDrugBundle(bundle);
cdssAlerts.then(function (response) {
var alerts = response.data;

$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,143 @@
describe("Diagnosis Controller", function () {
var $scope, rootScope, contextChangeHandler,mockDiagnosisService, spinner, appService, mockAppDescriptor, q, deferred, mockDiagnosisData, translate, retrospectiveEntryService, drugService;
var $scope, rootScope, contextChangeHandler, mockDiagnosisService, spinner, appService, mockAppDescriptor, q, deferred, mockDiagnosisData, translate, retrospectiveEntryService, drugService, cdssService;
var DateUtil = Bahmni.Common.Util.DateUtil;

beforeEach(module('bahmni.clinical'));

var cdssBundle = {
"resourceType": "Bundle",
"type": "collection",
"entry": [
{
"resource": {
"resourceType": "Condition",
"clinicalStatus": {
"coding": [
{
"code": "active",
"display": "Active",
"system": "http://terminology.hl7.org/CodeSystem/condition-clinical"
}
]
},
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "123456789",
"display": "Placeholder Diagnosis"
}
],
"text": "Placeholder Diagnosis"
},
"subject": {
"reference": "Patient/dc9444c6-ad55-4200-b6e9-407e025eb948"
}
}
},
{
"resource": {
"resourceType": "MedicationRequest",
"status": "active",
"intent": "order",
"subject": {
"reference": "Patient/dc9444c6-ad55-4200-b6e9-407e025eb948"
},
"medicationCodeableConcept": {
"id": "987654321",
"coding": [
{
"system": "http://snomed.info/sct",
"code": "987654321",
"display": "Placeholder Medication"
},
{
"code": "987654321",
"system": "https://example.com",
"display": "Placeholder Medication"
}
],
"text": "Placeholder Medication"
},
"dosageInstruction": [
{
"text": "{\"instructions\":\"As directed\"}",
"timing": {
"event": [
"2023-10-01T05:58:27.000Z"
],
"repeat": {
"duration": 3,
"durationUnit": "d"
},
"code": {
"coding": [
{
"code": "987654321",
"display": "Twice a day"
}
],
"text": "Twice a day"
}
},
"asNeededBoolean": false,
"doseAndRate": [
{
"doseQuantity": {
"value": 3,
"unit": "Tablet(s)",
"code": "987654321"
}
}
]
}
]
}
}
]
};

var cdssResponse = [{
"uuid": "7b544b67-fbc7-48af-af95-ddaee09e836b",
"indicator": "warning",
"summary": "Contraindication: \"Placeholder Medication\" and \"Placeholder Medication\" with patient condition \"Placeholder Condition\" and \"Placeholder Condition\".",
"detail": "The use of Placeholder Medication is contraindicated when the patient has Placeholder Condition.",
"source": {
"label": "Wikipedia",
"url": "https://en.wikipedia.org/wiki/Atorvastatin#Contraindications"
},
"referenceMedications": [
{
"coding": [
{
"system": "http://snomed.info/sct",
"code": "987654321",
"display": "Placeholder Medication"
},
{
"system": "https://example.com",
"code": "987654321",
"display": "Placeholder Medication"
}
]
}
],
"referenceCondition": {
"coding": [
{
"system": "https://example.com",
"code": "123456789",
"display": "Placeholder Condition"
},
{
"system": "http://snomed.info/sct",
"code": "123456789",
"display": "Placeholder Condition"
}
]
}
}];

beforeEach(inject(function ($controller, $rootScope, $q, diagnosisService) {
$scope = $rootScope.$new();
rootScope = $rootScope;
Expand Down Expand Up @@ -35,7 +169,7 @@ describe("Diagnosis Controller", function () {
}
}
});
translate = jasmine.createSpyObj('$translate',['instant']);
translate = jasmine.createSpyObj('$translate', ['instant']);

retrospectiveEntryService = jasmine.createSpyObj('retrospectiveEntryService', ['isRetrospectiveMode']);

Expand All @@ -47,6 +181,13 @@ describe("Diagnosis Controller", function () {
data: []
}));

cdssService = jasmine.createSpyObj('cdssService', ['createFhirBundle', 'sendDiagnosisDrugBundle', 'createParams', 'addNewAlerts', 'sortInteractionsByStatus']);
cdssService.createParams.and.returnValue(specUtil.respondWith({}));
cdssService.createFhirBundle.and.returnValue(specUtil.respondWith(cdssBundle));
cdssService.sendDiagnosisDrugBundle.and.returnValue(specUtil.respondWith(cdssResponse));
cdssService.addNewAlerts.and.returnValue(specUtil.respondWith(cdssResponse));
cdssService.sortInteractionsByStatus.and.returnValue(specUtil.respondWith(cdssResponse));

$controller('DiagnosisController', {
$scope: $scope,
$rootScope: rootScope,
Expand All @@ -56,7 +197,8 @@ describe("Diagnosis Controller", function () {
diagnosisService: mockDiagnosisService,
$translate: translate,
retrospectiveEntryService: retrospectiveEntryService,
drugService: drugService
drugService: drugService,
cdssService: cdssService
});
}));

Expand Down
142 changes: 142 additions & 0 deletions ui/test/unit/clinical/consultation/services/cdssService.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
describe('cdssService', function () {
var consultationDataMock = {
patient: {
uuid: 'patient_uuid_here'
},
conditions: [
{
uuid: 'condition_uuid_1',
status: 'CONFIRMED',
concept: {
uuid: 'concept_uuid_1',
name: 'Condition Name 1'
}
}
],
newlyAddedDiagnoses: [
{
uuid: 'diagnosis_uuid_1',
certainty: 'CONFIRMED',
codedAnswer: {
uuid: 'coded_answer_uuid_1',
name: 'Diagnosis Name 1'
}
},
{
uuid: 'diagnosis_uuid_2',
certainty: 'CONFIRMED',
codedAnswer: {
uuid: 'coded_answer_uuid_2',
name: 'Diagnosis Name 2'
}
}
],
draftDrug: [
{
uuid: 'medication_uuid_1',
drug: {
uuid: 'drug_uuid_1',
name: 'Drug Name 1'
},
instructions: 'Take once a day',
effectiveStartDate: '2023-10-03T08:00:00Z',
durationInDays: 7,
durationUnit: 'DAYS',
asNeeded: false,
uniformDosingType: {
frequency: 'Once daily',
dose: 1
},
doseUnits: 'mg'
}
]
};

var cdssService;
var drugService = jasmine.createSpyObj('drugService', ['getDrugConceptSourceMapping']);
drugService.getDrugConceptSourceMapping.and.callFake(function () {
return specUtil.respondWith({
data: {
entry: [{
resource: {
code: {
coding: [{
system: 'http://example.com',
code: '12345',
display: 'Sample Drug'
}]
}
}
}]
}
});
});

beforeEach(function () {
module('bahmni.clinical');

module(function ($provide) {
$provide.value('drugService', drugService);
});

inject(['cdssService', function (cdssServiceInjected) {
cdssService = cdssServiceInjected;
}]);
});

it('Should feturn an object with parameters for cdss request', function () {
var params = cdssService.createParams(consultationDataMock);
expect(params.patient).toEqual(consultationDataMock.patient);
expect(params.conditions).toEqual(consultationDataMock.conditions);
expect(params.diagnosis).toEqual(consultationDataMock.newlyAddedDiagnoses);
expect(params.medications).toEqual(consultationDataMock.draftDrug);
});

it('Should return a bundle of resources', function () {
cdssService.createFhirBundle(consultationDataMock.patient, consultationDataMock.conditions, consultationDataMock.draftDrug, consultationDataMock.newlyAddedDiagnoses, 'http://example.com').then(function (bundle) {

expect(bundle.resourceType).toEqual('Bundle');
expect(bundle.type).toEqual('collection');
expect(bundle.entry.length).toEqual(3);
expect(bundle.entry[0].resource.resourceType).toEqual('Condition');
expect(bundle.entry[2].resource.resourceType).toEqual('MedicationRequest');
});
});

it('Should return an array of alerts sorted by status', function () {
var alerts = [
{
uuid: 'alert_uuid_1',
indicator: 'warning',
isActive: false,
detail: 'Alert Detail 1',
source: {
url: 'http://example.com'
}
},
{
uuid: 'alert_uuid_2',
indicator: 'critical',
isActive: true,
detail: 'Alert Detail 2',
source: {
url: 'http://example.com'
}
},
{
uuid: 'alert_uuid_3',
indicator: 'info',
isActive: true,
detail: 'Alert Detail 3',
source: {
url: 'http://example.com'
}
}
];
var sortedAlerts = cdssService.sortInteractionsByStatus(alerts);
expect(sortedAlerts[0].indicator).toEqual('critical');
expect(sortedAlerts[1].indicator).toEqual('warning');
expect(sortedAlerts[2].indicator).toEqual('info');
});
});

Loading