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

RA-1864:Added saving encounter which should save encounter with detai… #456

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import java.util.Set;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.openmrs.Encounter;
import org.openmrs.EncounterProvider;
import org.openmrs.EncounterRole;
import org.openmrs.EncounterType;
import org.openmrs.Provider;
import org.openmrs.User;
import org.openmrs.*;
import org.openmrs.api.EncounterService;
import org.openmrs.api.context.Context;
import org.openmrs.module.appframework.domain.Extension;
Expand All @@ -21,6 +16,8 @@
import org.openmrs.ui.framework.SimpleObject;
import org.openmrs.ui.framework.UiUtils;

import static org.hibernate.validator.util.Contracts.assertNotNull;

public class ParseEncounterToJson {

private AppFrameworkService appFrameworkService;
Expand Down Expand Up @@ -141,6 +138,55 @@ private EncounterRole getPrimaryEncounterRoleForEncounter(Encounter encounter) {
return null;
}


public void saveEncounter_shouldSaveEncounterWithBasicDetails() {
Encounter encounter = buildEncounter();

EncounterService es = Context.getEncounterService();
es.saveEncounter(encounter);

assert encounter != null;
assertNotNull("The saved encounter should have an encounterid now", String.valueOf(encounter.getEncounterId()));
Encounter newSavedEncounter = es.getEncounter(encounter.getEncounterId());
assertNotNull("We should get back an encounter", String.valueOf(newSavedEncounter));
assertTrue("The created encounter needs to equal the pojo encounter", encounter.equals(newSavedEncounter));
}

public void purgeEncounter_shouldPurgeEncounter() {

EncounterService es = Context.getEncounterService();

//should fetch the encounter to delete from the database
Encounter encounterToDelete = es.getEncounter(1);

es.purgeEncounter(encounterToDelete);

// try to refetch the encounter. should get a null object
Encounter e = es.getEncounter(encounterToDelete.getEncounterId());
assertNull(e, "We shouldn't find the encounter after deletion");
}

private void assertNull(Encounter e, String s) {
}

private void assertTrue(String s, boolean equals) {
}

private Encounter buildEncounter() {
return null;
}

public void getObs_shouldGetObs() {
Encounter encounter = new Encounter();

//create and add an Obs
Obs o = new Obs();
encounter.addObs(o);

assertNotNull(encounter.getObs());

}

private Provider getFirstNonVoidedProvider(Encounter encounter) {
for (EncounterProvider provider : encounter.getEncounterProviders()) {
if (!provider.isVoided()) {
Expand Down