Search in sources :

Example 11 with LocationTag

use of org.openmrs.LocationTag in project openmrs-module-mirebalais by PIH.

the class PaperRecordServiceIT method shouldCreateTwoDifferentDossierNumbers.

@Test
@DirtiesContext
public void shouldCreateTwoDifferentDossierNumbers() throws Exception {
    authenticate();
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid("e66645eb-03a8-4991-b4ce-e87318e37566");
    when(paperRecordProperties.getPaperRecordIdentifierType()).thenReturn(patientIdentifierType);
    Location location = new Location(15);
    LocationTag locationTag = new LocationTag(15);
    locationTag.setName("tag");
    location.addTag(locationTag);
    when(paperRecordProperties.getMedicalRecordLocationLocationTag()).thenReturn(locationTag);
    PaperRecord paperRecord1 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
    assertTrue(paperRecord1.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
    PaperRecord paperRecord2 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
    assertTrue(paperRecord2.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
    assertThat(paperRecord1.getPatientIdentifier().getIdentifier(), not(paperRecord2.getPatientIdentifier().getIdentifier()));
}
Also used : LocationTag(org.openmrs.LocationTag) PaperRecord(org.openmrs.module.paperrecord.PaperRecord) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) PaperRecordServiceImpl(org.openmrs.module.paperrecord.PaperRecordServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 12 with LocationTag

use of org.openmrs.LocationTag in project openmrs-module-pihcore by PIH.

the class LocationTagSetup method setLocationTagsFor.

private static void setLocationTagsFor(LocationService service, LocationTagDescriptor locationTag, Collection<LocationDescriptor> locationsThatGetTag) {
    LocationTag tag = service.getLocationTagByUuid(locationTag.uuid());
    for (Location candidate : service.getAllLocations()) {
        boolean expected = false;
        if (locationsThatGetTag != null) {
            for (LocationDescriptor d : locationsThatGetTag) {
                if (d != null && d.uuid().equals(candidate.getUuid())) {
                    expected = true;
                }
            }
        }
        boolean actual = candidate.hasTag(tag.getName());
        if (actual && !expected) {
            candidate.removeTag(tag);
            service.saveLocation(candidate);
        } else if (!actual && expected) {
            candidate.addTag(tag);
            service.saveLocation(candidate);
        }
    }
}
Also used : LocationTag(org.openmrs.LocationTag) LocationDescriptor(org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor) Location(org.openmrs.Location)

Example 13 with LocationTag

use of org.openmrs.LocationTag in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTask method execute.

public void execute() {
    AdtService adtService = Context.getService(AdtService.class);
    VisitService visitService = Context.getVisitService();
    LocationService locationService = Context.getLocationService();
    LocationTag visitLocationTag = locationService.getLocationTagByName(EmrApiConstants.LOCATION_TAG_SUPPORTS_VISITS);
    List<Location> locations = locationService.getLocationsByTag(visitLocationTag);
    List<Visit> openVisits = visitService.getVisits(null, null, locations, null, null, null, null, null, null, false, false);
    for (Visit visit : openVisits) {
        if ((isOldEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_VERY_OLD_TIME_IN_HOURS)) || (adtService.shouldBeClosed(visit) && !isActiveEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_TIME_IN_HOURS)) || wasDischargedAndNotAdmitted(adtService.wrap(visit), HUM_VISIT_EXPIRE_TIME_IN_HOURS)) {
            try {
                adtService.closeAndSaveVisit(visit);
            } catch (Exception ex) {
                log.warn("Failed to close inactive visit " + visit, ex);
            }
        }
    }
}
Also used : LocationTag(org.openmrs.LocationTag) AdtService(org.openmrs.module.emrapi.adt.AdtService) LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) Location(org.openmrs.Location)

Example 14 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited.

/**
 * should set audit info if any item in the location tag is edited
 *
 * @see LocationService#saveLocationTag(LocationTag)
 */
@Test
public void saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited() {
    LocationService ls = Context.getLocationService();
    LocationTag tag = ls.getLocationTag(1);
    Assert.assertNull(tag.getDateChanged());
    Assert.assertNull(tag.getChangedBy());
    tag.setName("testing");
    tag.setDescription("desc");
    LocationTag editedTag = Context.getLocationService().saveLocationTag(tag);
    Context.flushSession();
    Assert.assertNotNull(editedTag.getDateChanged());
    Assert.assertNotNull(editedTag.getChangedBy());
}
Also used : LocationTag(org.openmrs.LocationTag) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocation_shouldAddLocationTagToLocation.

/**
 * You should be able to add a tag to a location.
 *
 * @see LocationService#saveLocation(Location)
 */
@Test
public void saveLocation_shouldAddLocationTagToLocation() {
    LocationService ls = Context.getLocationService();
    // First, create a new Location
    Location location = new Location();
    location.setName("name");
    location.setDescription("is a location");
    ls.saveLocation(location);
    // Create a tag
    LocationTag tag = new LocationTag();
    tag.setName("tag name");
    ls.saveLocationTag(tag);
    // Add tag to location
    location.addTag(tag);
    ls.saveLocation(location);
    Location newSavedLocation = ls.getLocation(location.getLocationId());
    // Saved parent location should have tags
    assertNotNull("newSavedLocation.tags must be not null", newSavedLocation.getTags());
    // Saved parent location should have exactly 1 tag
    assertEquals(1, newSavedLocation.getTags().size());
    // Tag must be the previously added object
    assertTrue("Tag must be the previously added tag", newSavedLocation.getTags().iterator().next().equals(tag));
}
Also used : LocationTag(org.openmrs.LocationTag) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

LocationTag (org.openmrs.LocationTag)21 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)16 Location (org.openmrs.Location)8 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1 Patient (org.openmrs.Patient)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Visit (org.openmrs.Visit)1 APIException (org.openmrs.api.APIException)1 LocationService (org.openmrs.api.LocationService)1 VisitService (org.openmrs.api.VisitService)1 AdtService (org.openmrs.module.emrapi.adt.AdtService)1 LocationDescriptor (org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor)1 PaperRecord (org.openmrs.module.paperrecord.PaperRecord)1 PaperRecordServiceImpl (org.openmrs.module.paperrecord.PaperRecordServiceImpl)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1