-
Notifications
You must be signed in to change notification settings - Fork 79
Add domain for FHIR ObservationCategoryMaps #201
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
Open
ibacher
wants to merge
4
commits into
main
Choose a base branch
from
fhir-obs-category-maps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...java/org/openmrs/module/initializer/api/fhir/ocm/FhirObservationCategoryMapCsvParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.openmrs.module.initializer.api.fhir.ocm; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.openmrs.ConceptClass; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.module.fhir2.model.FhirObservationCategoryMap; | ||
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.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
import static org.openmrs.module.initializer.Domain.FHIR_OBSERVATION_CATEGORY_MAPS; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.*" }) | ||
public class FhirObservationCategoryMapCsvParser extends CsvParser<FhirObservationCategoryMap, BaseLineProcessor<FhirObservationCategoryMap>> { | ||
|
||
public static final String FHIR_OBS_CATEGORY_HEADER = "Fhir observation category"; | ||
|
||
public static final String CONCEPT_CLASS_HEADER = "Concept class"; | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
@Autowired | ||
protected FhirObservationCategoryMapCsvParser(@Qualifier("sessionFactory") SessionFactory sessionFactory, | ||
BaseLineProcessor<FhirObservationCategoryMap> lineProcessor) { | ||
super(lineProcessor); | ||
|
||
this.sessionFactory = sessionFactory; | ||
} | ||
|
||
@Override | ||
public Domain getDomain() { | ||
return FHIR_OBSERVATION_CATEGORY_MAPS; | ||
} | ||
|
||
@Override | ||
public FhirObservationCategoryMap bootstrap(CsvLine line) throws IllegalArgumentException { | ||
FhirObservationCategoryMap result = null; | ||
|
||
String fhirObsCategory = line.get(FHIR_OBS_CATEGORY_HEADER); | ||
String conceptClass = line.get(CONCEPT_CLASS_HEADER); | ||
|
||
if (fhirObsCategory != null && !fhirObsCategory.isEmpty() && conceptClass != null && !conceptClass.isEmpty()) { | ||
result = (FhirObservationCategoryMap) sessionFactory.getCurrentSession() | ||
.createQuery("from " + FhirObservationCategoryMap.class.getSimpleName() | ||
+ " where observationCategory = :fhirObsCategory and conceptClass = (" + "select cc from " | ||
+ ConceptClass.class.getSimpleName() + " cc where cc.name = :conceptClass or cc.uuid = :conceptClass" + ")") | ||
.setParameter("fhirObsCategory", fhirObsCategory).setParameter("conceptClass", conceptClass) | ||
.uniqueResult(); | ||
} | ||
|
||
if (result == null && line.getUuid() != null && !line.getUuid().isEmpty()) { | ||
result = (FhirObservationCategoryMap) sessionFactory.getCurrentSession() | ||
.createQuery("from " + FhirObservationCategoryMap.class.getSimpleName() + " where uuid = :uuid") | ||
.setParameter("uuid", line.getUuid()).uniqueResult(); | ||
} | ||
|
||
if (result == null) { | ||
result = new FhirObservationCategoryMap(); | ||
result.setUuid(line.getUuid()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public FhirObservationCategoryMap save(FhirObservationCategoryMap instance) { | ||
sessionFactory.getCurrentSession().saveOrUpdate(instance); | ||
return instance; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../org/openmrs/module/initializer/api/fhir/ocm/FhirObservationCategoryMapLineProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.openmrs.module.initializer.api.fhir.ocm; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.openmrs.ConceptClass; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.api.ConceptService; | ||
import org.openmrs.module.fhir2.model.FhirObservationCategoryMap; | ||
import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
import org.openmrs.module.initializer.api.CsvLine; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.openmrs.module.initializer.api.fhir.ocm.FhirObservationCategoryMapCsvParser.CONCEPT_CLASS_HEADER; | ||
import static org.openmrs.module.initializer.api.fhir.ocm.FhirObservationCategoryMapCsvParser.FHIR_OBS_CATEGORY_HEADER; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.*" }) | ||
public class FhirObservationCategoryMapLineProcessor extends BaseLineProcessor<FhirObservationCategoryMap> { | ||
|
||
private final ConceptService conceptService; | ||
|
||
@Autowired | ||
public FhirObservationCategoryMapLineProcessor(ConceptService conceptService) { | ||
this.conceptService = conceptService; | ||
} | ||
|
||
@Override | ||
public FhirObservationCategoryMap fill(FhirObservationCategoryMap instance, CsvLine line) | ||
throws IllegalArgumentException { | ||
if (StringUtils.isBlank(instance.getUuid()) && StringUtils.isBlank(line.getUuid())) { | ||
throw new IllegalArgumentException("No UUID was found for FHIR observation category map"); | ||
} | ||
|
||
String fhirObsCategory = line.get(FHIR_OBS_CATEGORY_HEADER, true); | ||
if (StringUtils.isBlank(fhirObsCategory) && !instance.getRetired()) { | ||
throw new IllegalArgumentException("'" + FHIR_OBS_CATEGORY_HEADER | ||
+ "' was not found for FHIR observation category map " + instance.getUuid()); | ||
} | ||
|
||
String conceptClass = line.get(CONCEPT_CLASS_HEADER, true); | ||
if (StringUtils.isBlank(conceptClass) && !instance.getRetired()) { | ||
throw new IllegalArgumentException( | ||
"'" + CONCEPT_CLASS_HEADER + "' was not found for FHIR observation category map " + instance.getUuid()); | ||
} | ||
|
||
ConceptClass cc = conceptService.getConceptClassByName(conceptClass); | ||
if (cc == null && !instance.getRetired()) { | ||
throw new IllegalArgumentException("Concept class " + conceptClass | ||
+ " was not found while creating FHIR observation category map " + instance.getUuid()); | ||
} | ||
|
||
if (StringUtils.isNotBlank(line.getUuid())) { | ||
instance.setUuid(line.getUuid()); | ||
} | ||
|
||
instance.setObservationCategory(fhirObsCategory); | ||
instance.setConceptClass(cc); | ||
|
||
return instance; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...in/java/org/openmrs/module/initializer/api/fhir/ocm/FhirObservationCategoryMapLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.openmrs.module.initializer.api.fhir.ocm; | ||
|
||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.module.fhir2.model.FhirObservationCategoryMap; | ||
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.*" }) | ||
public class FhirObservationCategoryMapLoader extends BaseCsvLoader<FhirObservationCategoryMap, FhirObservationCategoryMapCsvParser> { | ||
|
||
@Autowired | ||
public void setParser(FhirObservationCategoryMapCsvParser parser) { | ||
this.parser = parser; | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...st/java/org/openmrs/module/initializer/api/FhirObservationCategoryMapIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.openmrs.module.initializer.api; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.Query; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.ConceptClass; | ||
import org.openmrs.api.ConceptService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.fhir2.model.FhirObservationCategoryMap; | ||
import org.openmrs.module.initializer.DomainBaseModuleContextSensitiveTest; | ||
import org.openmrs.module.initializer.api.fhir.ocm.FhirObservationCategoryMapLoader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasProperty; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
public class FhirObservationCategoryMapIntegrationTest extends DomainBaseModuleContextSensitiveTest { | ||
|
||
@Autowired | ||
@Qualifier("sessionFactory") | ||
private SessionFactory sessionFactory; | ||
|
||
@Autowired | ||
private ConceptService conceptService; | ||
|
||
@Autowired | ||
private FhirObservationCategoryMapLoader loader; | ||
|
||
@Before | ||
public void setup() { | ||
{ | ||
ConceptClass conceptClass = conceptService.getConceptClassByName("Test"); | ||
if (conceptClass == null) { | ||
conceptClass = new ConceptClass(); | ||
conceptClass.setName("Test"); | ||
conceptClass.setUuid(ConceptClass.TEST_UUID); | ||
sessionFactory.getCurrentSession().saveOrUpdate(conceptClass); | ||
} | ||
} | ||
|
||
{ | ||
ConceptClass conceptClass = conceptService.getConceptClassByName("Finding"); | ||
if (conceptClass == null) { | ||
conceptClass = new ConceptClass(); | ||
conceptClass.setName("Finding"); | ||
conceptClass.setUuid(ConceptClass.FINDING_UUID); | ||
sessionFactory.getCurrentSession().saveOrUpdate(conceptClass); | ||
} | ||
} | ||
|
||
{ | ||
FhirObservationCategoryMap observationCategoryMap = new FhirObservationCategoryMap(); | ||
observationCategoryMap.setObservationCategory("laboratory"); | ||
observationCategoryMap.setConceptClass(conceptService.getConceptClassByName("Test")); | ||
observationCategoryMap.setUuid("2309836d-bf13-4fea-b2d4-87bb997425c7"); | ||
sessionFactory.getCurrentSession().saveOrUpdate(observationCategoryMap); | ||
} | ||
|
||
Context.flushSession(); | ||
} | ||
|
||
@Test | ||
public void loader_shouldLoadFhirObservationCategoryMapsAccordingToCsvFiles() { | ||
// Replay | ||
loader.load(); | ||
|
||
// Verify | ||
Session session = sessionFactory.getCurrentSession(); | ||
Query getObsCategoryByCategoryQuery = session.createQuery("from " + FhirObservationCategoryMap.class.getSimpleName() | ||
+ " where observationCategory = :observationCategory"); | ||
|
||
{ | ||
List<FhirObservationCategoryMap> observationCategories = getObsCategoryByCategoryQuery | ||
.setParameter("observationCategory", "laboratory").list(); | ||
|
||
assertThat(observationCategories, hasSize(2)); | ||
assertThat(observationCategories, | ||
hasItem(allOf(hasProperty("uuid", equalTo("e518de2a-be31-4202-9772-cc65c3ef7227")), | ||
hasProperty("conceptClass", hasProperty("name", equalTo("Test")))))); | ||
assertThat(observationCategories, | ||
hasItem(allOf(hasProperty("uuid", equalTo("2374215a-8808-4eee-b5a5-9190423862a0")), | ||
hasProperty("conceptClass", hasProperty("name", equalTo("LabSet")))))); | ||
} | ||
|
||
{ | ||
List<FhirObservationCategoryMap> observationCategories = getObsCategoryByCategoryQuery | ||
.setParameter("observationCategory", "exam").list(); | ||
|
||
assertThat(observationCategories, hasSize(1)); | ||
assertThat(observationCategories.get(0), hasProperty("uuid", equalTo("5f8e2dd2-ce1f-42d3-bb34-55acb3f58c5d"))); | ||
assertThat(observationCategories.get(0).getConceptClass(), hasProperty("name", equalTo("Finding"))); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...rces/testAppDataDir/configuration/fhirobservationcategorymaps/observationcategorymaps.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Uuid,Void/Retire,Fhir observation category,Concept class,_order:1000 | ||
e518de2a-be31-4202-9772-cc65c3ef7227,,laboratory,Test, | ||
5f8e2dd2-ce1f-42d3-bb34-55acb3f58c5d,,exam,Finding, | ||
2374215a-8808-4eee-b5a5-9190423862a0,,laboratory,LabSet, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.