Search in sources :

Example 1 with Location

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);
}
Also used : Obs(org.openmrs.Obs) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with Location

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);
}
Also used : AutoGenerationOption(org.openmrs.module.idgen.AutoGenerationOption) SequentialIdentifierGenerator(org.openmrs.module.idgen.SequentialIdentifierGenerator) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location)

Example 3 with Location

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());
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ConceptName(org.openmrs.ConceptName) Date(java.util.Date) LinkedList(java.util.LinkedList) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 4 with Location

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()));
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 5 with Location

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();
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) CharArrayReader(java.io.CharArrayReader) ComplexData(org.openmrs.obs.ComplexData) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) File(java.io.File) Person(org.openmrs.Person) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15