use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterType_shouldNotGetRetiredTypes.
/**
* @see EncounterService#getEncounterType(String)
*/
@Test
public void getEncounterType_shouldNotGetRetiredTypes() {
EncounterService encounterService = Context.getEncounterService();
// loop over all types to make sure
// that the retired "Test Enc Type C" exists
boolean foundRetired = false;
for (EncounterType encType : encounterService.getAllEncounterTypes(true)) {
if (encType.getName().equals("Test Enc Type C") && encType.getRetired()) {
foundRetired = true;
}
}
assertTrue(foundRetired);
assertNull(encounterService.getEncounterType("Test Enc Type C"));
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterType_shouldNotOverwriteCreatorOrDateCreated.
/**
* @see EncounterService#saveEncounterType(EncounterType)
*/
@Test
public void saveEncounterType_shouldNotOverwriteCreatorOrDateCreated() {
EncounterService encounterService = Context.getEncounterService();
// the encounter to save without a dateCreated
EncounterType encounterType = new EncounterType("testing", "desc");
encounterType.setCreator(new User(4));
// make sure we have a date that isn't "right now"
Date date = new Date(System.currentTimeMillis() - 5000);
encounterType.setDateCreated(date);
// make sure the logged in user isn't the user we're testing with
assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
encounterService.saveEncounterType(encounterType);
// make sure the encounter type creator is user 4 not user 1
assertNotSame(encounterType.getCreator().getId(), Context.getAuthenticatedUser().getId());
// make sure the encounter type date created wasn't overwritten
assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
// make sure we can fetch this new encounter type
// from the database and its values are the same as the passed in ones
EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId());
assertNotNull(newEncounterType);
assertEquals(4, encounterType.getCreator().getId().intValue());
assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method voidEncounter_shouldNotVoidProviders.
/**
* @see EncounterService#voidEncounter(Encounter, String)
*/
@Test
public void voidEncounter_shouldNotVoidProviders() {
EncounterService encounterService = Context.getEncounterService();
Encounter encounter = new Encounter();
encounter.setLocation(new Location(1));
encounter.setEncounterType(new EncounterType(1));
encounter.setEncounterDatetime(new Date());
encounter.setPatient(new Patient(3));
EncounterRole role = new EncounterRole();
role.setName("role");
role = encounterService.saveEncounterRole(role);
Provider provider = new Provider();
provider.setIdentifier("id1");
provider.setPerson(newPerson("name"));
provider = Context.getProviderService().saveProvider(provider);
encounter.addProvider(role, provider);
encounterService.saveEncounter(encounter);
assertEquals(1, encounter.getProvidersByRoles().size());
encounterService.voidEncounter(encounter, "reason");
encounter = encounterService.getEncounter(encounter.getEncounterId());
assertEquals(1, encounter.getProvidersByRoles().size());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterType_shouldUpdateAnExistingEncounterTypeName.
/**
* @see EncounterService#saveEncounterType(EncounterType)
*/
@Test
public void saveEncounterType_shouldUpdateAnExistingEncounterTypeName() {
EncounterService encounterService = Context.getEncounterService();
EncounterType encounterTypeToChange = encounterService.getEncounterType(1);
// change the name of the type
encounterTypeToChange.setName("another test");
// save the type to the database
encounterService.saveEncounterType(encounterTypeToChange);
// make sure the encounter type id didn't change
assertEquals(1, encounterTypeToChange.getEncounterTypeId().intValue());
// refetch the encounter type from the database
EncounterType fetchedEncounterType = encounterService.getEncounterType(1);
assertTrue(fetchedEncounterType.getName().equals("another test"));
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class ORUR01Handler method createEncounter.
/**
* This method does not call the database to create the encounter row. The encounter is only
* created after all obs have been attached to it Creates an encounter pojo to be attached
* later. This method does not create an encounterId
*
* @param msh
* @param patient
* @param pv1
* @param orc
* @return
* @throws HL7Exception
*/
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
// the encounter we will return
Encounter encounter;
// look for the encounter id in PV1-19
CX visitNumber = pv1.getVisitNumber();
Integer encounterId = null;
try {
encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
} catch (NumberFormatException e) {
// pass
}
// the database
if (encounterId != null) {
encounter = Context.getEncounterService().getEncounter(encounterId);
} else {
// if no encounter_id was passed in, this is a new
// encounter, create the object
encounter = new Encounter();
Date encounterDate = getEncounterDate(pv1);
Provider provider = getProvider(pv1);
Location location = getLocation(pv1);
Form form = getForm(msh);
EncounterType encounterType = getEncounterType(msh, form);
User enterer = getEnterer(orc);
// Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
encounter.setEncounterDatetime(encounterDate);
if (unknownRole == null) {
unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
}
encounter.setProvider(unknownRole, provider);
encounter.setPatient(patient);
encounter.setLocation(location);
encounter.setForm(form);
encounter.setEncounterType(encounterType);
encounter.setCreator(enterer);
encounter.setDateCreated(new Date());
}
return encounter;
}
Aggregations