use of org.openmrs.PatientIdentifier in project openmrs-module-mirebalais by PIH.
the class IdCardFragmentController method recordSuccessfulPrintAttempt.
/**
* This method takes in a patientId and an identifier and validates that this is a valid identifier for this patient
* If it is valid, it will save an Observation to the patient record indicating that an id card was successfully printed
* @return a SimpleObject containing a flag indicating success, and a message suitable for display
*/
public SimpleObject recordSuccessfulPrintAttempt(UiUtils ui, UiSessionContext uiSessionContext, @SpringBean EmrApiProperties emrApiProperties, @RequestParam("patientId") Patient patient, @RequestParam("identifier") String identifier) {
StatusMessage status = new StatusMessage(false, ui.message("zl.registration.patient.idcard.invalidForPatient", identifier, ui.format(patient.getPersonName())));
for (PatientIdentifier pi : patient.getIdentifiers()) {
if (pi.getIdentifierType().getUuid().equals(emrApiProperties.getPrimaryIdentifierType().getUuid())) {
if (pi.getIdentifier().equalsIgnoreCase(identifier)) {
status = new StatusMessage(true, "");
savePrintingStatusObs(patient, uiSessionContext.getSessionLocation(), true);
}
}
}
return SimpleObject.fromObject(status, ui, "success", "message");
}
use of org.openmrs.PatientIdentifier in project openmrs-module-mirebalais by PIH.
the class FindPatientPageController method post.
public String post(@RequestParam(required = false, value = "remoteServer") String remoteServer, @RequestParam("remoteUuid") String remoteUuid, UiUtils ui, HttpServletRequest request) {
if (StringUtils.isNotBlank(remoteUuid)) {
HttpSession session = request.getSession();
RemotePatient remotePatient = getFromCache(remoteUuid, session);
if (remotePatient != null) {
// import the patient
try {
Patient patient = remotePatient.getPatient();
PatientIdentifierType zlIdentifierType = MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.ZL_EMR_ID.uuid());
if (zlIdentifierType != null && patient != null) {
PatientIdentifier patientIdentifier = patient.getPatientIdentifier(zlIdentifierType);
if (patientIdentifier != null) {
patientIdentifier.setPreferred(true);
}
}
patient = Context.getPatientService().savePatient(patient);
if (patient != null) {
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("mirebalais.mpi.import.success", ui.format(patient)));
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
removeFromCache(remoteUuid, session);
return "redirect:" + ui.pageLink("coreapps", "patientdashboard/patientDashboard?patientId=" + patient.getId().toString());
}
} catch (Exception e) {
log.error("failed to import patient", e);
request.getSession().setAttribute(EmrConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, ui.message("mirebalais.mpi.import.error", e.getMessage()));
}
}
}
return "redirect:" + ui.pageLink("mirebalais/mpi", "findPatient");
}
use of org.openmrs.PatientIdentifier in project openmrs-module-coreapps by openmrs.
the class FindPatientFragmentController method simplify.
SimpleObject simplify(UiUtils ui, EmrApiProperties emrApiProperties, Patient patient) {
PersonName name = patient.getPersonName();
SimpleObject preferredName = SimpleObject.fromObject(name, ui, "givenName", "middleName", "familyName", "familyName2");
preferredName.put("name", ui.format(name));
PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
List<PatientIdentifier> primaryIdentifiers = patient.getPatientIdentifiers(primaryIdentifierType);
SimpleObject o = SimpleObject.fromObject(patient, ui, "patientId", "gender", "age", "birthdate", "birthdateEstimated");
o.put("preferredName", preferredName);
o.put("primaryIdentifiers", SimpleObject.fromCollection(primaryIdentifiers, ui, "identifier"));
return o;
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceImpl method mergeIdentifiers.
private void mergeIdentifiers(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
// (must be done after all calls to services above so hbm doesn't try to save things prematurely (hacky)
for (PatientIdentifier pi : notPreferred.getActiveIdentifiers()) {
PatientIdentifier tmpIdentifier = new PatientIdentifier();
tmpIdentifier.setIdentifier(pi.getIdentifier());
tmpIdentifier.setIdentifierType(pi.getIdentifierType());
tmpIdentifier.setLocation(pi.getLocation());
tmpIdentifier.setPatient(preferred);
boolean found = false;
for (PatientIdentifier preferredIdentifier : preferred.getIdentifiers()) {
if (preferredIdentifier.getIdentifier() != null && preferredIdentifier.getIdentifier().equals(tmpIdentifier.getIdentifier()) && preferredIdentifier.getIdentifierType() != null && preferredIdentifier.getIdentifierType().equals(tmpIdentifier.getIdentifierType())) {
found = true;
}
}
if (!found) {
tmpIdentifier.setIdentifierType(pi.getIdentifierType());
tmpIdentifier.setCreator(Context.getAuthenticatedUser());
tmpIdentifier.setDateCreated(new Date());
tmpIdentifier.setVoided(false);
tmpIdentifier.setVoidedBy(null);
tmpIdentifier.setVoidReason(null);
tmpIdentifier.setUuid(UUID.randomUUID().toString());
// we don't want to change the preferred identifier of the preferred patient
tmpIdentifier.setPreferred(false);
preferred.addIdentifier(tmpIdentifier);
mergedData.addCreatedIdentifier(tmpIdentifier.getUuid());
log.debug("Merging identifier " + tmpIdentifier.getIdentifier() + " to " + preferred.getPatientId());
}
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceImplTest method processDeath_shouldMapValuesAndSavePatient.
@Test
public void processDeath_shouldMapValuesAndSavePatient() throws Exception {
// given
final Date dateDied = new Date();
final Concept causeOfDeath = new Concept(2);
when(conceptServiceMock.getConcept(anyString())).thenReturn(new Concept());
when(locationServiceMock.getDefaultLocation()).thenReturn(new Location());
ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
when(patientDaoMock.savePatient(argumentCaptor.capture())).thenReturn(new Patient());
// when
final Patient patient = new Patient();
patient.addIdentifier(new PatientIdentifier("an identifier", new PatientIdentifierType(1234), new Location()));
patientService.processDeath(patient, dateDied, causeOfDeath, "unknown");
// then
final Patient savedPatient = argumentCaptor.getValue();
assertEquals(true, savedPatient.getDead());
assertEquals(dateDied, savedPatient.getDeathDate());
assertEquals(causeOfDeath, savedPatient.getCauseOfDeath());
}
Aggregations