/// <summary> /// /// </summary> protected override void DoWork(CodeActivityContext context) { var patId1 = PatId.Get(context); var patient = Patient.GetEntityByID(patId1, PM); if (patient.IsNullEntity) { return; } short?docType = null; var docTypeTemp = DocType.Get(context); if (docTypeTemp.HasValue) { docType = (short)docTypeTemp.Value; } var dictId = DictatedBy.Get(context); if (dictId == 0) { return; } int?reviewId = null; int temp = ReviewRequiredBy.Get(context); if (temp > 0) { reviewId = temp; } int?cosignId = null; temp = CoSignRequiredBy.Get(context); if (temp > 0) { cosignId = temp; } int?transId = null; temp = TranscribedBy.Get(context); if (temp > 0) { transId = temp; } var encounterTemp = EncounterDate.Get(context); if (!encounterTemp.HasValue) { return; } var encounterDate = encounterTemp.Value; var transcribedDate = TranscribedDate.Get(context); var instId = Department.Get(context); var accountId = Account.Get(context); var template = Template.Get(context); var openAfterCreation = OpenAfterCreation.Get(context).Key == (int)OpenAfterCreationOptions.Yes; var status = (byte)Status.Get(context); if (CreateIfDuplicateExists.Get(context).Key == (int)CreateIfDuplicateExistsOptions.No) { // Check for a duplicate encounter var query = new ImpacRdbQuery(typeof(ObjectTable)); query.AddClause(ObjectTableDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1); query.AddClause(ObjectTableDataRow.DocTypeEntityColumn, EntityQueryOp.EQ, docType); query.AddClause(ObjectTableDataRow.Dict_IDEntityColumn, EntityQueryOp.EQ, dictId); query.AddClause(ObjectTableDataRow.Review_IDEntityColumn, EntityQueryOp.EQ, reviewId); query.AddClause(ObjectTableDataRow.CoSig_IDEntityColumn, EntityQueryOp.EQ, cosignId); query.AddClause(ObjectTableDataRow.Trans_IDEntityColumn, EntityQueryOp.EQ, transId); // Defect 11605, the Encounter_DtTm and Trans_DtTm store date time rather than the previous date part // so we should check items if it exists within the day of datetime query.AddClause(ObjectTableDataRow.Encounter_DtTmEntityColumn, EntityQueryOp.Between, encounterDate.Date, encounterDate.Date.AddDays(1)); if (transcribedDate.HasValue) { query.AddClause(ObjectTableDataRow.Trans_DtTmEntityColumn, EntityQueryOp.Between, transcribedDate.Value.Date, transcribedDate.Value.Date.AddDays(1)); } query.AddClause(ObjectTableDataRow.Inst_IDEntityColumn, EntityQueryOp.EQ, instId); query.AddClause(ObjectTableDataRow.Account_IDEntityColumn, EntityQueryOp.EQ, accountId); query.AddClause(ObjectTableDataRow.DocumentTemplateEntityColumn, EntityQueryOp.EQ, template); var objectEntity = PM.GetEntity(query); if (objectEntity != null && !objectEntity.IsNullEntity) { return; } } EscribeOperations.CreateDocument(patId1, docType, dictId, reviewId, cosignId, transId, encounterDate, transcribedDate, instId, accountId, template, status, openAfterCreation); }