use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.
the class ProcessHL7InQueueTask method execute.
/**
* Process the next form entry in the database and then remove the form entry from the database.
*/
@Override
public void execute() {
Context.openSession();
try {
log.debug("Processing HL7 queue ... ");
processor.processHL7InQueue();
} catch (HL7Exception e) {
log.error("Error running hl7 in queue task", e);
throw new APIException("Hl7inQueue.error.running", null, e);
} finally {
Context.closeSession();
}
}
use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.
the class ORUR01Handler method createEncounter.
/**
* This method does not call the database to create the encounter row. The encounter is only
* created after all obs have been attached to it Creates an encounter pojo to be attached
* later. This method does not create an encounterId
*
* @param msh
* @param patient
* @param pv1
* @param orc
* @return
* @throws HL7Exception
*/
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
// the encounter we will return
Encounter encounter;
// look for the encounter id in PV1-19
CX visitNumber = pv1.getVisitNumber();
Integer encounterId = null;
try {
encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
} catch (NumberFormatException e) {
// pass
}
// the database
if (encounterId != null) {
encounter = Context.getEncounterService().getEncounter(encounterId);
} else {
// if no encounter_id was passed in, this is a new
// encounter, create the object
encounter = new Encounter();
Date encounterDate = getEncounterDate(pv1);
Provider provider = getProvider(pv1);
Location location = getLocation(pv1);
Form form = getForm(msh);
EncounterType encounterType = getEncounterType(msh, form);
User enterer = getEnterer(orc);
// Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
encounter.setEncounterDatetime(encounterDate);
if (unknownRole == null) {
unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
}
encounter.setProvider(unknownRole, provider);
encounter.setPatient(patient);
encounter.setLocation(location);
encounter.setForm(form);
encounter.setEncounterType(encounterType);
encounter.setCreator(enterer);
encounter.setDateCreated(new Date());
}
return encounter;
}
use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.
the class ORUR01Handler method getDatetime.
/**
* Return a java date object for the given TS
*
* @param ts TS to parse
* @return date object or null
* @throws HL7Exception
*/
private Date getDatetime(TS ts) throws HL7Exception {
Date datetime = null;
DTM value = ts.getTime();
if (value.getYear() == 0 || value.getValue() == null) {
return null;
}
try {
datetime = getDate(value.getYear(), value.getMonth(), value.getDay(), value.getHour(), value.getMinute(), value.getSecond());
} catch (DataTypeException e) {
}
return datetime;
}
use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.
the class ORUR01Handler method getEnterer.
private User getEnterer(ORC orc) throws HL7Exception {
XCN hl7Enterer = orc.getEnteredBy(0);
Integer entererId = Context.getHL7Service().resolveUserId(hl7Enterer);
if (entererId == null) {
throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedEnterer"));
}
User enterer = new User();
enterer.setUserId(entererId);
return enterer;
}
use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.
the class ORUR01Handler method getProvider.
private Provider getProvider(PV1 pv1) throws HL7Exception {
XCN hl7Provider = pv1.getAttendingDoctor(0);
Provider provider = null;
String id = hl7Provider.getIDNumber().getValue();
String assignAuth = hl7Provider.getAssigningAuthority().getUniversalID().getValue();
String type = hl7Provider.getAssigningAuthority().getUniversalIDType().getValue();
String errorMessage;
if (StringUtils.hasText(id)) {
String specificErrorMsg = "";
if (OpenmrsUtil.nullSafeEquals("L", type)) {
if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_ID.equalsIgnoreCase(assignAuth)) {
try {
provider = Context.getProviderService().getProvider(Integer.valueOf(id));
} catch (NumberFormatException e) {
// ignore
}
specificErrorMsg = "with provider Id";
} else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER.equalsIgnoreCase(assignAuth)) {
provider = Context.getProviderService().getProviderByIdentifier(id);
specificErrorMsg = "with provider identifier";
} else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID.equalsIgnoreCase(assignAuth)) {
provider = Context.getProviderService().getProviderByUuid(id);
specificErrorMsg = "with provider uuid";
}
} else {
try {
Person person = Context.getPersonService().getPerson(Integer.valueOf(id));
Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
if (!providers.isEmpty()) {
provider = providers.iterator().next();
}
} catch (NumberFormatException e) {
// ignore
}
specificErrorMsg = "associated to a person with person id";
}
errorMessage = "Could not resolve provider " + specificErrorMsg + ":" + id;
} else {
errorMessage = "No unique identifier was found for the provider";
}
if (provider == null) {
throw new HL7Exception(errorMessage);
}
return provider;
}
Aggregations