def get_linked_patient(self, instance): """Get the linked client """ mrn = instance.getMedicalRecordNumberValue() if not mrn: return None return patient_api.get_patient_by_mrn(mrn, include_inactive=True)
def set_mrn(self, value): value = value.strip() if self.mrn == value: # noting changed return if patient_api.get_patient_by_mrn(value, full_object=False, include_inactive=True): raise ValueError("A patient with that MRN already exists!") self.mrn = value
def update_patient(instance): if instance.isMedicalRecordTemporary(): return mrn = instance.getMedicalRecordNumberValue() # Allow empty value when patients are not required for samples if mrn is None: return patient = patient_api.get_patient_by_mrn(mrn, include_inactive=True) if patient is None: logger.info("Creating new Patient with MRN #: {}".format(mrn)) patient = patient_api.create_empty_patient() # XXX: Sync the values back from Sample -> Patient? values = get_patient_fields(instance) patient_api.update_patient(patient, **values)
def validate_mrn(data): """Checks if the patient MRN # is unique """ # https://community.plone.org/t/dexterity-unique-field-validation context = getattr(data, "__context__", None) if context is not None: if context.mrn == data.mrn: # nothing changed return patient = patient_api.get_patient_by_mrn(data.mrn, full_object=False, include_inactive=True) if patient: raise Invalid(_("Patient Medical Record # must be unique"))
def on_before_transition(instance, event): """Event handler when a sample was created """ # we only care when reactivating the patient if event.new_state.getId() != "active": return mrn = instance.get_mrn() patient = patient_api.get_patient_by_mrn(mrn, full_object=False) if not patient: return True # set UID as new MRN # uid = api.get_uid(instance) instance.set_mrn(api.get_uid(instance)) # Add warning message message = "Duplicate MRN # '{}' was changed to '{}'".format(mrn, uid) instance.plone_utils.addPortalMessage(message, "warning")