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

#277 - CSV parser should save cached objects once file has been loaded. #278

Merged
merged 5 commits into from
Sep 13, 2024
Merged
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
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PaymentModesCsvParser extends CsvParser<PaymentMode, BaseLineProces

@Autowired
public PaymentModesCsvParser(@Qualifier("cashierPaymentModeService") IPaymentModeService paymentModeService,
PaymentModesLineProcessor processor) {
PaymentModesLineProcessor processor) {
super(processor);
this.paymentModeService = paymentModeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArg

String attributes = line.get(HEADER_ATTRIBUTES, false);
if (StringUtils.isNotBlank(attributes)) {
paymentMode.getAttributeTypes().clear();
if (paymentMode.getAttributeTypes() != null) {
paymentMode.getAttributeTypes().clear();
}
for (String attribute : attributes.split(BaseLineProcessor.LIST_SEPARATOR)) {
String[] parts = attribute.trim().split("::");
if (parts.length > 3) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), Boolean.parseBoolean(parts[3].trim()));
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(),
Boolean.parseBoolean(parts[3].trim()));
} else if (parts.length > 2) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), false);
} else if (parts.length > 1) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), null, false);
} else {
paymentMode.addAttributeType(parts[0].trim(), null, null, false);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public void load_shouldLoadPaymentModesAccordingToCsvFiles() {
{
PaymentMode paymentMode = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606");
assertNotNull(paymentMode);
assertEquals("Paypal", paymentMode.getName());
assertEquals("Paypal", paymentMode.getName());

paymentMode.getAttributeTypes().forEach(attributeType -> {
if (attributeType.getName().equals("Maximum")) {
assertEquals("Numeric", attributeType.getFormat());
assertTrue(attributeType.getRequired());
} else {
assertEquals("Minimum", attributeType.getName());
}
});
if (attributeType.getName().equals("Maximum")) {
assertEquals("Numeric", attributeType.getFormat());
assertTrue(attributeType.getRequired());
} else {
assertEquals("Minimum", attributeType.getName());
}
});
}

// Verify edition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uuid, Void/Retire, name, attributes
526bf278-ba81-4436-b867-c2f6641d060a, , Visa card edited,
2b1b9aae-5d35-43dd-9214-3fd370fd7737, true, Bank transfer,
e168c141-f5fd-4eec-bd3e-633bed1c9606, , Paypal, Maximum::Numeric::::True;Minimum
uuid,Void/Retire,name,attributes
526bf278-ba81-4436-b867-c2f6641d060a,,Visa card edited,
2b1b9aae-5d35-43dd-9214-3fd370fd7737,true,Bank transfer,
e168c141-f5fd-4eec-bd3e-633bed1c9606,,Paypal,Maximum::Numeric::::True;Minimum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public List<String[]> getLines() {
* @return The resulting CsvParserResult instance.
*/
public CsvFailingLines process(List<String[]> lines) {
// Save cached objects to avoid losing them prematurely by other Parsers
// See DisplaysCsvParser#save(OpenmrsObject)
Context.flushSession();
Context.clearSession();
Ruhanga marked this conversation as resolved.
Show resolved Hide resolved

CsvFailingLines result = new CsvFailingLines();
int saved = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.openmrs.module.initializer.api;

import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ProgramWorkflow;
import org.openmrs.ProgramWorkflowState;
Expand Down Expand Up @@ -50,6 +53,7 @@ public void setup() {
{
Concept c = new Concept();
c.setShortName(new ConceptName("Active treatment (initial)", Locale.ENGLISH));
c.setDescriptions(Collections.singleton(new ConceptDescription("Active treatment (initial)", Locale.ENGLISH)));
c.setConceptClass(cs.getConceptClassByName("State"));
c.setDatatype(cs.getConceptDatatypeByName("Text"));
c = cs.saveConcept(c);
Expand Down Expand Up @@ -124,8 +128,8 @@ public void load_shouldLoadProgramWorkflowStatesAccordingToCsvFiles() {
Assert.assertEquals(wf, state.getProgramWorkflow());

Assert.assertEquals(cs.getConceptByName("Active treatment (initial)"), state.getConcept());
Assert.assertEquals("Active treatment (initial)", state.getName());
Assert.assertEquals("Active treatment (initial)", state.getDescription());
Assert.assertEquals("Active treatment (initial)", state.getConcept().getName().getName());
Assert.assertEquals("Active treatment (initial)", state.getConcept().getDescription().getDescription());
Assert.assertFalse(state.isRetired());
Assert.assertTrue(state.getInitial());
Assert.assertFalse(state.getTerminal());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.openmrs.module.initializer.api;

import java.util.Collections;
import java.util.Locale;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Program;
import org.openmrs.ProgramWorkflow;
Expand Down Expand Up @@ -39,6 +41,8 @@ public static void setupWorkflows(ConceptService cs, ProgramWorkflowService pws)
{
Concept c = new Concept();
c.setShortName(new ConceptName("TB Treatment Status (workflow)", Locale.ENGLISH));
c.setDescriptions(
Collections.singleton(new ConceptDescription("TB Treatment Status (workflow)", Locale.ENGLISH)));
c.setConceptClass(cs.getConceptClassByName("Workflow"));
c.setDatatype(cs.getConceptDatatypeByName("Text"));
c = cs.saveConcept(c);
Expand Down Expand Up @@ -133,8 +137,8 @@ public void load_shouldLoadProgramWorkflowsAccordingToCsvFiles() {
Program prog = pws.getProgramByName("TB Program");
Assert.assertEquals(prog, wf.getProgram());
Assert.assertEquals(cs.getConceptByName("TB Treatment Status (workflow)"), wf.getConcept());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getName());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getDescription());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getName().getName());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getDescription().getDescription());
Assert.assertFalse(wf.isRetired());
Assert.assertEquals(wf, prog.getWorkflow(wf.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
{
RelationshipType rt = ps.getRelationshipTypeByUuid("c86d9979-b8ac-4d8c-85cf-cc04e7f16315");
Assert.assertNotNull(rt);
Assert.assertEquals("Uncle/Nephew", rt.getName());
Assert.assertEquals("Uncle/Nephew", rt.toString());
Ruhanga marked this conversation as resolved.
Show resolved Hide resolved
Assert.assertEquals("A relationship of an uncle and his nephew", rt.getDescription());
Assert.assertEquals("Uncle", rt.getaIsToB());
Assert.assertEquals("Nephew", rt.getbIsToA());
Expand All @@ -41,7 +41,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
{
RelationshipType rt = ps.getRelationshipTypeByUuid("53d8a8f3-0084-4a52-8666-c655f5bd2689");
Assert.assertNotNull(rt);
Assert.assertEquals("Supervisor/Supervisee", rt.getName());
Assert.assertEquals("Supervisor/Supervisee", rt.toString());
Ruhanga marked this conversation as resolved.
Show resolved Hide resolved
Assert.assertEquals("A new description for supervisor to supervisee relationship", rt.getDescription());
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<openconceptlabVersion>1.2.9</openconceptlabVersion>
<fhir2Version>1.6.0</fhir2Version>
<billingVersion>1.1.0</billingVersion>
<stockmanagementVersion>2.0.2-SNAPSHOT</stockmanagementVersion>

<!-- Modules compatibility > Core 2.3.0 -->
<datafilterVersion>1.0.0</datafilterVersion>
Expand Down
16 changes: 16 additions & 0 deletions validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,22 @@
<version>${mysqlTestContainerVersion}</version>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>exti18n-api</artifactId>
<version>${exti18nVersion}</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>stockmanagement-api</artifactId>
<version>${stockmanagementVersion}</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>

</dependencies>

<build>
Expand Down
Loading