use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class ConceptServiceImpl method mapConceptProposalToConcept.
/**
* @see org.openmrs.api.ConceptService#mapConceptProposalToConcept(ConceptProposal, Concept, Locale)
*/
@Override
public Concept mapConceptProposalToConcept(ConceptProposal cp, Concept mappedConcept, Locale locale) throws APIException {
if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_REJECT)) {
cp.rejectConceptProposal();
Context.getConceptService().saveConceptProposal(cp);
return null;
}
if (mappedConcept == null) {
throw new APIException("Concept.mapped.illegal", (Object[]) null);
}
ConceptName conceptName = null;
if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT) || !StringUtils.hasText(cp.getFinalText())) {
cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT);
cp.setFinalText("");
} else if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM)) {
checkIfLocked();
String finalText = cp.getFinalText();
conceptName = new ConceptName(finalText, null);
conceptName.setConcept(mappedConcept);
conceptName.setLocale(locale == null ? Context.getLocale() : locale);
conceptName.setDateCreated(new Date());
conceptName.setCreator(Context.getAuthenticatedUser());
// If this is pre 1.9
if (conceptName.getUuid() == null) {
conceptName.setUuid(UUID.randomUUID().toString());
}
mappedConcept.addName(conceptName);
mappedConcept.setChangedBy(Context.getAuthenticatedUser());
mappedConcept.setDateChanged(new Date());
ValidateUtil.validate(mappedConcept);
Context.getConceptService().saveConcept(mappedConcept);
}
cp.setMappedConcept(mappedConcept);
if (cp.getObsConcept() != null) {
Obs ob = new Obs();
ob.setEncounter(cp.getEncounter());
ob.setConcept(cp.getObsConcept());
ob.setValueCoded(cp.getMappedConcept());
if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM)) {
ob.setValueCodedName(conceptName);
}
ob.setCreator(Context.getAuthenticatedUser());
ob.setDateCreated(new Date());
ob.setObsDatetime(cp.getEncounter().getEncounterDatetime());
ob.setLocation(cp.getEncounter().getLocation());
ob.setPerson(cp.getEncounter().getPatient());
if (ob.getUuid() == null) {
ob.setUuid(UUID.randomUUID().toString());
}
Context.getObsService().saveObs(ob, null);
cp.setObs(ob);
}
return mappedConcept;
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class AdministrationServiceImpl method setImplementationId.
/**
* @see org.openmrs.api.AdministrationService#setImplementationId(org.openmrs.ImplementationId)
*/
@Override
public void setImplementationId(ImplementationId implementationId) throws APIException {
if (implementationId == null) {
return;
}
// check the validity of this implementation id with the server
String description = implementationId.getDescription();
try {
// check that source id is valid
description = checkImplementationIdValidity(implementationId.getImplementationId(), description, implementationId.getPassphrase());
// save the server's description back to this concept source object
implementationId.setDescription(description);
boolean foundMatchingSource = false;
// loop over the concept sources to make sure one exists for this hl7Code/implementationId
List<ConceptSource> sources = Context.getConceptService().getAllConceptSources(false);
if (sources != null) {
for (ConceptSource source : sources) {
if (implementationId.getImplementationId().equals(source.getHl7Code())) {
foundMatchingSource = true;
}
}
}
// as a new ConceptSource
if (!foundMatchingSource) {
ConceptSource newConceptSource = new ConceptSource();
newConceptSource.setName(implementationId.getName());
newConceptSource.setDescription(implementationId.getDescription());
newConceptSource.setHl7Code(implementationId.getImplementationId());
if (Context.getAuthenticatedUser() == null) {
// (hackish)
// fake the user because no one is logged in
newConceptSource.setCreator(new User(1));
}
Context.getConceptService().saveConceptSource(newConceptSource);
}
// serialize and save the ImplementationId to the global properties table
String value = Context.getSerializationService().getDefaultSerializer().serialize(implementationId);
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID, value));
} catch (APIException e) {
throw e;
} catch (Exception e) {
// pass any other exceptions on up the train
throw new APIException(e);
} finally {
// save an empty concept source to the database when something fails?
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class CohortServiceImpl method notifyPatientUnvoided.
/**
* @see org.openmrs.api.CohortService#notifyPatientUnvoided(Patient, User, Date)
*/
@Override
public void notifyPatientUnvoided(Patient patient, User originallyVoidedBy, Date originalDateVoided) throws APIException {
List<CohortMembership> memberships = getCohortMemberships(patient.getPatientId(), null, true);
List<CohortMembership> toUnvoid = memberships.stream().filter(m -> m.getVoided() && m.getVoidedBy().equals(originallyVoidedBy) && OpenmrsUtil.compare(truncateToSeconds(m.getDateVoided()), truncateToSeconds(originalDateVoided)) == 0).collect(Collectors.toList());
for (CohortMembership member : toUnvoid) {
member.setVoided(false);
member.setDateVoided(null);
member.setVoidedBy(null);
member.setVoidReason(null);
dao.saveCohortMembership(member);
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class ObsServiceImpl method registerHandler.
/**
* @see org.openmrs.api.ObsService#registerHandler(String, String)
*/
@Override
public void registerHandler(String key, String handlerClass) throws APIException {
try {
Class<?> loadedClass = OpenmrsClassLoader.getInstance().loadClass(handlerClass);
registerHandler(key, (ComplexObsHandler) loadedClass.newInstance());
} catch (Exception e) {
throw new APIException("unable.load.and.instantiate.handler", null, e);
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class UserServiceImpl method saveUserProperties.
@Override
public User saveUserProperties(Map<String, String> properties) {
User user = Context.getAuthenticatedUser();
if (user == null) {
throw new APIException("no.authenticated.user.found", (Object[]) null);
}
user.getUserProperties().clear();
for (Map.Entry<String, String> entry : properties.entrySet()) {
user.setUserProperty(entry.getKey(), entry.getValue());
}
return dao.saveUser(user, null);
}
Aggregations