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

TRUNK-5721: Fix ObsService.getObs error when Obs.valueComplex null #4599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions api/src/test/java/org/openmrs/api/ObsServiceTest.java
Expand Up @@ -55,6 +55,7 @@
import org.openmrs.api.impl.ObsServiceImpl;
import org.openmrs.obs.ComplexData;
import org.openmrs.obs.ComplexObsHandler;
import org.openmrs.obs.handler.AbstractHandler;
import org.openmrs.obs.handler.BinaryDataHandler;
import org.openmrs.obs.handler.ImageHandler;
import org.openmrs.obs.handler.TextHandler;
Expand Down Expand Up @@ -812,6 +813,46 @@ public void getObs_shouldGetObsMatchingGivenObsId() {
assertEquals(5089, obs.getConcept().getId().intValue());
}

/**
* This is a test to verify the behavior reported in TRUNK-5721.
* The test name and the content will be refactored once the expected behavior is known
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by once the expected behaviour is known?

Copy link
Member Author

@gayanW gayanW Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to confirm whether we should allow, a complx observation with ComplexData#data null to be saved in the database?

If it is okay to be saved, then I could make the changes, so ObsService#getObs would allow retrieving complex observation with no data files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not find it correct to save complex data without data. 😊

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you.. I'll also make a community post, if there's more things to clarify.

*
* @see ObsService#saveObs(Obs,String)
* @see ObsService#getObs(Integer)
* @see ComplexObsHandler#saveObs(Obs)
*/
@Test
public void getObs_shouldGetObsWithComplexDataNull() throws IOException {
// load and retrieve a complex concept from COMPLEX_OBS_XML
executeDataSet(COMPLEX_OBS_XML);
Concept complexConcept = Context.getConceptService().getConcept(8474);

// construct complex observation, but with complex data field set to null
Obs complexObs = new Obs(new Person(1), complexConcept, new Date(), new Location(1));
ComplexData complexData = new ComplexData("title", null);
complexObs.setComplexData(complexData);
assertTrue(complexObs.isComplex());

// delete the complex data file if already exists
File complexDataFile = new AbstractHandler().getOutputFileToWrite(complexObs);
if (complexDataFile.exists()) {
complexDataFile.delete();
}

try {
Context.getObsService().saveObs(complexObs, null);

// Verify that data file not exist
assertFalse(complexDataFile.exists());

// Assert that ObsService.getObs fails if data file not exist
assertThrows(NullPointerException.class, () -> obsService.getObs(complexObs.getObsId()));
}
finally {
complexDataFile.delete();
}
}

/**
* @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean)
* @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String)
Expand Down