Skip to content

Instantly share code, notes, and snippets.

@ImaginaryDevelopment
Created November 9, 2015 21:27
Show Gist options
  • Save ImaginaryDevelopment/079d3fc2a3630a11a77e to your computer and use it in GitHub Desktop.
Save ImaginaryDevelopment/079d3fc2a3630a11a77e to your computer and use it in GitHub Desktop.
let internal save connection apptId apptPatientId apptPatientInfoId apptProviderScheduledId apptFacilityId apptStartTime apptEndTime apptTypeId apptStatus apptBillingStage apptLoS apptCheckInFlag apptCheckInTime apptCheckOutTime apptForeignEhrId apptAccidentRelated apptAccidentId apptAccidentDate apptAccidentState presentingCondition notesToBiller isChecked apptPrimaryGuarantorType admitStatus (admitFacilityId:int Nullable) referralPcp =
let admitStatus = if String.IsNullOrEmpty(admitStatus) then null else admitStatus
getScalar connection false (fun db -> db.UspAppointmentsInsUpd(apptId, apptPatientId, apptPatientInfoId, apptProviderScheduledId, apptFacilityId, apptStartTime, apptEndTime, apptTypeId, apptStatus, apptBillingStage, apptLoS, apptCheckInFlag, apptCheckInTime, apptCheckOutTime, apptForeignEhrId, apptAccidentRelated, apptAccidentId, apptAccidentDate, apptAccidentState, presentingCondition, notesToBiller, isChecked, apptPrimaryGuarantorType,admitStatus=admitStatus,admitFacilityId=admitFacilityId,referralPcp=referralPcp))
let SaveConn con apptId apptPatientId apptPatientInfoId apptProviderScheduledId apptFacilityId apptStartTime apptEndTime apptTypeId apptStatus apptBillingStage apptLoS apptCheckInFlag apptCheckInTime apptCheckOutTime apptForeignEhrId apptAccidentRelated apptAccidentId apptAccidentDate apptAccidentState presentingCondition notesToBiller isChecked apptPrimaryGuarantorType admitStatus admitFacilityId referralPcp =
save (SqlConn.Conn con) apptId apptPatientId apptPatientInfoId apptProviderScheduledId apptFacilityId apptStartTime apptEndTime apptTypeId apptStatus apptBillingStage apptLoS apptCheckInFlag apptCheckInTime apptCheckOutTime apptForeignEhrId apptAccidentRelated apptAccidentId apptAccidentDate apptAccidentState presentingCondition notesToBiller isChecked apptPrimaryGuarantorType admitStatus admitFacilityId referralPcp
// instead of
let SaveConn' con = save (SqlConn.Conn con)
// this version while vastly shorter gives no information about parameter names in either F# or C# when called
@tpetricek
Copy link

I can definitely see that propagating the parameter names would be useful. Though in a case like this, I would say that having that many parameters is going to make your code hard to use no matter whether F# propagates parameter names or not.

My recommendation would be to define a record and pass around the parameters in a record:

type Appointment = 
  { ApptId : int
    ApptPatientId : int 
    ApptPatientInfoId :string 
    ApptProviderScheduledId : int
    ApptFacilityId : int
    ApptStartTime :DateTime 
    ApptEndTime : DateTime
    // ... more stuff here ...
  }

Then you can write just:

let SaveConn con appt  =  
    save (SqlConn.Conn con) appt // possibly few other records

Also, creating F# records from C# will be pretty nice, so it shouldn't make that part ugly.

@dsyme
Copy link

dsyme commented Nov 10, 2015

With this many parameters (and this much "metadata" such as parameter names) it can make sense to use a either a static member or an instance member on a context type. Some parameters can be associated with the type, and the remaining parameters with the method. And both can use named/optional arguments.

type Connection(connection) = 
    let conn = SqlConn.Conn connection
    member __.SaveAppointment(referralPcp, id, patientId, patientInfoId, providerScheduledId, facilityId, startTime, endTime, typeId, status, billingStage, los, checkInFlag, checkInTime, checkOutTime, foreignEhrId, accidentRelated, accidentId, accidentDate, accidentState, presentingCondition, notesToBiller, isChecked, primaryGuarantorType, ?admitStatus, ?admitFacilityId:int) =  
        let admitStatus = defaultArg admitStatus null 
        getScalar connection false (fun db -> db.UspAppointmentsInsUpd(id, patientId, patientInfoId, providerScheduledId, facilityId, startTime, endTime, typeId, status, billingStage, los, checkInFlag, checkInTime, checkOutTime, foreignEhrId, accidentRelated, accidentId, accidentDate, accidentState, presentingCondition, notesToBiller, isChecked, primaryGuarantorType, admitStatus, admitFacilityId, referralPcp)) 


let conn = Connection(...)
conn.SaveAppointment(referralPcp, Id, patientId, patientInfoId, providerScheduledId, facilityId, startTime, endTime, typeId, status, billingStage, los, checkInFlag, checkInTime, checkOutTime, foreignEhrId, accidentRelated, accidentId, accidentDate, accidentState, presentingCondition, notesToBiller, isChecked, primaryGuarantorType, admitStatus, admitFacilityId)

This works particularly well if there are multiple operations closing over the same context parameters.

There are other variations on this that can serve just as well. A record doesn't cope well with named/optional arguments, except by adding a static "Create" member which makes things optional, which is also ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment