Failing test in PatientServiceTests class

I modified and added code to merge overlapping visits of an individual in the mergeVisits method. It does the merging into one when i check in the ui but the test fails with the below error. Primarily what i do is, extend the dates of preferred patient visit in accordance to that of non preferred patient visit then save the preferred visit. I updated the test and dataset but still got the error.

Tests in error: PatientServiceTest.mergePatients_shouldMergeVisitsFromNonPreferredToPreferredPatient:643->mergeAndRetrieveAudit:2615 » Validation PatientServiceTest.mergePatients_shouldMoveAllObsWithSameHierarchy:3238 » Validation

i checked the method and the reported line is patientService.mergePatients(preferred, notPreferred); which in turn calls mergeVisits(preferred, notPreferred)

i’ll appreciate some pointers to what might be going wrong

@harisu I was just replying to say you should make sure to check the existing code in the emrapi module for this, and then I noticed that you’re actually working on TRUNK-5221. Great! (FYI it would have been helpful if you had started your message by saying “I’m working on TRUNK-5221 and…”)

Can you please give a bit more info about the current state of code? E.g. can you commit your changes so far, and share a link to the branch in github (so someone could look at specific line numbers after your changes)? Also, can you give a better-formatted and/or more complete list of the failed tests? I can’t tell what the actual error was from this.

@darius Thanks, the complete error when i run mvn clean install is :

Results :

Tests in error: 
  PatientServiceTest.mergePatients_shouldMergeVisitsFromNonPreferredToPreferredPatient:643->mergeAndRetrieveAudit:2615 » Validation
  PatientServiceTest.mergePatients_shouldMoveAllObsWithSameHierarchy:3238 » Validation

Tests run: 3946, Failures: 0, Errors: 2, Skipped: 36

and the commit is found her https://github.com/fanyui/openmrs-core/commit/e83df861b1913ae63882fe6fd6cd9f38ec08cc9b

Your code have broken some existing tests. You now need to determine whether this is a real error in your code, or if the existing tests need to be changed to reflect the new behavior you’re introducing.

You should run each of these test individually, and look at the full error or stack trace of each test. (E.g. I assume there’s really a deeper stack trace beneath mergeAndRetrieveAudit:2615 in the first line.) If this doesn’t help, you might need to use your IDE’s debugger to step through the code and see what’s going on.

The first step is to understand exactly what error is being reported though.

That’s where exactly i have a problem i just get validation error. i’ll try stepping through the code using the debugger.

A validation error would usually include some kind of message indicating what validation failed.

@darius Thanks very much my bad Updating this late. I stepped through the code using the debugger and could get an explanatory Display message for the failing test. It was actually my code that made some test not to no longer pass i had to change the test behaviour. Really Greateful for the help.

@harisu Not sure if you used your IDE’s debugger to help solve this, but just to mention there are a few ways to get more info on failing tests using Maven. When you run mvn clean install, details of the failed test results are usually added as text/xml files to the directory .../OPENMRS_REPO_NAME/api/target/surefire-reports.

You can also run Maven using the -X or -e switch:

  • mvn clean install -X enables full debug logging.
  • mvn clean install -e will show the full stacktrace of errors.

@danfuterman Thanks for the additional info. But with exclipse i was able to get an error of Expected 6 but found 3 as well as encounter and visit should belong to thesame patient in shouldMergeVisitsFromNonPreferredToPreferredPatient . which was as a result of merging overlapping visits . Instead of the just Validation error when i used maven clean install directly.

Also I need some help finding the dataset of the Visit which correspond to the patient with id 7. I did get the Encounters in the file https://github.com/openmrs/openmrs-core/blob/master/api/src/test/resources/org/openmrs/include/standardTestDataset.xml . Or in other words is it possible to have and encounter without a visit?

At the Hibernate/database level, yes, a Visit is not mandatory/required for an Encounter. There are handlers in place though to determine if if an Encounter should be part of a Visit and to assign an Encounter to an existing or new Visit. You can also see how this has been implemented in the EMR API module to ensure that encounters are assigned to visits.

In your case, this is possibly irrelevant. You mentioned you were working on PatientServiceTest. You can check which datasets are used at the top of the source file. Here, the relevant datasets are likely mergePatientWithExistingObsHavingGroupMember.xml and PersonServiceTest-encountersForVisits.xml, both of which specify Visits for each Encounter.

@danfuterman I have moved through all of the datasets in the file PatientServiceTest but can’t find visits partianing to patient with id 7. Encounters for the said patient is found here standardDataset. I needed it because the existing code for merging patients used the patient to get the encounter but since TRUNK-5221 demand merging overlapping visits. During the merging I moved the encounters as well but this time using the visit to get the encounters. this worked well but I noticed a test failing with, shouldAuditMovedEncounter looking at the test I noticed it is using patient (id=7 and id= 999) which am unable to actually find the dataset. So am supposing those patient don’t have visit but are linked directly to the encounter through the patient id. I fixed the failing test by actually using the patient to get the encouters that are left on the non preferred patient after the encounters of the visits have been moved or merged to the preferred patient. moving the left encounters to the preferred patient. I don’t know if this is good enough.