Search in sources :

Example 31 with Encounter

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

the class RedirectToDeathNoteIfMissing method hasDeathCertificateEncounter.

private boolean hasDeathCertificateEncounter(Patient patient) {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType deathCertificateEncounterType = Context.getEncounterService().getEncounterTypeByUuid(PihCoreConstants.DEATH_CERTIFICATE_ENCOUNTER_TYPE_UUID);
    List<Encounter> deathCertificateEncounters = encounterService.getEncounters(patient, null, null, null, null, Arrays.asList(deathCertificateEncounterType), null, null, null, false);
    return deathCertificateEncounters.size() > 0;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) EncounterService(org.openmrs.api.EncounterService)

Example 32 with Encounter

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

the class CleanDiagnosisConstructAction method applyAction.

@Override
public void applyAction(FormEntrySession formEntrySession) {
    Concept diagnosisConstructConcept = Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_DIAGNOSIS_CONCEPT_SET, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME);
    Concept codedDiagnosisConcept = Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_CODED_DIAGNOSIS, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME);
    Concept nonCodedDiagnosisConcept = Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_NON_CODED_DIAGNOSIS, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME);
    Concept orderDiagnosisConcept = Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_DIAGNOSIS_ORDER, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME);
    Encounter encounter = formEntrySession.getEncounter();
    boolean updateEncounter = false;
    for (Obs obsGroup : encounter.getObsAtTopLevel(false)) {
        if (obsGroup.getConcept().equals(diagnosisConstructConcept)) {
            // we found a diagnosis construct
            Set<Obs> groupMembers = obsGroup.getGroupMembers();
            if (groupMembers != null && groupMembers.size() > 0) {
                boolean hasDiagnosis = false;
                boolean hasOrder = false;
                for (Obs member : groupMembers) {
                    if (member.getConcept().equals(codedDiagnosisConcept) || member.getConcept().equals(nonCodedDiagnosisConcept)) {
                        hasDiagnosis = true;
                    } else if (member.getConcept().equals(orderDiagnosisConcept)) {
                        hasOrder = true;
                    }
                }
                if (!hasDiagnosis) {
                    // we do not have a diagnosis but have other dangling construct obs
                    removeGivenObsAndTheirGroupMembersFromEncounter(Arrays.asList(obsGroup), encounter);
                    updateEncounter = true;
                } else if (!hasOrder) {
                    // add by default SECONDARY order
                    Obs order = new Obs();
                    order.setConcept(Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_DIAGNOSIS_ORDER, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME));
                    order.setValueCoded(Context.getConceptService().getConceptByMapping(EmrApiConstants.CONCEPT_CODE_DIAGNOSIS_ORDER_SECONDARY, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME));
                    order.setObsDatetime(encounter.getEncounterDatetime());
                    order.setLocation(encounter.getLocation());
                    order.setEncounter(encounter);
                    order.setPerson(encounter.getPatient());
                    obsGroup.addGroupMember(order);
                    Context.getObsService().saveObs(obsGroup, "add diagnosis order");
                }
            }
        }
    }
    if (updateEncounter) {
        Context.getEncounterService().saveEncounter(encounter);
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter)

Example 33 with Encounter

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

the class SetObsDatesToSpecimenCollectionDateAction method applyAction.

@Override
public void applyAction(FormEntrySession formEntrySession) {
    Concept specimenCollectionDateConcept = Context.getConceptService().getConceptByMapping(SPECIMEN_DATE_COLLECTED_CONCEPT_CODE_PIH, "PIH");
    Date specimenCollectionDate = null;
    Encounter encounter = formEntrySession.getEncounter();
    if (specimenCollectionDateConcept != null) {
        for (Obs candidate : encounter.getAllObs(false)) {
            if (candidate.getConcept().equals(specimenCollectionDateConcept)) {
                specimenCollectionDate = candidate.getValueDate();
                candidate.setObsDatetime(specimenCollectionDate);
                break;
            }
        }
        if (specimenCollectionDate != null) {
            for (Obs candidate : encounter.getAllObs(false)) {
                if (!candidate.getConcept().getDatatype().containsDate()) {
                    // the logic here is that we don't want to change the obs date of other dates like "Test Result Date"
                    candidate.setObsDatetime(specimenCollectionDate);
                }
            }
            Context.getEncounterService().saveEncounter(encounter);
        }
    } else {
        log.error("Unable to final specimen collection date cnept when applying setObsDatesToSpecimenCollectionDateAction");
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) Date(java.util.Date)

Example 34 with Encounter

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

the class PihPatientMergeActions method voidMostRecentRegistrationIfNonPreferred.

private void voidMostRecentRegistrationIfNonPreferred(Patient preferred, Patient nonPreferred) {
    EncounterType registrationEncounterType = encounterService.getEncounterTypeByUuid(PihEmrConfigConstants.ENCOUNTERTYPE_PATIENT_REGISTRATION_UUID);
    // the getEncounters method returns encounters sorted by date
    List<Encounter> preferredRegistrations = encounterService.getEncounters(preferred, null, null, null, null, Collections.singleton(registrationEncounterType), null, null, null, false);
    List<Encounter> nonPreferredRegistrations = encounterService.getEncounters(nonPreferred, null, null, null, null, Collections.singleton(registrationEncounterType), null, null, null, false);
    Encounter mostRecentPreferredRegistration = (preferredRegistrations != null && preferredRegistrations.size() > 0) ? preferredRegistrations.get(preferredRegistrations.size() - 1) : null;
    if (nonPreferredRegistrations != null && mostRecentPreferredRegistration != null) {
        for (Encounter nonPreferredRegistration : nonPreferredRegistrations) {
            if (nonPreferredRegistration.getEncounterDatetime().after(mostRecentPreferredRegistration.getEncounterDatetime())) {
                encounterService.voidEncounter(nonPreferredRegistration, "merging into patient " + preferred.getId() + ": voiding most recent registration encounter on non-preferred patient");
            }
        }
    }
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType)

Example 35 with Encounter

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

the class CleanPrescriptionConstructAction method applyAction.

@Override
public void applyAction(FormEntrySession formEntrySession) {
    Concept prescriptionConstructConcept = Context.getConceptService().getConceptByMapping(CleanPrescriptionConstructAction.PRESCRIPTION_CONSTRUCT_CONCEPT, "PIH");
    Concept medicationOrdersConcept = Context.getConceptService().getConceptByMapping(CleanPrescriptionConstructAction.MEDICATION_ORDERS_CONCEPT, "PIH");
    Encounter encounter = formEntrySession.getEncounter();
    boolean updateEncounter = false;
    for (Obs obsGroup : encounter.getObsAtTopLevel(false)) {
        if (obsGroup.getConcept().equals(prescriptionConstructConcept)) {
            // we found a prescription medication construct
            Set<Obs> groupMembers = obsGroup.getGroupMembers();
            if (groupMembers != null && groupMembers.size() > 0) {
                boolean hasMedicationOrders = false;
                for (Obs member : groupMembers) {
                    if (member.getConcept().equals(medicationOrdersConcept)) {
                        hasMedicationOrders = true;
                    }
                }
                if (!hasMedicationOrders) {
                    // we do not have a medication order but have other dangling construct obs
                    removeGivenObsAndTheirGroupMembersFromEncounter(Arrays.asList(obsGroup), encounter);
                    updateEncounter = true;
                }
            }
        }
    }
    if (updateEncounter) {
        Context.getEncounterService().saveEncounter(encounter);
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19