use of org.openmrs.Location in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButAlsoDischargeEncounter.
@Test
public void test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButAlsoDischargeEncounter() throws Exception {
ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
// patient already has one visit in test dataset
Patient patient = patientService.getPatient(7);
// need to tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
Location unknownLocation = locationService.getLocation(1);
unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
locationService.saveLocation(unknownLocation);
Location location = locationService.getLocation(2);
location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
locationService.saveLocation(location);
Visit visit = new Visit();
visit.setStartDatetime(DateUtils.addHours(new Date(), -60));
visit.setPatient(patient);
visit.setLocation(location);
visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
// create ED Triage encounter
Encounter edTriage = new Encounter();
edTriage.setPatient(patient);
edTriage.setEncounterType(encounterService.getEncounterTypeByUuid(ED_TRIAGE_ENCOUNTER_TYPE_UUID));
edTriage.setEncounterDatetime(visit.getStartDatetime());
encounterService.saveEncounter(edTriage);
// create a another encounter within 48 hours
Encounter consult = new Encounter();
consult.setPatient(patient);
consult.setEncounterType(emrApiProperties.getVisitNoteEncounterType());
consult.setEncounterDatetime(DateUtils.addHours(new Date(), -47));
encounterService.saveEncounter(consult);
// create an encounter with a disposition obs of "discharge
Encounter encounterWithDisposition = new Encounter();
encounterWithDisposition.setPatient(patient);
encounterWithDisposition.setEncounterType(encounterService.getEncounterType(1));
encounterWithDisposition.setEncounterDatetime(visit.getStartDatetime());
Obs dispositionObsGroup = new Obs();
dispositionObsGroup.setConcept(dispositionService.getDispositionDescriptor().getDispositionSetConcept());
Obs dispositionObs = new Obs();
dispositionObs.setConcept(dispositionService.getDispositionDescriptor().getDispositionConcept());
// this fake code is set in ContextSensitiveMetadataTestUtils
dispositionObs.setValueCoded(emrConceptService.getConcept(EmrApiConstants.EMR_CONCEPT_SOURCE_NAME + ":Discharged"));
dispositionObsGroup.addGroupMember(dispositionObs);
encounterWithDisposition.addObs(dispositionObsGroup);
encounterService.saveEncounter(encounterWithDisposition);
visit.addEncounter(edTriage);
visit.addEncounter(consult);
visit.addEncounter(encounterWithDisposition);
visitService.saveVisit(visit);
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
// sanity check
assertNotNull(activeVisit);
new PihCloseStaleVisitsTask().execute();
activeVisit = adtService.getActiveVisit(patient, location);
assertNull(activeVisit);
}
use of org.openmrs.Location in project openmrs-module-pihcore by PIH.
the class ConfigureSierraLeoneIdGenerators method configureGenerators.
public static void configureGenerators(IdentifierSourceService identifierSourceService) {
Location identifierLocation = MetadataUtils.existing(Location.class, SierraLeoneLocations.WELLBODY_HEALTH_CENTER.uuid());
SequentialIdentifierGenerator wellbodyPrimaryIdentifierSource = (SequentialIdentifierGenerator) identifierSourceService.getIdentifierSourceByUuid(WELLBODY_PRIMARY_IDENTIFIER_SOURCE_UUID);
if (wellbodyPrimaryIdentifierSource == null) {
wellbodyPrimaryIdentifierSource = new SequentialIdentifierGenerator();
}
wellbodyPrimaryIdentifierSource.setName("Wellbody Primary Identifier Source");
wellbodyPrimaryIdentifierSource.setDescription("Primary Identifier Generator for Wellbody");
wellbodyPrimaryIdentifierSource.setIdentifierType(MetadataUtils.existing(PatientIdentifierType.class, SierraLeonePatientIdentifierTypes.WELLBODY_EMR_ID.uuid()));
wellbodyPrimaryIdentifierSource.setPrefix("W");
wellbodyPrimaryIdentifierSource.setMinLength(7 + wellbodyPrimaryIdentifierSource.getPrefix().length());
wellbodyPrimaryIdentifierSource.setMaxLength(8 + wellbodyPrimaryIdentifierSource.getPrefix().length());
wellbodyPrimaryIdentifierSource.setBaseCharacterSet("0123456789");
wellbodyPrimaryIdentifierSource.setFirstIdentifierBase("0000001");
wellbodyPrimaryIdentifierSource.setUuid(WELLBODY_PRIMARY_IDENTIFIER_SOURCE_UUID);
identifierSourceService.saveIdentifierSource(wellbodyPrimaryIdentifierSource);
AutoGenerationOption autoGenerationOption = identifierSourceService.getAutoGenerationOption(wellbodyPrimaryIdentifierSource.getIdentifierType(), identifierLocation);
if (autoGenerationOption == null) {
autoGenerationOption = new AutoGenerationOption();
}
autoGenerationOption.setIdentifierType(MetadataUtils.existing(PatientIdentifierType.class, SierraLeonePatientIdentifierTypes.WELLBODY_EMR_ID.uuid()));
autoGenerationOption.setSource(wellbodyPrimaryIdentifierSource);
autoGenerationOption.setAutomaticGenerationEnabled(true);
autoGenerationOption.setManualEntryEnabled(false);
autoGenerationOption.setLocation(identifierLocation);
identifierSourceService.saveAutoGenerationOption(autoGenerationOption);
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class ObsServiceTest method getObservationCount_shouldReturnTheCountOfAllObservationsUsingTheSpecifiedConceptNamesAsAnswers.
/**
* @see ObsService#getObservationCount(List, boolean)
*/
@Test
public void getObservationCount_shouldReturnTheCountOfAllObservationsUsingTheSpecifiedConceptNamesAsAnswers() {
ObsService os = Context.getObsService();
Obs o = new Obs();
o.setConcept(Context.getConceptService().getConcept(3));
o.setPerson(new Patient(2));
o.setEncounter(new Encounter(3));
o.setObsDatetime(new Date());
o.setLocation(new Location(1));
ConceptName cn1 = new ConceptName(1847);
o.setValueCodedName(cn1);
os.saveObs(o, null);
Obs o2 = new Obs();
o2.setConcept(Context.getConceptService().getConcept(3));
o2.setPerson(new Patient(2));
o2.setEncounter(new Encounter(3));
o2.setObsDatetime(new Date());
o2.setLocation(new Location(1));
ConceptName cn2 = new ConceptName(2453);
o2.setValueCodedName(cn2);
os.saveObs(o2, null);
List<ConceptName> names = new LinkedList<>();
names.add(cn1);
names.add(cn2);
Assert.assertEquals(2, os.getObservationCount(names, true).intValue());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldCreateVeryBasicObsAndAddNewObsId.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldCreateVeryBasicObsAndAddNewObsId() {
Obs o = new Obs();
o.setConcept(Context.getConceptService().getConcept(3));
o.setPerson(new Patient(2));
o.setEncounter(new Encounter(3));
o.setObsDatetime(new Date());
o.setLocation(new Location(1));
o.setValueNumeric(50d);
Obs oSaved = Context.getObsService().saveObs(o, null);
// make sure the returned Obs and the passed in obs
// now both have primary key obsIds
assertTrue(oSaved.getObsId().equals(o.getObsId()));
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldCreateNewFileFromComplexDataForNewObs.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldCreateNewFileFromComplexDataForNewObs() {
executeDataSet(COMPLEX_OBS_XML);
ObsService os = Context.getObsService();
ConceptService cs = Context.getConceptService();
AdministrationService as = Context.getAdministrationService();
// make sure the file isn't there to begin with
File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(as.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR));
File createdFile = new File(complexObsDir, "nameOfFile.txt");
if (createdFile.exists())
createdFile.delete();
// the complex data to put onto an obs that will be saved
Reader input = new CharArrayReader("This is a string to save to a file".toCharArray());
ComplexData complexData = new ComplexData("nameOfFile.txt", input);
// must fetch the concept instead of just new Concept(8473) because the attributes on concept are checked
// this is a concept mapped to the text handler
Concept questionConcept = cs.getConcept(8474);
Obs obsToSave = new Obs(new Person(1), questionConcept, new Date(), new Location(1));
obsToSave.setComplexData(complexData);
try {
os.saveObs(obsToSave, null);
// make sure the file appears now after the save
Assert.assertTrue(createdFile.exists());
} finally {
// we always have to delete this inside the same unit test because it is outside the
// database and hence can't be "rolled back" like everything else
createdFile.delete();
}
}
Aggregations