public string GetSingleStatement(Observation observation) { var mConcept = GetMConcept(observation.MConceptId); if (null == mConcept) { Log.Debug($"No concept {observation.MConceptId} for single statement"); return(string.Empty); } var iqConcept = mConcept.IQConcepts.FirstOrDefault(); if (null == iqConcept) { Log.Debug($"No iq-concept for {observation.MConceptId}"); return(string.Empty); } StringBuilder singleBuilder = new StringBuilder(); singleBuilder.AppendLine( $@" UPDATE {iqConcept.Tablename} SET {iqConcept.Fieldname}={observation.ObsvalueSqlString()} WHERE Ptn_pk=@ptnpk AND Visit_Pk=@visitipk AND LocationId=(select TOP 1 FacilityID from mst_Facility WHERE DeleteFlag = 0) IF @@ROWCOUNT=0 Insert into [{iqConcept.Tablename}] ( [ptn_pk], [Visit_Pk], [LocationID],[{iqConcept.Fieldname}],UserId, CreateDate) values ( @ptnpk,@visitipk, (select TOP 1 FacilityID from mst_Facility WHERE DeleteFlag = 0),{observation.ObsvalueSqlString()},{Patient.UserId},Getdate());"); return(singleBuilder.ToString()); }