Search in sources :

Example 1 with ProviderService

use of org.openmrs.api.ProviderService in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldCreateAnEncounterAndFindTheProviderByUuid.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldCreateAnEncounterAndFindTheProviderByUuid() throws Exception {
    executeDataSet("org/openmrs/api/include/ProviderServiceTest-initial.xml");
    int patientId = 2;
    Patient patient = new Patient(patientId);
    List<Encounter> encForPatient1 = Context.getEncounterService().getEncountersByPatient(patient);
    ProviderService ps = Context.getProviderService();
    Provider provider = ps.getProviderByIdentifier("8a760");
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||" + patientId + "^^^^||Hornblower^Horatio^Test||\r" + "PV1||O|1^Unknown Location||||ba4781f4-6b94-11e0-93c3-18a905e044dc^name^^^^^^^&" + HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID + "&L|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT";
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    // check for the new encounter
    List<Encounter> encForPatient2 = Context.getEncounterService().getEncountersByPatient(patient);
    encForPatient2.removeAll(encForPatient1);
    Assert.assertTrue(encForPatient2.size() == 1);
    Provider newProvider = encForPatient2.get(0).getProvidersByRole(Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID)).iterator().next();
    Assert.assertEquals(4, newProvider.getId().intValue());
}
Also used : ProviderService(org.openmrs.api.ProviderService) Message(ca.uhn.hl7v2.model.Message) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with ProviderService

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

the class UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts method execute.

@Override
public void execute() {
    UserService userService = Context.getUserService();
    ProviderService providerService = Context.getProviderService();
    Set<Person> personsToIncludeWhenRetiringProviderAccts = new HashSet<Person>();
    Set<Person> personsToExcludeWhenRetiringProviderAccts = new HashSet<Person>();
    for (User user : userService.getUsers(null, null, true)) {
        // the user account has been retired over a month ago
        if (user.isRetired() && user.getDateRetired() != null && user.getDateRetired().before(new DateTime().minusMonths(1).toDate())) {
            personsToIncludeWhenRetiringProviderAccts.add(user.getPerson());
        } else {
            personsToExcludeWhenRetiringProviderAccts.add(user.getPerson());
        /* if (!user.isRetired()) {
                    personsToMakeSureHaveActiveProviderAcct.add(user.getPerson());
                }*/
        }
    }
    personsToIncludeWhenRetiringProviderAccts.removeAll(personsToExcludeWhenRetiringProviderAccts);
    // retire all provider accts associated with persons with retired user accts
    for (Person person : personsToIncludeWhenRetiringProviderAccts) {
        for (Provider provider : providerService.getProvidersByPerson(person)) {
            if (!provider.isRetired()) {
                providerService.retireProvider(provider, "user account retired over 1 month ago");
            }
        }
    }
/*   // check all persons to include and make sure, if they have provider accts, that at least one is unretired
        for (Person person : personsToMakeSureHaveActiveProviderAcct) {

            Collection<Provider> providers = providerService.getProvidersByPerson(person);

            if (providers.size() == 1 && providers.iterator().next().isRetired()) {
                providerService.unretireProvider(providers.iterator().next());
            }
            else if (providers.size() > 1) {

                Provider mostRecentlyRetiredProvider = null;
                Boolean noUnretiredProviders = true;
                Iterator<Provider> i = providers.iterator();

                while (i.hasNext()) {
                    Provider provider = i.next();
                    if (!provider.isRetired()) {
                        noUnretiredProviders = false;
                        break;
                    }
                    else if (mostRecentlyRetiredProvider == null || mostRecentlyRetiredProvider.getDateRetired().before(provider.getDateRetired())) {
                        mostRecentlyRetiredProvider = provider;
                    }
                }

                if (noUnretiredProviders) {
                    providerService.unretireProvider(mostRecentlyRetiredProvider);
                }
            }
        }*/
}
Also used : ProviderService(org.openmrs.api.ProviderService) User(org.openmrs.User) UserService(org.openmrs.api.UserService) Person(org.openmrs.Person) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Provider(org.openmrs.Provider)

Aggregations

Provider (org.openmrs.Provider)2 ProviderService (org.openmrs.api.ProviderService)2 Message (ca.uhn.hl7v2.model.Message)1 HashSet (java.util.HashSet)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Encounter (org.openmrs.Encounter)1 Patient (org.openmrs.Patient)1 Person (org.openmrs.Person)1 User (org.openmrs.User)1 UserService (org.openmrs.api.UserService)1 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)1