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;
}
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);
}
}
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");
}
}
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");
}
}
}
}
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);
}
}
Aggregations