Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ configuration/
├── locations/
├── locationtagmaps/
├── locationtags/
├── medicationsideeffects/
├── messageproperties/
├── metadatasetmembers/
├── metadatasets/
Expand Down Expand Up @@ -160,6 +161,7 @@ This is the list of currently supported domains in their loading order:
1. [Identifier Sources (CSV files)](readme/idgen.md)
1. [Autogeneration Options (CSV files)](readme/autogenerationoptions.md)
1. [Drugs (CSV files)](readme/drugs.md)
1. [Medication Side Effects (CSV files)](readme/medicationsideeffects.md)
1. [Order Frequencies (CSV files)](readme/freqs.md)
1. [Order Types (CSV files)](readme/ordertypes.md)
1. [Bahmni Appointment Specialities (CSV files)](readme/appointmentspecialities.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected boolean matchesSafely(List<Loader> loaders, Description mismatchDescri
exclude.add(Domain.BILLABLE_SERVICES.getName());
exclude.add(Domain.CASH_POINTS.getName());
exclude.add(Domain.CASHIER_ITEM_PRICES.getName());
exclude.add(Domain.MEDICATION_SIDE_EFFECTS.getName());
exclude.add(Domain.CONCEPT_REFERENCE_RANGE.getName());
exclude.add(Domain.FLAGS.getName());
exclude.add(Domain.FLAG_PRIORITIES.getName());
Expand Down
7 changes: 7 additions & 0 deletions api-2.4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@
<version>${billingVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>medicationsideeffects-api</artifactId>
<version>${medicationsideeffectsVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.initializer.api.medicationsideeffects;

import org.apache.commons.lang3.StringUtils;
import org.openmrs.Concept;
import org.openmrs.Drug;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.api.ConceptService;
import org.openmrs.module.initializer.api.BaseLineProcessor;
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.medicationsideeffects.model.MedicationSideEffect;
import org.openmrs.module.medicationsideeffects.model.SideEffectClassification;
import org.springframework.beans.factory.annotation.Autowired;

@OpenmrsProfile(modules = { "medicationsideeffects:1.0.0 - 9.*" })
public class MedicationSideEffectLineProcessor extends BaseLineProcessor<MedicationSideEffect> {

protected static final String HEADER_DRUG_UUID = "Drug Uuid";

protected static final String HEADER_CLASSIFICATION = "Classification";

protected static final String HEADER_CONCEPT_UUID = "Side Effect Concept Uuid";

protected static final String HEADER_SIDE_EFFECT_TEXT = "Side Effect Text";

protected static final String HEADER_RECOMMENDED_ACTION = "Recommended Action";

protected static final String HEADER_NOTES = "Notes";

private final ConceptService conceptService;

@Autowired
public MedicationSideEffectLineProcessor(ConceptService conceptService) {
this.conceptService = conceptService;
}

@Override
public MedicationSideEffect fill(MedicationSideEffect instance, CsvLine line) throws IllegalArgumentException {
String drugUuid = line.get(HEADER_DRUG_UUID, true);
Drug drug = conceptService.getDrugByUuid(drugUuid);
if (drug == null) {
throw new IllegalArgumentException("No drug found for uuid '" + drugUuid + "'");
}
instance.setDrug(drug);

String classification = line.get(HEADER_CLASSIFICATION, true);
try {
instance.setClassification(SideEffectClassification.valueOf(classification.toUpperCase()));
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Invalid classification '" + classification + "' (expected common or serious)");
}

String conceptUuid = line.getString(HEADER_CONCEPT_UUID);
Concept concept = null;
if (StringUtils.isNotBlank(conceptUuid)) {
concept = conceptService.getConceptByUuid(conceptUuid);
if (concept == null) {
throw new IllegalArgumentException("No concept found for uuid '" + conceptUuid + "'");
}
}
instance.setSideEffectConcept(concept);

instance.setSideEffectText(line.getString(HEADER_SIDE_EFFECT_TEXT));
instance.setRecommendedAction(line.getString(HEADER_RECOMMENDED_ACTION));
instance.setNotes(line.getString(HEADER_NOTES));

if (concept == null && StringUtils.isBlank(instance.getSideEffectText())) {
throw new IllegalArgumentException("either 'Side Effect Concept Uuid' or 'Side Effect Text' must be provided");
}

return instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.initializer.api.medicationsideeffects;

import org.apache.commons.lang3.StringUtils;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.initializer.Domain;
import org.openmrs.module.initializer.api.BaseLineProcessor;
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.initializer.api.CsvParser;
import org.openmrs.module.medicationsideeffects.model.MedicationSideEffect;
import org.openmrs.module.medicationsideeffects.service.MedicationSideEffectService;
import org.springframework.beans.factory.annotation.Autowired;

@OpenmrsProfile(modules = { "medicationsideeffects:1.0.0 - 9.*" })
public class MedicationSideEffectsCsvParser extends CsvParser<MedicationSideEffect, BaseLineProcessor<MedicationSideEffect>> {

private final MedicationSideEffectService service;

@Autowired
public MedicationSideEffectsCsvParser(MedicationSideEffectService service,
MedicationSideEffectLineProcessor lineProcessor) {
super(lineProcessor);
this.service = service;
}

@Override
public MedicationSideEffect bootstrap(CsvLine line) throws IllegalArgumentException {
String uuid = line.getUuid();
MedicationSideEffect sideEffect = service.getByUuid(uuid);
if (sideEffect == null) {
sideEffect = new MedicationSideEffect();
if (StringUtils.isNotBlank(uuid)) {
sideEffect.setUuid(uuid);
}
}
return sideEffect;
}

@Override
public MedicationSideEffect save(MedicationSideEffect instance) {
return service.saveMedicationSideEffect(instance);
}

@Override
public Domain getDomain() {
return Domain.MEDICATION_SIDE_EFFECTS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.initializer.api.medicationsideeffects;

import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
import org.openmrs.module.medicationsideeffects.model.MedicationSideEffect;
import org.springframework.beans.factory.annotation.Autowired;

@OpenmrsProfile(modules = { "medicationsideeffects:1.0.0 - 9.*" })
public class MedicationSideEffectsLoader extends BaseCsvLoader<MedicationSideEffect, MedicationSideEffectsCsvParser> {

@Autowired
public void setParser(MedicationSideEffectsCsvParser parser) {
this.parser = parser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public DomainBaseModuleContextSensitive_2_4_test() {
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "medicationsideeffects", "", "", "", "1.0.0");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.initializer.api.medicationsideeffects;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openmrs.Concept;
import org.openmrs.Drug;
import org.openmrs.api.ConceptService;
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.medicationsideeffects.model.MedicationSideEffect;
import org.openmrs.module.medicationsideeffects.model.SideEffectClassification;

public class MedicationSideEffectLineProcessorTest {

private static final String[] HEADERS = new String[] { "Uuid", "Void/Retire", "Drug Uuid", "Classification",
"Side Effect Concept Uuid", "Side Effect Text", "Recommended Action", "Notes" };

private static final String DRUG_UUID = "a1a1a1a1-0000-0000-0000-000000000001";

private static final String CONCEPT_UUID = "b1b1b1b1-0000-0000-0000-000000000001";

@Mock
private ConceptService conceptService;

private MedicationSideEffectLineProcessor processor;

private Drug drug;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
processor = new MedicationSideEffectLineProcessor(conceptService);
drug = new Drug();
drug.setUuid(DRUG_UUID);
when(conceptService.getDrugByUuid(DRUG_UUID)).thenReturn(drug);
}

private CsvLine line(String... values) {
return new CsvLine(HEADERS, values);
}

@Test
public void fill_shouldMapCodedCommonEffect() {
Concept concept = new Concept();
concept.setUuid(CONCEPT_UUID);
when(conceptService.getConceptByUuid(CONCEPT_UUID)).thenReturn(concept);

MedicationSideEffect result = processor.fill(new MedicationSideEffect(),
line(null, null, DRUG_UUID, "common", CONCEPT_UUID, null, null, "Nausea note"));

assertEquals(drug, result.getDrug());
assertEquals(SideEffectClassification.COMMON, result.getClassification());
assertEquals(concept, result.getSideEffectConcept());
assertNull(result.getSideEffectText());
assertEquals("Nausea note", result.getNotes());
}

@Test
public void fill_shouldMapFreeTextSeriousEffect() {
MedicationSideEffect result = processor.fill(new MedicationSideEffect(),
line(null, null, DRUG_UUID, "serious", null, "Signs of liver injury", "Seek urgent care", null));

assertEquals(SideEffectClassification.SERIOUS, result.getClassification());
assertNull(result.getSideEffectConcept());
assertEquals("Signs of liver injury", result.getSideEffectText());
assertEquals("Seek urgent care", result.getRecommendedAction());
}

@Test(expected = IllegalArgumentException.class)
public void fill_shouldThrowWhenDrugNotFound() {
processor.fill(new MedicationSideEffect(), line(null, null, "missing-drug-uuid", "common", null, "x", null, null));
}

@Test(expected = IllegalArgumentException.class)
public void fill_shouldThrowWhenClassificationInvalid() {
processor.fill(new MedicationSideEffect(), line(null, null, DRUG_UUID, "moderate", null, "x", null, null));
}

@Test(expected = IllegalArgumentException.class)
public void fill_shouldThrowWhenNeitherConceptNorTextProvided() {
processor.fill(new MedicationSideEffect(), line(null, null, DRUG_UUID, "common", null, null, null, null));
}
}
Loading