protected String getQueryPrameters(HttpServletRequest request, FormEntrySession formEntrySession) { return "?patientId=" + formEntrySession.getPatient().getPersonId(); } }
/** * Adds the patientId=xyz parameter to the returnUrl * * @return the returnUrl with patientId parameter */ public String getReturnUrlWithParameters() { if (!StringUtils.hasText(returnUrl)) return null; String ret = returnUrl; if (!ret.contains("?")) ret += "?"; if (!ret.endsWith("?") && !ret.endsWith("&")) ret += "&"; ret += "patientId=" + getPatient().getPatientId(); return ret; }
@Override public void applyAction(FormEntrySession session) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(scriptType); scriptEngine.put("patient", session.getPatient()); scriptEngine.put("encounter", session.getSubmissionActions().getCurrentEncounter()); scriptEngine.put("formEntrySession", session); try { Object result = scriptEngine.eval(script); session.setAfterSaveUrlTemplate(result.toString()); } catch (ScriptException ex) { throw new IllegalStateException("Exception while evaluating " + scriptType + " for <redirectOnSave>", ex); } } }
private void cannotBePreviewed() { if ("testing-html-form-entry".equals(session.getPatient().getUuid())) throw new CannotBePreviewedException(); }
public List<Obs> allObs(String conceptId) { if (session.getPatient() == null) { return new ArrayList<Obs>(); } cannotBePreviewed(); Patient p = session.getPatient(); Concept concept = HtmlFormEntryUtil.getConcept(conceptId); if (p == null || concept == null) { return new ArrayList<Obs>(); } else { return getObsService().getObservationsByPersonAndConcept(p, concept); } }
private List<Encounter> getAllEncounters(EncounterType type) { if (session.getPatient() == null) { return new ArrayList<Encounter>(); } cannotBePreviewed(); Patient p = session.getPatient(); if (p == null) { return new ArrayList<Encounter>(); } else { if (type == null) { return Context.getEncounterService().getEncountersByPatient(p); } else { List<EncounterType> typeList = new ArrayList<EncounterType>(); typeList.add(type); EncounterServiceCompatibility esc = Context.getRegisteredComponent("htmlformentry.EncounterServiceCompatibility", EncounterServiceCompatibility.class); return esc.getEncounters(p, null, null, null, null, typeList, null, null, null, false); } } }
/** * * @return patient's age given in months * @should return the ageInMonths accurately to the nearest month */ public Integer patientAgeInMonths() { Patient patient = session.getPatient(); if(patient == null || patient.getBirthdate() == null){ return null; // if there is error in patient's data return age as null } Date birthdate = patient.getBirthdate(); DateTime today = new DateTime(); DateTime dob = new DateTime(birthdate.getTime()); return Months.monthsBetween(dob.toDateMidnight(), today.toDateMidnight()).getMonths(); }
/** * * @return patient's age in days * @should return the ageInDays accurately to the nearest date */ public Integer patientAgeInDays(){ Patient patient = session.getPatient(); if(patient == null || patient.getBirthdate() == null){ return null; // if there is error in patient's data return age as null } Date birthdate = patient.getBirthdate(); DateTime today = new DateTime(); DateTime dob = new DateTime(birthdate.getTime()); return Days.daysBetween(dob.toDateMidnight(), today.toDateMidnight()).getDays(); }
public Result logic(String expression) { if (session.getPatient() == null) return new EmptyResult(); cannotBePreviewed(); LogicCriteria lc = getLogicService().parse(expression); return getLogicService().eval(session.getPatient().getPatientId(), lc); }
if ("testing-html-form-entry".equals(session.getPatient().getUuid())) return false; else { try { return ls.eval(session.getPatient().getPatientId(), logicCriteria).toBoolean(); } catch (Exception ex) { throw new BadFormDesignException(ex.getMessage());
if (session.getContext().getMode() == Mode.ENTER && session.hasPatientTag() && session.getPatient() == null && (session.getSubmissionActions().getPersonsToCreate() == null || session.getSubmissionActions().getPersonsToCreate().size() == 0)) throw new IllegalArgumentException("This form is not going to create an Patient"); String successView = session.getAfterSaveUrlTemplate(); if (successView != null) { successView = successView.replaceAll("\\{\\{patient.id\\}\\}", session.getPatient().getId().toString()); successView = successView.replaceAll("\\{\\{encounter.id\\}\\}", session.getEncounter().getId().toString()); successView = request.getContextPath() + "/" + successView;
@Before public void setUp() { patient = new Patient(); encounter = new Encounter(); encounter.setPatient(patient); unknownConcept = new Concept(); patientService = mock(PatientService.class); submissionController = mock(FormSubmissionController.class); formEntrySession = mock(FormEntrySession.class); when(formEntrySession.getSubmissionController()).thenReturn(submissionController); when(formEntrySession.getPatient()).thenReturn(patient); when(formEntrySession.getEncounter()).thenReturn(encounter); tagHandler = new MarkPatientDeadTagHandler() { @Override Concept getUnknownConcept() { return unknownConcept; } }; tagHandler.setPatientService(patientService); }
protected void enterStandardRegimen(FormEntrySession session, HttpServletRequest submission, String regCode, Date startDate, Date discontinuedDate, String discontinuedReasonStr) { RegimenSuggestion rs = RegimenUtil.getStandardRegimenByCode(possibleRegimens, regCode); //create new drugOrders Set<Order> ords = RegimenUtil.standardRegimenToDrugOrders(rs, startDate, session.getPatient()); for (Order o: ords){ if (o.getDateCreated() == null) o.setDateCreated(new Date()); if (o.getCreator() == null) o.setCreator(Context.getAuthenticatedUser()); if (o.getUuid() == null) o.setUuid(UUID.randomUUID().toString()); if (!StringUtils.isEmpty(discontinuedReasonStr)) o.setDiscontinuedReason(HtmlFormEntryUtil.getConcept(discontinuedReasonStr)); if (discontinuedDate != null){ o.setDiscontinuedDate(discontinuedDate); o.setDiscontinued(true); o.setDiscontinuedBy(Context.getAuthenticatedUser()); } session.getSubmissionActions().getCurrentEncounter().addOrder(o); } }
Patient patient = session.getPatient(); Encounter encounter = session.getEncounter(); SerializableFormObject formObject = null;
RegimenSuggestion rs = RegimenUtil1_10.getStandardRegimenByCode(possibleRegimens, regCode); Set<Order> ords = RegimenUtil1_10.standardRegimenToDrugOrders(rs, startDate, session.getPatient()); for (Order o : ords) { if (o.getDateCreated() == null)
drugOrder.setUuid(UUID.randomUUID().toString()); drugOrder.setDrug(orderTag.drug); drugOrder.setPatient(session.getPatient()); drugOrder.setDose(orderTag.dose); drugOrder.setFrequency(orderTag.frequency);
Set<Order> ords = RegimenUtil1_10.standardRegimenToDrugOrders(rs, startDate, session.getPatient()); for (Order o : ords) { if (o.getDateCreated() == null)
@Override public void applyAction(FormEntrySession session) { Patient patient = session.getPatient(); Encounter encounter = session.getEncounter(); patient.setDead(true); if (deathDateFromEncounter) { if (patient.getDeathDate() == null || !preserveExistingDeathDate) { patient.setDeathDate(encounter.getEncounterDatetime()); } } if (patient.getCauseOfDeath() == null || !preserveExistingCauseOfDeath) { Concept causeOfDeath = null; if (causeOfDeathFromObs != null) { causeOfDeath = findObsCodedValue(session.getEncounter(), causeOfDeathFromObs); } if (causeOfDeath == null) { // don't overwrite with Unknown, even if we haven't specifically said to preserve existing causeOfDeath = patient.getCauseOfDeath(); } if (causeOfDeath == null) { causeOfDeath = getUnknownConcept(); } patient.setCauseOfDeath(causeOfDeath); } patientService.savePatient(patient); }
private SubmissionResults doSubmission(FormEntrySession session, HttpServletRequest request) throws Exception { SubmissionResults results = new SubmissionResults(); session.prepareForSubmit(); List<FormSubmissionError> validationErrors = session.getSubmissionController().validateSubmission( session.getContext(), request); if (validationErrors != null && validationErrors.size() > 0) { results.setValidationErrors(validationErrors); return results; } session.getSubmissionController().handleFormSubmission(session, request); if (session.getContext().getMode() == Mode.ENTER && session.hasEncouterTag() && (session.getSubmissionActions().getEncountersToCreate() == null || session.getSubmissionActions() .getEncountersToCreate().size() == 0)) throw new IllegalArgumentException("This form is not going to create an encounter"); Context.getService(HtmlFormEntryService.class).applyActions(session); results.setPatient(session.getPatient()); results.setEncounterCreated(session.getEncounter()); results.setFormEntrySession(session); return results; }
drugOrder.setPatient(session.getPatient()); drugOrder.setDosingType(orderTag.dosingType); drugOrder.setDose(orderTag.dose);