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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BS-208 | Patrick | Update system information in FHIR bundle payload
  • Loading branch information
nyatindopatrick committed Sep 1, 2023
commit 489fe777e02b99a043ca02aea1f957e10260eb89
52 changes: 46 additions & 6 deletions ui/app/clinical/consultation/controllers/diagnosisController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ angular.module('bahmni.clinical')
$scope.hasAnswers = false;

$scope.cdssEnabled = false;
$scope.conceptSource = localStorage.getItem('conceptSource') || '';

$scope.orderOptions = {
'CLINICAL_DIAGNOSIS_ORDER_PRIMARY': 'PRIMARY',
Expand Down Expand Up @@ -70,7 +71,7 @@ angular.module('bahmni.clinical')
const newMedications = $scope.consultation.newlyAddedTabTreatments;
var drugs = [];

function createDrugObject (medication) {
function createDrugObject (medication, conceptSource) {
return {
"resourceType": "MedicationRequest",
"id": medication.uuid,
Expand All @@ -81,7 +82,7 @@ angular.module('bahmni.clinical')
{
display: medication.drug.name,
code: medication.concept.mappings ? medication.concept.mappings[0].code : medication.drug.uuid,
system: medication.concept.mappings ? medication.concept.mappings[0].source : 'https://fhir.openmrs.org'
system: medication.concept.mappings ? medication.concept.mappings[0].source : conceptSource
}
]
},
Expand All @@ -91,15 +92,42 @@ angular.module('bahmni.clinical')
};
}

function processMedication (medication) {
medication.concept.mappings = medication.concept.mappings && medication.concept.mappings.map(function (mapping) {
return {
code: mapping.code || mapping.uuid,
source: mapping.source && mapping.source.match(/^(http|https):\/\//) ? mapping.source : $scope.conceptSource,
display: mapping.display
};
});
drugs.push({ resource: createDrugObject(medication, $scope.conceptSource) });
}

if (medications && medications.length > 0) {
medications.forEach(function (medication) {
drugs.push({ resource: createDrugObject(medication) });
if (!$scope.conceptSource) {
drugService.getDrugConceptSourceMapping(medication.uuid).then(function (response) {
var bundle = response.data;
var code = bundle.entry && bundle.entry.length > 0 && bundle.entry[0].resource.code;
var conceptCode = code.coding.find(function (coding) {
return coding.system;
});

if (conceptCode) {
localStorage.setItem("conceptSource", conceptCode.system);
$scope.conceptSource = conceptCode.system;
processMedication(medication);
}
});
} else {
processMedication(medication);
}
});
}

if (newMedications && newMedications.allMedications && newMedications.allMedications.treatments.length > 0) {
newMedications.allMedications.treatments.forEach(function (medication) {
drugs.push({ resource: createDrugObject(medication) });
processMedication(medication);
});
}

Expand All @@ -111,13 +139,25 @@ angular.module('bahmni.clinical')
var diagnosisLists = [$scope.consultation.newlyAddedDiagnoses, $scope.consultation.savedDiagnosesFromCurrentEncounter, $scope.consultation.pastDiagnoses];

function createDiagnosisResource (diagnosis) {
var conditionStatus = diagnosis.status || diagnosis.certainty || 'ACTIVE';
var activeConditions = ['CONFIRMED', 'PRESUMED', 'ACTIVE'];
var status = activeConditions.indexOf(conditionStatus) > -1 ? 'active' : 'inactive';
return {
resourceType: 'Condition',
id: diagnosis.uuid,
clinicalStatus: {
coding: [
{
system: diagnosis.codedAnswer.mappings ? diagnosis.codedAnswer.mappings[0].source : 'https://fhir.openmrs.org',
code: status,
display: status.charAt(0).toUpperCase() + status.slice(1),
system: 'http://terminology.hl7.org/CodeSystem/condition-clinical'
}
]
},
code: {
coding: [
{
system: diagnosis.codedAnswer.mappings ? diagnosis.codedAnswer.mappings[0].source : diagnosis.codedAnswer.conceptSystem || 'https://fhir.openmrs.org',
code: diagnosis.codedAnswer.mappings ? diagnosis.codedAnswer.mappings[0].code : diagnosis.codedAnswer.uuid,
display: diagnosis.codedAnswer.name
}
Expand Down Expand Up @@ -145,7 +185,7 @@ angular.module('bahmni.clinical')
var medications = medicationResource();
var bundle = {
"resourceType": "Bundle",
"type": "transaction",
"type": "collection",
"entry": [].concat(diagnoses, medications)
};

Expand Down
8 changes: 8 additions & 0 deletions ui/app/clinical/consultation/views/diagnosis.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
{{ ::'CLINICAL_DIAGNOSIS' | translate }}
</div>
<div class="col-body">
<span ng-if="diagnosis.alert" class="alert-item">
<button class="cdss-alert-icon button-alert alert-button">
<i class="fa cdss-icon-medication"
ng-class="{'fa-exclamation-triangle critical': diagnosis.alert.indicator == 'critical','fa-exclamation-triangle warning' : diagnosis.alert.indicator == 'warning', 'fa-info-circle info': diagnosis.alert.indicator == 'info'}"
>
</i>
</button>
</span>
<input ng-model="diagnosis.codedAnswer.name" type="text" name="name"
id="name-{{$index}}" bahmni-autocomplete source="getDiagnosis"
response-map="cleanOutDiagnosisList"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe("Diagnosis Controller", function () {
var $scope, rootScope, contextChangeHandler,mockDiagnosisService, spinner, appService, mockAppDescriptor, q, deferred, mockDiagnosisData, translate, retrospectiveEntryService;
var $scope, rootScope, contextChangeHandler,mockDiagnosisService, spinner, appService, mockAppDescriptor, q, deferred, mockDiagnosisData, translate, retrospectiveEntryService, drugService;
var DateUtil = Bahmni.Common.Util.DateUtil;

beforeEach(module('bahmni.clinical'));
Expand Down Expand Up @@ -39,6 +39,14 @@ describe("Diagnosis Controller", function () {

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

drugService = jasmine.createSpyObj('drugService', ['getCdssEnabled', 'sendDiagnosisDrugBundle']);

drugService.getCdssEnabled.and.returnValue(specUtil.respondWith(true));

drugService.sendDiagnosisDrugBundle.and.returnValue(specUtil.respondWith({
data: []
}));

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

Expand Down