/** * @see org.openmrs.api.VisitService#getVisitsByPatient(org.openmrs.Patient, boolean, boolean) */ @Override @Transactional(readOnly = true) public List<Visit> getVisitsByPatient(Patient patient, boolean includeInactive, boolean includeVoided) throws APIException { if (patient == null || patient.getId() == null) { return Collections.emptyList(); } return dao.getVisits(null, Collections.singletonList(patient), null, null, null, null, null, null, null, includeInactive, includeVoided); }
/** * Gets all active conditions related to the specified patient. * * @param patient the patient whose active conditions are being queried. * @return all active conditions associated with the specified patient. */ @Override public List<Condition> getActiveConditions(Patient patient) { Query query = sessionFactory.getCurrentSession().createQuery( "from Condition c where c.patient.patientId = :patientId and c.voided = false and c.endDate is null order " + "by c.onsetDate desc"); query.setInteger("patientId", patient.getId()); return query.list(); }
/** * Gets all conditions related to the specified patient. * * @param patient the patient whose condition history is being queried. * @return all active and non active conditions related to the specified patient. */ @Override public List<Condition> getConditionHistory(Patient patient) { Query query = sessionFactory.getCurrentSession().createQuery( "from Condition con where con.patient.patientId = :patientId and con.voided = false " + "order by con.onsetDate desc"); query.setInteger("patientId", patient.getId()); return query.list(); }
/** * @see org.openmrs.api.VisitService#getVisitsByPatient(org.openmrs.Patient) */ @Override @Transactional(readOnly = true) public List<Visit> getVisitsByPatient(Patient patient) throws APIException { //Don't bother to hit the database if (patient == null || patient.getId() == null) { return Collections.emptyList(); } return Context.getVisitService().getVisits(null, Collections.singletonList(patient), null, null, null, null, null, null, null, true, false); }
/** * Gets all active diagnoses related to the specified patient. * * @param patient the patient whose active diagnoses are being queried. * @return all active diagnoses associated with the specified patient. */ @SuppressWarnings("unchecked") @Override public List<Diagnosis> getActiveDiagnoses(Patient patient, Date fromDate) { String fromDateCriteria = ""; if(fromDate != null){ fromDateCriteria = " and d.dateCreated >= :fromDate "; } Query query = sessionFactory.getCurrentSession().createQuery( "from Diagnosis d where d.patient.patientId = :patientId and d.voided = false " + fromDateCriteria + " order by d.dateCreated desc"); query.setInteger("patientId", patient.getId()); if(fromDate != null){ query.setDate("fromDate", fromDate); } return query.list(); }
@Override public Encounter transferEncounter(Encounter encounter, Patient patient) { Encounter encounterCopy = encounter.copyAndAssignToAnotherPatient(patient); voidEncounter(encounter, "transfer to patient: id = " + patient.getId()); //void visit if voided encounter is the only one Visit visit = encounter.getVisit(); if (visit != null && visit.getEncounters().size() == 1) { Context.getVisitService().voidVisit(visit, "Visit does not contain non-voided encounters"); } return saveEncounter(encounterCopy); } }
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldCascadePatientToOrdersInTheEncounter() { Encounter enc = Context.getEncounterService().getEncounter(15); Order existing = enc.getOrders().iterator().next(); // for some reason the xml for the existing encounter has already given // this order a different patient than the encounter that it's contained // in, but let's verify that: Assert.assertNotSame(enc.getPatient().getId(), existing.getPatient().getId()); Context.getEncounterService().saveEncounter(enc); Assert.assertEquals(enc.getPatient().getId(), existing.getPatient().getId()); }
@Test public void getPatient_shouldCreatePatientFromPerson() throws Exception { executeDataSet(USER_WHO_IS_NOT_PATIENT_XML); Patient patient = patientService.getPatientOrPromotePerson(202); Assert.assertNotNull(patient); Assert.assertEquals(202, patient.getId().intValue()); }
@Override public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) { if (patient.getId() != null) {
/** * @verifies not return ended memberships * @see CohortService#getCohortsContainingPatient(org.openmrs.Patient) */ @Test public void getCohortsContainingPatient_shouldNotReturnEndedMemberships() throws Exception { executeDataSet(COHORT_XML); Cohort cohort = service.getCohort(2); Patient patient = new Patient(7); CohortMembership membership = new CohortMembership(patient.getPatientId()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startDate = dateFormat.parse("2017-01-01 00:00:00"); membership.setStartDate(startDate); cohort.addMembership(membership); assertTrue(cohort.contains(patient.getPatientId())); Date endDate = dateFormat.parse("2017-01-31 00:00:00"); membership.setEndDate(endDate); List<Cohort> cohortsWithPatientAdded = service.getCohortsContainingPatientId(patient.getId()); assertEquals(0, cohortsWithPatientAdded.size()); }
/** * @see CohortService#getCohortsContainingPatient(Patient) */ @Test public void getCohortsContainingPatient_shouldReturnCohortsThatHaveGivenPatient() { executeDataSet(COHORT_XML); Patient patientToAdd = new Patient(7); service.addPatientToCohort(service.getCohort(2), patientToAdd); assertTrue(service.getCohort(2).contains(patientToAdd.getPatientId())); List<Cohort> cohortsWithGivenPatient = service.getCohortsContainingPatientId(patientToAdd.getId()); assertTrue(cohortsWithGivenPatient.contains(service.getCohort(2))); }
public Boolean metBy(Patient patient) { return (patient.getId() > 5717) && patientFromUpperEast(patient) && patientNotInTreatmentGroup(patient); }
@Test public void patientVoided_shouldVoidMemberships() { executeDataSet(COHORT_XML); Cohort cohort = Context.getCohortService().getCohort(2); Patient voidedPatient = new Patient(7); voidedPatient.setVoided(true); voidedPatient.setDateVoided(new Date()); voidedPatient.setVoidedBy(Context.getAuthenticatedUser()); voidedPatient.setVoidReason("Voided as a result of the associated patient getting voided"); CohortMembership newMemberContainingVoidedPatient = new CohortMembership(voidedPatient.getPatientId()); cohort.addMembership(newMemberContainingVoidedPatient); assertTrue(cohort.contains(voidedPatient.getPatientId())); assertEquals(1, service.getCohortsContainingPatientId(voidedPatient.getId()).size()); service.notifyPatientVoided(voidedPatient); assertTrue(newMemberContainingVoidedPatient.getVoided()); assertEquals(newMemberContainingVoidedPatient.getDateVoided(), voidedPatient.getDateVoided()); assertEquals(newMemberContainingVoidedPatient.getVoidedBy(), voidedPatient.getVoidedBy()); assertEquals(newMemberContainingVoidedPatient.getVoidReason(), voidedPatient.getVoidReason()); }
/** * @see CohortService#getCohortsContainingPatient(Patient) */ @Test public void getCohortsContainingPatient_shouldNotReturnVoidedCohorts() { executeDataSet(COHORT_XML); // make sure we have two cohorts, the first of which is voided assertTrue(service.getCohort(1).getVoided()); assertFalse(service.getCohort(2).getVoided()); // add a patient to both cohorts Patient patientToAdd = new Patient(7); service.addPatientToCohort(service.getCohort(1), patientToAdd); service.addPatientToCohort(service.getCohort(2), patientToAdd); assertTrue(service.getCohort(1).contains(patientToAdd.getPatientId())); assertTrue(service.getCohort(2).contains(patientToAdd.getPatientId())); // call the method and it should not return the voided cohort List<Cohort> cohortsWithPatientAdded = service.getCohortsContainingPatientId(patientToAdd.getId()); assertNotNull(cohortsWithPatientAdded); assertFalse(cohortsWithPatientAdded.contains(service.getCohort(1))); }
OpenMRSPatient getMrsPatient(org.openmrs.Patient patient) { final PatientIdentifier patientIdentifier = patient.getPatientIdentifier(); MRSFacility mrsFacility = ((patientIdentifier != null) ? facilityAdapter.convertLocationToFacility(patientIdentifier.getLocation()) : null); String motechId = (patientIdentifier != null) ? patientIdentifier.getIdentifier() : null; OpenMRSPerson mrsPerson = PersonHelper.openMRSToMRSPerson(patient); return new OpenMRSPatient(String.valueOf(patient.getId()), motechId, mrsPerson, mrsFacility); }
/** * @param member the patient to be removed from cohort */ public void removeMemberFromCohort(CohortMember1_8 member) { getParent(member).removeMember(member.getPatient().getId()); Context.getCohortService().saveCohort(getParent(member)); }
/** * @param member the patient to be added to cohort */ public void addMemberToCohort(CohortMember1_8 member) { getParent(member).addMember(member.getPatient().getId()); Context.getCohortService().saveCohort(getParent(member)); }
@SuppressWarnings("deprecation") public PatientState currentProgramWorkflowStatus(Integer programWorkflowId) { Patient p = session.getPatient(); if (p == null || p.getId() == null) { return null;