Skip to content

Commit

Permalink
Updating to Platform 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Jan 22, 2024
1 parent 356df07 commit ff44719
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected Object task() {
return null;
}

}.executeInManualFlushMode();
}.executeInAutoFlushMode();
}

/**
Expand Down
9 changes: 8 additions & 1 deletion api-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptMap;
import org.openmrs.ConceptName;
import org.openmrs.ConceptSource;
Expand All @@ -50,6 +51,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("c", Locale.ENGLISH));
c.setUuid("c");
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

ConceptSource newSource = new ConceptSource();
Expand All @@ -63,15 +65,15 @@ public List<?> prepareExportServer() throws Exception {
Context.getConceptService().saveConceptSource(commonSource);

ConceptMap newMap = new ConceptMap();
newMap.setSource(newSource);
newMap.setSourceCode("c");
newMap.getConceptReferenceTerm().setConceptSource(newSource);
newMap.getConceptReferenceTerm().setCode("c");
c.addConceptMapping(newMap);

Context.getConceptService().saveConcept(c);

ConceptMap commonMap = new ConceptMap();
commonMap.setSource(commonSource);
commonMap.setSourceCode("cd");
commonMap.getConceptReferenceTerm().setConceptSource(commonSource);
commonMap.getConceptReferenceTerm().setCode("cd");
c.addConceptMapping(commonMap);

Context.getConceptService().saveConcept(c);
Expand All @@ -86,6 +88,8 @@ public void prepareImportServer() throws Exception {
c.addName(new ConceptName("c", Locale.ENGLISH));
c.setUuid("c");
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getConceptService().saveConcept(c);

ConceptSource commonSource = new ConceptSource();
Expand All @@ -94,8 +98,8 @@ public void prepareImportServer() throws Exception {
Context.getConceptService().saveConceptSource(commonSource);

ConceptMap commonMap = new ConceptMap();
commonMap.setSource(commonSource);
commonMap.setSourceCode("cd");
commonMap.getConceptReferenceTerm().setConceptSource(commonSource);
commonMap.getConceptReferenceTerm().setCode("cd");
c.addConceptMapping(commonMap);

Context.getConceptService().saveConcept(c);
Expand All @@ -121,7 +125,7 @@ public void runOnImportServerAfterImport() throws Exception {

Set<String> uuids = new HashSet<String>(Arrays.asList("csNew", "csOld"));
for (ConceptMap conceptMap : concept.getConceptMappings()) {
if (!uuids.contains(conceptMap.getSource().getUuid())) {
if (!uuids.contains(conceptMap.getConceptReferenceTerm().getConceptSource().getUuid())) {
Assert.fail("Must be csNew or csOld");
}
}
Expand All @@ -132,6 +136,7 @@ public void runOnImportServerAfterImport() throws Exception {
@Test
public void shouldUpdateRelatedConceptSourceWhenImportedAgain() throws Exception {
Concept concept = ConceptMock.newInstance().addMapping("1", "source").addPreferredName("hiv", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept().getConcept();
PackageExporter exporter = MetadataSharing.getInstance().newPackageExporter();
exporter.addItem(concept);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.api.context.Context;
import org.openmrs.module.metadatasharing.wrapper.PackageImporter;
Expand All @@ -50,9 +51,11 @@ public void shouldOverwritePreferredNameIfPreferTheirs() throws Exception {
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));


ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -71,9 +74,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down Expand Up @@ -124,9 +128,10 @@ public void shouldRemoveExistingNamesIfNotInIncomingInMirrorMode() throws Except
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -145,9 +150,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down Expand Up @@ -194,9 +200,10 @@ public void shouldNotOverwritePreferredNameIfPreferMine() throws Exception {
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -215,9 +222,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ConceptShareScenarioTest extends BaseShareScenarioTest<Concept> {
@Override
public List<Concept> prepareItemsToExport() {
Concept concept = ConceptMock.newInstance().addPreferredName("Some test concept", Locale.ENGLISH).setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept().getConcept();
return Arrays.asList(concept);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void shouldImportConceptWithMappingToEmptyServer() throws Exception {
@Override
public List<?> prepareExportServer() throws Exception {
exportedConcept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A").saveConcept()
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(exportedConcept);
Expand Down Expand Up @@ -64,16 +66,20 @@ public void shouldUpdateConceptByAddingNewMapping() throws Exception {
@Override
public List<?> prepareExportServer() throws Exception {
exportedConcept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A").saveConcept()
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(exportedConcept);
}

@Override
public void prepareImportServer() throws Exception {
ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH).addMapping("373066001", "SNOMED CT")
.setDatatype("N/A").saveConcept();
ConceptMock.newInstance().addPreferredName("Yes Yes 2", Locale.ENGLISH).addMapping("373066001", "SNOMED CT")
.setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept();
}

@Override
Expand All @@ -96,7 +102,9 @@ public void shouldMergeConceptNamesIgnoringCaseInP2PMode() throws Exception {

@Override
public List<?> prepareExportServer() throws Exception {
Concept concept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH).saveConcept()
Concept concept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(concept);
Expand All @@ -105,6 +113,7 @@ public List<?> prepareExportServer() throws Exception {
@Override
public void prepareImportServer() throws Exception {
ConceptMock.newInstance().addName("YES YES", Locale.ENGLISH).addPreferredName("Yes!", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptAnswer;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Drug;
import org.openmrs.api.context.Context;
Expand All @@ -41,6 +42,7 @@ public List<?> prepareExportServer() throws Exception {
Concept c = new Concept();
c.setUuid("1");
c.addName(new ConceptName("DrugAnswerDrugConcept", Locale.US));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

//here's the drug
Expand All @@ -54,7 +56,8 @@ public List<?> prepareExportServer() throws Exception {
Concept cTest = new Concept();
cTest.setUuid("3");
cTest.addName(new ConceptName("TestAnswerDrugConcept", Locale.US));

cTest.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptAnswer ca = new ConceptAnswer();
ca.setAnswerConcept(c);
ca.setAnswerDrug(drug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
import org.openmrs.api.context.Context;
Expand All @@ -41,6 +42,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("ConceptNumericConcept", Locale.US));
c.setHiNormal(Double.valueOf(1));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

return Collections.nCopies(1, c);
Expand All @@ -52,6 +54,7 @@ public void prepareImportServer() throws Exception {
Concept c = new Concept();
c.addName(new ConceptName("ConceptNumericConcept", Locale.US));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
import org.openmrs.api.context.Context;
Expand All @@ -40,6 +41,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("ConceptName", Locale.US));
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

return Collections.nCopies(1, c);
Expand All @@ -53,6 +55,7 @@ public void prepareImportServer() throws Exception {
c.addName(new ConceptName("ConceptNumericName", Locale.US));
c.setHiNormal(Double.valueOf(1));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.GlobalProperty;
import org.openmrs.api.context.Context;
Expand All @@ -42,7 +43,8 @@ public List<?> prepareExportServer() throws Exception {
Concept c = new Concept();
ConceptName conceptName = new ConceptName("1234567890-1234567890", Locale.US);
c.addName(conceptName);

c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getConceptService().saveConcept(c);

// check to make sure the child server uses this one
Expand Down Expand Up @@ -75,13 +77,17 @@ public void shouldNotPreserveConceptIdAcrossServersIfImportingServerDoesntReques
runShareTest(new ShareTestHelper() {

Integer newConceptId = null;

Concept concept;

@Override
public List<?> prepareExportServer() throws Exception {

Concept c = new Concept();
c.addName(new ConceptName("Test", Locale.US));

c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
concept = c;

Context.getConceptService().saveConcept(c);

// check to make sure the child server uses this one
Expand All @@ -104,8 +110,8 @@ public void prepareImportServer() throws Exception {
@Override
public void runOnImportServerAfterImport() throws Exception {
Concept c = Context.getConceptService().getConcept(newConceptId);
Assert.assertNull("The concept was found with the same id, wha happened??", c);

Assert.assertEquals(concept, c);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import junit.framework.Assert;

import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.api.context.Context;
import org.openmrs.module.metadatasharing.handler.BaseHandlersTest;
Expand All @@ -30,6 +31,7 @@ public class ConceptHandlersFunctionalTest extends BaseHandlersTest<Concept> {
public Concept getNewItem(){
Concept concept = new Concept();
concept.addName(new ConceptName("New Concept", Locale.ENGLISH));
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
return concept;
}

Expand All @@ -38,6 +40,7 @@ public Concept getExistingItem(){
Concept concept = new Concept();
concept.setUuid("1");
concept.addName(new ConceptName("Existing concept", Locale.ENGLISH));
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
return Context.getConceptService().saveConcept(concept);
}

Expand Down
Loading

0 comments on commit ff44719

Please sign in to comment.